com.gargoylesoftware.htmlunit.html.xpath
Class DocumentNavigator

java.lang.Object
  extended by org.jaxen.DefaultNavigator
      extended by com.gargoylesoftware.htmlunit.html.xpath.DocumentNavigator
All Implemented Interfaces:
java.io.Serializable, org.jaxen.Navigator

public class DocumentNavigator
extends org.jaxen.DefaultNavigator

Jaxen Navigator implementation for navigating around the HtmlUnit DOM object model in the context of XPath evaluation. The implementation is closely modeled after the W3C DOM Navigator that comes with Jaxen.

This class is not intended for direct usage, but is used by the Jaxen engine during evaluation.

Version:
$Revision: 1.3 $
Author:
Christian Sell, Mike Bowler, Ahmed Ashour
See Also:
HtmlUnitXPath, Serialized Form

Field Summary
static DocumentNavigator instance
 Constant: singleton navigator.
 
Constructor Summary
DocumentNavigator()
  
 
Method Summary
 java.util.Iterator getAttributeAxisIterator(java.lang.Object contextNode)
 Get an iterator over all attributes.
 java.lang.String getAttributeName(java.lang.Object object)
 Get the local name of an attribute.
 java.lang.String getAttributeNamespaceUri(java.lang.Object object)
  
 java.lang.String getAttributeQName(java.lang.Object object)
 Get the qualified name of an attribute.
 java.lang.String getAttributeStringValue(java.lang.Object object)
 Get the string value of an attribute node.
 java.util.Iterator getChildAxisIterator(java.lang.Object contextNode)
 Get an iterator over all of this node's children.
 java.lang.String getCommentStringValue(java.lang.Object object)
 Get the string value of a comment node.
 java.lang.Object getDocumentNode(java.lang.Object contextNode)
 Get the top-level document node.
 java.lang.Object getElementById(java.lang.Object contextNode, java.lang.String elementId)
 Returns the element whose ID is given by elementId.
 java.lang.String getElementName(java.lang.Object object)
 Get the local name of an element.
 java.lang.String getElementNamespaceUri(java.lang.Object object)
 Get the Namespace URI of an element.
 java.lang.String getElementQName(java.lang.Object object)
 Get the qualified name of an element.
 java.lang.String getElementStringValue(java.lang.Object object)
 Get the string value of an element node.
 java.util.Iterator getFollowingAxisIterator(java.lang.Object contextNode)
 Get an iterator over all following nodes, depth-first.
 java.util.Iterator getFollowingSiblingAxisIterator(java.lang.Object contextNode)
 Get an iterator over all following siblings.
 java.lang.String getNamespacePrefix(java.lang.Object object)
 Get the prefix value of a Namespace node.
 java.lang.String getNamespaceStringValue(java.lang.Object object)
 Get the string value of a Namespace node.
 java.util.Iterator getParentAxisIterator(java.lang.Object contextNode)
 Get a (single-member) iterator over this node's parent.
 java.util.Iterator getPrecedingAxisIterator(java.lang.Object contextNode)
 Get an iterator over all preceding nodes, depth-first.
 java.util.Iterator getPrecedingSiblingAxisIterator(java.lang.Object contextNode)
 Get an iterator over all preceding siblings.
 java.lang.String getTextStringValue(java.lang.Object object)
 Get the string value of text.
 boolean isAttribute(java.lang.Object object)
 Test if a node is an attribute.
 boolean isComment(java.lang.Object object)
 Test if a node is a comment.
 boolean isDocument(java.lang.Object object)
 Test if a node is a top-level document.
 boolean isElement(java.lang.Object object)
 Test if a node is an element.
 boolean isNamespace(java.lang.Object object)
 Test if a node is a Namespace.
 boolean isProcessingInstruction(java.lang.Object object)
 Test if a node is a processing instruction.
 boolean isText(java.lang.Object object)
 Test if a node is plain text.
 org.jaxen.XPath parseXPath(java.lang.String xpath)
  
 
Methods inherited from class org.jaxen.DefaultNavigator
getAncestorAxisIterator, getAncestorOrSelfAxisIterator, getDescendantAxisIterator, getDescendantOrSelfAxisIterator, getDocument, getNamespaceAxisIterator, getNodeType, getParentNode, getProcessingInstructionData, getProcessingInstructionTarget, getSelfAxisIterator, translateNamespacePrefixToUri
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

