Package org.dlese.dpc.xml
Class XPathUtils
java.lang.Object
org.dlese.dpc.xml.XPathUtils
Utilities for testing and manipulating XPaths, represented as String.
- Author:
- ostwald
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intCompares two xpaths for "xpath order", using "natuiral" or alphabetical ordering except for when xpath indexing is involved, e.g., "/record/general[3]/foo[5]" is "less than" "/record/general[4]/foo[6]".static StringdecodeXPath(String path) Converts encoded paths of the form used in jsp pages ( "foo_1_") to a XPath form ("foo[1]").static StringConverts indexed paths of the form ("foo[1]") to the form used in jsp pages ( "foo_1_")static intReturns the index, if any, for the leaf of the given path.static StringReturns the name of the element refered to by the given xpath, which is the leaf, stripped of "\@" in the case of attribute paths).static StringgetNodeName(String xpath) Returns the name of the node referred to by the (possibly jsp-encoded) xpath, stripped of indexing information.static StringgetParentXPath(String xpath) Gets the parentXPath attribute of the XPathUtils classstatic StringgetSiblingXPath(String xpath) Gets the siblingPath (that matches all like-named nodes of the parent Element) of a given xpath.static booleanisAttributePath(String xpath) Returns true if the xpath refers to an attribute.static StringRemoves indexing information from XPath strings.static StringRemove jsp expressionLanauge brackets used to support indexing in jsp pages (i.e., ${...}) from a path.
-
Constructor Details
-
XPathUtils
public XPathUtils()
-
-
Method Details
-
decodeXPath
Converts encoded paths of the form used in jsp pages ( "foo_1_") to a XPath form ("foo[1]"). (square brackets cannot be used in xpaths contained in jsp pages)- Parameters:
path- NOT YET DOCUMENTED- Returns:
- equivalent XPath
-
removeELbrackets
Remove jsp expressionLanauge brackets used to support indexing in jsp pages (i.e., ${...}) from a path.- Parameters:
s- path containing el-encoded brackets- Returns:
- NOT YET DOCUMENTED
-
getIndex
Returns the index, if any, for the leaf of the given path.Works for both encoded indexing (e.g., "asdf_1_") and decoded (e.g., "asasdf[1]".
- Parameters:
s- NOT YET DOCUMENTED- Returns:
- The index value
-
encodeXPath
Converts indexed paths of the form ("foo[1]") to the form used in jsp pages ( "foo_1_")- Parameters:
s- indexed xpath- Returns:
- equivalent XPath
-
normalizeXPath
Removes indexing information from XPath strings.- before: "/itemRecord/general/foo[1]/@url"
- after: "/itemRecord/general/foo/@url"
- Parameters:
s- xpath possibly containing index notation- Returns:
- equivalent XPath
-
getLeaf
Returns the name of the element refered to by the given xpath, which is the leaf, stripped of "\@" in the case of attribute paths). Accepts jsp-encoded xpaths.- Parameters:
xpath- NOT YET DOCUMENTED- Returns:
- The leafName value, with indexing intact
-
isAttributePath
Returns true if the xpath refers to an attribute.- Parameters:
xpath- xpath to be tested- Returns:
- The attributePath value
-
getNodeName
Returns the name of the node referred to by the (possibly jsp-encoded) xpath, stripped of indexing information.- Parameters:
xpath- NOT YET DOCUMENTED- Returns:
- The nodeName, stripped of indexing
-
getParentXPath
Gets the parentXPath attribute of the XPathUtils class- Parameters:
xpath- Description of the Parameter- Returns:
- The parentXPath value
-
getSiblingXPath
Gets the siblingPath (that matches all like-named nodes of the parent Element) of a given xpath. Removes indexing information only on the terminal element (leaf), NOT on the rest of the path (as(String)does).- Parameters:
xpath- XPath as String- Returns:
- The siblingPath value
-
compare
Compares two xpaths for "xpath order", using "natuiral" or alphabetical ordering except for when xpath indexing is involved, e.g., "/record/general[3]/foo[5]" is "less than" "/record/general[4]/foo[6]".NOTE: result of this comparison is not the same "document order", since XML documents are not structured in alpha order!
- Parameters:
path1- first path to be comparedpath2- second path to be compared- Returns:
- 0 if the two paths are equal, -1 if path1 is "less than" path 2, 1 otherwise
-