Java Code Examples for org.apache.velocity.util.ExtProperties#subset()
The following examples show how to use
org.apache.velocity.util.ExtProperties#subset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertiesFactoryConfiguration.java From velocity-tools with Apache License 2.0 | 6 votes |
protected void readData(ExtProperties 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; } Data data = new Data(); data.setKey(key); data.setValue(dataset.getString(key)); // get/set the type/converter properties ExtProperties props = dataset.subset(key); setProperties(props, data); addData(data); } } }
Example 2
Source File: PropertiesFactoryConfiguration.java From velocity-tools with Apache License 2.0 | 5 votes |
protected void readProperties(ExtProperties configProps, Configuration config) { ExtProperties properties = configProps.subset("property"); if (properties != null) { for (Iterator i = properties.getKeys(); i.hasNext(); ) { String name = (String)i.next(); String value = properties.getString(name); ExtProperties 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); property.setValue(value); // set the type/converter properties setProperties(propProps, property); } } } }
Example 3
Source File: PropertiesFactoryConfiguration.java From velocity-tools with Apache License 2.0 | 5 votes |
protected void readToolboxes(ExtProperties factory) { String[] scopes = factory.getStringArray("toolbox"); for (String scope : scopes) { ToolboxConfiguration toolbox = new ToolboxConfiguration(); toolbox.setScope(scope); addToolbox(toolbox); ExtProperties toolboxProps = factory.subset(scope); readTools(toolboxProps, toolbox); readProperties(toolboxProps, toolbox); } }
Example 4
Source File: PropertiesFactoryConfiguration.java From velocity-tools with Apache License 2.0 | 5 votes |
protected void readTools(ExtProperties 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; } String classname = tools.getString(key); ToolConfiguration tool = new ToolConfiguration(); tool.setClassname(classname); tool.setKey(key); toolbox.addTool(tool); // get tool properties prefixed by 'property' ExtProperties 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); } }
Example 5
Source File: CommonsExtPropTestCase.java From velocity-engine with Apache License 2.0 | 4 votes |
/** * Runs the test. */ public void testExtendedProperties () throws Exception { assureResultsDirectoryExists(RESULTS_DIR); ExtProperties c = new ExtProperties(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.loaders")); message(result, "Testing subset(prefix).getKeys() ..."); ExtProperties subset = c.subset("resource.loader.file"); 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(Boolean.valueOf(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."); } }