Search in sources :

Example 1 with TemporaryDataSource

use of org.santfeliu.util.TemporaryDataSource in project gdmatrix by gdmatrix.

the class MergeTransformer method transform.

@Override
public DataHandler transform(Document document, String transformationName, Map options) throws TransformationException {
    try {
        Content content = document.getContent();
        DataHandler data = content.getData();
        File file = IOUtils.writeToFile(data);
        File mergedFile = File.createTempFile("merged", ".odt");
        ODFUtils.merge(file, mergedFile, options);
        file.delete();
        DataHandler dh = new DataHandler(new TemporaryDataSource(mergedFile));
        return dh;
    } catch (Exception ex) {
        throw new TransformationException(ex);
    }
}
Also used : TransformationException(org.santfeliu.doc.transform.TransformationException) TemporaryDataSource(org.santfeliu.util.TemporaryDataSource) Content(org.matrix.doc.Content) DataHandler(javax.activation.DataHandler) File(java.io.File) TransformationException(org.santfeliu.doc.transform.TransformationException)

Example 2 with TemporaryDataSource

use of org.santfeliu.util.TemporaryDataSource in project gdmatrix by gdmatrix.

the class DocumentManager method markupContent.

@Override
public DataHandler markupContent(String contentId, String searchExpression) {
    try {
        logOperation("markupContent", "IN", "contentId=" + contentId + "&search=" + searchExpression);
        ContentStoreConnection conn = contentStore.getConnection();
        try {
            File file = conn.markupContent(contentId, searchExpression);
            TemporaryDataSource ds = new TemporaryDataSource(file);
            logOperation("markupContent", "OUT", ds.toString());
            return new DataHandler(ds);
        } catch (Exception ex) {
            conn.rollback();
            throw ex;
        } finally {
            conn.close();
        }
    } catch (Exception ex) {
        logOperation("markupContent", "FAULT", ex.getMessage());
        throw WSExceptionFactory.create(ex);
    }
}
Also used : TemporaryDataSource(org.santfeliu.util.TemporaryDataSource) ContentStoreConnection(org.santfeliu.doc.store.ContentStoreConnection) DataHandler(javax.activation.DataHandler) StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler) File(java.io.File) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException)

Example 3 with TemporaryDataSource

use of org.santfeliu.util.TemporaryDataSource in project gdmatrix by gdmatrix.

the class JasperReportEngine method exportReport.

