com.noelios.restlet.util
Class FormUtils

java.lang.Object
  extended by com.noelios.restlet.util.FormUtils

public class FormUtils
extends Object

Representation of a Web form containing submitted parameters.

Author:
Jerome Louvel (contact@noelios.com)

Constructor Summary
FormUtils()
           
 
Method Summary
static Parameter create(CharSequence name, CharSequence value, CharacterSet characterSet)
          Creates a parameter.
static Parameter getFirstParameter(Logger logger, Representation post, String name)
          Reads the first parameter with the given name.
static Parameter getFirstParameter(Logger logger, String query, String name, CharacterSet characterSet)
          Reads the first parameter with the given name.
static Object getParameter(Logger logger, Representation form, String name)
          Reads the parameters with the given name.
If multiple values are found, a list is returned created.
static Object getParameter(Logger logger, String query, String name, CharacterSet characterSet)
          Reads the parameters with the given name.
If multiple values are found, a list is returned created.
static void getParameters(Logger logger, Representation post, Map<String,Object> parameters)
          Reads the parameters whose name is a key in the given map.
If a matching parameter is found, its value is put in the map.
If multiple values are found, a list is created and set in the map.
static void getParameters(Logger logger, String query, Map<String,Object> parameters, CharacterSet characterSet)
          Reads the parameters whose name is a key in the given map.
If a matching parameter is found, its value is put in the map.
If multiple values are found, a list is created and set in the map.
static void parsePost(Logger logger, Form form, Representation post)
          Parses a post into a given form.
static void parseQuery(Logger logger, Form form, String query, CharacterSet characterSet)
          Parses a query into a given form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormUtils

public FormUtils()
Method Detail

parseQuery

public static void parseQuery(Logger logger,
                              Form form,
                              String query,
                              CharacterSet characterSet)
Parses a query into a given form.

Parameters:
logger - The logger.
form - The target form.
query - Query string.
characterSet - The supported character encoding.

parsePost

public static void parsePost(Logger logger,
                             Form form,
                             Representation post)
Parses a post into a given form.

Parameters:
logger - The logger.
form - The target form.
post - The posted form.

getParameters

public static void getParameters(Logger logger,
                                 String query,
                                 Map<String,Object> parameters,
                                 CharacterSet characterSet)
                          throws IOException
Reads the parameters whose name is a key in the given map.
If a matching parameter is found, its value is put in the map.
If multiple values are found, a list is created and set in the map.

Parameters:
logger - The logger.
query - The query string.
parameters - The parameters map controlling the reading.
characterSet - The supported character encoding.
Throws:
IOException

getParameters

public static void getParameters(Logger logger,
                                 Representation post,
                                 Map<String,Object> parameters)
                          throws IOException
Reads the parameters whose name is a key in the given map.
If a matching parameter is found, its value is put in the map.
If multiple values are found, a list is created and set in the map.

Parameters:
logger - The logger.
post - The web form representation.
parameters - The parameters map controlling the reading.
Throws:
IOException

getFirstParameter

public static Parameter getFirstParameter(Logger logger,
                                          String query,
                                          String name,
                                          CharacterSet characterSet)
                                   throws IOException
Reads the first parameter with the given name.

Parameters:
logger - The logger.
query - The query string.
name - The parameter name to match.
characterSet - The supported character encoding.
Returns:
The parameter.
Throws:
IOException

getFirstParameter

public static Parameter getFirstParameter(Logger logger,
                                          Representation post,
                                          String name)
                                   throws IOException
Reads the first parameter with the given name.

Parameters:
logger - The logger.
post - The web form representation.
name - The parameter name to match.
Returns:
The parameter.
Throws:
IOException

getParameter

public static Object getParameter(Logger logger,
                                  String query,
                                  String name,
                                  CharacterSet characterSet)
                           throws IOException
Reads the parameters with the given name.
If multiple values are found, a list is returned created.

Parameters:
logger - The logger.
query - The query string.
name - The parameter name to match.
characterSet - The supported character encoding.
Returns:
The parameter value or list of values.
Throws:
IOException

getParameter

public static Object getParameter(Logger logger,
                                  Representation form,
                                  String name)
                           throws IOException
Reads the parameters with the given name.
If multiple values are found, a list is returned created.

Parameters:
logger - The logger.
form - The web form representation.
name - The parameter name to match.
Returns:
The parameter value or list of values.
Throws:
IOException

create

public static Parameter create(CharSequence name,
                               CharSequence value,
                               CharacterSet characterSet)
                        throws IOException
Creates a parameter.

Parameters:
name - The parameter name buffer.
value - The parameter value buffer (can be null).
characterSet - The supported character encoding.
Returns:
The created parameter.
Throws:
IOException


Copyright © 2005-2007 Noelios Consulting.