类 ValueParser

所有已实现的接口:
Map<String,Object>

@DefaultKey("parser") @InvalidScope("session") @SkipSetters public class ValueParser extends FormatConfig implements Map<String,Object>

Utility class for easy parsing of String values held in a Map.

This comes in very handy when parsing parameters.

When subkeys are allowed, getValue("foo") will also search for all keys of the form "foo.bar" and return a ValueParser of the type "bar" -> value for all found values.

TODO: someone doing java configuration ought to be able to put a source Map in the tool properties, allowing this to be used like other tools
从以下版本开始:
VelocityTools 1.2
版本:
$Revision$ $Date$
作者:
Nathan Bubna
  • 字段详细资料

    • STRINGS_DELIMITER_FORMAT_KEY

      public static final String STRINGS_DELIMITER_FORMAT_KEY
      另请参阅:
    • DEFAULT_STRINGS_DELIMITER

      public static final String DEFAULT_STRINGS_DELIMITER
      另请参阅:
    • ALLOWSUBKEYS_KEY

      public static final String ALLOWSUBKEYS_KEY
      The key used for specifying whether to support subkeys
      另请参阅:
    • READONLY_KEY

      public static final String READONLY_KEY
      The key used for specifying whether to be read-only
      另请参阅:
  • 构造器详细资料

    • ValueParser

      public ValueParser()
    • ValueParser

      public ValueParser(Map<String,Object> source)
  • 方法详细资料

    • setSource

      protected void setSource(Map<String,Object> source)
    • getSource

      protected Map<String,Object> getSource(boolean create)
    • getSource

      protected Map<String,Object> getSource()
    • getAllowSubkeys

      protected boolean getAllowSubkeys()
      Are subkeys allowed ?
      返回:
      yes/no
    • setAllowSubkeys

      protected void setAllowSubkeys(boolean allow)
      allow or disallow subkeys
      参数:
      allow - flag value
    • getReadOnly

      protected boolean getReadOnly()
      Is the Map read-only?
      返回:
      yes/no
    • setReadOnly

      protected void setReadOnly(boolean ro)
      Set or unset read-only behaviour
      参数:
      ro - flag value
    • setStringsDelimiter

      protected final void setStringsDelimiter(String stringsDelimiter)
      Sets the delimiter used for separating values in a single String value. The default string delimiter is a comma.
      参数:
      stringsDelimiter - strings delimiter
      另请参阅:
    • configure

      protected void configure(ValueParser values)
      Does the actual configuration. This is protected, so subclasses may share the same ValueParser and call configure at any time, while preventing templates from doing so when configure(Map) is locked.
      覆盖:
      configure 在类中 FormatConfig
      参数:
      values - configuration values
    • exists

      public boolean exists(String key)
      Convenience method for checking whether a certain parameter exists.
      参数:
      key - the parameter's key
      返回:
      true if a parameter exists for the specified key; otherwise, returns false.
    • get

      public Object get(String key)
      Convenience method for use in Velocity templates. This allows for easy "dot" access to parameters. e.g. $params.foo instead of $params.getString('foo')
      参数:
      key - the parameter's key
      返回:
      parameter matching the specified key or null if there is no matching parameter
    • getValue

      public Object getValue(String key)
      Returns the value mapped to the specified key in the Map returned by getSource(). If there is no source, then this will always return null.
      参数:
      key - property key
      返回:
      property value, or null
    • getValue

      public Object getValue(String key, Object alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate value
      返回:
      parameter matching the specified key or the specified alternate Object if there is no matching parameter
    • parseStringList

      protected String[] parseStringList(String value)
    • getValues

      public Object[] getValues(String key)

      Returns an array of values. If the internal value is a string, it is split using the configured delimitor (',' by default).

      If the internal value is not an array or is a string without any delimiter, a singletin array is returned.

      参数:
      key - the desired parameter's key
      返回:
      array of values, or null of the key has not been found. specified alternate Object if there is no matching parameter
    • getString

      public String getString(String key)
      参数:
      key - the parameter's key
      返回:
      parameter matching the specified key or null if there is no matching parameter
    • getString

      public String getString(String key, String alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate value
      返回:
      parameter matching the specified key or the specified alternate String if there is no matching parameter
    • getBoolean

      public Boolean getBoolean(String key)
      参数:
      key - the desired parameter's key
      返回:
      a Boolean object for the specified key or null if no matching parameter is found
    • getBoolean

      public boolean getBoolean(String key, boolean alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate boolean value
      返回:
      boolean value for the specified key or the alternate boolean is no value is found
    • getBoolean

      public Boolean getBoolean(String key, Boolean alternate)
      参数:
      key - the desired parameter's key
      alternate - the alternate Boolean
      返回:
      a Boolean for the specified key or the specified alternate if no matching parameter is found
    • getInteger

      public Integer getInteger(String key)
      参数:
      key - the desired parameter's key
      返回:
      a Integer for the specified key or null if no matching parameter is found
    • getInteger

      public Integer getInteger(String key, Integer alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate Integer
      返回:
      an Integer for the specified key or the specified alternate if no matching parameter is found
    • getLong

      public Long getLong(String key)
      参数:
      key - the desired parameter's key
      返回:
      a Long for the specified key or null if no matching parameter is found
    • getLong

      public Long getLong(String key, Long alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate Long
      返回:
      a Long for the specified key or the specified alternate if no matching parameter is found
    • getDouble

      public Double getDouble(String key)
      参数:
      key - the desired parameter's key
      返回:
      a Double for the specified key or null if no matching parameter is found
    • getDouble

      public Double getDouble(String key, Double alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate Double
      返回:
      an Double for the specified key or the specified alternate if no matching parameter is found
    • getNumber

      public Number getNumber(String key)
      参数:
      key - the desired parameter's key
      返回:
      a Number for the specified key or null if no matching parameter is found
    • getLocale

      public Locale getLocale(String key)
      参数:
      key - the desired parameter's key
      返回:
      a Locale for the specified key or null if no matching parameter is found
    • getNumber

      public Number getNumber(String key, Number alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate Number
      返回:
      a Number for the specified key or the specified alternate if no matching parameter is found
    • getInt

      public int getInt(String key, int alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate int value
      返回:
      the int value for the specified key or the specified alternate value if no matching parameter is found
    • getDouble

      public double getDouble(String key, double alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate double value
      返回:
      the double value for the specified key or the specified alternate value if no matching parameter is found
    • getLocale

      public Locale getLocale(String key, Locale alternate)
      参数:
      key - the desired parameter's key
      alternate - The alternate Locale
      返回:
      a Locale for the specified key or the specified alternate if no matching parameter is found
    • getStrings

      public String[] getStrings(String key)
      参数:
      key - the key for the desired parameter
      返回:
      an array of String objects containing all of the values associated with the given key, or null if the no values are associated with the given key
    • getBooleans

      public Boolean[] getBooleans(String key)
      参数:
      key - the key for the desired parameter
      返回:
      an array of Boolean objects associated with the given key.
    • getNumbers

      public Number[] getNumbers(String key)
      参数:
      key - the key for the desired parameter
      返回:
      an array of Number objects associated with the given key, or null if Numbers are not associated with it.
    • getInts

      public int[] getInts(String key)
      参数:
      key - the key for the desired parameter
      返回:
      an array of int values associated with the given key, or null if numbers are not associated with it.
    • getDoubles

      public double[] getDoubles(String key)
      参数:
      key - the key for the desired parameter
      返回:
      an array of double values associated with the given key, or null if numbers are not associated with it.
    • getLocales

      public Locale[] getLocales(String key)
      参数:
      key - the key for the desired parameter
      返回:
      an array of Locale objects associated with the given key, or null if Locales are not associated with it.
    • hasSubkeys

      public boolean hasSubkeys()
      Determines whether there are subkeys available in the source map.
      返回:
      true if there are subkeys (key names containing a dot)
    • getSubkeys

      public Set<String> getSubkeys()
      returns the set of all possible first-level subkeys, including complete keys without dots (or returns keySet() if allowSubKeys is false)
      返回:
      the set of all possible first-level subkeys
    • getSubkey

      public ValueParser getSubkey(String subkey)
      subkey getter that returns a map subkey#2 -> value for every "subkey.subkey2" found entry
      参数:
      subkey - subkey to search for
      返回:
      the map of found values
    • size

      public int size()
      指定者:
      size 在接口中 Map<String,Object>
    • isEmpty

      public boolean isEmpty()
      指定者:
      isEmpty 在接口中 Map<String,Object>
    • containsKey

      public boolean containsKey(Object key)
      指定者:
      containsKey 在接口中 Map<String,Object>
    • containsValue

      public boolean containsValue(Object value)
      指定者:
      containsValue 在接口中 Map<String,Object>
    • get

      public Object get(Object key)
      指定者:
      get 在接口中 Map<String,Object>
    • put

      public Object put(String key, Object value)
      指定者:
      put 在接口中 Map<String,Object>
    • remove

      public Object remove(Object key)
      指定者:
      remove 在接口中 Map<String,Object>
    • putAll

      public void putAll(Map<? extends String,? extends Object> m)
      指定者:
      putAll 在接口中 Map<String,Object>
    • clear

      public void clear()
      指定者:
      clear 在接口中 Map<String,Object>
    • keySet

      public Set<String> keySet()
      指定者:
      keySet 在接口中 Map<String,Object>
    • values

      public Collection values()
      指定者:
      values 在接口中 Map<String,Object>
    • entrySet

      public Set<Map.Entry<String,Object>> entrySet()
      指定者:
      entrySet 在接口中 Map<String,Object>
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object