List of usage examples for org.apache.commons.configuration XMLConfiguration setAttributeSplittingDisabled
public void setAttributeSplittingDisabled(boolean attributeSplittingDisabled)
Sets a flag whether attribute splitting is disabled.
From source file:com.aol.advertising.qiao.config.AgentXmlConfiguration.java
/** * Load configuration file and interpolate variables. Note that due to the * way Apache Commons Configuration treats property keys, user should avoid * using dot ('.') in the property key. Otherwise ACC may not substitute * some value if the variable contains valid element name(s). * * @param xmlConfigFile/*from w w w. ja va 2 s . c o m*/ * @param propConfigFiles * @return * @throws ConfigurationException */ protected HierarchicalConfiguration readConfigurationFiles(String xmlConfigFile, String propConfigFiles) throws ConfigurationException { try { // convert URI to URL URL[] prop_urls = null; URL xml_url = CommonUtils.uriToURL(xmlConfigFile); if (propConfigFiles != null) { String[] prop_files = propConfigFiles.split(","); prop_urls = new URL[prop_files.length]; for (int i = 0; i < prop_files.length; i++) { prop_urls[i] = CommonUtils.uriToURL(prop_files[i]); } } // combine xml and properties configurations CombinedConfiguration combined_cfg = new CombinedConfiguration(new OverrideCombiner()); XMLConfiguration cfg_xml = new XMLConfiguration(); cfg_xml.setDelimiterParsingDisabled(true); cfg_xml.setAttributeSplittingDisabled(true); cfg_xml.load(xml_url); combined_cfg.addConfiguration(cfg_xml); if (prop_urls != null) { // properties in the earlier files take precedence if duplicate for (int i = 0; i < prop_urls.length; i++) { PropertiesConfiguration cfg_props = new PropertiesConfiguration(); cfg_props.setDelimiterParsingDisabled(true); cfg_props.load(prop_urls[i]); combined_cfg.addConfiguration(cfg_props); } } HierarchicalConfiguration config = (HierarchicalConfiguration) combined_cfg.interpolatedConfiguration(); // !!! resolve variables return config; } catch (Exception e) { throw new ConfigurationException(e.getMessage(), e); } }
From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java
private XMLConfiguration createXMLConfiguration() { XMLConfiguration xmlConfig = new XMLConfiguration(); xmlConfig.setAttributeSplittingDisabled(true); xmlConfig.setDelimiterParsingDisabled(true); if (schemaValidation) { final InputStream resource = Resource.getAsInputStream("vrp_xml_schema.xsd"); if (resource != null) { EntityResolver resolver = new EntityResolver() { @Override/*from ww w . j a v a 2s .c om*/ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { { InputSource is = new InputSource(resource); return is; } } }; xmlConfig.setEntityResolver(resolver); xmlConfig.setSchemaValidation(true); } else { logger.debug( "cannot find schema-xsd file (vrp_xml_schema.xsd). try to read xml without xml-file-validation."); } } return xmlConfig; }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests whether attribute splitting can be disabled. *///from w ww.j a va 2 s .com @Test public void testAttributeSplittingDisabled() throws ConfigurationException { List<Object> values = conf.getList("expressions[@value2]"); assertEquals("Wrong number of attribute values", 2, values.size()); assertEquals("Wrong value 1", "a", values.get(0)); assertEquals("Wrong value 2", "b|c", values.get(1)); XMLConfiguration conf2 = new XMLConfiguration(); conf2.setAttributeSplittingDisabled(true); conf2.setFile(conf.getFile()); conf2.load(); assertEquals("Attribute was split", "a,b|c", conf2.getString("expressions[@value2]")); }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests disabling both delimiter parsing and attribute splitting. *///from w w w . j av a 2s . com @Test public void testAttributeSplittingAndDelimiterParsingDisabled() throws ConfigurationException { conf.clear(); conf.setDelimiterParsingDisabled(true); conf.load(); List<Object> values = conf.getList("expressions[@value2]"); assertEquals("Wrong number of attribute values", 2, values.size()); assertEquals("Wrong value 1", "a,b", values.get(0)); assertEquals("Wrong value 2", "c", values.get(1)); XMLConfiguration conf2 = new XMLConfiguration(); conf2.setAttributeSplittingDisabled(true); conf2.setDelimiterParsingDisabled(true); conf2.setFile(conf.getFile()); conf2.load(); assertEquals("Attribute was split", "a,b|c", conf2.getString("expressions[@value2]")); }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests string properties with list delimiters when delimiter parsing is * disabled/*from w ww. j a v a2 s .c om*/ */ @Test public void testSaveWithDelimiterParsingDisabled() throws ConfigurationException { XMLConfiguration conf = new XMLConfiguration(); conf.setExpressionEngine(new XPathExpressionEngine()); conf.setDelimiterParsingDisabled(true); conf.setAttributeSplittingDisabled(true); conf.setFile(new File(testProperties)); conf.load(); assertEquals("a,b,c", conf.getString("split/list3/@values")); assertEquals(0, conf.getMaxIndex("split/list3/@values")); assertEquals("a\\,b\\,c", conf.getString("split/list4/@values")); assertEquals("a,b,c", conf.getString("split/list1")); assertEquals(0, conf.getMaxIndex("split/list1")); assertEquals("a\\,b\\,c", conf.getString("split/list2")); // save the configuration conf.save(testSaveConf.getAbsolutePath()); // read the configuration and compare the properties XMLConfiguration checkConfig = new XMLConfiguration(); checkConfig.setFileName(testSaveConf.getAbsolutePath()); checkSavedConfig(checkConfig); XMLConfiguration config = new XMLConfiguration(); config.setFileName(testFile2); // config.setExpressionEngine(new XPathExpressionEngine()); config.setDelimiterParsingDisabled(true); config.setAttributeSplittingDisabled(true); config.load(); config.setProperty("Employee[@attr1]", "3,2,1"); assertEquals("3,2,1", config.getString("Employee[@attr1]")); config.save(testSaveFile.getAbsolutePath()); config = new XMLConfiguration(); config.setFileName(testSaveFile.getAbsolutePath()); // config.setExpressionEngine(new XPathExpressionEngine()); config.setDelimiterParsingDisabled(true); config.setAttributeSplittingDisabled(true); config.load(); config.setProperty("Employee[@attr1]", "1,2,3"); assertEquals("1,2,3", config.getString("Employee[@attr1]")); config.setProperty("Employee[@attr2]", "one, two, three"); assertEquals("one, two, three", config.getString("Employee[@attr2]")); config.setProperty("Employee.text", "a,b,d"); assertEquals("a,b,d", config.getString("Employee.text")); config.setProperty("Employee.Salary", "100,000"); assertEquals("100,000", config.getString("Employee.Salary")); config.save(testSaveFile.getAbsolutePath()); checkConfig = new XMLConfiguration(); checkConfig.setFileName(testSaveFile.getAbsolutePath()); checkConfig.setExpressionEngine(new XPathExpressionEngine()); checkConfig.setDelimiterParsingDisabled(true); checkConfig.setAttributeSplittingDisabled(true); checkConfig.load(); assertEquals("1,2,3", checkConfig.getString("Employee/@attr1")); assertEquals("one, two, three", checkConfig.getString("Employee/@attr2")); assertEquals("a,b,d", checkConfig.getString("Employee/text")); assertEquals("100,000", checkConfig.getString("Employee/Salary")); }
From source file:org.apache.james.container.spring.lifecycle.ConfigurationProviderImpl.java
/** * Load the xmlConfiguration from the given resource. * //from w w w . jav a 2 s.c om * @param r * @return * @throws ConfigurationException * @throws IOException */ private XMLConfiguration getConfig(Resource r) throws ConfigurationException, IOException { XMLConfiguration config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); // Don't split attributes which can have bad side-effects with matcher-conditions. // See JAMES-1233 config.setAttributeSplittingDisabled(true); // Use InputStream so we are not bound to File implementations of the // config config.load(r.getInputStream()); return config; }
From source file:org.apache.james.container.spring.lifecycle.osgi.OSGIConfigurationProvider.java
@Override public HierarchicalConfiguration getConfiguration(String beanName) throws ConfigurationException { XMLConfiguration config = new XMLConfiguration(); FileInputStream fis = null;//w ww . ja v a 2s. c o m config.setDelimiterParsingDisabled(true); // Don't split attributes which can have bad side-effects with matcher-conditions. // See JAMES-1233 config.setAttributeSplittingDisabled(true); // Use InputStream so we are not bound to File implementations of the // config try { fis = new FileInputStream("/tmp/" + beanName + ".xml"); config.load(fis); } catch (FileNotFoundException e) { throw new ConfigurationException("Bean " + beanName); } finally { if (fis != null) { try { fis.close(); } catch (Exception e) { // Left empty on purpose } } } return config; }
From source file:org.apache.james.http.jetty.JettyHttpServerFactoryTest.java
private HierarchicalConfiguration loadConfiguration(InputStream configuration) throws org.apache.commons.configuration.ConfigurationException { XMLConfiguration config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); config.setAttributeSplittingDisabled(true); config.load(configuration);//from w w w .j a v a2 s . c om return config; }
From source file:org.apache.james.server.core.configuration.FileConfigurationProvider.java
public static XMLConfiguration getConfig(InputStream configStream) throws ConfigurationException { PropertiesConfiguration.setDefaultListDelimiter(SEMICOLON); XMLConfiguration config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); config.setAttributeSplittingDisabled(true); config.load(configStream);//from w w w .jav a 2 s. co m return config; }
From source file:org.apache.james.utils.FileConfigurationProvider.java
private XMLConfiguration getConfig(InputStream configStream) throws ConfigurationException { XMLConfiguration config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); config.setAttributeSplittingDisabled(true); config.load(configStream);//from w w w. java 2 s. co m return config; }