Example usage for org.apache.commons.lang StringUtils replaceChars

List of usage examples for org.apache.commons.lang StringUtils replaceChars

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils replaceChars.

Prototype

public static String replaceChars(String str, String searchChars, String replaceChars) 

Source Link

Document

Replaces multiple characters in a String in one go.

Usage

From source file:com.redhat.rhn.frontend.struts.RhnHelper.java

/**
 * Use this for every textarea that we use in our UI.  Otherwise you will get ^M
 * in your file showing up./*from  w w w .ja  v a2 s  .c o m*/
 * @param form to fetch from
 * @param name of value in form
 * @return String without CR in them.
 */
public static String getTextAreaValue(DynaActionForm form, String name) {
    String value = form.getString(name);
    return StringUtils.replaceChars(value, "\r", "");
}

From source file:edu.cornell.mannlib.vitro.webapp.servlet.ConceptSearchServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    super.doGet(req, resp);
    VitroRequest vreq = new VitroRequest(req);

    try {/*from   w w  w.ja v  a  2  s  .  c  om*/
        ServletContext ctx = vreq.getSession().getServletContext();
        //Captures both concept list and any errors if they exist
        ConceptInfo conceptInfo = new ConceptInfo();
        conceptInfo.setSemanticServicesError(null);

        //Json output should be written out
        List<Concept> results = null;
        try {
            results = ConceptSearchServiceUtils.getSearchResults(ctx, vreq);
        } catch (Exception ex) {
            SemanticServicesError semanticServicesError = new SemanticServicesError("Exception encountered ",
                    ex.getMessage(), "fatal");
            log.error("An error occurred retrieving search results", ex);
            conceptInfo.setSemanticServicesError(semanticServicesError);
        }
        conceptInfo.setConceptList(results);

        String json = renderJson(conceptInfo);

        json = StringUtils.replaceChars(json, "\r\t\n", "");
        PrintWriter writer = resp.getWriter();
        resp.setContentType("application/json");
        writer.write(json);
        writer.close();

    } catch (Exception ex) {
        log.warn(ex, ex);
    }
}

From source file:models.elasticsearch.PlayRestRequest.java

public PlayRestRequest(Request request, String path, String body) throws IOException {
    this.playRequest = request;
    this.path = path;
    this.method = Method.valueOf(request.method);
    this.params = new HashMap<String, String>();

    if (request.querystring != null) {
        RestUtils.decodeQueryString(request.querystring, 0, params);
    }/*from www.j  a  v  a 2s  . c om*/

    if (body == null)
        body = IO.readContentAsString(request.body);

    if (StringUtils.isBlank(body) && !"get".equals(request.method.toLowerCase())) {
        Logger.warn("body was empty but method != GET " + request.url);
    } else if (Logger.isDebugEnabled())
        Logger.debug("Executing request " + path + "\nbody=" + body);
    /**
     * strip out ctrl chars that break jackson
     */
    body = StringUtils.replaceChars(body, "\n\t", "  ");
    content = body.getBytes();
}

From source file:com.haulmont.cuba.web.toolkit.ui.CubaDateField.java

@Override
public void setDateFormat(String dateFormat) {
    super.setDateFormat(dateFormat);
    getState().dateMask = StringUtils.replaceChars(dateFormat, "dDMYy", "#####");
    markAsDirty();/* w w  w. j  av a  2 s  .c  o  m*/
}

From source file:com.excilys.ebi.bank.web.controller.account.transfer.operations.TransferPerformController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    // accept "," as a decimal separator
    binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, true) {
        @Override//from w  w w . j a  va2 s  .c  om
        public void setAsText(String text) throws IllegalArgumentException {
            super.setAsText(StringUtils.replaceChars(text, ',', '.'));
        }
    });
}

From source file:module.signed_workflow.domain.data.ActivitySignatureDataBean.java

/**
 * //from   ww w  .j  a  v  a 2  s  .c  o m
 * @return the SignatureId, this id should be unique and will identify the
 *         signed document
 */
@Override
public String generateSignatureId() {
    DateTime currentDateTime = new DateTime();
    String signatureId = getWorkflowProcess().getProcessNumber() + "-" + activity.getSimpleName() + "-"
            + currentDateTime.getYear() + "-" + currentDateTime.getMonthOfYear() + "-"
            + currentDateTime.getDayOfMonth() + "_" + currentDateTime.getMillis() + "_"
            + randomNrForSigIdGeneration.nextInt(100000);
    signatureId = StringUtils.replaceChars(signatureId, ' ', '_');
    return signatureId;

}

