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:com.qcadoo.view.internal.components.grid.GridComponentFilterUtils.java

private static String getFieldNameFromExpression(final String expression) {
    String pattern = "#(\\w+)(\\['(\\w+)'\\])?([[?]?.get\\('\\w+'\\)]*)";
    Matcher matcher = Pattern.compile(pattern).matcher(StringUtils.trim(expression));
    if (matcher.matches()) {
        final StringBuilder fieldNameBuilder = new StringBuilder(matcher.group(1));
        if (StringUtils.isNotBlank(matcher.group(3))) {
            fieldNameBuilder.append(".");
            fieldNameBuilder.append(matcher.group(3));
        }/*from ww w  .jav  a  2s . c  o  m*/
        if (StringUtils.isNotBlank(matcher.group(4))) {
            final String[] searchList = new String[] { "get('", "?.get('", "')" };
            final String[] replacementList = new String[] { "", ".", "" };
            fieldNameBuilder.append(StringUtils.replaceEach(matcher.group(4), searchList, replacementList));
        }
        return fieldNameBuilder.toString();
    }
    return null;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.exporter.ExportWorkbook.java

/**
 * Makes a new sheet with <code>sheetName</code> and returns it. Only its current row insert
 * marker is tracked in this Class//from   w ww  . j  a  v  a 2  s .c o m
 * 
 * @param sheetName
 * @return The internal sheet ID of the newly created sheet
 */
public int createSheet(String sheetName) {
    // If these characters are not replaced, then the Excel workbook cannot be generated and it
    // throws an IllegalArgumentException
    String sanitizedSheetName = StringUtils.replaceEach(sheetName,
            new String[] { "\\", "/", "*", "[", "]", "?" }, new String[] { "_", "_", "_", "(", ")", "_" });

    checkIfSheetExists(sanitizedSheetName);

    Sheet sheet = this.getWb().createSheet(sanitizedSheetName);
    sheet.setZoom(SHEET_NUMERATOR, SHEET_DENOMINATOR);
    sheet.setDefaultColumnWidth(DEFAULT_COLUMN_WIDTH);

    sheetOrder.add(sheet);

    return sheetOrder.size() - 1; // return the sheet position in the list
}

From source file:de.d3web.we.ci4ke.build.CIRenderer.java

private void appendMessageText(String web, Message message, RenderResult result) {
    String text = message.getText();
    if (text == null)
        text = "";
    ArrayList<MessageObject> objects = new ArrayList<>(message.getObjects());
    Collections.sort(objects, new SizeComparator());
    String[] targets = new String[objects.size()];
    String[] replacements = new String[objects.size()];
    int i = 0;//from   w  ww  . ja v a 2s  .  co  m
    for (MessageObject object : objects) {
        RenderResult temp = new RenderResult(result);
        renderObjectName(web, object.getObjectName(), object.geObjectClass(), temp);
        String renderedObjectName = temp.toStringRaw();
        targets[i] = object.getObjectName();
        replacements[i] = renderedObjectName;
        i++;
    }
    // This is non repeating and since the targets are sorted by length, the
    // replacing will be correct, if all targets are in the text. If not all
    // are in the text, the replacing will only be inaccurate in rare cases
    // (e.g. targets[0].contains(target[1]...)
    text = StringUtils.replaceEach(text, targets, replacements);
    String lb = new RenderResult(result).appendHtml("<br>\n").toStringRaw();
    text = text.replaceAll("\\r?\\n", lb);
    result.appendJSPWikiMarkup(text);
}

From source file:at.pagu.soldockr.core.query.Criteria.java

private String escapeCriteriaValue(String criteriaValue) {
    return StringUtils.replaceEach(criteriaValue, RESERVED_CHARS, RESERVED_CHARS_REPLACEMENT);
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.brat.BratWriter.java

private void writeAnnotations(JCas aJCas) throws IOException {
    BratAnnotationDocument doc = new BratAnnotationDocument();

    List<FeatureStructure> relationFS = new ArrayList<>();

    Map<BratEventAnnotation, FeatureStructure> eventFS = new LinkedHashMap<>();

    // Go through all the annotations but only handle the ones that have no references to
    // other annotations.
    for (FeatureStructure fs : selectAll(aJCas)) {
        // Skip document annotation
        if (fs == aJCas.getDocumentAnnotationFs()) {
            continue;
        }//from   w ww .  ja  va 2 s  .  c o m

        // Skip excluded types
        if (excludeTypes.contains(fs.getType().getName())) {
            getLogger().debug("Excluding [" + fs.getType().getName() + "]");
            continue;
        }

        if (spanTypes.contains(fs.getType().getName())) {
            writeTextAnnotation(doc, (AnnotationFS) fs);
        } else if (parsedRelationTypes.containsKey(fs.getType().getName())) {
            relationFS.add(fs);
        } else if (hasNonPrimitiveFeatures(fs) && (fs instanceof AnnotationFS)) {
            //            else if (parsedEventTypes.containsKey(fs.getType().getName())) {
            BratEventAnnotation event = writeEventAnnotation(doc, (AnnotationFS) fs);
            eventFS.put(event, fs);
        } else if (fs instanceof AnnotationFS) {
            warnings.add("Assuming annotation type [" + fs.getType().getName() + "] is span");
            writeTextAnnotation(doc, (AnnotationFS) fs);
        } else {
            warnings.add("Skipping annotation with type [" + fs.getType().getName() + "]");
        }
    }

    // Handle relations now since now we can resolve their targets to IDs.
    for (FeatureStructure fs : relationFS) {
        writeRelationAnnotation(doc, fs);
    }

    // Handle event slots now since now we can resolve their targets to IDs.
    for (Entry<BratEventAnnotation, FeatureStructure> e : eventFS.entrySet()) {
        writeSlots(doc, e.getKey(), e.getValue());
    }

    switch (filenameSuffix) {
    case ".ann":
        try (Writer out = new OutputStreamWriter(getOutputStream(aJCas, filenameSuffix), "UTF-8")) {
            doc.write(out);
            break;
        }
    case ".html":
    case ".json":
        String template;
        if (filenameSuffix.equals(".html")) {
            template = IOUtils.toString(getClass().getResource("html/template.html"));
        } else {
            template = "{ \"collData\" : ##COLL-DATA## , \"docData\" : ##DOC-DATA## }";
        }

        JsonFactory jfactory = new JsonFactory();
        try (Writer out = new OutputStreamWriter(getOutputStream(aJCas, filenameSuffix), "UTF-8")) {
            String docData;
            try (StringWriter buf = new StringWriter()) {
                try (JsonGenerator jg = jfactory.createGenerator(buf)) {
                    jg.useDefaultPrettyPrinter();
                    doc.write(jg, aJCas.getDocumentText());
                }
                docData = buf.toString();
            }

            String collData;
            try (StringWriter buf = new StringWriter()) {
                try (JsonGenerator jg = jfactory.createGenerator(buf)) {
                    jg.useDefaultPrettyPrinter();
                    conf.write(jg);
                }
                collData = buf.toString();
            }

            template = StringUtils.replaceEach(template, new String[] { "##COLL-DATA##", "##DOC-DATA##" },
                    new String[] { collData, docData });

            out.write(template);
        }
        conf = new BratConfiguration();
        break;
    default:
        throw new IllegalArgumentException("Unknown file format: [" + filenameSuffix + "]");
    }
}

From source file:de.interactive_instruments.ShapeChange.Target.JSON.JsonSchema.java

/**
 * <p>See https://tools.ietf.org/html/rfc7159: characters that must be escaped quotation mark, reverse solidus, and the control characters (U+0000 through U+001F)</p>
 * <p>Control characters that are likely to occur in EA models, especially when using memo tagged values: \n, \r and \t.</p>
 *///from   www . ja  v  a2s .  co  m
private String escape(String s2) {
    return StringUtils.replaceEach(s2, new String[] { "\"", "\\", "\n", "\r", "\t" },
            new String[] { "\\\"", "\\\\", CharUtils.unicodeEscaped('\n'), CharUtils.unicodeEscaped('\r'),
                    CharUtils.unicodeEscaped('\t') });
}

From source file:ddf.catalog.source.solr.SolrFilterDelegate.java

private String escapeSpecialCharacters(String searchPhrase) {
    return StringUtils.replaceEach(searchPhrase, LUCENE_SPECIAL_CHARACTERS, ESCAPED_LUCENE_SPECIAL_CHARACTERS);
}

From source file:edu.harvard.iq.dvn.ingest.dsb.AdvancedStatGUIdata.java

public String shortenTitle(String title) {
    String st = StringUtils.replaceEach(
            title, new String[] { "Dichotomous", "Regression", "Continuous", "Dependent", "Variables",
                    "Categorical", "Social Network" },
            new String[] { "Binary", "Reg", "Cont", "Dep", "Vars", "Cat", "SN" });

    return st;//from ww  w.ja  v  a 2s  .co  m
}

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

private String average(String... strings) {
    String case$ = getAverageCasePattern();
    String arg0$ = join(EMPTY, getAdd(), strings);
    String arg1$ = count(strings);
    String[] placeHolders = new String[] { ARG0, ARG1 };
    String[] argumentList = new String[] { arg0$, arg1$ };
    return StringUtils.replaceEach(case$, placeHolders, argumentList);
}

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

private String imum(String comparador, String... strings) {
    String case$ = "case ";
    String when$ = "when {1} then {0} ";
    String else$ = "else null end";
    String arg0$;//from   w w w  .j av a2  s. c  o m
    String arg1$;
    String conector = getAnd();
    String[] placeHolders = new String[] { ARG0, ARG1 };
    //      String[] argumentList = new String[]{arg0$, arg1$};
    String[] strings1 = new String[strings.length];
    int i1;
    for (int i = 0; i < strings.length; i++) {
        arg0$ = strings[i];
        if (StringUtils.isNotBlank(arg0$)) {
            Arrays.fill(strings1, EMPTY);
            i1 = 0;
            for (int j = 0; j < strings.length; j++) {
                if (i != j) {
                    arg1$ = strings[j];
                    if (StringUtils.isNotBlank(arg1$)) {
                        strings1[i1++] = join(EMPTY, comparador, arg0$, arg1$);
                    }
                }
            }
            arg1$ = join(EMPTY, conector, strings1);
            case$ += StringUtils.replaceEach(when$, placeHolders, new String[] { arg0$, arg1$ });
        }
    }
    return case$ + else$;
}