org.restlet.resource
Class DomRepresentation

java.lang.Object
  extended by org.restlet.resource.Variant
      extended by org.restlet.resource.Representation
          extended by org.restlet.resource.StreamRepresentation
              extended by org.restlet.resource.OutputRepresentation
                  extended by org.restlet.resource.XmlRepresentation
                      extended by org.restlet.resource.DomRepresentation
All Implemented Interfaces:
javax.xml.namespace.NamespaceContext

public class DomRepresentation
extends XmlRepresentation

XML representation based on a DOM document. DOM is a standard XML object model defined by the W3C.

Author:
Jerome Louvel

Field Summary
 
Fields inherited from class org.restlet.resource.Representation
UNKNOWN_SIZE
 
Constructor Summary
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
protected  javax.xml.transform.Transformer createTransformer()
          Creates a new JAXP Transformer object that will be used to serialize this DOM.
 java.lang.Object evaluate(java.lang.String expression, javax.xml.namespace.QName returnType)
          Evaluates an XPath expression and returns the result as in the given return type.
 org.w3c.dom.Document getDocument()
          Returns the wrapped DOM document.
 javax.xml.transform.dom.DOMSource getDomSource()
          Returns a DOM source.
 void release()
          Releases the wrapped DOM document and the source XML representation if they have been defined.
 void setDocument(org.w3c.dom.Document dom)
          Sets the wrapped DOM document.
 void write(java.io.OutputStream outputStream)
          Writes the representation to a byte stream.
 
Methods inherited from class org.restlet.resource.XmlRepresentation
getBoolean, getDocumentBuilder, getNamespaceURI, getNode, getNodes, getNumber, getPrefix, getPrefixes, getSaxSource, getSaxSource, getStreamSource, getText, isNamespaceAware, putNamespace, setNamespaceAware, validate, validate, validate, validate
 
Methods inherited from class org.restlet.resource.OutputRepresentation
getStream
 
Methods inherited from class org.restlet.resource.StreamRepresentation
getChannel, getReader, write, write
 
Methods inherited from class org.restlet.resource.Representation
checkDigest, checkDigest, computeDigest, createEmpty, exhaust, getAvailableSize, getDigest, getDownloadName, getExpirationDate, getModificationDate, getRange, getSize, getTag, getText, isAvailable, isDownloadable, isTransient, setAvailable, setDigest, setDownloadable, setDownloadName, setExpirationDate, setModificationDate, setRange, setSize, setTag, setTransient
 
Methods inherited from class org.restlet.resource.Variant
getCharacterSet, getEncodings, getIdentifier, getLanguages, getMediaType, setCharacterSet, setEncodings, setIdentifier, setIdentifier, setLanguages, setMediaType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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

evaluate

public java.lang.Object evaluate(java.lang.String expression,
                                 javax.xml.namespace.QName returnType)
                          throws java.lang.Exception
Description copied from class: XmlRepresentation
Evaluates an XPath expression and returns the result as in the given return type.

Specified by:
evaluate in class XmlRepresentation
returnType - The qualified name of the return type.
Returns:
The evaluation result.
Throws:
java.lang.Exception
See Also:
XPathException, XPathConstants

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.

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

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.

write

public void write(java.io.OutputStream outputStream)
           throws java.io.IOException
Description copied from class: Representation
Writes the representation to a byte stream. 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.

Specified by:
write in class Representation
Parameters:
outputStream - The output stream.
Throws:
java.io.IOException


Copyright © 2005-2008 Noelios Technologies.