com.threerings.servlet.util
Class Parameters

java.lang.Object
  extended by com.threerings.servlet.util.Parameters

public class Parameters
extends Object

Provides convenient access to and conversion of the parameters of an HttpServletRequest.


Constructor Summary
Parameters(javax.servlet.ServletRequest req)
           
 
Method Summary
 Collection<Tuple<String,String>> entries()
          Returns all the names and values in the parameters.
 String get(String name)
          Returns the value for the parameter on this request or null if it has no such parameter.
<T> T
get(String name, Function<String,T> converter, T def)
          Returns the value for the parameter on this request as converted by converter or defif it has no such parameter.
 String get(String name, String def)
          Returns the value for the parameter on this request or def if it has no such parameter.
<T> Collection<T>
getAll(String name, Function<String,T> converter, T... defaultValues)
          Returns all the values for the given parameter on the request as converted by converter, or defaultValues if it has no such parameter.
 String[] getAll(String name, String... defaultValues)
          Returns all the values for the given parameter on the request, or defaultValues if it has no such parameter.
 boolean has(String name)
          Returns true if the request contains the given parameter.
 Set<String> names()
          Returns an Iterable over all the parameter names for this request.
 String require(String name)
          Returns the value for the parameter on this request or throws NullPointerException if it has no such parameter.
<T> T
require(String name, Function<String,T> converter)
          Returns the value for the parameter on this request as converted by converter or throws NullPointerException if it has no such parameter.
 Collection<String[]> values()
          Returns a Collection of all the parameter values for this request.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parameters

public Parameters(javax.servlet.ServletRequest req)
Method Detail

names

public Set<String> names()
Returns an Iterable over all the parameter names for this request.


values

public Collection<String[]> values()
Returns a Collection of all the parameter values for this request.


entries

public Collection<Tuple<String,String>> entries()
Returns all the names and values in the parameters. The name is Tuple.left and the value is Tuple.right. If a name appears multiple times, it'll be in multiple tuples.


has

public boolean has(String name)
Returns true if the request contains the given parameter.


get

public String get(String name)
Returns the value for the parameter on this request or null if it has no such parameter. IllegalStateException is thrown if the request has multiple values for the parameter.


get

public String get(String name,
                  String def)
Returns the value for the parameter on this request or def if it has no such parameter. IllegalStateException is thrown if the request has multiple values for the parameter.


get

public <T> T get(String name,
                 Function<String,T> converter,
                 T def)
Returns the value for the parameter on this request as converted by converter or defif it has no such parameter.

If converter can't handle the value and throws ConversionFailedException, that will be propagated by this method with the parameter name and value filled in. Any other exceptions thrown by converter will be wrapped in ConversionFailedException and rethrown.

IllegalStateException is thrown if the request has multiple values for the parameter.


require

public String require(String name)
Returns the value for the parameter on this request or throws NullPointerException if it has no such parameter. IllegalStateException is thrown if the request has multiple values for the parameter.


require

public <T> T require(String name,
                     Function<String,T> converter)
Returns the value for the parameter on this request as converted by converter or throws NullPointerException if it has no such parameter.

If converter can't handle the value and throws ConversionFailedException, that will be propagated by this method with the parameter name and value filled in. Any other exceptions thrown by converter will be wrapped in ConversionFailedException and rethrown.

IllegalStateException is thrown if the request has multiple values for the parameter.


getAll

public String[] getAll(String name,
                       String... defaultValues)
Returns all the values for the given parameter on the request, or defaultValues if it has no such parameter.


getAll

public <T> Collection<T> getAll(String name,
                                Function<String,T> converter,
                                T... defaultValues)
Returns all the values for the given parameter on the request as converted by converter, or defaultValues if it has no such parameter.

If converter can't handle the value and throws ConversionFailedException, that will be propagated by this method with the parameter name and value filled in. Any other exceptions thrown by converter will be wrapped in ConversionFailedException and rethrown.



Copyright © 2012. All Rights Reserved.