protected Map<String,Object> getSource() { return getSource(true); }
/** * Returns the value mapped to the specified key * in the {@link Map} returned by {@link #getSource()}. If there is * no source, then this will always return {@code null}. * @param key property key * @return property value, or null */ public Object getValue(String key) { if (getSource() == null) { return null; } return getSource().get(key); }
public Set<Map.Entry<String,Object>> entrySet() { return getSource().entrySet(); }
public void putAll(Map<? extends String,? extends Object> m) { if(readOnly) { throw new UnsupportedOperationException("Cannot putAll("+m+"); "+getClass().getName()+" is read-only"); } hasSubkeys = null; getSource().putAll(m); }
public void clear() { if(readOnly) { throw new UnsupportedOperationException("Cannot clear(); "+getClass().getName()+" is read-only"); } hasSubkeys = Boolean.FALSE; getSource().clear(); }
public Object remove(Object key) { if(readOnly) { throw new UnsupportedOperationException("Cannot remove("+key+"); "+getClass().getName()+" is read-only"); } if(hasSubkeys != null && hasSubkeys.equals(Boolean.TRUE) && ((String)key).indexOf('.') != -1) { hasSubkeys = null; } return getSource().remove(key); }
public Object put(String key, Object value) { if(readOnly) { throw new UnsupportedOperationException("Cannot put("+key+","+value+"); "+getClass().getName()+" is read-only"); } if(hasSubkeys != null && hasSubkeys.equals(Boolean.FALSE) && key.indexOf('.') != -1) { hasSubkeys = Boolean.TRUE; } return getSource().put(key,value); // TODO this tool should be made thread-safe (the request-scoped ParameterTool doesn't need it, but other uses could...) }
/** * Determines whether there are subkeys available in the source map. * @return <code>true</code> if there are subkeys (key names containing a dot) */ public boolean hasSubkeys() { if (getSource() == null || !getAllowSubkeys()) { return false; } if (hasSubkeys == null) { for (String key : getSource().keySet()) { int dot = key.indexOf('.'); if (dot > 0 && dot < key.length()) { hasSubkeys = Boolean.TRUE; break; } } if (hasSubkeys == null) { hasSubkeys = Boolean.FALSE; } } return hasSubkeys; }
/** * returns the set of all possible first-level subkeys, including complete keys without dots (or returns keySet() if allowSubKeys is false) * @return the set of all possible first-level subkeys */ public Set<String> getSubkeys() { Set<String> keys = keySet(); if (getSource() == null || !getAllowSubkeys()) { return keys; } else { Set<String> result = new TreeSet<String>(); for (String key: keys) { int dot = key.indexOf('.'); if (dot > 0 && dot < key.length()) { result.add(key.substring(0, dot)); } } return result; } }
for (Map.Entry<String,Object> entry : getSource().entrySet())
/** * 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; }