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:gov.nih.nci.caIMAGE.util.SafeHTMLUtil.java

public static String cleanKeyword(String s) {
    String clean = Translate.decode(s).replace("<", "").replace(">", "");
    clean = StringUtils.replace(clean, "script", "");
    clean = StringUtils.replace(clean, "%", "");
    clean = StringUtils.replace(clean, "#", "");
    clean = StringUtils.replace(clean, ";", "");
    clean = StringUtils.replace(clean, "\"", "");
    clean = StringUtils.replace(clean, "$", "");
    clean = StringUtils.replace(clean, "&", "");
    clean = StringUtils.replace(clean, "(", "");
    clean = StringUtils.replace(clean, ")", "");
    clean = StringUtils.replace(clean, "/", "");
    clean = StringUtils.replace(clean, "\\", "");
    if (clean.length() == 0) {
        clean = "empty";
    }//from   w  ww .j  a va2s  . c  o  m
    return clean;
}

From source file:adalid.core.programmers.AbstractProgrammer.java

public static String format(String pattern, Object... arguments) {
    if (StringUtils.isBlank(pattern)) {
        return pattern;
    }//w w w .  ja v a 2s  . com
    String str = pattern;
    if (arguments != null && arguments.length > 0) {
        int i = 0;
        String key, val;
        for (Object argument : arguments) {
            key = "{" + i++ + "}";
            val = argument == null ? "" : argument.toString();
            str = StringUtils.replace(str, key, val);
        }
    }
    str = str.replaceAll("\\{[\\d]*\\}", "");
    return str;
}

From source file:info.magnolia.importexport.PropertiesImportExport.java

/**
 * Transforms the keys to the following inner notation: <code>some/path/node.prop</code> or <code>some/path/node.@type</code>.
 *///from  ww  w .  j a v  a  2s  .  co  m
private Properties keysToInnerFormat(Properties properties) {
    Properties cleaned = new OrderedProperties();

    for (Object o : properties.keySet()) {
        String orgKey = (String) o;

        //if this is a node definition (no property)
        String newKey = orgKey;

        // make sure we have a dot as a property separator
        newKey = StringUtils.replace(newKey, "@", ".@");
        // avoid double dots
        newKey = StringUtils.replace(newKey, "..@", ".@");

        String propertyName = StringUtils.substringAfterLast(newKey, ".");
        String keySuffix = StringUtils.substringBeforeLast(newKey, ".");
        String path = StringUtils.replace(keySuffix, ".", "/");
        path = StringUtils.removeStart(path, "/");

        // if this is a path (no property)
        if (StringUtils.isEmpty(propertyName)) {
            // no value --> is a node
            if (StringUtils.isEmpty(properties.getProperty(orgKey))) {
                // make this the type property if not defined otherwise
                if (!properties.containsKey(orgKey + "@type")) {
                    cleaned.put(path + ".@type", ItemType.CONTENTNODE.getSystemName());
                }
                continue;
            }
            propertyName = StringUtils.substringAfterLast(path, "/");
            path = StringUtils.substringBeforeLast(path, "/");
        }
        cleaned.put(path + "." + propertyName, properties.get(orgKey));
    }
    return cleaned;
}

From source file:com.bibisco.manager.TextEditorManager.java

private static void parseTextNode(HtmlParsingResult pHtmlParsingResult, Node pNode) {

    List<String> lListWords = new ArrayList<String>();

    mLog.debug("Start parseTextNode(HtmlParsingResult, Node): ", pNode.toString());

    // character count
    String lStrNodeText = StringUtils.replace(pNode.toString(), "&nbsp;", " ");
    lStrNodeText = StringUtils.replace(lStrNodeText, "\n", "");
    lStrNodeText = StringEscapeUtils.unescapeHtml(lStrNodeText);
    pHtmlParsingResult.characterCount += lStrNodeText.length();

    // extract words
    lStrNodeText = pNode.toString();//from  www .ja  va 2 s .com
    lStrNodeText = StringUtils.replace(lStrNodeText, "&nbsp;", "");
    lStrNodeText = StringUtils.replace(lStrNodeText, "&laquo;", "");
    lStrNodeText = StringUtils.replace(lStrNodeText, "&raquo;", "");
    lStrNodeText = StringUtils.replace(lStrNodeText, "&mdash;", "");
    lStrNodeText = StringEscapeUtils.unescapeHtml(lStrNodeText);
    lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 33, 38);
    lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 40, 47);
    lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 58, 64);
    lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 91, 96);
    lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 123, 126);
    lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 161, 191);
    lStrNodeText = StringUtils.replaceChars(lStrNodeText, '', ' ');
    lStrNodeText = StringUtils.replaceChars(lStrNodeText, '', ' ');
    lStrNodeText = StringUtils.replaceChars(lStrNodeText, '', ' ');
    lStrNodeText = lStrNodeText.trim();

    if (StringUtils.isNotBlank(lStrNodeText)) {
        StringTokenizer lStringTokenizer = new StringTokenizer(lStrNodeText);
        while (lStringTokenizer.hasMoreTokens()) {
            lListWords.add(lStringTokenizer.nextToken());
        }
    }
    pHtmlParsingResult.words.addAll(lListWords);

    mLog.debug("End parseTextNode(HtmlParsingResult, Node)");
}

