gnu.xml.dom.html2

Class DomHTMLDocument

Implemented Interfaces:
Cloneable, Comparable<T>, Document, DocumentEvent, DocumentTraversal, EventTarget, HTMLDocument, Node, NodeList, XPathEvaluator

public class DomHTMLDocument
extends DomDocument
implements HTMLDocument

An HTML document. This is the factory object used to create HTML elements.

Fields inherited from interface org.w3c.dom.Node

ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE

Constructor Summary

DomHTMLDocument()
Convenience constructor.
DomHTMLDocument(DomHTMLImpl impl)
Constructor.

Method Summary

void
close()
Closes a document stream opened by open() and forces rendering.
Element
createElement(String tagName)
Creates an element of the type specified.
Element
createElementNS(String uri, String qName)
Creates an element of the given qualified name and namespace URI.
HTMLCollection
getAnchors()
A collection of all the anchor (A) elements in a document with a value for the name attribute.
HTMLCollection
getApplets()
A collection of all the OBJECT elements that include applets and APPLET (deprecated) elements in a document.
HTMLElement
getBody()
The element that contains the content for the document.
String
getCookie()
This mutable string attribute denotes persistent state information that (1) is associated with the current frame or document and (2) is composed of information described by the cookies non-terminal of [IETF RFC 2965], Section 4.2.2.
String
getDomain()
The domain name of the server that served the document, or null if the server cannot be identified by a domain name.
NodeList
getElementsByName(String name)
With [HTML 4.01] documents, this method returns the (possibly empty) collection of elements whose name value is given by elementName.
HTMLCollection
getForms()
A collection of all the forms of a document.
HTMLCollection
getImages()
A collection of all the IMG elements in a document.
HTMLCollection
getLinks()
A collection of all AREA elements and anchor ( A) elements in a document with a value for the href attribute.
String
getReferrer()
Returns the URI [IETF RFC 2396] of the page that linked to this page.
String
getTitle()
The title of a document as specified by the TITLE element in the head of the document.
String
getURL()
The absolute URI [IETF RFC 2396] of the document.
void
open()
Open a document stream for writing.
void
setBody(HTMLElement body)
The element that contains the content for the document.
void
setCookie(String cookie)
This mutable string attribute denotes persistent state information that (1) is associated with the current frame or document and (2) is composed of information described by the cookies non-terminal of [IETF RFC 2965], Section 4.2.2.
void
setTitle(String title)
The title of a document as specified by the TITLE element in the head of the document.
void
write(String text)
Write a string of text to a document stream opened by open().
void
writeln(String text)
Write a string of text followed by a newline character to a document stream opened by open().

Methods inherited from class gnu.xml.dom.DomDocument

adoptNode, appendChild, createAttribute, createAttributeNS, createCDATASection, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEntityReference, createExpression, createNSResolver, createNodeIterator, createProcessingInstruction, createTextNode, createTextNode, createTreeWalker, evaluate, getBaseURI, getDoctype, getDocumentElement, getDocumentURI, getDomConfig, getElementById, getImplementation, getInputEncoding, getNodeName, getStrictErrorChecking, getXmlEncoding, getXmlStandalone, getXmlVersion, importNode, insertBefore, isDefaultNamespace, isEqualNode, lookupNamespaceURI, lookupPrefix, normalizeDocument, renameNode, replaceChild, setBuilding, setCheckWellformedness, setCheckingCharacters, setDefaultAttributes, setDocumentURI, setInputEncoding, setStrictErrorChecking, setXmlEncoding, setXmlStandalone, setXmlVersion, verifyXmlName

Methods inherited from class gnu.xml.dom.DomNode

addEventListener, appendChild, clone, cloneNode, compact, compareDocumentPosition, compareTo, createEvent, dispatchEvent, getAttributes, getBaseURI, getChildNodes, getElementsByTagName, getElementsByTagNameNS, getFeature, getFirstChild, getLastChild, getLength, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isReadonly, isSameNode, isSupported, item, list, lookupNamespaceURI, lookupPrefix, makeReadonly, nameAndTypeEquals, normalize, removeChild, removeEventListener, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData, toString, trimToSize

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

DomHTMLDocument

public DomHTMLDocument()
Convenience constructor.

DomHTMLDocument

public DomHTMLDocument(DomHTMLImpl impl)
Constructor. This is called by the DOMImplementation.

Method Details

