public abstract class FlexibleStringExpander extends Object implements Serializable, IsEmpty
This class extends the UEL by allowing nested expressions.
Modifier and Type | Class and Description |
---|---|
protected static class |
FlexibleStringExpander.ArrayOffsetString |
protected static class |
FlexibleStringExpander.ConstOffsetElem
An object that represents a
String constant portion of an expression. |
protected static class |
FlexibleStringExpander.ConstSimpleElem
An object that represents a
String 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.
|
Modifier and Type | Field and Description |
---|---|
protected char[] |
chars |
static String |
closeBracket |
protected static UtilCache<org.apache.ofbiz.base.util.string.FlexibleStringExpander.Key,FlexibleStringExpander> |
exprCache |
protected int |
hint |
static String |
module |
protected static FlexibleStringExpander |
nullExpr |
static String |
openBracket |
Modifier | Constructor and Description |
---|---|
protected |
FlexibleStringExpander(char[] chars) |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsConstant(FlexibleStringExpander fse)
Returns
true if fse contains a String constant. |
static boolean |
containsExpression(FlexibleStringExpander fse)
Returns
true if fse contains an expression. |
static boolean |
containsScript(FlexibleStringExpander fse)
Returns
true if fse contains a script. |
Object |
expand(Map<String,? extends Object> context)
Evaluate this object's expression and return the result as an
Object . |
Object |
expand(Map<String,? extends Object> context,
Locale locale)
Evaluate this object's expression and return the result as an
Object . |
Object |
expand(Map<String,? extends Object> context,
TimeZone timeZone,
Locale locale)
Evaluate this object's expression and return the result as an
Object . |
String |
expandString(Map<String,? extends Object> context)
Evaluate this object's expression and return the result as a
String . |
String |
expandString(Map<String,? extends Object> context,
Locale locale)
Evaluate this object's expression and return the result as a
String . |
String |
expandString(Map<String,? extends Object> context,
TimeZone timeZone,
Locale locale)
Evaluate this object's expression and return the result as a
String . |
static String |
expandString(String expression,
Map<String,? extends Object> context)
Evaluate an expression and return the result as a
String . |
static String |
expandString(String expression,
Map<String,? extends Object> context,
Locale locale)
Evaluate an expression and return the result as a
String . |
static String |
expandString(String expression,
Map<String,? extends Object> context,
TimeZone timeZone,
Locale locale)
Evaluate an expression and return the result as a
String . |
protected abstract Object |
get(Map<String,? extends Object> context,
TimeZone timeZone,
Locale locale) |
static FlexibleStringExpander |
getInstance(String expression)
Returns a
FlexibleStringExpander object. |
static FlexibleStringExpander |
getInstance(String expression,
boolean useCache) |
abstract String |
getOriginal()
Returns a copy of the original expression.
|
protected static FlexibleStringExpander[] |
getStrElems(char[] chars,
int offset,
int length) |
abstract boolean |
isEmpty()
Returns
true if the original expression is empty
or null . |
String |
toString()
Returns a copy of the original expression.
|
public static final String module
public static final String openBracket
public static final String closeBracket
protected static final UtilCache<org.apache.ofbiz.base.util.string.FlexibleStringExpander.Key,FlexibleStringExpander> exprCache
protected static final FlexibleStringExpander nullExpr
protected final char[] chars
protected int hint
public static boolean containsConstant(FlexibleStringExpander fse)
true
if fse
contains a String
constant.fse
- The FlexibleStringExpander
to testtrue
if fse
contains a String
constantpublic static boolean containsExpression(FlexibleStringExpander fse)
true
if fse
contains an expression.fse
- The FlexibleStringExpander
to testtrue
if fse
contains an expressionpublic static boolean containsScript(FlexibleStringExpander fse)
true
if fse
contains a script.fse
- The FlexibleStringExpander
to testtrue
if fse
contains a scriptpublic static String expandString(String expression, Map<String,? extends Object> context)
String
.
Null expressions return null
.
A null context
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 returns null
when given a null expression
argument, and
FlexibleStringExpander.getInstance(expression).expandString(context)
returns an empty String
.
expression
- The original expressioncontext
- The evaluation contextString
public static String expandString(String expression, Map<String,? extends Object> context, Locale locale)
String
.
Null expressions return null
.
A null context
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 returns null
when given a null expression
argument, and
FlexibleStringExpander.getInstance(expression).expandString(context, locale)
returns an empty String
.
expression
- The original expressioncontext
- The evaluation contextlocale
- The locale to be used for localizationString
public static String expandString(String expression, Map<String,? extends Object> context, TimeZone timeZone, Locale locale)
String
.
Null expressions return null
.
A null context
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 returns null
when given a null expression
argument, and
FlexibleStringExpander.getInstance(expression).expandString(context, timeZone, locale)
returns an empty String
.
expression
- The original expressioncontext
- The evaluation contexttimeZone
- The time zone to be used for localizationlocale
- The locale to be used for localizationString
public static FlexibleStringExpander getInstance(String expression)
FlexibleStringExpander
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, the FlexibleStringExpander
object
that is returned does not perform any evaluations on the original
String
- any methods that return a String
will return the original String
. The object returned by
this method is very compact - taking less memory than the original
String
.
expression
- The original expressionFlexibleStringExpander
instancepublic static FlexibleStringExpander getInstance(String expression, boolean useCache)
protected static FlexibleStringExpander[] getStrElems(char[] chars, int offset, int length)
protected abstract Object get(Map<String,? extends Object> context, TimeZone timeZone, Locale locale)
public String expandString(Map<String,? extends Object> context)
String
.
Null or empty expressions return an empty String
.
A null context
argument will return the original expression.context
- The evaluation contextString
public String expandString(Map<String,? extends Object> context, Locale locale)
String
.
Null or empty expressions return an empty String
.
A null context
argument will return the original expression.context
- The evaluation contextlocale
- The locale to be used for localizationString
public String expandString(Map<String,? extends Object> context, TimeZone timeZone, Locale locale)
String
.
Null or empty expressions return an empty String
.
A null context
argument will return the original expression.context
- The evaluation contexttimeZone
- The time zone to be used for localizationlocale
- The locale to be used for localizationString
public Object expand(Map<String,? extends Object> context)
Object
.
Null or empty expressions return an empty String
.
A null context
argument will return the original expression.context
- The evaluation contextString
public Object expand(Map<String,? extends Object> context, Locale locale)
Object
.
Null or empty expressions return an empty String
.
A null context
argument will return the original expression.context
- The evaluation contextlocale
- The locale to be used for localizationString
public Object expand(Map<String,? extends Object> context, TimeZone timeZone, Locale locale)
Object
.
Null or empty expressions return an empty String
.
A null context
argument will return the original expression.context
- The evaluation contexttimeZone
- The time zone to be used for localizationlocale
- The locale to be used for localizationString
public abstract String getOriginal()
public abstract boolean isEmpty()
true
if the original expression is empty
or null
.