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

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

Introduction

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

Prototype

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

Source Link

Document

Replaces multiple characters in a String in one go.

Usage

From source file:org.dbgl.util.StringRelatedUtils.java

public static String join(final boolean[] values) {
    return StringUtils.replaceChars(Arrays.toString(values), "[,]", "");
}

From source file:org.fabrician.enabler.DockerContainer.java

private String getEngineUsername() throws Exception {
    String username = getEngineProperty(EngineProperties.USERNAME);
    username = StringUtils.replaceChars(username, '-', '_');
    return username;
}

From source file:org.fabrician.enabler.DockerContainer.java

private String getComponentName() {
    String componentName = getCurrentDomain().getName();
    if (componentName != null) {
        Iterable<String> parts = Splitter.on(" ").omitEmptyStrings().trimResults().split(componentName);
        Joiner joiner = Joiner.on("_").skipNulls();
        componentName = joiner.join(parts);
    }//ww  w  . j  a  va2s  . c o  m
    componentName = StringUtils.replaceChars(componentName, '-', '_');
    return componentName;
}

From source file:org.fourthline.cling.transport.impl.RecoverGENAEventProcessor.java

private String fixXMLEncodedLastChange(String xml) {
    Pattern pattern = Pattern.compile("<LastChange>(.*)</LastChange>", Pattern.DOTALL);
    Matcher matcher = pattern.matcher(xml);

    if (matcher.find() && matcher.groupCount() == 1) {

        String xmlEncodedLastChange = matcher.group(1);

        if (XmlPullParserUtils.isNullOrEmpty(xmlEncodedLastChange))
            return xml;

        xmlEncodedLastChange = xmlEncodedLastChange.trim();

        String fixedXmlEncodedLastChange;

        // first look if LastChange text is XML encoded (some renderers will sent it not XML encoded)
        if (xmlEncodedLastChange.charAt(0) == '<') {
            fixedXmlEncodedLastChange = StringEscapeUtils.escapeXml(xmlEncodedLastChange);
            log.warning("fixed LastChange that was not XML encoded");
        } else {/*ww  w.j a va  2  s.c  o m*/
            // delete potential funky characters (at least found in the Philips NP2900 that inserts garbage HTML)
            fixedXmlEncodedLastChange = StringUtils.replaceChars(xmlEncodedLastChange, "<>", null);
            if (fixedXmlEncodedLastChange.equals(xmlEncodedLastChange)) {
                // no change
                return xml;
            }

            log.warning("deleted invalid characters in LastChange");
        }

        String fixedXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                + "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">" + "<e:property>" + "<LastChange>"
                + fixedXmlEncodedLastChange + "</LastChange>" + "</e:property>" + "</e:propertyset>";

        return fixedXml;

    }

    return xml;
}

From source file:org.kalypso.ogc.gml.serialize.test.GmlTriSurface2HmoConverterTest.java

private void assertContentEquals(final File file, final URL location) throws IOException {
    final String fileContent = FileUtils.readFileToString(new File(file.getAbsolutePath()));
    final String urlContent = UrlUtilities.toString(location, Charset.defaultCharset().name());

    final String fileContentClean = StringUtils.replaceChars(fileContent, "\r", null); //$NON-NLS-1$
    final String urlContentClean = StringUtils.replaceChars(urlContent, "\r", null); //$NON-NLS-1$

    assertEquals(fileContentClean, urlContentClean);
}

From source file:org.kuali.coeus.common.impl.print.PrintingServiceImpl.java

