/** * Return the String property value associated with the given key, or * {@code defaultValue} if the key cannot be resolved. * * @param key the property name to resolve * @param defaultValue the default value to return if no value is found * @return The string property */ public String getString(String key, String defaultValue) { return configuration.getString(key, defaultValue); }
/** * Return the list of keys. * * @return the list of keys. */ public List<String> getKeys() { return IteratorUtils.toList(configuration.getKeys()); }
@Override public Optional<String> lookup(final Map<String, Object> coordinates) throws LookupFailureException { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (StringUtils.isBlank(key)) { return Optional.empty(); } final Configuration config = getConfiguration(); if (config != null) { final Object value = config.getProperty(key); if (value != null) { return Optional.of(String.valueOf(value)); } } return Optional.empty(); }
if (!getConfiguration().containsKey(name)) { return (T) getConfiguration().getStringArray(name); } else if (String.class.equals(type) || type.isAssignableFrom(String.class)) { return (T) getConfiguration().getString(name); } else if (BigDecimal.class.equals(type)) { return (T) getConfiguration().getBigDecimal(name); } else if (BigInteger.class.equals(type)) { return (T) getConfiguration().getBigInteger(name); } else if (Boolean.class.equals(type) || boolean.class.equals(type)) { return (T) Boolean.valueOf(getConfiguration().getBoolean(name)); } else if (Byte.class.equals(type) || byte.class.equals(type)) { return (T) Byte.valueOf(getConfiguration().getByte(name)); } else if (Double.class.equals(type) || double.class.equals(type)) { return (T) Double.valueOf(getConfiguration().getDouble(name)); } else if (Float.class.equals(type) || float.class.equals(type)) { return (T) Float.valueOf(getConfiguration().getFloat(name)); } else if (Integer.class.equals(type) || int.class.equals(type)) { return (T) Integer.valueOf(getConfiguration().getInt(name)); } else if (List.class.equals(type)) { return (T) getConfiguration().getList(name); } else if (Long.class.equals(type) || long.class.equals(type)) { return (T) Long.valueOf(getConfiguration().getLong(name)); } else if (Short.class.equals(type) || short.class.equals(type)) { return (T) Short.valueOf(getConfiguration().getShort(name)); } else { return (T) converter.convertIfNecessary(getConfiguration().getProperty(name), type);
public static RichIterable<DbMergeInfo> parseFromProperties(Configuration config) { MutableSet<String> dbs = CollectionAdapter.wrapSet(config.getList(String.class, "instances", Lists.mutable.<String>empty())); Configuration subset = config.subset(db); if (subset.containsKey("inputDir")) { File inputDir = new File(subset.getString("inputDir")); if (!inputDir.canRead()) { if (inputDir.getPath().contains("\r")) { if (subset.containsKey("driverClassName")) { mergeInfo.setDriverClassName(subset.getString("driverClassName")); mergeInfo.setUrl(subset.getString("url")); mergeInfo.setUsername(subset.getString("username")); mergeInfo.setPassword(subset.getString("password")); mergeInfo.setPhysicalSchema(subset.getString("physicalSchema"));
public static Optional<JCloudsConfiguration> getJCloudsConfiguration() { if (CONFIGURATION.containsKey(KEY_JCLOUDS_CONTEXT_PROVIDER)) { return Optional.of(new JCloudsConfiguration( CONFIGURATION.getString(KEY_JCLOUDS_CONTEXT_IDENTITY), CONFIGURATION.getString(KEY_JCLOUDS_CONTEXT_CREDENTIAL), CONFIGURATION.getString(KEY_JCLOUDS_BLOBSTORE_LOCATION), CONFIGURATION.getString(KEY_JCLOUDS_CONTAINERNAME), CONFIGURATION.getString(KEY_JCLOUDS_END_POINT))); } else { return Optional.empty(); } }
protected final String getStringOptionValue(String key) { String valueStr = _line.getOptionValue(key); if (valueStr != null) { _config.setProperty(key, valueStr); } return _config.getString(key); }
"Couldn't load configuration from " + configPath + ", classpath has problem"); props = props.subset("jmxterm.commands"); if (props == null) { throw new IOException("Expected configuration doesn't appear in " + configPath); for (String name : props.getStringArray("name")) { String type = props.getString(name + ".type"); Class<? extends Command> commandType; try { String[] aliases = props.getStringArray(name + ".alias"); if (!ArrayUtils.isEmpty(aliases)) { for (String alias : aliases) {
c.lock(LockMode.READ); try for (final Iterator<String> it = c.getKeys(); it.hasNext();) final Object value = encodeForCopy(c.getProperty(key)); addProperty(key, value); c.unlock(LockMode.READ);
@Override @SuppressWarnings("unchecked") public <T> T getProperty(String key, Class<T> valueClass) { T result = null; try { if (String.class == valueClass) { result = (T) getConfiguration().getString(key); } else if (List.class.isAssignableFrom(valueClass)) { result = (T) getConfiguration().getList(key); } else if (Properties.class.isAssignableFrom(valueClass)) { result = (T) getConfiguration().getProperties(key); } else { Object value = getProperty(key); if (value != null) { result = this.converterManager.convert(valueClass, getProperty(key)); } } } catch (org.apache.commons.configuration2.ex.ConversionException | org.xwiki.properties.converter.ConversionException e) { throw new org.xwiki.configuration.ConversionException( "Key [" + key + "] is not compatible with type [" + valueClass.getName() + "]", e); } return result; }
/** * Set System properties from a configuration object. * @param systemConfig The configuration containing the properties to be set. * @since 1.6 */ public static void setSystemProperties(final Configuration systemConfig) { final Iterator<String> iter = systemConfig.getKeys(); while (iter.hasNext()) { final String key = iter.next(); final String value = (String) systemConfig.getProperty(key); if (log.isDebugEnabled()) { log.debug("Setting system property " + key + " to " + value); } System.setProperty(key, value); } }
/** * Return the boolean property value associated with the given key, or * {@code defaultValue} if the key cannot be resolved. * * @param key the property name to resolve * @param defaultValue the default value to return if no value is found * @return The boolean property */ public boolean getBoolean(String key, boolean defaultValue) { return configuration.getBoolean(key, defaultValue); }
/** * Read property from underlying composite * * @param key key to use for mapping * * @return object associated with the given configuration key. */ @Override protected Object getPropertyInternal(final String key) { Configuration firstMatchingConfiguration = null; for (final Configuration config : configList) { if (config.containsKey(key)) { firstMatchingConfiguration = config; break; } } if (firstMatchingConfiguration != null) { return firstMatchingConfiguration.getProperty(key); } return null; }
/** * Stores the value for the specified key. The value is stored in the * underlying configuration. * * @param key the key (will be converted to a string) * @param value the value * @return the old value of this key or <b>null</b> if it is new * @see java.util.Map#put(java.lang.Object, java.lang.Object) */ @Override public Object put(final Object key, final Object value) { final String strKey = String.valueOf(key); final Object old = configuration.getProperty(strKey); configuration.setProperty(strKey, value); return old; }
/** * Return the int property value associated with the given key, or * {@code defaultValue} if the key cannot be resolved. * * @param key the property name to resolve * @param defaultValue the default value to return if no value is found * @return The int property */ public int getInt(String key, int defaultValue) { return configuration.getInt(key, defaultValue); }
protected final List<String> getStringListOptionValue(String key) { if (_line.hasOption(key)) { String[] optionValues = _line.getOptionValues(key); if (optionValues == null) { _config.setProperty(key, ImmutableList.of()); } else { _config.setProperty(key, ImmutableList.of(Arrays.asList(optionValues))); } } return _config.getList(String.class, key); }
@Override protected boolean containsKeyInternal(final String key) { return configuration.containsKey(key); }
@Override public Object get(final String name, final String key) { final Configuration subset = getConfiguration().subset(name); if (subset == null) { throw new IllegalArgumentException("Mapped property '" + name + "' does not exist."); } return subset.getProperty(key); }
@Override public boolean contains(final String name, final String key) { final Configuration subset = getConfiguration().subset(name); if (subset == null) { throw new IllegalArgumentException("Mapped property '" + name + "' does not exist."); } return subset.containsKey(key); }
public List<PageBreakLocations> getPageBreakLocations(String key) { List<PageBreakLocations> result = configuration.getList(PageBreakLocations.class, key); if(result == null) result = new ArrayList<PageBreakLocations>(); return result; }