org.apache.commons.configuration
Class ConfigurationUtils

java.lang.Object
  extended byorg.apache.commons.configuration.ConfigurationUtils

public final class ConfigurationUtils
extends Object

Miscellaneous utility methods for configurations.

Version:
$Revision$, $Date: 2005-02-26 13:56:39 +0100 (Sat, 26 Feb 2005) $
Author:
Herve Quiroz, Oliver Heger, Emmanuel Bourg

Method Summary
static void append(Configuration source, Configuration target)
          Append all properties from the source configuration to the target configuration.
static void copy(Configuration source, Configuration target)
          Copy all properties from the source configuration to the target configuration.
static void dump(Configuration configuration, PrintStream out)
          Dump the configuration key/value mappings to some ouput stream.
static void dump(Configuration configuration, PrintWriter out)
          Dump the configuration key/value mappings to some writer.
static File getFile(String basePath, String fileName)
          Tries to convert the specified base path and file name into a file object.
static URL getURL(String basePath, String file)
          Constructs a URL from a base path and a file name.
static URL locate(String name)
          Return the location of the specified resource by searching the user home directory, the current classpath and the system classpath.
static URL locate(String base, String name)
          Return the location of the specified resource by searching the user home directory, the current classpath and the system classpath.
static String toString(Configuration configuration)
          Get a string representation of the key/value mappings of a configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

dump

public static void dump(Configuration configuration,
                        PrintStream out)
Dump the configuration key/value mappings to some ouput stream.

Parameters:
configuration - the configuration
out - the output stream to dump the configuration to

dump

public static void dump(Configuration configuration,
                        PrintWriter out)
Dump the configuration key/value mappings to some writer.

Parameters:
configuration - the configuration
out - the writer to dump the configuration to

toString

public static String toString(Configuration configuration)
Get a string representation of the key/value mappings of a configuration.

Parameters:
configuration - the configuration
Returns:
a string representation of the configuration

copy

public static void copy(Configuration source,
                        Configuration target)
Copy all properties from the source configuration to the target configuration. Properties in the target configuration are replaced with the properties with the same key in the source configuration.

Parameters:
source - the source configuration
target - the target configuration
Since:
1.1

append

public static void append(Configuration source,
                          Configuration target)
Append all properties from the source configuration to the target configuration. Properties in the source configuration are appended to the properties with the same key in the target configuration.

Parameters:
source - the source configuration
target - the target configuration
Since:
1.1

getURL

public static URL getURL(String basePath,
                         String file)
                  throws MalformedURLException
Constructs a URL from a base path and a file name. The file name can be absolute, relative or a full URL. If necessary the base path URL is applied.

Parameters:
basePath - the base path URL (can be null)
file - the file name
Returns:
the resulting URL
Throws:
MalformedURLException - if URLs are invalid

locate

public static URL locate(String name)
Return the location of the specified resource by searching the user home directory, the current classpath and the system classpath.

Parameters:
name - the name of the resource
Returns:
the location of the resource

locate

public static URL locate(String base,
                         String name)
Return the location of the specified resource by searching the user home directory, the current classpath and the system classpath.

Parameters:
base - the base path of the resource
name - the name of the resource
Returns:
the location of the resource

getFile

public static File getFile(String basePath,
                           String fileName)
Tries to convert the specified base path and file name into a file object. This method is called e.g. by the save() methods of file based configurations. The parameter strings can be relative files, absolute files and URLs as well.

Parameters:
basePath - the base path
fileName - the file name
Returns:
the file object (null if no file can be obtained)


Copyright © 2001-2005 The Apache Software Foundation. All Rights Reserved.