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

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

Introduction

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

Prototype

public static String replace(String text, String searchString, String replacement) 

Source Link

Document

Replaces all occurrences of a String within another String.

Usage

From source file:com.ms.app.web.validation.validator.AbstarctValidator.java

String paser(String errorMessage, String displayName) {
    int beginIndex = errorMessage.indexOf("${");
    int endIndex = errorMessage.indexOf("}");
    if (beginIndex != -1 && endIndex != -1) {
        String name = errorMessage.substring(beginIndex + 2, endIndex);
        if (name.equalsIgnoreCase("displayName")) {
            errorMessage = StringUtils.replace(errorMessage, "${" + name + "}", displayName);
        } else {//  w ww.  j  av  a2s  .co m
            try {
                Field f = this.getClass().getDeclaredField(name);
                f.setAccessible(true);
                Object value = f.get(this);
                errorMessage = StringUtils.replace(errorMessage, "${" + name + "}", value.toString());
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                return errorMessage;
            }
        }
        return paser(errorMessage, displayName);
    } else {
        return errorMessage;
    }
}

From source file:jetbrick.tools.chm.reader.KeyManager.java

public void add(String name, String url) {
    String text;/*w ww. j  av  a 2s. c  o  m*/
    if (name.indexOf('(') >= 0) {
        text = StringUtils.replace(name, key + "(", "<b>" + key + "</b>(");
    } else {
        text = StringUtils.replace(name, "." + key, ".<b>" + key + "</b>");
    }
    text = "<a href='" + url + "'>" + text + "</a>";
    pairs.add(text);
}

From source file:com.voa.weixin.task.DownloadFileTask.java

@Override
public void generateUrl() {
    this.url = StringUtils.replace(url, "ACCESS_TOKEN", Carp.token);
    this.url = StringUtils.replace(url, "MEDIA_ID", this.mediaId);
}

From source file:eionet.cr.staging.util.ImportExportLogUtil.java

/**
 * Formats the given import log line for display in the browser.
 *
 * @param line The log line.//from w  w  w. ja  v  a  2s . c o  m
 * @return The log line formatted.
 */
