|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.xpath.DOMHelper
Field Summary | |
protected Vector |
m_candidateNoAncestorXMLNS
Deprecated. Vector of node (odd indexes) and NSInfos (even indexes) that tell if the given node is a candidate for ancestor namespace processing. |
protected org.w3c.dom.Document |
m_DOMFactory
Deprecated. The factory object used for creating nodes in the result tree. |
protected static NSInfo |
m_NSInfoNullNoAncestorXMLNS
Deprecated. Object to put into the m_NSInfos table that tells that a node has been processed, and has no xmlns namespace decls. and has no ancestor decls. |
protected static NSInfo |
m_NSInfoNullWithoutXMLNS
Deprecated. Object to put into the m_NSInfos table that tells that a node has been processed, and has no xmlns namespace decls. |
protected static NSInfo |
m_NSInfoNullWithXMLNS
Deprecated. Object to put into the m_NSInfos table that tells that a node has been processed, and has xmlns namespace decls. |
(package private) Hashtable |
m_NSInfos
Deprecated. An experiment for the moment. |
protected static NSInfo |
m_NSInfoUnProcNoAncestorXMLNS
Deprecated. Object to put into the m_NSInfos table that tells that a node has not been processed, and has no xmlns namespace decls, and has no ancestor decls. |
protected static NSInfo |
m_NSInfoUnProcWithoutXMLNS
Deprecated. Object to put into the m_NSInfos table that tells that a node has not been processed, but has no xmlns namespace decls. |
protected static NSInfo |
m_NSInfoUnProcWithXMLNS
Deprecated. Object to put into the m_NSInfos table that tells that a node has not been processed, but has xmlns namespace decls. |
Constructor Summary | |
DOMHelper()
Deprecated. |
Method Summary | |
static org.w3c.dom.Document |
createDocument()
Deprecated. DOM Level 1 did not have a standard mechanism for creating a new Document object. |
org.w3c.dom.Document |
getDOMFactory()
Deprecated. Retrieve the factory object required to create DOM nodes in the result tree. |
org.w3c.dom.Element |
getElementByID(String id,
org.w3c.dom.Document doc)
Deprecated. Given an ID, return the element. |
String |
getExpandedAttributeName(org.w3c.dom.Attr attr)
Deprecated. Returns the attribute name with the namespace prefix (if any) replaced by the Namespace URI it was bound to. |
String |
getExpandedElementName(org.w3c.dom.Element elem)
Deprecated. Returns the element name with the namespace prefix (if any) replaced by the Namespace URI it was bound to. |
short |
getLevel(org.w3c.dom.Node n)
Deprecated. Get the depth level of this node in the tree (equals 1 for a parentless node). |
String |
getLocalNameOfNode(org.w3c.dom.Node n)
Deprecated. Returns the local name of the given node. |
String |
getNamespaceForPrefix(String prefix,
org.w3c.dom.Element namespaceContext)
Deprecated. Given an XML Namespace prefix and a context in which the prefix is to be evaluated, return the Namespace Name this prefix was bound to. |
String |
getNamespaceOfNode(org.w3c.dom.Node n)
Deprecated. Returns the namespace of the given node. |
static String |
getNodeData(org.w3c.dom.Node node)
Deprecated. Get the textual contents of the node. |
static void |
getNodeData(org.w3c.dom.Node node,
FastStringBuffer buf)
Deprecated. Retrieve the text content of a DOM subtree, appending it into a user-supplied FastStringBuffer object. |
static org.w3c.dom.Node |
getParentOfNode(org.w3c.dom.Node node)
Deprecated. Obtain the XPath-model parent of a DOM node -- ownerElement for Attrs, parent for other nodes. |
org.w3c.dom.Node |
getRoot(org.w3c.dom.Node node)
Deprecated. |
org.w3c.dom.Node |
getRootNode(org.w3c.dom.Node n)
Deprecated. Get the root node of the document tree, regardless of whether or not the node passed in is a document node. |
String |
getUniqueID(org.w3c.dom.Node node)
Deprecated. Supports the XPath function GenerateID by returning a unique identifier string for any given DOM Node. |
String |
getUnparsedEntityURI(String name,
org.w3c.dom.Document doc)
Deprecated. 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]). |
boolean |
isIgnorableWhitespace(org.w3c.dom.Text node)
Deprecated. |
boolean |
isNamespaceNode(org.w3c.dom.Node n)
Deprecated. Test whether the given node is a namespace decl node. |
static boolean |
isNodeAfter(org.w3c.dom.Node node1,
org.w3c.dom.Node node2)
Deprecated. Figure out whether node2 should be considered as being later in the document than node1, in Document Order as defined by the XPath model. |
private static boolean |
isNodeAfterSibling(org.w3c.dom.Node parent,
org.w3c.dom.Node child1,
org.w3c.dom.Node child2)
Deprecated. Figure out if child2 is after child1 in document order. |
static boolean |
isNodeTheSame(org.w3c.dom.Node node1,
org.w3c.dom.Node node2)
Deprecated. Use DTMNodeProxy to determine whether two nodes are the same. |
private static org.w3c.dom.Node |
locateAttrParent(org.w3c.dom.Element elem,
org.w3c.dom.Node attr)
Deprecated. Support for getParentOfNode; walks a DOM tree until it finds the Element which owns the Attr. |
void |
setDOMFactory(org.w3c.dom.Document domFactory)
Deprecated. Store the factory object required to create DOM nodes in the result tree. |
boolean |
shouldStripSourceNode(org.w3c.dom.Node textNode)
Deprecated. 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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
Hashtable m_NSInfos
protected static final NSInfo m_NSInfoUnProcWithXMLNS
protected static final NSInfo m_NSInfoUnProcWithoutXMLNS
protected static final NSInfo m_NSInfoUnProcNoAncestorXMLNS
protected static final NSInfo m_NSInfoNullWithXMLNS
protected static final NSInfo m_NSInfoNullWithoutXMLNS
protected static final NSInfo m_NSInfoNullNoAncestorXMLNS
protected Vector m_candidateNoAncestorXMLNS
protected org.w3c.dom.Document m_DOMFactory
Constructor Detail |
public DOMHelper()
Method Detail |
public static org.w3c.dom.Document createDocument()
TODO: This isn't directly compatable with DOM Level 2. The Level 2 createDocument call also creates the root element, and thus requires that you know what that element will be before creating the Document. We should think about whether we want to change this code, and the callers, so we can use the DOM's own method. (It's also possible that DOM Level 3 may relax this sequence, but you may give up some intelligence in the DOM by doing so; the intent was that knowing the document type and root element might let the DOM automatically switch to a specialized subclass for particular kinds of documents.)
public boolean shouldStripSourceNode(org.w3c.dom.Node textNode) throws javax.xml.transform.TransformerException
textNode
- A text node from the source tree.
javax.xml.transform.TransformerException
public String getUniqueID(org.w3c.dom.Node node)
Warning: The base implementation uses the Node object's hashCode(), which is NOT guaranteed to be unique. If that method hasn't been overridden in this DOM ipmlementation, most Java implementions will derive it from the object's address and should be OK... but if your DOM uses a different definition of hashCode (eg hashing the contents of the subtree), or if your DOM may have multiple objects that represent a single Node in the data structure (eg via proxying), you may need to find another way to assign a unique identifier.
Also, be aware that if nodes are destroyed and recreated, there is an open issue regarding whether an ID may be reused. Currently we're assuming that the input document is stable for the duration of the XPath/XSLT operation, so this shouldn't arise in this context.
(DOM Level 3 is investigating providing a unique node "key", but that won't help Level 1 and Level 2 implementations.)
node
- whose identifier you want to obtain
public static boolean isNodeAfter(org.w3c.dom.Node node1, org.w3c.dom.Node node2)
There are some cases where ordering isn't defined, and neither are the results of this function -- though we'll generally return true. TODO: Make sure this does the right thing with attribute nodes!!!
node1
- DOM Node to perform position comparison on.node2
- DOM Node to perform position comparison on .
(node1.documentOrderPosition <= node2.documentOrderPosition)
.public static boolean isNodeTheSame(org.w3c.dom.Node node1, org.w3c.dom.Node node2)
node1
- The first DOM node to compare.node2
- The second DOM node to compare.
private static boolean isNodeAfterSibling(org.w3c.dom.Node parent, org.w3c.dom.Node child1, org.w3c.dom.Node child2)
Warning: Some aspects of "document order" are not well defined. For example, the order of attributes is considered meaningless in XML, and the order reported by our model will be consistant for a given invocation but may not match that of either the source file or the serialized output.
parent
- Must be the parent of both child1 and child2.child1
- Must be the child of parent and not equal to child2.child2
- Must be the child of parent and not equal to child1.
public short getLevel(org.w3c.dom.Node n)
n
- Node to be examined.
public String getNamespaceForPrefix(String prefix, org.w3c.dom.Element namespaceContext)
prefix
- String containing namespace prefix to be resolved,
without the ':' which separates it from the localname when used
in a Node Name. The empty sting signifies the default namespace
at this point in the document.namespaceContext
- Element which provides context for resolution.
(We could extend this to work for other nodes by first seeking their
nearest Element ancestor.)
public String getNamespaceOfNode(org.w3c.dom.Node n)
n
- Node to be examined.
public String getLocalNameOfNode(org.w3c.dom.Node n)
n
- the node to be examined.
public String getExpandedElementName(org.w3c.dom.Element elem)
elem
- Element to be examined.
getExpandedAttributeName(org.w3c.dom.Attr)
public String getExpandedAttributeName(org.w3c.dom.Attr attr)
attr
- Attr to be examined
getExpandedElementName(org.w3c.dom.Element)
public boolean isIgnorableWhitespace(org.w3c.dom.Text node)
node
- Node to be examined
public org.w3c.dom.Node getRoot(org.w3c.dom.Node node)
node
- Starting node, to specify which chain to chase
public org.w3c.dom.Node getRootNode(org.w3c.dom.Node n)
TODO: This doesn't handle DocumentFragments or "orphaned" subtrees -- it's currently returning ownerDocument even when the tree is not actually part of the main Document tree. We should either rewrite the description to say that it finds the Document node, or change the code to walk up the ancestor chain.
n
- Node to be examined
public boolean isNamespaceNode(org.w3c.dom.Node n)
n
- Node to be examined.
public static org.w3c.dom.Node getParentOfNode(org.w3c.dom.Node node) throws RuntimeException
Background: The DOM believes that you must be your Parent's Child, and thus Attrs don't have parents. XPath said that Attrs do have their owning Element as their parent. This function bridges the difference, either by using the DOM Level 2 ownerElement function or by using a "silly and expensive function" in Level 1 DOMs.
(There's some discussion of future DOMs generalizing ownerElement into ownerNode and making it work on all types of nodes. This still wouldn't help the users of Level 1 or Level 2 DOMs)
node
- Node whose XPath parent we want to obtain
RuntimeException
- if the Document has no root element.
This can't arise if the Document was created
via the DOM Level 2 factory methods, but is possible if other
mechanisms were used to obtain itpublic org.w3c.dom.Element getElementByID(String id, org.w3c.dom.Document doc)
Note that DOM Level 1 had no ability to retrieve this information. DOM Level 2 introduced it but does not promise that it will be supported in all DOMs; those which can't support it will always return null.
TODO: getElementByID is currently unimplemented. Support DOM Level 2?
id
- The unique identifier to be searched for.doc
- The document to search within.
public String getUnparsedEntityURI(String name, org.w3c.dom.Document doc)
XML processors may choose to use the System Identifier (if one is provided) to resolve the entity, rather than the URI in the Public Identifier. The details are dependent on the processor, and we would have to support some form of plug-in resolver to handle this properly. Currently, we simply return the System Identifier if present, and hope that it a usable URI or that our caller can map it to one. TODO: Resolve Public Identifiers... or consider changing function name.
If we find a relative URI reference, XML expects it to be resolved in terms of the base URI of the document. The DOM doesn't do that for us, and it isn't entirely clear whether that should be done here; currently that's pushed up to a higher levelof our application. (Note that DOM Level 1 didn't store the document's base URI.) TODO: Consider resolving Relative URIs.
(The DOM's statement that "An XML processor may choose to completely expand entities before the structure model is passed to the DOM" refers only to parsed entities, not unparsed, and hence doesn't affect this function.)
name
- A string containing the Entity Name of the unparsed
entity.doc
- Document node for the document to be searched.
private static org.w3c.dom.Node locateAttrParent(org.w3c.dom.Element elem, org.w3c.dom.Node attr)
The DOM Level 1 developers expected that folks would keep track of the last Element they'd seen and could recover the info from that source. Obviously that doesn't work very well if the only information you've been presented with is the Attr. The DOM Level 2 getOwnerElement() method fixes that, but only for Level 2 and later DOMs.
elem
- Element whose subtree is to be searched for this Attrattr
- Attr whose owner is to be located.
public void setDOMFactory(org.w3c.dom.Document domFactory)
domFactory
- The DOM Document Node within whose context
the result tree will be built.public org.w3c.dom.Document getDOMFactory()
public static String getNodeData(org.w3c.dom.Node node)
node
- DOM Node to be examined
getNodeData(Node,FastStringBuffer)
public static void getNodeData(org.w3c.dom.Node node, FastStringBuffer buf)
There are open questions regarding whitespace stripping. Currently we make no special effort in that regard, since the standard DOM doesn't yet provide DTD-based information to distinguish whitespace-in-element-context from genuine #PCDATA. Note that we should probably also consider xml:space if/when we address this. DOM Level 3 may solve the problem for us.
node
- Node whose subtree is to be walked, gathering the
contents of all Text or CDATASection nodes.buf
- FastStringBuffer into which the contents of the text
nodes are to be concatenated.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |