Class FlexibleStringExpander
- java.lang.Object
-
- org.apache.ofbiz.base.util.string.FlexibleStringExpander
-
- All Implemented Interfaces:
java.io.Serializable
,IsEmpty
- Direct Known Subclasses:
FlexibleStringExpander.ArrayOffsetString
,FlexibleStringExpander.ConstSimpleElem
public abstract class FlexibleStringExpander extends java.lang.Object implements java.io.Serializable, IsEmpty
Expands String values that contain Unified Expression Language (JSR 245) syntax. This class also supports the execution of Groovy scripts by using the 'groovy:' prefix. Further it is possible to control the output by specifying the suffix '?currency(XXX)' to format the output according to the supplied locale and specified (XXX) currency.This class extends the UEL by allowing nested expressions.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
FlexibleStringExpander.ArrayOffsetString
protected static class
FlexibleStringExpander.ConstOffsetElem
An object that represents aString
constant portion of an expression.protected static class
FlexibleStringExpander.ConstSimpleElem
An object that represents aString
constant portion of an expression.protected static class
FlexibleStringExpander.CurrElem
An object that represents a currency portion of an expression.protected static class
FlexibleStringExpander.Elements
A container object that contains expression fragments.protected static class
FlexibleStringExpander.NestedVarElem
An object that represents a nested expression.protected static class
FlexibleStringExpander.ScriptElem
An object that represents a${[groovy|bsh]:}
expression.protected static class
FlexibleStringExpander.VarElem
An object that represents a simple, non-nested expression.
-
Field Summary
Fields Modifier and Type Field Description protected char[]
chars
static java.lang.String
closeBracket
protected static UtilCache<org.apache.ofbiz.base.util.string.FlexibleStringExpander.Key,FlexibleStringExpander>
exprCache
protected int
hint
static java.lang.String
module
protected static FlexibleStringExpander
nullExpr
static java.lang.String
openBracket
-
Constructor Summary
Constructors Modifier Constructor Description protected
FlexibleStringExpander(char[] chars)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static boolean
containsConstant(FlexibleStringExpander fse)
Returnstrue
iffse
contains aString
constant.static boolean
containsExpression(FlexibleStringExpander fse)
Returnstrue
iffse
contains an expression.static boolean
containsScript(FlexibleStringExpander fse)
Returnstrue
iffse
contains a script.java.lang.Object
expand(java.util.Map<java.lang.String,? extends java.lang.Object> context)
Evaluate this object's expression and return the result as anObject
.java.lang.Object
expand(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Locale locale)
Evaluate this object's expression and return the result as anObject
.java.lang.Object
expand(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.TimeZone timeZone, java.util.Locale locale)
Evaluate this object's expression and return the result as anObject
.static java.lang.String
expandString(java.lang.String expression, java.util.Map<java.lang.String,? extends java.lang.Object> context)
Evaluate an expression and return the result as aString
.static java.lang.String
expandString(java.lang.String expression, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Locale locale)
Evaluate an expression and return the result as aString
.static java.lang.String
expandString(java.lang.String expression, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.TimeZone timeZone, java.util.Locale locale)
Evaluate an expression and return the result as aString
.java.lang.String
expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context)
Evaluate this object's expression and return the result as aString
.java.lang.String
expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Locale locale)
Evaluate this object's expression and return the result as aString
.java.lang.String
expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.TimeZone timeZone, java.util.Locale locale)
Evaluate this object's expression and return the result as aString
.protected abstract java.lang.Object
get(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.TimeZone timeZone, java.util.Locale locale)
static FlexibleStringExpander
getInstance(java.lang.String expression)
Returns aFlexibleStringExpander
object.static FlexibleStringExpander
getInstance(java.lang.String expression, boolean useCache)
abstract java.lang.String
getOriginal()
Returns a copy of the original expression.protected static FlexibleStringExpander[]
getStrElems(char[] chars, int offset, int length)
abstract boolean
isEmpty()
Returnstrue
if the original expression is empty ornull
.java.lang.String
toString()
Returns a copy of the original expression.
-
-
-
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<org.apache.ofbiz.base.util.string.FlexibleStringExpander.Key,FlexibleStringExpander> exprCache
-
nullExpr
protected static final FlexibleStringExpander nullExpr
-
chars
protected final char[] chars
-
hint
protected int hint
-
-
Method Detail
-
containsConstant
public static boolean containsConstant(FlexibleStringExpander fse)
Returnstrue
iffse
contains aString
constant.- Parameters:
fse
- TheFlexibleStringExpander
to test- Returns:
true
iffse
contains aString
constant
-
containsExpression
public static boolean containsExpression(FlexibleStringExpander fse)
Returnstrue
iffse
contains an expression.- Parameters:
fse
- TheFlexibleStringExpander
to test- Returns:
true
iffse
contains an expression
-
containsScript
public static boolean containsScript(FlexibleStringExpander fse)
Returnstrue
iffse
contains a script.- Parameters:
fse
- TheFlexibleStringExpander
to test- Returns:
true
iffse
contains a script
-
expandString
public static java.lang.String expandString(java.lang.String expression, java.util.Map<java.lang.String,? extends java.lang.Object> context)
Evaluate an expression and return the result as aString
. Null expressions returnnull
. A nullcontext
argument will return the original expression.Note that the behavior of this method is not the same as using
FlexibleStringExpander.getInstance(expression).expandString(context)
because it returnsnull
when given a nullexpression
argument, andFlexibleStringExpander.getInstance(expression).expandString(context)
returns an emptyString
.- Parameters:
expression
- The original expressioncontext
- The evaluation context- Returns:
- The original expression's evaluation result as a
String
-
expandString
public static java.lang.String expandString(java.lang.String expression, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Locale locale)
Evaluate an expression and return the result as aString
. Null expressions returnnull
. A nullcontext
argument will return the original expression.Note that the behavior of this method is not the same as using
FlexibleStringExpander.getInstance(expression).expandString(context, locale)
because it returnsnull
when given a nullexpression
argument, andFlexibleStringExpander.getInstance(expression).expandString(context, locale)
returns an emptyString
.- Parameters:
expression
- The original expressioncontext
- The evaluation contextlocale
- The locale to be used for localization- Returns:
- The original expression's evaluation result as a
String
-
expandString
public static java.lang.String expandString(java.lang.String expression, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.TimeZone timeZone, java.util.Locale locale)
Evaluate an expression and return the result as aString
. Null expressions returnnull
. A nullcontext
argument will return the original expression.Note that the behavior of this method is not the same as using
FlexibleStringExpander.getInstance(expression).expandString(context, timeZone locale)
because it returnsnull
when given a nullexpression
argument, andFlexibleStringExpander.getInstance(expression).expandString(context, timeZone, locale)
returns an emptyString
.- Parameters:
expression
- The original expressioncontext
- The evaluation contexttimeZone
- The time zone to be used for localizationlocale
- The locale to be used for localization- Returns:
- The original expression's evaluation result as a
String
-
getInstance
public static FlexibleStringExpander getInstance(java.lang.String expression)
Returns aFlexibleStringExpander
object.A null or empty argument will return a
FlexibleStringExpander
object that represents an empty expression. That object is a shared singleton, so there is no memory or performance penalty in using it.If the method is passed a
String
argument that doesn't contain an expression, theFlexibleStringExpander
object that is returned does not perform any evaluations on the originalString
- any methods that return aString
will return the originalString
. The object returned by this method is very compact - taking less memory than the originalString
.- Parameters:
expression
- The original expression- Returns:
- A
FlexibleStringExpander
instance
-
getInstance
public static FlexibleStringExpander getInstance(java.lang.String expression, boolean useCache)
-
getStrElems
protected static FlexibleStringExpander[] getStrElems(char[] chars, int offset, int length)
-
get
protected abstract java.lang.Object get(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.TimeZone timeZone, java.util.Locale locale)
-
expandString
public java.lang.String expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context)
Evaluate this object's expression and return the result as aString
. Null or empty expressions return an emptyString
. Anull context
argument will return the original expression.- Parameters:
context
- The evaluation context- Returns:
- This object's expression result as a
String
-
expandString
public java.lang.String expandString(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Locale locale)
Evaluate this object's expression and return the result as aString
. Null or empty expressions return an emptyString
. Anull context
argument will return the original expression.- Parameters:
context
- The evaluation contextlocale
- The locale to be used for localization- Returns:
- This object's expression result as a
String
-
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)
Evaluate this object's expression and return the result as aString
. Null or empty expressions return an emptyString
. Anull context
argument will return the original expression.- Parameters:
context
- The evaluation contexttimeZone
- The time zone to be used for localizationlocale
- The locale to be used for localization- Returns:
- This object's expression result as a
String
-
expand
public java.lang.Object expand(java.util.Map<java.lang.String,? extends java.lang.Object> context)
Evaluate this object's expression and return the result as anObject
. Null or empty expressions return an emptyString
. Anull context
argument will return the original expression.- Parameters:
context
- The evaluation context- Returns:
- This object's expression result as a
String
-
expand
public java.lang.Object expand(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Locale locale)
Evaluate this object's expression and return the result as anObject
. Null or empty expressions return an emptyString
. Anull context
argument will return the original expression.- Parameters:
context
- The evaluation contextlocale
- The locale to be used for localization- Returns:
- This object's expression result as a
String
-
expand
public java.lang.Object expand(java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.TimeZone timeZone, java.util.Locale locale)
Evaluate this object's expression and return the result as anObject
. Null or empty expressions return an emptyString
. Anull context
argument will return the original expression.- Parameters:
context
- The evaluation contexttimeZone
- The time zone to be used for localizationlocale
- The locale to be used for localization- Returns:
- This object's expression result as a
String
-
getOriginal
public abstract java.lang.String getOriginal()
Returns a copy of the original expression.- Returns:
- The original expression
-
isEmpty
public abstract boolean isEmpty()
Returnstrue
if the original expression is empty ornull
.
-
toString
public java.lang.String toString()
Returns a copy of the original expression.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The original expression
-
-