Java Code Examples for org.apache.commons.configuration2.tree.DefaultExpressionEngineSymbols#DEFAULT_SYMBOLS

The following examples show how to use org.apache.commons.configuration2.tree.DefaultExpressionEngineSymbols#DEFAULT_SYMBOLS . 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: TestINIConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether an expression engine can be used which ignores case.
 */
@Test
public void testExpressionEngineIgnoringCase()
        throws ConfigurationException
{
    final DefaultExpressionEngine engine =
            new DefaultExpressionEngine(
                    DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS,
                    NodeNameMatchers.EQUALS_IGNORE_CASE);
    final INIConfiguration config = new INIConfiguration();
    config.setExpressionEngine(engine);
    load(config, INI_DATA);

    checkContent(config);
    assertEquals("Wrong result (1)", "foo",
            config.getString("Section1.var1"));
    assertEquals("Wrong result (2)", "foo",
            config.getString("section1.Var1"));
    assertEquals("Wrong result (1)", "foo",
            config.getString("SECTION1.VAR1"));
}
 
Example 2
Source File: TestConfigurationUtils.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests converting an already hierarchical configuration using an
 * expression engine. The new engine should be set.
 */
@Test
public void testConvertHierarchicalToHierarchicalEngine()
{
    final BaseHierarchicalConfiguration hc = new BaseHierarchicalConfiguration();
    final ExpressionEngine engine =
            new DefaultExpressionEngine(
                    DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS);
    assertSame("Created new configuration", hc, ConfigurationUtils
            .convertToHierarchical(hc, engine));
    assertSame("Engine was not set", engine, hc.getExpressionEngine());
}
 
Example 3
Source File: TestConfigurationUtils.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests converting an already hierarchical configuration using a null
 * expression engine. In this case the expression engine of the
 * configuration should not be touched.
 */
@Test
public void testConvertHierarchicalToHierarchicalNullEngine()
{
    final BaseHierarchicalConfiguration hc = new BaseHierarchicalConfiguration();
    final ExpressionEngine engine =
            new DefaultExpressionEngine(
                    DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS);
    hc.setExpressionEngine(engine);
    assertSame("Created new configuration", hc, ConfigurationUtils
            .convertToHierarchical(hc, null));
    assertSame("Expression engine was changed", engine, hc
            .getExpressionEngine());
}
 
Example 4
Source File: XmlFileConfigReader.java    From obevo with Apache License 2.0 4 votes vote down vote up
@Override
public HierarchicalConfiguration getConfig(FileObject checkoutFolder) {
    try {
        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<>(YAMLConfiguration.class)
                    .configure(new Parameters().hierarchical()
                            .setURL(envFileToRead.getURLDa())
                            .setListDelimiterHandler(new DisabledListDelimiterHandler())
                    )
                    .getConfiguration();
        }
    } catch (ConfigurationException e) {
        throw new DeployerRuntimeException(e);
    }
}