public Element exec(Element metadata, ServiceContext context) throws Exception { Element htmlDoc = metadata.getChild("html"); XMLOutputter printer = new XMLOutputter(); String htmlContent = printer.outputString(htmlDoc); File tempDir = (File) context.getServlet().getServletContext().getAttribute("javax.servlet.context.tempdir"); File tempFile = File.createTempFile(TMP_PDF_FILE, ".pdf", tempDir); OutputStream os = new FileOutputStream(tempFile); try { ITextRenderer renderer = new ITextRenderer(); renderer.setDocumentFromString(htmlContent); renderer.layout(); renderer.createPDF(os); } finally { os.close(); } Element res = BinaryFile.encode(200, tempFile.getAbsolutePath(), true); return res; }
private void updateChangedFile( String id, String file, String dir, String changeDate, InputStream is) throws IOException { String resourcesDir = Lib.resource.getDir(context, dir, id); File locFile = new File(resourcesDir, file); ISODate locIsoDate = new ISODate(locFile.lastModified()); ISODate remIsoDate = new ISODate(changeDate); if (!locFile.exists() || remIsoDate.sub(locIsoDate) > 0) { if (log.isDebugEnabled()) log.debug(" - Adding remote " + dir + " file with name:" + file); FileOutputStream os = new FileOutputStream(locFile); BinaryFile.copy(is, os, false, true); locFile.setLastModified(remIsoDate.getSeconds() * 1000); } else { if (log.isDebugEnabled()) log.debug(" - Nothing to do in dir " + dir + " for file with name:" + file); } }