Java Doc for DOMHelper.java in  » XML » xalan » org » apache » xml » utils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML » xalan » org.apache.xml.utils 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.xml.utils.DOMHelper

All known Subclasses:   org.apache.xml.utils.DOM2Helper,
DOMHelper
public class DOMHelper (Code)


Field Summary
protected  Documentm_DOMFactory
     The factory object used for creating nodes in the result tree.
final protected static  NSInfom_NSInfoNullNoAncestorXMLNS
     Object to put into the m_NSInfos table that tells that a node has been processed, and has no xmlns namespace decls.
final protected static  NSInfom_NSInfoNullWithXMLNS
     Object to put into the m_NSInfos table that tells that a node has been processed, and has xmlns namespace decls.
final protected static  NSInfom_NSInfoNullWithoutXMLNS
     Object to put into the m_NSInfos table that tells that a node has been processed, and has no xmlns namespace decls.
final protected static  NSInfom_NSInfoUnProcNoAncestorXMLNS
     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.
final protected static  NSInfom_NSInfoUnProcWithXMLNS
     Object to put into the m_NSInfos table that tells that a node has not been processed, but has xmlns namespace decls.
final protected static  NSInfom_NSInfoUnProcWithoutXMLNS
     Object to put into the m_NSInfos table that tells that a node has not been processed, but has no xmlns namespace decls.
 Hashtablem_NSInfos
     An experiment for the moment.
protected  Vectorm_candidateNoAncestorXMLNS
     Vector of node (odd indexes) and NSInfos (even indexes) that tell if the given node is a candidate for ancestor namespace processing.


Method Summary
public static  DocumentcreateDocument(boolean isSecureProcessing)
     DOM Level 1 did not have a standard mechanism for creating a new Document object.
public static  DocumentcreateDocument()
     DOM Level 1 did not have a standard mechanism for creating a new Document object.
public  DocumentgetDOMFactory()
     Retrieve the factory object required to create DOM nodes in the result tree.
public  ElementgetElementByID(String id, Document doc)
     Given an ID, return the element.
public  StringgetExpandedAttributeName(Attr attr)
     Returns the attribute name with the namespace prefix (if any) replaced by the Namespace URI it was bound to.
public  StringgetExpandedElementName(Element elem)
     Returns the element name with the namespace prefix (if any) replaced by the Namespace URI it was bound to.
public  shortgetLevel(Node n)
     Get the depth level of this node in the tree (equals 1 for a parentless node).
Parameters:
  n - Node to be examined.
public  StringgetLocalNameOfNode(Node n)
     Returns the local name of the given node.
public  StringgetNamespaceForPrefix(String prefix, Element namespaceContext)
     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.
public  StringgetNamespaceOfNode(Node n)
     Returns the namespace of the given node.
public static  StringgetNodeData(Node node)
     Get the textual contents of the node.
public static  voidgetNodeData(Node node, FastStringBuffer buf)
     Retrieve the text content of a DOM subtree, appending it into a user-supplied FastStringBuffer object.
public static  NodegetParentOfNode(Node node)
     Obtain the XPath-model parent of a DOM node -- ownerElement for Attrs, parent for other nodes.
public  NodegetRoot(Node node)
     Get the first unparented node in the ancestor chain.
public  NodegetRootNode(Node n)
     Get the root node of the document tree, regardless of whether or not the node passed in is a document node.

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.

public  StringgetUniqueID(Node node)
     Supports the XPath function GenerateID by returning a unique identifier string for any given DOM Node.

Warning: The base implementation uses the Node object's hashCode(), which is NOT guaranteed to be unique.

public  StringgetUnparsedEntityURI(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]).
public  booleanisIgnorableWhitespace(Text node)
     Tell if the node is ignorable whitespace.
public  booleanisNamespaceNode(Node n)
     Test whether the given node is a namespace decl node.
public static  booleanisNodeAfter(Node node1, Node node2)
     Figure out whether node2 should be considered as being later in the document than node1, in Document Order as defined by the XPath model.
public static  booleanisNodeTheSame(Node node1, Node node2)
     Use DTMNodeProxy to determine whether two nodes are the same.
Parameters:
  node1 - The first DOM node to compare.
Parameters:
  node2 - The second DOM node to compare.
public  voidsetDOMFactory(Document domFactory)
     Store the factory object required to create DOM nodes in the result tree.
