@Override public Blob renderTemplate(TemplateBasedDocument templateBasedDocument, String templateName) throws Exception { Blob sourceTemplateBlob = getSourceTemplateBlob(templateBasedDocument, templateName); List<TemplateInput> params = templateBasedDocument.getParams(templateName); DocumentModel doc = templateBasedDocument.getAdaptedDoc(); Map<String, Object> ctx = FMContextBuilder.build(doc, false); JXLSBindingResolver resolver = new JXLSBindingResolver(); resolver.resolve(params, ctx, templateBasedDocument); File workingDir = getWorkingDir(); File generated = new File(workingDir, "JXLSresult-" + System.currentTimeMillis()); generated.createNewFile(); File input = new File(workingDir, "JXLSInput-" + System.currentTimeMillis()); input.createNewFile(); sourceTemplateBlob.transferTo(input); XLSTransformer transformer = new XLSTransformer(); transformer.transformXLS(input.getAbsolutePath(), ctx, generated.getAbsolutePath()); input.delete(); Blob newBlob = new FileBlob(generated); String templateFileName = sourceTemplateBlob.getFilename(); // set the output file name String targetFileExt = FileUtils.getFileExtension(templateFileName); String targetFileName = FileUtils.getFileNameNoExt(templateBasedDocument.getAdaptedDoc().getTitle()); targetFileName = targetFileName + "." + targetFileExt; newBlob.setFilename(targetFileName); // mark the file for automatic deletion on GC Framework.trackFile(generated, newBlob); return newBlob; }
public List<Blob> getPreview(Blob blob, DocumentModel dm) throws PreviewException { final String USER_TEMP = System.getProperty("java.io.tmpdir"); Message msg = null; try { blob.transferTo(new File(USER_TEMP + "\\previewnuxeo.tmp")); MsgParser msgp = new MsgParser(); msg = msgp.parseMsg(USER_TEMP + "\\previewnuxeo.tmp"); } catch (IOException e1) { log.error(e1.toString()); } List<Blob> blobResults = new ArrayList<Blob>(); StringBuilder htmlPage = new StringBuilder(); htmlPage.append("<html>"); String tempheader = msg.toString() .replace("&", "&") .replace("<", "<") .replace(">", ">") .replace("\'", "'") .replace("\"", """); String tempbody = msg.getBodyText() .replace("&", "&") .replace("<", "<") .replace(">", ">") .replace("\'", "'") .replace("\"", """); htmlPage.append("<pre>").append(tempheader.replace("\n", "<br/>")).append("</pre>"); htmlPage.append("<pre>").append(tempbody.replace("\n", "")).append("</pre>"); htmlPage.append("</html>"); Blob mainBlob = new StringBlob(htmlPage.toString()); mainBlob.setFilename("index.html"); mainBlob.setMimeType("text/html"); blobResults.add(mainBlob); return blobResults; }