Java Code Examples for org.apache.commons.configuration2.interpol.ConfigurationInterpolator#registerLookup()

The following examples show how to use org.apache.commons.configuration2.interpol.ConfigurationInterpolator#registerLookup() . 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: InterpolationTestHelper.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests accessing and manipulating the interpolator object.
 *
 * @param config the configuration to test
 */
public static void testGetInterpolator(final AbstractConfiguration config)
{
    config.addProperty("var", "${echo:testVar}");
    final ConfigurationInterpolator interpol = config.getInterpolator();
    interpol.registerLookup("echo", varName -> "Value of variable " + varName);
    assertEquals("Wrong value of echo variable",
            "Value of variable testVar", config.getString("var"));
}
 
Example 2
Source File: TestSubnodeConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
@Test
public void testLocalLookupsInInterpolatorAreInherited()
{
    parent.addProperty("tablespaces.tablespace.name", "default");
    parent.addProperty("tablespaces.tablespace(-1).name", "test");
    parent.addProperty("tables.table(0).var", "${brackets:x}");

    final ConfigurationInterpolator interpolator = parent.getInterpolator();
    interpolator.registerLookup("brackets", key -> "(" + key + ")");
    setUpSubnodeConfig();
    assertEquals("Local lookup was not inherited", "(x)",
            config.getString("var", ""));
}
 
Example 3
Source File: TestSubsetConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocalLookupsInInterpolatorAreInherited() {
    final BaseConfiguration config = new BaseConfiguration();
    final ConfigurationInterpolator interpolator = config.getInterpolator();
    interpolator.registerLookup("brackets", key -> "(" + key +")");
    config.setProperty("prefix.var", "${brackets:x}");
    final AbstractConfiguration subset = (AbstractConfiguration) config
            .subset("prefix");
    assertEquals("Local lookup was not inherited", "(x)", subset
            .getString("var", ""));
}
 
Example 4
Source File: AbstractMultiFileConfigurationBuilderTest.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@code ConfigurationInterpolator} to be used by tests. This
 * object contains a lookup for system properties.
 *
 * @return the new {@code ConfigurationInterpolator}
 */
protected static ConfigurationInterpolator createInterpolator()
{
    final ConfigurationInterpolator ci = new ConfigurationInterpolator();
    ci.registerLookup(DefaultLookups.SYSTEM_PROPERTIES.getPrefix(),
            DefaultLookups.SYSTEM_PROPERTIES.getLookup());
    return ci;
}