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);
}
}
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);
}
}
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%\"> </td><td align=\"left\">");
exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "</td><td width=\"50%\"> </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;
}
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);
}
}
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);
}
Aggregations