# HG changeset patch # User robcast # Date 1286908978 -7200 # Node ID f140d5ee8c0b92008d9e6e43969714788778c696 # Parent a4a4b31d615e657dc9a1e42cbcb243383aaa87fe new NumRange class allows "1-" specifications diff -r a4a4b31d615e -r f140d5ee8c0b servlet/src/digilib/servlet/DigilibPDFWorker.java --- 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); diff -r a4a4b31d615e -r f140d5ee8c0b servlet/src/digilib/servlet/ImageJobInformation.java --- 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(){ diff -r a4a4b31d615e -r f140d5ee8c0b servlet/src/digilib/servlet/NumRange.java --- 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++; } diff -r a4a4b31d615e -r f140d5ee8c0b servlet/src/digilib/servlet/PDFJobInformation.java --- 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 pgs = new ArrayList(); - 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