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

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

Introduction

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

Prototype

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

Source Link

Document

Replaces all occurrences of Strings within another String.

Usage

From source file:org.structr.rest.serialization.StructrConfigHtmlWriter.java

@Override
public RestWriter value(String value) throws IOException {

    if (!hasName) {

        currentElement = currentElement.block("li");
    }/* w  ww .  j  a va 2  s  . c  om*/

    if ("id".equals(lastName)) {

        if (currentObject == null) {

            currentElement.inline("a").css("id").attr(new Href(restPath + "/" + value + propertyView))
                    .text("\"", value, "\"");

        } else if (currentObject instanceof AbstractRelationship) {

            currentElement.inline("a").css("id").attr(new Href(restPath + "/"
                    + currentObject.getProperty(AbstractRelationship.type) + "/" + value + propertyView))
                    .text("\"", value, "\"");

        } else {

            currentElement.inline("a").css("id")
                    .attr(new Href(restPath + "/" + currentObject.getType() + "/" + value + propertyView))
                    .text("\"", value, "\"");

        }

    } else {

        value = value.replaceAll("\\\\", "\\\\\\\\"); // escape backslashes in strings
        value = value.replaceAll("\"", "\\\\\\\""); // escape quotation marks inside strings

        // Escape for HTML output
        value = StringUtils.replaceEach(value, new String[] { "&", "<", ">" },
                new String[] { "&amp;", "&lt;", "&gt;" });

        currentElement.inline("span").css("string").text("\"", value, "\"");

    }

    currentElement = currentElement.parent(); // end LI

    hasName = false;

    return this;
}

From source file:org.structr.rest.serialization.StructrJsonHtmlWriter.java

@Override
public RestWriter value(String value) throws IOException {

    if (!hasName) {

        currentElement = currentElement.block("li");
    }//from   w w  w  .  j a v  a 2s .  c  o m

    if ("id".equals(lastName)) {

        currentElement.inline("a").css("id").attr(new Href(restPath + "/" + value + propertyView)).text("\"",
                value, "\"");

    } else {

        value = value.replaceAll("\\\\", "\\\\\\\\"); // escape backslashes in strings
        value = value.replaceAll("\"", "\\\\\\\""); // escape quotation marks inside strings

        // Escape for HTML output
        value = StringUtils.replaceEach(value, new String[] { "&", "<", ">" },
                new String[] { "&amp;", "&lt;", "&gt;" });

        currentElement.inline("span").css("string").text("\"", value, "\"");

    }

    currentElement = currentElement.parent(); // end LI

    hasName = false;

    return this;
}

From source file:org.structr.web.entity.dom.DOMNode.java

protected String escapeForHtml(final String raw) {

    return StringUtils.replaceEach(raw, new String[] { "&", "<", ">" },
            new String[] { "&amp;", "&lt;", "&gt;" });

}

From source file:org.structr.web.entity.dom.DOMNode.java

protected String escapeForHtmlAttributes(final String raw) {

    return StringUtils.replaceEach(raw, new String[] { "&", "<", ">", "\"", "'" },
            new String[] { "&amp;", "&lt;", "&gt;", "&quot;", "&#39;" });

}

From source file:org.thelq.stackexchange.api.queries.methods.VectorQueryMethod.java

public String getFinal() {
    String methodFinal = raw;/*  w ww .  j a  v  a  2  s .  c  o m*/
    if (vectorSingle != null) {
        String[] subsitutions = new String[vectorSingle.length];
        Arrays.fill(subsitutions, "{}");
        methodFinal = StringUtils.replaceEach(raw, subsitutions, vectorSingle);
    } else if (vectorCollection != null) {
        if (StringUtils.countMatches(raw, "{}") != 1)
            throw new RuntimeException("No more vectors to replace! Raw: " + raw + " | Final: " + methodFinal);
        //Verify vector if it is required
        Iterator<?> vectorItr = vectorCollection.iterator();
        if (!vectorItr.hasNext())
            throw new RuntimeException("Vector cannot be empty");

        //Do the replace
        methodFinal = StringUtils.replaceOnce(raw, "{}", QueryUtils.PARAMETER_JOINER.join(vectorItr));

        //Make sure we didn't miss anything
        if (methodFinal.contains("{}"))
            throw new RuntimeException("Still contains vector: " + methodFinal);
    } else
        throw new RuntimeException("No vector to replace! " + raw);
    return methodFinal;
}

