Class SaxRepresentation

  • All Implemented Interfaces:
    javax.xml.namespace.NamespaceContext
    Direct Known Subclasses:
    Categories, Entry, Feed, Service

    public class SaxRepresentation
    extends XmlRepresentation
    XML representation for SAX events processing. The purpose is to create a streamable content based on a custom Java object model instead of a neutral DOM tree. This domain object can then be directly modified and efficiently serialized at a later time.

    Subclasses only need to override the ContentHandler methods required for the reading and also the write(XmlWriter writer) method when serialization is requested.

    SECURITY WARNING: Using XML parsers configured to not prevent nor limit document type definition (DTD) entity resolution can expose the parser to an XML Entity Expansion injection attack, see https://github.com/restlet/restlet- framework-java/wiki/XEE-injection-security-fix.
    Author:
    Jerome Louvel
    • Field Detail

      • XML_SECURE_PROCESSING

        public static final boolean XML_SECURE_PROCESSING
        True for turning on secure parsing XML representations; default value provided by system property "org.restlet.ext.xml.secureProcessing", true by default.
    • Constructor Detail

      • SaxRepresentation

        public SaxRepresentation()
        Default constructor. Uses the MediaType.TEXT_XML media type.
      • SaxRepresentation

        public SaxRepresentation​(org.restlet.data.MediaType mediaType)
        Constructor.
        Parameters:
        mediaType - The representation media type.
      • SaxRepresentation

        public SaxRepresentation​(org.restlet.data.MediaType mediaType,
                                 org.w3c.dom.Document xmlDocument)
        Constructor.
        Parameters:
        mediaType - The representation's media type.
        xmlDocument - A DOM document to parse.
      • SaxRepresentation

        public SaxRepresentation​(org.restlet.data.MediaType mediaType,
                                 org.xml.sax.InputSource xmlSource)
        Constructor.
        Parameters:
        mediaType - The representation's media type.
        xmlSource - A SAX input source to parse.
      • SaxRepresentation

        public SaxRepresentation​(org.restlet.data.MediaType mediaType,
                                 javax.xml.transform.sax.SAXSource xmlSource)
        Constructor.
        Parameters:
        mediaType - The representation's media type.
        xmlSource - A JAXP source to parse.
      • SaxRepresentation

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

      • 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
      • getSaxSource

        public javax.xml.transform.sax.SAXSource getSaxSource()
                                                       throws java.io.IOException
        Returns the SAX source that can be parsed by the parse(ContentHandler) method or used for an XSLT transformation.
        Overrides:
        getSaxSource in class XmlRepresentation
        Returns:
        A SAX source.
        Throws:
        java.io.IOException
      • isSecureProcessing

        public boolean isSecureProcessing()
        Indicates if it limits potential XML overflow attacks.
        Returns:
        True if it limits potential XML overflow attacks.
      • parse

        public void parse​(org.xml.sax.ContentHandler contentHandler)
                   throws java.io.IOException
        Parses the source and sends SAX events to a content handler.
        Parameters:
        contentHandler - The SAX content handler to use for parsing.
        Throws:
        java.io.IOException
      • setSaxSource

        public void setSaxSource​(javax.xml.transform.sax.SAXSource source)
        Sets a SAX source that can be parsed by the parse(ContentHandler) method.
        Parameters:
        source - A SAX source.
      • setSecureProcessing

        public void setSecureProcessing​(boolean secureProcessing)
        Indicates if it limits potential XML overflow attacks.
        Parameters:
        secureProcessing - True if it limits potential XML overflow attacks.
      • write

        public void write​(java.io.Writer writer)
                   throws java.io.IOException
        Specified by:
        write in class org.restlet.representation.Representation
        Throws:
        java.io.IOException
      • write

        public void write​(XmlWriter writer)
                   throws java.io.IOException
        Writes the representation to a XML writer. The default implementation calls parse(ContentHandler) using the XmlWriter parameter as the content handler. This behavior is intended to be overridden.
        Parameters:
        writer - The XML writer to write to.
        Throws:
        java.io.IOException