com.jalios.rest.client
Class ClientUtil

java.lang.Object
  extended by com.jalios.rest.client.ClientUtil

public class ClientUtil
extends Object

Utility functions (static public methods) used in Rest Clients.

Since:
JCMS-6.0
Author:
dissert

Constructor Summary
ClientUtil()
           
 
Method Summary
static void addHttpHeader(org.restlet.data.Request request, String key, String value)
          Adds a header in a HTTP request represented by the request parameter.
static boolean getBoolean(JcmsResource resource, String xpathExpression, boolean def)
          If the result of the XPath query is a boolean String, it is converted in Boolean.
static Date getDate(JcmsResource resource, String xpathExpression, Date def)
          If the result of the XPath query is a Date as defined by the W3C Date Time format (eg 1999-01-01T14:07:00+01:00).
static org.jdom.Element getFirstElement(JcmsResource resource, String xpathExpression)
          Utility functions to use XPath expression to introspect xml contained in entity boby of HTTP response
static long getLong(JcmsResource resource, String xpathExpression, long def)
          If the result of the XPath query is a long representation String, it is converted as an long.
static List<?> getNodeList(JcmsResource resource, String xpathExpression)
          Provide XPath feature : returns the list of Nodes in the xml in the entity body of the resource in first argument, with the xPathExpression in second argument.
static org.restlet.data.Preference<org.restlet.data.MediaType> getPreferenceMediaType(org.restlet.data.MediaType mediaType)
           
static org.restlet.data.Request getRequest(org.restlet.data.Reference resourceRef, org.restlet.data.Method method)
          Instanciate the request with the uri and the HTTP method.
static Object getSingleNode(JcmsResource resource, String xpathExpression)
          Provide XPath feature : returns the first of the Nodes in the xml in the entity body of the resource in first argument, with the xPathExpression in second argument.
static String getString(JcmsResource resource, String xpathExpression)
          Return the most pertinent String for the result of the XPath query in the body content of the given resource.
static void setPreferedMediaType(org.restlet.data.Request request, org.restlet.data.MediaType[] mediaTypes)
          In a Restlet Request object, set the prefered MediaType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientUtil

public ClientUtil()
Method Detail

addHttpHeader

public static void addHttpHeader(org.restlet.data.Request request,
                                 String key,
                                 String value)
Adds a header in a HTTP request represented by the request parameter.

Parameters:
request - The Restlet object representing an HTTP request.
key - The name of the given HTTP header
value - The name for the given HTTP header

getRequest

public static org.restlet.data.Request getRequest(org.restlet.data.Reference resourceRef,
                                                  org.restlet.data.Method method)
Instanciate the request with the uri and the HTTP method.

Parameters:
resourceRef -
method -
Returns:
the Request object, with the URI and the HTTP method.

setPreferedMediaType

public static void setPreferedMediaType(org.restlet.data.Request request,
                                        org.restlet.data.MediaType[] mediaTypes)
In a Restlet Request object, set the prefered MediaType

Parameters:
request - The Restlet Request object
mediaTypes - The prefered media type

getPreferenceMediaType

public static org.restlet.data.Preference<org.restlet.data.MediaType> getPreferenceMediaType(org.restlet.data.MediaType mediaType)

getFirstElement

public static org.jdom.Element getFirstElement(JcmsResource resource,
                                               String xpathExpression)
                                        throws org.jdom.JDOMException
Utility functions to use XPath expression to introspect xml contained in entity boby of HTTP response

Parameters:
resource - the given resource get by a rest request
xpathExpression - an xpath expression to dig into the body content of the request
Returns:
the first element if the node as a result of the XPath xpression is an element
Throws:
org.jdom.JDOMException - if the XPath expression is invalid or its evaluation on the specified context failed.

getSingleNode

public static Object getSingleNode(JcmsResource resource,
                                   String xpathExpression)
                            throws org.jdom.JDOMException
Provide XPath feature : returns the first of the Nodes in the xml in the entity body of the resource in first argument, with the xPathExpression in second argument.

Parameters:
resource - the search is done into the entity body of this resource
xpathExpression - the XPath expression
Returns:
the list of selected item, which may be of types: Element, Attribute, Text, CDATA, Comment, ProcessingInstruction, Boolean, Double, String, or null if no item was selected.
Throws:
org.jdom.JDOMException - if the XPath expression is invalid or its evaluation on the specified context failed.

getNodeList

public static List<?> getNodeList(JcmsResource resource,
                                  String xpathExpression)
                           throws org.jdom.JDOMException
Provide XPath feature : returns the list of Nodes in the xml in the entity body of the resource in first argument, with the xPathExpression in second argument.

Parameters:
resource - the given resource get by a rest request
xpathExpression - the XPath expression
Returns:
the list of selected item, which may be of types: Element, Attribute, Text, CDATA, Comment, ProcessingInstruction, Boolean, Double, String, or null if no item was selected.
Throws:
org.jdom.JDOMException - if the XPath expression is invalid or its evaluation on the specified context failed.

getString

public static String getString(JcmsResource resource,
                               String xpathExpression)
                        throws org.jdom.JDOMException
Return the most pertinent String for the result of the XPath query in the body content of the given resource.

Parameters:
resource - the given resource get by a rest request
xpathExpression - an xpath expression to dig into the body content of the request
Returns:
the String found or null
Throws:
org.jdom.JDOMException - if the XPath expression is invalid or its evaluation on the specified context failed.

getBoolean

public static boolean getBoolean(JcmsResource resource,
                                 String xpathExpression,
                                 boolean def)
If the result of the XPath query is a boolean String, it is converted in Boolean. Otherwise, the default value is returned.

Parameters:
resource - the given resource get by a rest request
xpathExpression - an xpath expression to dig into the body content of the request
def - the default value
Returns:
the value associated to the string found or def.

getDate

public static Date getDate(JcmsResource resource,
                           String xpathExpression,
                           Date def)
If the result of the XPath query is a Date as defined by the W3C Date Time format (eg 1999-01-01T14:07:00+01:00).
For more details, see http://www.w3.org/TR/NOTE-datetime
, it is converted this Date. Otherwise, the default value is returned.

Parameters:
resource - the given resource get by a rest request
xpathExpression - an xpath expression to dig into the body content of the request
def - the default value
Returns:
the value associated to the string found or def.

getLong

public static long getLong(JcmsResource resource,
                           String xpathExpression,
                           long def)
If the result of the XPath query is a long representation String, it is converted as an long. Otherwise, the default value is returned.

Parameters:
resource - the given resource get by a rest request
xpathExpression - an xpath expression to dig into the body content of the request
def - the default value
Returns:
the value associated to the string found or def.


Copyright © 2001-2007 Jalios SA. All Rights Reserved.