com.smartwerkz.jupload.classic.config.params
Class Parameters

java.lang.Object
  extended by com.smartwerkz.jupload.classic.util.CaseInsensitiveMap
      extended by com.smartwerkz.jupload.classic.config.params.Parameters
All Implemented Interfaces:
java.util.Map

public class Parameters
extends CaseInsensitiveMap

This class provides simplified parameter access and string-to-type-conversion methods. When created, it will automatically parse all default values or -if existing- their user-overridden complements. See the description for the types for conversion hints. Empty strings will be replaced by their type-default stringValue which is null for some non-native types. The type is case-independent and of the format: "formatString[ list_of_strings]" If a list of strings (strings, seperated by komma) is provided, it will be considered a list of restrictions. Values must then be either of theese values or the parsing will fail. Every plugin author is recommended to add all intended values into the defaults for more type-safety. For the use of user-customized Parameters, the get-method is overridden to fetch those non-default values directly from the environment and the parseValue, parseListValue and parseMapValue methods are delivered to convert values of given keys on-the-fly. Theese methods are only to be used for user-given values that the plugin author could not (or did not want to) define by default. If the parsing succeeds, the stringValue will be added to the Parameters-table.

Since:
Jan 25, 2006, 4:58:30 AM
Author:
Dominik Seifert

Nested Class Summary
 
Nested classes/interfaces inherited from class com.smartwerkz.jupload.classic.util.CaseInsensitiveMap
CaseInsensitiveMap.StringWrapper
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
 java.lang.String defaultListSeperator
          A string that seperates List elements.
static CaseInsensitiveMap defaultValues
           
 ParameterEnvironment environment
           
static java.lang.String TYPE_BOOL
           
