List of usage examples for org.apache.commons.lang.text StrSubstitutor StrSubstitutor
public StrSubstitutor(StrLookup variableResolver)
From source file:com.enonic.cms.framework.util.PropertiesUtil.java
/** * Interpolate properties names like ${..}. *//*from w ww . j av a 2 s. co m*/ public static Properties interpolate(final Properties props) { Properties target = new Properties(); Properties source = new Properties(); source.putAll(System.getProperties()); source.putAll(props); StrLookup lookup = StrLookup.mapLookup(source); StrSubstitutor substitutor = new StrSubstitutor(lookup); for (Object key : props.keySet()) { String value = props.getProperty((String) key); try { value = substitutor.replace(value); } catch (IllegalStateException e) { // Do nothing } target.put(key, value); } return target; }
From source file:com.redhat.utils.PluginUtils.java
public static String getSubstitutedValue(String id, EnvVars env) { String text = id.replaceAll("\\$([a-zA-Z_]+[a-zA-Z0-9_]*)", "\\${$1}"); //replace $VAR instances with ${VAR}. StrSubstitutor sub1 = new StrSubstitutor(env); return sub1.replace(text).trim(); }
From source file:com.infullmobile.jenkins.plugin.restrictedregister.mail.impl.LocalVariablesDecorator.java
@Override public String getTransformedMessage(FormatterData formatterData, String input) { final LocalVariables localVariables = formatterData.getDataForType(LocalVariables.class); if (localVariables != null) { final Map<String, String> vars = localVariables.getVariables(); final StrSubstitutor strSubstitutor = new StrSubstitutor(vars); return strSubstitutor.replace(input); } else {/*from w w w . j av a 2 s.c o m*/ return input; } }
From source file:com.infullmobile.jenkins.plugin.restrictedregister.mail.impl.EnvVariablesDecorator.java
@Override public String getTransformedMessage(FormatterData formatterData, String input) { final IJenkinsDescriptor jenkinsDescriptor = formatterData.getDataForType(IJenkinsDescriptor.class); if (jenkinsDescriptor != null) { final Map<String, String> vars = jenkinsDescriptor.getMasterEnvironmentVariables(); final StrSubstitutor strSubstitutor = new StrSubstitutor(vars); return strSubstitutor.replace(input); } else {//from www.ja va 2 s . co m return input; } }
From source file:net.sf.morph2.integration.commons.lang.LanguageStrLookupTestCase.java
public void testMe() { HashMap map = new HashMap(); map.put("string", "\"string\""); map.put("one", new Integer(1)); map.put("array", new String[] { "foo", "bar", "baz" }); StrSubstitutor ss = new StrSubstitutor(new LanguageStrLookup(map)); assertEquals("\"string\"", ss.replace("${string}")); assertEquals("1", ss.replace("${one}")); assertEquals("foo", ss.replace("${array[0]}")); assertEquals("bar", ss.replace("${array[1]}")); assertEquals("baz", ss.replace("${array[2]}")); }
From source file:com.appdynamics.monitors.muleesb.JMXUtil.java
private static String buildUrl(String host, int port) { Map<String, String> valueMap = new HashMap<String, String>(); valueMap.put("HOST", host); valueMap.put("PORT", String.valueOf(port)); StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap); return strSubstitutor.replace(JMX_URL); }
From source file:com.agnie.common.email.MessageTemplate.java
/** * Generate the message from template by replacing variable values inside template. * /*from ww w. ja va2s .com*/ * @param valuesMap * @return * @throws IOException */ public String getMessage(Map<String, String> valuesMap) throws IOException { if (messageTemplate == null) { init(); } StrSubstitutor sub = new StrSubstitutor(valuesMap); return sub.replace(messageTemplate); }
From source file:com.dotosoft.dot4command.commands.CallTemplateCommand.java
private void modifyKeyMap(Command newTemp) { ModifierHandler modifier = new ModifierHandler() { StrSubstitutor sub;/* ww w. j av a 2s . c o m*/ @Override public void modifier(Object... params) { Command valueCommand = (Command) params[0]; Map valuesMap = (Map) params[1]; sub = new StrSubstitutor(valuesMap); modifyField(valueCommand); } private void modifyField(Command valueCommand) { List<Field> allFields = listAllFields(valueCommand); for (Field field : allFields) { try { Object value = getProperty(valueCommand, field.getName()); if (value instanceof String) { setProperty(valueCommand, field.getName(), sub.replace(value)); } } catch (Exception ex) { } } if (valueCommand instanceof ChainBase) { ChainBase chainBase = (ChainBase) valueCommand; List<Command<K, V, C>> listOfCommands = chainBase.getCommands(); for (Command comm : listOfCommands) { modifyField(comm); } } } private List<Field> listAllFields(Object objReflection) { List<Field> fieldList = new ArrayList<Field>(); Class tmpClass = objReflection.getClass(); while (tmpClass != null) { fieldList.addAll(Arrays.asList(tmpClass.getDeclaredFields())); tmpClass = tmpClass.getSuperclass(); } return fieldList; } }; newTemp.modify(modifier, newTemp, keyMap); }
From source file:com.googlecode.xtecuannet.framework.catalina.manager.tomcat.constants.Constants.java
public static String getResolvedValue(String elKey, Class toResolve, PropertiesConfiguration cfg) { String out = null;/*from w w w .j a v a2s . co m*/ String value = cfg.getString(elKey); if (value.contains("${")) { Map map = generateMapFromConfig(toResolve); StrSubstitutor subs = new StrSubstitutor(map); subs.setEnableSubstitutionInVariables(true); out = subs.replace(value); if (out != null && out.contains("${")) { out = evaluateTransformationFunction(out); } } else { out = value; } return out; }
From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnReplicationREADMEFileWriter.java
public String generatePt1Block() { StrSubstitutor sub = new StrSubstitutor(valueMap); return sub.replace(pt1Template); }