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:org.oscarehr.sharingcenter.util.EformParser.java

@Override
public void startElement(String namespaceURI, String sName, // simple name
        String qName, // qualified name
        Attributes attrs) throws SAXException {

    boolean isHTMLElement = false;
    boolean isFormElement = false;

    String eName = sName; // element name
    if ("".equals(eName)) {
        eName = qName; // not namespace-aware
    }/*from  www .  j a  va  2 s .co m*/
    echoText();
    emit("<" + eName);

    if (eName.equalsIgnoreCase("html")) {
        isHTMLElement = true;
    } else if (eName.equalsIgnoreCase("form")) {
        isFormElement = true;
    }

    if (attrs != null) {
        if (isHTMLElement) {
            emit(" xmlns=\"http://www.w3.org/1999/xhtml\"");
        }
        for (int i = 0; i < attrs.getLength(); i++) {
            String aName = attrs.getLocalName(i); // Attr name

            if ("".equals(aName)) {
                aName = attrs.getQName(i);
            }
            emit(" ");

            String attributeValue = StringUtils.replaceEach(attrs.getValue(i),
                    new String[] { "&", "\"", "<", ">" }, new String[] { "&amp;", "&quot;", "&lt;", "&gt;" });

            emit(aName + "=\"" + attributeValue + "\"");
        }

    }

    //Check if this element name is in the array of self-closing names array.
    if (isSelfClosing(eName)) {
        suppressNextClosingTag = true;
        emit(" />");
        return;
    } else {

        if (eName.equals("style") || eName.equals("script")) {
            emit("><![CDATA[");
        } else {
            emit(">");
        }
    }

    if (isFormElement) {
        nl();
        //emit("<input type=\"hidden\" name=\"pcsFormId\" value=\"" + formSerialNumber + "\" />");
        nl();
    }

}

From source file:org.sakaiproject.tool.assessment.qti.util.XmlUtil.java

public static String convertoLTGT(String value) {
    return StringUtils.replaceEach(value, new String[] { "<", ">" }, new String[] { "&lt;", "&gt;" });
}

From source file:org.sonar.cxx.preprocessor.CxxPreprocessor.java

private String quote(String str) {
    return StringUtils.replaceEach(str, new String[] { "\\", "\"" }, new String[] { "\\\\", "\\\"" });
}

From source file:org.sonar.plugins.xml.rules.AbstractMessagesRepository.java

public Map<String, Pattern> getMessagePatterns() {
    if (patterns == null) {
        patterns = new HashMap<String, Pattern>();

        String[] replacements = new String[] { ".*", ".*", ".*", ".*", ".*" };

        for (Entry entry : messages.entrySet()) {
            String regExp = (String) entry.getValue();

            // replace single quoted 1-4 markers
            regExp = StringUtils.replaceEach(regExp,
                    new String[] { "'{0}'", "'{1}'", "'{2}'", "'{3}'", "'{4}'" }, replacements);
            // replace double quoted 1-4 markers
            regExp = StringUtils.replaceEach(regExp,
                    new String[] { "\"{0}\"", "\"{1}\"", "\"{2}\"", "\"{3}\"", "\"{4}\"" }, replacements);
            // replace unquoted 1-4 markers
            regExp = StringUtils.replaceEach(regExp, new String[] { "{0}", "{1}", "{2}", "{3}", "{4}" },
                    replacements);//w w w.  j  av a  2s.c o m

            // replace remaining regexp special characters
            regExp = StringUtils.replaceEach(regExp,
                    new String[] { "?", "[", "]", "{", "}", "(", ")", "\"</{0}>\"", "''" },
                    new String[] { ".", ".", ".", ".", ".", ".", ".", ".*", ".*" });

            try {
                Pattern pattern = Pattern.compile(regExp);
                patterns.put((String) entry.getKey(), pattern);
            } catch (PatternSyntaxException e) {
                LOG.debug("", e);
                // ignore
            }
        }
    }
    return patterns;
}

From source file:org.sonar.updatecenter.deprecated.UpdateCenter.java