static java.lang.String TYPE_COLOR
          Will use web-color rgb values to create a new color object (e.g.
static java.lang.String TYPE_DIMENSION
          Will create a new Dimension object where the stringValue should be widthXheight.
static java.lang.String TYPE_DOUBLE
           
static java.lang.String TYPE_EXTFILEFILTER
          Will create a new swing FileFilter with a double vertical line to seprate description and regex for valid files using the pattern: description||regexforfilepathes to be accepted
static java.lang.String TYPE_FILE
          Will use the string stringValue as path.
static java.lang.String TYPE_FONT
          Will create a new Font from a list of strings in the pattern: fontname,fontsize,fontstyle The fontstyle can be 0 (plain), 1 (bold), 2 (underline) or 3 (bold and underline).
static java.lang.String TYPE_IMAGE
          Will create a new BufferedImage from the given file location
static java.lang.String TYPE_INT
           
static java.lang.String TYPE_INTEGERRANGE
          A list of ranges of integers (eg 1-5,8,23,400-3201).
static java.lang.String TYPE_LIST
          Will create a new List, containing elements that are seperated by the given list seperator.
static java.lang.String TYPE_LOCALE
          Will create a new locale out of a list of strings of the following pattern: language[,country[,variant]]
static java.lang.String TYPE_LONG
           
static java.lang.String TYPE_MAP
          Will create a new Map, containing a list of key=stringValue pairs.
static java.lang.String TYPE_REGEXFILEFILTER
          Will create a new swing FileFilter with a double vertical line to seprate description and regex for valid files using the pattern: description||regexforfilepathes to be accepted
static java.lang.String TYPE_STRING
           
static java.lang.String TYPE_STRINGPAIR
           
static java.lang.String TYPE_URL
          Will use the string stringValue to build a new url or merge it with the underlying environment's codebase if its a relative target.
 
Constructor Summary
Parameters(ParameterEnvironment environment)
           
Parameters(ParameterEnvironment environment, java.lang.String defaultListSeperator)
           
Parameters(ParameterEnvironment environment, java.lang.String[][] defaults)
          Creates a new Paremeters container which retrieves the defaults from the given String array.
Parameters(Parameters ps)
           
 
Method Summary
 Parameter add(java.lang.String key, java.lang.String value, java.lang.String type)
           
 Parameter add(java.lang.String key, java.lang.String value, java.lang.String type, java.lang.String[] subtypes)
           
 void addParameters(java.lang.String[][] defaults)
          Will parse and add the given String array of parameters to this instance.
 java.lang.Object get(java.lang.Object key)
           
 boolean getBool(java.lang.Object key)
           
 java.awt.Color getColor(java.lang.Object key)
           
 java.awt.Dimension getDimension(java.lang.Object key)
           
 double getDouble(java.lang.Object key)
           
 java.io.File getFile(java.lang.Object key)
           
 javax.swing.filechooser.FileFilter getFileFilter(java.lang.Object key)
           
 float getFloat(java.lang.Object key)
           
 java.awt.Font getFont(java.lang.Object key)
           
 java.awt.image.BufferedImage getImage(java.lang.Object key)
           
 int getInt(java.lang.Object key)
           
 IntRanges getIntRanges(java.lang.Object key)
           
 java.util.List getList(java.lang.Object key)
           
 java.util.Locale getLocale(java.lang.Object key)
           
 long getLong(java.lang.Object key)
           
 NOKMap getMap(java.lang.Object key)
           
 java.lang.Object getObject(java.lang.Object key)
           
 Parameter getParam(java.lang.Object key)
           
 java.lang.String getString(java.lang.Object key)
           
 StringPair getStringPair(java.lang.Object key)
           
 java.net.URL getURL(java.lang.Object key)
           
 java.lang.Object parse(Parameter p)
          Returns the given stringValue parsed and converted into an Object of the given type.
static boolean parseBool(java.lang.String value)
           
static java.awt.Color parseColor(java.lang.String value)
          converts a web-color stringValue (e.g.
static java.awt.Dimension parseDimension(Parameter p, java.lang.String value)
          Returns a new Dimension where the stringValue is of the following pattern: widthXheight.
static javax.swing.filechooser.FileFilter parseExtFileFilter(java.lang.String value)
          Returns a filefilter where the description and a regex pattern for all files to be allowed are seperated by the first double vertical line ("||").
 java.awt.Font parseFont(java.lang.String value)
          Returns a new font where the stringValue is a list of the following pattern: fontname,fontsize,fontstyle.
 java.awt.image.BufferedImage parseImage(java.lang.String value)
           
 IntRanges parseIntRanges(java.lang.String value)
           
 java.util.List parseList(java.lang.String value, java.lang.String valueType)
          Returns a List of the given type where the list elements are seperated by the defaultListSeperator.
 java.util.List parseList(java.lang.String value, java.lang.String valueType, java.lang.String seperator)
          Returns a List of the given type where the list elements are seperated by seperator.
 java.util.Locale parseLocal(java.lang.String value)
          Returns a new locale where the stringValue is a string-list of the following pattern: language[,country[,variant]]
 NOKMap parseMap(java.lang.String value, java.lang.String keyType, java.lang.String valueType)
           
 NOKMap parseMap(java.lang.String value, java.lang.String keyType, java.lang.String valueType, java.lang.String seperator)
          Parses the given stringValue as a map.
static javax.swing.filechooser.FileFilter parseRegexFileFilter(java.lang.String value)
          Returns a filefilter where the description and a regex pattern for all files to be allowed are seperated by the first double vertical line ("||").
 java.net.URL parseURL(java.lang.String value)
           
static java.net.URL parseURL(java.lang.String value, java.net.URL context)
          Creates a new url from the given string.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 Parameter put(Parameter p)
           
 Parameter put(java.lang.String key, java.lang.Object value, java.lang.String type)
           
 
Methods inherited from class com.smartwerkz.jupload.classic.util.CaseInsensitiveMap
clear, containsKey, containsValue, createCIHashMap, createCITreeMap, entrySet, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

TYPE_STRING

public static final java.lang.String TYPE_STRING
See Also:
Constant Field Values

TYPE_STRINGPAIR

public static final java.lang.String TYPE_STRINGPAIR
See Also:
Constant Field Values

TYPE_INT

public static final java.lang.String TYPE_INT
See Also:
Constant Field Values

TYPE_LONG

public static final java.lang.String TYPE_LONG
See Also:
Constant Field Values

TYPE_DOUBLE

public static final java.lang.String TYPE_DOUBLE
See Also:
Constant Field Values

TYPE_BOOL

public static final java.lang.String TYPE_BOOL
See Also:
Constant Field Values

TYPE_INTEGERRANGE

public static final java.lang.String TYPE_INTEGERRANGE
A list of ranges of integers (eg 1-5,8,23,400-3201).

See Also:
Constant Field Values

TYPE_FILE

public static final java.lang.String TYPE_FILE
Will use the string stringValue as path.

See Also:
Constant Field Values

TYPE_URL

public static final java.lang.String TYPE_URL
Will use the string stringValue to build a new url or merge it with the underlying environment's codebase if its a relative target.

See Also:
Constant Field Values

TYPE_COLOR

public static final java.lang.String TYPE_COLOR
Will use web-color rgb values to create a new color object (e.g. #C0FF40 or C0FF40)

See Also:
Constant Field Values

TYPE_REGEXFILEFILTER

public static final java.lang.String TYPE_REGEXFILEFILTER
Will create a new swing FileFilter with a double vertical line to seprate description and regex for valid files using the pattern: description||regexforfilepathes to be accepted

See Also:
Constant Field Values

TYPE_EXTFILEFILTER

public static final java.lang.String TYPE_EXTFILEFILTER
Will create a new swing FileFilter with a double vertical line to seprate description and regex for valid files using the pattern: description||regexforfilepathes to be accepted

See Also:
Constant Field Values

TYPE_LOCALE

public static final java.lang.String TYPE_LOCALE
Will create a new locale out of a list of strings of the following pattern: language[,country[,variant]]

See Also:
Constant Field Values

TYPE_FONT

public static final java.lang.String TYPE_FONT
Will create a new Font from a list of strings in the pattern: fontname,fontsize,fontstyle The fontstyle can be 0 (plain), 1 (bold), 2 (underline) or 3 (bold and underline).

See Also:
Constant Field Values

TYPE_DIMENSION

public static final java.lang.String TYPE_DIMENSION
Will create a new Dimension object where the stringValue should be widthXheight.

See Also:
Constant Field Values

TYPE_IMAGE

public static final java.lang.String TYPE_IMAGE
Will create a new BufferedImage from the given file location

See Also:
Constant Field Values

TYPE_LIST

public static final java.lang.String TYPE_LIST
Will create a new List, containing elements that are seperated by the given list seperator. If no seperator has been specified, it will use the stringValue of #defaultListSeperator which again defaults to ",". The list's element type must be the 4th parameter.

See Also:
Constant Field Values

TYPE_MAP

public static final java.lang.String TYPE_MAP
Will create a new Map, containing a list of key=stringValue pairs. The map's key type must be the 4th and the stringValue type the 5th parameter.

See Also:
Constant Field Values

defaultValues

public static final CaseInsensitiveMap defaultValues

environment

public final ParameterEnvironment environment

defaultListSeperator

public java.lang.String defaultListSeperator
A string that seperates List elements. Defaults to ",".

Constructor Detail

Parameters

public Parameters(Parameters ps)

Parameters

public Parameters(ParameterEnvironment environment,
                  java.lang.String[][] defaults)
           throws ParameterException
Creates a new Paremeters container which retrieves the defaults from the given String array.

Parameters:
environment - the environment to read the configuration parameters
defaults - an array to get the default values for parameters
Throws:
ParameterException

Parameters

public Parameters(ParameterEnvironment environment)
           throws ParameterException
Throws:
ParameterException

Parameters

public Parameters(ParameterEnvironment environment,
                  java.lang.String defaultListSeperator)
           throws ParameterException
Throws:
ParameterException
Method Detail

addParameters

public void addParameters(java.lang.String[][] defaults)
                   throws ParameterException
Will parse and add the given String array of parameters to this instance.

Throws:
ParameterException

add

public Parameter add(java.lang.String key,
                     java.lang.String value,
                     java.lang.String type)
              throws ParameterException
Throws:
ParameterException

add

public Parameter add(java.lang.String key,
                     java.lang.String value,
                     java.lang.String type,
                     java.lang.String[] subtypes)
              throws ParameterException
Throws:
ParameterException

put

public Parameter put(java.lang.String key,
                     java.lang.Object value,
                     java.lang.String type)

put

public Parameter put(Parameter p)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map
Overrides:
put in class CaseInsensitiveMap

getObject

public java.lang.Object getObject(java.lang.Object key)

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map
Overrides:
get in class CaseInsensitiveMap

getParam

public Parameter getParam(java.lang.Object key)

getString

public java.lang.String getString(java.lang.Object key)

getStringPair

public StringPair getStringPair(java.lang.Object key)

getInt

public int getInt(java.lang.Object key)
Throws:
java.lang.NullPointerException - if the key has a null-stringValue.

getLong

public long getLong(java.lang.Object key)
Throws:
java.lang.NullPointerException - if the key has a null-stringValue.

getFloat

public float getFloat(java.lang.Object key)
Throws:
java.lang.NullPointerException - if the key has a null-stringValue.

getDouble

public double getDouble(java.lang.Object key)
Throws:
java.lang.NullPointerException - if the key has a null-stringValue.

getBool

public boolean getBool(java.lang.Object key)
Throws:
java.lang.NullPointerException - if the key has a null-stringValue.

getFile

public java.io.File getFile(java.lang.Object key)

getURL

public java.net.URL getURL(java.lang.Object key)

getColor

public java.awt.Color getColor(java.lang.Object key)

getFileFilter

public javax.swing.filechooser.FileFilter getFileFilter(java.lang.Object key)

getLocale

public java.util.Locale getLocale(java.lang.Object key)

getFont

public java.awt.Font getFont(java.lang.Object key)

getDimension

public java.awt.Dimension getDimension(java.lang.Object key)

getImage

public java.awt.image.BufferedImage getImage(java.lang.Object key)

getIntRanges

public IntRanges getIntRanges(java.lang.Object key)

getList

public java.util.List getList(java.lang.Object key)

getMap

public NOKMap getMap(java.lang.Object key)

parse

public java.lang.Object parse(Parameter p)
                       throws ParameterException
Returns the given stringValue parsed and converted into an Object of the given type. If the given type contains a list of restrictions, the stringValue must be of either of theese values or the parsing will fail.
E.g.:
  1. parse("sweet", "String blue,green,black,brown"); will fail
  2. parse("sweet", "String sweet,sour,bitter,spicy"); will succeed

Parameters:
type - Is of the format: "formatString[ list_of_restriction_strings]"
Throws:
ParameterException - In case that the given type is not supported or the stringValue could not be converted.

parseBool

public static boolean parseBool(java.lang.String value)

parseURL

public java.net.URL parseURL(java.lang.String value)
                      throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

parseURL

public static java.net.URL parseURL(java.lang.String value,
                                    java.net.URL context)
                             throws java.net.MalformedURLException
Creates a new url from the given string. If it is a relative URL, it will use the given context url in combination with the stringValue instead.

Throws:
java.net.MalformedURLException

parseColor

public static java.awt.Color parseColor(java.lang.String value)
converts a web-color stringValue (e.g. #C0FF40) to a Color object


parseRegexFileFilter

public static javax.swing.filechooser.FileFilter parseRegexFileFilter(java.lang.String value)
Returns a filefilter where the description and a regex pattern for all files to be allowed are seperated by the first double vertical line ("||"). It will only accept files whose name matches the given pattern.


parseExtFileFilter

public static javax.swing.filechooser.FileFilter parseExtFileFilter(java.lang.String value)
Returns a filefilter where the description and a regex pattern for all files to be allowed are seperated by the first double vertical line ("||"). It will only accept files whose path match the given pattern.


parseLocal

public java.util.Locale parseLocal(java.lang.String value)
                            throws ParameterException
Returns a new locale where the stringValue is a string-list of the following pattern: language[,country[,variant]]

Throws:
ParameterException

parseFont

public java.awt.Font parseFont(java.lang.String value)
                        throws ParameterException
Returns a new font where the stringValue is a list of the following pattern: fontname,fontsize,fontstyle. The fontstyle can be 0 (plain), 1 (bold), 2 (underline) or 3 (bold and underline)

Throws:
ParameterException

parseDimension

public static java.awt.Dimension parseDimension(Parameter p,
                                                java.lang.String value)
                                         throws ParameterException
Returns a new Dimension where the stringValue is of the following pattern: widthXheight.

Throws:
ParameterException

parseImage

public java.awt.image.BufferedImage parseImage(java.lang.String value)
                                        throws java.io.IOException
Returns:
a new BufferedImage where the stringValue is a file location.
Throws:
java.io.IOException

parseIntRanges

public IntRanges parseIntRanges(java.lang.String value)
                         throws java.lang.Exception
Throws:
java.lang.Exception

parseList

public java.util.List parseList(java.lang.String value,
                                java.lang.String valueType)
                         throws ParameterException
Returns a List of the given type where the list elements are seperated by the defaultListSeperator. Seperators within one element must be escaped with "\". Correspondingly "\" before a seperator must also be escaped with "\". Eg (if seperator = ","): "myList=c:,d:\\,e:\mypathwith\,komma" will result into: {"c:", "d:\", "e:\mypathwith,komma"}

Throws:
ParameterException

parseList

public java.util.List parseList(java.lang.String value,
                                java.lang.String valueType,
                                java.lang.String seperator)
                         throws ParameterException
Returns a List of the given type where the list elements are seperated by seperator. Seperators within one element must be escaped with "\". Correspondingly "\" before a seperator must also be escaped with "\".

Throws:
ParameterException

parseMap

public NOKMap parseMap(java.lang.String value,
                       java.lang.String keyType,
                       java.lang.String valueType)
                throws ParameterException
Throws:
ParameterException

parseMap

public NOKMap parseMap(java.lang.String value,
                       java.lang.String keyType,
                       java.lang.String valueType,
                       java.lang.String seperator)
                throws ParameterException
Parses the given stringValue as a map. The pairs are seperated by seperator and have the form: key=stringValue

Throws:
ParameterException


Copyright © 2007 smartwerkz.com. All Rights Reserved.