Package org.restlet.ext.xml
Class DomRepresentation
- java.lang.Object
-
- All Implemented Interfaces:
javax.xml.namespace.NamespaceContext
- Direct Known Subclasses:
MessageRepresentation,MessagesRepresentation
public class DomRepresentation extends XmlRepresentation
XML representation based on a DOM document. DOM is a standard XML object model defined by the W3C.
-
-
Field Summary
Fields Modifier and Type Field Description private org.w3c.dom.DocumentdocumentThe wrapped DOM document.private booleanindentingIndicates if the XML serialization should be indented.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 DomRepresentation()Default constructor.DomRepresentation(MediaType mediaType)Constructor for an empty document.DomRepresentation(MediaType mediaType, org.w3c.dom.Document xmlDocument)Constructor from an existing DOM document.DomRepresentation(Representation xmlRepresentation)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.xml.transform.TransformercreateTransformer()Creates a new JAXP Transformer object that will be used to serialize this DOM.org.w3c.dom.DocumentgetDocument()Returns the wrapped DOM document.javax.xml.transform.dom.DOMSourcegetDomSource()Returns a DOM source.org.xml.sax.InputSourcegetInputSource()Returns the XML representation as a SAX input source.booleanisIndenting()Indicates if the XML serialization should be indented.voidrelease()Releases the wrapped DOM document and the source XML representation if they have been defined.voidsetDocument(org.w3c.dom.Document dom)Sets the wrapped DOM document.voidsetIndenting(boolean indenting)Indicates if the XML serialization should be indented.voidwrite(java.io.Writer writer)Writes the representation to a characters writer.-
Methods inherited from class org.restlet.ext.xml.XmlRepresentation
getBoolean, getDocumentBuilder, getEntityResolver, getErrorHandler, getNamespaces, getNamespaceURI, getNode, getNodes, getNumber, getPrefix, getPrefixes, getSaxSource, 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
-
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.IOExceptionDefault constructor. Uses theMediaType.TEXT_XMLmedia 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.IOExceptionCreates 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.IOExceptionReturns 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:
getDocumentin classXmlRepresentation- Returns:
- The wrapped DOM document.
- Throws:
java.io.IOException
-
getDomSource
public javax.xml.transform.dom.DOMSource getDomSource() throws java.io.IOExceptionReturns a DOM source.- Overrides:
getDomSourcein classXmlRepresentation- Returns:
- A DOM source.
- Throws:
java.io.IOException
-
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
-
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:
releasein classXmlRepresentation
-
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.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
-
-