protected void logPrintDetails(Map<String, byte[]> xmlStreamMap) throws PrintingException {
    byte[] xmlBytes = null;
    String xmlString = null;/*from   w w  w  .j  av  a2  s  .c om*/
    String loggingDirectory = kualiConfigurationService
            .getPropertyValueAsString(Constants.PRINT_LOGGING_DIRECTORY);
    Iterator<String> it = xmlStreamMap.keySet().iterator();
    if (loggingDirectory != null) {
        BufferedWriter out = null;
        try {
            while (it.hasNext()) {
                String key = (String) it.next();
                xmlBytes = xmlStreamMap.get(key);
                xmlString = new String(xmlBytes);
                String dateString = getDateTimeService().getCurrentTimestamp().toString();
                String reportName = StringUtils.deleteWhitespace(key);
                String createdTime = StringUtils.replaceChars(StringUtils.deleteWhitespace(dateString), ":",
                        "_");
                File dir = new File(loggingDirectory);
                if (!dir.exists() || !dir.isDirectory()) {
                    dir.mkdirs();
                }
                File file = new File(dir, reportName + createdTime + ".xml");

                out = new BufferedWriter(new FileWriter(file));
                out.write(xmlString);
            }
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        } finally {
            try {
                if (out != null) {
                    out.flush();
                    out.close();
                }
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }
}

From source file:org.kuali.coeus.propdev.impl.budget.subaward.PropDevPropDevBudgetSubAwardServiceImpl.java

protected String cleanContentId(String contentId) {
    return StringUtils.replaceChars(contentId, " .%-_", "");
}

From source file:org.kuali.coeus.propdev.impl.s2s.S2sSubmissionServiceImpl.java

public File getGrantsGovSavedFile(ProposalDevelopmentDocument pdDoc) throws IOException {

    String loggingDirectory = s2SConfigurationService
            .getValueAsString(ConfigurationConstants.PRINT_XML_DIRECTORY);
    String opportunityId = pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityId();
    String proposalnumber = pdDoc.getDevelopmentProposal().getProposalNumber();
    String exportDate = StringUtils
            .replaceChars((pdDoc.getDevelopmentProposal().getUpdateTimestamp().toString()), ":", "_");
    exportDate = StringUtils.replaceChars(exportDate, " ", ".");

    if (StringUtils.isNotBlank(loggingDirectory)) {
        File directory = new File(loggingDirectory);
        if (!directory.exists()) {
            directory.createNewFile();/*  ww  w .j a  v  a  2 s  .c o  m*/
        }
        return new File(loggingDirectory + opportunityId + "." + proposalnumber + "." + exportDate + ".zip");
    } else {
        return null;
    }

}

From source file:org.kuali.coeus.s2sgen.impl.print.FormPrintServiceImpl.java

protected void saveGrantsGovXml(ProposalDevelopmentDocumentContract pdDoc, boolean formEntryFlag,
        XmlObject formObject, List<AttachmentData> attachmentList,
        List<? extends S2sAppAttachmentsContract> attachmentLists) throws Exception {
    String loggingDirectory = s2SConfigurationService
            .getValueAsString(ConfigurationConstants.PRINT_XML_DIRECTORY);
    String opportunityId = pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityId();
    String proposalnumber = pdDoc.getDevelopmentProposal().getProposalNumber();
    String exportDate = StringUtils
            .replaceChars((pdDoc.getDevelopmentProposal().getUpdateTimestamp().toString()), ":", "_");
    exportDate = StringUtils.replaceChars(exportDate, " ", ".");

    File grantsGovXmlDirectoryFile = new File(
            loggingDirectory + opportunityId + "." + proposalnumber + "." + exportDate);
    if (!grantsGovXmlDirectoryFile.exists() || formEntryFlag) {
        grantsGovXmlDirectoryFile.mkdir();
    }//from  w ww  .j a va  2s .c  om

    for (AttachmentData attachmentData : attachmentList) {
        File attachmentFile = new File(grantsGovXmlDirectoryFile, "Attachments");
        attachmentFile.mkdir();
        File attachedFile = new File(attachmentFile, attachmentData.getFileName());
        try (FileOutputStream output = new FileOutputStream(attachedFile)) {
            output.write(attachmentData.getContent());
        }
    }
    for (S2sAppAttachmentsContract attAppAttachments : attachmentLists) {
        File attachmentFile = new File(grantsGovXmlDirectoryFile, "Attachments");
        attachmentFile.mkdir();
        KcFile ads = getAttributeContent(pdDoc, attAppAttachments.getContentId());
        File attachedFile = new File(attachmentFile, ads.getName());
        try (FileOutputStream output = new FileOutputStream(attachedFile)) {
            output.write(getAttContent(pdDoc, attAppAttachments.getContentId()));
        }
    }
    File xmlFile = new File(grantsGovXmlDirectoryFile,
            opportunityId + "." + proposalnumber + "." + exportDate + ".xml");
    try (BufferedWriter out = new BufferedWriter(new FileWriter(xmlFile))) {
        out.write(formObject.xmlText());
    }

    try (FileOutputStream fileOutputStream = new FileOutputStream(grantsGovXmlDirectoryFile + ".zip");
            ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream)) {
        addFolderToZip("", grantsGovXmlDirectoryFile.getPath(), zipOutputStream);
        zipOutputStream.flush();
    }

}

From source file:org.kuali.coeus.s2sgen.impl.print.S2SPrintingServiceImpl.java

protected void logPrintDetails(Map<String, byte[]> xmlStreamMap) {
    String loggingDirectory = s2SConfigurationService
            .getValueAsString(ConfigurationConstants.PRINT_LOGGING_DIRECTORY);
    if (loggingDirectory != null) {

        for (String key : xmlStreamMap.keySet()) {
            byte[] xmlBytes = xmlStreamMap.get(key);
            String xmlString = new String(xmlBytes);
            String dateString = new Timestamp(new Date().getTime()).toString();
            String reportName = StringUtils.deleteWhitespace(key);
            String createdTime = StringUtils.replaceChars(StringUtils.deleteWhitespace(dateString), ":", "_");
            File dir = new File(loggingDirectory);
            if (!dir.exists() || !dir.isDirectory()) {
                dir.mkdirs();//  ww  w .ja va  2s  . com
            }
            File file = new File(dir, reportName + createdTime + ".xml");
            try (BufferedWriter out = new BufferedWriter(new FileWriter(file))) {
                out.write(xmlString);
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }
}