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: 31824 $, $Date: 2011-09-09 13:25:58 +0200 (Fri, 09 Sep 2011) $
Author:
Markus Schneider, Oliver Tonnhofer, last edited by: $Author: mschneider $

Constructor Summary
KVPUtils()
           
 
Method Summary
static BigInteger getBigInt(Map<String,String> kvpParams, String paramName, BigInteger defaultValue)
          Returns the specified parameter from a KVP map as a BigInteger value.
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 Map<String,String> getNormalizedKVPMap(String queryString, String encoding)
           
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.
static String[] splitList(String param)
           
static List<String> splitLists(String s)
          Splits a parameter list thats encoded according to ISO 19143, 5.5
static String toQueryString(Map<String,String> map)
           
 
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.

splitLists

public static List<String> splitLists(String s)
Splits a parameter list thats encoded according to ISO 19143, 5.5

Parameters:
s -
Returns:

splitList

public static String[] splitList(String param)

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

getBigInt

public static BigInteger getBigInt(Map<String,String> kvpParams,
                                   String paramName,
                                   BigInteger defaultValue)
                            throws InvalidParameterValueException
Returns the specified parameter from a KVP map as a BigInteger 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

getNormalizedKVPMap

public static Map<String,String> getNormalizedKVPMap(String queryString,
                                                     String encoding)
                                              throws UnsupportedEncodingException
Parameters:
queryString -
encoding - used for decoding the URL-decoded characters, may be null (turns on guessing, don't do it)
Returns:
a map with the query string's kvps parsed (uppercase keys)
Throws:
UnsupportedEncodingException

toQueryString

public static String toQueryString(Map<String,String> map)
Parameters:
map -
Returns:
an UTF-8 URL encoded query string from the kvps in the map


Copyright © 2011. All Rights Reserved.