public static String formatLogLineForDisplay(String line) {

    String start = Level.WARN + ":";
    if (line.startsWith(start)) {
        StringUtils.replaceOnce(line, start, "<span style=\"color:#F5B800\">" + start + "</span>");
    }
    start = Level.ERROR + ":";
    if (line.startsWith(start)) {
        StringUtils.replaceOnce(line, start, "<span style=\"color:#FF0000\">" + start + "</span>");
    }

    return StringUtils.replace(line, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
}

From source file:co.marcin.novaguilds.PermissionEnumTest.java

@Test
public void testPermissionEnum() throws Exception {
    boolean passed = true;
    for (Command command : Command.values()) {
        Permission permission = command.getPermission();

        if (permission == null) {
            if (passed) {
                System.out.println("Missing enums:");
            }//from   w  w  w.j  a va  2  s .co m

            System.out.println(StringUtils.replace(command.getPermission().getPath().toUpperCase(), ".", "_"));
            passed = false;
        }
    }

    if (!passed) {
        throw new Exception("Found missing Permission enums!");
    }
}

From source file:com.googlecode.jtiger.modules.ecside.util.ExportViewUtils.java

public static String parseCSV(String content) {

    boolean needPrefix = true;
    boolean needTrim = true;
    boolean needQuote = false;

    if (content == null) {
        return needPrefix ? String.valueOf(TAB) : "";
    }/*from  ww w .j a  va2  s  .c  o  m*/
    content = needTrim ? content.trim() : content;

    if (content.indexOf("\r") != -1 || content.indexOf("\n") != -1 || content.indexOf(",") != -1) {
        needQuote = true;
    }

    content = StringUtils.replace(content, SPACE_C1, "" + SPACE);
    content = StringUtils.replace(content, SPACE_C2, "" + SPACE);
    content = StringUtils.replace(content, "" + QUOTE, "" + QUOTE + QUOTE);
    content = StringUtils.replace(content, "" + CR + LF, "" + CR);
    content = StringUtils.replace(content, "" + LF, "" + CR);

    content = needPrefix ? TAB + content : content;
    if (needQuote) {
        content = QUOTE + content + QUOTE;
    }
    return content;
}

From source file:com.sunrise.sup.core.common.util.URLUtil.java

/**
 * Url/*from  w  w  w. jav  a 2  s . co  m*/
 * 
 * @param url
 * @param name
 * @param value
 * @return
 */
public static String concatUrl(String url, String name, String value) {
    String params = name + "=" + value;
    params = StringUtils.replace(params, "#", "%23");
    if (url.indexOf("?") >= 0) {
        url += "&" + params;
    } else {
        url += "?" + params;
    }
    return url;
}

From source file:net.jforum.formatters.SmiliesFormatter.java

/**
 * @see net.jforum.formatters.Formatter#format(java.lang.String, net.jforum.formatters.PostOptions)
 *///from w ww  .j ava  2 s. co  m
@Override
public String format(String text, PostOptions postOptions) {
    SmilieRepository repository = container.instanceFor(SmilieRepository.class);

    if (postOptions.isSmiliesEnabled()) {
        for (Smilie smilie : repository.getAllSmilies()) {
            text = StringUtils.replace(text, smilie.getCode(),
                    this.imageTag(smilie.getDiskName(), postOptions.contextPath()));
        }
    }

    return text;
}

From source file:com.ultrapower.eoms.common.plugin.ecside.util.ExportViewUtils.java

 public static String parseCSV(String content) {

   boolean needPrefix= true;
   boolean needTrim = true;
   boolean needQuote = false;
      /*from   ww w  .j ava  2 s.  c  om*/
   if (content == null) {
      return needPrefix?String.valueOf(TAB):"";
   }
   content=needTrim?content.trim():content;
      
   if (content.indexOf("\r") != -1 || content.indexOf("\n") != -1
         || content.indexOf(",") != -1) {
      needQuote = true;
   }
      
     content = StringUtils.replace(content, SPACE_C1, ""+SPACE);
     content = StringUtils.replace(content, SPACE_C2, ""+SPACE);
   content = StringUtils.replace(content, "" + QUOTE, ""+ QUOTE + QUOTE);
   content = StringUtils.replace(content, "" + CR + LF, ""   + CR);
   content = StringUtils.replace(content, "" + LF, "" + CR);
      
   content=needPrefix?TAB+content:content;
   if (needQuote) {
      content = QUOTE + content + QUOTE;
   }
   return content;
}

From source file:cn.cuizuoli.gotour.utils.HtmlHelper.java

/**
 * toTable/* w  w w.  j av a2  s.c o  m*/
 * @param text
 * @return
 */
public static String toTable(String text) {
    String[] lines = StringUtils.split(text, "\r\n");
    StringBuffer tableBuffer = new StringBuffer();
    for (String line : lines) {
        Matcher tileMatcher = TITLE_PATTERN.matcher(line);
        if (tileMatcher.matches()) {
            String h4 = new StringBuffer().append("<h4>").append(tileMatcher.group(1)).append("</h4>")
                    .append("\n").append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">")
                    .append("\n").toString();
            tableBuffer.append(h4);
        }
        Matcher tableMatcher = TABLE_PATTERN.matcher(line);
        if (tableMatcher.matches()) {
            String tr = new StringBuffer().append("<tr>").append("\n").append("<th>")
                    .append(tableMatcher.group(1)).append("</th>").append("\n").append("<td>")
                    .append(tableMatcher.group(2)).append("</td>").append("\n").append("</tr>").append("\n")
                    .toString();
            tableBuffer.append(tr);
        }
    }
    tableBuffer.append("</table>\n");
    String table = tableBuffer.toString();
    table = StringUtils.replace(table, "<h4>", "</table>\n<h4>");
    table = StringUtils.replaceOnce(table, "</table>\n<h4>", "<h4>");
    if (!StringUtils.contains(table, "<table")) {
        table = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n" + table;
    }
    return table;
}