to.etc.domui.state
Class PageParameters

java.lang.Object
  extended by to.etc.domui.state.PageParameters

public class PageParameters
extends java.lang.Object

Encapsulates parameters for a page. All parameters must be presentable in URL form, i.e. they must be renderable as part of a GET or POST. A page request formed by a Page class and a PageParameters class is bookmarkable. This is a mutable object. A PageParameters object can be rendered on an URL by using DomUtil.addUrlParameters(StringBuilder, PageParameters, boolean).

Author:
Frits Jalvingh Created on Jun 22, 2008

Constructor Summary
PageParameters()
          Create an empty PageParameters.
PageParameters(java.lang.Object... list)
          Create page parameters and fill with the initial set defined in the argument list.
 
Method Summary
 void addParameter(java.lang.String name, java.lang.Object value)
          Adds a parameter with the specified name.
 void addParameters(java.lang.Object... plist)
          Add parameters.
static PageParameters createFrom(IRequestContext ctx)
          Create this from an actual request.
 boolean equals(java.lang.Object obj)
          Compare this with another instance.
 int getInt(java.lang.String name)
          Gets the value for the specified parametername as an int (primitive).
 int getInt(java.lang.String name, int df)
          Gets the value for the specified parametername as an int (primitive).
 long getLong(java.lang.String name)
          Gets the value for the specified parametername as a long (primitive).
 long getLong(java.lang.String name, long df)
          Gets the value for the specified parametername as a long (primitive).
 java.lang.Long getLongW(java.lang.String name)
          Gets the value for the specified parametername as a Long object.
 java.lang.Long getLongW(java.lang.String name, long df)
          Gets the value for the specified parametername as a Long object.
 java.lang.Long getLongW(java.lang.String name, java.lang.Long df)
          Gets the value for the specified parametername as a Long object.
 java.lang.String[] getParameterNames()
          Gets all the names of the parameters this object is holding
 java.lang.String getString(java.lang.String name)
          Gets the value for the specified parametername as a String object.
 java.lang.String getString(java.lang.String name, java.lang.String df)
          Gets the value for the specified parametername as a String object.
 java.lang.String[] getStringArray(java.lang.String name)
          Gets the value for the specified parametername as a String array.
 int hashCode()
           
 boolean hasParameter(java.lang.String name)
          Indicates whether a given parameter name exists in this PageParameters object.
 void removeParameter(java.lang.String name)
          Removes the parameter with specified name entirely from the map.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PageParameters

public PageParameters()
Create an empty PageParameters.


PageParameters

public PageParameters(java.lang.Object... list)
Create page parameters and fill with the initial set defined in the argument list. For details of what can be passed see addParameters(Object...).

Parameters:
list -
Method Detail

addParameters

public void addParameters(java.lang.Object... plist)
                   throws java.lang.Exception
Add parameters. This accepts multiple formats that can all be mixed. Each actual parameter always is a name, value pair. The simplest way to use this is to specify a list of strings in pairs where the first string in the pair is the key and the second one is the value. You can also substitute an object instance for the value; if this object instance represents some persistent entity or implements ILongIdentifyable the primary key for the object will be rendered as the value, otherwise it will be rendered as a tostring. You can also specify a single object in the location for the next key; in this case both key and value will be determined from this object; it must be some persistent object which knows it's key field.

Parameters:
plist -
Throws:
java.lang.Exception

addParameter

public void addParameter(java.lang.String name,
                         java.lang.Object value)
Adds a parameter with the specified name. When a parameter with the same name already exists, the existing value will be overwritten with the specified value.

Parameters:
name, - the parameter name.
value, - the (new) value.

removeParameter

public void removeParameter(java.lang.String name)
Removes the parameter with specified name entirely from the map.

Parameters:
name, - the name of the parameter to be removed.

hasParameter

public boolean hasParameter(java.lang.String name)
Indicates whether a given parameter name exists in this PageParameters object.

Parameters:
name, - the name of the parameter to be checked for.
Returns:
true when the parameter exists, false otherwise.

getInt

public int getInt(java.lang.String name)
Gets the value for the specified parametername as an int (primitive). If the parameter does not exists or the value cannot be converted to an int, a MissingParameterException is thrown.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
Returns:
the value as an int

