ExpressionHelper Class

DEPRECATED

com.bea.p13n.content.expression
ExpressionHelper Class

public class ExpressionHelper

    extends Object

Helper class to handle dealing with content Expressions.

For details on what content expression should look like, see ExpressionHelper.parse(String).


Hierarchy
Object
  ExpressionHelper

Nested Class Summary

public static classcom.bea.p13n.content.expression.ExpressionHelper.ParseException
           Exception to report an error while parsing a query expression.

Field Summary

public static final String
AND
Syntax textual and logical operator.
public static final String
CONTAINS
Syntax textual contains operator.
public static final String
CONTAINS_ALL
Syntax textual contains all operator.
public static final DateFormat
defDateFormat
The default date formatter.
public static final String
defDateFormatStr
The default datetime format string in the content expression syntax ("MM/dd/yyyy HH:mm:ss z").
public static final String
EQUALS
Syntax textual equals operator.
public static final String
GREATER_THAN
Syntax textual greater than operator.
public static final String
GREATER_THAN_EQUALS
Syntax textual greater than or equals operator.
public static final String
LESS_THAN
Syntax textual less than operator.
public static final String
LESS_THAN_EQUALS
Syntax textual less than or equals operator.
public static final String
LIKE
Syntax textual like operator.
public static final String
LIKE_IGNORECASE
Syntax textual case-insensitive like operator.
public static final String
NOT_EQUALS
Syntax textual not equals operator.
public static final String
OR
Syntax textual or logical operator.
 

Constructor Summary

ExpressionHelper()

 

Method Summary

public static ExpressionHelper.ParseException
convertException(Exception excep)
Convert a generic exception into a ParseException.
public static String
fromStringLiteral(String in)
Convert a String literal (which may contain quoted characters) into a corresponding String value.
public static String
getComparator(Expression expr)
Get the syntax comparator textual operator for the given leaf node.
public static String
getContentId(Expression expr)
Return the content id from the expression, if it's an expression for a single content object based upon identifier.
public static Search
getContentIdSearch(String contentId)
Get a search object for a single content based upon the supplied id.
public static Search
getContentNameSearch(String name)
Get a search object for a single content based upon the name/path.
public static PropertyRef
getLeftHandSide(Expression expr)
Get the left-hand-side of a valid leaf node, which should be a PropertyRef
public static String
getLogicalComparator(Expression expr)
Get the syntax logical comparator textual operator for the given branch node.
public static int
getOrdinalValue(char ch)
Get the ordinal (Unicode) value of a character.
public static Object
getRightHandSide(Expression expr)
Get the right-hand-side of a valid leaf node.
public static Expression
getSubExpression(Expression expr, int count)
public static boolean
isHexString(String str)
Determine if a string contains only ASCII hexidecimal characters ([0-9a-fA-F]).
public static Expression
isLogicalNot(Expression expr)
Tell if an expression is really a logical not and, if so, returned the contained expression.
public static boolean
isValidBranchNode(Expression expr)
Tell if an expression is a valid content branch node type.
public static boolean
isValidLeafNode(Expression expr)
Tell if an expression is a valid content leaf node type.
public static LogicalAnd
join(Expression expr1, Expression expr2)
Join together two expression via an AND expression.
public static Expression
normalize(Expression expr)
Normalize an Expression.
public static Expression
parse(String queryStr)
Convert a query expression string into an Expression object.
public static void
print(PrintWriter out, Expression expr)
Print a string representation of the given expression.
public static void
printBranchNode(PrintWriter out, Expression expr)
Return a string representation of the given expression branch.
public static void
printLeafNode(PrintWriter out, Expression expr)
Return a string representation of the given leaf expression node.
public static void
printTree(PrintWriter out, Expression expr)
For debug purposes, print the given expression as a tree.
public static void
printTree(int depth, PrintWriter out, Expression expr)
For debug purposes, print the given expression as a tree at the given depth.
public static Expression
realize(Expression expr, PropertyProvider props)
Realize an expression, which can contain property references, into an an expression which contains only literal values and can be sent to a ContentManager.
public static String
toString(Expression expr)
Get a string representation of the given expression.
public static String
toStringLiteral(String in)
Get an ASCII String literal from a Java string.
public static String
toTree(Expression expr)
For debug purposes, return a tree representation of the given expression.
 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
   

Field Detail

AND

public static final String AND
Syntax textual and logical operator.


CONTAINS

public static final String CONTAINS
Syntax textual contains operator.


CONTAINS_ALL

public static final String CONTAINS_ALL
Syntax textual contains all operator.


