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:
NamespaceContext
Direct Known Subclasses:
DomRepresentation, SaxRepresentation

public abstract class XmlRepresentation
extends OutputRepresentation
implements NamespaceContext

Representation based on an XML document. It knows how to evaluate XPath expressions and how to manage a namespace context.

Author:
Jerome Louvel (contact@noelios.com)

Field Summary
 
Fields inherited from class org.restlet.resource.Variant
UNKNOWN_SIZE
 
Constructor Summary
XmlRepresentation(MediaType mediaType)
          Constructor.
XmlRepresentation(MediaType mediaType, long expectedSize)
          Constructor.
 
Method Summary
abstract  Object evaluate(String expression, QName returnType)
          Evaluates an XPath expression and returns the result as in the given return type.
 Boolean getBoolean(String expression)
          Evaluates an XPath expression as a boolean.
 String getNamespaceURI(String prefix)
          
 Node getNode(String expression)
          Evaluates an XPath expression as a DOM Node.
 NodeSet getNodes(String expression)
          Evaluates an XPath expression as a DOM NodeList.
 Double getNumber(String expression)
          Evaluates an XPath expression as a number.
 String getPrefix(String namespaceURI)
          
 Iterator getPrefixes(String namespaceURI)
          
 String getText(String expression)
          Evaluates an XPath expression as a string.
 boolean isNamespaceAware()
          Indicates if processing is namespace aware.
 void putNamespace(String prefix, String namespaceURI)
          Puts a new mapping between a prefix and a namespace URI.
 void setNamespaceAware(boolean namespaceAware)
          Indicates if processing is namespace aware.
 
Methods inherited from class org.restlet.resource.OutputRepresentation
getStream, write
 
Methods inherited from class org.restlet.resource.StreamRepresentation
getChannel, write
 
Methods inherited from class org.restlet.resource.Representation
getText, isAvailable, isTransient, setAvailable, setTransient
 
Methods inherited from class org.restlet.resource.Variant
getCharacterSet, getEncodings, getExpirationDate, getIdentifier, getLanguages, getMediaType, getModificationDate, getSize, getTag, setCharacterSet, setExpirationDate, setIdentifier, setIdentifier, setMediaType, setModificationDate, setSize, setTag
 
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

evaluate

public abstract Object evaluate(String expression,
                                QName returnType)
                         throws 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:
Exception
See Also:
XPathException, XPathConstants

getBoolean

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

Returns:
The evaluation result.

getNamespaceURI

public String getNamespaceURI(String prefix)

Specified by:
getNamespaceURI in interface NamespaceContext

getNode

public Node getNode(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(String expression)
Evaluates an XPath expression as a DOM NodeList. If the evaluation fails, null will be returned.

Returns:
The evaluation result.

getNumber

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

Returns:
The evaluation result.

getPrefix

public String getPrefix(String namespaceURI)

Specified by:
getPrefix in interface NamespaceContext

getPrefixes

public Iterator getPrefixes(String namespaceURI)

Specified by:
getPrefixes in interface NamespaceContext

getText

public String getText(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(String prefix,
                         String namespaceURI)
Puts a new mapping between a prefix and a namespace URI.

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

setNamespaceAware

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

Parameters:
namespaceAware - Indicates if processing is namespace aware.


Copyright © 2005-2007 Noelios Consulting.