Enhydra 3.1 API

org.apache.xalan.xpath
Class XPathSupportDefault

java.lang.Object
  |
  +--org.apache.xalan.xpath.XPathSupportDefault
Direct Known Subclasses:
XMLParserLiaisonDefault

public class XPathSupportDefault
extends java.lang.Object
implements XPathSupport

Default class for execution context when XPath is used by itself. Many of the functions in this class need to be overridden in order to perform correct execution of the XPath (for instance, variable execution). This class will likely eventually replace XMLParserLiaisons.


Fields inherited from interface org.apache.xalan.xpath.XPathSupport
DATASOURCE, ERROR, WARNING, XMLPARSER, XPATHPARSER, XPATHPROCESSOR, XSLTPROCESSOR
 
Constructor Summary
XPathSupportDefault()
           
 
Method Summary
 void addExtensionNamespace(java.lang.String uri, ExtensionFunctionHandler extNS)
          Register an extension namespace handler.
 void associateXLocatorToNode(Node node, XLocator xlocator)
          Associate an XLocator provider to a node.
 void beginConstruction(KeyDeclaration kd)
           
 XLocator createXLocatorHandler()
          getXLocatorHandler.
 void deassociateXLocatorToNode(Node node)
          Deassociate an XLocator provider to a node based on the root of the tree that the node is parented by.
 void decrementContextNodePosition()
           Decrement the current context node position.
 boolean elementAvailable(java.lang.String namespace, java.lang.String extensionName)
          Execute the element-available() function.
 void endConstruction(KeyDeclaration kd)
           
 java.lang.Object extFunction(java.lang.String namespace, java.lang.String extensionName, java.util.Vector argVec, java.lang.Object methodKey)
          Handle an extension function.
 java.lang.String findURIFromDoc(Document owner)
          Given a DOM Document, tell what URI was used to parse it.
 boolean functionAvailable(java.lang.String namespace, java.lang.String extensionName)
          Execute the function-available() function.
 NodeCallback getCallback()
          Get the callback that may be called by XPath as nodes are located.
 java.lang.Object getCallbackInfo()
          Get the object that will be passed to the processLocatedNode method.
 NodeList getContextNodeList()
          Get the current context node list.
 int getContextNodePosition()
           Get the current position in the context node list.
 Node getCurrentNode()
          Get the current context node.
 Document getDOMFactory()
          Get a DOM document, primarily for creating result tree fragments.
 Element getElementByID(java.lang.String id, Document doc)
          Get an element from an ID.
 ErrorHandler getErrorHandler()
          Get the current error handler, if there is one.
 boolean getInConstruction(KeyDeclaration kd)
           
 java.lang.String getLocalNameOfNode(Node n)
          Returns the local name of the given node.
 PrefixResolver getNamespaceContext()
          Get the current namespace context for the xpath.
 java.lang.String getNamespaceForPrefix(java.lang.String prefix, Element namespaceContext)
          Given a namespace, get the corresponding prefix.
 java.lang.String getNamespaceOfNode(Node n)
          Returns the namespace of the given node.
 int getNodeNumber(Node n)
           
 NodeList getNodeSetByKey(Node doc, java.lang.String name, java.lang.String ref, PrefixResolver nscontext)
          Given a valid element key, return the corresponding node list.
 Node getParentOfNode(Node node)
          This function has to be implemented, because the DOM WG decided that attributes don't have parents.
 boolean getProcessNamespaces()
          Tells if namespaces should be supported.
 Node getRoot(Node node)
          Get the first unparented node in the ancestor chain.
 java.util.Hashtable getSourceDocsTable()
          Get table of source tree documents.
 boolean getThrowFoundIndex()
           ThrowFoundIndex tells if FoundIndex should be thrown if index is found.
 java.lang.String getUnparsedEntityURI(java.lang.String name, Document doc)
          The getUnparsedEntityURI function returns the URI of the unparsed entity with the specified name in the same document as the context node (see [3.3 Unparsed Entities]).
 java.net.URL getURLFromString(java.lang.String urlString, java.lang.String base)
          Take a user string and try and parse XML, and also return the url.
 XObject getVariable(QName name)
          Variables don't work when executing an XPath by itself.
 XLocator getXLocatorFromNode(Node node)
          Get an XLocator provider keyed by node.
 void incrementContextNodePosition(Node node)
           Increment the current context node position.
 boolean isIgnorableWhitespace(Text node)
          Deprecated.  
 Document parseXML(java.lang.String urlString, java.lang.String base)
          Deprecated.  
 Document parseXML(java.net.URL url, DocumentHandler docHandler, Document styleDoc)
          Take a user string and try and parse XML, and also return the url.
 void popContextNodeList()
           Pop the current context node list.
 void popContextNodePosition()
           Pop the current context node position.
 void popXPathContext()
           Pop the current XPathContext.
 boolean problem(short where, short classification, Node styleNode, Node sourceNode, java.lang.String msg, int lineNo, int charOffset)
          Function that is called when a problem event occurs.
 void pushContextNodeList(NodeList nl)
           Set the current context node list.
 void pushContextNodePosition()
          Push the current context node position.
 void pushDummyXPathContext()
          Push a dummy XPathContext so we can tell that the top-level xpath isn't in effect.
 void pushXPathContext(XPath xpath, XPathSupport execContext, Node contextNode, PrefixResolver namespaceContext)
           Push the current XPath selection, needed for support of the last() function in depth-first execution.
 XObject reExecuteXPathContext(XPath path, XPathSupport execContext, Node context)
           Reexecute the last xpath context after the specified one.
 void setCallback(NodeCallback callback, java.lang.Object callbackInfo)
          Set a callback that may be called by XPath as nodes are located.
 void setContextNodePosition(int newNodePos)
           Set the current context node position.
 void setCurrentNode(Node n)
          Set the current context node.
 void setDOMFactory(Document domFactory)
          Get the factory object required to create DOM nodes in the result tree.
 void setNamespaceContext(PrefixResolver pr)
          Get the current namespace context for the xpath.
 void setProcessNamespaces(boolean processNamespaces)
          Set whether or not the liaison attempts to expand namespaces.
 void setThrowFoundIndex(boolean b)
           ThrowFoundIndex tells if FoundIndex should be thrown if index is found.
 boolean shouldStripSourceNode(Node textNode)
          Tells, through the combination of the default-space attribute on xsl:stylesheet, xsl:strip-space, xsl:preserve-space, and the xml:space attribute, whether or not extra whitespace should be stripped from the node.
 boolean supportsNodeNumber(Node n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathSupportDefault

public XPathSupportDefault()
Method Detail

pushXPathContext

public void pushXPathContext(XPath xpath,
                             XPathSupport execContext,
                             Node contextNode,
                             PrefixResolver namespaceContext)
Push the current XPath selection, needed for support of the last() function in depth-first execution. If the last() function is called, the originating XPath will be executed to get a count. This is ugly, and later some sort of system can be done where the XPath can finish evaluating from the current point.
Specified by:
pushXPathContext in interface XPathSupport

popXPathContext

public void popXPathContext()
Pop the current XPathContext.
Specified by:
popXPathContext in interface XPathSupport

pushDummyXPathContext

public void pushDummyXPathContext()
Push a dummy XPathContext so we can tell that the top-level xpath isn't in effect.
Specified by:
pushDummyXPathContext in interface XPathSupport

reExecuteXPathContext

public XObject reExecuteXPathContext(XPath path,
                                     XPathSupport execContext,
                                     Node context)
                              throws SAXException
Reexecute the last xpath context after the specified one.
Specified by:
reExecuteXPathContext in interface XPathSupport

getContextNodePosition

public int getContextNodePosition()
Get the current position in the context node list. Used for depth-first searching.
Specified by:
getContextNodePosition in interface XPathSupport

setContextNodePosition

public void setContextNodePosition(int newNodePos)
Set the current context node position.
Specified by:
setContextNodePosition in interface XPathSupport

incrementContextNodePosition

public void incrementContextNodePosition(Node node)
Increment the current context node position.
Specified by:
incrementContextNodePosition in interface XPathSupport

decrementContextNodePosition

public void decrementContextNodePosition()
Decrement the current context node position.
Specified by:
decrementContextNodePosition in interface XPathSupport

pushContextNodePosition

public void pushContextNodePosition()
Push the current context node position.
Specified by:
pushContextNodePosition in interface XPathSupport

popContextNodePosition

public void popContextNodePosition()
Pop the current context node position.
Specified by:
popContextNodePosition in interface XPathSupport

getContextNodeList

public NodeList getContextNodeList()
Get the current context node list.
Specified by:
getContextNodeList in interface XPathSupport

pushContextNodeList

public void pushContextNodeList(NodeList nl)
Set the current context node list.
Specified by:
pushContextNodeList in interface XPathSupport
Parameters:
A - nodelist that represents the current context list as defined by XPath.

popContextNodeList

public void popContextNodeList()
Pop the current context node list.
Specified by:
popContextNodeList in interface XPathSupport

getThrowFoundIndex

public boolean getThrowFoundIndex()
ThrowFoundIndex tells if FoundIndex should be thrown if index is found. This is an optimization for match patterns, and is used internally by the XPath engine.
Specified by:
getThrowFoundIndex in interface XPathSupport

setThrowFoundIndex

public void setThrowFoundIndex(boolean b)
ThrowFoundIndex tells if FoundIndex should be thrown if index is found. This is an optimization for match patterns, and is used internally by the XPath engine.
Specified by:
setThrowFoundIndex in interface XPathSupport

getCurrentNode

public Node getCurrentNode()
Get the current context node.
Specified by:
getCurrentNode in interface XPathSupport
Tags copied from interface: XPathSupport
Returns:
The current context node as defined by the XPath recommendation.

setCurrentNode

public void setCurrentNode(Node n)
Set the current context node.
Specified by:
setCurrentNode in interface XPathSupport
Tags copied from interface: XPathSupport
Parameters:
n - The current context node as defined by the XPath recommendation.

getNamespaceContext

public PrefixResolver getNamespaceContext()
Get the current namespace context for the xpath.
Specified by:
getNamespaceContext in interface XPathSupport
Tags copied from interface: XPathSupport
Returns:
An object that can resolve XPath prefixes to namespaces.

setNamespaceContext

public void setNamespaceContext(PrefixResolver pr)
Get the current namespace context for the xpath.
Specified by:
setNamespaceContext in interface XPathSupport
Tags copied from interface: XPathSupport
Parameters:
pr - An object that can resolve XPath prefixes to namespaces.

getNamespaceForPrefix

public java.lang.String getNamespaceForPrefix(java.lang.String prefix,
                                              Element namespaceContext)
Given a namespace, get the corresponding prefix.
Specified by:
getNamespaceForPrefix in interface XPathSupport
Parameters:
prefix - A namespace prefix that is valid in the namespaceContext.
namespaceContext - An element from which to evaluate the prefix resolution.
Returns:
A namespace, or null if it can't be resolved.

getNamespaceOfNode

public java.lang.String getNamespaceOfNode(Node n)
Returns the namespace of the given node.
Specified by:
getNamespaceOfNode in interface XPathSupport
Parameters:
n - The node in question.
Returns:
A namespace, or null if there is none.

getLocalNameOfNode

public java.lang.String getLocalNameOfNode(Node n)
Returns the local name of the given node.
Specified by:
getLocalNameOfNode in interface XPathSupport
Parameters:
n - The node in question.
Returns:
The local name of the node, or null if the node doesn't have a name.

getParentOfNode

public Node getParentOfNode(Node node)
This function has to be implemented, because the DOM WG decided that attributes don't have parents.
Specified by:
getParentOfNode in interface XPathSupport
Parameters:
n - The node in question.
Returns:
The "owner" of the node.

getVariable

public XObject getVariable(QName name)
                    throws SAXException
Variables don't work when executing an XPath by itself.
Returns:
XString that is an error message.

isIgnorableWhitespace

public boolean isIgnorableWhitespace(Text node)
Deprecated.  

Tell if the node is ignorable whitespace. This should be in the DOM. Return false if the parser doesn't handle this.
Specified by:
isIgnorableWhitespace in interface XPathSupport

getNodeSetByKey

public NodeList getNodeSetByKey(Node doc,
                                java.lang.String name,
                                java.lang.String ref,
                                PrefixResolver nscontext)
                         throws SAXException
Given a valid element key, return the corresponding node list.
Returns:
null, derived element must override.

getSourceDocsTable

public java.util.Hashtable getSourceDocsTable()
Get table of source tree documents. Document objects are keyed by URL string.
Returns:
null, derived element must override.

findURIFromDoc

public java.lang.String findURIFromDoc(Document owner)
Given a DOM Document, tell what URI was used to parse it.
Returns:
string "unknown", derived element must override.

parseXML

public Document parseXML(java.lang.String urlString,
                         java.lang.String base)
Deprecated.  

Take given a URL, try and parse XML. the error condition is severe enough to halt processing.

getElementByID

public Element getElementByID(java.lang.String id,
                              Document doc)
Get an element from an ID.
Specified by:
getElementByID in interface XPathSupport
Returns:
null, derived element must override.

getUnparsedEntityURI

public java.lang.String getUnparsedEntityURI(java.lang.String name,
                                             Document doc)
The getUnparsedEntityURI function returns the URI of the unparsed entity with the specified name in the same document as the context node (see [3.3 Unparsed Entities]). It returns the empty string if there is no such entity.
Specified by:
getUnparsedEntityURI in interface XPathSupport
Returns:
empty string, derived element must override.

setDOMFactory

public void setDOMFactory(Document domFactory)
Get the factory object required to create DOM nodes in the result tree.

getDOMFactory

public Document getDOMFactory()
Get a DOM document, primarily for creating result tree fragments.

getInConstruction

public boolean getInConstruction(KeyDeclaration kd)
Specified by:
getInConstruction in interface XPathSupport

beginConstruction

public void beginConstruction(KeyDeclaration kd)
Specified by:
beginConstruction in interface XPathSupport

endConstruction

public void endConstruction(KeyDeclaration kd)
Specified by:
endConstruction in interface XPathSupport

problem

public boolean problem(short where,
                       short classification,
                       Node styleNode,
                       Node sourceNode,
                       java.lang.String msg,
                       int lineNo,
                       int charOffset)
Function that is called when a problem event occurs.
Specified by:
problem in interface XPathSupport
Parameters:
where - Either and XMLPARSER, XSLPROCESSOR, or QUERYENGINE.
classification - Either ERROR or WARNING.
styleNode - The style tree node where the problem occurred. May be null.
sourceNode - The source tree node where the problem occurred. May be null.
msg - A string message explaining the problem.
lineNo - The line number where the problem occurred, if it is known. May be zero.
charOffset - The character offset where the problem, occurred if it is known. May be zero.
Returns:
true if the return is an ERROR, in which case exception will be thrown. Otherwise the processor will continue to process.

functionAvailable

public boolean functionAvailable(java.lang.String namespace,
                                 java.lang.String extensionName)
Execute the function-available() function.

elementAvailable

public boolean elementAvailable(java.lang.String namespace,
                                java.lang.String extensionName)
Execute the element-available() function.

extFunction

public java.lang.Object extFunction(java.lang.String namespace,
                                    java.lang.String extensionName,
                                    java.util.Vector argVec,
                                    java.lang.Object methodKey)
                             throws SAXException
Handle an extension function.

getRoot

public Node getRoot(Node node)
Get the first unparented node in the ancestor chain.

associateXLocatorToNode

public void associateXLocatorToNode(Node node,
                                    XLocator xlocator)
Associate an XLocator provider to a node. This makes the association based on the root of the tree that the node is parented by.

deassociateXLocatorToNode

public void deassociateXLocatorToNode(Node node)
Deassociate an XLocator provider to a node based on the root of the tree that the node is parented by.

getXLocatorFromNode

public XLocator getXLocatorFromNode(Node node)
Get an XLocator provider keyed by node. This get's the association based on the root of the tree that the node is parented by.

setProcessNamespaces

public void setProcessNamespaces(boolean processNamespaces)
Set whether or not the liaison attempts to expand namespaces. Used for optimization.
Specified by:
setProcessNamespaces in interface XPathSupport

getProcessNamespaces

public boolean getProcessNamespaces()
Tells if namespaces should be supported. For optimization purposes.
Specified by:
getProcessNamespaces in interface XPathSupport

shouldStripSourceNode

public boolean shouldStripSourceNode(Node textNode)
                              throws SAXException
Tells, through the combination of the default-space attribute on xsl:stylesheet, xsl:strip-space, xsl:preserve-space, and the xml:space attribute, whether or not extra whitespace should be stripped from the node. Literal elements from template elements should not be tested with this function.
Parameters:
textNode - A text node from the source tree.
Returns:
true if the text node should be stripped of extra whitespace.

parseXML

public Document parseXML(java.net.URL url,
                         DocumentHandler docHandler,
                         Document styleDoc)
                  throws SAXException
Take a user string and try and parse XML, and also return the url. the error condition is severe enough to halt processing.
Specified by:
parseXML in interface XPathSupport

getURLFromString

public java.net.URL getURLFromString(java.lang.String urlString,
                                     java.lang.String base)
                              throws SAXException
Take a user string and try and parse XML, and also return the url.
Specified by:
getURLFromString in interface XPathSupport
Throws:
XSLProcessorException - thrown if the active ProblemListener and XMLParserLiaison decide the error condition is severe enough to halt processing.

addExtensionNamespace

public void addExtensionNamespace(java.lang.String uri,
                                  ExtensionFunctionHandler extNS)
Register an extension namespace handler. This handler provides functions for testing whether a function is known within the namespace and also for invoking the functions.
Specified by:
addExtensionNamespace in interface XPathSupport
Parameters:
uri - the URI for the extension.
extNS - the extension handler.

setCallback

public void setCallback(NodeCallback callback,
                        java.lang.Object callbackInfo)
Set a callback that may be called by XPath as nodes are located. The callback will only be called if the XLocator determines that the location path can process the nodes in document order. If the callback is called, the nodes will not be put into the node list, and the LocationPath will return an empty node list. The callback will be set to null after the next LocationPath or Union is processed.
Parameters:
callback - Interface that implements the processLocatedNode method.
callbackInfo - Object that will be passed to the processLocatedNode method.

getCallback

public NodeCallback getCallback()
Get the callback that may be called by XPath as nodes are located.
Returns:
the current callback method.

getCallbackInfo

public java.lang.Object getCallbackInfo()
Get the object that will be passed to the processLocatedNode method.
Returns:
object that will be passed to the processLocatedNode method.

getErrorHandler

public ErrorHandler getErrorHandler()
Get the current error handler, if there is one.
Specified by:
getErrorHandler in interface XPathSupport

createXLocatorHandler

public XLocator createXLocatorHandler()
getXLocatorHandler.
Specified by:
createXLocatorHandler in interface XPathSupport

supportsNodeNumber

public boolean supportsNodeNumber(Node n)
Specified by:
supportsNodeNumber in interface XPathSupport

getNodeNumber

public int getNodeNumber(Node n)
Specified by:
getNodeNumber in interface XPathSupport

Enhydra 3.1 API