com.caucho.xml
Class QDocument

java.lang.Object
  |
  +--com.caucho.xml.QAbstractNode
        |
        +--com.caucho.xml.QNode
              |
              +--com.caucho.xml.QDocumentFragment
                    |
                    +--com.caucho.xml.QDocument
All Implemented Interfaces:
CauchoDocument, CauchoNode, Document, DocumentFragment, Node, NodeList

public class QDocument
extends com.caucho.xml.QDocumentFragment
implements CauchoDocument

Implements the top-level document for the XML tree.


Field Summary
protected  Document masterDoc
           
 
Fields inherited from class com.caucho.xml.QAbstractNode
L
 
Fields inherited from interface com.caucho.xml.CauchoDocument
DEPENDS
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
QDocument()
           
 
Method Summary
 void addDepend(Path path)
           
 void addNamespace(java.lang.String prefix, java.lang.String url)
          Add a namespace declaration to a document.
 Node appendChild(Node newChild)
          Adds the node newChild to the end of the list of children of this node.
 Node cloneNode(boolean deep)
          Returns a clone of the document.
protected  Node copyNode(QDocument newNode, boolean deep)
           
static Document create()
           
 Attr createAttribute(QName name, java.lang.String value)
          Creates a new namespace-aware attribute
 Attr createAttribute(java.lang.String name)
          Creates an Attr of the given name.
 Attr createAttribute(java.lang.String name, java.lang.String value)
           
 Attr createAttribute(java.lang.String prefix, java.lang.String local, java.lang.String url)
          Creates a new namespace-aware attribute
 Attr createAttributeNS(java.lang.String uri, java.lang.String qname)
          Creates a new namespace-aware attribute
 CDATASection createCDATASection(java.lang.String data)
          Creates a CDATASection node whose value is the specified string.
 Comment createComment(java.lang.String data)
          Creates a Comment node given the specified string.
 DocumentFragment createDocumentFragment()
          Creates a new document fragment.
 Element createElement(java.lang.String tagName)
          Creates a new element
 Element createElement(java.lang.String prefix, java.lang.String local, java.lang.String url)
          Creates a new namespace-aware element
 Element createElementByName(QName name)
          Creates a new namespace-aware element
 Element createElementNS(java.lang.String namespaceURI, java.lang.String name)
          Creates a new namespace-aware element
 EntityReference createEntityReference(java.lang.String name)
          Creates an EntityReference object.
 QName createName(java.lang.String uri, java.lang.String name)
           
 ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data)
          Creates a ProcessingInstruction node given the specified name and data strings.
 Text createTextNode(java.lang.String data)
          Creates a new text node in this document.
 Text createUnescapedTextNode(java.lang.String data)
           
 DocumentType getDoctype()
          The Document Type Declaration (see DocumentType) associated with this document.
 Element getDocumentElement()
          This is a convenience attribute that allows direct access to the child node that is the root element of the document.
 Element getElementById(java.lang.String name)
          Returns the Element whose ID is given by elementId.
 NodeList getElementsByTagName(java.lang.String name)
          Returns a list of elements, filtered by the tag name.
 NodeList getElementsByTagNameNS(java.lang.String uri, java.lang.String name)
          Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of the Document tree.
 java.lang.String getEncoding()
           
 DOMImplementation getImplementation()
          The DOMImplementation object that handles this document.
 Document getMasterDoc()
           
 java.lang.String getNamespace(java.lang.String prefix)
          Returns the namespace url for a given prefix.
 java.util.Iterator getNamespaceKeys()
          Returns an iterator of top-level namespace prefixes.
 java.util.HashMap getNamespaces()
           
 java.lang.String getNodeName()
          The node name for the document is #document.
 short getNodeType()
          A code representing the type of the underlying object, as defined above.
 Document getOwnerDocument()
          The Document object associated with this node.
 java.lang.Object getProperty(java.lang.String name)
           
 java.lang.String getRootFilename()
           
 java.lang.String getTextValue()
          Returns the text value of the node
 Node importNode(Node node, boolean deep)
          Imports a copy of a node into the current document.
 boolean isSupported(java.lang.String feature, java.lang.String version)
          Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
 Node removeChild(Node oldChild)
          Removes the child node indicated by oldChild from the list of children, and returns it.
 void setDoctype(DocumentType dtd)
           
 void setDocumentElement(Element elt)
           
 void setProperty(java.lang.String name, java.lang.Object value)
           
 void setRootFilename(java.lang.String filename)
           
 java.lang.String toString()
           
 
