/** * Initializes this instance for the current request. * Also looks for a safe-mode configuration setting. By default, * safeMode is true and thus keys with '.' in them are hidden. */ protected void configure(ValueParser parser) { this.context = (Context)parser.getValue(ToolContext.CONTEXT_KEY); }
/** * Convenience method for checking whether a certain parameter exists. * * @param key the parameter's key * @return <code>true</code> if a parameter exists for the specified * key; otherwise, returns <code>false</code>. */ public boolean exists(String key) { return (getValue(key) != null); }
/** * @param key the desired parameter's key * @param alternate The alternate value * @return parameter matching the specified key or the * specified alternate Object if there is no matching * parameter */ public Object getValue(String key, Object alternate) { Object value = getValue(key); if (value == null) { return alternate; } return value; }
/** * @param key the parameter's key * @return parameter matching the specified key or * <code>null</code> if there is no matching * parameter */ public String getString(String key) { return ConversionUtils.toString(getValue(key)); }
/** * @param key the desired parameter's key * @return a {@link Locale} for the specified key or * <code>null</code> if no matching parameter is found */ public Locale getLocale(String key) { return toLocale(getValue(key)); }
/** * @param key the desired parameter's key * @return a {@link Boolean} object for the specified key or * <code>null</code> if no matching parameter is found */ public Boolean getBoolean(String key) { return ConversionUtils.toBoolean(getValue(key)); }
/** * <p>Returns an array of values. If the internal value is a string, it is split using the configured delimitor * (',' by default).</p> * <p>If the internal value is not an array or is a string without any delimiter, a singletin array is returned.</p> * @param key the desired parameter's key * @return array of values, or null of the key has not been found. * specified alternate Object if there is no matching * parameter */ public Object[] getValues(String key) { Object value = getValue(key); if (value == null) { return null; } if (value instanceof String) { return parseStringList((String)value); } if (value instanceof Object[]) { return (Object[])value; } return new Object[] { value }; }
/** * @param key the desired parameter's key * @return a {@link Integer} for the specified key or * <code>null</code> if no matching parameter is found */ public Integer getInteger(String key) { Object value = getValue(key); if (value == null) { return null; } Number number = ConversionUtils.toNumber(value, getFormat(), getLocale()); return number == null ? null : number.intValue(); }
/** * @param key the desired parameter's key * @return a {@link Double} for the specified key or * <code>null</code> if no matching parameter is found */ public Double getDouble(String key) { Object value = getValue(key); if (value == null) { return null; } Number number = ConversionUtils.toNumber(value, getFormat(), getLocale()); return number == null ? null : number.doubleValue(); }
/** * @param key the desired parameter's key * @return a {@link Number} for the specified key or * <code>null</code> if no matching parameter is found */ public Number getNumber(String key) { return ConversionUtils.toNumber(getValue(key), getFormat(), getLocale()); }
/** * Convenience method for use in Velocity templates. * This allows for easy "dot" access to parameters. * * e.g. $params.foo instead of $params.getString('foo') * * @param key the parameter's key * @return parameter matching the specified key or * <code>null</code> if there is no matching * parameter */ public Object get(String key) { Object value = getValue(key); if (value == null && getSource() != null && getAllowSubkeys()) { value = getSubkey(key); } return value; }