deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official

org.deegree.commons.utils.kvp
Class KVPUtils

java.lang.Object
  extended by org.deegree.commons.utils.kvp.KVPUtils

public class KVPUtils
extends Object

This class contains convenience methods for working with key-value pair maps (e.g. from OGC KVP requests).

Version:
$Revision: 22808 $, $Date: 2010-03-03 17:26:39 +0100 (Mi, 03 Mrz 2010) $
Author:
Markus Schneider, Oliver Tonnhofer, last edited by: $Author: rbezema $

Constructor Summary
KVPUtils()
           
 
Method Summary
static boolean getBoolean(Map<String,String> kvpParams, String paramName, boolean defaultValue)
          Returns the specified parameter from a KVP map as a boolean value.
static String getDefault(Map<String,String> param, String key, String defaultValue)
          Returns the value of the key or the default value if the kvp map doesn't contain the key.
static double getDefaultDouble(Map<String,String> param, String key, double defaultValue)
           
static int getInt(Map<String,String> kvpParams, String paramName, int defaultValue)
          Returns the specified parameter from a KVP map as an integer value.
static String getRequired(Map<String,String> param, String key)
          Returns the value of the key.
static double getRequiredDouble(Map<String,String> param, String key)
           
static int getRequiredInt(Map<String,String> param, String key)
           
static Map<String,String> readFileIntoMap(URL url)
          Reads a text file with KVP content into a map.
static List<String> splitAll(Map<String,String> param, String key)
          Return a list with all values for a key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KVPUtils

public KVPUtils()
Method Detail

getRequired

public static String getRequired(Map<String,String> param,
                                 String key)
                          throws MissingParameterException
Returns the value of the key. Throws an exception if the kvp map doesn't contain the key.

Parameters:
param - the key-value map
key -
Returns:
the value
Throws:
MissingParameterException - if the kvp map doesn't contain the key

getRequiredInt

public static int getRequiredInt(Map<String,String> param,
                                 String key)
                          throws MissingParameterException,
                                 InvalidParameterValueException
Parameters:
param -
key -
Returns:
the parsed value as an integer
Throws:
MissingParameterException - if the kvp map doesn't contain the key
InvalidParameterValueException - if the value is not an integer

getRequiredDouble

public static double getRequiredDouble(Map<String,String> param,
                                       String key)
                                throws MissingParameterException,
                                       InvalidParameterValueException
Parameters:
param -
key -
Returns:
the parsed value as a double
Throws:
MissingParameterException - if the kvp map doesn't contain the key
InvalidParameterValueException - if the value is not a double

getDefaultDouble

public static double getDefaultDouble(Map<String,String> param,
                                      String key,
                                      double defaultValue)
Parameters:
param -
key -
defaultValue - to be used if missing.
Returns:
the parsed value as a double or if the given key was not found or the value was not a number, the default value.

getDefault

public static String getDefault(Map<String,String> param,
                                String key,
                                String defaultValue)
Returns the value of the key or the default value if the kvp map doesn't contain the key.

Parameters:
param - the key-value map
key -
defaultValue -
Returns:
the value

splitAll

public static List<String> splitAll(Map<String,String> param,
                                    String key)
Return a list with all values for a key. Values are splitted if they contain multiple comma delimited values.

Parameters:
param - the key-value map
key -
Returns:
a list with all values

getBoolean

public static boolean getBoolean(Map<String,String> kvpParams,
                                 String paramName,
                                 boolean defaultValue)
                          throws InvalidParameterValueException
Returns the specified parameter from a KVP map as a boolean value.

Parameters:
kvpParams - KVP map
paramName - name of the parameter
defaultValue - returned when the specified parameter is not present in the map (=null)
Returns:
the specified parameter value as a boolean value
Throws:
InvalidParameterValueException - if the parameter value is neither null nor "true" nor "false"

getInt

public static int getInt(Map<String,String> kvpParams,
                         String paramName,
                         int defaultValue)
                  throws InvalidParameterValueException
Returns the specified parameter from a KVP map as an integer value.

Parameters:
kvpParams - KVP map
paramName - name of the parameter
defaultValue - returned when the specified parameter is not present in the map (=null)
Returns:
the specified parameter value as an integer value
Throws:
InvalidParameterValueException - if the parameter value does not denote an integer

readFileIntoMap

public static Map<String,String> readFileIntoMap(URL url)
                                          throws IOException
Reads a text file with KVP content into a map.

Example contents:

 SERVICE=WFS
 VERSION=1.1.0
 REQUEST=DescribeFeatureType
 TYPENAME=TreesA_1M
 
What this method does:

Parameters:
url - url of the text file
Returns:
map with the contents of the file, keys are uppercased
Throws:
IOException - if the the file cannot be loaded

deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org

]]>