us.monoid.web
Class XMLResource

java.lang.Object
  extended by us.monoid.web.Resty
      extended by us.monoid.web.AbstractResource
          extended by us.monoid.web.TextResource
              extended by us.monoid.web.XMLResource

public class XMLResource
extends TextResource

Resource presentation for an XML document. You can access the XML as a DOM document. I know, DOM sucks, but you are free to change this class to support your favorite XML parser. What is not so sucky is access to the XML via XPath with the convenient get(...) methods.

Author:
beders

Nested Class Summary
 
Nested classes/interfaces inherited from class us.monoid.web.Resty
Resty.Option, Resty.Proxy, Resty.Timeout
 
Constructor Summary
XMLResource(Resty.Option... options)
           
 
Method Summary
 Document doc()
          Return the DOM of the XML resource.
 NodeList get(String xPath)
          Access the XML evaluating an XPath on it, returning the resulting NodeList.
<T> T
get(String xPath, Class<T> returnType)
          Access the XML evaluating an XPath on it, returning the resulting Object of the desired type Supported types are NodeList, String, Boolean, Double, Node.
 JSONResource json(XPathQuery path)
          Execute the given path query on the XML, GET the returned URI expecting JSON as content
 JSONResource json(XPathQuery path, Content aContent)
          Execute the given path query on the XML, POST the returned URI expecting JSON
 TextResource text(XPathQuery path)
          Execute the given path query on the XML, GET the returned URI expecting text/* as content
 TextResource text(XPathQuery path, Content aContent)
          Execute the given path query on the XML, POST the returned URI expecting text/*
 XMLResource xml(XPathQuery path)
          Execute the given path query on the XML, GET the returned URI expecting xml/* as content
 XMLResource xml(XPathQuery path, Content aContent)
          Execute the given path query on the XML, POST the returned URI expecting XML
 
Methods inherited from class us.monoid.web.TextResource
toString
 
Methods inherited from class us.monoid.web.AbstractResource
getUrlConnection, http, location, status, stream
 
Methods inherited from class us.monoid.web.Resty
alwaysSend, authenticate, authenticate, authenticateForRealm, bytes, bytes, bytes, bytes, content, content, content, data, data, delete, dontSend, enc, form, form, identifyAsMozilla, identifyAsResty, ignoreAllCerts, json, json, json, json, path, put, setOptions, setProxy, text, text, text, text, withHeader, xml, xml, xml, xml, xpath
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLResource

public XMLResource(Resty.Option... options)
Method Detail

doc

public Document doc()
             throws IOException
Return the DOM of the XML resource.

Returns:
Throws:
IOException

json

public JSONResource json(XPathQuery path)
                  throws Exception
Execute the given path query on the XML, GET the returned URI expecting JSON as content

Parameters:
path - path to the URI to follow, must be a String QName result
Returns:
a new resource, as a result of getting it from the server in JSON format
Throws:
Exception
JSONException

json

public JSONResource json(XPathQuery path,
                         Content aContent)
                  throws Exception
Execute the given path query on the XML, POST the returned URI expecting JSON

Parameters:
path - path to the URI to follow, must be a String QName result
aContent - the content to POST
Returns:
a new resource, as a result of getting it from the server in JSON format
Throws:
Exception
JSONException

text

public TextResource text(XPathQuery path)
                  throws Exception
Execute the given path query on the XML, GET the returned URI expecting text/* as content

Parameters:
path - path to the URI to follow, must be a String QName result
Returns:
a new resource, as a result of getting it from the server in text format
Throws:
Exception

text

public TextResource text(XPathQuery path,
                         Content aContent)
                  throws Exception
Execute the given path query on the XML, POST the returned URI expecting text/*

Parameters:
path - path to the URI to follow, must be a String QName result
aContent - the content to POST
Returns:
a new resource, as a result of getting it from the server in text format
Throws:
Exception

xml

public XMLResource xml(XPathQuery path)
                throws Exception
Execute the given path query on the XML, GET the returned URI expecting xml/* as content

Parameters:
path - path to the URI to follow, must be a String QName result
Returns:
a new resource, as a result of getting it from the server in text format
Throws:
Exception

xml

public XMLResource xml(XPathQuery path,
                       Content aContent)
                throws Exception
Execute the given path query on the XML, POST the returned URI expecting XML

Parameters:
path - path to the URI to follow, must be a String QName result
aContent - the content to POST
Returns:
a new resource, as a result of getting it from the server in text format
Throws:
Exception

get

public NodeList get(String xPath)
             throws Exception
Access the XML evaluating an XPath on it, returning the resulting NodeList.

Throws:
Exception

get

public <T> T get(String xPath,
                 Class<T> returnType)
      throws Exception
Access the XML evaluating an XPath on it, returning the resulting Object of the desired type Supported types are NodeList, String, Boolean, Double, Node.

Throws:
Exception


Copyright © 2013. All Rights Reserved.