org.restlet.resource
Class SaxRepresentation

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.SaxRepresentation
All Implemented Interfaces:
javax.xml.namespace.NamespaceContext

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.

Author:
Jerome Louvel

Field Summary
 
Fields inherited from class org.restlet.resource.Representation
UNKNOWN_SIZE
 
Constructor Summary
SaxRepresentation(MediaType mediaType)
          Constructor.
SaxRepresentation(MediaType mediaType, org.w3c.dom.Document xmlDocument)
          Constructor.
SaxRepresentation(MediaType mediaType, org.xml.sax.InputSource xmlSource)
          Constructor.
SaxRepresentation(MediaType mediaType, javax.xml.transform.sax.SAXSource xmlSource)
          Constructor.
SaxRepresentation(Representation xmlRepresentation)
          Constructor.
 
Method Summary
 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.
 javax.xml.transform.sax.SAXSource getSaxSource()
          Returns the SAX source that can be parsed by the parse(ContentHandler) method or used for an XSLT transformation.
 void parse(org.xml.sax.ContentHandler contentHandler)
          Parses the source and sends SAX events to a content handler.
 void release()
          Releases the namespaces map.
 void setSaxSource(javax.xml.transform.sax.SAXSource source)
          Sets a SAX source that can be parsed by the parse(ContentHandler) method.
 void write(java.io.OutputStream outputStream)
          Writes the representation to a byte stream.
 void write(XmlWriter writer)
          Writes the representation to a XML writer.
 
Methods inherited from class org.restlet.resource.XmlRepresentation
getBoolean, getDocumentBuilder, getDomSource, getNamespaceURI, getNode, getNodes, getNumber, getPrefix, getPrefixes, 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

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.
Throws:
java.io.IOException
Method Detail

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

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

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

release

public void release()
Releases the namespaces map.

Overrides:
release in class XmlRepresentation

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.

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

write

public void write(XmlWriter writer)
           throws java.io.IOException
Writes the representation to a XML writer. The default implementation does nothing and is intended to be overriden.

Parameters:
writer - The XML writer to write to.
Throws:
java.io.IOException


Copyright © 2005-2008 Noelios Technologies.