public  booleanshouldStripSourceNode(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.

Field Detail
m_DOMFactory
protected Document m_DOMFactory(Code)
The factory object used for creating nodes in the result tree.



m_NSInfoNullNoAncestorXMLNS
final protected static NSInfo m_NSInfoNullNoAncestorXMLNS(Code)
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.



m_NSInfoNullWithXMLNS
final protected static NSInfo m_NSInfoNullWithXMLNS(Code)
Object to put into the m_NSInfos table that tells that a node has been processed, and has xmlns namespace decls.



m_NSInfoNullWithoutXMLNS
final protected static NSInfo m_NSInfoNullWithoutXMLNS(Code)
Object to put into the m_NSInfos table that tells that a node has been processed, and has no xmlns namespace decls.



m_NSInfoUnProcNoAncestorXMLNS
final protected static NSInfo m_NSInfoUnProcNoAncestorXMLNS(Code)
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.



m_NSInfoUnProcWithXMLNS
final protected static NSInfo m_NSInfoUnProcWithXMLNS(Code)
Object to put into the m_NSInfos table that tells that a node has not been processed, but has xmlns namespace decls.



m_NSInfoUnProcWithoutXMLNS
final protected static NSInfo m_NSInfoUnProcWithoutXMLNS(Code)
Object to put into the m_NSInfos table that tells that a node has not been processed, but has no xmlns namespace decls.



m_NSInfos
Hashtable m_NSInfos(Code)
An experiment for the moment.



m_candidateNoAncestorXMLNS
protected Vector m_candidateNoAncestorXMLNS(Code)
Vector of node (odd indexes) and NSInfos (even indexes) that tell if the given node is a candidate for ancestor namespace processing.





Method Detail
createDocument
public static Document createDocument(boolean isSecureProcessing)(Code)
DOM Level 1 did not have a standard mechanism for creating a new Document object. This function provides a DOM-implementation-independent abstraction for that for that concept. It's typically used when outputting a new DOM as the result of an operation.

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.)
Parameters:
  isSecureProcessing - state of the secure processing feature. The newly created DOM Document object, with no children, ornull if we can't find a DOM implementation that permits creatingnew empty Documents.




createDocument
public static Document createDocument()(Code)
DOM Level 1 did not have a standard mechanism for creating a new Document object. This function provides a DOM-implementation-independent abstraction for that for that concept. It's typically used when outputting a new DOM as the result of an operation. The newly created DOM Document object, with no children, ornull if we can't find a DOM implementation that permits creatingnew empty Documents.



getDOMFactory
public Document getDOMFactory()(Code)
Retrieve the factory object required to create DOM nodes in the result tree. The result tree's DOM Document Node.



getElementByID
public Element getElementByID(String id, Document doc)(Code)
Given an ID, return the element. This can work only if the document is interpreted in the context of a DTD or Schema, since otherwise we don't know which attributes are or aren't IDs.

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?
Parameters:
  id - The unique identifier to be searched for.
Parameters:
  doc - The document to search within. CURRENTLY HARDCODED TO NULL, but it should be:The node which has this unique identifier, or null if thereis no such node or this DOM can't reliably recognize it.




getExpandedAttributeName
public String getExpandedAttributeName(Attr attr)(Code)
Returns the attribute name with the namespace prefix (if any) replaced by the Namespace URI it was bound to. This is not a standard representation of a node name, but it allows convenient single-string comparison of the "universal" names of two nodes.
Parameters:
  attr - Attr to be examined String in the form "namespaceURI:localname" if the nodebelongs to a namespace, or simply "localname" if it doesn't.
See Also:   DOMHelper.getExpandedElementName



getExpandedElementName
public String getExpandedElementName(Element elem)(Code)
Returns the element name with the namespace prefix (if any) replaced by the Namespace URI it was bound to. This is not a standard representation of a node name, but it allows convenient single-string comparison of the "universal" names of two nodes.
Parameters:
  elem - Element to be examined. String in the form "namespaceURI:localname" if the nodebelongs to a namespace, or simply "localname" if it doesn't.
See Also:   DOMHelper.getExpandedAttributeName



getLevel
public short getLevel(Node n)(Code)
Get the depth level of this node in the tree (equals 1 for a parentless node).
Parameters:
  n - Node to be examined. the number of ancestors, plus one



getLocalNameOfNode
public String getLocalNameOfNode(Node n)(Code)
Returns the local name of the given node. If the node's name begins with a namespace prefix, this is the part after the colon; otherwise it's the full node name.
Parameters:
  n - the node to be examined. String containing the Local Name



getNamespaceForPrefix
public String getNamespaceForPrefix(String prefix, Element namespaceContext)(Code)
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. Note that DOM Level 3 is expected to provide a version of this which deals with the DOM's "early binding" behavior. Default handling:
Parameters:
  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 namespaceat this point in the document.
Parameters:
  namespaceContext - Element which provides context for resolution.(We could extend this to work for other nodes by first seeking theirnearest Element ancestor.) a String containing the Namespace URI which this prefixrepresents in the specified context.



getNamespaceOfNode
public String getNamespaceOfNode(Node n)(Code)
Returns the namespace of the given node. Differs from simply getting the node's prefix and using getNamespaceForPrefix in that it attempts to cache some of the data in NSINFO objects, to avoid repeated lookup. TODO: Should we consider moving that logic into getNamespaceForPrefix?
Parameters:
  n - Node to be examined. String containing the Namespace Name (uri) for this node.Note that this is undefined for any nodes other than Elements andAttributes.