defDateFormat

public static final DateFormat defDateFormat
The default date formatter.


defDateFormatStr

public static final String defDateFormatStr
The default datetime format string in the content expression syntax ("MM/dd/yyyy HH:mm:ss z").


EQUALS

public static final String EQUALS
Syntax textual equals operator.


GREATER_THAN

public static final String GREATER_THAN
Syntax textual greater than operator.


GREATER_THAN_EQUALS

public static final String GREATER_THAN_EQUALS
Syntax textual greater than or equals operator.


LESS_THAN

public static final String LESS_THAN
Syntax textual less than operator.


LESS_THAN_EQUALS

public static final String LESS_THAN_EQUALS
Syntax textual less than or equals operator.


LIKE

public static final String LIKE
Syntax textual like operator.


LIKE_IGNORECASE

public static final String LIKE_IGNORECASE
Syntax textual case-insensitive like operator.


NOT_EQUALS

public static final String NOT_EQUALS
Syntax textual not equals operator.


OR

public static final String OR
Syntax textual or logical operator.

 

Constructor Detail

ExpressionHelper

public ExpressionHelper()
 

Method Detail

convertException(Exception) Method

public static ExpressionHelper.ParseException convertException(Exception excep)
Convert a generic exception into a ParseException.


fromStringLiteral(String) Method

public static String fromStringLiteral(String in)
Convert a String literal (which may contain quoted characters) into a corresponding String value.

This supports the standard Java Language Specification escape sequences.

Parameters

in
the input string literal.

Returns

the string value.

getComparator(Expression) Method

public static String getComparator(Expression expr)
throws IllegalArgumentException
Get the syntax comparator textual operator for the given leaf node.

Exceptions

IllegalArgumentException

getContentId(Expression) Method

public static String getContentId(Expression expr)
Return the content id from the expression, if it's an expression for a single content object based upon identifier.

Returns

the content id, or null if it's not a identifier equality expression.

getContentIdSearch(String) Method

public static Search getContentIdSearch(String contentId)
Get a search object for a single content based upon the supplied id.


getContentNameSearch(String) Method

public static Search getContentNameSearch(String name)
Get a search object for a single content based upon the name/path.


getLeftHandSide(Expression) Method

public static PropertyRef getLeftHandSide(Expression expr)
throws IllegalArgumentException
Get the left-hand-side of a valid leaf node, which should be a PropertyRef

Exceptions

IllegalArgumentException

getLogicalComparator(Expression) Method

public static String getLogicalComparator(Expression expr)
throws IllegalArgumentException
Get the syntax logical comparator textual operator for the given branch node.

Exceptions

IllegalArgumentException

getOrdinalValue(char) Method

public static int getOrdinalValue(char ch)
Get the ordinal (Unicode) value of a character.


getRightHandSide(Expression) Method

public static Object getRightHandSide(Expression expr)
throws IllegalArgumentException
Get the right-hand-side of a valid leaf node.

Exceptions

IllegalArgumentException

getSubExpression(Expression, int) Method

public static Expression getSubExpression(Expression expr, 
                                          int count)
throws IllegalArgumentException

Exceptions

IllegalArgumentException

isHexString(String) Method

public static boolean isHexString(String str)
Determine if a string contains only ASCII hexidecimal characters ([0-9a-fA-F]).


isLogicalNot(Expression) Method

public static Expression isLogicalNot(Expression expr)
Tell if an expression is really a logical not and, if so, returned the contained expression.

Parameters

expr
the expression.

Returns

the contained expressions if expr is a logical not, null otherwise.

isValidBranchNode(Expression) Method

public static boolean isValidBranchNode(Expression expr)
Tell if an expression is a valid content branch node type.


isValidLeafNode(Expression) Method

public static boolean isValidLeafNode(Expression expr)
Tell if an expression is a valid content leaf node type.


join(Expression, Expression) Method

public static LogicalAnd join(Expression expr1, 
                              Expression expr2)
Join together two expression via an AND expression.

Parameters

expr1
the first expression.
expr2
the second expression.

Returns

a LogicalAnd of the two expressions.

normalize(Expression) Method

public static Expression normalize(Expression expr)
throws IllegalArgumentException
Normalize an Expression.

This will recursively remove branches that contain only one Expression (which are boolean equivelant to the one child expression) or that contain no children (which are considered empty).

Parameters

expr
the incoming expression.

Returns

the normalized expression, null if normalized to nothing.

Exceptions

IllegalArgumentException
thrown if the expression is not a valid content expression.

parse(String) Method