From source file:org.xwiki.contrib.confluence.parser.xhtml.internal.wikimodel.ConfluenceXWikiGeneratorListener.java

private String escapeSpace(String space) {
    return StringUtils.replaceEach(space, REPLACE_SPACE_PREVIOUS, REPLACE_SPACE_NEXT);
}

From source file:org.xwiki.contrib.confluence.parser.xhtml.internal.wikimodel.ConfluenceXWikiGeneratorListener.java

private String escapeDocument(String document) {
    return StringUtils.replaceEach(document, REPLACE_DOCUMENT_PREVIOUS, REPLACE_DOCUMENT_NEXT);
}

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

/**
 * {@inheritDoc}//from   w w  w .  j a va  2 s .c  om
 * 
 * @see org.xwiki.model.reference.EntityReferenceResolver#resolve
 */
public EntityReference resolve(String entityReferenceRepresentation, EntityType type, Object... parameters) {
    // TODO: Once we support nested spaces, handle the possibility of having nested spaces. The format is still
    // to be defined but it could be for example: Wiki:Space1.Space2.Page

    // First, check if there's a definition for the type
    if (!SEPARATORS.containsKey(type)) {
        throw new RuntimeException("No parsing definition found for Entity Type [" + type + "]");
    }

    // Handle the case when the passed representation is null. In this case we consider it similar to passing
    // an empty string.
    StringBuilder representation;
    if (entityReferenceRepresentation == null) {
        representation = new StringBuilder();
    } else {
        representation = new StringBuilder(entityReferenceRepresentation);
    }

    EntityReference reference = null;
    EntityReference lastReference = null;
    char[] separatorsForType = SEPARATORS.get(type);
    EntityType[] entityTypesForType = ENTITYTYPES.get(type);

    // Iterate over the representation string looking for iterators in the correct order (rightmost separator
    // looked for first).
    for (int i = 0; i < separatorsForType.length; i++) {
        String name;
        if (representation.length() > 0) {
            char separator = separatorsForType[i];
            name = lastIndexOf(representation, separator, entityTypesForType[i], parameters);
        } else {
            // There's no definition for the current segment use default values
            name = resolveDefaultValue(entityTypesForType[i], parameters);
        }

        if (name != null) {
            EntityReference newReference = new EntityReference(name, entityTypesForType[i]);
            if (lastReference != null) {
                lastReference.setParent(newReference);
            }
            lastReference = newReference;
            if (reference == null) {
                reference = lastReference;
            }
        }
    }

    // Handle last entity reference's name
    String name;
    if (representation.length() > 0) {
        name = StringUtils.replaceEach(representation.toString(), ESCAPEMATCHING, ESCAPEMATCHINGREPLACE);
    } else {
        name = resolveDefaultValue(entityTypesForType[separatorsForType.length], parameters);
    }

    if (name != null) {
        EntityReference newReference = new EntityReference(name, entityTypesForType[separatorsForType.length]);
        if (lastReference != null) {
            lastReference.setParent(newReference);
        }
        if (reference == null) {
            reference = newReference;
        }
    }

    return reference;
}

From source file:org.xwiki.rendering.internal.parser.reference.GenericLinkReferenceParser.java

/**
 * @param text the reference from which to remove unneeded escapes
 * @return the cleaned text/*ww w .  j av  a  2 s . co  m*/
 */
private String removeEscapesFromReferencePart(String text) {
    return StringUtils.replaceEach(text, ESCAPES_REFERENCE, ESCAPE_REPLACEMENTS_REFERENCE);
}

From source file:org.xwiki.rendering.internal.parser.reference.GenericLinkReferenceParser.java

/**
 * @param text the reference from which to remove unneeded escapes
 * @return the cleaned text/*www .jav  a2 s .c o  m*/
 */
private String removeEscapesFromExtraParts(String text) {
    return StringUtils.replaceEach(text, ESCAPES_EXTRA, ESCAPE_REPLACEMENTS_EXTRA);
}