/** * Get a string associated with the given configuration key. * * @param key The configuration key. * @return The associated string. * @throws ClassCastException is thrown if the key maps to an * object that is not a String. */ public String getString(String key) { return getString(key, null); }
/** * Get a string associated with the given configuration key. * * @param key The configuration key. * @return The associated string. * @throws ClassCastException is thrown if the key maps to an * object that is not a String. */ public String getString(String key) { return getString(key, null); }
public void testInheritDefaultProperties() { Properties defaults = new Properties(); defaults.setProperty("resource.loader", "class"); Properties properties = new Properties(defaults); properties.setProperty("test", "foo"); ExtendedProperties extended = ExtendedProperties.convertProperties(properties); assertEquals("foo", extended.getString("test")); assertEquals("class", extended.getString("resource.loader")); }
/** * Get a string associated with the given configuration key. * * @param key The configuration key. * @param defaultValue The default value. * @return The associated string if key is found, * default value otherwise. * @throws ClassCastException is thrown if the key maps to an * object that is not a String. */ public String getString(String key, String defaultValue) { Object value = get(key); if (value instanceof String) { return interpolate((String) value); } else if (value == null) { if (defaults != null) { return interpolate(defaults.getString(key, defaultValue)); } else { return interpolate(defaultValue); } } else if (value instanceof List) { return interpolate((String) ((List) value).get(0)); } else { throw new ClassCastException('\'' + key + "' doesn't map to a String object"); } }
/** * Get a string associated with the given configuration key. * * @param key The configuration key. * @param defaultValue The default value. * @return The associated string if key is found, * default value otherwise. * @throws ClassCastException is thrown if the key maps to an * object that is not a String. */ public String getString(String key, String defaultValue) { Object value = get(key); if (value instanceof String) { return interpolate((String) value); } else if (value == null) { if (defaults != null) { return interpolate(defaults.getString(key, defaultValue)); } else { return interpolate(defaultValue); } } else if (value instanceof List) { return interpolate((String) ((List) value).get(0)); } else { throw new ClassCastException('\'' + key + "' doesn't map to a String object"); } }
public void testInterpolation() { eprop.setProperty("applicationRoot", "/home/applicationRoot"); eprop.setProperty("db", "${applicationRoot}/db/hypersonic"); String dbProp = "/home/applicationRoot/db/hypersonic"; assertTrue("Checking interpolated variable", eprop.getString("db").equals(dbProp)); }
ep1.load(bais); assertEquals("Back-slashes not interpreted properly", "Hello\\World", ep1.getString("one")); assertEquals("Escaped commas not interpreted properly", "Hello,World", ep1.getString("two")); assertEquals("Commas not interpreted properly", 2, ep1.getVector("three").size()); ep2.load(bais); assertEquals("Back-slash not same after being saved and loaded", ep1.getString("one"), ep2.getString("one")); assertEquals("Escaped comma not same after being saved and loaded", ep1.getString("two"), ep2.getString("two")); assertEquals("Comma not same after being saved and loaded", ep1.getString("three"), ep2.getString("three")); } catch (IOException ioe) { fail("There was an exception saving and loading the EP");
public void testTrailingBackSlash() { ExtendedProperties ep1 = new ExtendedProperties(); try { /* initialize using: one=ONE two=TWO \\ three=THREE */ String s1 = "one=ONE\ntwo=TWO \\\\\nthree=THREE"; byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals("Trailing back-slashes not interpreted properly", 3, ep1.size()); assertEquals("Back-slash not escaped properly", "TWO \\", ep1.getString("two")); } catch (IOException ioe) { fail("There was an exception loading the EP"); } }
@Override public void init(ExtendedProperties configuration) { prefix = configuration.getString("prefix", ""); }
assertEquals("This returns '1'", eprop.getString("number"), "1"); assertTrue("This returns scalar", (eprop.getString("number") instanceof String)); eprop.remove("prop.string"); eprop.setProperty("prop.string", prop2); assertTrue("This returns array", (eprop.getString("prop.string") instanceof java.lang.String)); assertTrue("Returns the full string", subEprop.getString("string").equals(prop)); assertTrue("This returns string for subset", (subEprop.getString("string") instanceof java.lang.String)); assertTrue("This returns array for subset", (subEprop.getVector("string") instanceof java.util.Vector)); assertTrue("This returns array for subset", (subEprop.getList("string") instanceof java.util.List));
/** * String property accessor method to hide the configuration implementation * @param key property key * @return value of key or null */ public String getString(String key) { return configuration.getString( key ); }
/** * Get a string associated with the given configuration key. * * @param key The configuration key. * @return The associated string. * @throws ClassCastException is thrown if the key maps to an * object that is not a String. */ public String getString(String key) { return getString(key, null); }
/** * Get a string associated with the given configuration key. * * @param key The configuration key. * @return The associated string. * @throws ClassCastException is thrown if the key maps to an * object that is not a String. */ public String getString(String key) { return getString(key, null); }
/** * Get a string associated with the given configuration key. * * @param key The configuration key. * @return The associated string. * @throws ClassCastException is thrown if the key maps to an * object that is not a String. */ public String getString(String key) { return getString(key, null); }
/** 初始化resource loader. */ @Override public void init(ExtendedProperties configuration) { rsvc.getLog().info(getLogID() + " : initialization starting."); springLoader = assertNotNull((ResourceLoader) rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_KEY), SPRING_RESOURCE_LOADER_KEY); path = normalizeAbsolutePath(configuration.getString("path"), true); assertTrue(!isEmpty(path), "path"); path += "/"; rsvc.getLog().info(getLogID() + " : set path '" + path + "'"); rsvc.getLog().info(getLogID() + " : initialization complete."); }
/** 初始化resource loader. */ @Override public void init(ExtendedProperties configuration) { rsvc.getLog().info(getLogID() + " : initialization starting."); springLoader = assertNotNull((ResourceLoader) rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_KEY), SPRING_RESOURCE_LOADER_KEY); path = normalizeAbsolutePath(configuration.getString("path"), true); assertTrue(!isEmpty(path), "path"); path += "/"; rsvc.getLog().info(getLogID() + " : set path '" + path + "'"); rsvc.getLog().info(getLogID() + " : initialization complete."); }
static Properties toProperties( ExtendedProperties ep ) { Properties props = new Properties(); for ( Object key : ep.keySet() ) { props.setProperty( key.toString(), ep.getString( key.toString() ) ); } return props; }
/** 初始化resource loader. */ @Override public void init(ExtendedProperties configuration) { rsvc.getLog().info(getLogID() + " : initialization starting."); springLoader = assertNotNull((ResourceLoader) rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_KEY), SPRING_RESOURCE_LOADER_KEY); path = normalizeAbsolutePath(configuration.getString("path"), true); assertTrue(!isEmpty(path), "path"); path += "/"; rsvc.getLog().info(getLogID() + " : set path '" + path + "'"); rsvc.getLog().info(getLogID() + " : initialization complete."); }