Package org.htmlunit.xpath
Class XPathContext
- java.lang.Object
-
- org.htmlunit.xpath.xml.dtm.DTMManager
-
- org.htmlunit.xpath.XPathContext
-
public class XPathContext extends DTMManager
Default class for the runtime execution context for XPath.This class extends DTMManager but does not directly implement it.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Stack<SubContextList>
m_axesIteratorStack
Stack of AxesIterators.private java.util.Stack<java.lang.Integer>
m_currentNodes
The stack of current node objects.private javax.xml.transform.ErrorListener
m_defaultErrorListener
A default ErrorListener in case our m_errorListener was not specified and our owner either does not have an ErrorListener or has a null one.protected DTMManager
m_dtmManager
Though XPathContext context extends the DTMManager, it really is a proxy for this object, which is the real DTMManager.private javax.xml.transform.ErrorListener
m_errorListener
The ErrorListener where errors and warnings are to be reported.private java.util.Stack<java.lang.Integer>
m_predicatePos
private java.util.Stack<PrefixResolver>
m_prefixResolvers
private javax.xml.transform.URIResolver
m_uriResolver
The TrAX URI Resolver for resolving URIs from the document(...) function to source tree nodes.static int
RECURSIONLIMIT
The ammount to use for stacks that record information during the recursive execution.-
Fields inherited from class org.htmlunit.xpath.xml.dtm.DTMManager
IDENT_DTM_DEFAULT, IDENT_DTM_NODE_BITS, IDENT_MAX_DTMS, IDENT_NODE_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description XPathContext()
Create an XPathContext instance.XPathContext(boolean recursiveVarContext)
Create an XPathContext instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getCurrentNode()
Get the current context node.DTM
getDTM(int nodeHandle)
Get the instance of DTM that "owns" a node handle.DTM
getDTM(javax.xml.transform.Source source, boolean unique, boolean incremental, boolean doIndexing)
Get an instance of a DTM, loaded with the content from the specified source.int
getDTMHandleFromNode(org.w3c.dom.Node node)
Given a W3C DOM node, try and return a DTM handle.DTMManager
getDTMManager()
Return the DTMManager object.javax.xml.transform.ErrorListener
getErrorListener()
Get the ErrorListener where errors and warnings are to be reported.PrefixResolver
getNamespaceContext()
Get the current namespace context for the xpath.int
getPredicatePos()
SubContextList
getSubContextList()
Get the current axes iterator, or return null if none.javax.xml.transform.URIResolver
getURIResolver()
Get the URIResolver associated with this execution context.void
popCurrentNode()
Pop the current context node.void
popCurrentNodeAndExpression()
Set the current context node.void
popNamespaceContext()
Pop the current namespace context for the xpath.void
popPredicatePos()
void
popSubContextList()
Pop the last pushed axes iterator.void
pushCurrentNode(int n)
Set the current context node.void
pushCurrentNodeAndExpression(int cn)
Set the current context node and expression node.void
pushNamespaceContext(PrefixResolver pr)
Push a current namespace context for the xpath.void
pushPredicatePos(int n)
void
pushSubContextList(SubContextList iter)
Push a TreeWalker on the stack.void
reset()
Reset for new run.void
setErrorListener(javax.xml.transform.ErrorListener listener)
Set the ErrorListener where errors and warnings are to be reported.void
setNamespaceContext(PrefixResolver pr)
Get the current namespace context for the xpath.void
setURIResolver(javax.xml.transform.URIResolver resolver)
Set the URIResolver associated with this execution context.-
Methods inherited from class org.htmlunit.xpath.xml.dtm.DTMManager
newInstance
-
-
-
-
Field Detail
-
m_dtmManager
protected DTMManager m_dtmManager
Though XPathContext context extends the DTMManager, it really is a proxy for this object, which is the real DTMManager.
-
m_errorListener
private javax.xml.transform.ErrorListener m_errorListener
The ErrorListener where errors and warnings are to be reported.
-
m_defaultErrorListener
private javax.xml.transform.ErrorListener m_defaultErrorListener
A default ErrorListener in case our m_errorListener was not specified and our owner either does not have an ErrorListener or has a null one.
-
m_uriResolver
private javax.xml.transform.URIResolver m_uriResolver
The TrAX URI Resolver for resolving URIs from the document(...) function to source tree nodes.
-
RECURSIONLIMIT
public static final int RECURSIONLIMIT
The ammount to use for stacks that record information during the recursive execution.- See Also:
- Constant Field Values
-
m_currentNodes
private final java.util.Stack<java.lang.Integer> m_currentNodes
The stack of current node objects. Not to be confused with the current node list. %REVIEW% Note that there are no bounds check and resize for this stack, so if it is blown, it's all over.
-
m_predicatePos
private final java.util.Stack<java.lang.Integer> m_predicatePos
-
m_prefixResolvers
private final java.util.Stack<PrefixResolver> m_prefixResolvers
-
m_axesIteratorStack
private final java.util.Stack<SubContextList> m_axesIteratorStack
Stack of AxesIterators.
-
-
Constructor Detail
-
XPathContext
public XPathContext()
Create an XPathContext instance. This is equivalent to calling theXPathContext(boolean)
constructor with the valuetrue
.
-
XPathContext
public XPathContext(boolean recursiveVarContext)
Create an XPathContext instance.- Parameters:
recursiveVarContext
- Aboolean
value indicating whether the XPath context needs to support pushing of scopes for variable resolution
-
-
Method Detail
-
getDTMManager
public DTMManager getDTMManager()
Return the DTMManager object. Though XPathContext context extends the DTMManager, it really is a proxy for the real DTMManager. If a caller needs to make a lot of calls to the DTMManager, it is faster if it gets the real one from this function.
-
getDTM
public DTM getDTM(javax.xml.transform.Source source, boolean unique, boolean incremental, boolean doIndexing)
Get an instance of a DTM, loaded with the content from the specified source. If the unique flag is true, a new instance will always be returned. Otherwise it is up to the DTMManager to return a new instance or an instance that it already created and may be being used by someone else.(More parameters may eventually need to be added for error handling and entity resolution, and to better control selection of implementations.)
- Specified by:
getDTM
in classDTMManager
- Parameters:
source
- the specification of the source object, which may be null, in which case it is assumed that node construction will take by some other means.unique
- true if the returned DTM must be unique, probably because it is going to be mutated.incremental
- true if the DTM should be built incrementally, if possible.doIndexing
- true if the caller considers it worth it to use indexing schemes.- Returns:
- a non-null DTM reference.
-
getDTM
public DTM getDTM(int nodeHandle)
Get the instance of DTM that "owns" a node handle.- Specified by:
getDTM
in classDTMManager
- Parameters:
nodeHandle
- the nodeHandle.- Returns:
- a non-null DTM reference.
-
getDTMHandleFromNode
public int getDTMHandleFromNode(org.w3c.dom.Node node)
Given a W3C DOM node, try and return a DTM handle. Note: calling this may be non-optimal.- Specified by:
getDTMHandleFromNode
in classDTMManager
- Parameters:
node
- Non-null reference to a DOM node.- Returns:
- a valid DTM handle.
-
reset
public void reset()
Reset for new run.
-
getErrorListener
public final javax.xml.transform.ErrorListener getErrorListener()
Get the ErrorListener where errors and warnings are to be reported.- Returns:
- A non-null ErrorListener reference.
-
setErrorListener
public void setErrorListener(javax.xml.transform.ErrorListener listener) throws java.lang.IllegalArgumentException
Set the ErrorListener where errors and warnings are to be reported.- Parameters:
listener
- A non-null ErrorListener reference.- Throws:
java.lang.IllegalArgumentException
-
getURIResolver
public final javax.xml.transform.URIResolver getURIResolver()
Get the URIResolver associated with this execution context.- Returns:
- a URI resolver, which may be null.
-
setURIResolver
public void setURIResolver(javax.xml.transform.URIResolver resolver)
Set the URIResolver associated with this execution context.- Parameters:
resolver
- the URIResolver to be associated with this execution context, may be null to clear an already set resolver.
-
getCurrentNode
public final int getCurrentNode()
Get the current context node.- Returns:
- the current node.
-
pushCurrentNodeAndExpression
public final void pushCurrentNodeAndExpression(int cn)
Set the current context node and expression node.- Parameters:
cn
- the current node.
-
popCurrentNodeAndExpression
public final void popCurrentNodeAndExpression()
Set the current context node.
-
pushCurrentNode
public final void pushCurrentNode(int n)
Set the current context node.- Parameters:
n
- the current node.
-
popCurrentNode
public final void popCurrentNode()
Pop the current context node.
-
getPredicatePos
public final int getPredicatePos()
-
pushPredicatePos
public final void pushPredicatePos(int n)
-
popPredicatePos
public final void popPredicatePos()
-
getNamespaceContext
public final PrefixResolver getNamespaceContext()
Get the current namespace context for the xpath.- Returns:
- the current prefix resolver for resolving prefixes to namespace URLs.
-
setNamespaceContext
public final void setNamespaceContext(PrefixResolver pr)
Get the current namespace context for the xpath.- Parameters:
pr
- the prefix resolver to be used for resolving prefixes to namespace URLs.
-
pushNamespaceContext
public final void pushNamespaceContext(PrefixResolver pr)
Push a current namespace context for the xpath.- Parameters:
pr
- the prefix resolver to be used for resolving prefixes to namespace URLs.
-
popNamespaceContext
public final void popNamespaceContext()
Pop the current namespace context for the xpath.
-
pushSubContextList
public final void pushSubContextList(SubContextList iter)
Push a TreeWalker on the stack.- Parameters:
iter
- A sub-context AxesWalker.
-
popSubContextList
public final void popSubContextList()
Pop the last pushed axes iterator.
-
getSubContextList
public SubContextList getSubContextList()
Get the current axes iterator, or return null if none.- Returns:
- the sub-context node list.
-
-