Package org.restlet.ext.xml
Class SaxRepresentation
- java.lang.Object
-
- All Implemented Interfaces:
javax.xml.namespace.NamespaceContext
- Direct Known Subclasses:
Categories,Entry,Feed,Service,WadlRepresentation
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.
-
-
Field Summary
Fields Modifier and Type Field Description private booleansecureProcessingLimits potential XML overflow attacks.private javax.xml.transform.sax.SAXSourcesourceThe SAX source.static booleanXML_SECURE_PROCESSINGTrue for turning on secure parsing XML representations; default value provided by system property "org.restlet.ext.xml.secureProcessing", true by default.private RepresentationxmlRepresentationThe source XML representation.-
Fields inherited from class org.restlet.ext.xml.XmlRepresentation
XML_EXPANDING_ENTITY_REFS, XML_VALIDATING_DTD
-
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
-
-
Constructor Summary
Constructors Constructor Description SaxRepresentation()Default constructor.SaxRepresentation(MediaType mediaType)Constructor.SaxRepresentation(MediaType mediaType, javax.xml.transform.sax.SAXSource xmlSource)Constructor.SaxRepresentation(MediaType mediaType, org.w3c.dom.Document xmlDocument)Constructor.SaxRepresentation(MediaType mediaType, org.xml.sax.InputSource xmlSource)Constructor.SaxRepresentation(Representation xmlRepresentation)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.xml.sax.InputSourcegetInputSource()Returns the XML representation as a SAX input source.javax.xml.transform.sax.SAXSourcegetSaxSource()Returns the SAX source that can be parsed by theparse(ContentHandler)method or used for an XSLT transformation.booleanisSecureProcessing()Indicates if it limits potential XML overflow attacks.voidparse(org.xml.sax.ContentHandler contentHandler)Parses the source and sends SAX events to a content handler.voidrelease()Releases the namespaces map.voidsetSaxSource(javax.xml.transform.sax.SAXSource source)Sets a SAX source that can be parsed by theparse(ContentHandler)method.voidsetSecureProcessing(boolean secureProcessing)Indicates if it limits potential XML overflow attacks.voidwrite(java.io.Writer writer)Writes the representation to a characters writer.voidwrite(XmlWriter writer)Writes the representation to a XML writer.-
Methods inherited from class org.restlet.ext.xml.XmlRepresentation
getBoolean, getDocument, getDocumentBuilder, getDomSource, getEntityResolver, getErrorHandler, getNamespaces, getNamespaceURI, getNode, getNodes, getNumber, getPrefix, getPrefixes, getSaxSource, getSchema, getStreamSource, getText, getTextContent, isCoalescing, isExpandingEntityRefs, isIgnoringComments, isIgnoringExtraWhitespaces, isNamespaceAware, isValidatingDtd, isXIncludeAware, setCoalescing, setEntityResolver, setErrorHandler, setExpandingEntityRefs, setIgnoringComments, setIgnoringExtraWhitespaces, setNamespaceAware, setNamespaces, setSchema, setSchema, setValidatingDtd, setXIncludeAware, validate, validate, validate, validate
-
Methods inherited from class org.restlet.representation.WriterRepresentation
getReader
-
Methods inherited from class org.restlet.representation.CharacterRepresentation
getChannel, getStream, write, write
-
Methods inherited from class org.restlet.representation.Representation
append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getRegistration, getSize, getText, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient
-
Methods inherited from class org.restlet.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
-
Methods inherited from class org.restlet.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
-
-
-
-
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.
-
secureProcessing
private boolean secureProcessing
Limits potential XML overflow attacks.
-
source
private volatile javax.xml.transform.sax.SAXSource source
The SAX source.
-
xmlRepresentation
private volatile Representation xmlRepresentation
The source XML representation.
-
-
Constructor Detail
-
SaxRepresentation
public SaxRepresentation()
Default constructor. Uses theMediaType.TEXT_XMLmedia type.
-
SaxRepresentation
public SaxRepresentation(MediaType mediaType)
Constructor.- Parameters:
mediaType- The representation media type.
-
SaxRepresentation
public SaxRepresentation(MediaType mediaType, org.w3c.dom.Document xmlDocument)
Constructor.- Parameters:
mediaType- The representation's media type.xmlDocument- A DOM document to parse.
-
SaxRepresentation
public SaxRepresentation(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(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(Representation xmlRepresentation)
Constructor.- Parameters:
xmlRepresentation- A source XML representation to parse.
-
-
Method Detail
-
getInputSource
public org.xml.sax.InputSource getInputSource() throws java.io.IOExceptionDescription copied from class:XmlRepresentationReturns the XML representation as a SAX input source.- Specified by:
getInputSourcein classXmlRepresentation- Returns:
- The SAX input source.
- Throws:
java.io.IOException
-
getSaxSource
public javax.xml.transform.sax.SAXSource getSaxSource() throws java.io.IOExceptionReturns the SAX source that can be parsed by theparse(ContentHandler)method or used for an XSLT transformation.- Overrides:
getSaxSourcein classXmlRepresentation- 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.IOExceptionParses the source and sends SAX events to a content handler.- Parameters:
contentHandler- The SAX content handler to use for parsing.- Throws:
java.io.IOException
-
release
public void release()
Releases the namespaces map.- Overrides:
releasein classXmlRepresentation
-
setSaxSource
public void setSaxSource(javax.xml.transform.sax.SAXSource source)
Sets a SAX source that can be parsed by theparse(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.IOExceptionDescription copied from class:RepresentationWrites 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 givenWriterafter writing to it as this will be handled by the Restlet connectors automatically.- Specified by:
writein classRepresentation- Parameters:
writer- The characters writer.- Throws:
java.io.IOException
-
write
public void write(XmlWriter writer) throws java.io.IOException
Writes the representation to a XML writer. The default implementation callsparse(ContentHandler)using theXmlWriterparameter as the content handler. This behavior is intended to be overridden.- Parameters:
writer- The XML writer to write to.- Throws:
java.io.IOException
-
-