|
Copyright © 2000, 2008, Oracle and/or its affiliates. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.bea.content.expression.ExpressionHelper
public class ExpressionHelper
Helper class to handle dealing with content Expressions.
For details on what content expressions should look like, see
parse()
.
Nested Class Summary | |
---|---|
static class |
ExpressionHelper.ParseException
Exception to report an error while parsing a query expression. |
Field Summary | |
---|---|
static String |
AND
Syntax textual and logical operator. |
static String |
CONTAINS
Syntax textual contains operator. |
static String |
CONTAINS_ALL
Syntax textual contains all operator. |
static String |
CONTAINS_ANY
Syntax textual contains any operator. |
static String |
defDateFormatStr
The default datetime format string in the content expression syntax ("MM/dd/yyyy HH:mm:ss z"). |
static String |
EQUALS
Syntax textual equals operator. |
static String |
GREATER_THAN
Syntax textual greater than operator. |
static String |
GREATER_THAN_EQUALS
Syntax textual greater than or equals operator. |
static String |
IN
Syntax textual in operator. |
static String |
LESS_THAN
Syntax textual less than operator. |
static String |
LESS_THAN_EQUALS
Syntax textual less than or equals operator. |
static String |
LIKE
Syntax textual like operator. |
static String |
LIKE_IGNORE_CASE
Syntax textual like (case insensitive) operator. |
static String |
NOT_EQUALS
Syntax textual not equals operator. |
static String |
OR
Syntax textual or logical operator. |
Constructor Summary | |
---|---|
ExpressionHelper()
|
Method Summary | |
---|---|
static Expression |
convertContainsAnyOperators(Expression expr)
Convert an expression tree to not contain any 'containsany' comparison operators. |
static Expression |
convertInOperators(Expression expr)
Convert an expression tree to not contain any 'in' comparison operators. |
static String |
fromStringLiteral(String in)
Convert a String literal (which may contain quoted characters) into a corresponding String value. |
static String |
getComparator(Expression expr)
Get the syntax comparator textual operator for the given leaf node. |
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. |
static Search |
getContentIdSearch(String contentId)
Get a search object for a single content based upon the supplied id. |
static Search |
getContentPathSearch(ID uid,
String version)
Get a search object for a single version based upon the supplied UID and version. |
static Search |
getContentPathSearch(String contentPath)
Get a search object for a single content based upon the supplied path. |
static PropertyRef |
getLeftHandSide(Expression expr)
Get the left-hand-side of a valid leaf node, which should be a PropertyRef. |
static String |
getLogicalComparator(Expression expr)
Get the syntax logical comparator textual operator for the given branch node. |
static int |
getOrdinalValue(char ch)
Get the ordinal (Unicode) value of a character. |
static Object |
getRightHandSide(Expression expr)
Get the right-hand-side of a valid leaf node. |
static Expression |
getSubExpression(Expression expr,
int count)
Get a child expression of the specified expression at the count index. |
static boolean |
isHexString(String str)
Determine if a string contains only ASCII hexidecimal characters ([0-9a-fA-F]). |
static Expression |
isLogicalNot(Expression expr)
Tell if an expression is really a logical not and, if so, returns the contained expression. |
static boolean |
isValidBranchNode(Expression expr)
Tell if an expression is a valid content branch node type. |
static boolean |
isValidLeafNode(Expression expr)
Tell if an expression is a valid content leaf node type. |
static LogicalAnd |
join(Expression expr1,
Expression expr2)
Join together two expression via an AND expression. |
static Expression |
normalize(Expression expr)
Normalize an Expression. |
static Expression |
parse(String queryStr)
Convert a query expression string into an Expression object. |
static void |
print(PrintWriter out,
Expression expr)
Print a string representation of the given expression. |
static void |
printBranchNode(PrintWriter out,
Expression expr)
Return a string representation of the given expression branch. |
static void |
printLeafNode(PrintWriter out,
Expression expr)
Return a string representation of the given leaf expression node. |
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 SearchOps . |
static String |
retrievePathFromVersionPath(String path)
|
static String |
retrieveVersionFromVersionPath(String path)
|
static String |
toString(Expression expr)
Get a string representation of the given expression. |
static String |
toStringLiteral(String in)
Get an ASCII String literal from a Java string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String defDateFormatStr
public static final String EQUALS
public static final String NOT_EQUALS
public static final String GREATER_THAN
public static final String LESS_THAN
public static final String GREATER_THAN_EQUALS
public static final String LESS_THAN_EQUALS
public static final String LIKE
public static final String LIKE_IGNORE_CASE
public static final String CONTAINS
public static final String CONTAINS_ALL
public static final String CONTAINS_ANY
public static final String IN
public static final String AND
public static final String OR
Constructor Detail |
---|
public ExpressionHelper()
Method Detail |
---|
public static Expression parse(String queryStr) throws ExpressionHelper.ParseException, IllegalArgumentException
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. "cm_BinarySize <= 1234
").
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')
"properyset.name
" form or the
toProperty('propertyset', 'property')
"
The valid comparision operators are
=
(or ==
),
!=
,
<
,
>
,
<=
,
>=
,
"like
",
"likeignorecase
",
"contains
",
"containsall
"
"containsany
", and
"in
".
The "like
" and "likeignorecase
" operators
expect the pattern (which is the value of the leaf) to use
*
(match all) and ?
(match any);
"like
" and "likeignorecase
" also are only
expected to work against String values, although they might work with
other datatypes depending upon the search implementation.
"like
" does case sensitive matching;
"likeignorecase
" does case insensitive matching.
The "in
" operator expects the value to be a list.
Otherwise, it's equivalent to =
.
The "contains
" operator is only expected to work against
multi-valued properties, although it might work with other datatypes
depending upon the search implementation.
The "containsall
" and "containsany
" operators
are only expected to work against multi-valued properties, although
they might work with other datatypes depending upon the search
implementation. They expect the value to be a list.
Otherwise, they're equivalent to "contains
".
\u6565
"),
octal (e.g. "\7
", "\65
",
"\377
"), and standard Java escape sequences (e.g.
"\n
", "\r
", "\b
") are
allowed in the string literals.
true
" or
"false
" keyword (without quotes).
toDate(['formatStr'],
'dateStr')
"formatStr
must be a valid
SimpleDateFormat
format
string; if omitted, MM/dd/yyyy HH:mm:ss z
'now
" keyword specifies the time at
which the expression was created.
=
, !=
, "containsany
" or
"containsall
" against multi-valued property
in
" against single-valued property
<type>Property(<propertyset>, <propertyname>)
where<type>
is one of 'user', 'request', or 'session',<propertyset>
is the property set name and follows the rules for string literals.<propertyname>
is the property name and follows the rules for string literals.
References to properties should not be passed into theSearchOps
class. Expression which contain references to properties should be realized into a searchable expression via therealize()
method.
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 SearchOps
:
queryStr
- the query expression string
ExpressionHelper.ParseException
- thrown on a an invalid expression query or a
parser error.
IllegalArgumentException
- thrown on a general error.normalize(com.bea.p13n.expression.Expression)
public static LogicalAnd join(Expression expr1, Expression expr2)
expr1
- the first expression.expr2
- the second expression.
public static Search getContentIdSearch(String contentId)
public static Search getContentPathSearch(String contentPath)
public static Search getContentPathSearch(ID uid, String version)
public static String getContentId(Expression expr)
public static Expression normalize(Expression expr) throws IllegalArgumentException
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).
expr
- the incoming expression.
IllegalArgumentException
- thrown if the expression is not a
valid content expression.public static Expression convertInOperators(Expression expr) throws IllegalArgumentException
This will change all ContainedIn leafs into a MultiOr branch of
Equals leafs for each element of the ContainedIn right-hand-side list.
Or, in syntax terms,
"
" will become
"
".
expr
- the incoming expression.
prop in null
" or
"prop in ()
").
IllegalArgumentException
- if the expression structure isn't
valid.public static Expression convertContainsAnyOperators(Expression expr) throws IllegalArgumentException
This will change all CollectionContainsAny leafs into a MultiOr
branch of CollectionContains leafs for each element of the
CollectionContainsAny right-hand-side list.
Or, in syntax terms,
"
" will become
"
".
expr
- the incoming expression.
prop containsany null
"
or "prop containsany ()
").
IllegalArgumentException
- if the expression structure isn't
valid.public static Expression realize(Expression expr, PropertyProvider props) throws IllegalArgumentException
SearchOps
.
Or, in syntax terms,
if the user's "prop" property in the 'propset' Property Set is 'red',
"prop == userProperty('propset', 'prop')
"
will become "prop == 'red'
".
This will modify the passed in expression.
expr
- the expression to realize.props
- the object which provides values for property references.
IllegalArgumentException
- thrown if the expr is not a valid
content expression or contain a reference to an unknown
property type.public static Expression isLogicalNot(Expression expr)
expr
- the expression.
public static boolean isValidLeafNode(Expression expr)
public static boolean isValidBranchNode(Expression expr)
public static String toString(Expression expr) throws IllegalArgumentException
Pretty much, a string generated from this method can be parse()'ed into the semantically equivalent (not neccessarily identical) expression tree.
expr
- the expression.
IllegalArgumentException
- thrown if the given expression is not
a valid content expression.public static void print(PrintWriter out, Expression expr) throws IllegalArgumentException
Pretty much, a string generated from this method can be parse()'ed into the semantically equivalent (not neccessarily identical) expression tree.
out
- the output writer.expr
- the expression.
IllegalArgumentException
- thrown if the given expression is not
a valid content expression.public static void printLeafNode(PrintWriter out, Expression expr) throws IllegalArgumentException
out
- the output writer.expr
- the expression.
IllegalArgumentException
- thrown if the given expression is not
a valid leaf expression.public static PropertyRef getLeftHandSide(Expression expr) throws IllegalArgumentException
expr
- the leaf node expression.
IllegalArgumentException
- if the the left-hand-side is null or
not a PropertyRef.public static String getComparator(Expression expr) throws IllegalArgumentException
expr
- the leaf node expression.
EQUALS
,
NOT_EQUALS
, GREATER_THAN
, GREATER_THAN_EQUALS
,
LESS_THAN
, LESS_THAN_EQUALS
, LIKE
,
LIKE_IGNORE_CASE
, IN
, CONTAINS
,
CONTAINS_ALL
, or CONTAINS_ANY
or null if the
expression is null.
IllegalArgumentException
- if the expression is not a valid leaf
node.public static Object getRightHandSide(Expression expr) throws IllegalArgumentException
expr
- the leaf node expression.
RequestPropertyRef
, a SessionPropertyRef
, or a
UserPropertyRef
.
IllegalArgumentException
- if the expression is not a valid leaf
node.public static void printBranchNode(PrintWriter out, Expression expr)
out
- the output writer.expr
- the expression.
IllegalArgumentException
- thrown if the given expression is not
a valid branch node expression or one it's children is invalid.public static String getLogicalComparator(Expression expr) throws IllegalArgumentException
expr
- the expression.
AND
or OR
, or null if the expression is null.
IllegalArgumentException
- thrown if the given expression is not
a valid branch node expression.public static Expression getSubExpression(Expression expr, int count) throws IllegalArgumentException
expr
- the parent expression.count
- the index.
IllegalArgumentException
- if the child is not an Expression.public static String fromStringLiteral(String in)
This supports the standard Java Language Specification escape sequences.
In addition, this also supports escaping of wildcard characters '*' & '?' used by the expression helper
in
- the input string literal.
public static boolean isHexString(String str)
str
- the input string.
public static String toStringLiteral(String in)
This will quote some special characters with back-slashes.
The output of this can be sent through fromStringLiteral(java.lang.String)
to result in the original String.
public static int getOrdinalValue(char ch)
public static String retrieveVersionFromVersionPath(String path)
public static String retrievePathFromVersionPath(String path)
|
Copyright © 2000, 2008, Oracle and/or its affiliates. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |