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

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

Introduction

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

Prototype

public static String deleteWhitespace(String str) 

Source Link

Document

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

Usage

From source file:org.eclipse.skalli.core.destination.DestinationComponent.java

private void setProxy(HttpClient client, URL url) {
    if (isLocalDomain(url)) {
        return;/*w  w w .j  av a  2s . c om*/
    }

    String protocol = url.getProtocol();

    // use the system properties as default
    String defaultProxyHost = System.getProperty(HTTP_PROXY_HOST);
    String defaultProxyPort = System.getProperty(HTTP_PROXY_PORT);
    String proxyHost = HTTPS.equals(protocol) ? System.getProperty(HTTPS_PROXY_HOST, defaultProxyHost)
            : defaultProxyHost;
    int proxyPort = NumberUtils.toInt(
            HTTPS.equals(protocol) ? System.getProperty(HTTPS_PROXY_PORT, defaultProxyPort) : defaultProxyPort);
    String nonProxyHosts = System.getProperty(NON_PROXY_HOSTS, StringUtils.EMPTY);

    // allow to overwrite the system properties with configuration /api/config/proxy
    if (configService != null) {
        ProxyConfig proxyConfig = configService.readConfiguration(ProxyConfig.class);
        if (proxyConfig != null) {
            String defaultConfigProxyHost = proxyConfig.getHost();
            String defaultConfigProxyPort = proxyConfig.getPort();
            String configProxyHost = HTTPS.equals(protocol) ? proxyConfig.getHostSSL() : defaultConfigProxyHost;
            int configProxyPort = NumberUtils
                    .toInt(HTTPS.equals(protocol) ? proxyConfig.getPortSSL() : defaultConfigProxyPort);
            if (StringUtils.isNotBlank(configProxyHost) && configProxyPort > 0) {
                proxyHost = configProxyHost;
                proxyPort = configProxyPort;
            }
            String configNonProxyHosts = proxyConfig.getNonProxyHosts();
            if (StringUtils.isNotBlank(configNonProxyHosts)) {
                nonProxyHosts = configNonProxyHosts;
            }
        }
    }

    // sanitize the nonProxyHost pattern (remove whitespace etc.)
    if (StringUtils.isNotBlank(nonProxyHosts)) {
        nonProxyHosts = StringUtils.replaceEach(StringUtils.deleteWhitespace(nonProxyHosts), RE_SEARCH,
                RE_REPLACE);
    }

    if (StringUtils.isNotBlank(proxyHost) && proxyPort > 0 && !Pattern.matches(nonProxyHosts, url.getHost())) {
        HttpHost proxy = new HttpHost(proxyHost, proxyPort, HTTP);
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
}

From source file:org.efs.openreports.actions.JXLSReportAction.java

public String execute() {
    ReportUser user = (ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER);

    report = (Report) ActionContext.getContext().getSession().get(ORStatics.REPORT);

    Map parameters = getReportParameterMap(user);

    ReportLog reportLog = new ReportLog(user, report, new Date());

    Connection conn = null;//from  ww  w . j  ava2 s . co  m

    try {
        log.debug("Starting JXLS Report: " + report.getName());

        reportLogProvider.insertReportLog(reportLog);

        ReportEngineInput input = new ReportEngineInput(report, parameters);

        JXLSReportEngine reportEngine = new JXLSReportEngine(dataSourceProvider, directoryProvider,
                propertiesProvider);

        ReportEngineOutput output = reportEngine.generateReport(input);

        HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition",
                "inline; filename=" + StringUtils.deleteWhitespace(report.getName()) + ".xls");

        ServletOutputStream out = response.getOutputStream();

        out.write(output.getContent(), 0, output.getContent().length);

        out.flush();
        out.close();

        reportLog.setEndTime(new Date());
        reportLog.setStatus(ReportLog.STATUS_SUCCESS);
        reportLogProvider.updateReportLog(reportLog);

        log.debug("Finished JRXLS Report: " + report.getName());
    } catch (Exception e) {
        addActionError(e.getMessage());

        log.error(e.getMessage());

        reportLog.setMessage(e.getMessage());
        reportLog.setStatus(ReportLog.STATUS_FAILURE);

        reportLog.setEndTime(new Date());

        try {
            reportLogProvider.updateReportLog(reportLog);
        } catch (Exception ex) {
            log.error("Unable to create ReportLog: " + ex.getMessage());
        }

        return ERROR;
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception c) {
            log.error("Error closing");
        }
    }

    return NONE;
}

