Mercurial > hg > digilib-old
changeset 556:5cc180bb0a5c digilibPDF
pdf generation closer to working...
author | robcast |
---|---|
date | Thu, 16 Dec 2010 17:02:34 +0100 |
parents | 88ed97d08b97 |
children | 0885f5ca5b24 |
files | servlet/src/digilib/servlet/PDFCache.java servlet/src/digilib/servlet/PDFFileWorker.java |
diffstat | 2 files changed, 42 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/servlet/PDFCache.java Thu Dec 16 14:31:48 2010 +0100 +++ b/servlet/src/digilib/servlet/PDFCache.java Thu Dec 16 17:02:34 2010 +0100 @@ -36,7 +36,7 @@ public static String instanceKey = "digilib.servlet.PDFCache"; - private DigilibJobCenter<OutputStream> pdfJobCenter = null; + private DigilibJobCenter<File> pdfJobCenter = null; private DigilibJobCenter<DocuImage> pdfImageJobCenter = null; @@ -99,7 +99,7 @@ throw new ServletException("Configuration error: problem with pdf-cache-dir="+cache_fn); } - pdfJobCenter = (DigilibJobCenter<OutputStream>) dlConfig.getValue("servlet.worker.pdfexecutor"); + pdfJobCenter = (DigilibJobCenter<File>) dlConfig.getValue("servlet.worker.pdfexecutor"); pdfImageJobCenter = (DigilibJobCenter<DocuImage>) dlConfig.getValue("servlet.worker.pdfimageexecutor"); // register this instance globally @@ -214,8 +214,8 @@ /** check the status of the document corresponding to the documentid */ public Integer getStatus(String documentid){ // looks into the cache and temp directory in order to find out the status of the document - File cached = new File(cache_directory, documentid); - File wip = new File(temp_directory, documentid); + File cached = getCacheFile(documentid); + File wip = getTempFile(documentid); if(cached.exists()){ return STATUS_DONE; } else if (wip.exists()){ @@ -233,17 +233,14 @@ * @return * @throws FileNotFoundException */ - public Future<OutputStream> createNewPdfDocument(PDFJobDescription pdfji, String filename) throws FileNotFoundException{ + public Future<File> createNewPdfDocument(PDFJobDescription pdfji, String filename) throws FileNotFoundException{ // start new worker - File of = this.getTempFile(filename); - OutputStream os = new FileOutputStream(of); - PDFStreamWorker job = new PDFStreamWorker(dlConfig, os, pdfji, pdfImageJobCenter); + File tempf = this.getTempFile(filename); + File finalf = this.getCacheFile(filename); + PDFFileWorker job = new PDFFileWorker(dlConfig, tempf, finalf, pdfji, pdfImageJobCenter); // start job - Future<OutputStream> jobTicket = pdfJobCenter.submit(job); - // what do we do with the result? + Future<File> jobTicket = pdfJobCenter.submit(job); return jobTicket; - /* PDFMaker pdf_maker = new PDFMaker(context, pdfji,filename); - new Thread(pdf_maker, "PDFMaker").start();*/ }
--- a/servlet/src/digilib/servlet/PDFFileWorker.java Thu Dec 16 14:31:48 2010 +0100 +++ b/servlet/src/digilib/servlet/PDFFileWorker.java Thu Dec 16 17:02:34 2010 +0100 @@ -4,19 +4,50 @@ package digilib.servlet; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; import java.util.concurrent.Callable; +import digilib.image.DocuImage; + /** * @author casties * */ public class PDFFileWorker implements Callable<File> { + /** the wrapped PDFStreamWorker */ protected PDFStreamWorker streamWorker; + + /** the temporary output file */ + protected File tempFile; + /** the final output file */ + protected File finalFile; + + /** Create new PDFFileWorker. + * @param dlConfig + * @param tempFile + * @param job_info + * @param imageJobCenter + * @throws FileNotFoundException + */ + public PDFFileWorker(DigilibConfiguration dlConfig, + File tempFile, File finalFile, + PDFJobDescription job_info, + DigilibJobCenter<DocuImage> imageJobCenter) throws FileNotFoundException { + OutputStream outstream = new FileOutputStream(tempFile); + this.finalFile = finalFile; + this.streamWorker = new PDFStreamWorker(dlConfig, outstream, job_info, imageJobCenter); + } + @Override public File call() throws Exception { - // TODO Auto-generated method stub - return null; + OutputStream outstream = streamWorker.call(); + outstream.flush(); + // move temporary to final file + tempFile.renameTo(finalFile); + return finalFile; }