List of usage examples for org.apache.commons.collections ExtendedProperties subset
public ExtendedProperties subset(String prefix)
From source file:org.apache.cayenne.unit.di.server.ConnectionProperties.java
/** * Constructor for ConnectionProperties. *///w ww .j a va2 s .c o m ConnectionProperties(ExtendedProperties props) { connectionInfos = new HashMap<>(); for (String name : extractNames(props)) { DataSourceInfo dsi = buildDataSourceInfo(props.subset(name)); connectionInfos.put(name, dsi); } }
From source file:org.apache.flex.forks.velocity.test.CommonsExtPropTestCase.java
/** * Runs the test./*from w w w .ja v a 2 s. c o m*/ */ public void runTest() { try { assureResultsDirectoryExists(RESULTS_DIR); ExtendedProperties c = new ExtendedProperties(TEST_CONFIG); FileWriter result = new FileWriter(getFileName(RESULTS_DIR, "output", "res")); message(result, "Testing order of keys ..."); showIterator(result, c.getKeys()); message(result, "Testing retrieval of CSV values ..."); showVector(result, c.getVector("resource.loader")); message(result, "Testing subset(prefix).getKeys() ..."); ExtendedProperties subset = c.subset("file.resource.loader"); showIterator(result, subset.getKeys()); message(result, "Testing getVector(prefix) ..."); showVector(result, subset.getVector("path")); message(result, "Testing getString(key) ..."); result.write(c.getString("config.string.value")); result.write("\n\n"); message(result, "Testing getBoolean(key) ..."); result.write(new Boolean(c.getBoolean("config.boolean.value")).toString()); result.write("\n\n"); message(result, "Testing getByte(key) ..."); result.write(new Byte(c.getByte("config.byte.value")).toString()); result.write("\n\n"); message(result, "Testing getShort(key) ..."); result.write(new Short(c.getShort("config.short.value")).toString()); result.write("\n\n"); message(result, "Testing getInt(key) ..."); result.write(new Integer(c.getInt("config.int.value")).toString()); result.write("\n\n"); message(result, "Testing getLong(key) ..."); result.write(new Long(c.getLong("config.long.value")).toString()); result.write("\n\n"); message(result, "Testing getFloat(key) ..."); result.write(new Float(c.getFloat("config.float.value")).toString()); result.write("\n\n"); message(result, "Testing getDouble(key) ..."); result.write(new Double(c.getDouble("config.double.value")).toString()); result.write("\n\n"); message(result, "Testing escaped-comma scalar..."); result.write(c.getString("escape.comma1")); result.write("\n\n"); message(result, "Testing escaped-comma vector..."); showVector(result, c.getVector("escape.comma2")); result.write("\n\n"); result.flush(); result.close(); if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output", "res", "cmp")) { fail("Output incorrect."); } } catch (Exception e) { System.err.println("Cannot setup CommonsExtPropTestCase!"); e.printStackTrace(); System.exit(1); } }
From source file:org.apache.velocity.test.CommonsExtPropTestCase.java
/** * Runs the test.//from ww w .ja va2 s. co m */ public void testExtendedProperties() throws Exception { assureResultsDirectoryExists(RESULTS_DIR); ExtendedProperties c = new ExtendedProperties(TEST_CONFIG); FileWriter result = new FileWriter(getFileName(RESULTS_DIR, "output", "res")); message(result, "Testing order of keys ..."); showIterator(result, c.getKeys()); message(result, "Testing retrieval of CSV values ..."); showVector(result, c.getVector("resource.loader")); message(result, "Testing subset(prefix).getKeys() ..."); ExtendedProperties subset = c.subset("file.resource.loader"); showIterator(result, subset.getKeys()); message(result, "Testing getVector(prefix) ..."); showVector(result, subset.getVector("path")); message(result, "Testing getString(key) ..."); result.write(c.getString("config.string.value")); result.write("\n\n"); message(result, "Testing getBoolean(key) ..."); result.write(new Boolean(c.getBoolean("config.boolean.value")).toString()); result.write("\n\n"); message(result, "Testing getByte(key) ..."); result.write(new Byte(c.getByte("config.byte.value")).toString()); result.write("\n\n"); message(result, "Testing getShort(key) ..."); result.write(new Short(c.getShort("config.short.value")).toString()); result.write("\n\n"); message(result, "Testing getInt(key) ..."); result.write(new Integer(c.getInt("config.int.value")).toString()); result.write("\n\n"); message(result, "Testing getLong(key) ..."); result.write(new Long(c.getLong("config.long.value")).toString()); result.write("\n\n"); message(result, "Testing getFloat(key) ..."); result.write(new Float(c.getFloat("config.float.value")).toString()); result.write("\n\n"); message(result, "Testing getDouble(key) ..."); result.write(new Double(c.getDouble("config.double.value")).toString()); result.write("\n\n"); message(result, "Testing escaped-comma scalar..."); result.write(c.getString("escape.comma1")); result.write("\n\n"); message(result, "Testing escaped-comma vector..."); showVector(result, c.getVector("escape.comma2")); result.write("\n\n"); result.flush(); result.close(); if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output", "res", "cmp")) { fail("Output incorrect."); } }
From source file:org.apache.velocity.tools.config.PropertiesFactoryConfiguration.java
/** * <p>Reads an properties file from an {@link InputStream} * and uses it to configure this {@link FactoryConfiguration}.</p> * /* w w w .j a v a 2 s .com*/ * @param input the InputStream to read from */ public void read(InputStream input) throws IOException { ExtendedProperties props = new ExtendedProperties(); props.load(input); // all factory settings should be prefixed with "tools" read(props.subset("tools")); }
From source file:org.apache.velocity.tools.config.PropertiesFactoryConfiguration.java
public void read(ExtendedProperties factory) { // get the global properties readProperties(factory, this); // get the toolboxes readToolboxes(factory);//from www .j a va 2s . c o m // get the data readData(factory.subset("data")); }
From source file:org.apache.velocity.tools.config.PropertiesFactoryConfiguration.java
protected void readProperties(ExtendedProperties configProps, Configuration config) { ExtendedProperties properties = configProps.subset("property"); if (properties != null) { for (Iterator i = properties.getKeys(); i.hasNext();) { String name = (String) i.next(); String value = properties.getString(name); ExtendedProperties propProps = properties.subset(name); if (propProps.size() == 1) { // then set this as a 'simple' property config.setProperty(name, value); } else { // add it as a convertable property Property property = new Property(); property.setName(name);/*from ww w.ja va 2 s.com*/ property.setValue(value); // set the type/converter properties setProperties(propProps, property); } } } }
From source file:org.apache.velocity.tools.config.PropertiesFactoryConfiguration.java
protected void readToolboxes(ExtendedProperties factory) { String[] scopes = factory.getStringArray("toolbox"); for (String scope : scopes) { ToolboxConfiguration toolbox = new ToolboxConfiguration(); toolbox.setScope(scope);/*from w ww . jav a2 s.c o m*/ addToolbox(toolbox); ExtendedProperties toolboxProps = factory.subset(scope); readTools(toolboxProps, toolbox); readProperties(toolboxProps, toolbox); } }
From source file:org.apache.velocity.tools.config.PropertiesFactoryConfiguration.java
protected void readTools(ExtendedProperties tools, ToolboxConfiguration toolbox) { for (Iterator i = tools.getKeys(); i.hasNext();) { String key = (String) i.next(); // if it contains a period, it can't be a context key; // it must be a tool property. ignore it for now. if (key.indexOf('.') >= 0) { continue; }/* ww w . j av a 2s . c o m*/ String classname = tools.getString(key); ToolConfiguration tool = new ToolConfiguration(); tool.setClassname(classname); tool.setKey(key); toolbox.addTool(tool); // get tool properties prefixed by 'property' ExtendedProperties toolProps = tools.subset(key); readProperties(toolProps, tool); // ok, get tool properties that aren't prefixed by 'property' for (Iterator j = toolProps.getKeys(); j.hasNext();) { String name = (String) j.next(); if (!name.equals(tool.getKey())) { tool.setProperty(name, toolProps.getString(name)); } } // get special props explicitly String restrictTo = toolProps.getString("restrictTo"); tool.setRestrictTo(restrictTo); } }
From source file:org.apache.velocity.tools.config.PropertiesFactoryConfiguration.java
protected void readData(ExtendedProperties dataset) { if (dataset != null) { for (Iterator i = dataset.getKeys(); i.hasNext();) { String key = (String) i.next(); // if it contains a period, it can't be a context key; // it must be a data property. ignore it for now. if (key.indexOf('.') >= 0) { continue; }//from w w w.j ava 2s . c o m Data data = new Data(); data.setKey(key); data.setValue(dataset.getString(key)); // get/set the type/converter properties ExtendedProperties props = dataset.subset(key); setProperties(props, data); addData(data); } } }
From source file:org.objectstyle.cayenne.conf.ConnectionProperties.java
/** * Constructor for ConnectionProperties. *///w w w.jav a 2s.c o m public ConnectionProperties(ExtendedProperties props) { Iterator names = extractNames(props).iterator(); while (names.hasNext()) { String name = (String) names.next(); DataSourceInfo dsi = buildDataSourceInfo(props.subset(name)); connectionInfos.put(name, dsi); } }