close

public void close()
Closes a document stream opened by open() and forces rendering.
Specified by:
close in interface HTMLDocument

createElement

public Element createElement(String tagName)
Creates an element of the type specified. Note that the instance returned implements the Element interface, so attributes can be specified directly on the returned object.
In addition, if there are known attributes with default values, Attr nodes representing them are automatically created and attached to the element.
To create an element with a qualified name and namespace URI, use the createElementNS method.
Specified by:
createElement in interface Document
Overrides:
createElement in interface DomDocument
Parameters:
tagName - The name of the element type to instantiate. For XML, this is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use. In that case, the name is mapped to the canonical form of that markup 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 is not an XML name according to the XML version in use specified in the Document.xmlVersion attribute.

createElementNS

public Element createElementNS(String uri,
                               String qName)
Creates an element of the given qualified name and namespace URI.
Per [XML Namespaces] , applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.
Specified by:
createElementNS in interface Document
Overrides:
createElementNS in interface DomDocument
Parameters:
Returns:
A new Element object with the following attributes:
AttributeValue
Node.nodeName qualifiedName
Node.namespaceURI namespaceURI
Node.prefixprefix, extracted from qualifiedName, or null if there is no prefix
Node.localNamelocal name, extracted from qualifiedName
Element.tagName qualifiedName
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualifiedName is not an XML name according to the XML version in use specified in the Document.xmlVersion attribute.
NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified name, 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" [XML Namespaces] , or if the qualifiedName or its prefix is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/", or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the qualifiedName nor its prefix is "xmlns".
NOT_SUPPORTED_ERR: Always thrown if the current document does not support the "XML" feature, since namespaces were defined by XML.
Since:
DOM Level 2

getAnchors

public HTMLCollection getAnchors()
A collection of all the anchor (A) elements in a document with a value for the name attribute. For reasons of backward compatibility, the returned set of anchors only contains those anchors created with the name attribute, not those created with the id attribute. Note that in [XHTML 1.0], the name attribute (see section 4.10) has no semantics and is only present for legacy user agents: the id attribute is used instead. Users should prefer the iterator mechanisms provided by [DOM Level 2 Traversal] instead.
Specified by:
getAnchors in interface HTMLDocument

getApplets

public HTMLCollection getApplets()
A collection of all the OBJECT elements that include applets and APPLET (deprecated) elements in a document.
Specified by:
getApplets in interface HTMLDocument

getBody

public HTMLElement getBody()
The element that contains the content for the document. In documents with BODY contents, returns the BODY element. In frameset documents, this returns the outermost FRAMESET element.
Specified by:
getBody in interface HTMLDocument

getCookie

public String getCookie()
This mutable string attribute denotes persistent state information that (1) is associated with the current frame or document and (2) is composed of information described by the cookies non-terminal of [IETF RFC 2965], Section 4.2.2.
If no persistent state information is available for the current frame or document document, then this property's value is an empty string.
When this attribute is read, all cookies are returned as a single string, with each cookie's name-value pair concatenated into a list of name-value pairs, each list item being separated by a ';' (semicolon).
When this attribute is set, the value it is set to should be a string that adheres to the cookie non-terminal of [IETF RFC 2965]; that is, it should be a single name-value pair followed by zero or more cookie attribute values. If no domain attribute is specified, then the domain attribute for the new value defaults to the host portion of an absolute URI [IETF RFC 2396] of the current frame or document. If no path attribute is specified, then the path attribute for the new value defaults to the absolute path portion of the URI [IETF RFC 2396] of the current frame or document. If no max-age attribute is specified, then the max-age attribute for the new value defaults to a user agent defined value. If a cookie with the specified name is already associated with the current frame or document, then the new value as well as the new attributes replace the old value and attributes. If a max-age attribute of 0 is specified for the new value, then any existing cookies of the specified name are removed from the cookie storage. See [IETF RFC 2965] for the semantics of persistent state item attribute value pairs. The precise nature of a user agent session is not defined by this specification.
Specified by:
getCookie in interface HTMLDocument

getDomain

public String getDomain()
The domain name of the server that served the document, or null if the server cannot be identified by a domain name.
Specified by:
getDomain in interface HTMLDocument

getElementsByName

