org.apache.commons.configuration2.tree.DefaultExpressionEngineSymbols Java Examples

The following examples show how to use org.apache.commons.configuration2.tree.DefaultExpressionEngineSymbols. 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: TestCombinedConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests using a conversion expression engine for child configurations with
 * strange keys. This test is related to CONFIGURATION-336.
 */
@Test
public void testConversionExpressionEngine()
{
    final PropertiesConfiguration child = new PropertiesConfiguration();
    child.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    child.addProperty("test(a)", "1,2,3");
    config.addConfiguration(child);
    final DefaultExpressionEngine engineQuery =
            new DefaultExpressionEngine(
                    new DefaultExpressionEngineSymbols.Builder(
                            DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS)
                            .setIndexStart("<").setIndexEnd(">").create());
    config.setExpressionEngine(engineQuery);
    final DefaultExpressionEngine engineConvert =
            new DefaultExpressionEngine(
                    new DefaultExpressionEngineSymbols.Builder(
                            DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS)
                            .setIndexStart("[").setIndexEnd("]").create());
    config.setConversionExpressionEngine(engineConvert);
    assertEquals("Wrong property 1", "1", config.getString("test(a)<0>"));
    assertEquals("Wrong property 2", "2", config.getString("test(a)<1>"));
    assertEquals("Wrong property 3", "3", config.getString("test(a)<2>"));
}
 
Example #2
Source File: TestConfigurationUtils.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests converting a configuration to a hierarchical one using a specific
 * expression engine.
 */
@Test
public void testConvertToHierarchicalEngine()
{
    final Configuration conf = new BaseConfiguration();
    conf.addProperty("test(a)", Boolean.TRUE);
    conf.addProperty("test(b)", Boolean.FALSE);
    final DefaultExpressionEngine engine =
            new DefaultExpressionEngine(
                    new DefaultExpressionEngineSymbols.Builder(
                            DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS)
                            .setIndexStart("[").setIndexEnd("]").create());
    final HierarchicalConfiguration<?> hc = ConfigurationUtils
            .convertToHierarchical(conf, engine);
    assertTrue("Wrong value for test(a)", hc.getBoolean("test(a)"));
    assertFalse("Wrong value for test(b)", hc.getBoolean("test(b)"));
}
 
Example #3
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 #4
Source File: StudioConfigurationImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
protected ExpressionEngine getExpressionEngine() {
    DefaultExpressionEngineSymbols symbols =
        new DefaultExpressionEngineSymbols.Builder(DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS)
            // Use a slash as property delimiter
            .setPropertyDelimiter("/")
            // A Backslash is used for escaping property delimiters
            .setEscapedDelimiter("\\/").create();
    return new DefaultExpressionEngine(symbols);
}
 
Example #5
Source File: TestCombinedConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether write access to the conversion expression engine is
 * synchronized.
 */
@Test
public void testSetConversionExpressionEngineSynchronized()
{
    final SynchronizerTestImpl sync = setUpSynchronizerTest();
    config.setConversionExpressionEngine(new DefaultExpressionEngine(
            DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS));
    sync.verify(Methods.BEGIN_WRITE, Methods.END_WRITE);
    checkCombinedRootNotConstructed();
}
 
Example #6
Source File: TestAbstractHierarchicalConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
private ExpressionEngine createAlternativeExpressionEngine()
{
    return new DefaultExpressionEngine(
            new DefaultExpressionEngineSymbols.Builder(
                    DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS)
                    .setPropertyDelimiter("/").setIndexStart("[")
                    .setIndexEnd("]").create());
}
 
Example #7
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 #8
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 #9
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Prepares a parameters object for a test for properties inheritance.
 * @param params the {@code Parameters} object
 * @return the builder parameters
 */
private static XMLBuilderParameters prepareParamsForInheritanceTest(final Parameters params) {
    final DefaultExpressionEngineSymbols symbols = new DefaultExpressionEngineSymbols.Builder(
            DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS)
            .setPropertyDelimiter("/").create();
    final DefaultExpressionEngine engine = new DefaultExpressionEngine(symbols);
    final DefaultListDelimiterHandler listDelimiterHandler = new DefaultListDelimiterHandler(',');
    return params.xml()
            .setExpressionEngine(engine)
            .setListDelimiterHandler(listDelimiterHandler).setFile(TEST_FILE);
}
 
Example #10
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);
    }
}