AgileApps Support Wiki Pre Release

Difference between revisions of "REST API:BaseUtil"

From AgileApps Support Wiki
imported>Aeric
 
imported>Aeric
 
Line 4: Line 4:


;prettyPrint(InputStream xml_in): Displays nicely-formatted, indented XML.
;prettyPrint(InputStream xml_in): Displays nicely-formatted, indented XML.
;prettyPrint(MultivaluedMap<String,String> map):
: Pretty print a map of key/value pairs, where both the keys and the values are strings, and each key maps to a list of one or more string values. Lists are displayed in the form:
:: <tt>[item1, item2, ...]</tt>


;xpath_result(String xpath_expr, String xml): Given an XPath expression and an XML string, returns a string with the corresponding value from the XML. So for <tt><platform><message><status>200</status>...</tt>, the XPath expression <tt>"/platform/message/status"</tt> returns "200".  
;xpath_result(String xpath_expr, String xml): Given an XPath expression and an XML string, returns a string with the corresponding value from the XML. So for <tt><platform><message><status>200</status>...</tt>, the XPath expression <tt>"/platform/message/status"</tt> returns "200".  

Latest revision as of 02:18, 3 February 2012

The BaseUtil class contains methods that are useful when generating requests and processing responses in a subclass of BaseClient.

Thumbsup.gif

Tip: The REST_samples.zip file contains this utility class, BaseClient (which uses), and extensions to BaseClient that demonstrate REST operations.

prettyPrint(InputStream xml_in)
Displays nicely-formatted, indented XML.
prettyPrint(MultivaluedMap<String,String> map)
Pretty print a map of key/value pairs, where both the keys and the values are strings, and each key maps to a list of one or more string values. Lists are displayed in the form:
[item1, item2, ...]
xpath_result(String xpath_expr, String xml)
Given an XPath expression and an XML string, returns a string with the corresponding value from the XML. So for <platform><message><status>200</status>..., the XPath expression "/platform/message/status" returns "200".
mediaType(String filename)
Examines a filename's extension and returns a string with the appropriate MIME type for that kind of a file, so it can be inserted into a header. For example, if the extension is ".txt", it returns "text/plain".