org.restlet.resource
Class XmlRepresentation

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
All Implemented Interfaces:
javax.xml.namespace.NamespaceContext
Direct Known Subclasses:
DomRepresentation, SaxRepresentation

public abstract class XmlRepresentation
extends OutputRepresentation
implements javax.xml.namespace.NamespaceContext

Representation based on an XML document. It knows how to evaluate XPath expressions and how to manage a namespace context. This class also offers convenient methods to validate the document against a specified XML scheme.

Author:
Jerome Louvel

Field Summary
 
Fields inherited from class org.restlet.resource.Representation
UNKNOWN_SIZE
 
Constructor Summary
XmlRepresentation(MediaType mediaType)
          Constructor.
XmlRepresentation(MediaType mediaType, long expectedSize)
          Constructor.
 
Method Summary
abstract  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.
 java.lang.Boolean getBoolean(java.lang.String expression)
          Evaluates an XPath expression as a boolean.
protected  javax.xml.parsers.DocumentBuilder getDocumentBuilder()
          Returns a document builder properly configured.
 javax.xml.transform.dom.DOMSource getDomSource()
          Returns a DOM source.
 java.lang.String getNamespaceURI(java.lang.String prefix)
          
 org.w3c.dom.Node getNode(java.lang.String expression)
          Evaluates an XPath expression as a DOM Node.
 NodeSet getNodes(java.lang.String expression)
          Evaluates an XPath expression as a DOM NodeList.
 java.lang.Double getNumber(java.lang.String expression)
          Evaluates an XPath expression as a number.
 java.lang.String getPrefix(java.lang.String namespaceURI)
          
 java.util.Iterator<java.lang.String> getPrefixes(java.lang.String namespaceURI)
          
 javax.xml.transform.sax.SAXSource getSaxSource()
          Returns a SAX source.
static javax.xml.transform.sax.SAXSource getSaxSource(Representation xmlRepresentation)
          Returns a SAX source.
 javax.xml.transform.stream.StreamSource getStreamSource()
          Returns a stream of XML markup.
 java.lang.String getText(java.lang.String expression)
          Evaluates an XPath expression as a string.
 boolean isNamespaceAware()
          Indicates if processing is namespace aware.
 void putNamespace(java.lang.String prefix, java.lang.String namespaceURI)
          Puts a new mapping between a prefix and a namespace URI.
 void release()
          Releases the namespaces map.
 void setNamespaceAware(boolean namespaceAware)
          Indicates if processing is namespace aware.
 void validate(Representation schemaRepresentation)
          Validates the XML representation against a given schema.
 void validate(Representation schemaRepresentation, javax.xml.transform.Result result)
          Validates the XML representation against a given schema.
 void validate(javax.xml.validation.Schema schema)
          Validates the XML representation against a given schema.
 void validate(javax.xml.validation.Schema schema, javax.xml.transform.Result result)
          Validates the XML representation against a given schema.
 
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, write
 
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

XmlRepresentation

public XmlRepresentation(MediaType mediaType)
Constructor.

Parameters:
mediaType - The representation's mediaType.

XmlRepresentation

public XmlRepresentation(MediaType mediaType,
                         long expectedSize)
Constructor.

Parameters:
mediaType - The representation's mediaType.
expectedSize - The expected input stream size.
Method Detail

getSaxSource

public static javax.xml.transform.sax.SAXSource getSaxSource(Representation xmlRepresentation)
                                                      throws java.io.IOException
Returns a SAX source.

Parameters:
xmlRepresentation - The XML representation to wrap.
Returns:
A SAX source.
Throws:
java.io.IOException

evaluate

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

Parameters:
returnType - The qualified name of the return type.
Returns:
The evaluation result.
Throws:
java.lang.Exception
See Also:
XPathException, XPathConstants

getBoolean

public java.lang.Boolean getBoolean(java.lang.String expression)
Evaluates an XPath expression as a boolean. If the evaluation fails, null will be returned.