From source file:org.efs.openreports.actions.ReportRunAction.java

public String execute() {
    ReportUser user = (ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER);

    Report report = (Report) ActionContext.getContext().getSession().get(ORStatics.REPORT);

    int exportType = Integer
            .parseInt((String) ActionContext.getContext().getSession().get(ORStatics.EXPORT_TYPE));

    Map reportParameters = getReportParameterMap(user, report, exportType);
    Map imagesMap = getImagesMap();

    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();

    // set headers to disable caching      
    response.setHeader("Pragma", "public");
    response.setHeader("Cache-Control", "max-age=0");

    ReportLog reportLog = new ReportLog(user, report, new Date());

    JRVirtualizer virtualizer = null;/*from w w  w . ja v  a 2s  . c  o m*/

    try {
        if (exportType == ReportEngine.EXPORT_PDF) {
            // Handle "contype" request from Internet Explorer
            if ("contype".equals(request.getHeader("User-Agent"))) {
                response.setContentType("application/pdf");
                response.setContentLength(0);

                ServletOutputStream outputStream = response.getOutputStream();
                outputStream.close();

                return NONE;
            }
        }

        log.debug("Filling report: " + report.getName());

        reportLogProvider.insertReportLog(reportLog);

        if (report.isVirtualizationEnabled() && exportType != ReportEngine.EXPORT_IMAGE) {
            log.debug("Virtualization Enabled");
            virtualizer = new JRFileVirtualizer(2, directoryProvider.getTempDirectory());
            reportParameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
        }

        ReportEngineInput reportInput = new ReportEngineInput(report, reportParameters);
        reportInput.setExportType(exportType);
        reportInput.setImagesMap(imagesMap);

        // add any charts
        if (report.getReportChart() != null) {
            log.debug("Adding chart: " + report.getReportChart().getName());

            ChartReportEngine chartEngine = new ChartReportEngine(dataSourceProvider, directoryProvider,
                    propertiesProvider);

            ChartEngineOutput chartOutput = (ChartEngineOutput) chartEngine.generateReport(reportInput);

            reportParameters.put("ChartImage", chartOutput.getContent());
        }

        ReportEngineOutput reportOutput = null;
        JasperPrint jasperPrint = null;

        if (report.isJasperReport()) {
            JasperReportEngine jasperEngine = new JasperReportEngine(dataSourceProvider, directoryProvider,
                    propertiesProvider);

            jasperPrint = jasperEngine.fillReport(reportInput);

            log.debug("Report filled - " + report.getName() + " : size = " + jasperPrint.getPages().size());

            log.debug("Exporting report: " + report.getName());

            reportOutput = jasperEngine.exportReport(jasperPrint, exportType, report.getReportExportOption(),
                    imagesMap, false);
        } else {
            ReportEngine reportEngine = ReportEngineHelper.getReportEngine(report, dataSourceProvider,
                    directoryProvider, propertiesProvider);
            reportOutput = reportEngine.generateReport(reportInput);
        }

        response.setContentType(reportOutput.getContentType());

        if (exportType != ReportEngine.EXPORT_HTML && exportType != ReportEngine.EXPORT_IMAGE) {
            response.setHeader("Content-disposition", "inline; filename="
                    + StringUtils.deleteWhitespace(report.getName()) + reportOutput.getContentExtension());
        }

        if (exportType == ReportEngine.EXPORT_IMAGE) {
            if (jasperPrint != null) {
                ActionContext.getContext().getSession().put(ORStatics.JASPERPRINT, jasperPrint);
            }
        } else {
            byte[] content = reportOutput.getContent();

            response.setContentLength(content.length);

            ServletOutputStream out = response.getOutputStream();
            out.write(content, 0, content.length);
            out.flush();
            out.close();
        }

        reportLog.setEndTime(new Date());
        reportLog.setStatus(ReportLog.STATUS_SUCCESS);
        reportLogProvider.updateReportLog(reportLog);

        log.debug("Finished report: " + report.getName());
    } catch (Exception e) {
        if (e.getMessage() != null && e.getMessage().indexOf("Empty") > 0) {
            addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_EMPTY));
            reportLog.setStatus(ReportLog.STATUS_EMPTY);
        } else {
            addActionError(e.getMessage());

            log.error(e.getMessage());

            reportLog.setMessage(e.getMessage());
            reportLog.setStatus(ReportLog.STATUS_FAILURE);
        }

        reportLog.setEndTime(new Date());

        try {
            reportLogProvider.updateReportLog(reportLog);
        } catch (Exception ex) {
            log.error("Unable to create ReportLog: " + ex.getMessage());
        }

        return ERROR;
    } finally {
        if (virtualizer != null) {
            reportParameters.remove(JRParameter.REPORT_VIRTUALIZER);
            virtualizer.cleanup();
        }
    }

    if (exportType == ReportEngine.EXPORT_IMAGE)
        return SUCCESS;

    return NONE;
}

