DLESE Tools
v1.6.0

org.dlese.dpc.xml
Class XPathUtils

java.lang.Object
  extended by org.dlese.dpc.xml.XPathUtils

public class XPathUtils
extends Object

Utilities for testing and manipulating XPaths, represented as String.

Author:
ostwald

Constructor Summary
XPathUtils()
           
 
Method Summary
static int compare(String path1, String path2)
          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]".
static String decodeXPath(String path)
          Converts encoded paths of the form used in jsp pages ( "foo_1_") to a XPath form ("foo[1]").
static String encodeXPath(String s)
          Converts indexed paths of the form ("foo[1]") to the form used in jsp pages ( "foo_1_")
static int getIndex(String s)
          Returns the index, if any, for the leaf of the given path.
static String getLeaf(String xpath)
          Returns the name of the element refered to by the given xpath, which is the leaf, stripped of "\@" in the case of attribute paths).
static String getNodeName(String xpath)
          Returns the name of the node referred to by the (possibly jsp-encoded) xpath, stripped of indexing information.
static String getParentXPath(String xpath)
          Gets the parentXPath attribute of the XPathUtils class
static String getSiblingXPath(String xpath)
          Gets the siblingPath (that matches all like-named nodes of the parent Element) of a given xpath.
static boolean isAttributePath(String xpath)
          Returns true if the xpath refers to an attribute.
static String normalizeXPath(String s)
          Removes indexing information from XPath strings.
static String removeELbrackets(String s)
          Remove jsp expressionLanauge brackets used to support indexing in jsp pages (i.e., ${...}) from a path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathUtils

public XPathUtils()
Method Detail

decodeXPath

public static String decodeXPath(String path)
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

public static String removeELbrackets(String s)
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

public static int getIndex(String s)
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

public static String encodeXPath(String s)
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

public static String normalizeXPath(String s)
Removes indexing information from XPath strings.

Parameters:
s - xpath possibly containing index notation
Returns:
equivalent XPath

getLeaf

public static String getLeaf(String xpath)
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

public static boolean isAttributePath(String xpath)
Returns true if the xpath refers to an attribute.

Parameters:
xpath - xpath to be tested
Returns:
The attributePath value

getNodeName

public static String getNodeName(String xpath)
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

public static String getParentXPath(String xpath)
Gets the parentXPath attribute of the XPathUtils class

Parameters:
xpath - Description of the Parameter
Returns:
The parentXPath value

getSiblingXPath

public static String getSiblingXPath(String xpath)
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

public static int compare(String path1,
                          String path2)
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 compared
path2 - second path to be compared
Returns:
0 if the two paths are equal, -1 if path1 is "less than" path 2, 1 otherwise

DLESE Tools
v1.6.0