Methods inherited from class com.caucho.xml.QNode
checkValid, equals, equals, getAttributes, getChildNodes, getFirstChild, getLastChild, getLength, getNextPreorder, getNextSibling, getNodeValue, getPreviousSibling, hasChildNodes, insertBefore, item, normalize, replaceChild, setNodeValue
 
Methods inherited from class com.caucho.xml.QAbstractNode
getCanonicalName, getColumn, getFilename, getLine, getLocalName, getNamespaceURI, getNextContent, getParentNode, getPrefix, getPreviousContent, hasAttributes, hasContent, print, printHtml, printPretty, setLocation, setPrefix, supports
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Node
getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, insertBefore, normalize, replaceChild, setNodeValue, setPrefix
 
Methods inherited from interface com.caucho.xml.CauchoNode
checkValid, getCanonicalName, getColumn, getFilename, getLine, getLocalName, getNamespaceURI, getPrefix, getTextValue, print, printHtml, printPretty, setLocation
 

Field Detail

masterDoc

protected Document masterDoc
Constructor Detail

QDocument

public QDocument()
Method Detail

getRootFilename

public java.lang.String getRootFilename()

setRootFilename

public void setRootFilename(java.lang.String filename)

getOwnerDocument

public Document getOwnerDocument()
Description copied from interface: Node
The Document object associated with this node. This is also the Document object used to create new nodes. When this node is a Document or a DocumentType which is not used with any Document yet, this is null.
Specified by:
getOwnerDocument in interface Node
Overrides:
getOwnerDocument in class QAbstractNode

isSupported

public boolean isSupported(java.lang.String feature,
                           java.lang.String version)
Description copied from interface: Node
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
Specified by:
isSupported in interface Node
Overrides:
isSupported in class QAbstractNode
Following copied from interface: org.w3c.dom.Node
Parameters:
feature - The name of the feature to test. This is the same name which can be passed to the method hasFeature on DOMImplementation.
version - This is the version number of the feature to test. In Level 2, version 1, this is the string "2.0". If the version is not specified, supporting any version of the feature will cause the method to return true.
Returns:
Returns true if the specified feature is supported on this node, false otherwise.

getNodeName

public java.lang.String getNodeName()
The node name for the document is #document.
Specified by:
getNodeName in interface Node
Overrides:
getNodeName in class com.caucho.xml.QDocumentFragment

getNodeType

public short getNodeType()
Description copied from interface: Node
A code representing the type of the underlying object, as defined above.
Specified by:
getNodeType in interface Node
Overrides:
getNodeType in class com.caucho.xml.QDocumentFragment

copyNode

protected Node copyNode(QDocument newNode,
                        boolean deep)

cloneNode

public Node cloneNode(boolean deep)
Returns a clone of the document.
Specified by:
cloneNode in interface Node
Overrides:
cloneNode in class QAbstractNode
Parameters:
deep - if true, recursively copy the document.

importNode

public Node importNode(Node node,
                       boolean deep)
Imports a copy of a node into the current document.
Specified by:
importNode in interface Document
Parameters:
node - the node to import/copy
deep - if true, recursively copy the children.
Returns:
the new imported node.

getDoctype

public DocumentType getDoctype()
Description copied from interface: Document
The Document Type Declaration (see DocumentType) associated with this document. For HTML documents as well as XML documents without a document type declaration this returns null. The DOM Level 2 does not support editing the Document Type Declaration. docType cannot be altered in any way, including through the use of methods inherited from the Node interface, such as insertNode or removeNode.
Specified by:
getDoctype in interface Document

setDoctype

public void setDoctype(DocumentType dtd)

getEncoding

public java.lang.String getEncoding()

getImplementation

public DOMImplementation getImplementation()
Description copied from interface: Document
The DOMImplementation object that handles this document. A DOM application may use objects from multiple implementations.
Specified by:
getImplementation in interface Document

getDocumentElement

public Element getDocumentElement()
Description copied from interface: Document
This is a convenience attribute that allows direct access to the child node that is the root element of the document. For HTML documents, this is the element with the tagName "HTML".
Specified by:
getDocumentElement in interface Document

setDocumentElement

public void setDocumentElement(Element elt)

createElement

public Element createElement(java.lang.String tagName)
                      throws DOMException