Returns:
The evaluation result.

getDocumentBuilder

protected javax.xml.parsers.DocumentBuilder getDocumentBuilder()
                                                        throws java.io.IOException
Returns a document builder properly configured.

Returns:
A document builder properly configured.
Throws:
java.io.IOException

getDomSource

public javax.xml.transform.dom.DOMSource getDomSource()
                                               throws java.io.IOException
Returns a DOM source.

Returns:
A DOM source.
Throws:
java.io.IOException

getNamespaceURI

public java.lang.String getNamespaceURI(java.lang.String prefix)

Specified by:
getNamespaceURI in interface javax.xml.namespace.NamespaceContext

getNode

public org.w3c.dom.Node getNode(java.lang.String expression)
Evaluates an XPath expression as a DOM Node. If the evaluation fails, null will be returned.

Returns:
The evaluation result.

getNodes

public NodeSet getNodes(java.lang.String expression)
Evaluates an XPath expression as a DOM NodeList. If the evaluation fails, null will be returned.

Returns:
The evaluation result.

getNumber

public java.lang.Double getNumber(java.lang.String expression)
Evaluates an XPath expression as a number. If the evaluation fails, null will be returned.

Returns:
The evaluation result.

getPrefix

public java.lang.String getPrefix(java.lang.String namespaceURI)

Specified by:
getPrefix in interface javax.xml.namespace.NamespaceContext

getPrefixes

public java.util.Iterator<java.lang.String> getPrefixes(java.lang.String namespaceURI)

Specified by:
getPrefixes in interface javax.xml.namespace.NamespaceContext

getSaxSource

public javax.xml.transform.sax.SAXSource getSaxSource()
                                               throws java.io.IOException
Returns a SAX source.

Returns:
A SAX source.
Throws:
java.io.IOException

getStreamSource

public javax.xml.transform.stream.StreamSource getStreamSource()
                                                        throws java.io.IOException
Returns a stream of XML markup.

Returns:
A stream of XML markup.
Throws:
java.io.IOException

getText

public java.lang.String getText(java.lang.String expression)
Evaluates an XPath expression as a string.

Returns:
The evaluation result.

isNamespaceAware

public boolean isNamespaceAware()
Indicates if processing is namespace aware.

Returns:
True if processing is namespace aware.

putNamespace

public void putNamespace(java.lang.String prefix,
                         java.lang.String namespaceURI)
Puts a new mapping between a prefix and a namespace URI.

Parameters:
prefix - The namespace prefix.
namespaceURI - The namespace URI.

release

public void release()
Releases the namespaces map.

Overrides:
release in class OutputRepresentation

setNamespaceAware

public void setNamespaceAware(boolean namespaceAware)
Indicates if processing is namespace aware.

Parameters:
namespaceAware - Indicates if processing is namespace aware.

validate

public void validate(Representation schemaRepresentation)
              throws java.lang.Exception
Validates the XML representation against a given schema.

Parameters:
schemaRepresentation - The XML schema representation to use.
Throws:
java.lang.Exception

validate

public void validate(Representation schemaRepresentation,
                     javax.xml.transform.Result result)
              throws java.lang.Exception
Validates the XML representation against a given schema.

Parameters:
schemaRepresentation - The XML schema representation to use.
result - The Result object that receives (possibly augmented) XML.
Throws:
java.lang.Exception

validate

public void validate(javax.xml.validation.Schema schema)
              throws java.lang.Exception
Validates the XML representation against a given schema.

Parameters:
schema - The XML schema to use.
Throws:
java.lang.Exception

validate

public void validate(javax.xml.validation.Schema schema,
                     javax.xml.transform.Result result)
              throws java.lang.Exception
Validates the XML representation against a given schema.

Parameters:
schema - The XML schema to use.
result - The Result object that receives (possibly augmented) XML.
Throws:
java.lang.Exception


Copyright © 2005-2008 Noelios Technologies.