Class XPathExpressionHelper
A table record XPath expression is of the form: /root/table[./field='a']
, where
/root/table
is the table path and ./field='a'
the optional predicate.
- Since:
- 5.4.1
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
buildXPath
(Path aTablePath, XPathFilter anXPathFilter) Builds an XPath expression given a table path and an optional XPath filter.static String
buildXPath
(Path aTablePath, String aPredicate) Builds an XPath expression given a table path and an optional predicate expression.static AdaptationFilter
createAdaptationFilterForXPath
(String anXPath, SchemaNode aTable, Locale aLocale) Creates a new filter, given a table and an XPath expression.static Request
createRequestForXPath
(Adaptation aDataSet, String anXPath) Creates a new request given a dataset and an XPath expression.static String
encodeLiteralStringWithDelimiters
(String aLiteralExpression) Encodes a valid string literal with its delimiters to be used in an XPath predicate.static String
getPredicateForXPath
(String anXPath) Returns the predicate expression from an XPath expression,null
if the expression does not specify a predicate.static Path
getTablePathForXPath
(String anXPath) Returns the table path expression based on the specified XPath expression.static XPathFilter
getXPathFilterForXPath
(boolean isCached, String anXPath) Returns an XPath filter from an XPath expression,null
if the expression does not specify a predicate.static Adaptation
lookupFirstRecordMatchingXPath
(boolean checkActualPrimaryKey, Adaptation aDataSet, String anXPath) Returns the first record that matches the specified XPath predicate,null
if no such record exists.static Adaptation
lookupFirstRecordMatchingXPath
(boolean checkActualPrimaryKey, Adaptation aDataSet, String anXPath, boolean includeOcculting) Returns a record based on the specified dataset and XPath expression,null
if no such record exists.static Adaptation
lookupFirstRecordMatchingXPath
(Adaptation aDataSet, String anXPath) Returns the first record that matches the specified XPath predicate,null
if no such record exists.
-
Constructor Details
-
XPathExpressionHelper
public XPathExpressionHelper()
-
-
Method Details
-
buildXPath
Builds an XPath expression given a table path and an optional predicate expression. For example, for a table path such as/root/table
and a predicate./field='a'
, this method would return/root/table[./field='a']
.- Throws:
IllegalArgumentException
- if one of the specified arguments is not defined.- See Also:
-
buildXPath
Builds an XPath expression given a table path and an optional XPath filter. For example, for a table path such as/root/table
and an XPath filter having as predicate expression./field='a'
, this method would return/root/table[./field='a']
.- Throws:
IllegalArgumentException
- if one of the specified arguments is not defined.- Since:
- 5.7.0
- See Also:
-
getPredicateForXPath
Returns the predicate expression from an XPath expression,null
if the expression does not specify a predicate.For example, for the XPath expression
/root/table[./field='a']
, this method would return./field='a'
.- Throws:
IllegalArgumentException
- if the specified path is not defined.MalformedXPathExpressionException
- if the specified path is not syntactically correct.- See Also:
-
getXPathFilterForXPath
public static XPathFilter getXPathFilterForXPath(boolean isCached, String anXPath) throws MalformedXPathExpressionException Returns an XPath filter from an XPath expression,null
if the expression does not specify a predicate.For example, for the XPath expression
/root/table[./field='a']
, this method would return an XPath filter that has as predicate expression./field='a'
.- Parameters:
isCached
- Iftrue
, the filter is cached in order to be reused when the same predicate expression is applied. Iffalse
, the filter is not cached and thus it cannot be reused.anXPath
- the XPath expression.- Throws:
IllegalArgumentException
- if the specified path is not defined.MalformedXPathExpressionException
- if the specified path is not syntactically correct.- Since:
- 5.7.0
- See Also:
-
getTablePathForXPath
Returns the table path expression based on the specified XPath expression.For example, for the XPath expression
/root/table[./field='a']
, this method returns/root/table
.- Throws:
IllegalArgumentException
- if the specified path is not defined.MalformedXPathExpressionException
- if the specified XPath expression is not syntactically correct.- See Also:
-
createRequestForXPath
public static Request createRequestForXPath(Adaptation aDataSet, String anXPath) throws MalformedXPathExpressionException, PathAccessException Creates a new request given a dataset and an XPath expression.- Throws:
IllegalArgumentException
- if one of the specified arguments is not defined.IllegalArgumentException
- if the specifiedAdaptation
is not a dataset.MalformedXPathExpressionException
- if the specified XPath expression is not syntactically correct.PathAccessException
- if the extracted table path expression does not refer to an existing table node in the underlying structure.- See Also:
-
createAdaptationFilterForXPath
public static AdaptationFilter createAdaptationFilterForXPath(String anXPath, SchemaNode aTable, Locale aLocale) Creates a new filter, given a table and an XPath expression.- Throws:
IllegalArgumentException
- if one of the specified arguments is not defined.IllegalArgumentException
- if the specifiedSchemaNode
is not a table.MalformedXPathExpressionException
- if the specified XPath expression is not syntactically correct.PathAccessException
- if the extracted table path expression does not refer to an existing table node in the underlying structure.- Since:
- 6.0.0
-
lookupFirstRecordMatchingXPath
Returns the first record that matches the specified XPath predicate,null
if no such record exists.This method is equivalent to:
AdaptationTable.lookupFirstRecordMatchingXPath( false, aDataSet, anXPath, false);
- Since:
- 5.4.3
- See Also:
-
lookupFirstRecordMatchingXPath
public static Adaptation lookupFirstRecordMatchingXPath(boolean checkActualPrimaryKey, Adaptation aDataSet, String anXPath) Returns the first record that matches the specified XPath predicate,null
if no such record exists.This method is equivalent to:
AdaptationTable.lookupFirstRecordMatchingXPath( checkActualPrimaryKey, aDataSet, anXPath, false);
- Since:
- 5.4.3
- See Also:
-
lookupFirstRecordMatchingXPath
public static Adaptation lookupFirstRecordMatchingXPath(boolean checkActualPrimaryKey, Adaptation aDataSet, String anXPath, boolean includeOcculting) throws MalformedXPathExpressionException, PathAccessException Returns a record based on the specified dataset and XPath expression,null
if no such record exists.For example, for the XPath expression
/root/table[./name='Smith']
, this method would return the first record (in primary key order) with its field 'name' equal to "Smith", ornull
if none exists.If the argument
checkActualPrimaryKey
istrue
, the predicate must specify the value of each primary key field. Using this type of predicate allows for a much faster resolution.- Throws:
IllegalArgumentException
- if one of the specified arguments is not defined.IllegalArgumentException
- if the specifiedAdaptation
is not a dataset.IllegalArgumentException
- ifcheckActualPrimaryKey
istrue
and the specified XPath expression argument is not a primary key expression.MalformedXPathExpressionException
- if the specified XPath expression is not syntactically correct.PathAccessException
- if the extracted table path expression does not reference an existing table node in the underlying structure.- Since:
- 5.4.3
- See Also:
-
- Supported XPath syntax
TblTable.lookupFirstRecordMatchingPredicate(boolean, String, boolean)
-
encodeLiteralStringWithDelimiters
Encodes a valid string literal with its delimiters to be used in an XPath predicate. This method must be used when building an XPath predicate, if there is a chance that a string contains single or double quote characters. For example:... String predicate = "./lastName=" + XPathExpressionHelper.encodeLiteralStringWithDelimiters(aLastName); request.setXPathFilter(predicate); ...
By default, the literal expression is delimited by single quotes (
'
). If the literal expression contains single quotes and no double quotes, it will be delimited by double quotes ("
). If the literal expression contains both single and double quotes, any single quotes within will be doubled.Examples:
Value of aLiteralExpression
Result of this method Coeur
'Coeur'
Coeur d'Alene
"Coeur d'Alene"
He said: "They live in Coeur d'Alene".
'He said: "They live in Coeur d''Alene".'
- See Also:
-