Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.configuration.interpol
Class ExprLookup

    java.lang.Object
      org.apache.commons.lang.text.StrLookup
          org.apache.commons.configuration.interpol.ExprLookup

    public class ExprLookup

extends org.apache.commons.lang.text.StrLookup

Lookup that allows expressions to be evaluated.

         ExprLookup.Variables vars = new ExprLookup.Variables();
         vars.add(new ExprLookup.Variable("String", org.apache.commons.lang.StringUtils.class));
         vars.add(new ExprLookup.Variable("Util", new Utility("Hello")));
         vars.add(new ExprLookup.Variable("System", "Class:java.lang.System"));
         XMLConfiguration config = new XMLConfiguration(TEST_FILE);
         config.setLogger(log);
         ExprLookup lookup = new ExprLookup(vars);
         lookup.setConfiguration(config);
         String str = lookup.lookup("'$[element] ' + String.trimToEmpty('$[space.description]')");

In the example above TEST_FILE contains xml that looks like:

     <configuration>
       <element>value</element>
       <space xml:space="preserve">
         <description xml:space="default">     Some text      </description>
       </space>
     </configuration>

The result will be "value Some text". This lookup uses Apache Commons Jexl and requires that the dependency be added to any projects which use this.

Since:
  1.7
Version:
  $Id: ExprLookup.java 1234539 2012-01-22 16:19:15Z oheger $
Author:
  Commons Configuration team

Nested Class Summary
`static class` | `ExprLookup.Variable` The key and corresponding object that will be made available to the JexlContext for use in expressions.
`static class` | `ExprLookup.Variables` List wrapper used to allow the Variables list to be created as beans in DefaultConfigurationBuilder.

Constructor Summary
`ExprLookup()` The default constructor.
`ExprLookup(ExprLookup.Variables list)` Constructor for use by applications.
`ExprLookup(ExprLookup.Variables list, String prefix, String suffix)` Constructor for use by applications.

Method Summary
`ExprLookup.Variables` | `getVariables()` Returns the list of Variables that are accessible within expressions.
`String` | `lookup(String var)` Evaluates the expression.
`void` | `setConfiguration(AbstractConfiguration config)` Set the configuration to be used to interpolate subordinate expressions.
`void` | `setVariablePrefixMatcher(String prefix)` Set the prefix to use to identify subordinate expressions.
`void` | `setVariables(ExprLookup.Variables list)` Add the Variables that will be accessible within expressions.
`void` | `setVariableSuffixMatcher(String suffix)` Set the suffix to use to identify subordinate expressions.

Methods inherited from class org.apache.commons.lang.text.StrLookup
`mapLookup, noneLookup, systemPropertiesLookup`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ExprLookup

    public ExprLookup()

  The default constructor. Will get used when the Lookup is constructed via configuration.

### ExprLookup

    public ExprLookup(ExprLookup.Variables list)

  Constructor for use by applications.

  Parameters:
    `list` - The list of objects to be accessible in expressions.

### ExprLookup

    public ExprLookup(ExprLookup.Variables list,
                      String prefix,
                      String suffix)

  Constructor for use by applications.

  Parameters:
    `list` - The list of objects to be accessible in expressions.
    `prefix` - The prefix to use for subordinate lookups.
    `suffix` - The suffix to use for subordinate lookups.

Method Detail

### setVariablePrefixMatcher

    public void setVariablePrefixMatcher(String prefix)

  Set the prefix to use to identify subordinate expressions. This cannot be the same as the prefix used for the primary expression.

  Parameters:
    `prefix` - The String identifying the beginning of the expression.

### setVariableSuffixMatcher

    public void setVariableSuffixMatcher(String suffix)

  Set the suffix to use to identify subordinate expressions. This cannot be the same as the suffix used for the primary expression.

  Parameters:
    `suffix` - The String identifying the end of the expression.

### setVariables

    public void setVariables(ExprLookup.Variables list)

  Add the Variables that will be accessible within expressions.

  Parameters:
    `list` - The list of Variables.

### getVariables

    public ExprLookup.Variables getVariables()

  Returns the list of Variables that are accessible within expressions.

  Returns:
    the List of Variables that are accessible within expressions.

### setConfiguration

    public void setConfiguration(AbstractConfiguration config)

  Set the configuration to be used to interpolate subordinate expressions.

  Parameters:
    `config` - The Configuration.

### lookup

    public String lookup(String var)

  Evaluates the expression.

  Specified by:
    `lookup` in class `org.apache.commons.lang.text.StrLookup`
  Parameters:
    `var` - The expression.
  Returns:
    The String result of the expression.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2012 The Apache Software Foundation. All Rights Reserved.