public NodeList getElementsByName(String name)
With [HTML 4.01] documents, this method returns the (possibly empty) collection of elements whose name value is given by elementName. In [XHTML 1.0] documents, this methods only return the (possibly empty) collection of form controls with matching name. This method is case sensitive.
Specified by:
getElementsByName in interface HTMLDocument
Parameters:
Returns:
The matching elements.

getForms

public HTMLCollection getForms()
A collection of all the forms of a document.
Specified by:
getForms in interface HTMLDocument

getImages

public HTMLCollection getImages()
A collection of all the IMG elements in a document. The behavior is limited to IMG elements for backwards compatibility. As suggested by [HTML 4.01], to include images, authors may use the OBJECT element or the IMG element. Therefore, it is recommended not to use this attribute to find the images in the document but getElementsByTagName with HTML 4.01 or getElementsByTagNameNS with XHTML 1.0.
Specified by:
getImages in interface HTMLDocument

getLinks

public HTMLCollection getLinks()
A collection of all AREA elements and anchor ( A) elements in a document with a value for the href attribute.
Specified by:
getLinks in interface HTMLDocument

getReferrer

public String getReferrer()
Returns the URI [IETF RFC 2396] of the page that linked to this page. The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark).
Specified by:
getReferrer in interface HTMLDocument

getTitle

public String getTitle()
The title of a document as specified by the TITLE element in the head of the document.
Specified by:
getTitle in interface HTMLDocument

getURL

public String getURL()
The absolute URI [IETF RFC 2396] of the document.
Specified by:
getURL in interface HTMLDocument

open

public void open()
Open a document stream for writing. If a document exists in the target, this method clears it. This method and the ones following allow a user to add to or replace the structure model of a document using strings of unparsed HTML. At the time of writing alternate methods for providing similar functionality for both HTML and XML documents were being considered (see [DOM Level 3 Load and Save]).
Specified by:
open in interface HTMLDocument

setBody

public void setBody(HTMLElement body)
The element that contains the content for the document. In documents with BODY contents, returns the BODY element. In frameset documents, this returns the outermost FRAMESET element.
Specified by:
setBody in interface HTMLDocument

setCookie

public void setCookie(String cookie)
This mutable string attribute denotes persistent state information that (1) is associated with the current frame or document and (2) is composed of information described by the cookies non-terminal of [IETF RFC 2965], Section 4.2.2.
If no persistent state information is available for the current frame or document document, then this property's value is an empty string.
When this attribute is read, all cookies are returned as a single string, with each cookie's name-value pair concatenated into a list of name-value pairs, each list item being separated by a ';' (semicolon).
When this attribute is set, the value it is set to should be a string that adheres to the cookie non-terminal of [IETF RFC 2965]; that is, it should be a single name-value pair followed by zero or more cookie attribute values. If no domain attribute is specified, then the domain attribute for the new value defaults to the host portion of an absolute URI [IETF RFC 2396] of the current frame or document. If no path attribute is specified, then the path attribute for the new value defaults to the absolute path portion of the URI [IETF RFC 2396] of the current frame or document. If no max-age attribute is specified, then the max-age attribute for the new value defaults to a user agent defined value. If a cookie with the specified name is already associated with the current frame or document, then the new value as well as the new attributes replace the old value and attributes. If a max-age attribute of 0 is specified for the new value, then any existing cookies of the specified name are removed from the cookie storage. See [IETF RFC 2965] for the semantics of persistent state item attribute value pairs. The precise nature of a user agent session is not defined by this specification.
Specified by:
setCookie in interface HTMLDocument
Throws:
DOMException - SYNTAX_ERR: If the new value does not adhere to the cookie syntax specified by [IETF RFC 2965].

setTitle

public void setTitle(String title)
The title of a document as specified by the TITLE element in the head of the document.
Specified by:
setTitle in interface HTMLDocument

write

public void write(String text)
Write a string of text to a document stream opened by open(). Note that the function will produce a document which is not necessarily driven by a DTD and therefore might be produce an invalid result in the context of the document.
Specified by:
write in interface HTMLDocument
Parameters:
text - The string to be parsed into some structure in the document structure model.

writeln

public void writeln(String text)
Write a string of text followed by a newline character to a document stream opened by open(). Note that the function will produce a document which is not necessarily driven by a DTD and therefore might be produce an invalid result in the context of the document
Specified by:
writeln in interface HTMLDocument
Parameters:
text - The string to be parsed into some structure in the document structure model.

DomHTMLDocument.java -- Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.