From source file:com.impetus.spark.client.SparkClient.java

public Object find(Class entityClass, Object key) {

    EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass);

    String tableName = entityMetadata.getTableName();
    Class fieldClass = entityMetadata.getIdAttribute().getJavaType();
    String select_Query = SparkQueryConstants.SELECTALL_QUERY;
    select_Query = StringUtils.replace(select_Query, SparkQueryConstants.TABLE, tableName);
    StringBuilder builder = new StringBuilder(select_Query);
    builder.append(SparkQueryConstants.ADD_WHERE_CLAUSE);
    builder.append(dataHandler.getColumnName(entityMetadata.getIdAttribute()));
    builder.append(SparkQueryConstants.EQUALS);

    appendValue(builder, fieldClass, key);
    List result = this.executeQuery(builder.toString(), entityMetadata, null);
    return result.isEmpty() ? null : result.get(0);
}

From source file:com.valygard.aohruthless.Joystick.java

/**
 * Not satisfied with global logging, which can become cluttered and messy
 * with many plugins or players using commands, etc, the Bukkit logger will
 * log all relevant information to a log file. This log file can be found in
 * the plugin data folder, in the subdirectory <i>logs</i>.
 * <p>/*from ww w  .jav a 2  s. c om*/
 * The log file, <i>joystick.log</i>, will not be overriden. The logger will
 * simply append new information if the file already exists. All messages
 * will be logged in the format:<br>
 * [month-day-year hr-min-sec] (level): (message), where level is the
 * {@link LogRecord#getLevel()} and the message is the
 * {@link LogRecord#getMessage()}.
 * </p>
 * 
 * @return the created FileHandler, null if a SecurityException or
 *         IOException were thrown and handled.
 */
private FileHandler setupLogger() {
    File dir = new File(getDataFolder() + File.separator + "logs");
    dir.mkdirs();
    try {
        FileHandler handler = new FileHandler(dir + File.separator + "joystick.log", true);
        getLogger().addHandler(handler);
        handler.setFormatter(new SimpleFormatter() {

            @Override
            public String format(LogRecord record) {
                Date date = new Date();
                SimpleDateFormat df = new SimpleDateFormat("[MM-dd-yyyy HH:mm:ss]");
                return df.format(date) + " " + record.getLevel() + ":"
                // org.apache.commons.lang
                        + StringUtils.replace(record.getMessage(), "[Joystick]", "")
                        + System.getProperty("line.separator");
            }
        });
        return handler;
    } catch (SecurityException | IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.flexive.tests.shared.FxSharedUtilTest.java

/**
 * Tests for the filter method/*from   ww w.  j a va2 s.co m*/
 */
@Test
public void filter() {
    String newline = "abc\ndef";
    String htmlFilter = "1 > 2 < 3";
    Assert.assertEquals(FxFormatUtils.escapeForJavaScript(newline, false), newline.replace('\n', ' '),
            "Did not preserve newlines correctly.");
    Assert.assertEquals(FxFormatUtils.escapeForJavaScript(newline, true),
            StringUtils.replace(newline, "\n", "<br/>"), "Did not replaces newlines correctly.");
    Assert.assertEquals(FxFormatUtils.escapeForJavaScript(htmlFilter, false, true),
            StringUtils.replace(StringUtils.replace(htmlFilter, "<", "&lt;"), ">", "&gt;"),
            "Did not escape HTML code correctly.");
    Assert.assertEquals(FxFormatUtils.escapeForJavaScript(null), "", "Did not treat null value correctly.");
    Assert.assertEquals(FxFormatUtils.escapeForJavaScript(""), "", "Did not treat empty string correctly.");
}

From source file:AIR.Common.Web.FileFtpHandler.java

public static InputStream openStream(String ftpFilePath) throws FtpResourceException {
    try {/*from   www  . ja  v  a2 s  .  c  o  m*/
        ftpFilePath = StringUtils.replace(ftpFilePath, "\\", "/");
        URI requestUri = new URI(ftpFilePath);
        return openStream(requestUri);
    } catch (URISyntaxException exp) {
        throw new FtpResourceException(exp);
    }
}

From source file:com.jnj.b2b.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    final String originalReferer = (String) request.getSession()
            .getAttribute(StorefrontFilter.ORIGINAL_REFERER);
    if (StringUtils.isNotBlank(originalReferer)) {
        return REDIRECT_PREFIX + StringUtils.replace(originalReferer, "/" + old + "/", "/" + current + "/");
    }/*from w  w  w  .j  a v  a2 s  .  co  m*/

    String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (!StringUtils.endsWith(referer, "/")) {
        referer = referer + "/";
    }
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old)) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old, "/" + current);
    }
    return REDIRECT_PREFIX + referer;
}

From source file:com.taobao.tdhs.jdbc.TDHSPreparedStatement.java

public void setString(int parameterIndex, @Nullable String x) throws SQLException {
    if (StringUtils.isNotBlank(x)) {
        x = StringUtils.replace(x, "\\", "\\\\");
        x = StringUtils.replace(x, "\'", "\\\'");
        x = StringUtils.replace(x, "\"", "\\\"");
        x = "\'" + x + "\'";
    }/*from   w w w.  ja v a  2s .  c  om*/
    setDString(parameterIndex, x);
}