Example usage for org.apache.commons.lang3.text StrSubstitutor StrSubstitutor

List of usage examples for org.apache.commons.lang3.text StrSubstitutor StrSubstitutor

Introduction

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

Prototype

public StrSubstitutor(final StrLookup<?> variableResolver, final StrMatcher prefixMatcher,
        final StrMatcher suffixMatcher, final char escape) 

Source Link

Document

Creates a new instance and initializes it.

Usage

From source file:com.thruzero.common.core.strategy.StrMatcherSubstitutionStrategy.java

public <V> StrMatcherSubstitutionStrategy(final Map<String, V> valueMap, final String prefix,
        final String suffix, final char escape) {
    this.strSubstitutor = new StrSubstitutor(valueMap, prefix, suffix, escape);
}

From source file:com.astamuse.asta4d.util.i18n.formatter.ApacheStrSubstitutorFormatter.java

@Override
public String format(String pattern, Map<String, Object> paramMap) {
    StrSubstitutor sub = new StrSubstitutor(paramMap, prefix, suffix, escape);
    return sub.replace(pattern);
}

From source file:edu.isi.pegasus.common.util.VariableExpander.java

/**
 * Overloaded constructor //  w ww.jav  a  2s  .c o  m
 * 
 * @param caseSensitive  boolean indicating whether you want lookups to be
 *                       case sensitive or not.
 */
public VariableExpander(boolean caseSensitive) {
    mValuesMap = new HashMap(System.getenv());
    mExpander = new StrSubstitutor(mValuesMap, "${", "}", '\\');
    mExpander.setVariableResolver(new CaseSensitiveStrLookup(this.mValuesMap, caseSensitive));

}

From source file:com.thruzero.common.core.strategy.StrMatcherSubstitutionStrategy.java

/**
 * @param substitutionSpecs the key/value pairs used for search and replace.
 */// w w  w. ja  va2s  .  c  o  m
public StrMatcherSubstitutionStrategy(final String prefix, final String suffix, final char escape,
        final KeyValuePair... substitutionSpecs) {
    Map<String, Object> valueMap = new HashMap<String, Object>();

    for (KeyValuePair keyValuePair : substitutionSpecs) {
        valueMap.put(keyValuePair.getKey(), keyValuePair.getValue());
    }

    // no prefix or suffix is used with this version
    this.strSubstitutor = new StrSubstitutor(valueMap, prefix, suffix, escape);
}

From source file:ca.uhn.fhir.rest.server.interceptor.BaseValidatingInterceptor.java

private void addResponseIssueHeader(RequestDetails theRequestDetails, SingleValidationMessage theNext) {
    // Perform any string substitutions from the message format
    StrLookup<?> lookup = new MyLookup(theNext);
    StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');

    // Log the header
    String headerValue = subs.replace(myResponseIssueHeaderValue);
    ourLog.trace("Adding header to response: {}", headerValue);

    theRequestDetails.getResponse().addHeader(myResponseIssueHeaderName, headerValue);
}

From source file:ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor.java

@Override
public boolean handleException(RequestDetails theRequestDetails, BaseServerResponseException theException,
        HttpServletRequest theServletRequest, HttpServletResponse theServletResponse)
        throws ServletException, IOException {
    if (myLogExceptions) {
        // Perform any string substitutions from the message format
        StrLookup<?> lookup = new MyLookup(theServletRequest, theException, theRequestDetails);
        StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');

        // Actuall log the line
        String line = subs.replace(myErrorMessageFormat);
        myLogger.info(line);/*  www. ja v  a2 s .  co  m*/

    }
    return true;
}

From source file:moe.encode.airblock.commands.localization.TranslationManager.java

/**
 * Translates the message with the given values.
 * @param locale    The language that should be used.
 * @param msg       The message-key that will be used for translation.
 * @param values    The values that should be used for translation.
 * @return The translated message./*from  w ww . ja  v  a  2s .c o  m*/
 */
public String translate(@NonNull Locale locale, @NonNull String msg, @Nullable Object... values) {
    // Create the value source that should be used for resolving the values.
    // Also create the string-substitutor that should be used for translating strings.
    MultiValueSource mvs = new MultiValueSource();
    mvs.addSource(new ArrayValueSource(values)); // The values given by the executor.
    mvs.addSource(this); // The values added to this manager.
    mvs.addSource(new MapValueSource(System.getProperties())); // The system properties.
    StrSubstitutor ss = new StrSubstitutor(new ValueSourceLookup(this, mvs, locale), "{", "}", '\\');

    // Replace the values.
    return ss.replace(this.getRawTranslation(locale, msg));
}

From source file:ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor.java

@Override
public void processingCompletedNormally(ServletRequestDetails theRequestDetails) {
    // Perform any string substitutions from the message format
    StrLookup<?> lookup = new MyLookup(theRequestDetails.getServletRequest(), theRequestDetails);
    StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');

    // Actuall log the line
    String line = subs.replace(myMessageFormat);
    myLogger.info(line);/*from  w  w w. ja  v  a 2 s  . c om*/
}

From source file:co.jirm.orm.writer.SqlWriterStrategy.java

public String replacePropertyPaths(final SqlObjectDefinition<?> definition, final String sql) {
    StrLookup<String> lookup = new StrLookup<String>() {
        @Override/*  www  . j av a2s  .c  om*/
        public String lookup(String key) {
            Optional<String> p = parameterPathToSql(definition, key);
            check.state(p.isPresent(), "Invalid object path: {}", key);
            return p.get();
        }
    };
    StrSubstitutor s = new StrSubstitutor(lookup, "{{", "}}", '$');
    String result = s.replace(sql);
    return result;
}

From source file:co.jirm.orm.writer.SqlWriterStrategy.java

public String replaceProperties(final SqlObjectDefinition<?> definition, final String sql) {
    StrLookup<String> lookup = new StrLookup<String>() {
        @Override// www  .jav a2 s .  co  m
        public String lookup(String key) {
            Optional<String> sqlName = definition.parameterNameToSql(key);
            check.state(sqlName.isPresent(), "Property: {} not found in object.", key);
            return sqlName.get();
        }
    };
    StrSubstitutor s = new StrSubstitutor(lookup, "{{", "}}", '$');
    String result = s.replace(sql);
    return result;
}