Example usage for org.apache.commons.configuration2.tree DefaultExpressionEngineSymbols DEFAULT_SYMBOLS

List of usage examples for org.apache.commons.configuration2.tree DefaultExpressionEngineSymbols DEFAULT_SYMBOLS

Introduction

In this page you can find the example usage for org.apache.commons.configuration2.tree DefaultExpressionEngineSymbols DEFAULT_SYMBOLS.

Prototype

DefaultExpressionEngineSymbols DEFAULT_SYMBOLS

To view the source code for org.apache.commons.configuration2.tree DefaultExpressionEngineSymbols DEFAULT_SYMBOLS.

Click Source Link

Document

An instance with default symbols.

Usage

From source file:com.gs.obevo.api.factory.XmlFileConfigReader.java

@Override
public HierarchicalConfiguration getConfig(FileObject checkoutFolder) {
    try {/*from   w  ww.j  a v a  2  s  . c o  m*/
        FileObject envFileToRead = getEnvFileToRead(checkoutFolder);
        if (envFileToRead.getName().getExtension().equals("xml")) {
            // For the XML lookup, we want all access to fall to attribute queries if we choose. To do that, we override
            // the expression engine.
            DefaultExpressionEngine engine = new DefaultExpressionEngine(
                    DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS) {
                @Override
                public <T> List<QueryResult<T>> query(T root, String key, NodeHandler<T> handler) {
                    List<QueryResult<T>> results = super.query(root, key, handler);
                    if (!results.isEmpty()) {
                        return results;
                    }

                    // If we find no results, fall back to the query that specifies the attribute handler
                    return super.query(root, this.attributeKey(null, key), handler);
                }
            };

            XMLConfiguration configuration = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
                    .configure(new Parameters().hierarchical().setURL(envFileToRead.getURLDa())
                            .setListDelimiterHandler(new DisabledListDelimiterHandler())
                            .setExpressionEngine(engine))
                    .getConfiguration();
            postProcess(configuration);
            return configuration;
        } else {
            return new FileBasedConfigurationBuilder<>(FixedYAMLConfiguration.class)
                    .configure(new Parameters().hierarchical().setURL(envFileToRead.getURLDa())
                            .setListDelimiterHandler(new DisabledListDelimiterHandler()))
                    .getConfiguration();
        }
    } catch (ConfigurationException e) {
        throw new DeployerRuntimeException(e);
    }
}