org.apache.commons.configuration
public final class ConfigurationUtils extends Object
Version: $Revision: 503227 $, $Date: 2007-02-03 17:19:15 +0100 (Sa, 03 Feb 2007) $
Field Summary | |
---|---|
static Log | log The logger. |
static String | METHOD_CLONE Constant for the name of the clone() method. |
static String | PROTOCOL_FILE Constant for the file URL protocol. |
static String | RESOURCE_PATH_SEPARATOR Constant for the resource path separator. |
Constructor Summary | |
---|---|
ConfigurationUtils()
Private constructor. |
Method Summary | |
---|---|
static void | append(Configuration source, Configuration target)
Append all properties from the source configuration to the target
configuration. |
static Object | clone(Object obj)
An internally used helper method for cloning objects. |
static Configuration | cloneConfiguration(Configuration config)
Clones the given configuration object if this is possible. |
static File | constructFile(String basePath, String fileName)
Helper method for constructing a file object from a base path and a
file name. |
static HierarchicalConfiguration | convertToHierarchical(Configuration conf)
Converts the passed in configuration to a hierarchical one. |
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 void | enableRuntimeExceptions(Configuration src)
Enables runtime exceptions for the specified configuration object. |
static File | fileFromURL(URL url)
Tries to convert the specified URL to a file object. |
static String | getBasePath(URL url)
Return the path without the file name, for example http://xyz.net/foo/bar.xml
results in http://xyz.net/foo/
|
static File | getFile(String basePath, String fileName)
Tries to convert the specified base path and file name into a file object.
|
static String | getFileName(URL url)
Extract the file name from the specified URL.
|
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 URL | locateFromClasspath(String resourceName)
Tries to find a resource with the given name in the classpath. |
static String | toString(Configuration configuration)
Get a string representation of the key/value mappings of a
configuration.
|
Parameters: source the source configuration target the target configuration
Since: 1.1
Cloneable
interface. If
this is the case, the clone()
method is invoked by
reflection. Errors that occur during the cloning process are re-thrown as
runtime exceptions.
Parameters: obj the object to be cloned
Returns: the cloned object
Throws: CloneNotSupportedException if the object cannot be cloned
Cloneable
interface, its clone()
method will be invoked. Otherwise
an exception will be thrown.
Parameters: config the configuration object to be cloned (can be null)
Returns: the cloned configuration (null if the argument was null, too)
Throws: ConfigurationRuntimeException if cloning is not supported for this object
Since: 1.3
getURL()
does not seem to be a valid URL.
Parameters: basePath the base path fileName the file name
Returns: the resulting file
Parameters: conf the configuration to convert
Returns: the new hierarchical configuration (the result is null if and only if the passed in configuration is null)
Since: 1.3
clone()
methods
should be used.
Parameters: source the source configuration target the target configuration
Since: 1.1
Parameters: configuration the configuration out the output stream to dump the configuration to
Parameters: configuration the configuration out the writer to dump the configuration to
DatabaseConfiguration
or
JNDIConfiguration
. Per default such errors are simply
logged and then ignored. This implementation will register a special
ConfigurationErrorListener
that throws a runtime
exception (namely a ConfigurationRuntimeException
) on
each received error event.
Parameters: src the configuration, for which runtime exceptions are to be
enabled; this configuration must be derived from
EventSource
Parameters: url the URL
Returns: the resulting file object
Parameters: url the URL from which to extract the path
Returns: the path component of the passed in URL
java.io.File.isAbsolute()
. If the file name starts with a
slash, this method will return true on Unix, but false on
Windows. So to ensure correct behavior for relative file names on all
platforms you should never let relative paths start with a slash. E.g.
in a configuration definition file do not use something like that:
<properties fileName="/subdir/my.properties"/>Under Windows this path would be resolved relative to the configuration definition file. Under Unix this would be treated as an absolute path name.
Parameters: basePath the base path fileName the file name
Returns: the file object (null if no file can be obtained)
Parameters: url the URL from which to extract the file name
Returns: the extracted file name
Parameters: basePath the base path URL (can be null) file the file name
Returns: the resulting URL
Throws: MalformedURLException if URLs are invalid
Parameters: name the name of the resource
Returns: the location of the resource
Parameters: base the base path of the resource name the name of the resource
Returns: the location of the resource
Parameters: resourceName the name of the resource
Returns: the URL to the found resource or null if the resource cannot be found
Parameters: configuration the configuration
Returns: a string representation of the configuration