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

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

Introduction

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

Prototype

public static String replace(String text, String searchString, String replacement) 

Source Link

Document

Replaces all occurrences of a String within another String.

Usage

From source file:com.sfs.whichdoctor.xml.writer.GroupXmlWriter.java

/**
 * Output the group as an XML string.//from  ww w. ja  v  a2 s. c o m
 *
 * @param group the group
 *
 * @return the xml string
 */
public static String getGroupXml(final GroupBean group) {

    final XmlWriter xmlwriter = new XmlWriter();

    xmlwriter.writeEntity("group").writeAttribute("GUID", group.getGUID()).writeAttribute("groupId",
            group.getId());

    xmlwriter.writeXml(HistoryXmlHelper.getHistoryXml(group));

    xmlwriter.writeEntity("name").writeText(group.getName()).endEntity();
    xmlwriter.writeEntity("description").writeXml(StringUtils.replace(group.getDescription(), "\n", "<br />"))
            .endEntity();

    xmlwriter.writeEntity("type").writeText(group.getType()).endEntity();

    // Process memos
    if (group.getMemo() != null) {
        xmlwriter.writeXml(MemoXmlHelper.getMemosXml(group.getMemo()));
    }

    // Get list of Employees
    int commentReference = 1;
    if (group.getItems() != null) {
        xmlwriter.writeEntity("items");
        for (String itemIndex : group.getItems().keySet()) {
            ItemBean item = group.getItems().get(itemIndex);
            if (item != null) {
                xmlwriter.writeEntity("item").writeAttribute("refguid", item.getObject2GUID());
                xmlwriter.writeEntity("name").writeText(item.getName()).endEntity();

                if (item.getStartDate() != null) {
                    xmlwriter.writeEntity("startDate").writeText(Formatter.convertDate(item.getStartDate()))
                            .endEntity();
                }

                if (item.getEndDate() != null) {
                    xmlwriter.writeEntity("endDate").writeText(Formatter.convertDate(item.getEndDate()))
                            .endEntity();
                }

                if (item.getTitle() != null) {
                    xmlwriter.writeEntity("title").writeText(item.getTitle()).endEntity();
                }

                if (item.getComment() != null) {
                    if (item.getComment().compareTo("") != 0) {
                        xmlwriter.writeEntity("comment");
                        xmlwriter.writeAttribute("commentId", String.valueOf(commentReference));
                        xmlwriter.writeXml(StringUtils.replace(item.getComment(), "\n", "<br />")).endEntity();
                        commentReference += 1;
                    }
                }
                xmlwriter.writeEntity("weighting").writeText(item.getWeighting()).endEntity();

                if (item.getIdentity() != null) {
                    // Output the identity information for this item
                    WhichDoctorCoreIdentityBean identity = item.getIdentity();

                    // Process addresses
                    if (identity.getAddress().size() > 0) {
                        xmlwriter.writeXml(AddressXmlHelper.getAddressesXml(identity.getAddress()));
                    }
                    // Process phones
                    if (identity.getPhone().size() > 0) {
                        xmlwriter.writeXml(PhoneXmlHelper.getPhonesXml(identity.getPhone()));
                    }
                    // Process emails
                    if (identity.getEmail().size() > 0) {
                        xmlwriter.writeXml(EmailXmlHelper.getEmailsXml(identity.getEmail()));
                    }
                }
                xmlwriter.endEntity();
            }
        }
        xmlwriter.endEntity();
    }
    xmlwriter.endEntity();

    return xmlwriter.getXml();
}

From source file:ams.fwk.customtag.AmsExcelExportTag.java

/**
 * @return int//from w  ww . ja  v a 2 s.  c om
 * @throws JspException
 */
public int doEndTag() throws JspException {
    try {
        JspWriter out = pageContext.getOut();
        out.print(listOpen);
        StringBuffer sb = new StringBuffer();
        sb.append(StringUtils.replace(excelTxTag, "$transactionId$", transactionId));
        sb.append(excelResTag);
        sb.append(StringUtils.replace(exportFileInfoTag, "$exportFileName$", exportFileName));

        out.print(sb.toString());

        out.print(listClose);

        return EVAL_PAGE;
    } catch (IOException e) {
        throw new JspException(e);
    } finally {

    }
}

From source file:cn.vlabs.duckling.vwb.ui.accclb.AttSaver.java

