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.xwiki.rendering.internal.parser.reference.GenericLinkReferenceParser.java

/**
 * @param text the reference from which to remove unneeded escapes
 * @return the cleaned text//from ww w  .  ja va 2 s .co m
 */
private String removeEscapes(String text) {
    return StringUtils.replaceEach(text, ESCAPE_INTERWIKI, ESCAPE_REPLACEMENTS_INTERWIKI);
}

From source file:org.xwiki.rendering.internal.renderer.xwiki20.reference.DocumentReferenceTypeSerializer.java

/**
 * @param text the reference to which to add escapes to
 * @return the modified text//  w w w  .  ja  v  a  2 s .  c  o  m
 */
protected String addEscapesToReferencePart(String text) {
    return StringUtils.replaceEach(text, ESCAPES_REFERENCE, ESCAPE_REPLACEMENTS_REFERENCE);
}

From source file:org.xwiki.rendering.internal.renderer.xwiki20.reference.DocumentReferenceTypeSerializer.java

/**
 * @param text the query string and anchor parts to which to add escapes to
 * @return the modified text//  ww w .j a v  a  2s  . c  om
 */
protected String addEscapesToExtraParts(String text) {
    return StringUtils.replaceEach(text, ESCAPES_EXTRA, ESCAPE_REPLACEMENTS_EXTRA);
}

From source file:password.pwm.config.profile.RuleHelperTest.java

private Answer<String> replaceAllMacrosInMap(final String[][] macroMap) {
    return new Answer<String>() {
        @Override/*from   w  w  w  .  j  a  v  a  2s  .c om*/
        public String answer(InvocationOnMock invocation) throws Throwable {
            final String[] macroNames = new String[macroMap.length];
            final String[] macroValues = new String[macroMap.length];

            for (int i = 0; i < macroMap.length; i++) {
                macroNames[i] = macroMap[i][0];
                macroValues[i] = macroMap[i][1];
            }

            final String stringWithMacros = invocation.getArgument(0);
            return StringUtils.replaceEach(stringWithMacros, macroNames, macroValues);
        }
    };
}

From source file:pt.ua.dicoogle.core.query.ExportToCSVQueryTask.java

private void printLine(SearchResult result) {
    StringBuilder builder = new StringBuilder();

    HashMap<String, Object> extraFields = result.getExtraData();

    for (String tag : tagsOrder) {
        Object temp1 = extraFields.get(tag);

        String s = StringUtils.trimToEmpty(temp1.toString());

        if (s.length() > 0) {
            String temp = StringUtils.replaceEach(s, searchChars, replaceChars);
            builder.append(temp).append(";");
        } else {/*  w  w  w. j  a  va2  s  .c o  m*/
            builder.append(";");
        }
    }

    log.debug("Printing Line: ", builder.toString());
    nLines++;
    this.writter.println(builder.toString());
}

From source file:replace.Replacer.java

public static String unfold_common(final String string) {
    return StringUtils.replaceEach(string, TODO, TO);
}

From source file:se.trixon.jota.client.ui.TabItem.java

void save() {
    String ext = "log";
    FileNameExtensionFilter filter = new FileNameExtensionFilter(Dict.EXTENSION_FILTER_LOG.toString(), ext);

    SimpleDialog.clearFilters();//w w w  .  java2s .c  o  m
    SimpleDialog.addFilter(filter);
    SimpleDialog.setFilter(filter);
    SimpleDialog.setParent(this);
    String[] invalidChars = new String[] { "<", ">", ":", "\"", "/", "\\", "|", "?", "*" };
    String[] replaceChars = new String[] { "_", "_", "_", "_", "_", "_", "_", "_", "_" };
    String jobName = StringUtils.replaceEach(mJob.getName(), invalidChars, replaceChars);

    String filename = String.format("%s_%s.%s", jobName, getFinishedTime(), ext);
    SimpleDialog.setSelectedFile(new File(filename));
    if (SimpleDialog.saveFile(new String[] { ext })) {
        try {
            FileUtils.writeStringToFile(SimpleDialog.getPath(), logPanel.getText());
        } catch (IOException ex) {
            Message.error(this, Dict.IO_ERROR_TITLE.toString(), ex.getLocalizedMessage());
        }
    }
}

From source file:se.trixon.jota.server.JobExecutor.java

private void writelogs() {
    File directory = new File(ServerOptions.INSTANCE.getLogDir());
    String[] invalidChars = new String[] { "<", ">", ":", "\"", "/", "\\", "|", "?", "*" };
    String[] replaceChars = new String[] { "_", "_", "_", "_", "_", "_", "_", "_", "_" };
    String jobName = StringUtils.replaceEach(mJob.getName(), invalidChars, replaceChars);
    String outFile = String.format("%s.log", jobName);
    String errFile = String.format("%s.err", jobName);

    int logMode = mJob.getLogMode();
    if (logMode == 2) {
        outFile = String.format("%s %s.log", jobName, mJob.getLastRunDateTime("", mLastRun));
        errFile = String.format("%s %s.err", jobName, mJob.getLastRunDateTime("", mLastRun));
    }// w w  w  . ja  v  a 2s  .  c o  m

    boolean append = logMode == 0;

    try {
        FileUtils.forceMkdir(directory);
        File file = new File(directory, outFile);
        send(ProcessEvent.OUT, "");

        StringBuilder builder = new StringBuilder();
        if (mJob.isLogOutput() || mJob.isLogErrors() && !mJob.isLogSeparateErrors()) {
            FileUtils.writeStringToFile(file, mOutBuffer.toString(), append);
            String message = file.getAbsolutePath();
            Xlog.timedOut(message);
            builder.append(String.format("%s:%s", SystemHelper.getHostname(), message));
        }

        if (mJob.isLogErrors() && mJob.isLogSeparateErrors()) {
            if (builder.length() > 0) {
                builder.append("\n");
            }
            file = new File(directory, errFile);
            FileUtils.writeStringToFile(file, mErrBuffer.toString(), append);
            String message = file.getAbsolutePath();
            Xlog.timedOut(message);
            builder.append(String.format("%s:%s", SystemHelper.getHostname(), message));
        }

        if (builder.length() > 0) {
            builder.insert(0, String.format("%s\n", Dict.SAVE_LOG.toString()));
            send(ProcessEvent.OUT, builder.toString());
        }
    } catch (IOException ex) {
        Xlog.timedErr(ex.getLocalizedMessage());
    }
}

