diff --git a/src/java/com/samskivert/util/ConfigUtil.java b/src/java/com/samskivert/util/ConfigUtil.java index ef93ca60..1eb89d2a 100644 --- a/src/java/com/samskivert/util/ConfigUtil.java +++ b/src/java/com/samskivert/util/ConfigUtil.java @@ -24,24 +24,20 @@ import java.io.*; import java.net.URL; import java.security.AccessControlException; import java.util.*; +import java.util.Map; import static com.samskivert.Log.log; /** - * The config util class provides routines for loading configuration - * information. - * - * @see #loadProperties - * @see #getSystemProperty + * The config util class provides routines for loading configuration information. */ public class ConfigUtil { /** - * Obtains the specified system property via {@link - * System#getProperty}, parses it into an integer and returns the - * value. If the property is not set, the default value will be - * returned. If the property is not a properly formatted integer, an - * error will be logged and the default value will be returned. + * Obtains the specified system property via {@link System#getProperty}, parses it into an + * integer and returns the value. If the property is not set, the default value will be + * returned. If the property is not a properly formatted integer, an error will be logged and + * the default value will be returned. */ public static int getSystemProperty (String key, int defval) { @@ -59,20 +55,17 @@ public class ConfigUtil } /** - * Loads a properties file from the named file that exists somewhere - * in the classpath. + * Loads a properties file from the named file that exists somewhere in the classpath. * - *
The classloader that loaded the ConfigUtil class
- * is searched first, followed by the system classpath. If you wish to
- * provide an additional classloader, use the version of this function
- * that takes a classloader as an argument.
+ *
The classloader that loaded the ConfigUtil class is searched first,
+ * followed by the system classpath. If you wish to provide an additional classloader, use the
+ * version of this function that takes a classloader as an argument.
*
- * @param path The path to the properties file, relative to the root
- * of the classpath entry from which it will be loaded
- * (e.g. com/foo/config.properties).
+ * @param path The path to the properties file, relative to the root of the classpath entry
+ * from which it will be loaded (e.g. com/foo/config.properties).
*
- * @return A properties object loaded with the contents of the
- * specified file if the file could be found, null otherwise.
+ * @return A properties object loaded with the contents of the specified file if the file could
+ * be found, null otherwise.
*/
public static Properties loadProperties (String path)
throws IOException
@@ -81,9 +74,8 @@ public class ConfigUtil
}
/**
- * Like {@link #loadProperties(String)} but this method uses the
- * supplied class loader rather than the class loader used to load the
- * ConfigUtil class.
+ * Like {@link #loadProperties(String)} but this method uses the supplied class loader rather
+ * than the class loader used to load the ConfigUtil class.
*/
public static Properties loadProperties (String path, ClassLoader loader)
throws IOException
@@ -94,8 +86,8 @@ public class ConfigUtil
}
/**
- * Like {@link #loadProperties(String,ClassLoader)} but the properties
- * are loaded into the supplied {@link Properties} object.
+ * Like {@link #loadProperties(String,ClassLoader)} but the properties are loaded into the
+ * supplied {@link Properties} object.
*/
public static void loadProperties (
String path, ClassLoader loader, Properties target)
@@ -110,18 +102,16 @@ public class ConfigUtil
}
/**
- * Creates a properties instance by combining properties files loaded
- * using the specified classpath-relative property file
- * path.
+ * Creates a properties instance by combining properties files loaded using the specified
+ * classpath-relative property file path.
*
*
The inheritance works in two ways: * *
All properties files with the specified name are located - * in the classpath and merged into a single set of properties - * according to an explicit inheritance hierarchy defined by a couple - * of custom properties. This is best explained with an example: + *
All properties files with the specified name are located in the classpath and merged + * into a single set of properties according to an explicit inheritance hierarchy defined by a + * couple of custom properties. This is best explained with an example: * *
com/samskivert/foolib/config.properties contains:
*
@@ -133,10 +123,9 @@ public class ConfigUtil
* ...
*
*
- * and this is packaged into foolib.jar. Happy Corp
- * writes an application that uses foolib and wants to override some
- * properties in foolib's configuration. They create a properties file
- * in happyapp.jar with the path
+ * and this is packaged into foolib.jar. Happy Corp writes an application that
+ * uses foolib and wants to override some properties in foolib's configuration. They create a
+ * properties file in happyapp.jar with the path
* com/samskivert/foolib/config.properties. It contains:
*
*
@@ -146,15 +135,13 @@ public class ConfigUtil
* config2 = happyvalue
*
*
- * When foolib loads its config.properties the overrides
- * from happyapp.jar will be applied to the properties
- * defined in foolib.jar and foolib will see Happy Corp's
- * overridden properties.
+ * When foolib loads its config.properties the overrides from
+ * happyapp.jar will be applied to the properties defined in
+ * foolib.jar and foolib will see Happy Corp's overridden properties.
*
- * Note that conflicting overrides must be resolved "by hand" so
- * to speak. For example, if Happy Corp used some other library that
- * also overrode foolib's configuration, say barlib, whose
- * barlib.jar contained:
+ *
Note that conflicting overrides must be resolved "by hand" so to speak. For example, if
+ * Happy Corp used some other library that also overrode foolib's configuration, say barlib,
+ * whose barlib.jar contained:
*
*
* _package = barlib
@@ -163,10 +150,9 @@ public class ConfigUtil
* config1 = barvalue
*
*
- * Happy Corp's config.properties would not be able to
- * override foolib's configuration directly because the config system
- * would not know which overrides to use. It instead must override
- * barlib's configuration, like so:
+ * Happy Corp's config.properties would not be able to override foolib's
+ * configuration directly because the config system would not know which overrides to use. It
+ * instead must override barlib's configuration, like so:
*
*
* _package = happyapp
@@ -174,9 +160,8 @@ public class ConfigUtil
* ...
*
*
- * Moreover, if there were yet a third library that also overrode
- * foolib, Happy Corp would have to resolve the conflict between
- * barlib and bazlib explicitly:
+ * Moreover, if there were yet a third library that also overrode foolib, Happy Corp would have
+ * to resolve the conflict between barlib and bazlib explicitly:
*
*
* _package = happyapp
@@ -184,20 +169,17 @@ public class ConfigUtil
* ...
*
*
- * This would force bazlib's overrides to take precedence over
- * barlib's overrides, resolving the inheritance ambiguity created
- * when both barlib and bazlib claimed to override foolib.
+ * This would force bazlib's overrides to take precedence over barlib's overrides, resolving
+ * the inheritance ambiguity created when both barlib and bazlib claimed to override foolib.
*
- * This all certainly seems a bit complicated, but in most cases - * there is only one user of a library and overriding is very - * straightforward. The additional functionality is provided to - * resolve cases where conflicts do arise. + *
This all certainly seems a bit complicated, but in most cases there is only one user of + * a library and overriding is very straightforward. The additional functionality is provided + * to resolve cases where conflicts do arise. * *
The second type of inheritance, extension, is more - * straightforward. In this case, a properties file explicitly extends - * another properties file. For example, + *
The second type of inheritance, extension, is more straightforward. In this case, a
+ * properties file explicitly extends another properties file. For example,
* com/foocorp/puzzle/config.properties contains:
*
*
@@ -216,55 +198,45 @@ public class ConfigUtil
* bonus = 55
*
*
- * The Footris configuration will inherit default values from the
- * general puzzle configuration, overriding any that are specified
- * explicitly.
+ * The Footris configuration will inherit default values from the general puzzle configuration,
+ * overriding any that are specified explicitly.
*
- * When resolving a properties file that extends another
- * properties file, first the extended properties are loaded and all
- * _overrides are applied to that properties file. Then
- * all _overrides are applied to the extending properties
- * file and then the extending properties are merged with the extended
- * properties.
- *
When resolving a properties file that extends another properties file, first the
+ * extended properties are loaded and all The classloader that loaded the The classloader that loaded the The supplied classloader is searched first, followed by the
- * system classloader.
+ * The supplied classloader is searched first, followed by the system classloader.
*
- * @param path The path to the file, relative to the root of the
- * classpath directory from which it will be loaded
- * (e.g. _overrides are applied to that
+ * properties file. Then all _overrides are applied to the extending properties
+ * file and then the extending properties are merged with the extended properties.
*
- * A final note: All of the inheritance directives must be
- * grouped together in an uninterrupted sequence of lines. One the
- * parsing code finds the first directive, it stops parsing when it
- * sees a line that does not contain a directive.
+ * A final note: All of the inheritance directives must be grouped together in an
+ * uninterrupted sequence of lines. One the parsing code finds the first directive, it stops
+ * parsing when it sees a line that does not contain a directive.
*
- * @param path The path to the properties file, relative to the root
- * of the classpath entries from which it will be loaded
- * (e.g. com/foo/config.properties).
+ * @param path The path to the properties file, relative to the root of the classpath entries
+ * from which it will be loaded (e.g. com/foo/config.properties).
*
- * @return A properties object loaded with the contents of the
- * specified file if the file could be found, null otherwise.
+ * @return A properties object loaded with the contents of the specified file if the file could
+ * be found, null otherwise.
*/
public static Properties loadInheritedProperties (String path)
throws IOException
{
- return loadInheritedProperties(
- path, ConfigUtil.class.getClassLoader());
+ return loadInheritedProperties(path, ConfigUtil.class.getClassLoader());
}
/**
- * Like {@link #loadInheritedProperties(String)} but loads the
- * properties into the supplied target object.
+ * Like {@link #loadInheritedProperties(String)} but loads the properties into the supplied
+ * target object.
*/
public static void loadInheritedProperties (String path, Properties target)
throws IOException
{
- loadInheritedProperties(
- path, ConfigUtil.class.getClassLoader(), target);
+ loadInheritedProperties(path, ConfigUtil.class.getClassLoader(), target);
}
/**
- * Like {@link #loadInheritedProperties(String)} but this method uses
- * the supplied class loader rather than the class loader used to load
- * the ConfigUtil class.
+ * Like {@link #loadInheritedProperties(String)} but this method uses the supplied class loader
+ * rather than the class loader used to load the ConfigUtil class.
*/
- public static Properties loadInheritedProperties (
- String path, ClassLoader loader)
+ public static Properties loadInheritedProperties (String path, ClassLoader loader)
throws IOException
{
Properties props = new Properties();
@@ -273,21 +245,18 @@ public class ConfigUtil
}
/**
- * Like {@link #loadInheritedProperties(String,ClassLoader)} but the
- * properties are loaded into the supplied properties object.
- * Properties that already exist in the supplied object will be
- * overwritten by the loaded properties where they have the same key.
+ * Like {@link #loadInheritedProperties(String,ClassLoader)} but the properties are loaded into
+ * the supplied properties object. Properties that already exist in the supplied object will
+ * be overwritten by the loaded properties where they have the same key.
*/
- public static void loadInheritedProperties (
- String path, ClassLoader loader, Properties target)
+ public static void loadInheritedProperties (String path, ClassLoader loader, Properties target)
throws IOException
{
// first look for the files in the supplied class loader
EnumerationConfigUtil class
- * is searched first, followed by the system classpath. If you wish to
- * provide an additional classloader, use the version of this function
- * that takes a classloader as an argument.
+ * ConfigUtil class is searched first,
+ * followed by the system classpath. If you wish to provide an additional classloader, use the
+ * version of this function that takes a classloader as an argument.
*
- * @param path The path to the file, relative to the root of the
- * classpath directory from which it will be loaded
- * (e.g. com/foo/bar/foo.gif).
+ * @param path The path to the file, relative to the root of the classpath directory from which
+ * it will be loaded (e.g. com/foo/bar/foo.gif).
*/
public static InputStream getStream (String path)
{
@@ -546,15 +500,12 @@ public class ConfigUtil
}
/**
- * Returns an input stream referencing a file that exists somewhere in
- * the classpath.
+ * Returns an input stream referencing a file that exists somewhere in the classpath.
*
- * com/foo/bar/foo.gif).
+ * @param path The path to the file, relative to the root of the classpath directory from which
+ * it will be loaded (e.g. com/foo/bar/foo.gif).
*/
public static InputStream getStream (String path, ClassLoader loader)
{
@@ -564,8 +515,8 @@ public class ConfigUtil
return in;
}
- // if that didn't work, try the system class loader (but only if
- // it's different from the class loader we just tried)
+ // if that didn't work, try the system class loader (but only if it's different from the
+ // class loader we just tried)
try {
ClassLoader sysloader = ClassLoader.getSystemClassLoader();
if (sysloader != loader) {
@@ -577,8 +528,7 @@ public class ConfigUtil
return null;
}
- protected static InputStream getResourceAsStream (
- String path, ClassLoader loader)
+ protected static InputStream getResourceAsStream (String path, ClassLoader loader)
{
// make sure the class loader isn't null
if (loader == null) {
@@ -595,8 +545,7 @@ public class ConfigUtil
return loader.getResourceAsStream(togglePath(path));
}
- protected static Enumeration