Creates a new element
Specified by:
createElement in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
tagName - The name of the element type to instantiate. For XML, this is case-sensitive. For HTML, the tagName parameter may be provided in any case, but it must be mapped to the canonical uppercase form by the DOM implementation.
Returns:
A new Element object with the nodeName attribute set to tagName, and localName, prefix, and namespaceURI set to null.
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

createElementNS

public Element createElementNS(java.lang.String namespaceURI,
                               java.lang.String name)
                        throws DOMException
Creates a new namespace-aware element
Specified by:
createElementNS in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
namespaceURI - The namespace URI of the element to create.
qualifiedName - The qualified name of the element type to instantiate.
Returns:
A new Element object with the following attributes:
Attribute Value
Node.nodeName qualifiedName
Node.namespaceURI namespaceURI
Node.prefix prefix, extracted from qualifiedName, or null if there is no prefix
Node.localName local name, extracted from qualifiedName
Element.tagName qualifiedName
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character, per the XML 1.0 specification .
NAMESPACE_ERR: Raised if the qualifiedName is malformed per the Namespaces in XML specification, if the qualifiedName has a prefix and the namespaceURI is null, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from " http://www.w3.org/XML/1998/namespace" .
NOT_SUPPORTED_ERR: Always thrown if the current document does not support the "XML" feature, since namespaces were defined by XML.

createElement

public Element createElement(java.lang.String prefix,
                             java.lang.String local,
                             java.lang.String url)
                      throws DOMException
Creates a new namespace-aware element
Specified by:
createElement in interface CauchoDocument

createElementByName

public Element createElementByName(QName name)
                            throws DOMException
Creates a new namespace-aware element

createDocumentFragment

public DocumentFragment createDocumentFragment()
Creates a new document fragment.
Specified by:
createDocumentFragment in interface Document
Following copied from interface: org.w3c.dom.Document
Returns:
A new DocumentFragment.

createTextNode

public Text createTextNode(java.lang.String data)
Creates a new text node in this document.
Specified by:
createTextNode in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
data - The data for the node.
Returns:
The new Text object.

createUnescapedTextNode

public Text createUnescapedTextNode(java.lang.String data)
Specified by:
createUnescapedTextNode in interface CauchoDocument

createComment

public Comment createComment(java.lang.String data)
Description copied from interface: Document
Creates a Comment node given the specified string.
Specified by:
createComment in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
data - The data for the node.
Returns:
The new Comment object.

createCDATASection

public CDATASection createCDATASection(java.lang.String data)
Description copied from interface: Document
Creates a CDATASection node whose value is the specified string.
Specified by:
createCDATASection in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
data - The data for the CDATASection contents.
Returns:
The new CDATASection object.
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

createProcessingInstruction

public ProcessingInstruction createProcessingInstruction(java.lang.String target,
                                                         java.lang.String data)
                                                  throws DOMException
Description copied from interface: Document
Creates a ProcessingInstruction node given the specified name and data strings.
Specified by:
createProcessingInstruction in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
target - The target part of the processing instruction.
data - The data for the node.
Returns:
The new ProcessingInstruction object.
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified target contains an illegal character.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

createAttribute

public Attr createAttribute(java.lang.String name,
                            java.lang.String value)
                     throws DOMException

createAttribute

public Attr createAttribute(java.lang.String name)
                     throws DOMException
Description copied from interface: Document
Creates an Attr of the given name. Note that the Attr instance can then be set on an Element using the setAttributeNode method.
To create an attribute with a qualified name and namespace URI, use the createAttributeNS method.
Specified by:
createAttribute in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
name - The name of the attribute.
Returns:
A new Attr object with the nodeName attribute set to name, and localName, prefix, and namespaceURI set to null. The value of the attribute is the empty string.
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

createAttribute

public Attr createAttribute(java.lang.String prefix,
                            java.lang.String local,
                            java.lang.String url)
                     throws DOMException
Creates a new namespace-aware attribute
Specified by:
createAttribute in interface CauchoDocument

createAttributeNS

public Attr createAttributeNS(java.lang.String uri,
                              java.lang.String qname)
                       throws DOMException