From source file:se.trixon.mapollage.Operation.java

private void saveToFile() {
    mListener.onOperationLog("");
    List keys = new ArrayList(mRootFolders.keySet());
    Collections.sort(keys);//from  w w w . ja  v a  2s .  co  m

    keys.stream().forEach((key) -> {
        mRootFolder.getFeature().add(mRootFolders.get((String) key));
    });

    if (mPathFolder != null && !mPathFolder.getFeature().isEmpty()) {
        mRootFolder.getFeature().add(mPathFolder);
    }

    if (mPathGapFolder != null && !mPathGapFolder.getFeature().isEmpty()) {
        mRootFolder.getFeature().add(mPathGapFolder);
    }

    if (isUsingThumbnails()) {
        mListener.onOperationLog(
                "\n" + String.format(mBundle.getString("stored_thumbnails"), mThumbsDir.getAbsolutePath()));
    }

    try {
        StringWriter stringWriter = new StringWriter();
        mKml.marshal(stringWriter);
        String kmlString = stringWriter.toString();

        if (mOptions.isCleanNs2()) {
            mListener.onOperationLog(mBundle.getString("clean_ns2"));
            kmlString = StringUtils.replace(kmlString, "xmlns:ns2=", "xmlns=");
            kmlString = StringUtils.replace(kmlString, "<ns2:", "<");
            kmlString = StringUtils.replace(kmlString, "</ns2:", "</");
        }

        if (mOptions.isCleanSpace()) {
            mListener.onOperationLog(mBundle.getString("clean_space"));
            kmlString = StringUtils.replace(kmlString, "        ", "\t");
            kmlString = StringUtils.replace(kmlString, "    ", "\t");
        }

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

        if (mOptions.isLogKml()) {
            mListener.onOperationLog("\n");
            mListener.onOperationLog(kmlString);
            mListener.onOperationLog("\n");
        }

        mListener.onOperationLog(String.format(Dict.SAVING.toString(), mDestinationFile.getAbsolutePath()));
        FileUtils.writeStringToFile(mDestinationFile, kmlString, "utf-8");

        String files = mBundle.getString("status_files");
        String exif = mBundle.getString("status_exif");
        String coordinate = mBundle.getString("status_coordinate");
        String time = mBundle.getString("status_time");
        String error = " " + Dict.Dialog.ERRORS.toString().toLowerCase();
        String placemarks = mBundle.getString("status_placemarks");

        int rightPad = files.length();
        rightPad = Math.max(rightPad, exif.length());
        rightPad = Math.max(rightPad, coordinate.length());
        rightPad = Math.max(rightPad, time.length());
        rightPad = Math.max(rightPad, error.length());
        rightPad = Math.max(rightPad, placemarks.length());
        rightPad++;

        int leftPad = 8;
        StringBuilder summaryBuilder = new StringBuilder("\n");

        String filesValue = String.valueOf(mFiles.size());
        summaryBuilder.append(StringUtils.rightPad(files, rightPad)).append(":")
                .append(StringUtils.leftPad(filesValue, leftPad)).append("\n");

        String exifValue = String.valueOf(mNumOfExif);
        summaryBuilder.append(StringUtils.rightPad(exif, rightPad)).append(":")
                .append(StringUtils.leftPad(exifValue, leftPad)).append("\n");

        String coordinateValue = String.valueOf(mNumOfGps);
        summaryBuilder.append(StringUtils.rightPad(coordinate, rightPad)).append(":")
                .append(StringUtils.leftPad(coordinateValue, leftPad)).append("\n");

        String placemarksValue = String.valueOf(mNumOfPlacemarks);
        summaryBuilder.append(StringUtils.rightPad(placemarks, rightPad)).append(":")
                .append(StringUtils.leftPad(placemarksValue, leftPad)).append("\n");

        String errorValue = String.valueOf(mNumOfErrors);
        summaryBuilder.append(StringUtils.rightPad(error, rightPad)).append(":")
                .append(StringUtils.leftPad(errorValue, leftPad)).append("\n");

        String timeValue = String.valueOf(Math.round((System.currentTimeMillis() - mStartTime) / 1000.0));
        summaryBuilder.append(StringUtils.rightPad(time, rightPad)).append(":")
                .append(StringUtils.leftPad(timeValue, leftPad)).append(" s").append("\n");

        mListener.onOperationFinished(summaryBuilder.toString(), mFiles.size());
    } catch (IOException ex) {
        mListener.onOperationFailed(ex.getLocalizedMessage());
    }
}