public void save(String filename, InputStream in) {
    try {//from   w  ww  .  ja  v  a 2  s.  com
        filename = java.net.URLDecoder.decode(filename, "UTF-8");
        String mimetype = getMimeType(m_req, filename);
        m_res.setContentType(mimetype);
        String agent = m_req.getHeader("USER-AGENT");

        String suffix = filename.substring(filename.indexOf(".") + 1, filename.length());

        m_res.setContentType(MimeType.getContentType(suffix));
        if (filename.indexOf("swf") != -1) {
            m_res.setContentType("application/x-shockwave-flash");
        } else {
            if (null != agent && -1 != agent.indexOf("MSIE")) {

                String codedfilename = java.net.URLEncoder.encode(filename, "UTF-8");
                codedfilename = StringUtils.replace(codedfilename, "+", "%20");
                if (codedfilename.length() > 150) {
                    codedfilename = new String(filename.getBytes("GBK"), "ISO8859-1");
                    codedfilename = StringUtils.replace(codedfilename, " ", "%20");
                }
                m_res.setHeader("Content-Disposition", "attachment;filename=\"" + codedfilename + "\"");
            } else if (null != agent && -1 != agent.indexOf("Firefox")) {
                String codedfilename = javax.mail.internet.MimeUtility.encodeText(filename, "UTF-8", "B");

                m_res.setHeader("Content-Disposition", "attachment;filename=\"" + codedfilename + "\"");
            } else {
                String codedfilename = java.net.URLEncoder.encode(filename, "UTF-8");
                m_res.setHeader("Content-Disposition", "attachment;filename=\"" + codedfilename + "\"");
            }
        }

        if (out == null)
            out = m_res.getOutputStream();
        int read = 0;
        byte buf[] = new byte[4096];
        while ((read = in.read(buf, 0, 4096)) != -1) {
            out.write(buf, 0, read);
        }
        if (out != null) {
            out.close();
        }
    } catch (IOException e) {
        log.info(String.format("Client %s aborted while download file %s, error message:%s",
                m_req.getRemoteAddr(), filename, e.getMessage()));
    }
}

From source file:cec.easyshop.storefront.web.wrappers.UrlEncodeHttpRequestWrapper.java

@Override
public String getServletPath() {
    final String originalServletPath = super.getServletPath();
    if (("/").equals(originalServletPath) || ("/" + pattern).equals(originalServletPath)
            || ("/" + pattern + "/").equals(originalServletPath)) {
        return "";
    } else if (urlPatternChecker(originalServletPath, pattern)) {
        return StringUtils.replace(originalServletPath, "/" + pattern + "/", "/");
    }/*from   w  ww. j  a va  2s.  c om*/
    return originalServletPath;
}

From source file:jetbrick.tools.chm.style.Javadoc8Style.java

@Override
public String getMethodFullName(String url) {
    String name = StringUtils.substringAfter(url, "#");
    int count = StringUtils.countMatches(name, "-");
    name = StringUtils.replaceOnce(name, "-", "(");
    for (int i = 0; i < count - 2; i++) {
        name = StringUtils.replaceOnce(name, "-", ", ");
    }//from  w  w w  . j  a  v  a2  s. co m
    name = StringUtils.replaceOnce(name, "-", ")");
    name = StringUtils.replace(name, ":A", "[]");
    return name;
}

From source file:io.kamax.mxisd.config.ServerConfig.java

@PostConstruct
public void build() {
    log.info("--- Server config ---");

    if (StringUtils.isBlank(getName())) {
        setName(mxCfg.getDomain());/*from   w w  w.j ava 2 s  .c  o m*/
        log.debug("server.name is empty, using matrix.domain");
    }

    if (StringUtils.isBlank(getPublicUrl())) {
        setPublicUrl("https://" + getName());
        log.debug("Public URL is empty, generating from name");
    } else {
        setPublicUrl(StringUtils.replace(getPublicUrl(), "%SERVER_NAME%", getName()));
    }

    try {
        new URL(getPublicUrl());
    } catch (MalformedURLException e) {
        log.warn("Public URL is not valid: {}",
                StringUtils.defaultIfBlank(e.getMessage(), "<no reason provided>"));
    }

    log.info("Name: {}", getName());
    log.info("Port: {}", getPort());
    log.info("Public URL: {}", getPublicUrl());
}

From source file:com.sfs.whichdoctor.beans.OnlineApplicationBean.java

/**
 * Try parsing the XML document and setting the relevant online application
 * attributes e.g. key, content/*from ww w .jav  a 2s.  c o  m*/
 *
 * @param xmlApplicationVal the xml payload
 *
 * @throws JDOMException the JDOM exception
 */