From source file:org.efs.openreports.delivery.EMailDeliveryMethod.java

protected ByteArrayDataSource exportReport(ReportEngineOutput reportOutput, ReportSchedule reportSchedule,
        ArrayList<ByteArrayDataSource> htmlImageDataSources) {
    String reportName = StringUtils.deleteWhitespace(reportSchedule.getReport().getName());

    ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(reportOutput.getContent(),
            reportOutput.getContentType());
    byteArrayDataSource.setName(reportName + reportOutput.getContentExtension());

    if (reportSchedule.getExportType() == ExportType.HTML.getCode()) {
        Map imagesMap = ((JasperReportEngineOutput) reportOutput).getImagesMap();

        for (Iterator entryIter = imagesMap.entrySet().iterator(); entryIter.hasNext();) {
            Map.Entry entry = (Map.Entry) entryIter.next();

            ByteArrayDataSource imageDataSource = new ByteArrayDataSource((byte[]) entry.getValue(),
                    getImageContentType((byte[]) entry.getValue()));

            imageDataSource.setName((String) entry.getKey());

            htmlImageDataSources.add(imageDataSource);
        }//  www  . j  a  va2 s . co  m
    }

    return byteArrayDataSource;
}

From source file:org.efs.openreports.delivery.FileSystemDeliveryMethod.java

public void deliverReport(ReportSchedule reportSchedule, ReportEngineOutput reportOutput)
        throws DeliveryException {
    Report report = reportSchedule.getReport();
    ReportUser user = reportSchedule.getUser();

    Date runDate = new Date();

    String fileName = runDate.getTime() + "-" + StringUtils.deleteWhitespace(user.getName()) + "-"
            + StringUtils.deleteWhitespace(report.getName());

    try {/*w  w w  . j av  a 2  s.  com*/
        FileOutputStream file = new FileOutputStream(directoryProvider.getReportGenerationDirectory() + fileName
                + reportOutput.getContentExtension());

        file.write(reportOutput.getContent());
        file.flush();
        file.close();
    } catch (IOException ioe) {
        throw new DeliveryException(ioe);
    }

    DeliveredReport info = new DeliveredReport();
    info.setParameters(reportSchedule.getReportParameters());
    info.setReportDescription(reportSchedule.getScheduleDescription());
    info.setReportName(report.getName());
    info.setReportFileName(fileName + reportOutput.getContentExtension());
    info.setRunDate(runDate);
    info.setUserName(user.getName());
    info.setDeliveryMethod("fileSystemDeliveryMethod");

    try {
        FileOutputStream file = new FileOutputStream(
                directoryProvider.getReportGenerationDirectory() + fileName + ".xml");

        XStream xStream = new XStream();
        xStream.alias("reportGenerationInfo", DeliveredReport.class);
        xStream.toXML(info, file);

        file.flush();
        file.close();
    } catch (IOException ioe) {
        throw new DeliveryException(ioe);
    }

    MailMessage mail = new MailMessage();
    mail.setSender(user.getEmail());
    mail.parseRecipients(reportSchedule.getRecipients());
    mail.setText(report.getName() + ": Generated on " + new Date());
    mail.setBounceAddress(reportSchedule.getDeliveryReturnAddress());

    if (reportSchedule.getScheduleDescription() != null
            && reportSchedule.getScheduleDescription().trim().length() > 0) {
        mail.setSubject(reportSchedule.getScheduleDescription());
    } else {
        mail.setSubject(reportSchedule.getReport().getName());
    }

    try {
        mailProvider.sendMail(mail);
    } catch (ProviderException pe) {
        throw new DeliveryException(pe);
    }

    log.debug(report.getName() + " written to: " + fileName);
}

