# HG changeset patch # User cmielack # Date 1236956077 -3600 # Node ID e9d116e7eceaf9c6bf2930c27dbc8f1bf7be4dba # Parent e7b2e78cdb6866ce8f2e9f845f338affec72093e *** empty log message *** diff -r e7b2e78cdb68 -r e9d116e7ecea servlet/src/digilib/servlet/DigilibInfoReader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/servlet/DigilibInfoReader.java Fri Mar 13 15:54:37 2009 +0100 @@ -0,0 +1,65 @@ +package digilib.servlet; + +/** DigilibInfoReader + * A class for reading the information from info.xml files used in digilib image directories. + * + */ + +import java.io.File; +import java.util.List; + +import org.apache.log4j.Logger; +import org.jdom.*; +import org.jdom.input.*; +import org.jdom.output.*; + + + +public class DigilibInfoReader { + + /** gengeral logger for this class */ + protected static Logger logger = Logger.getLogger("digilib.servlet"); + + private String filename = null; + private static String base_element = "info"; + + public DigilibInfoReader(String fn){ + filename = fn; + } + + + public String getAsString(String attr){ + try{ + SAXBuilder builder = new SAXBuilder(); + Document doc = builder.build(new File(filename)); + Element root = doc.getRootElement(); + List mainElements = root.getChildren(); + logger.debug("XML mainElements:"+mainElements.toString()); + + for(int i=0; i pgs = new ArrayList(); diff -r e7b2e78cdb68 -r e9d116e7ecea servlet/src/digilib/servlet/ImageJobInformation.java --- a/servlet/src/digilib/servlet/ImageJobInformation.java Fri Mar 13 15:51:47 2009 +0100 +++ b/servlet/src/digilib/servlet/ImageJobInformation.java Fri Mar 13 15:54:37 2009 +0100 @@ -101,7 +101,7 @@ // url of the page/document (first part, may be empty) newParameter("request.path", "", null, 'i'); // base URL (from http:// to below /servlet) - newParameter("base.url", null, null, 'i'); + newParameter("base.url", "", null, 'i'); /* * Parameters of type 'c' are for the clients use @@ -143,7 +143,12 @@ } } setValueFromString("request.path", ((HttpServletRequest) request).getPathInfo()); - + String[] baseurl_parts = ((HttpServletRequest) request).getRequestURL().toString().split("/"); + String baseurl = ""; + for(int i=0; i()); + - //cache_hash = (HashMap) context.getAttribute(cache_hash_id); + temp_directory = dlConfig.getAsString("pdf-temp-dir"); + cache_directory = dlConfig.getAsString("pdf-cache-dir"); - /*if (cache_hash==null){ - cache_hash = new HashMap(); - context.setAttribute(cache_hash_id, cache_hash); - }*/ + + // rid the temporary directory of possible incomplete document files + emptyTempDirectory(); - // scan the directory - // scanCacheDirectory(); - emptyTempDirectory(); + // register this instance globally + context.setAttribute(global_instance, this); + } public void emptyTempDirectory(){ - // search the cache-directory for existing files and fill them into the Hashtable as STATUS_DONE - File temp_dir = new File(temp_directory); String[] cached_files = temp_dir.list(); - for (String file: cached_files){ new File(temp_directory,file).delete(); } @@ -195,7 +196,7 @@ public void createNewPdfDocument(PDFJobInformation pdfji, String filename){ // start new worker - PDFMaker pdf_maker = new PDFMaker(dlConfig, pdfji,filename); + PDFMaker pdf_maker = new PDFMaker(context, pdfji,filename); new Thread(pdf_maker, "PDFMaker").start(); } @@ -254,4 +255,12 @@ } } + + public String getCacheDirectory(){ + return cache_directory; + } + + public String getTempDirectory(){ + return temp_directory; + } } diff -r e7b2e78cdb68 -r e9d116e7ecea servlet/src/digilib/servlet/PDFJobInformation.java --- a/servlet/src/digilib/servlet/PDFJobInformation.java Fri Mar 13 15:51:47 2009 +0100 +++ b/servlet/src/digilib/servlet/PDFJobInformation.java Fri Mar 13 15:54:37 2009 +0100 @@ -217,4 +217,8 @@ return true; } + public DigilibConfiguration getDlConfig(){ + return dlConfig; + } + } \ No newline at end of file diff -r e7b2e78cdb68 -r e9d116e7ecea servlet/src/digilib/servlet/PDFMaker.java --- a/servlet/src/digilib/servlet/PDFMaker.java Fri Mar 13 15:51:47 2009 +0100 +++ b/servlet/src/digilib/servlet/PDFMaker.java Fri Mar 13 15:54:37 2009 +0100 @@ -13,20 +13,23 @@ public class PDFMaker extends HttpServlet implements Runnable { + public static String version = "0.1"; + private PDFJobInformation job_info = null; private String filename = null; private DigilibConfiguration dlConfig = null; - + private ServletContext context = null; /** gengeral logger for this class */ protected static Logger logger = Logger.getLogger("digilib.servlet"); - public PDFMaker(DigilibConfiguration dlConfig, PDFJobInformation pdfji, String filename){ + public PDFMaker(ServletContext context, PDFJobInformation pdfji, String filename){ this.job_info = pdfji; this.filename = filename; - this.dlConfig = dlConfig; + this.dlConfig = pdfji.getDlConfig(); + this.context = context; } @@ -41,13 +44,15 @@ return; } + PDFCache pdfcache = (PDFCache) context.getAttribute(PDFCache.global_instance); + // create PDFWorker - DigilibPDFWorker pdf_worker = new DigilibPDFWorker(dlConfig, job_info, filename); + DigilibPDFWorker pdf_worker = new DigilibPDFWorker(dlConfig, job_info, pdfcache.getTempDirectory()+filename); // run PDFWorker pdf_worker.run(); - File document = new File(PDFCache.temp_directory + filename); + File document = new File(pdfcache.getTempDirectory() + filename); if(pdf_worker.hasError()){ // raise error, write to logger @@ -55,8 +60,8 @@ document.delete(); return; } - else{ - boolean success = document.renameTo(new File(PDFCache.cache_directory, filename)); + else{ // move the completed file to the cache directory + boolean success = document.renameTo(new File(pdfcache.getCacheDirectory(), filename)); if(!success){ // TODO raise error diff -r e7b2e78cdb68 -r e9d116e7ecea servlet/src/digilib/servlet/PDFTitlePage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/servlet/PDFTitlePage.java Fri Mar 13 15:54:37 2009 +0100 @@ -0,0 +1,161 @@ +package digilib.servlet; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +import org.apache.log4j.Logger; + +import com.lowagie.text.*; +import com.lowagie.text.pdf.*; + +import digilib.io.DocuDirCache; + +/** A class for the generation of title pages for the generated pdf documents. + * + * + */ +public class PDFTitlePage { + + private PDFJobInformation job_info = null; + private DigilibInfoReader info_reader= null; + private DocuDirCache dirCache = null; + protected static Logger logger = Logger.getLogger("digilib.servlet"); + + + public PDFTitlePage(PDFJobInformation pdfji){ + job_info = pdfji; + dirCache = (DocuDirCache) job_info.getDlConfig().getValue("servlet.dir.cache"); + + String fn = getBase(dirCache.getDirectory(pdfji.getImageJobInformation().getAsString("fn")).getDir().getPath()) + "presentation/info.xml"; + + info_reader = new DigilibInfoReader(fn); + } + + + public Element getPageContents(){ + Paragraph content = new Paragraph(); + content.setAlignment(Element.ALIGN_CENTER); + + // add vertical whitespace + for(int i=0; i<8; i++){ + content.add(Chunk.NEWLINE); + } + + + // add logo + content.add(getLogo()); + content.add(Chunk.NEWLINE); + content.add(Chunk.NEWLINE); + + // add title + Anchor title = new Anchor(new Paragraph(getTitle(),FontFactory.getFont(FontFactory.HELVETICA,16))); + String burl = job_info.getImageJobInformation().getAsString("base.url"); + + title.setReference(burl+"digilib.jsp?fn="+job_info.getImageJobInformation().getAsString("fn")); + content.add(title); + content.add(Chunk.NEWLINE); + + // add author + if(getDate()!=" ") + content.add(new Paragraph(getAuthor()+" ("+getDate()+")",FontFactory.getFont(FontFactory.HELVETICA,14))); + else + content.add(new Paragraph(getAuthor(),FontFactory.getFont(FontFactory.HELVETICA,14))); + + content.add(Chunk.NEWLINE); + + // add page numbers + content.add(new Paragraph(getPages(), FontFactory.getFont(FontFactory.HELVETICA, 12))); + + + content.add(Chunk.NEWLINE); + content.add(Chunk.NEWLINE); + content.add(Chunk.NEWLINE); + + // add credits + content.add(new Paragraph("MPIWG Berlin 2009", FontFactory.getFont(FontFactory.HELVETICA,10))); + + // add digilib version + content.add(new Paragraph(getDigilibVersion(),FontFactory.getFont(FontFactory.HELVETICA,10))); + + for(int i=0; i<8; i++){ + content.add(Chunk.NEWLINE); + } + Anchor address = new Anchor( + new Paragraph(burl+"digilib.jsp?fn="+job_info.getImageJobInformation().getAsString("fn"), FontFactory.getFont(FontFactory.COURIER, 9)) + ); + address.setReference(burl+"digilib.jsp?fn="+job_info.getImageJobInformation().getAsString("fn")); + + content.add(address); + + + return content; + } + + private String getBase(String path){ + // return base directory of an image directory + if(path.contains("/")){ + String[] x = path.split("/"); + String newpath = ""; + for(int i=0; i