public static final DocumentNavigator instance
Constant: singleton navigator.

Constructor Detail

DocumentNavigator

public DocumentNavigator()
Method Detail

getAttributeAxisIterator

public java.util.Iterator getAttributeAxisIterator(java.lang.Object contextNode)
Get an iterator over all attributes.

Specified by:
getAttributeAxisIterator in interface org.jaxen.Navigator
Overrides:
getAttributeAxisIterator in class org.jaxen.DefaultNavigator
Parameters:
contextNode - The context node for the attribute axis.
Returns:
A possibly-empty iterator (not null).

getAttributeName

public java.lang.String getAttributeName(java.lang.Object object)
Get the local name of an attribute.

Parameters:
object - The target node.
Returns:
A string representing the unqualified local name if the node is an attribute, or null otherwise.

getAttributeNamespaceUri

public java.lang.String getAttributeNamespaceUri(java.lang.Object object)
Parameters:
object - The target node.
Returns:
the Namespace URI of an attribute.

getAttributeQName

public java.lang.String getAttributeQName(java.lang.Object object)
Get the qualified name of an attribute.

Parameters:
object - The target node.
Returns:
A string representing the qualified (i.e. possibly prefixed) name if the node is an attribute, or null otherwise.

getAttributeStringValue

public java.lang.String getAttributeStringValue(java.lang.Object object)
Get the string value of an attribute node.

Parameters:
object - The target node.
Returns:
The text of the attribute value if the node is an attribute, null otherwise.

getChildAxisIterator

public java.util.Iterator getChildAxisIterator(java.lang.Object contextNode)
Get an iterator over all of this node's children.

Specified by:
getChildAxisIterator in interface org.jaxen.Navigator
Overrides:
getChildAxisIterator in class org.jaxen.DefaultNavigator
Parameters:
contextNode - The context node for the child axis.
Returns:
A possibly-empty iterator (not null).

getCommentStringValue

public java.lang.String getCommentStringValue(java.lang.Object object)
Get the string value of a comment node.

Parameters:
object - The target node.
Returns:
The text of the comment if the node is a comment, null otherwise.

getDocumentNode

public java.lang.Object getDocumentNode(java.lang.Object contextNode)
Get the top-level document node.

Specified by:
getDocumentNode in interface org.jaxen.Navigator
Overrides:
getDocumentNode in class org.jaxen.DefaultNavigator
Parameters:
contextNode - Any node in the document.
Returns:
The root node.

getElementById

public java.lang.Object getElementById(java.lang.Object contextNode,
                                       java.lang.String elementId)
Returns the element whose ID is given by elementId. If no such element exists, returns null. Attributes with the name "ID" are not of type ID unless so defined. Attribute types are only known if when the parser understands DTD's or schemas that declare attributes of type ID. When JAXP is used, you must call setValidating(true) on the DocumentBuilderFactory.

Specified by:
getElementById in interface org.jaxen.Navigator
Overrides:
getElementById in class org.jaxen.DefaultNavigator
Parameters:
contextNode - a node from the document in which to look for the id
elementId - id to look for
Returns:
element whose ID is given by elementId, or null if no such element exists in the document or if the implementation does not know about attribute types
See Also:
DocumentBuilderFactory

getElementName

public java.lang.String getElementName(java.lang.Object object)
Get the local name of an element.

Parameters:
object - The target node.
Returns:
A string representing the unqualified local name if the node is an element, or null otherwise.

getElementNamespaceUri

public java.lang.String getElementNamespaceUri(java.lang.Object object)
Get the Namespace URI of an element.

Parameters:
object - The target node.
Returns:
A string (possibly empty) if the node is an element, and null otherwise.

getElementQName

public java.lang.String getElementQName(java.lang.Object object)
Get the qualified name of an element.

Parameters:
object - The target node.
Returns:
A string representing the qualified (i.e. possibly prefixed) name if the node is an element, or null otherwise.

getElementStringValue

public java.lang.String getElementStringValue(java.lang.Object object)
Get the string value of an element node.

Parameters:
object - The target node.
Returns:
The text inside the node and its descendants if the node is an element, null otherwise.

getFollowingAxisIterator

public java.util.Iterator getFollowingAxisIterator(java.lang.Object contextNode)
Get an iterator over all following nodes, depth-first.