From source file:org.efs.openreports.services.servlet.ReportServiceServlet.java

protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {// w w w . j a  va2s  .  c o m
        ServletReportServiceInput reportInput = buildReportServiceInput(request);
        reportInput.setParameterMap(request.getParameterMap());

        ReportEngineOutput reportOutput = reportService.generateReport(reportInput);

        if (reportOutput instanceof QueryEngineOutput) {
            QueryEngineOutput queryReport = (QueryEngineOutput) reportOutput;

            request.getSession().setAttribute("properties", queryReport.getProperties());
            request.getSession().setAttribute("results", queryReport.getResults());
            request.getSession().setAttribute("reportName",
                    StringUtils.deleteWhitespace(reportInput.getReportName()));

            response.sendRedirect("report-viewer/query-report.jsp");

            //getServletContext().getRequestDispatcher("/report-viewer/query-report.jsp").forward(request, response);

            return;
        }

        ServletOutputStream out = response.getOutputStream();

        if (reportOutput.getContent() != null) {
            if (reportInput.getExportType() != ReportEngine.EXPORT_HTML) {
                response.setContentType(reportOutput.getContentType());
                response.setContentLength(reportOutput.getContent().length);
                response.setHeader("Content-disposition",
                        "inline; filename=" + StringUtils.deleteWhitespace(reportInput.getReportName())
                                + reportOutput.getContentExtension());
            }

            out.write(reportOutput.getContent(), 0, reportOutput.getContent().length);
        } else {
            out.write(reportOutput.getContentMessage().getBytes());
        }

        out.flush();
        out.close();
    } catch (Exception e) {
        response.getOutputStream().write(e.toString().getBytes());
    }
}

From source file:org.efs.openreports.util.ScheduledReportJob.java

protected ByteArrayDataSource exportReport(ReportEngineOutput reportOutput, ReportSchedule reportSchedule,
        Vector htmlImageDataSources) throws JRException {
    String reportName = StringUtils.deleteWhitespace(reportSchedule.getReport().getName());

    ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(reportOutput.getContent(),
            reportOutput.getContentType());
    byteArrayDataSource.setName(reportName + reportOutput.getContentExtension());

    if (reportSchedule.getExportType() == ReportEngine.EXPORT_HTML
            && reportSchedule.getReport().isJasperReport()) {
        Map imagesMap = ((JasperReportEngineOutput) reportOutput).getImagesMap();

        for (Iterator entryIter = imagesMap.entrySet().iterator(); entryIter.hasNext();) {
            Map.Entry entry = (Map.Entry) entryIter.next();

            ByteArrayDataSource imageDataSource = new ByteArrayDataSource((byte[]) entry.getValue(),
                    getImageContentType((byte[]) entry.getValue()));

            imageDataSource.setName((String) entry.getKey());

            htmlImageDataSources.add(imageDataSource);
        }/*from  w w w . j  a v  a  2  s  .co m*/
    }

    return byteArrayDataSource;
}

From source file:org.fao.geonet.kernel.SchemaManager.java

