Example usage for org.apache.commons.lang.text StrSubstitutor replace

List of usage examples for org.apache.commons.lang.text StrSubstitutor replace

Introduction

In this page you can find the example usage for org.apache.commons.lang.text StrSubstitutor replace.

Prototype

public String replace(Object source) 

Source Link

Document

Replaces all the occurrences of variables in the given source object with their matching values from the resolver.

Usage

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.agnie.common.email.MessageTemplate.java

/**
 * Generate the message from template by replacing variable values inside template.
 * //w  w w.  ja va2 s  . c o m
 * @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:io.apiman.gateway.engine.policies.auth.LDAPIdentityValidator.java

/**
 * Formats the configured DN by replacing any properties it finds.
 * @param dnPattern/*from w w w  .j av a  2 s . c  o m*/
 * @param username
 * @param request
 */
private String formatDn(String dnPattern, String username, ServiceRequest request) {
    Map<String, String> valuesMap = new HashMap<String, String>();
    valuesMap.putAll(request.getHeaders());
    valuesMap.put("username", username); //$NON-NLS-1$
    StrSubstitutor sub = new StrSubstitutor(valuesMap);
    return sub.replace(dnPattern);
}

From source file:com.datatorrent.demos.ads.HdfsHashMapOutputOperator.java

@Override
public Path nextFilePath() {
    Map<String, String> params = new HashMap<String, String>();
    params.put(FNAME_SUB_PART_INDEX, String.valueOf(index));
    params.put(FNAME_SUB_OPERATOR_ID, Integer.toString(operatorId));
    StrSubstitutor sub = new StrSubstitutor(params, "%(", ")");
    index++;/*from ww  w . ja  v a  2  s  . c  om*/
    return new Path(sub.replace(getFilePathPattern().toString()));
}

From source file:com.datatorrent.benchmark.HdfsByteOutputOperator.java

@Override
public Path nextFilePath() {
    Map<String, String> params = new HashMap<String, String>();
    params.put(FNAME_SUB_PART_INDEX, String.valueOf(index));
    params.put(FNAME_SUB_CONTEXT_ID, Integer.toString(contextId));
    StrSubstitutor sub = new StrSubstitutor(params, "%(", ")");
    index++;//from  ww w  .  ja  v  a  2s . c o  m
    return new Path(sub.replace(getFilePathPattern().toString()));
}

From source file:com.datatorrent.demos.frauddetect.operator.HdfsStringOutputOperator.java

@Override
public Path nextFilePath() {
    Map<String, String> params = new HashMap<String, String>();
    params.put(FNAME_SUB_PART_INDEX, String.valueOf(index));
    params.put(FNAME_SUB_CONTEXT_ID, contextId);
    StrSubstitutor sub = new StrSubstitutor(params, "%(", ")");
    index++;//from  w  w  w .  j  a va2  s . co  m
    return new Path(sub.replace(getFilePathPattern().toString()));
}

From source file:com.prowidesoftware.swift.model.IbanValidationResult.java

/**
 * Validation problem description including expected and found content when necessary
 *///from  w  w w  .jav a2  s. com
public String message() {
    final StrSubstitutor sub = new StrSubstitutor(this.vars);
    return sub.replace(this.message);
}

From source file:net.firejack.platform.core.model.registry.DatabaseName.java

public String getDbUrlConnection(DatabaseProtocol protocol, String domain, String port) {
    Map<String, String> valuesMap = new HashMap<String, String>();
    valuesMap.put("protocol", protocol.name().toLowerCase());
    valuesMap.put("domain", domain);
    valuesMap.put("port", port);
    StrSubstitutor sub = new StrSubstitutor(valuesMap);
    return sub.replace(dbUrlTemplate);
}

From source file:net.firejack.platform.core.model.registry.DatabaseName.java

public String getDbSchemaUrlConnection(DatabaseProtocol protocol, String domain, String port, String sid,
        String schema) {//from  ww w .j a va  2 s . co  m
    Map<String, String> valuesMap = new HashMap<String, String>();
    valuesMap.put("protocol", protocol.name().toLowerCase());
    valuesMap.put("domain", domain);
    valuesMap.put("port", port);
    valuesMap.put("sid", sid);
    valuesMap.put("schema", schema);
    StrSubstitutor sub = new StrSubstitutor(valuesMap);
    return sub.replace(dbSchemaUrlTemplate);
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnReplicationREADMEFileWriter.java

public String generatePt1Block() {
    StrSubstitutor sub = new StrSubstitutor(valueMap);
    return sub.replace(pt1Template);
}