Apache CXF API

org.apache.cxf.jaxrs.ext.xml
Class XMLSource

java.lang.Object
  extended by org.apache.cxf.jaxrs.ext.xml.XMLSource

public class XMLSource
extends Object

Utility class for manipulating XML response using XPath and XSLT


Constructor Summary
XMLSource(InputStream is)
           
 
Method Summary
 URI getBaseURI()
          Returns the value of the xml:base attribute, if any.
 URI getLink(String expression)
          Find an attribute or text node representing an absolute or relative link and convert it to URI
 URI getLink(String expression, Map<String,String> namespaces)
          Find an attribute or text node representing an absolute or relative link and convert it to URI
 URI[] getLinks(String expression, Map<String,String> namespaces)
          Find attributes or text nodes representing absolute or relative links and convert them to URIs
<T> T
getNode(String expression, Class<T> cls)
          Find the matching XML node and convert it into an instance of the provided class.
<T> T
getNode(String expression, Map<String,String> namespaces, Class<T> cls)
          Find the matching XML node and convert it into an instance of the provided class.
<T> T[]
getNodes(String expression, Class<T> cls)
          Find the list of matching XML nodes and convert them into an array of instances of the provided class.
<T> T[]
getNodes(String expression, Map<String,String> namespaces, Class<T> cls)
          Find the list of matching XML nodes and convert them into an array of instances of the provided class.
 String getValue(String expression)
          Find the attribute or simple/text node
 String getValue(String expression, Map<String,String> namespaces)
          Find the attribute or simple/text node
<T> T
getValue(String expression, Map<String,String> namespaces, Class<T> cls)
          Find the attribute or simple/text node and convert the string value to the instance of the provided class, example, Integer.class.
 String[] getValues(String expression)
          Find the attributes or simple/text nodes
 String[] getValues(String expression, Map<String,String> namespaces)
          Find the attributes or simple/text nodes
 void setBuffering()
          Allows for multiple queries against the same stream by buffering to DOM
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLSource

public XMLSource(InputStream is)
Method Detail

setBuffering

public void setBuffering()
Allows for multiple queries against the same stream by buffering to DOM


getNode

public <T> T getNode(String expression,
                     Class<T> cls)
Find the matching XML node and convert it into an instance of the provided class. The default JAXB MessageBodyReader is currently used in case of non-primitive types.

Parameters:
expression - XPath expression
cls - class of the node
Returns:
the instance representing the matching node

getNode

public <T> T getNode(String expression,
                     Map<String,String> namespaces,
                     Class<T> cls)
Find the matching XML node and convert it into an instance of the provided class. The default JAXB MessageBodyReader is currently used in case of non-primitive types.

Parameters:
expression - XPath expression
namespaces - the namespaces map, prefixes which are used in the XPath expression are the keys, namespace URIs are the values; note, the prefixes do not have to match the actual ones used in the XML instance.
cls - class of the node
Returns:
the instance representing the matching node

getNodes

public <T> T[] getNodes(String expression,
                        Class<T> cls)
Find the list of matching XML nodes and convert them into an array of instances of the provided class. The default JAXB MessageBodyReader is currently used in case of non-primitive types.

Parameters:
expression - XPath expression
cls - class of the node
Returns:
the array of instances representing the matching nodes

getNodes

public <T> T[] getNodes(String expression,
                        Map<String,String> namespaces,
                        Class<T> cls)
Find the list of matching XML nodes and convert them into an array of instances of the provided class. The default JAXB MessageBodyReader is currently used in case of non-primitive types.

Parameters:
expression - XPath expression
namespaces - the namespaces map, prefixes which are used in the XPath expression are the keys, namespace URIs are the values; note, the prefixes do not have to match the actual ones used in the XML instance.
cls - class of the node
Returns:
the array of instances representing the matching nodes

getLink

public URI getLink(String expression)
Find an attribute or text node representing an absolute or relative link and convert it to URI

Parameters:
expression - the XPath expression
Returns:
the link

getLink

public URI getLink(String expression,
                   Map<String,String> namespaces)
Find an attribute or text node representing an absolute or relative link and convert it to URI

Parameters:
expression - the XPath expression
namespaces - the namespaces map, prefixes which are used in the XPath expression are the keys, namespace URIs are the values; note, the prefixes do not have to match the actual ones used in the XML instance.
Returns:
the link

getLinks

public URI[] getLinks(String expression,
                      Map<String,String> namespaces)
Find attributes or text nodes representing absolute or relative links and convert them to URIs

Parameters:
expression - the XPath expression
namespaces - the namespaces map, prefixes which are used in the XPath expression are the keys, namespace URIs are the values; note, the prefixes do not have to match the actual ones used in the XML instance.
Returns:
the links

getBaseURI

public URI getBaseURI()
Returns the value of the xml:base attribute, if any. This can be used to calculate an absolute URI provided the links in the actual XML instance are relative.

Returns:
the xml:base value

getValue

public String getValue(String expression)
Find the attribute or simple/text node

Parameters:
expression - the XPath expression
Returns:
the value of the matching node

getValue

public String getValue(String expression,
                       Map<String,String> namespaces)
Find the attribute or simple/text node

Parameters:
expression - the XPath expression
namespaces - the namespaces map, prefixes which are used in the XPath expression are the keys, namespace URIs are the values; note, the prefixes do not have to match the actual ones used in the XML instance.
Returns:
the value of the matching node

getValues

public String[] getValues(String expression)
Find the attributes or simple/text nodes

Parameters:
expression - the XPath expression
Returns:
the values of the matching nodes

getValues

public String[] getValues(String expression,
                          Map<String,String> namespaces)
Find the attributes or simple/text nodes

Parameters:
expression - the XPath expression
namespaces - the namespaces map, prefixes which are used in the XPath expression are the keys, namespace URIs are the values; note, the prefixes do not have to match the actual ones used in the XML instance.
Returns:
the values of the matching nodes

getValue

public <T> T getValue(String expression,
                      Map<String,String> namespaces,
                      Class<T> cls)
Find the attribute or simple/text node and convert the string value to the instance of the provided class, example, Integer.class.

Parameters:
expression - the XPath expression
namespaces - the namespaces map, prefixes which are used in the XPath expression are the keys, namespace URIs are the values; note, the prefixes do not have to match the actual ones used in the XML instance.
cls - the class of the response
Returns:
the value

Apache CXF API

Apache CXF