getNodeData
public static String getNodeData(Node node)(Code)
Get the textual contents of the node. See getNodeData(Node,FastStringBuffer) for discussion of how whitespace nodes are handled.
Parameters:
  node - DOM Node to be examined String containing a concatenation of all the textual content within that node.
See Also:   DOMHelper.getNodeData(Node,FastStringBuffer)



getNodeData
public static void getNodeData(Node node, FastStringBuffer buf)(Code)
Retrieve the text content of a DOM subtree, appending it into a user-supplied FastStringBuffer object. Note that attributes are not considered part of the content of an element.

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.
Parameters:
  node - Node whose subtree is to be walked, gathering thecontents of all Text or CDATASection nodes.
Parameters:
  buf - FastStringBuffer into which the contents of the textnodes are to be concatenated.




getParentOfNode
public static Node getParentOfNode(Node node) throws RuntimeException(Code)
Obtain the XPath-model parent of a DOM node -- ownerElement for Attrs, parent for other nodes.

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)


Parameters:
  node - Node whose XPath parent we want to obtain the parent of the node, or the ownerElement if it's anAttr node, or null if the node is an orphan.
throws:
  RuntimeException - if the Document has no root element.This can't arise if the Document was createdvia the DOM Level 2 factory methods, but is possible if othermechanisms were used to obtain it




getRoot
public Node getRoot(Node node)(Code)
Get the first unparented node in the ancestor chain.
Parameters:
  node - Starting node, to specify which chain to chase the topmost ancestor.



getRootNode
public Node getRootNode(Node n)(Code)
Get the root node of the document tree, regardless of whether or not the node passed in is a document node.

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.
Parameters:
  n - Node to be examined the Document node. Note that this is not the correct answerif n was (or was a child of) a DocumentFragment or an orphaned node,as can arise if the DOM has been edited rather than being generatedby a parser.




getUniqueID
public String getUniqueID(Node node)(Code)
Supports the XPath function GenerateID by returning a unique identifier string for any given DOM 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.)
Parameters:
  node - whose identifier you want to obtain a string which should be different for every Node object.




getUnparsedEntityURI
public String getUnparsedEntityURI(String name, Document doc)(Code)
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.

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.)
Parameters:
  name - A string containing the Entity Name of the unparsedentity.
Parameters:
  doc - Document node for the document to be searched. String containing the URI of the Unparsed Entity, or anempty string if no such entity exists.




isIgnorableWhitespace
public boolean isIgnorableWhitespace(Text node)(Code)
Tell if the node is ignorable whitespace. Note that this can be determined only in the context of a DTD or other Schema, and that DOM Level 2 has nostandardized DOM API which can return that information.
Parameters:
  node - Node to be examined CURRENTLY HARDCODED TO FALSE, but should return true ifand only if the node is of type Text, contains only whitespace,and does not appear as part of the #PCDATA content of an element.(Note that determining this last may require allowing for Entity References.)



isNamespaceNode
public boolean isNamespaceNode(Node n)(Code)
Test whether the given node is a namespace decl node. In DOM Level 2 this can be done in a namespace-aware manner, but in Level 1 DOMs it has to be done by testing the node name.
Parameters:
  n - Node to be examined. boolean -- true iff the node is an Attr whose name is "xmlns" or has the "xmlns:" prefix.



isNodeAfter
public static boolean isNodeAfter(Node node1, Node node2)(Code)
Figure out whether node2 should be considered as being later in the document than node1, in Document Order as defined by the XPath model. This may not agree with the ordering defined by other XML applications.

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!!!
Parameters:
  node1 - DOM Node to perform position comparison on.
Parameters:
  node2 - DOM Node to perform position comparison on . false if node2 comes before node1, otherwise return true.You can think of this as (node1.documentOrderPosition <= node2.documentOrderPosition).




isNodeTheSame
public static boolean isNodeTheSame(Node node1, Node node2)(Code)
Use DTMNodeProxy to determine whether two nodes are the same.
Parameters:
  node1 - The first DOM node to compare.
Parameters:
  node2 - The second DOM node to compare. true if the two nodes are the same.



setDOMFactory
public void setDOMFactory(Document domFactory)(Code)
Store the factory object required to create DOM nodes in the result tree. In fact, that's just the result tree's Document node...
Parameters:
  domFactory - The DOM Document Node within whose contextthe result tree will be built.



shouldStripSourceNode
public boolean shouldStripSourceNode(Node textNode) throws javax.xml.transform.TransformerException(Code)
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. true if the text node should be stripped of extra whitespace.
throws:
  javax.xml.transform.TransformerException -



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.