Creates a new namespace-aware attribute
Specified by:
createAttributeNS in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
namespaceURI - The namespace URI of the attribute to create.
qualifiedName - The qualified name of the attribute to instantiate.
Returns:
A new Attr object with the following attributes:
Attribute Value
Node.nodeName qualifiedName
Node.namespaceURI namespaceURI
Node.prefix prefix, extracted from qualifiedName, or null if there is no prefix
Node.localName local name, extracted from qualifiedName
Attr.name qualifiedName
Node.nodeValue the empty string
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character, per the XML 1.0 specification .
NAMESPACE_ERR: Raised if the qualifiedName is malformed per the Namespaces in XML specification, if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from " http://www.w3.org/XML/1998/namespace", or if the qualifiedName, or its prefix, is "xmlns" and the namespaceURI is different from " http://www.w3.org/2000/xmlns/".
NOT_SUPPORTED_ERR: Always thrown if the current document does not support the "XML" feature, since namespaces were defined by XML.

createName

public QName createName(java.lang.String uri,
                        java.lang.String name)

createAttribute

public Attr createAttribute(QName name,
                            java.lang.String value)
                     throws DOMException
Creates a new namespace-aware attribute

createEntityReference

public EntityReference createEntityReference(java.lang.String name)
                                      throws DOMException
Description copied from interface: Document
Creates an EntityReference object. In addition, if the referenced entity is known, the child list of the EntityReference node is made the same as that of the corresponding Entity node.If any descendant of the Entity node has an unbound namespace prefix, the corresponding descendant of the created EntityReference node is also unbound; (its namespaceURI is null). The DOM Level 2 does not support any mechanism to resolve namespace prefixes.
Specified by:
createEntityReference in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
name - The name of the entity to reference.
Returns:
The new EntityReference object.
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

getElementsByTagName

public NodeList getElementsByTagName(java.lang.String name)
Returns a list of elements, filtered by the tag name.
Specified by:
getElementsByTagName in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
tagname - The name of the tag to match on. The special value "*" matches all tags.
Returns:
A new NodeList object containing all the matched Elements.

getElementsByTagNameNS

public NodeList getElementsByTagNameNS(java.lang.String uri,
                                       java.lang.String name)
Description copied from interface: Document
Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of the Document tree.
Specified by:
getElementsByTagNameNS in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
namespaceURI - The namespace URI of the elements to match on. The special value "*" matches all namespaces.
localName - The local name of the elements to match on. The special value "*" matches all local names.
Returns:
A new NodeList object containing all the matched Elements.

getElementById

public Element getElementById(java.lang.String name)
Description copied from interface: Document
Returns the Element whose ID is given by elementId. If no such element exists, returns null. Behavior is not defined if more than one element has this ID. The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null.
Specified by:
getElementById in interface Document
Following copied from interface: org.w3c.dom.Document
Parameters:
elementId - The unique id value for an element.
Returns:
The matching element.

create

public static Document create()

appendChild

public Node appendChild(Node newChild)
                 throws DOMException
Description copied from interface: Node
Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.
Specified by:
appendChild in interface Node
Overrides:
appendChild in class QNode
Following copied from interface: org.w3c.dom.Node
Parameters:
newChild - The node to add.If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node
Returns:
The node added.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to append is one of this node's ancestors or this node itself.
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or if the previous parent of the node being inserted is readonly.

removeChild

public Node removeChild(Node oldChild)
                 throws DOMException
Description copied from interface: Node
Removes the child node indicated by oldChild from the list of children, and returns it.
Specified by:
removeChild in interface Node
Overrides:
removeChild in class QNode
Following copied from interface: org.w3c.dom.Node
Parameters:
oldChild - The node being removed.
Returns:
The node removed.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised if oldChild is not a child of this node.

addNamespace

public void addNamespace(java.lang.String prefix,
                         java.lang.String url)
Add a namespace declaration to a document. If the declaration prefix already has a namespace, the old one wins.

getNamespaces

public java.util.HashMap getNamespaces()
Specified by:
getNamespaces in interface CauchoDocument

getNamespace

public java.lang.String getNamespace(java.lang.String prefix)
Returns the namespace url for a given prefix.

getNamespaceKeys

public java.util.Iterator getNamespaceKeys()
Returns an iterator of top-level namespace prefixes.

getProperty

public java.lang.Object getProperty(java.lang.String name)
Specified by:
getProperty in interface CauchoDocument

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
Specified by:
setProperty in interface CauchoDocument

addDepend

public void addDepend(Path path)

toString

public java.lang.String toString()
Overrides:
toString in class com.caucho.xml.QDocumentFragment

getMasterDoc

public Document getMasterDoc()

getTextValue

public java.lang.String getTextValue()
Description copied from interface: CauchoNode
Returns the text value of the node
Overrides:
getTextValue in class QAbstractNode