From source file:hydrograph.ui.expression.editor.buttons.OperatorToolCombo.java

private void loadDropDownItems() {
    Properties properties = new Properties();
    InputStream inStream;//from ww w. ja  va  2  s .c om
    try {
        inStream = ExpressionEditorUtil.INSTANCE.getPropertyFilePath(PathConstant.OPERATOR_CONFIG_FILE);
        properties.load(inStream);
        for (Object key : properties.keySet()) {
            if (key != null && properties.get(key) != null) {
                String operatorName = StringUtils.replaceChars((String) key, '_', SWT.SPACE);
                this.add(operatorName);
                this.setData(operatorName, (String) properties.get(key));
            }
        }
    } catch (IOException | RuntimeException exception) {
        LOGGER.error("Exception occurred while loading property file.", exception);
        StringBuffer buffer = new StringBuffer();
        buffer.append(Messages.OPERATOR_FILE_NOT_FOUND);
        new CustomMessageBox(SWT.ICON_WARNING, buffer.toString(), Messages.WARNING).open();
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopExportDisplay.java

/**
 * Show/Download resource at client side
 *
 * @param dataProvider {@link ExportDataProvider}
 * @param resourceName ResourceName for client side
 * @param format       {@link ExportFormat}
 * @see com.haulmont.cuba.gui.export.FileDataProvider
 * @see com.haulmont.cuba.gui.export.ByteArrayDataProvider
 *///  w w w. j a  va 2 s. c o  m
@Override
public void show(final ExportDataProvider dataProvider, String resourceName, ExportFormat format) {
    backgroundWorker.checkUIAccess();

    String fileName = resourceName;
    if (format != null) {
        if (StringUtils.isEmpty(getFileExt(fileName)))
            fileName += "." + format.getFileExt();
    }

    String dialogMessage = messages.getMessage(getClass(), "export.saveFile");
    String correctName = StringUtils.replaceChars(fileName, RESERVED_SYMBOLS, "_");
    dialogMessage = String.format(dialogMessage, correctName);

    final String finalFileName = correctName;
    String fileCaption = messages.getMessage(getClass(), "export.fileCaption");
    getFrame().getWindowManager().showOptionDialog(fileCaption, dialogMessage, Frame.MessageType.CONFIRMATION,
            new com.haulmont.cuba.gui.components.Action[] {
                    new AbstractAction("action.openFile", Status.PRIMARY) {
                        @Override
                        public void actionPerform(Component component) {
                            openFileAction(finalFileName, dataProvider);
                        }
                    }, new AbstractAction("action.saveFile") {
                        @Override
                        public void actionPerform(Component component) {
                            saveFileAction(finalFileName, getFrame(), dataProvider);
                        }
                    }, new AbstractAction("actions.Cancel") {
                        @Override
                        public void actionPerform(Component component) {
                            // do nothing
                        }
                    } });
}

From source file:net.mikaboshi.intra_mart.tools.log_stats.ant.ParserParameterDataType.java

public void setBegin(String begin) throws BuildException {

    begin = AntParameterUtil.parseToday(begin);

    if (begin != null) {

        begin = StringUtils.replaceChars(begin, '/', '-');

        if (begin.length() == 10) {
            begin += " 00:00";
        }//from w ww.j av  a  2s . c o  m
    }

    try {
        this.begin = this.dateFormat.parse(begin);
    } catch (ParseException e) {
        throw new BuildException("begin's date format is invalid : " + begin);
    }
}

From source file:info.magnolia.templating.jsp.taglib.ConvertNewLineTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *///from  ww w  .  ja  va 2 s . co  m
@Override
public int doEndTag() throws JspException {
    String bodyText = bodyContent.getString();

    if (StringUtils.isNotEmpty(bodyText)) {
        StringTokenizer bodyTk = new StringTokenizer(bodyText, "\n", false);
        JspWriter out = pageContext.getOut();

        try {
            if (this.para) {
                // wrap text in p
                while (bodyTk.hasMoreTokens()) {
                    out.write("<p>");
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    out.write("</p>");
                }
            } else {
                // add newlines
                while (bodyTk.hasMoreTokens()) {
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    if (bodyTk.hasMoreTokens()) {
                        out.write("<br/>");
                    }
                }
            }
        } catch (IOException e) {
            throw new JspTagException(e.getMessage());
        }
    }
    return EVAL_PAGE;
}