org.ofbiz.base.util.string
Class FlexibleStringExpander

java.lang.Object
  extended by org.ofbiz.base.util.string.FlexibleStringExpander
All Implemented Interfaces:
java.io.Serializable

public class FlexibleStringExpander
extends java.lang.Object
implements java.io.Serializable

Expands String values that contain Unified Expression Language syntax. Also supports the execution of bsh scripts by using the 'bsh:' prefix. Further it is possible to control the output by specifying the suffix '?currency(XXX)' to format the output according the current locale and specified (XXX) currency.

This class extends the UEL by allowing nested expressions.

See Also:
Serialized Form

Nested Class Summary
protected static class FlexibleStringExpander.BshElem
           
protected static class FlexibleStringExpander.ConstElem
           
protected static class FlexibleStringExpander.CurrElem
           
protected static class FlexibleStringExpander.GroovyElem
           
protected static class FlexibleStringExpander.NestedVarElem
           
protected static interface FlexibleStringExpander.StrElem
           
protected static class FlexibleStringExpander.VarElem
           
 
Field Summary
static java.lang.String closeBracket
           
protected static UtilCache<java.lang.String,FlexibleStringExpander> exprCache
           
protected  int hint
           
static java.lang.String module
           
protected static FlexibleStringExpander nullExpr
           
static java.lang.String openBracket
           
protected  java.lang.String orig
           
protected  java.util.List<FlexibleStringExpander.StrElem> strElems
           
 
Constructor Summary
protected FlexibleStringExpander(java.lang.String original)
           
 
Method Summary
 java.lang.String expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context)
          This expands the pre-parsed String given the context passed in.
 java.lang.String expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Locale locale)
          This expands the pre-parsed String given the context passed in.
 java.lang.String expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.TimeZone timeZone, java.util.Locale locale)
          This expands the pre-parsed String given the context passed in.
static java.lang.String expandString(java.lang.String original, java.util.Map<java.lang.String,? extends java.lang.Object> context)
          Does on-the-fly parsing and expansion of the original String using variable values from the passed context.
static java.lang.String expandString(java.lang.String original, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Locale locale)
          Does on-the-fly parsing and expansion of the original String using variable values from the passed context.
static java.lang.String expandString(java.lang.String original, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.TimeZone timeZone, java.util.Locale locale)
          Does on-the-fly parsing and expansion of the original String using variable values from the passed context.
static FlexibleStringExpander getInstance(java.lang.String original)
          Returns a FlexibleStringExpander instance.
 java.lang.String getOriginal()
           
protected static java.util.List<FlexibleStringExpander.StrElem> getStrElems(java.lang.String original)
          Protected helper method.
 boolean isEmpty()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

module

public static final java.lang.String module

openBracket

public static final java.lang.String openBracket
See Also:
Constant Field Values

closeBracket

public static final java.lang.String closeBracket
See Also:
Constant Field Values

exprCache

protected static final UtilCache<java.lang.String,FlexibleStringExpander> exprCache

nullExpr

protected static final FlexibleStringExpander nullExpr

orig

protected final java.lang.String orig

strElems

protected final java.util.List<FlexibleStringExpander.StrElem> strElems

hint

protected int hint
Constructor Detail

FlexibleStringExpander

protected FlexibleStringExpander(java.lang.String original)
Parameters:
original -
Method Detail

isEmpty

public boolean isEmpty()

getOriginal

public java.lang.String getOriginal()

expandString

public java.lang.String expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context)
This expands the pre-parsed String given the context passed in. A null context argument will return the original String.

Parameters:
context - A context Map containing the variable values
Returns:
The original String expanded by replacing varaible place holders.

expandString

public java.lang.String expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context,
                                     java.util.Locale locale)
This expands the pre-parsed String given the context passed in. A null context argument will return the original String.

Parameters:
context - A context Map containing the variable values
locale - the current set locale
Returns:
The original String expanded by replacing varaible place holders.

expandString

public java.lang.String expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context,
                                     java.util.TimeZone timeZone,
                                     java.util.Locale locale)
This expands the pre-parsed String given the context passed in. A null context argument will return the original String.

Parameters:
context - A context Map containing the variable values
timeZone - the current set time zone
locale - the current set locale
Returns:
The original String expanded by replacing varaible place holders.

getInstance

public static FlexibleStringExpander getInstance(java.lang.String original)
Returns a FlexibleStringExpander instance.

Parameters:
original - The original String expression
Returns:
A FlexibleStringExpander instance

expandString

public static java.lang.String expandString(java.lang.String original,
                                            java.util.Map<java.lang.String,? extends java.lang.Object> context)
Does on-the-fly parsing and expansion of the original String using variable values from the passed context. A null context argument will return the original String.

Parameters:
original - The original String that will be expanded
context - A context Map containing the variable values
Returns:
The original String expanded by replacing varaible place holders.

expandString

public static java.lang.String expandString(java.lang.String original,
                                            java.util.Map<java.lang.String,? extends java.lang.Object> context,
                                            java.util.Locale locale)
Does on-the-fly parsing and expansion of the original String using variable values from the passed context. A null context argument will return the original String.

Parameters:
original - The original String that will be expanded
context - A context Map containing the variable values
Returns:
The original String expanded by replacing varaible place holders.

expandString

public static java.lang.String expandString(java.lang.String original,
                                            java.util.Map<java.lang.String,? extends java.lang.Object> context,
                                            java.util.TimeZone timeZone,
                                            java.util.Locale locale)
Does on-the-fly parsing and expansion of the original String using variable values from the passed context. A null context argument will return the original String.

Parameters:
original - The original String that will be expanded
context - A context Map containing the variable values
Returns:
The original String expanded by replacing varaible place holders.

getStrElems

protected static java.util.List<FlexibleStringExpander.StrElem> getStrElems(java.lang.String original)
Protected helper method.

Parameters:
original -
Returns:
a list of parsed string elements