public static Expression parse(String queryStr)
throws ExpressionHelper.ParseException, IllegalArgumentException
Convert a query expression string into an Expression object.

The string should follow the query syntax specified in the Personalization Server documentation. The expression syntax is tree-based, with each leaf in the tree beinging of the form "property comparator value" (e.g. "identifier == '1234'").

Property (LHS)

This specifies the object property to match against. To specify a property name which contains non-identifier characters (e.g. whitespace, double quotes, dashes), you can use the "toProperty('property name')" form in the left-hand-side. To specify property set names as part of the property name, either use the "properyset.name" form or the "toProperty('propertyset', 'property')" form in the left-hand-side.

Comparators

The valid comparision operators are = (or ==), !=, <, >, <=, >=, "like", "likeignorecase" and "contains". The "like" and "likeignorecase" operator expects the pattern (which is the value of the leaf) to use * (match all) and ? (match any); "like" and "likeignorecase" also is only expected to work against String values, although it might work with other datatypes depending upon the search implementation. "like" operator does case-sensitive pattern match, while "likeignorecase" operator does case- insensitive pattern match. The "contains" operator is only expected to work against multi-valued properties, although it might work with other datatypes depending upon the search implementation.

Value (RHS)

Each branch in the tree is comprised of 1 or more leafs or branches separated by either "&&" (boolean AND) or "||" (boolean OR). They can be enclosed in parenthesis for clearity and ordering (AND has precendance over OR). Additionally, "!" marks a branch as using negative logic (boolean NOT). The "!" operator can only be used preceding an open parenthesis.

Examples of valid expression strings:

In the resulting expression tree, the following caveats apply for it to be valid for the ContentManager:

Parameters

queryStr
the query expression string

Returns

an Expression object representing (null if queryStr is a null expression).

Exceptions

ExpressionHelper.ParseException
IllegalArgumentException
thrown on a general error.

Related Topics

ExpressionHelper.convertException(Exception)
ExpressionHelper.normalize(Expression)


print(PrintWriter, Expression) Method

public static void print(PrintWriter out, 
                         Expression expr)
throws IllegalArgumentException
Print a string representation of the given expression.

Pretty much, a string generated from this method can be parse()'ed into the equivalent (not neccessarily identical) expression tree.

Parameters

out
the output writer.
expr
the expression.

Exceptions

IllegalArgumentException
thrown if the given expression is not a valid content expression.

printBranchNode(PrintWriter, Expression) Method

public static void printBranchNode(PrintWriter out, 
                                   Expression expr)
Return a string representation of the given expression branch.


printLeafNode(PrintWriter, Expression) Method

public static void printLeafNode(PrintWriter out, 
                                 Expression expr)
throws IllegalArgumentException
Return a string representation of the given leaf expression node.

Exceptions

IllegalArgumentException

printTree(PrintWriter, Expression) Method

public static void printTree(PrintWriter out, 
                             Expression expr)
For debug purposes, print the given expression as a tree.

Parameters

out
the output stream to print on.
expr
the expression.

printTree(int, PrintWriter, Expression) Method

public static void printTree(int depth, 
                             PrintWriter out, 
                             Expression expr)
For debug purposes, print the given expression as a tree at the given depth.

Parameters

depth
the depth of this expression in the tree.
out
the output stream to print on.
expr
the expression.

realize(Expression, PropertyProvider) Method

public static Expression realize(Expression expr, 
                                 PropertyProvider props)
throws IllegalArgumentException
Realize an expression, which can contain property references, into an an expression which contains only literal values and can be sent to a ContentManager.

This will modify the passed in expression.

Parameters

expr
the expression to realize.
props
the object which provides values for property references.

Returns

the modified expression

Exceptions

IllegalArgumentException
thrown if the expr is not a valid content expression or contain a reference to an unknown property type.

toString(Expression) Method

public static String toString(Expression expr)
throws IllegalArgumentException
Get a string representation of the given expression.

Pretty much, a string generated from this method can be parse()'ed into the equivalent (not neccessarily identical) expression tree.

Parameters

expr
the expression.

Returns

the query syntax representation of the expression.

Exceptions

IllegalArgumentException
thrown if the given expression is not a valid content expression.

toStringLiteral(String) Method

public static String toStringLiteral(String in)
Get an ASCII String literal from a Java string.

This will quote some special characters with back-slashes.

The output of this can be sent through ExpressionHelper.fromStringLiteral(String) to result in the original String.


toTree(Expression) Method

public static String toTree(Expression expr)
For debug purposes, return a tree representation of the given expression.