public abstract class IlvServletParameters extends Object
IlvServletParameters
class represents a read-only collection
of parameter name-value string pairs. IlvServletParameters
is an
abstract base class because it defines useful methods that simplify parameter
parsing and handling, but does not define the source of the parameters.
Concrete subclasses must connect to the source of the parameters and
return them by implementing the getParameterTable()
method.
Methods of this class can return parameter values of many basic types (no casting or parsing required), can throw an exception when a parameter is not found (simplifying error handling), and can accept default values (eliminating error handling). It is used like this:
float jpegQuality = params.getFloat("quality", 1.0); int width = 0; try { width = params.getInteger("width"); } catch (NumberFormatException e) { handleBadWidth(); } catch (IlvParameterException e) { handleNoWidth(); }
The IlvServletParameters
class uses a delegation model to search
for named parameters. Each instance of IlvServletParameters
has an optional parent parameters object. When called upon to find a
named parameter, an IlvServletParameters
instance will first
attempt to search itself for the parameter. If it cannot find the named
parameter, it will then delegate the search to its parent.
The default charset for input parameters is ISO-8859-1 (Latin-1).
If the parameter values are encoded in another format, specify the encoding
using setCharacterEncoding()
before parsing. The parameter
names currently have to be in the Latin-1 character set:
This class is based on work done by Jason Hunter as part of theparams.setCharacterEncoding("Shift_JIS"); String japaneseValue = params.getString("latinName");
com.oreilly.servlet
package.Constructor and Description |
---|
IlvServletParameters()
Creates a new
IlvServletParameters with no parent parameters. |
IlvServletParameters(IlvServletParameters parent)
Creates a new
IlvServletParameters with the specified
set of parent parameters. |
Modifier and Type | Method and Description |
---|---|
boolean |
getBoolean(String name)
Returns the named parameter value as a boolean, with
true
indicated by "true", "on", or "yes" (in any letter case) and
false indicated by "false", "off", or "no" (in any letter
case). |
boolean |
getBoolean(String name,
boolean def)
Returns the named parameter value as a boolean.
|
char |
getChar(String name)
Returns the named parameter value as a character.
|
char |
getChar(String name,
char def)
Returns the named parameter value as a character.
|
Date |
getDate(String name)
Returns the named parameter value as a Date.
|
Date |
getDate(String name,
Date def)
Returns the named parameter value as a Date.
|
double |
getDouble(String name)
Returns the named parameter value as a double.
|
double |
getDouble(String name,
double def)
Returns the named parameter value as a double.
|
float |
getFloat(String name)
Returns the named parameter value as a float.
|
float |
getFloat(String name,
float def)
Returns the named parameter value as a float.
|
int |
getInteger(String name)
Returns the named parameter value as an integer.
|
int |
getInteger(String name,
int def)
Returns the named parameter value as an integer.
|
long |
getLong(String name)
Returns the named parameter value as a long.
|
long |
getLong(String name,
long def)
Returns the named parameter value as a long.
|
protected abstract Hashtable |
getParameterTable()
Returns the lookup table of parameter name-value string pairs.
|
IlvServletParameters |
getParentParameters()
Returns the parent parameters or
null if there are none. |
String |
getString(String name)
Returns the named parameter value as a String.
|
String |
getString(String name,
String def)
Returns the named parameter value as a String.
|
String |
getString(String name,
String[] validValues,
String def)
Returns the named parameter value as a String, which must be one of the
specified valid values.
|
String[] |
getStringArray(String name)
Returns the named parameter as an array of String values.
|
String[] |
getStringArray(String name,
String delims)
Returns the named parameter as an array of String values.
|
void |
setCharacterEncoding(String encoding)
Sets the character encoding (charset) of the parameters to help the parser
properly decode values.
|
public IlvServletParameters()
IlvServletParameters
with no parent parameters.public IlvServletParameters(IlvServletParameters parent)
IlvServletParameters
with the specified
set of parent parameters.parent
- The parent parameters.protected abstract Hashtable getParameterTable()
public IlvServletParameters getParentParameters()
null
if there are none.public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException
encoding
- The charset encoding.UnsupportedEncodingException
- if the charset is not supported
on this system.public String getString(String name) throws IlvParameterException
name
- The parameter name.IlvParameterException
- if the parameter was not found
or was the empty string.public String getString(String name, String def)
name
- The parameter name.def
- The default parameter value.public String getString(String name, String[] validValues, String def) throws IlvParameterException
name
- The parameter name.validValues
- The array of valid parameter values.def
- The default parameter value or null
for no default.IlvParameterException
- if the parameter is not one of the
specified valid values.public String[] getStringArray(String name, String delims) throws IlvParameterException
delims
argument are the delimiters for separating tokens.
Delimiter characters themselves will not be treated as tokens.name
- The parameter name.delims
- The delimiters.IlvParameterException
- if the parameter was not found
or was the empty string.public String[] getStringArray(String name) throws IlvParameterException
name
- The parameter name.IlvParameterException
- if the parameter was not found
or was the empty string.public boolean getBoolean(String name) throws IlvParameterException, NumberFormatException
true
indicated by "true", "on", or "yes" (in any letter case) and
false
indicated by "false", "off", or "no" (in any letter
case).name
- The parameter name.IlvParameterException
- if the parameter was not found.NumberFormatException
- if the parameter could not be converted
to a boolean.public boolean getBoolean(String name, boolean def)
name
- The parameter name.def
- the default parameter value.public char getChar(String name) throws IlvParameterException
name
- The parameter name.IlvParameterException
- if the parameter was not found
or was the empty string.public char getChar(String name, char def)
name
- The parameter name.def
- The default parameter value.public double getDouble(String name) throws IlvParameterException, NumberFormatException
name
- The parameter name.IlvParameterException
- if the parameter was not found.NumberFormatException
- if the parameter could not be converted
to a double.public double getDouble(String name, double def)
name
- The parameter name.def
- The default parameter value.public float getFloat(String name) throws IlvParameterException, NumberFormatException
name
- The parameter name.IlvParameterException
- if the parameter was not found.NumberFormatException
- if the parameter could not be converted
to a float.public float getFloat(String name, float def)
name
- The parameter name.def
- The default parameter value.public int getInteger(String name) throws IlvParameterException, NumberFormatException
name
- The parameter name.IlvParameterException
- if the parameter was not found.NumberFormatException
- if the parameter could not be converted
to an integer.public int getInteger(String name, int def)
name
- The parameter name.def
- The default parameter value.public long getLong(String name) throws IlvParameterException, NumberFormatException
name
- The parameter name.IlvParameterException
- if the parameter was not found.NumberFormatException
- if the parameter could not be converted
to a long.public long getLong(String name, long def)
name
- The parameter name.def
- The default parameter value.public Date getDate(String name) throws IlvParameterException, NumberFormatException
java.util.Calendar
class:
name
- The parameter name.IlvParameterException
- if the parameter was not found.NumberFormatException
- if the parameter could not be converted
to a Date.public Date getDate(String name, Date def)
java.util.Calendar
class:
name
- The parameter name.def
- The default parameter value.© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.