org.apache.tapestry5.dom

## Class Document

- java.lang.Object
- - org.apache.tapestry5.dom.Node
  - - org.apache.tapestry5.dom.Document

-     public final class Document
      extends Node

  The root node of a DOM.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `XML_NAMESPACE_URI` XML Namespace URI.
    `static String` | `XMLNS_NAMESPACE_URI` Namespace used exclusively for defining namespaces.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Document()` Builds with an instance of `DefaultMarkupModel`.
    `Document(MarkupModel model)` Same as Document(model, null).
    `Document(MarkupModel model, String encoding)` Same as Document(model, encoding, null).
    `Document(MarkupModel model, String encoding, String mimeType)` Creates a document instance with a given markup model, encoding and MIME type.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `CData` | `cdata(String content)` Adds and returns a new CDATA node.
    `Document` | `comment(String text)` Adds the comment and returns this document for further construction.
    `void` | `dtd(String name, String publicId, String systemId)` Sets the DTD for the document, overriding any prior DTD.
    `Element` | `find(String path)` Finds an element based on a path of element names.
    `Document` | `getDocument()`
    `Element` | `getElementById(String id)` Tries to find an element in this document whose id is specified.
    `MarkupModel` | `getMarkupModel()`
    `String` | `getMimeType()` Returns the MIME type of this document.
    `protected Map<String,String>` | `getNamespaceURIToPrefix()`
    `Element` | `getRootElement()`
    `boolean` | `hasDTD()` Returns true if the document has an explicit DTD (set via `dtd(String, String, String)`).
    `Element` | `newRootElement(String name)` Creates the root element for this document, replacing any previous root element.
    `Element` | `newRootElement(String namespace, String name)` Creates a new root element within a namespace.
    `Document` | `raw(String text)` Adds the raw text and returns this document for further construction.
    `Text` | `text(String text)` Adds and returns a new text node (the text node is returned so that `Text.write(String)` or [@link `Text.writef(String, Object[])` may be invoked.
    `void` | `toMarkup(Document document, PrintWriter writer, Map<String,String> namespaceURIToPrefix)` Implemented by each subclass, with the document passed in for efficiency.

    - ### Methods inherited from class org.apache.tapestry5.dom.Node

      `getContainer, moveAfter, moveBefore, moveToBottom, moveToTop, remove, toMarkup, toString, wrap`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### XML_NAMESPACE_URI

          public static final String XML_NAMESPACE_URI

      XML Namespace URI. May be bound to the "xml" but must not be bound to any other prefix.
      See Also:
        Constant Field Values

    - #### XMLNS_NAMESPACE_URI

          public static final String XMLNS_NAMESPACE_URI

      Namespace used exclusively for defining namespaces.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Document

          public Document(MarkupModel model)

      Same as Document(model, null).
      Parameters:
        `model` - a `MarkupModel`.

    - #### Document

          public Document(MarkupModel model,
                          String encoding)

      Same as Document(model, encoding, null).
      Parameters:
        `model` - a `MarkupModel`.

    - #### Document

          public Document(MarkupModel model,
                          String encoding,
                          String mimeType)

      Creates a document instance with a given markup model, encoding and MIME type.
      Parameters:
        `model` - a `MarkupModel`.
        `encoding` - the encoding.
        `mimeType` - the MIME type.
      Since:
        5.4

    - #### Document

          public Document()

      Builds with an instance of `DefaultMarkupModel`.

  - ### Method Detail

    - #### getDocument

          public Document getDocument()

      Overrides:
        `getDocument` in class `Node`

    - #### find

          public Element find(String path)

      Finds an element based on a path of element names.
      Parameters:
        `path` - slash separated series of element names
      Returns:
        the matching element, or null if not found
      See Also:
        `Element.find(String)`

    - #### getMarkupModel

          public MarkupModel getMarkupModel()

    - #### newRootElement

          public Element newRootElement(String name)

      Creates the root element for this document, replacing any previous root element.

    - #### newRootElement

          public Element newRootElement(String namespace,
                                        String name)

      Creates a new root element within a namespace.
      Parameters:
        `namespace` - URI of namespace containing the element
        `name` - name of element with namespace
      Returns:
        the root element

    - #### toMarkup

          public void toMarkup(Document document,
                               PrintWriter writer,
                               Map<String,String> namespaceURIToPrefix)

      Description copied from class: `Node`
      Implemented by each subclass, with the document passed in for efficiency.

    - #### getRootElement

          public Element getRootElement()

    - #### getElementById

          public Element getElementById(String id)

      Tries to find an element in this document whose id is specified.
      Parameters:
        `id` - the value of the id attribute of the element being looked for
      Returns:
        the element if found. null if not found.

    - #### dtd

          public void dtd(String name,
                          String publicId,
                          String systemId)

      Sets the DTD for the document, overriding any prior DTD.
      Parameters:
        `name` - non-blank name of document type (i.e., "html")
        `publicId` - optional
        `systemId` - optional

    - #### hasDTD

          public boolean hasDTD()

      Returns true if the document has an explicit DTD (set via `dtd(String, String, String)`).
      Since:
        5.3

    - #### getNamespaceURIToPrefix

          protected Map<String,String> getNamespaceURIToPrefix()

      Overrides:
        `getNamespaceURIToPrefix` in class `Node`

    - #### comment

          public Document comment(String text)

      Adds the comment and returns this document for further construction.
      Since:
        5.1.0.0

    - #### raw

          public Document raw(String text)

      Adds the raw text and returns this document for further construction.
      Since:
        5.1.0.0

    - #### text

          public Text text(String text)

      Adds and returns a new text node (the text node is returned so that `Text.write(String)` or [@link `Text.writef(String, Object[])` may be invoked.
      Parameters:
        `text` - initial text for the node
      Returns:
        the new Text node

    - #### cdata

          public CData cdata(String content)

      Adds and returns a new CDATA node.
      Parameters:
        `content` - the content to be rendered by the node
      Returns:
        the newly created node

    - #### getMimeType

          public String getMimeType()

      Returns the MIME type of this document.
      Returns:
        the MIME type.
      Since:
        5.4

${project.version} - Copyright © 2003-2015 The Apache Software Foundation.