[Jukebox-cvs] CVS update: J4/src/java/gnu/j4/config Configuration.java
Brought to you by:
vtt
From: CVS B. <vt...@fr...> - 2000-03-08 07:25:56
|
User: vt Date: 00/03/08 00:21:32 Modified: src/java/gnu/j4/config Configuration.java Log: Fixed the platform dependency, except for the one derived from gnu.j4.LocalConfig. Revision Changes Path 1.24 +74 -70 J4/src/java/gnu/j4/config/Configuration.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/config/Configuration.java?annotate=1.24&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/config/Configuration.java?rev=1.24&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/config/Configuration.java.diff?r1=1.24&r2=1.23&cvsroot=jukebox4 ----------------------------------- Index: Configuration.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/config/Configuration.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- Configuration.java 1999/09/29 04:31:59 1.23 +++ Configuration.java 2000/03/08 07:21:32 1.24 @@ -31,7 +31,7 @@ * target=_top>Java-Apache Project</a> in general and code written by <a * href="mailto:st...@ap...">Stefano Mazzocchi</a> in particular. * - * @version $Id: Configuration.java,v 1.23 1999/09/29 04:31:59 vt Exp $ + * @version $Id: Configuration.java,v 1.24 2000/03/08 07:21:32 vt Exp $ */ public class Configuration extends Hashtable { @@ -100,35 +100,39 @@ * (previous is used as {@link #defaultCfg default configuration} for * it). */ - public static Configuration createChain( String confName,Configuration defaultCfg ) { - File target = new File( confName ), - base = new File( target.getName() ); + public static Configuration createChain(String confName, Configuration defaultCfg) { + + File target = new File(confName), + base = new File(target.getName()); Vector path = new Vector(); String jukebox = "jukebox"; // Read @prefix@/etc/ ... first - path.addElement( new File( gnu.j4.LocalConfig.prefix+"/etc",base.toString() ) ); + path.addElement(new File(gnu.j4.LocalConfig.prefix + + File.separatorChar + + "etc", + base.toString())); // Read $HOME/.jukebox/... second - File home = new File( System.getProperty( "user.home" ),"."+jukebox ); + File home = new File(System.getProperty("user.home"), "."+jukebox); - path.addElement( new File( home,base.toString() ) ); + path.addElement(new File(home, base.toString())); // If the configuration name is absolute, use it as is, otherwise // prepend "./etc/" and make it absolute. if ( !target.isAbsolute() ) { - target = new File( System.getProperty( "user.dir" ),"etc/"+base.toString() ); + target = new File(System.getProperty("user.dir"), "." + base.toString()); } - path.addElement( target ); + path.addElement(target); - return createChain( path,defaultCfg ); + return createChain(path, defaultCfg); } - public static Configuration createChain( Vector path,Configuration defaultCfg ) { + public static Configuration createChain(Vector path, Configuration defaultCfg) { Configuration last = null; for ( Enumeration e = path.elements(); e.hasMoreElements(); ) { @@ -140,21 +144,21 @@ // default. try { - PropertiesReader pr = new PropertiesReader( nextFile.toString() ); + PropertiesReader pr = new PropertiesReader(nextFile.toString()); Configuration next = (last==null) - ? new Configuration( defaultCfg ) - : new Configuration( last ); + ? new Configuration(defaultCfg) + : new Configuration(last); - pr.load( next ); + pr.load(next); last = next; } catch ( IOException ioex ) { - throw new Error( "Not Implemented: "+ioex.toString() ); + throw new Error("Not Implemented: " + ioex.toString()); } } } if ( last == null ) { - last = new Configuration( defaultCfg ); + last = new Configuration(defaultCfg); } return last; @@ -167,8 +171,8 @@ * @return Value as a <code>String</code>, regardless of intended type, * <code>null</code> if not found. */ - public String getString( String key ) { - return getString( key,null ); + public String getString(String key) { + return getString(key, null); } /** @@ -178,8 +182,8 @@ * @return Value as a <code>boolean</code>, <code>false</code> if not * found. */ - public boolean getBoolean( String key ) { - return getBoolean( key,false ); + public boolean getBoolean(String key) { + return getBoolean(key, false); } /** @@ -188,8 +192,8 @@ * @param Keyword to look up. * @return Value as an <code>int</code>, <code>0</code> if not found. */ - public int getInteger( String key ) { - return getInteger( key,0 ); + public int getInteger(String key) { + return getInteger(key, 0); } /** @@ -198,8 +202,8 @@ * @param Keyword to look up. * @return Value as a <code>long</code>, <code>0</code> if not found. */ - public long getLong( String key ) { - return getLong( key,0 ); + public long getLong(String key) { + return getLong(key, 0); } /** @@ -209,8 +213,8 @@ * @return Value as a <code>Vector</code>, <code>null</code> if not * found. */ - public Vector getVector( String key ) { - return getVector( key,null ); + public Vector getVector(String key) { + return getVector(key, null); } /** @@ -222,11 +226,11 @@ * @exception IllegalArgumentException when the object contained here is * neither String nor Vector. */ - public String getString( String key,String defaultValue ) { - Object found = super.get( key ); + public String getString(String key, String defaultValue) { + Object found = super.get(key); if ( found == null && defaultCfg != null ) { - return defaultCfg.getString( key,defaultValue ); + return defaultCfg.getString(key, defaultValue); } if ( found == null ) { @@ -245,31 +249,31 @@ String next = e.nextElement().toString(); if ( result.length() != 0 ) { - result.append( "," ); + result.append(","); } - result.append( next ); + result.append(next); } return result.toString(); } - throw new IllegalArgumentException( key + throw new IllegalArgumentException(key + " expects to see String or Vector, found " - + found.getClass().getName() ); + + found.getClass().getName()); } - public Vector getVector( String key,Vector defaultValue ) { + public Vector getVector(String key, Vector defaultValue) { if ( defaultValue == null ) { defaultValue = new Vector(); } - Object found = super.get( key ); + Object found = super.get(key); if ( found == null && defaultCfg != null ) { - return defaultCfg.getVector( key,defaultValue ); + return defaultCfg.getVector(key, defaultValue); } if ( found == null ) { @@ -282,7 +286,7 @@ Vector dummy = new Vector(); - dummy.addElement( found ); + dummy.addElement(found); return dummy; } @@ -300,18 +304,18 @@ String found = null; try { - found = (String)super.get( key ); + found = (String)super.get(key); } catch ( ClassCastException ccex ) { duplicateKeyword(key); } if ( found == null && defaultCfg != null ) { - return defaultCfg.getBoolean( key,defaultValue ); + return defaultCfg.getBoolean(key, defaultValue); } if ( found != null ) { - return parseBoolean( found ); + return parseBoolean(found); } return defaultValue; @@ -326,7 +330,7 @@ * @exception IllegalArgumentException when the object contained here is * not Integer. */ - public int getInteger( String key,int defaultValue ) { + public int getInteger(String key, int defaultValue) { String found = null; @@ -338,13 +342,13 @@ if ( found == null && defaultCfg != null ) { - return defaultCfg.getInteger( key,defaultValue ); + return defaultCfg.getInteger(key, defaultValue); } if ( found != null ) { try { - return Integer.parseInt( found ); + return Integer.parseInt(found); } catch ( NumberFormatException nfex ) { return defaultValue; } @@ -362,7 +366,7 @@ * @exception IllegalArgumentException when the object contained here is * not Long. */ - public long getLong( String key,long defaultValue ) { + public long getLong(String key, long defaultValue) { String found = null; @@ -374,13 +378,13 @@ if ( found == null && defaultCfg != null ) { - return defaultCfg.getLong( key,defaultValue ); + return defaultCfg.getLong(key, defaultValue); } if ( found != null ) { try { - return Long.parseLong( found ); + return Long.parseLong(found); } catch ( NumberFormatException nfex ) { return defaultValue; } @@ -397,19 +401,19 @@ * @param key The key. * @param value The value. */ - public void put( String key, String value ) { - Object found = super.get( key ); + public void put(String key, String value) { + Object found = super.get(key); if ( found == null ) { - super.put( key,value ); + super.put(key, value); return; } if ( found instanceof Vector ) { Vector vFound = (Vector)found; - if ( vFound.indexOf( value ) == -1 ) { - vFound.addElement( value ); + if ( vFound.indexOf(value) == -1 ) { + vFound.addElement(value); } return; @@ -417,18 +421,18 @@ if ( found instanceof String ) { String first = (String)found; - super.remove( key ); + super.remove(key); Vector set = new Vector(); - set.addElement( first ); - set.addElement( value ); - super.put( key,set ); + set.addElement(first); + set.addElement(value); + super.put(key, set); return; } - throw new IllegalArgumentException( key + throw new IllegalArgumentException(key + " maps to " + found.getClass().getName() - + ", String/Vector expected" ); + + ", String/Vector expected"); } /** @@ -443,34 +447,34 @@ * @param value Value to parse. * @return Boolean value of the string. */ - public static boolean parseBoolean( String value ) { + public static boolean parseBoolean(String value) { String source = value.toLowerCase(); - if ( source.equals( "on" ) - || source.equals( "true" ) - || source.equals( "1" ) - || source.equals( "yes" ) ) { + if ( source.equals("on") + || source.equals("true") + || source.equals("1") + || source.equals("yes") ) { return true; } - if ( source.equals( "off" ) - || source.equals( "false" ) - || source.equals( "0" ) - || source.equals( "no" ) ) { + if ( source.equals("off") + || source.equals("false") + || source.equals("0") + || source.equals("no") ) { return false; } - throw new IllegalArgumentException( "Not boolean: '"+value+"'" ); + throw new IllegalArgumentException("Not boolean: '" + value + "'"); } public String toString() { - String result = "("+super.toString()+")"; + String result = "(" + super.toString() + ")"; if ( defaultCfg == null ) { return result; } - return "(Default: "+defaultCfg.toString()+result+")"; + return "(Default: " + defaultCfg.toString() + result + ")"; } /** |