Specified by:
getFollowingAxisIterator in interface org.jaxen.Navigator
Overrides:
getFollowingAxisIterator in class org.jaxen.DefaultNavigator
Parameters:
contextNode - The context node for the following axis.
Returns:
A possibly-empty iterator (not null).

getFollowingSiblingAxisIterator

public java.util.Iterator getFollowingSiblingAxisIterator(java.lang.Object contextNode)
Get an iterator over all following siblings.

Specified by:
getFollowingSiblingAxisIterator in interface org.jaxen.Navigator
Overrides:
getFollowingSiblingAxisIterator in class org.jaxen.DefaultNavigator
Parameters:
contextNode - the context node for the sibling iterator.
Returns:
A possibly-empty iterator (not null).

getNamespacePrefix

public java.lang.String getNamespacePrefix(java.lang.Object object)
Get the prefix value of a Namespace node.

Parameters:
object - The target node.
Returns:
The Namespace prefix a (possibly empty) string if the node is a namespace node, null otherwise.

getNamespaceStringValue

public java.lang.String getNamespaceStringValue(java.lang.Object object)
Get the string value of a Namespace node.

Parameters:
object - The target node.
Returns:
The Namespace URI as a (possibly empty) string if the node is a namespace node, null otherwise.

getParentAxisIterator

public java.util.Iterator getParentAxisIterator(java.lang.Object contextNode)
Get a (single-member) iterator over this node's parent.

Specified by:
getParentAxisIterator in interface org.jaxen.Navigator
Overrides:
getParentAxisIterator in class org.jaxen.DefaultNavigator
Parameters:
contextNode - the context node for the parent axis.
Returns:
A possibly-empty iterator (not null).

getPrecedingAxisIterator

public java.util.Iterator getPrecedingAxisIterator(java.lang.Object contextNode)
Get an iterator over all preceding nodes, depth-first.

Specified by:
getPrecedingAxisIterator in interface org.jaxen.Navigator
Overrides:
getPrecedingAxisIterator in class org.jaxen.DefaultNavigator
Parameters:
contextNode - The context node for the preceding axis.
Returns:
A possibly-empty iterator (not null).

getPrecedingSiblingAxisIterator

public java.util.Iterator getPrecedingSiblingAxisIterator(java.lang.Object contextNode)
Get an iterator over all preceding siblings.

Specified by:
getPrecedingSiblingAxisIterator in interface org.jaxen.Navigator
Overrides:
getPrecedingSiblingAxisIterator in class org.jaxen.DefaultNavigator
Parameters:
contextNode - The context node for the preceding sibling axis.
Returns:
A possibly-empty iterator (not null).

getTextStringValue

public java.lang.String getTextStringValue(java.lang.Object object)
Get the string value of text.

Parameters:
object - The target node.
Returns:
The string of text if the node is text, null otherwise.

isAttribute

public boolean isAttribute(java.lang.Object object)
Test if a node is an attribute.

Parameters:
object - The target node.
Returns:
true if the node is an attribute, false otherwise.

isComment

public boolean isComment(java.lang.Object object)
Test if a node is a comment.

Parameters:
object - The target node.
Returns:
true if the node is a comment, false otherwise.

isDocument

public boolean isDocument(java.lang.Object object)
Test if a node is a top-level document.

Parameters:
object - The target node.
Returns:
true if the node is the document root, false otherwise.

isElement

public boolean isElement(java.lang.Object object)
Test if a node is an element.

Parameters:
object - The target node.
Returns:
true if the node is an element, false otherwise.

isNamespace

public boolean isNamespace(java.lang.Object object)
Test if a node is a Namespace.

Parameters:
object - The target node.
Returns:
true if the node is a Namespace, false otherwise.

isProcessingInstruction

public boolean isProcessingInstruction(java.lang.Object object)
Test if a node is a processing instruction.

Parameters:
object - The target node.
Returns:
true if the node is a processing instruction, false otherwise.

isText

public boolean isText(java.lang.Object object)
Test if a node is plain text.

Parameters:
object - The target node.
Returns:
true if the node is a text node, false otherwise.

parseXPath

public org.jaxen.XPath parseXPath(java.lang.String xpath)
                           throws org.jaxen.JaxenException
Parameters:
xpath - an xpath expression
Returns:
a parsed form of the given xpath string, which will be suitable for queries on DOM documents.
Throws:
org.jaxen.JaxenException - if the expression could not be parsed


Copyright © 2003-2009 AppPerfect Corporation. All Rights Reserved.