Mercurial > hg > digilib-old
changeset 541:f140d5ee8c0b digilibPDF
new NumRange class
allows "1-" specifications
author | robcast |
---|---|
date | Tue, 12 Oct 2010 20:42:58 +0200 |
parents | a4a4b31d615e |
children | e2ff961001af |
files | servlet/src/digilib/servlet/DigilibPDFWorker.java servlet/src/digilib/servlet/ImageJobInformation.java servlet/src/digilib/servlet/NumRange.java servlet/src/digilib/servlet/PDFJobInformation.java |
diffstat | 4 files changed, 68 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/servlet/DigilibPDFWorker.java Mon Oct 11 16:06:03 2010 +0200 +++ b/servlet/src/digilib/servlet/DigilibPDFWorker.java Tue Oct 12 20:42:58 2010 +0200 @@ -90,7 +90,8 @@ logger.debug("- "+outputfile+" doc.open()ed ("+(System.currentTimeMillis()-start_time) + "ms)"); start_time = System.currentTimeMillis(); - Integer[] pgs = job_info.getPageNrs();//get_pgs(); + //Integer[] pgs = job_info.getPageNrs();//get_pgs(); + NumRange pgs = job_info.getPages(); for(Integer p: pgs){ logger.debug(" - adding Image "+p+" to " + outputfile);
--- a/servlet/src/digilib/servlet/ImageJobInformation.java Mon Oct 11 16:06:03 2010 +0200 +++ b/servlet/src/digilib/servlet/ImageJobInformation.java Tue Oct 12 20:42:58 2010 +0200 @@ -14,6 +14,7 @@ import digilib.image.ImageOps; import digilib.image.ImageSize; import digilib.io.DocuDirCache; +import digilib.io.DocuDirectory; import digilib.io.FileOpException; import digilib.io.FileOps; import digilib.io.ImageFile; @@ -43,7 +44,8 @@ ImageFile fileToLoad = null; ImageFileset fileset=null; - String FilePath = null; + DocuDirectory fileDir = null; + String filePath = null; ImageSize expectedSourceSize = null; Float scaleXY = null; Rectangle2D userImgArea = null; @@ -223,26 +225,38 @@ } - public ImageFileset get_fileset() throws FileOpException{ - if(fileset==null){ + public DocuDirectory getFileDirectory() throws FileOpException{ + if(fileDir==null){ DocuDirCache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); - fileset = (ImageFileset) dirCache.getFile(getFilePath(), getAsInt("pn"), FileOps.CLASS_IMAGE); - if (fileset == null) { - throw new FileOpException("File " + getFilePath() + "(" - + getAsInt("pn") + ") not found."); + fileDir = dirCache.getDirectory(getFilePath()); + if (fileDir == null) { + throw new FileOpException("Directory " + getFilePath() + " not found."); } } - return fileset; + return fileDir; } + public ImageFileset get_fileset() throws FileOpException{ + if(fileset==null){ + DocuDirCache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); + + fileset = (ImageFileset) dirCache.getFile(getFilePath(), getAsInt("pn"), FileOps.CLASS_IMAGE); + if (fileset == null) { + throw new FileOpException("File " + getFilePath() + "(" + + getAsInt("pn") + ") not found."); + } + } + return fileset; + } + public String getFilePath() { - if(FilePath == null){ + if(filePath == null){ String s = this.getAsString("request.path"); s += this.getAsString("fn"); - FilePath = FileOps.normalName(s); + filePath = FileOps.normalName(s); } - return FilePath; + return filePath; } public boolean get_hiresOnly(){
--- a/servlet/src/digilib/servlet/NumRange.java Mon Oct 11 16:06:03 2010 +0200 +++ b/servlet/src/digilib/servlet/NumRange.java Tue Oct 12 20:42:58 2010 +0200 @@ -59,6 +59,13 @@ if (nums.length > 1) { // second number is end of range int end = Integer.valueOf(nums[1]); + if (intervals.length == 1) { + // optimized case of just one interval + this.start = start; + this.end = end; + this.list = null; + return; + } for (int i = start; i <= end; i++) { // add all numbers to list pgs.add(i); @@ -110,7 +117,7 @@ private int end = getEnd(); public boolean hasNext() { - return (num < end); + return (num <= end); } public Integer next() { @@ -131,13 +138,24 @@ private int end = getEnd(); public boolean hasNext() { - return (num < end); + return (num <= end); } public Integer next() { - if (listidx < listend) { + if (listidx < listend - 1) { num = list.get(listidx++); return num; + } else if (listidx == listend - 1) { + // last element in list + int n = list.get(listidx++); + if (n == Integer.MAX_VALUE) { + // open end -- continue + num++; + return num++; + } else { + num = n; + return num++; + } } else { return num++; }
--- a/servlet/src/digilib/servlet/PDFJobInformation.java Mon Oct 11 16:06:03 2010 +0200 +++ b/servlet/src/digilib/servlet/PDFJobInformation.java Tue Oct 12 20:42:58 2010 +0200 @@ -8,6 +8,9 @@ import org.apache.log4j.Logger; +import digilib.io.DocuDirectory; +import digilib.io.FileOps; + /** * A container class for storing a set of instruction parameters @@ -26,6 +29,7 @@ ImageJobInformation image_info = null; DigilibConfiguration dlConfig = null; + NumRange pages = null; /** gengeral logger for this class */ protected static Logger logger = Logger.getLogger("digilib.servlet"); @@ -60,6 +64,15 @@ setValueFromString(param, request.getParameter(param)); } } + // process parameters + try { + pages = new NumRange(getAsString("pgs")); + DocuDirectory dir = image_info.getFileDirectory(); + int dirsize = dir.size(FileOps.CLASS_IMAGE); + pages.setMaxnum(dirsize); + } catch (Exception e) { + logger.warn("Problem with parsing page numbers: "+e.toString()); + } } @@ -101,39 +114,8 @@ } - /** - * Convert the "pgs"-Parameter to an Array of Integers. - * - * @return - * @throws Exception - */ - public Integer[] getPageNrs() throws Exception{ - - String pages = getAsString("pgs"); - ArrayList<Integer> pgs = new ArrayList<Integer>(); - Integer[] out = null; - - String intervals[] = pages.split(","); - - // convert the page-interval-strings into a list containing every single page - for(String interval: intervals){ - if(interval.contains("-")){ - String nums[] = interval.split("-"); - int start = Integer.valueOf(nums[0]); - int end = Integer.valueOf(nums[1]); - for(int i = start; i <= end; i++){ - // add all numbers to list - pgs.add(i); - } - } - else{ - pgs.add(Integer.valueOf(interval)); - } - } - out = new Integer[pgs.size()]; - - pgs.toArray(out); - return out; + public NumRange getPages() { + return pages; } @@ -144,39 +126,11 @@ * @return */ public boolean checkValidity(){ - String pgs = getAsString("pgs"); - try{ - String[] intervals = null; - if(pgs.indexOf(",")>0){ - intervals = pgs.split(","); - } - else{ - intervals = new String[1]; - intervals[0]=pgs; - } - for(String interval:intervals){ - if(interval.indexOf("-")>=0){ - String[] intrvl = interval.split("-"); - int a = Integer.valueOf(intrvl[0]); - int b = Integer.valueOf(intrvl[1]); - if(a<=0 || b<a){ - return false; - } - } - else { - int c = Integer.valueOf(interval); - if(c<=0) - return false; - - } - } - } - catch(Exception e){ - logger.error("invalid pgs-input"); - return false; - } - return true; - } + if (pages != null) { + return true; + } + return false; + } public DigilibConfiguration getDlConfig(){ return dlConfig;