Search in sources :

Example 1 with ClasspathLocationStrategy

use of org.apache.commons.configuration2.io.ClasspathLocationStrategy in project zeppelin by apache.

the class ZeppelinConfiguration method loadXMLConfig.

private void loadXMLConfig(@Nullable String filename) throws ConfigurationException {
    if (StringUtils.isBlank(filename)) {
        filename = ZEPPELIN_SITE_XML;
    }
    List<FileLocationStrategy> subs = Arrays.asList(new ZeppelinLocationStrategy(), new ClasspathLocationStrategy());
    FileLocationStrategy strategy = new CombinedLocationStrategy(subs);
    Parameters params = new Parameters();
    FileBasedConfigurationBuilder<XMLConfiguration> xmlbuilder = new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class).configure(params.xml().setLocationStrategy(strategy).setFileName(filename).setBasePath(File.separator + "conf" + File.separator));
    XMLConfiguration xmlConfig = xmlbuilder.getConfiguration();
    List<ImmutableNode> nodes = xmlConfig.getNodeModel().getRootNode().getChildren();
    if (nodes != null && !nodes.isEmpty()) {
        for (ImmutableNode p : nodes) {
            String name = String.valueOf(p.getChildren("name").get(0).getValue());
            String value = String.valueOf(p.getChildren("value").get(0).getValue());
            if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) {
                setProperty(name, value);
            }
        }
    }
}
Also used : FileLocationStrategy(org.apache.commons.configuration2.io.FileLocationStrategy) XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) ImmutableNode(org.apache.commons.configuration2.tree.ImmutableNode) CombinedLocationStrategy(org.apache.commons.configuration2.io.CombinedLocationStrategy) ClasspathLocationStrategy(org.apache.commons.configuration2.io.ClasspathLocationStrategy)

Aggregations

XMLConfiguration (org.apache.commons.configuration2.XMLConfiguration)1 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)1 ClasspathLocationStrategy (org.apache.commons.configuration2.io.ClasspathLocationStrategy)1 CombinedLocationStrategy (org.apache.commons.configuration2.io.CombinedLocationStrategy)1 FileLocationStrategy (org.apache.commons.configuration2.io.FileLocationStrategy)1 ImmutableNode (org.apache.commons.configuration2.tree.ImmutableNode)1