private JSONArray resolvePlugins() throws Exception {
    List<String> plugins = FileUtils.readLines(FileUtils.toFile(getClass().getResource("/plugins.txt")));

    String pluginInfoWidgetTemplate = FileUtils
            .readFileToString(FileUtils.toFile(getClass().getResource("/plugin-info-widget-template.html")));
    if (outputDirectory != null) {
        FileUtils.copyURLToFile(getClass().getResource("/style.css"),
                new File(outputDirectory, "plugins/style.css"));
    }//  w  w w  .j a  v a 2 s  .c om

    JSONArray json = new JSONArray();
    for (String plugin : plugins) {
        if (plugin.startsWith("#")) {
            // Skip comments
            continue;
        }
        History<Plugin> history = resolvePluginHistory(plugin);
        if (history.latest() == null) {
            System.out.println("WTF? " + plugin);
            continue;
        }
        json.add(history.latest().toJsonObject());

        Plugin latest = history.latest();

        if (outputDirectory != null) {
            String pluginInfoWidget = StringUtils.replaceEach(pluginInfoWidgetTemplate,
                    new String[] { "%name%", "%version%", "%date%", "%downloadUrl%", "%sonarVersion%",
                            "%issueTracker%", "%sources%", "%license%", "%developers%" },
                    new String[] { latest.getName(), latest.getVersion(), latest.getReleaseDate(),
                            latest.getDownloadUrl(), latest.getRequiredSonarVersion(),
                            formatLink(latest.getIssueTracker()), formatLink(latest.getSources()),
                            latest.getLicense() == null ? "Unknown" : latest.getLicense(),
                            formatDevelopers(latest.getDevelopers()) });
            FileUtils.writeStringToFile(new File(outputDirectory, "plugins/" + latest.getKey() + ".html"),
                    pluginInfoWidget, "UTF-8");
        }

        // TODO use logger
        System.out.println(
                latest.getName() + " : " + history.getAllVersions() + ", latest " + latest.getVersion());
    }

    return json;
}

From source file:org.talend.dataquality.datamasking.functions.Function.java

/**
 * Remove all the spaces in the input string
 * // w w  w. j  a v  a  2s . co  m
 * @param input
 * @return
 */
protected String removeFormatInString(String input) {
    return StringUtils.replaceEach(input, new String[] { " ", ".", "-", "/" }, new String[] { "", "", "", "" });
}

From source file:org.tap4j.plugin.TapResult.java

public String escapeHTML(String html) {
    return StringUtils.replaceEach(html, new String[] { "&", "\"", "<", ">" },
            new String[] { "&amp;", "&quot;", "&lt;", "&gt;" });
}

From source file:org.tinygroup.template.rumtime.TemplateUtil.java

/**
 * Html//from w  ww. j  a va  2  s  .  c  om
 *
 * @param object
 * @return
 */
public static String escapeHtml(Object object) {
    if (object == null) {
        return null;
    }
    return StringUtils.replaceEach(object.toString(), new String[] { "&", "\"", "<", ">" },
            new String[] { "&amp;", "&quot;", "&lt;", "&gt;" });

}

From source file:org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer.java

protected void serializeEntityReference(EntityReference currentReference, StringBuilder representation,
        boolean isLastReference) {
    List<String> currentEscapeChars = this.escapes.get(currentReference.getType());

    // If we're on the Root reference then we don't need to escape anything
    if (currentEscapeChars != null) {
        representation.append(/* ww w.ja  v  a  2 s  . com*/
                StringUtils.replaceEach(currentReference.getName(), currentEscapeChars.toArray(new String[0]),
                        this.replacements.get(currentReference.getType()).toArray(new String[0])));
    } else {
        representation.append(currentReference.getName());
    }

    //  If the reference is the last one in the chain then don't print the separator char
    if (!isLastReference && currentReference.getChild() != null) {
        String separatorChar = this.escapes.get(currentReference.getChild().getType()).get(0);
        representation.append(separatorChar);
    }
}

From source file:ru.altruix.commons.impl.util.DatabaseUtils.java

public static String replacePlaceholders(final String aTemplate, final Object... aReplacements) {
    final String[] searchList = new String[aReplacements.length];

    for (int i = 0; i < searchList.length; i++) {
        searchList[i] = "{" + Integer.toString(i) + "}";
    }//from w w w  .j av  a 2s. c o m

    final String[] replacements = new String[aReplacements.length];

    for (int i = 0; i < replacements.length; i++) {
        replacements[i] = (String) aReplacements[i];
    }

    return StringUtils.replaceEach(aTemplate, searchList, replacements);
}