1 package alt.jiapi.file; 2 3 import java.io.InputStream ; 4 import java.util.Properties ; 5 6 import org.apache.log4j.Category; 7 8 13 class Configuration { 14 private static final Category log = Category.getInstance(Configuration.class); 15 private String resource; 16 17 Configuration() { 18 this.resource = "/jiapi.properties"; 19 } 20 21 Configuration(String resource) { 22 this.resource = resource; 23 } 24 25 26 boolean getBoolean(String key) { 27 if (key == null) { 28 return false; 29 } 30 31 Properties p = getProperties(resource); 32 String s = p.getProperty(key); 33 34 boolean b = false; 35 try { 36 b = Boolean.valueOf(s).booleanValue(); 37 } 38 catch(Exception e) { 39 } 40 41 return b; 42 } 43 44 45 boolean getBoolean(String key, boolean dflt) { 46 if (key == null) { 47 return dflt; 48 } 49 50 Properties p = getProperties(resource); 51 String s = p.getProperty(key); 52 53 boolean b = dflt; 54 try { 55 b = Boolean.valueOf(s).booleanValue(); 56 } 57 catch(Exception e) { 58 } 59 60 return b; 61 } 62 63 64 private Properties getProperties(String name) { 65 Properties properties = new Properties (); 66 67 try { 68 InputStream is = getClass().getResourceAsStream(name); 69 if (is != null) { 70 properties.load(is); 71 } 72 else { 73 log.warn("Could not find resource: " + name); 74 } 75 } 76 catch (Exception e) { 77 log.error("Failed to get property file " + name + ", " + e); 78 } 79 80 return properties; 81 } 82 } 83 | Popular Tags |