Example usage for org.apache.commons.lang StringUtils replaceEach

List of usage examples for org.apache.commons.lang StringUtils replaceEach

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils replaceEach.

Prototype

public static String replaceEach(String text, String[] searchList, String[] replacementList) 

Source Link

Document

Replaces all occurrences of Strings within another String.

Usage

From source file:dk.dma.msiproxy.common.util.TextUtils.java

/**
 * Converts the text from plain text to html
 * @param text the text/*from w  w  w .ja  v  a 2s.  co  m*/
 * @return the html version
 */
public static String txt2html(String text) {
    text = StringUtils.replaceEach(text, new String[] { "&", "\"", "<", ">", "\n", "\t" },
            new String[] { "&amp;", "&quot;", "&lt;", "&gt;", "<br>", "&nbsp;&nbsp;&nbsp;" });
    return text;
}

From source file:com.careerly.utils.TextUtils.java

/**
 * ?  //  w w w. ja  v a2s .co m
 *
 * @param text ??
 * @return ??
 */
public static String convertTraditionalChineseNumber2ArabicNumber(String text) {
    if (StringUtils.isBlank(text)) {
        return StringUtils.EMPTY;
    }

    return StringUtils.replaceEach(text,
            new String[] { "", "", "", "??", "", "?", "", "", "?", "" },
            new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" });
}

From source file:com.reizes.shiva.etl.core.transformer.MapToMySqlDumpTransformer.java

@SuppressWarnings("unchecked")
@Override/*w  w w.j av  a2  s . c om*/
public Object doProcess(Object input) throws Exception {
    Map<String, Object> map = (Map<String, Object>) input;
    String[] output = new String[columns.length];

    for (int i = 0; i < columns.length; i++) {
        Object data = map.get(columns[i]);
        output[i] = data != null ? ("\"" + StringUtils.replaceEach(data.toString().trim(),
                new String[] { "\"", "\\", "\t" }, new String[] { "\\\"", "\\\\", "\\t" }) + "\"") : "NULL";
    }

    String str = StringUtil.join(output, '\t') + '\n';
    return str;
}

From source file:com.cognifide.slice.mapper.helper.Utf8StringEscapeUtils.java

/**
 * Escapes HTML encoded in UTF-8 range, as opposed to {@link StringEscapeUtils#escapeHtml(String)} that
 * escapes everything outside ASCII range. This method is more like
 * {@link StringEscapeUtils#escapeXml(String)}, but the <tt>&apos;</tt> entity is not used because it's
 * not a legal HTML entity./*from  ww  w.j av a  2 s . c o  m*/
 * 
 * @param input the <tt>String</tt> to escape, may be null
 * @return a new escaped <tt>String</tt>, <tt>null</tt> if null string input.
 */
public static String escapeUtf8Html(String input) {
    if (null == input) {
        return null;
    }
    return StringUtils.replaceEach(input, SEARCH_LIST, REPLACEMENT_LIST);
}

From source file:com.careerly.utils.TextUtils.java

/**
 *   /*from  ww w.  ja  va2  s . com*/
 *
 * @param number ??
 * @return ??
 */
public static String convertSimplifiedArabicNumber2ChineseNumber(int number) {
    return StringUtils.replaceEach(number + "",
            new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" },
            new String[] { "", "", "", "", "", "", "", "", "", "?" });
}

From source file:com.reizes.shiva.etl.core.transformer.ModelToMySqlDumpTransformer.java

@Override
public Object doProcess(Object input) throws Exception {
    String[] output = new String[columns.length];

    for (int i = 0; i < columns.length; i++) {
        String name = StringUtil.camelize(columns[i]);

        if (PropertyUtils.isReadable(input, name)) {
            Object data = PropertyUtils.getSimpleProperty(input, name);

            if (data != null) {
                if (data instanceof Date) {
                    output[i] = String.format("%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", data);
                } else if (data instanceof Boolean) {
                    output[i] = (Boolean) data ? "1" : "0";
                } else {
                    output[i] = "\"" + StringUtils.replaceEach(data.toString().trim(),
                            new String[] { "\"", "\\", "\t" }, new String[] { "\\\"", "\\\\", "\\t" }) + "\"";
                }/* w ww.  j  av a2 s  . c om*/
            } else {
                output[i] = "NULL";
            }
        }
    }

    String str = StringUtil.join(output, '\t') + '\n';
    return str;
}

From source file:de.tor.tribes.util.bb.TagListFormatter.java

@Override
public String formatElements(List<Tag> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;//  w  w  w. j a  v a  2s.  co m
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedStart);
    for (Tag t : pElements) {
        String[] replacements = t.getReplacements(pExtended);
        String itemLine = StringUtils.replaceEach(listItemTemplate, t.getBBVariables(), replacements);
        itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT },
                new String[] { f.format(cnt), f.format(pElements.size()) });
        b.append(itemLine).append("\n");
        cnt++;
    }
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedEnd);
    return b.toString();
}

From source file:de.tor.tribes.util.bb.AllyReportStatsFormatter.java

@Override
public String formatElements(List<AllyStatResult> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;/*from w  w  w . j av  a  2  s. co  m*/
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedStart);
    for (AllyStatResult n : pElements) {
        String[] replacements = n.getReplacements(pExtended);
        String itemLine = StringUtils.replaceEach(listItemTemplate, n.getBBVariables(), replacements);
        itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT },
                new String[] { f.format(cnt), f.format(pElements.size()) });
        b.append(itemLine).append("\n");
        cnt++;
    }
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedEnd);
    return b.toString();
}

From source file:de.tor.tribes.util.bb.TribeReportStatsFormatter.java

@Override
public String formatElements(List<TribeStatResult> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;//  w w  w .j  a va  2 s . c o  m
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedStart);
    for (TribeStatResult n : pElements) {
        String[] replacements = n.getReplacements(pExtended);
        String itemLine = StringUtils.replaceEach(listItemTemplate, n.getBBVariables(), replacements);
        itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT },
                new String[] { f.format(cnt), f.format(pElements.size()) });
        b.append(itemLine).append("\n");
        cnt++;
    }
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedEnd);
    return b.toString();
}

From source file:de.tor.tribes.util.bb.MarkerListFormatter.java

@Override
public String formatElements(List<Marker> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;/* w ww .ja  va2s.  c  o  m*/
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedStart);
    for (Marker m : pElements) {
        String[] replacements = m.getReplacements(pExtended);
        String itemLine = StringUtils.replaceEach(listItemTemplate, m.getBBVariables(), replacements);
        itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT },
                new String[] { f.format(cnt), f.format(pElements.size()) });
        b.append(itemLine).append("\n");
        cnt++;
    }
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT },
            new String[] { f.format(pElements.size()) });
    b.append(replacedEnd);
    return b.toString();
}