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 static String replace(Object source, Map valueMap) 

Source Link

Document

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

Usage

From source file:org.xmlactions.action.Action.java

private void processMarkers(String pageContent, List<ReplacementMarker> markers, IExecContext execContext)
        throws NestedActionException {

    for (ReplacementMarker marker : markers) {
        BaseAction action = marker.getAction();
        try {/*from  w  ww . ja  v a  2s. c o  m*/
            action.processAction(pageContent, action, execContext);
        } catch (Exception ex) {
            log.error(ex.getMessage() + "\n" + pageContent, ex);
            throw new NestedActionException(
                    "Error Processing page [" + StrSubstitutor.replace(getPageName(), execContext) + "]", ex);
        }
    }
}

From source file:org.xmlactions.action.actions.ActionUtils.java

public static String evaluateCalculation(IExecContext execContext, String exp) throws BSFException {
    String script = null;/*from  www  . j av a 2  s .c om*/
    script = convertExpressionAmps(StrSubstitutor.replace(exp, execContext));
    // log.debug("expression:" + exp + " script:" + script);
    Object result = Scripting.getInstance().evaluate(script);
    return ConvertUtils.convert(result, Integer.class).toString();
}

From source file:org.xmlactions.action.config.ExecContext.java

public String replace(String content) {
    return StrSubstitutor.replace(content, this);
}

From source file:org.xmlactions.common.text.ReplaceMarkers.java

/**
 * This will firstly replace any markers within the text with values found in the map and secondly
 * remove any unset markers within the text. An unset marker is ${...}. This usually means that the
 * StrSubstutior was not able to find a value for the marker and so left it unchanged.
 * /*from  ww  w  . j  a va 2  s  . c o m*/
 * Any unset markers will be replaced with "null"
 * 
 * @param text
 * @return the text updated with the replacement markers
 */
public static String replace(String text, Map<String, Object> map) {
    text = StrSubstitutor.replace(text, map);
    text = removeUnusedMarkers(text, "null");
    return text;
}

From source file:org.xmlactions.common.text.ReplaceMarkers.java

/**
 * This will firstly replace any markers within the text with values found in the map and secondly
 * remove any unset markers within the text. An unset marker is ${...}. This usually means that the
 * StrSubstutior was not able to find a value for the marker and so left it unchanged.
 * //w w  w . j  a  va 2 s .  c o m
 * Any unset markers will be replaced with the missingReplaceValue.
 * @param text
 * @return the text updated with the replacement markers
 */
public static String replace(String text, Map<String, Object> map, Object missingReplacementValue) {
    text = StrSubstitutor.replace(text, map);
    text = removeUnusedMarkers(text, missingReplacementValue);
    return text;
}

From source file:org.xmlactions.common.text.ReplaceMarkers.java

/**
 * This will remove unset markers within the text. An unset marker is ${...}. This usually
 * means that the StrSubstutior was not able to find a value for the marker and so left it
 * unchanged.//  w  w  w .  j  ava 2 s.  co  m
 * 
 * This method will simply replace any ${...} that it finds in the text with a null.
 * @param text
 * @return the text with the replacement markers removed.
 */
public static String removeUnusedMarkers(String text, Object missingReplacementValue) {
    String[] markers = findMarkers(text);
    if (markers.length > 0) {
        Map<String, Object> map = new HashMap<String, Object>();
        for (String marker : markers) {
            map.put(marker, missingReplacementValue);
        }
        text = StrSubstitutor.replace(text, map);
    }
    return text;
}

From source file:org.xmlactions.pager.actions.EchoAction.java

public String execute(IExecContext execContext) {

    return StrSubstitutor.replace(getContent(), execContext);
}

From source file:org.xmlactions.pager.actions.form.FileViewerAction.java

private String loadPage() throws IOException {
    String page = null;//w  w w  .j  a  va 2s. c  om
    if (getRef() != null) {
        page = execContext.getString(getRef());
    } else {
        if (path == null) {
            path = (String) execContext.get(ActionConst.WEB_REAL_PATH_BEAN_REF);
        }
        String fileName = StrSubstitutor.replace(getFile_name(), execContext);
        if (path == null) {
            path = (String) execContext.get(ActionConst.WEB_REAL_PATH_BEAN_REF);
        }
        if (path != null) {
            path = StrSubstitutor.replace(getPath(), execContext);
        }
        try {
            page = Action.loadPage(path, fileName);
        } catch (IllegalArgumentException ex) {
            // try a load a page from a url
            InputStream is = null;
            try {
                URL url = new URL(fileName);
                if (url != null) {
                    is = url.openStream();
                    // emm we may have an inputsteam
                    char[] content = IOUtils.toCharArray(is);
                    page = new String(content);
                } else {
                    throw ex;
                }
            } catch (Exception ignoreme) {
                throw ex;
            }
        }
    }
    return page;
}

From source file:org.xmlactions.pager.actions.form.FrameAction.java

public Object getReplacementData(IExecContext execContext, Object innerContent) {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put(getKey(), "" + innerContent);
    return StrSubstitutor.replace(getFrameContent(), map);
}

From source file:org.xmlactions.pager.actions.highlighter.HighlighterAction.java

private String loadPage() throws IOException {
    String page = null;/*from   w  w w . ja  v a2 s. c o m*/
    if (getRef() != null) {
        page = execContext.getString(getRef());
    } else {
        if (path == null) {
            path = (String) execContext.get(ActionConst.WEB_REAL_PATH_BEAN_REF);
        }
        String fileName = StrSubstitutor.replace(getFile_name(), execContext);
        if (path == null) {
            path = (String) execContext.get(ActionConst.WEB_REAL_PATH_BEAN_REF);
        }
        if (path != null) {
            path = StrSubstitutor.replace(getPath(), execContext);
        }
        try {
            page = Action.loadPage(path, fileName);
        } catch (IllegalArgumentException ex) {
            // try a load a page from a url
            InputStream is = null;
            try {
                URL url = new URL(fileName);
                if (url == null) {
                    throw ex;
                }
                is = url.openStream();
                // emm we may have an inputsteam
                char[] content = IOUtils.toCharArray(is);
                page = new String(content);
            } catch (Exception ignoreme) {
                throw ex;
            }
        }
    }
    return page;
}