public final void parseXmlApplication(final String xmlApplicationVal) throws JDOMException {
    // Ensure there are no "& " characters
    String xmlApplication = StringUtils.replace(xmlApplicationVal, "&gt;", "|gt;");
    xmlApplication = StringUtils.replace(xmlApplication, "&lt;", "|lt;");
    xmlApplication = StringUtils.replace(xmlApplication, "&amp;", "|amp;");
    // Replace the & characters left
    xmlApplication = StringUtils.replace(xmlApplication, "&", "&amp;");
    // Bring the special characters back
    xmlApplication = StringUtils.replace(xmlApplication, "|gt;", "&gt;");
    xmlApplication = StringUtils.replace(xmlApplication, "|lt;", "&lt;");
    xmlApplication = StringUtils.replace(xmlApplication, "|amp;", "&amp;");

    if (xmlApplication.startsWith("<?xml ")) {
        xmlApplication = StringUtils.replace(xmlApplication, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
    }

    // Parse the online application XML document to get the identifier
    final SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
    final Reader stringReader = new StringReader(xmlApplication);
    Document applicationDocument = null;
    try {
        applicationDocument = saxBuilder.build(stringReader);
    } catch (JDOMException e) {
        // Error parsing the XML document
        throw new JDOMException(
                "Error parsing online application XML: " + e.getMessage() + "\n" + xmlApplication);
    } catch (IOException e) {
        // Error parsing the XML document
        throw new JDOMException("Error reading online application XML string: " + e.getMessage());
    }

    if (applicationDocument != null) {
        // Get the key for this application
        try {
            this.setKey(applicationDocument.getRootElement().getChild("applicationkey").getValue());
        } catch (NullPointerException npe) {
            throw new JDOMException("The applicationkey element does not exist");
        }
        // Get the first name for this application
        try {
            this.setFirstName(applicationDocument.getRootElement().getChild("personaldetails")
                    .getChild("firstname").getValue());
        } catch (NullPointerException npe) {
            throw new JDOMException("The firstname element does not exist");
        }

        // Get the last name for this application
        try {
            this.setLastName(applicationDocument.getRootElement().getChild("personaldetails")
                    .getChild("lastname").getValue());
        } catch (NullPointerException npe) {
            throw new JDOMException("The lastname element does not exist");
        }

        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());

        this.applicationXml = outputter.outputString(applicationDocument);

    } else {
        throw new JDOMException("The parsed application XML document was null");
    }
}

From source file:com.flexive.tests.embedded.benchmark.logger.HudsonPlotLogger.java

@Override
protected void logResult(String name, double time, String measurement, String unit) {
    super.logResult(name, time, measurement, unit);
    final String filename = OUTPUT_DIRECTORY + File.separator + StringUtils.replace(name, File.separator, "_")
            + ".properties";
    if (!new File(OUTPUT_DIRECTORY).exists() && !new File(OUTPUT_DIRECTORY).mkdirs()) {
        LOG.warn("Failed to create output directory " + OUTPUT_DIRECTORY);
        return;/*  www.ja v  a  2  s.  co  m*/
    }
    FileWriter fw = null;
    try {
        fw = new FileWriter(new File(filename));
        fw.write("YVALUE=" + time + "\n");
    } catch (IOException e) {
        LOG.error("Failed to write result file: " + e.getMessage(), e);
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException e) {
                LOG.error("Failed to close file: " + e.getMessage(), e);
            }
        }
    }
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.ComponentNameField.java

protected IStatus nameChanged() {
    SpindleStatus status = new SpindleStatus();
    String name = getTextValue();
    if ("".equals(name)) {
        status.setError("");
        return status;
    }/*  ww w . j  a  v a2  s .com*/
    if (name.indexOf('.') != -1) {
        status.setError(UIPlugin.getString(fName + ".error.QualifiedName"));
        return status;
    }

    IStatus val = JavaConventions.validateJavaTypeName(name);
    if (!val.isOK()) {
        if (val.getSeverity() == IStatus.ERROR) {
            String message = val.getMessage();
            message = StringUtils.replace(message, "type", "");
            status.setError(UIPlugin.getString(fName + ".error.InvalidComponentName", message));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            String message = val.getMessage();
            message = StringUtils.replace(message, "Java", "Tapestry");
            message = StringUtils.replace(message, "type", "component/page");
            status.setWarning(UIPlugin.getString(fName + ".warning.ComponentNameDiscouraged", name, message));
            return status;
        }
    }
    char first = name.charAt(0);
    if (Character.isLowerCase(first)) {
        status.setWarning(UIPlugin.getString(fName + ".warning.ComponentNameDiscouraged",
                "first character is lowercase"));
    }

    return status;
}

From source file:net.kamhon.ieagle.dao.AbstractJdbcDao.java

public String replace(String sql) {
    if (StringUtils.isNotBlank(fromSchema) && StringUtils.isNotBlank(toSchema)) {
        sql = StringUtils.replace(sql, fromSchema, toSchema);
    }//from  w ww . jav  a2s .  co  m
    return sql;
}