ExpressionHelper Class

DEPRECATED Use com.bea.p13n.content.expression.ExpressionHelper instead.

com.beasys.commerce.util
ExpressionHelper Class

public class ExpressionHelper

    extends Object

Helper class to handle dealing with Expression, Criteria, and Logical objects.

Related Topics

Expression
Criteria
Logical


Hierarchy
Object
  ExpressionHelper

Nested Class Summary

public static classcom.beasys.commerce.util.ExpressionHelper.ParseException
           Exception to report an error while parsing a query expression.

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 int
getOrdinalValue(char ch)
Get the ordinal (Unicode) value of a character.
public static boolean
isHexString(String str)
Determine is a string contains only ASCII hexidecimal characters ([0-9a-fA-F]).
public static Logical
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
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 String
toString(Expression expr)
Get a string representation of the given expression.
public static String
toString(Criteria c)
Return a string representation of the given criteria.
public static String
toString(Logical l)
Return a string representation of the given Logical.
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
   

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.

getOrdinalValue(char) Method

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


isHexString(String) Method

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


join(Expression, Expression) Method

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

Parameters

expr1
the first expression.
expr2
the second expression.

Returns

a Logical of the two expressions.

normalize(Expression) Method

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

This will remove:

Parameters

expr
the incoming expression.

Returns

the normalized expression, null if normalized to nothing.

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 scopenames as part of the property name, either use the "scope.name" form or the "toProperty('scope', 'property')" form in the left-hand-side.

Comparators

The valid comparision operators are = (or ==), !=, <, >, <=, >=, "like", and "contains". The "like" operator expects the pattern (which is the value of the leaf) to use * (match all) and ? (match any); "like" also is only expected to work against String values, although it might work with other datatypes depending upon the search implementation. 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 logical (boolean NOT). The "!" operator can only be used preceding an open parenthesis.

Examples of valid expression strings:

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)


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.

toString(Expression) Method

public static String toString(Expression expr)
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.

toString(Criteria) Method

public static String toString(Criteria c)
Return a string representation of the given criteria.


toString(Logical) Method

public static String toString(Logical l)
Return a string representation of the given Logical.


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.