String loggerName = params.getString(LOGGER_NAME_KEY); if (loggerName != null) boolean useClassLogger = params.getBoolean(USE_CLASS_LOGGER_KEY, false); if (!useClassLogger) VelocityEngine engine = (VelocityEngine) params.get(ToolContext.ENGINE_KEY); String key = (String) params.get(ToolContext.TOOLKEY_KEY); if (engine != null && key != null)
/** * 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; }
/** * @param key the desired parameter's key * @param alternate The alternate Double * @return an Double for the specified key or the specified * alternate if no matching parameter is found */ public Double getDouble(String key, Double alternate) { Double num = getDouble(key); if (num == null) { return alternate; } return num; }
/** * 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. * @param values configuration values */ @Override protected void configure(ValueParser values) { super.configure(values); String delimiter = values.getString(STRINGS_DELIMITER_FORMAT_KEY); if (delimiter != null) { setStringsDelimiter(delimiter); } Boolean allow = values.getBoolean(ALLOWSUBKEYS_KEY); if(allow != null) { setAllowSubkeys(allow); } Boolean ro = values.getBoolean(READONLY_KEY); if(ro != null) { setReadOnly(ro); } }
public Object get(Object key) { return get(String.valueOf(key)); }
if (!hasSubkeys() || subkey == null || subkey.length() == 0) for (Map.Entry<String,Object> entry : getSource().entrySet()) ValueParser ret = new ValueParser(values); ret.setReadOnly(getReadOnly()); return ret;
String listDelim = values.getString(LIST_DELIM_KEY); if (listDelim != null) String listFinalDelim = values.getString(LIST_FINAL_DELIM_KEY); if (listFinalDelim != null) Integer truncateLength = values.getInteger(TRUNCATE_LENGTH_KEY); if (truncateLength != null) String truncateSuffix = values.getString(TRUNCATE_SUFFIX_KEY); if (truncateSuffix != null) Boolean truncateAtWord = values.getBoolean(TRUNCATE_AT_WORD_KEY); if (truncateAtWord != null) Integer cellLength = values.getInteger(CELL_LENGTH_KEY); if (cellLength != null) String cellSuffix = values.getString(CELL_SUFFIX_KEY); if (cellSuffix != null) String defaultAlternate = values.getString(DEFAULT_ALTERNATE_KEY); if (defaultAlternate != null) String[] allowedTags = values.getStrings(ALLOWED_TAGS_KEY); if (allowedTags != null)
/** * Looks for deprecated parse depth and catch.exceptions properties, * as well as any 'forceThreadSafe' setting. */ protected void configure(ValueParser parser) { // look for deprecated parse.depth key Integer depth = parser.getInteger(KEY_PARSE_DEPTH); if (depth != null) { setParseDepth(depth); } // look for deprecated catch.exceptions key Boolean catchEm = parser.getBoolean(KEY_CATCH_EXCEPTIONS); if (catchEm != null) { setCatchExceptions(catchEm); } // check if they want thread-safety manually turned off this.forceThreadSafe = parser.getBoolean(KEY_FORCE_THREAD_SAFE, forceThreadSafe); // if we're request-scoped, then there's no point in forcing the issue if (Scope.REQUEST.equals(parser.getString("scope"))) { this.forceThreadSafe = false; } }
/** * @param key the desired parameter's key * @param alternate The alternate value * @return parameter matching the specified key or the * specified alternate String if there is no matching * parameter */ public String getString(String key, String alternate) { String s = getString(key); return (s != null) ? s : alternate; }
/** * @param key the key for the desired parameter * @return an array of double values associated with the given key, * or <code>null</code> if numbers are not associated with it. */ public double[] getDoubles(String key) { Object[] array = getValues(key); if (array == null) { return null; } double[] ret = new double[array.length]; for (int i = 0; i < array.length; ++i) { ret[i] = ConversionUtils.toNumber(array[i], getFormat(), getLocale()).doubleValue(); } return ret; }
/** * Calls the superclass implementation, then looks for a bundle name * and any time units to be skipped. */ protected void configure(ValueParser values) { // do DateTool config super.configure(values); // look for an alternate bundle String bundle = values.getString(BUNDLE_NAME_KEY); if (bundle != null) { this.bundleName = bundle; } this.depth = values.getInt(DEPTH_KEY, 1); // look for time units to be ignored String[] skip = values.getStrings(SKIPPED_UNITS_KEY); if (skip != null) { timeUnits = new LinkedHashMap(TIME_UNITS); for (int i=0; i < skip.length; i++) { timeUnits.remove(skip[i]); } } }
/** * Configure this tool * @param values configuration values */ protected void configure(ValueParser values) { this.showDeprecated = values.getBoolean(SHOW_DEPRECATED_KEY, showDeprecated); String classname = values.getString(INSPECT_KEY); if (classname != null) { setType(toClass(classname)); } }
/** * 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; } }
/** * 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 supplied URL rendered as a String. * * @param url the URL to import * @return the URL as a string */ public String fetch(String url) { if (url == null || url.length() == 0) { return null; } try { if (importSupport == null) { initializeImportSupport(new ValueParser()); } return importSupport.acquireString(url); } catch (Exception ex) { getLog().error("Exception while acquiring '{}'", url, ex); return null; } }
protected void configure(ValueParser values) { // retrieve any classnames to be inspected and inspect them // *before* setting the storeDynamicLookups property! String[] classnames = values.getStrings(INCLUDE_KEY); if (classnames != null) { for (String classname : classnames) { // make sure we get results for each classname // since these come from the configuration, it's // an error if they're invalid if (in(classname) == null) { // shame that ClassNotFoundException is checked... throw new RuntimeException("Could not find "+classname+" in the classpath"); } } } // find out whether or not we should store dynamic lookups this.storeDynamicLookups = values.getBoolean(STORE_DYNAMIC_KEY, this.storeDynamicLookups); }
/** * If {@link #isConfigLocked} returns {@code true}, then this method * does nothing; otherwise, if {@code false}, this will create a new * {@link ValueParser} from the specified Map of params and call * {@link #configure(ValueParser)} with it. Then this will check * the parameters itself to find out whether or not the configuration * for this tool should be put into safe mode or have its config locked. * The safe mode value should be a boolean under the key * {@link #SAFE_MODE_KEY} and the lock value should be a boolean * under the key {@link #LOCK_CONFIG_KEY}. * @param params configuration values map */ public void configure(Map params) { if (!isConfigLocked()) { ValueParser values = new ValueParser(params); // set up logger initLogger(values); // call configure configure(values); setSafeMode(values.getBoolean(SAFE_MODE_KEY, true)); // check under the new key Boolean lock = values.getBoolean(LOCK_CONFIG_KEY, Boolean.TRUE); setLockConfig(lock.booleanValue()); } }
/** * @param key the desired parameter's key * @param alternate the alternate {@link Boolean} * @return a {@link Boolean} for the specified key or the specified * alternate if no matching parameter is found */ public Boolean getBoolean(String key, Boolean alternate) { Boolean bool = getBoolean(key); return (bool != null) ? bool : alternate; }