Class DomRepresentation

    • Field Detail

      • document

        private volatile org.w3c.dom.Document document
        The wrapped DOM document.
      • indenting

        private volatile boolean indenting
        Indicates if the XML serialization should be indented.
      • xmlRepresentation

        private volatile Representation xmlRepresentation
        The source XML representation.
    • Constructor Detail

      • DomRepresentation

        public DomRepresentation()
                          throws java.io.IOException
        Default constructor. Uses the MediaType.TEXT_XML media type.
        Throws:
        java.io.IOException
      • DomRepresentation

        public DomRepresentation​(MediaType mediaType)
                          throws java.io.IOException
        Constructor for an empty document.
        Parameters:
        mediaType - The representation's media type.
        Throws:
        java.io.IOException
      • DomRepresentation

        public DomRepresentation​(MediaType mediaType,
                                 org.w3c.dom.Document xmlDocument)
        Constructor from an existing DOM document.
        Parameters:
        mediaType - The representation's media type.
        xmlDocument - The source DOM document.
      • DomRepresentation

        public DomRepresentation​(Representation xmlRepresentation)
        Constructor.
        Parameters:
        xmlRepresentation - A source XML representation to parse.
    • Method Detail

      • createTransformer

        protected javax.xml.transform.Transformer createTransformer()
                                                             throws java.io.IOException
        Creates a new JAXP Transformer object that will be used to serialize this DOM. This method may be overridden in order to set custom properties on the Transformer.
        Returns:
        The transformer to be used for serialization.
        Throws:
        java.io.IOException
      • getDocument

        public org.w3c.dom.Document getDocument()
                                         throws java.io.IOException
        Returns the wrapped DOM document. If no document is defined yet, it attempts to parse the XML representation eventually given at construction time. Otherwise, it just creates a new document.
        Overrides:
        getDocument in class XmlRepresentation
        Returns:
        The wrapped DOM document.
        Throws:
        java.io.IOException
      • getDomSource

        public javax.xml.transform.dom.DOMSource getDomSource()
                                                       throws java.io.IOException
        Returns a DOM source.
        Overrides:
        getDomSource in class XmlRepresentation
        Returns:
        A DOM source.
        Throws:
        java.io.IOException
      • getInputSource

        public org.xml.sax.InputSource getInputSource()
                                               throws java.io.IOException
        Description copied from class: XmlRepresentation
        Returns the XML representation as a SAX input source.
        Specified by:
        getInputSource in class XmlRepresentation
        Returns:
        The SAX input source.
        Throws:
        java.io.IOException
      • isIndenting

        public boolean isIndenting()
        Indicates if the XML serialization should be indented. False by default.
        Returns:
        True if the XML serialization should be indented.
      • release

        public void release()
        Releases the wrapped DOM document and the source XML representation if they have been defined.
        Overrides:
        release in class XmlRepresentation
      • setDocument

        public void setDocument​(org.w3c.dom.Document dom)
        Sets the wrapped DOM document.
        Parameters:
        dom - The wrapped DOM document.
      • setIndenting

        public void setIndenting​(boolean indenting)
        Indicates if the XML serialization should be indented.
        Parameters:
        indenting - True if the XML serialization should be indented.
      • write

        public void write​(java.io.Writer writer)
                   throws java.io.IOException
        Description copied from class: Representation
        Writes the representation to a characters writer. This method is ensured to write the full content for each invocation unless it is a transient representation, in which case an exception is thrown.

        Note that the class implementing this method shouldn't flush or close the given Writer after writing to it as this will be handled by the Restlet connectors automatically.
        Specified by:
        write in class Representation
        Parameters:
        writer - The characters writer.
        Throws:
        java.io.IOException