org.tinyjee.maven.dim.utils
Class XPathEvaluatorImplementation

java.lang.Object
  extended by org.tinyjee.maven.dim.utils.XPathEvaluatorImplementation
All Implemented Interfaces:
XPathEvaluator

public class XPathEvaluatorImplementation
extends Object
implements XPathEvaluator

Implements XPathEvaluator.

Author:
Juergen_Kellerer, 2011-10-12

Field Summary
static String DEFAULT_PREFIX
           
 
Constructor Summary
XPathEvaluatorImplementation(Document document)
          Creates a new evaluator around the given document.
 
Method Summary
 List<Node> asList(NodeList nodeList)
          Converts the given NodeList to a java list of Node instances.
 List<Node> findNodes(String xpathExpression)
          Finds all DOM nodes that match the given XPath expression.
 String findText(String xpathExpression)
          Searches the loaded document for the text content of the first node matched by the given XPath expression.
 XPathEvaluator newEvaluator(Node node)
          Creates a new dependent evaluator that resolves nodes relative to the given node.
 String serialize(Node node)
          Serializes the given DOM node to XML.
static String serializeNode(Node node, boolean omitDeclaration, boolean standalone)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PREFIX

public static final String DEFAULT_PREFIX
See Also:
Constant Field Values
Constructor Detail

XPathEvaluatorImplementation

public XPathEvaluatorImplementation(Document document)
Creates a new evaluator around the given document.

Parameters:
document - the document to evaluate on.
Method Detail

serializeNode

public static String serializeNode(Node node,
                                   boolean omitDeclaration,
                                   boolean standalone)

findText

public String findText(String xpathExpression)
Description copied from interface: XPathEvaluator
Searches the loaded document for the text content of the first node matched by the given XPath expression.

Specified by:
findText in interface XPathEvaluator
Parameters:
xpathExpression - The xpath expression used to select the text content. E.g. "/html/head/title"
Returns:
The first matched text content or 'null' if not found.

findNodes

public List<Node> findNodes(String xpathExpression)
Description copied from interface: XPathEvaluator
Finds all DOM nodes that match the given XPath expression.

Specified by:
findNodes in interface XPathEvaluator
Parameters:
xpathExpression - The xpath expression used to select nodes, E.g. //table
Returns:
A list of all matched DOM nodes. If no nodes were matched, an empty list is returned instead.

serialize

public String serialize(Node node)
Description copied from interface: XPathEvaluator
Serializes the given DOM node to XML.

Specified by:
serialize in interface XPathEvaluator
Parameters:
node - the node to serialize.
Returns:
the XML string representing the serialized node.

asList

public List<Node> asList(NodeList nodeList)
Description copied from interface: XPathEvaluator
Converts the given NodeList to a java list of Node instances.

Specified by:
asList in interface XPathEvaluator
Parameters:
nodeList - the node list to convert.
Returns:
a node list that uses the standard java collection framework.

newEvaluator

public XPathEvaluator newEvaluator(Node node)
Description copied from interface: XPathEvaluator
Creates a new dependent evaluator that resolves nodes relative to the given node.

The evaluator returned by this method shares internals like namespace resolution and xpath engine and may not be used concurrently (in multiple threads) with its creator.

Specified by:
newEvaluator in interface XPathEvaluator
Parameters:
node - the node to resolve against.
Returns:
a new evaluator that resolves nodes relative to the given node.