private DataSource exportReport(JasperPrint print, ExportOptions exportOptions) throws Exception {
    DataSource ds = null;
    String format = exportOptions.getFormat().toUpperCase();
    if ("PDF".equals(format)) {
        File file = File.createTempFile("out", ".pdf");
        ds = new TemporaryDataSource(file, "application/pdf");
        OutputStream os = ds.getOutputStream();
        try {
            JasperExportManager.exportReportToPdfStream(print, os);
            os.flush();
        } finally {
            os.close();
        }
    } else if ("RTF".equals(format)) {
        File file = File.createTempFile("out", ".rtf");
        ds = new TemporaryDataSource(file, "application/rtf");
        OutputStream os = ds.getOutputStream();
        try {
            JRRtfExporter exporter = new JRRtfExporter();
            exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, print);
            exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, os);
            exporter.exportReport();
            os.flush();
        } finally {
            os.close();
        }
    } else if ("CSV".equals(format)) {
        File file = File.createTempFile("out", ".csv");
        ds = new TemporaryDataSource(file, "text/csv");
        OutputStream os = ds.getOutputStream();
        try {
            JRCsvExporter exporter = new JRCsvExporter();
            exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, ";");
            exporter.setParameter(JRCsvExporterParameter.CHARACTER_ENCODING, "ISO-8859-1");
            exporter.setParameter(JRCsvExporterParameter.JASPER_PRINT, print);
            exporter.setParameter(JRCsvExporterParameter.OUTPUT_STREAM, os);
            exporter.exportReport();
            os.flush();
        } finally {
            os.close();
        }
    } else if ("HTML".equals(format)) {
        File file = File.createTempFile("out", ".html");
        ds = new TemporaryDataSource(file, "text/html");
        JRExtendedHtmlExporter exporter = new JRExtendedHtmlExporter();
        OutputStream os = ds.getOutputStream();
        try {
            exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, print);
            exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, os);
            exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, false);
            exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "<html>\n" + "<head>\n" + "  <title></title>\n" + "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n" + "  <style type=\"text/css\">\n" + "    a {text-decoration: none}\n" + "  </style>\n" + "</head>\n" + "<body text=\"#000000\" link=\"#000000\" alink=\"#000000\" vlink=\"#000000\">\n" + "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n" + "<tr><td width=\"50%\">&nbsp;</td><td align=\"left\">");
            exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "</td><td width=\"50%\">&nbsp;</td></tr>\n" + "</table></body></html>");
            exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, print);
            boolean ignoreMargins = exportOptions.isIgnorePageMargins();
            if (ignoreMargins) {
                exporter.setParameter(JRHtmlExporterParameter.IGNORE_PAGE_MARGINS, true);
            }
            String encoding = exportOptions.getCharacterEncoding();
            if (encoding != null) {
                exporter.setParameter(JRHtmlExporterParameter.CHARACTER_ENCODING, encoding);
            }
            exporter.exportReport();
            os.flush();
        } finally {
            os.close();
        }
    }
    return ds;
}
Also used : TemporaryDataSource(org.santfeliu.util.TemporaryDataSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) JRCsvExporter(net.sf.jasperreports.engine.export.JRCsvExporter) File(java.io.File) JRRtfExporter(net.sf.jasperreports.engine.export.JRRtfExporter) FileDataSource(javax.activation.FileDataSource) MemoryDataSource(org.santfeliu.util.MemoryDataSource) TemporaryDataSource(org.santfeliu.util.TemporaryDataSource) DataSource(javax.activation.DataSource)

Example 4 with TemporaryDataSource

use of org.santfeliu.util.TemporaryDataSource in project gdmatrix by gdmatrix.

the class DocumentEditor method storeDocument.

public void storeDocument(boolean keepLocking) throws Exception {
    try {
        if (document == null)
            throw new Exception("CANNOT_STORE_NULL_DOCUMENT");
        else {
            if (!keepLocking)
                unlockDocument();
            TemporaryDataSource dataSource = writeDocument(documentData, document.getContent().getContentType());
            DataHandler dataHandler = new DataHandler(dataSource);
            document.getContent().setContentId(null);
            document.getContent().setData(dataHandler);
            document.setIncremental(true);
            document.setState(State.COMPLETE);
            getClient().storeDocument(document);
        }
    } finally {
        if (document != null && document.getContent() != null)
            document.getContent().setData(null);
    }
}
Also used : TemporaryDataSource(org.santfeliu.util.TemporaryDataSource) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException)

Example 5 with TemporaryDataSource

use of org.santfeliu.util.TemporaryDataSource in project gdmatrix by gdmatrix.

the class UploadFileManager method getDataSource.

private TemporaryDataSource getDataSource() {
    File file = new File(filePath);
    MimeTypeMap mimeTypeMap = MimeTypeMap.getMimeTypeMap();
    String mimeType = mimeTypeMap.getContentType(fileName);
    return new TemporaryDataSource(file, mimeType);
}
Also used : TemporaryDataSource(org.santfeliu.util.TemporaryDataSource) MimeTypeMap(org.santfeliu.util.MimeTypeMap) UploadedFile(org.apache.myfaces.custom.fileupload.UploadedFile) File(java.io.File)

Aggregations

TemporaryDataSource (org.santfeliu.util.TemporaryDataSource)10 File (java.io.File)9 DataHandler (javax.activation.DataHandler)7 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)3 Content (org.matrix.doc.Content)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)1 PdfFileSpecification (com.lowagie.text.pdf.PdfFileSpecification)1 PdfImportedPage (com.lowagie.text.pdf.PdfImportedPage)1 PdfReader (com.lowagie.text.pdf.PdfReader)1 PdfString (com.lowagie.text.pdf.PdfString)1 PdfWriter (com.lowagie.text.pdf.PdfWriter)1 StreamingDataHandler (com.sun.xml.ws.developer.StreamingDataHandler)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1