/**
  * This method searches an entire metadata file for an element that matches the "needle" metadata element arg - A
  * matching element has the same name, namespace and value.
 *
 * @param needle the XML element we are trying to find
 * @param haystack the XML metadata record we are searching
 * @param checkValue compare the value of the needle with the value of the element we find in the md
  * @return//from  w  w w .  j a  v  a  2  s. c o m
  */
private boolean isMatchingElementInMetadata(Element needle, Element haystack, boolean checkValue) {
    boolean returnVal = false;
    Iterator<Element> haystackIterator = haystack.getDescendants(new ElementFilter());

    String needleName = needle.getName();
    Namespace needleNS = needle.getNamespace();
    if (Log.isDebugEnabled(Geonet.SCHEMA_MANAGER))
        Log.debug(Geonet.SCHEMA_MANAGER, "Matching " + Xml.getString(needle));

    while (haystackIterator.hasNext()) {
        Element tempElement = haystackIterator.next();

        if (tempElement.getName().equals(needleName) && tempElement.getNamespace().equals(needleNS)) {
            if (checkValue) {
                if (Log.isDebugEnabled(Geonet.SCHEMA_MANAGER))
                    Log.debug(Geonet.SCHEMA_MANAGER, "  Searching value for element: " + tempElement.getName());

                String needleVal = needle.getValue();
                String[] needleToken = StringUtils.deleteWhitespace(needleVal).split("\\|");
                String tempVal = StringUtils.deleteWhitespace(tempElement.getValue());

                for (String t : needleToken) {
                    Log.debug(Geonet.SCHEMA_MANAGER,
                            "    Comparing: '" + t + "' \n****with****\n '" + tempVal + "'");
                    if (tempVal != null && needleVal != null) {
                        returnVal = t.equals(tempVal);
                        if (returnVal) {
                            if (Log.isDebugEnabled(Geonet.SCHEMA_MANAGER))
                                Log.debug(Geonet.SCHEMA_MANAGER,
                                        "    Found value: " + t + " for needle: " + needleName);
                            break;
                        }
                    }
                }
            } else {
                returnVal = true;
                break;
            }
        }
    }
    return returnVal;
}

From source file:org.gbif.portal.web.util.QueryHelper.java

/**
 * Tidies the supplied query string removing multiple space chars.
 * @return//ww w  .  j  av a  2s.c o  m
 */
public static String tidyValue(String queryString) {
    if (StringUtils.isEmpty(queryString))
        return null;
    queryString = queryString.trim();
    StringTokenizer tokenizer = new StringTokenizer(queryString, " ");
    StringBuffer tidiedBuffer = new StringBuffer();
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        token = StringUtils.deleteWhitespace(token);
        tidiedBuffer.append(token);
        if (tokenizer.hasMoreTokens())
            tidiedBuffer.append(' ');
    }
    return tidiedBuffer.toString();
}

From source file:org.jasig.ssp.util.liquibase.MessageTemplateCheckSumPrecondition.java

@Override
public void check(Database database)
        throws CustomPreconditionFailedException, CustomPreconditionErrorException {

    if (StringUtils.isBlank(columnName))
        throw new CustomPreconditionErrorException("columnName is empty");
    if (StringUtils.isBlank(messageTemplateId))
        throw new CustomPreconditionErrorException("messageTemplateId is empty");

    final String query = "select " + columnName + " from message_template where id = '" + messageTemplateId
            + "'";
    String columnValue = processQuery(database, query);

    String currentChecksum = "";
    try {//from   ww w  .j av  a2  s . c o  m
        currentChecksum = getCheckSum(StringUtils.deleteWhitespace(columnValue));
    } catch (NoSuchAlgorithmException e) {
        throw new CustomPreconditionErrorException("Unable to calculate checksum");
    }

    final String defaultCheckSumQuery = "select " + columnName + "_checksum"
            + " from message_template where id = '" + messageTemplateId + "'";
    final String defaultCheckSum = processQuery(database, defaultCheckSumQuery);

    if (!defaultCheckSum.equals(currentChecksum))
        throw new CustomPreconditionFailedException("checkSums did not match for message template id: "
                + messageTemplateId + " and column" + columnName);
}