getInt

public int getInt(java.lang.String name,
                  int df)
Gets the value for the specified parametername as an int (primitive). If the parameter does cannot be converted to an int, a MissingParameterException is thrown. When the parameter does not exist, the specified default value is returned.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
df, - the default value to be returned, when the specified parameter does not exist.
Returns:
the value as an int

getLong

public long getLong(java.lang.String name)
Gets the value for the specified parametername as a long (primitive). When multiple value exists for the specified parameter, the first element of the array is returned. If the parameter does not exists or the value cannot be converted to an int, a MissingParameterException is thrown.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
Returns:
the value as a long

getLong

public long getLong(java.lang.String name,
                    long df)
Gets the value for the specified parametername as a long (primitive). When multiple value exists for the specified parameter, the first element of the array is returned. If the parameter does cannot be converted to an int, a MissingParameterException is thrown. When the parameter does not exist, the specified default value is returned.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
df, - the default value to be returned, when the specified parameter does not exist.
Returns:
the value as a long

getLongW

public java.lang.Long getLongW(java.lang.String name)
Gets the value for the specified parametername as a Long object. When multiple value exists for the specified parameter, the first element of the array is returned. If the parameter does not exists or the value cannot be converted to an int, a MissingParameterException is thrown. This method uses decode() so hexadecimal and octal strings can be used as parameter values.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
Returns:
the value as a Long

getLongW

public java.lang.Long getLongW(java.lang.String name,
                               long df)
Gets the value for the specified parametername as a Long object. When multiple value exists for the specified parameter, the first element of the array is returned. If the parameter does cannot be converted to an int, a MissingParameterException is thrown. When the parameter does not exist, the specified default value is returned. This method uses decode() so hexadecimal and octal strings can be used as parameter values.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
df, - the default value to be returned, when the specified parameter does not exist.
Returns:
the value as a Long

getLongW

public java.lang.Long getLongW(java.lang.String name,
                               java.lang.Long df)
Gets the value for the specified parametername as a Long object. When multiple value exists for the specified parameter, the first element of the array is returned. If the parameter does cannot be converted to an int, a MissingParameterException is thrown. When the parameter does not exist, the specified default value is returned. This method uses decode() so hexadecimal and octal strings can be used as parameter values.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
df, - the default value to be returned, when the specified parameter does not exist.
Returns:
the value as a Long

getString

@Nonnull
public java.lang.String getString(java.lang.String name)
Gets the value for the specified parametername as a String object. When multiple value exists for the specified parameter, the first element of the array is returned. When the parameter does not exist, a MissingParameterException is thrown.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
Returns:
the value as a String

getString

@Nullable
public java.lang.String getString(java.lang.String name,
                                           java.lang.String df)
Gets the value for the specified parametername as a String object. When multiple value exists for the specified parameter, the first element of the array is returned. When the parameter does not exist, the specified default value is returned.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
df, - the default value to be returned, when the specified parameter does not exist.
Returns:
the value as a String

getStringArray

@Nonnull
public java.lang.String[] getStringArray(java.lang.String name)
Gets the value for the specified parametername as a String array. When the parameter does not exist, a MissingParameterException is thrown. This method is provided for legacy reasons only. The domui framework discourages uses of parameter arrays.

Parameters:
name, - the name of the parameter who's value is to be retrieved.
Returns:
the value as a String

createFrom

@Nonnull
public static PageParameters createFrom(IRequestContext ctx)
Create this from an actual request. This does not add any parameter that starts with _ or $.

Parameters:
c -
Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getParameterNames

@Nonnull
public java.lang.String[] getParameterNames()
Gets all the names of the parameters this object is holding

Returns:
the parameter names in an array

equals

public boolean equals(java.lang.Object obj)
Compare this with another instance. Used to see that a new request has different parameters than an earlier request.

remark

We check the size of the maps; if they are equal we ONLY have to check that each key-value pair in SOURCE exists in TARGET AND is the same. We don't need to check for "thingies in SRC that do not occur in TGT" because that cannot happen if the map sizes are equal.

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object