use of org.apache.commons.configuration2.io.FileHandler in project commons by craftercms.
the class ConfigUtils method readXmlConfiguration.
/**
* Reads the XML configuration from the specified input stream, using the given file encoding.
*
* @param input the input stream from where to read the configuration
* @param fileEncoding the encoding of the file. If not specified {@link #DEFAULT_ENCODING} will be used
*
* @return the loaded XML configuration, as a an Apache Commons {@link HierarchicalConfiguration}
*
* @throws ConfigurationException if an error occurs while reading the configuration
*/
public static HierarchicalConfiguration<ImmutableNode> readXmlConfiguration(InputStream input, Map<String, Lookup> prefixLookups, String fileEncoding) throws ConfigurationException {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class);
try {
XMLBuilderParameters xmlParams = params.xml();
if (MapUtils.isNotEmpty(prefixLookups)) {
xmlParams = xmlParams.setPrefixLookups(prefixLookups);
}
builder.configure(xmlParams);
XMLConfiguration config = builder.getConfiguration();
FileHandler fileHandler = new FileHandler(config);
fileHandler.setEncoding(StringUtils.isNotBlank(fileEncoding) ? fileEncoding : DEFAULT_ENCODING);
fileHandler.load(input);
return config;
} catch (Exception e) {
throw new ConfigurationException("Unable to read XML configuration", e);
}
}
use of org.apache.commons.configuration2.io.FileHandler in project studio by craftercms.
the class ConfigUtils method readXmlConfiguration.
public static HierarchicalConfiguration<ImmutableNode> readXmlConfiguration(InputStream input) throws ConfigurationException {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class);
XMLConfiguration config = builder.configure(params.xml()).getConfiguration();
FileHandler fileHandler = new FileHandler(config);
fileHandler.setEncoding("UTF-8");
fileHandler.load(input);
return config;
}
use of org.apache.commons.configuration2.io.FileHandler in project hugegraph-common by hugegraph.
the class HugeConfigTest method testHugeConfigWithConfiguration.
@Test
public void testHugeConfigWithConfiguration() throws Exception {
PropertiesConfiguration configuration = new PropertiesConfiguration();
FileHandler fileHandler = new FileHandler(configuration);
fileHandler.load(CONF);
HugeConfig config = new HugeConfig(configuration);
Assert.assertEquals("file-text1-value", config.get(TestOptions.text1));
Assert.assertEquals("file-text2-value", config.get(TestOptions.text2));
Assert.assertEquals("CHOICE-3", config.get(TestOptions.text3));
}
use of org.apache.commons.configuration2.io.FileHandler in project jcore-dependencies by JULIELab.
the class DBTestUtils method createTestCostosysConfig.
/**
* Writes a CoStoSys test configuration to <code>targetPath</code>.
* @param targetPath The path to write the configuration file to.
* @param schemaName The data table schema to use.
* @param maxActiveConnections The DB connection pool size.
* @param postgres The org.testcontainers postgres test container.
* @return The path to the CoStoSys configuration file.
* @throws ConfigurationException If the creation of the configuration file failed.
*/
public static String createTestCostosysConfig(String targetPath, String schemaName, int maxActiveConnections, PostgreSQLContainer postgres) throws ConfigurationException {
XMLConfiguration costosysconfig = new XMLConfiguration();
costosysconfig.setProperty("databaseConnectorConfiguration.DBSchemaInformation.activeTableSchema", schemaName);
costosysconfig.setProperty("databaseConnectorConfiguration.DBConnectionInformation.activeDBConnection", postgres.getDatabaseName());
costosysconfig.setProperty("databaseConnectorConfiguration.DBConnectionInformation.DBConnections.DBConnection[@name]", postgres.getDatabaseName());
costosysconfig.setProperty("databaseConnectorConfiguration.DBConnectionInformation.DBConnections.DBConnection[@url]", postgres.getJdbcUrl());
costosysconfig.setProperty("databaseConnectorConfiguration.DBConnectionInformation.maxActiveDBConnections", maxActiveConnections);
FileHandler fh = new FileHandler(costosysconfig);
String costosysConfig = targetPath;
fh.save(costosysConfig);
return costosysConfig;
}
use of org.apache.commons.configuration2.io.FileHandler in project modules by assimbly.
the class XMLFileConfiguration method getFlowConfiguration.
public TreeMap<String, String> getFlowConfiguration(String flowId, URI uri) throws Exception {
String scheme = uri.getScheme();
// load uri to configuration
Parameters params = new Parameters();
DocumentBuilder docBuilder = setDocumentBuilder("integration.xsd");
if (scheme.startsWith("sonicfs")) {
URL Url = uri.toURL();
InputStream is = Url.openStream();
conf = new BasicConfigurationBuilder<>(XMLConfiguration.class).configure(params.xml()).getConfiguration();
FileHandler fh = new FileHandler(conf);
fh.load(is);
} else if (scheme.startsWith("file")) {
File xml = new File(uri.getRawPath());
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class).configure(params.xml().setFileName("integration.xml").setFile(xml).setDocumentBuilder(docBuilder).setSchemaValidation(true).setExpressionEngine(new XPathExpressionEngine()));
// This will throw a ConfigurationException if the XML document does not
// conform to its Schema.
conf = builder.getConfiguration();
} else if (scheme.startsWith("http")) {
URL Url = uri.toURL();
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class).configure(params.xml().setURL(Url).setFileName("integration.xml").setDocumentBuilder(docBuilder).setSchemaValidation(true).setExpressionEngine(new XPathExpressionEngine()));
// This will throw a ConfigurationException if the XML document does not
// conform to its Schema.
conf = builder.getConfiguration();
} else {
throw new Exception("URI scheme for " + uri.getRawPath() + " is not supported");
}
properties = new Unmarshall().getProperties(conf, flowId);
return properties;
}
Aggregations