Search in sources :

Example 1 with CaseInsensitiveHashMap

use of org.mule.runtime.core.api.util.CaseInsensitiveHashMap in project mule by mulesoft.

the class TemplateParser method parse.

protected String parse(Map<?, ?> props, String template, TemplateCallback callback) {
    if (styleIs(WIGGLY_MULE_TEMPLATE_STYLE)) {
        return parseMule(props, template, callback);
    }
    String result = template;
    Map<?, ?> newProps = props;
    if (props != null && !(props instanceof CaseInsensitiveHashMap)) {
        newProps = new CaseInsensitiveHashMap(props);
    }
    Matcher m = pattern.matcher(result);
    while (m.find()) {
        Object value = null;
        String match = m.group();
        String propname = match.substring(pre, match.length() - post);
        if (callback != null) {
            value = callback.match(propname);
            if (value == null) {
                value = NULL_AS_STRING;
            }
        } else if (newProps != null) {
            value = newProps.get(propname);
        }
        if (value == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Value " + propname + " not found in context");
            }
        } else {
            String matchRegex = Pattern.quote(match);
            String valueString = value.toString();
            valueString = replaceBackSlash(valueString);
            valueString = replaceDollarSign(valueString);
            result = result.replaceAll(matchRegex, valueString);
        }
    }
    return result;
}
Also used : Matcher(java.util.regex.Matcher) CaseInsensitiveHashMap(org.mule.runtime.core.api.util.CaseInsensitiveHashMap)

Example 2 with CaseInsensitiveHashMap

use of org.mule.runtime.core.api.util.CaseInsensitiveHashMap in project mule by mulesoft.

the class CopyOnWriteCaseInsensitiveMap method copy.

@SuppressWarnings("unchecked")
private void copy() {
    if (requiresCopy) {
        updateCore(new CaseInsensitiveHashMap(core));
        requiresCopy = false;
    }
}
Also used : CaseInsensitiveHashMap(org.mule.runtime.core.api.util.CaseInsensitiveHashMap)

Aggregations

CaseInsensitiveHashMap (org.mule.runtime.core.api.util.CaseInsensitiveHashMap)2 Matcher (java.util.regex.Matcher)1