net.sf.jett.util
Class AttributeUtil

java.lang.Object
  extended by net.sf.jett.util.AttributeUtil

public class AttributeUtil
extends java.lang.Object

The AttributeUtil utility class provides utility methods for evaluating Expressions that are expected to result in a specific type.

Since:
0.3.0
Author:
Randy Gettman

Field Summary
static java.lang.String SPEC_SEP
          Separates expressions in attributes that take multiple values.
static java.lang.String SPEC_SEP_2
          Separates expressions in attributes that take multiple values at a second level.
 
Constructor Summary
AttributeUtil()
           
 
Method Summary
static void ensureAtLeastOneExists(java.util.List<org.apache.poi.ss.usermodel.RichTextString> attrValues, java.util.List<java.lang.String> attrNames)
          Ensures that at least one of the given attribute values exists.
static void ensureAtMostOneExists(java.util.List<org.apache.poi.ss.usermodel.RichTextString> attrValues, java.util.List<java.lang.String> attrNames)
          Ensures that at most one of the given attribute values exists.
static void ensureExactlyOneExists(java.util.List<org.apache.poi.ss.usermodel.RichTextString> attrValues, java.util.List<java.lang.String> attrNames)
          Ensures that exactly one of the given attribute values exists.
static boolean evaluateBoolean(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, boolean def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a boolean value from the result, calling Boolean.parseBoolean() on the result if necessary.
static double evaluateDouble(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String attrName, double def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a double value from the result, calling toString() on the result and parsing it if necessary.
static int evaluateInt(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String attrName, int def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract an integer value from the result, calling toString() on the result and parsing it if necessary.
static java.util.List<java.lang.Integer> evaluateIntegerArray(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.util.List<java.lang.Integer> def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a List of Integers from the result, accepting an int array or a Collection or delimited list of numbers.
static java.util.List<java.util.List<java.lang.Integer>> evaluateIntegerArrayArray(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.util.List<java.util.List<java.lang.Integer>> def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a List of Lists of Integers from the result, accepting a 2D int array or a Collection of Collections or delimited list of numbers.
static java.util.List<java.lang.String> evaluateList(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.util.List<java.lang.String> def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a List out of the result, parsing a delimited list to create a list if necessary.
static int evaluateNonNegativeInt(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String attrName, int def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract an integer value from the result, calling toString() on the result and parsing it if necessary.
static int evaluateNonZeroInt(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String attrName, int def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract an integer value from the result, calling toString() on the result and parsing it if necessary.
static
<T> T
evaluateObject(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String attrName, java.lang.Class<T> expectedClass, T def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a result, and cast it to the same class as the given expected class.
static
<T> T
evaluateObject(java.lang.String text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String attrName, java.lang.Class<T> expectedClass, T def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a result, and cast it to the same class as the given expected class.
static int evaluatePositiveInt(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String attrName, int def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract an integer value from the result, calling toString() on the result and parsing it if necessary.
static java.lang.Object evaluateRichTextString(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.Object def)
          Evaluates the given RichTextString text, which may have embedded Expressions, and attempts to extract a RichTextString result.
static java.lang.String evaluateString(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a String result, calling toString() on the result.
static java.lang.String evaluateStringNotNull(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String attrName, java.lang.String def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a String result, calling toString() on the result.
static java.lang.String evaluateStringSpecificValues(org.apache.poi.ss.usermodel.RichTextString text, java.util.Map<java.lang.String,java.lang.Object> beans, java.lang.String attrName, java.util.List<java.lang.String> legalValues, java.lang.String def)
          Evaluates the given text, which may have embedded Expressions, and attempts to extract a String result, calling toString() on the result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPEC_SEP

public static final java.lang.String SPEC_SEP
Separates expressions in attributes that take multiple values. This was originally defined as the same value in multiple sub-classes, but was moved to BaseTag/AttributeUtil for 0.3.0.

Since:
0.3.0
See Also:
Constant Field Values

SPEC_SEP_2

public static final java.lang.String SPEC_SEP_2
Separates expressions in attributes that take multiple values at a second level. I.e. this is possible: "0,1;2,3" which would be interpreted as a 2D array: [[0, 1], [2, 3]].

Since:
0.4.0
See Also:
Constant Field Values
Constructor Detail

AttributeUtil

public AttributeUtil()
Method Detail

evaluateBoolean

public static boolean evaluateBoolean(org.apache.poi.ss.usermodel.RichTextString text,
                                      java.util.Map<java.lang.String,java.lang.Object> beans,
                                      boolean def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract a boolean value from the result, calling Boolean.parseBoolean() on the result if necessary. If the text is null, then the result defaults to the given default boolean value.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
def - The default value if the text is null.
Returns:
The boolean result.

evaluateInt

public static int evaluateInt(org.apache.poi.ss.usermodel.RichTextString text,
                              java.util.Map<java.lang.String,java.lang.Object> beans,
                              java.lang.String attrName,
                              int def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract an integer value from the result, calling toString() on the result and parsing it if necessary. If the text is null, then the result defaults to the given default integer value.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
attrName - The attribute name. This is only used when constructing an exception message.
def - The default value if the text is null.
Returns:
The integer result.
Throws:
TagParseException - If the result of the evaluation of the text is not a number.

evaluateNonNegativeInt

public static int evaluateNonNegativeInt(org.apache.poi.ss.usermodel.RichTextString text,
                                         java.util.Map<java.lang.String,java.lang.Object> beans,
                                         java.lang.String attrName,
                                         int def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract an integer value from the result, calling toString() on the result and parsing it if necessary. Enforce the result to be non-negative.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
attrName - The attribute name. This is only used when constructing an exception message.
def - The default value if the text is null.
Returns:
The integer result.
Throws:
TagParseException - If the result of the evaluation of the text is not a number, or if the result is negative.

evaluatePositiveInt

public static int evaluatePositiveInt(org.apache.poi.ss.usermodel.RichTextString text,
                                      java.util.Map<java.lang.String,java.lang.Object> beans,
                                      java.lang.String attrName,
                                      int def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract an integer value from the result, calling toString() on the result and parsing it if necessary. Enforce the result to be positive.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
attrName - The attribute name. This is only used when constructing an exception message.
def - The default value if the text is null.
Returns:
The integer result.
Throws:
TagParseException - If the result of the evaluation of the text is not a number, or if the result is negative.

evaluateNonZeroInt

public static int evaluateNonZeroInt(org.apache.poi.ss.usermodel.RichTextString text,
                                     java.util.Map<java.lang.String,java.lang.Object> beans,
                                     java.lang.String attrName,
                                     int def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract an integer value from the result, calling toString() on the result and parsing it if necessary. Enforce the result to be not zero.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
attrName - The attribute name. This is only used when constructing an exception message.
def - The default value if the text is null.
Returns:
The integer result.
Throws:
TagParseException - If the result of the evaluation of the text is not a number, or if the result is zero.

evaluateDouble

public static double evaluateDouble(org.apache.poi.ss.usermodel.RichTextString text,
                                    java.util.Map<java.lang.String,java.lang.Object> beans,
                                    java.lang.String attrName,
                                    double def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract a double value from the result, calling toString() on the result and parsing it if necessary.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
attrName - The attribute name. This is only used when constructing an exception message.
def - The default value if the text is null.
Returns:
The double result.
Throws:
TagParseException - If the result of the evaluation of the text is not a number.

evaluateString

public static java.lang.String evaluateString(org.apache.poi.ss.usermodel.RichTextString text,
                                              java.util.Map<java.lang.String,java.lang.Object> beans,
                                              java.lang.String def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract a String result, calling toString() on the result.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
def - The default value if the text is null.
Returns:
The String result.

evaluateStringNotNull

public static java.lang.String evaluateStringNotNull(org.apache.poi.ss.usermodel.RichTextString text,
                                                     java.util.Map<java.lang.String,java.lang.Object> beans,
                                                     java.lang.String attrName,
                                                     java.lang.String def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract a String result, calling toString() on the result.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
attrName - The attribute name. This is only used when constructing an exception message.
def - The default value if the text is null.
Returns:
The String result.

evaluateStringSpecificValues

public static java.lang.String evaluateStringSpecificValues(org.apache.poi.ss.usermodel.RichTextString text,
                                                            java.util.Map<java.lang.String,java.lang.Object> beans,
                                                            java.lang.String attrName,
                                                            java.util.List<java.lang.String> legalValues,
                                                            java.lang.String def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract a String result, calling toString() on the result. Enforces that the result is one of the given expected values, ignoring case.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
attrName - The attribute name. This is only used when constructing an exception message.
legalValues - A List of expected values.
def - The default value if the text is null.
Returns:
The String result.
Throws:
TagParseException - If the result isn't one of the expected legal values.

evaluateRichTextString

public static java.lang.Object evaluateRichTextString(org.apache.poi.ss.usermodel.RichTextString text,
                                                      java.util.Map<java.lang.String,java.lang.Object> beans,
                                                      org.apache.poi.ss.usermodel.CreationHelper helper,
                                                      java.lang.Object def)
Evaluates the given RichTextString text, which may have embedded Expressions, and attempts to extract a RichTextString result.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
helper - A POI CreationHelper
def - The default value if the text is null.
Returns:
The result.

evaluateObject

public static <T> T evaluateObject(org.apache.poi.ss.usermodel.RichTextString text,
                                   java.util.Map<java.lang.String,java.lang.Object> beans,
                                   java.lang.String attrName,
                                   java.lang.Class<T> expectedClass,
                                   T def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract a result, and cast it to the same class as the given expected class.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
attrName - The attribute name. This is only used when constructing an exception message.
expectedClass - The result is expected to be of the given class or of a subclass.
def - The default value if the text is null.
Returns:
The result.
Throws:
TagParseException - If the result is not of the expected class or of a subclass.

evaluateObject

public static <T> T evaluateObject(java.lang.String text,
                                   java.util.Map<java.lang.String,java.lang.Object> beans,
                                   java.lang.String attrName,
                                   java.lang.Class<T> expectedClass,
                                   T def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract a result, and cast it to the same class as the given expected class.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
attrName - The attribute name. This is only used when constructing an exception message.
expectedClass - The result is expected to be of the given class or of a subclass.
def - The default value if the text is null.
Returns:
The result.
Throws:
TagParseException - If the result is not of the expected class or of a subclass.

evaluateList

public static java.util.List<java.lang.String> evaluateList(org.apache.poi.ss.usermodel.RichTextString text,
                                                            java.util.Map<java.lang.String,java.lang.Object> beans,
                                                            java.util.List<java.lang.String> def)
Evaluates the given text, which may have embedded Expressions, and attempts to extract a List out of the result, parsing a delimited list to create a list if necessary.

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
def - The default value if the text is null.
Returns:
A List.

evaluateIntegerArray

public static java.util.List<java.lang.Integer> evaluateIntegerArray(org.apache.poi.ss.usermodel.RichTextString text,
                                                                     java.util.Map<java.lang.String,java.lang.Object> beans,
                                                                     java.util.List<java.lang.Integer> def)

Evaluates the given text, which may have embedded Expressions, and attempts to extract a List of Integers from the result, accepting an int array or a Collection or delimited list of numbers.

Examples of proper input:

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
def - The default value if the text is null.
Returns:
A List of Integers.

evaluateIntegerArrayArray

public static java.util.List<java.util.List<java.lang.Integer>> evaluateIntegerArrayArray(org.apache.poi.ss.usermodel.RichTextString text,
                                                                                          java.util.Map<java.lang.String,java.lang.Object> beans,
                                                                                          java.util.List<java.util.List<java.lang.Integer>> def)

Evaluates the given text, which may have embedded Expressions, and attempts to extract a List of Lists of Integers from the result, accepting a 2D int array or a Collection of Collections or delimited list of numbers.

Examples of proper input:

  • [[0, 1], [2]]
  • (ArrayList){(ArrayList){0, 1}, (ArrayList){2}}
  • "0, 1; 2"

Parameters:
text - Text which may have embedded Expressions.
beans - A Map of bean names to bean values.
def - The default value if the text is null.
Returns:
A List of Lists of Integers.

ensureExactlyOneExists

public static void ensureExactlyOneExists(java.util.List<org.apache.poi.ss.usermodel.RichTextString> attrValues,
                                          java.util.List<java.lang.String> attrNames)
Ensures that exactly one of the given attribute values exists.

Parameters:
attrValues - A List of attribute values.
attrNames - A List of attribute names.
Throws:
TagParseException - If none of the attribute values is not null, or if more than one attribute value is not null.

ensureAtMostOneExists

public static void ensureAtMostOneExists(java.util.List<org.apache.poi.ss.usermodel.RichTextString> attrValues,
                                         java.util.List<java.lang.String> attrNames)
Ensures that at most one of the given attribute values exists.

Parameters:
attrValues - A List of attribute values.
attrNames - A List of attribute names.
Throws:
TagParseException - If more than one of the attribute values is not null.
Since:
0.4.0

ensureAtLeastOneExists

public static void ensureAtLeastOneExists(java.util.List<org.apache.poi.ss.usermodel.RichTextString> attrValues,
                                          java.util.List<java.lang.String> attrNames)
Ensures that at least one of the given attribute values exists.

Parameters:
attrValues - A List of attribute values.
attrNames - A List of attribute names.
Throws:
TagParseException - If all of the attribute values are null.
Since:
0.4.0


Copyright © 2012-2013 Jett Team. All Rights Reserved.