changeset 585:95417c4615b8 stream

more cleanup for ImageFileSet
author robcast
date Wed, 05 Jan 2011 14:41:28 +0100
parents 7357ad8f9f42
children 41a8d293b798
files servlet/src/digilib/image/ImageJobDescription.java servlet/src/digilib/io/DigilibInfoReader.java servlet/src/digilib/io/ImageFile.java servlet/src/digilib/io/ImageFileSet.java servlet/src/digilib/io/ImageInput.java servlet/src/digilib/pdf/DigilibInfoReader.java servlet/src/digilib/pdf/PDFTitlePage.java servlet/src/digilib/servlet/DigilibConfiguration.java servlet/src/digilib/servlet/DocumentBean.java
diffstat 9 files changed, 126 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageJobDescription.java	Wed Jan 05 12:12:19 2011 +0100
+++ b/servlet/src/digilib/image/ImageJobDescription.java	Wed Jan 05 14:41:28 2011 +0100
@@ -132,9 +132,6 @@
 	public String getMimeType() throws IOException {
 		if (mimeType == null) {
 			fileToLoad = getFileToLoad();
-			if(! fileToLoad.isChecked()){
-				DigilibConfiguration.docuImageIdentify((ImageFile) fileToLoad); //FIXME: cast to file?
-			}
 			mimeType = fileToLoad.getMimetype();
 		}
 		return mimeType;
@@ -249,9 +246,6 @@
 		ImageSet fileset = getFileset();
 		if (getAbsoluteScale()) {
 			ImageInput hiresFile = fileset.getBiggest();
-			if (!hiresFile.isChecked()) {
-				DigilibConfiguration.docuImageIdentify((ImageFile) hiresFile); //FIXME: cast to file?
-			}
 			hiresSize = hiresFile.getSize();
 		}
 		return hiresSize;
--- a/servlet/src/digilib/io/DigilibInfoReader.java	Wed Jan 05 12:12:19 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-package digilib.io;
-
-/** 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.Document;
-import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
-
-
-
-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;
-	}
-
-	/**
-	 * Returns the attribute defined by 'attr' as a String.
-	 * 
-	 * @param attr
-	 * @return
-	 */
-	@SuppressWarnings("unchecked") // Element.getChildren() returns naked List
-    public String getAsString(String attr){
-		try{
-			SAXBuilder builder = new SAXBuilder();
-			Document doc = builder.build(new File(filename));
-			Element root = doc.getRootElement();
-			List<Element> mainElements = root.getChildren();
-			// logger.debug("XML mainElements:"+mainElements.toString());
-
-			for(int i=0; i<mainElements.size(); i++){
-				Element elem = mainElements.get(i);
-				if(elem.getName()==attr){
-					// logger.debug(attr+" == "+(String)elem.getTextTrim());
-					return (String)elem.getTextTrim();
-				}
-			}
-
-		}
-		catch(Exception e){
-			logger.error(e.getMessage());
-		}
-		return null;
-	}
-	
-	
-	/**
-	 * Find out if the info.xml exists
-	 * @return
-	 */
-	public boolean hasInfo(){
-		try {
-			SAXBuilder builder = new SAXBuilder();
-			builder.build(new File(filename));
-			return true;
-		}
-		catch(Exception e){
-			return false;
-		}
-	}
-	
-}
--- a/servlet/src/digilib/io/ImageFile.java	Wed Jan 05 12:12:19 2011 +0100
+++ b/servlet/src/digilib/io/ImageFile.java	Wed Jan 05 14:41:28 2011 +0100
@@ -22,8 +22,10 @@
 package digilib.io;
 
 import java.io.File;
+import java.io.IOException;
 
 import digilib.image.ImageSize;
+import digilib.servlet.DigilibConfiguration;
 
 /**
  * @author casties
@@ -64,7 +66,49 @@
 		this.parent = parent;
 	}
 	
-	/** Returns the file name (without path).
+	
+	/** Checks the image and sets size and type.
+	 * 
+	 */
+	public void check() {
+	    if (pixelSize == null) {
+	        try {
+	            // use the configured toolkit to identify the image
+                DigilibConfiguration.identifyDocuImage(this);
+            } catch (IOException e) {
+                // nothing much to do...
+            }
+	    }
+	}
+	
+	/* (non-Javadoc)
+     * @see digilib.io.ImageInput#getSize()
+     */
+    @Override
+    public ImageSize getSize() {
+        check();
+        return pixelSize;
+    }
+
+    /* (non-Javadoc)
+     * @see digilib.io.ImageInput#getMimetype()
+     */
+    @Override
+    public String getMimetype() {
+        check();
+        return mimetype;
+    }
+
+    /* (non-Javadoc)
+     * @see digilib.io.ImageInput#getAspect()
+     */
+    @Override
+    public float getAspect() {
+        check();
+        return (pixelSize != null) ? pixelSize.getAspect() : 0f;
+    }
+
+    /** Returns the file name (without path).
 	 * 
 	 * @return
 	 */
@@ -72,7 +116,6 @@
 		return name;
 	}
 
-
 	/**
 	 * @return File
 	 */
--- a/servlet/src/digilib/io/ImageFileSet.java	Wed Jan 05 12:12:19 2011 +0100
+++ b/servlet/src/digilib/io/ImageFileSet.java	Wed Jan 05 14:41:28 2011 +0100
@@ -140,7 +140,8 @@
     	// add the first ImageFile to the ImageSet
     	add(new ImageFile(fl, this, parentDir));
     	// iterate the remaining base directories
-    	for (Directory dir: dirs) {
+    	for (int i = 1; i < dirs.length; ++i) {
+    	    Directory dir = dirs[i];
     		if (dir == null) {
     			continue;
     		}
--- a/servlet/src/digilib/io/ImageInput.java	Wed Jan 05 12:12:19 2011 +0100
+++ b/servlet/src/digilib/io/ImageInput.java	Wed Jan 05 14:41:28 2011 +0100
@@ -74,7 +74,7 @@
 	 * @return
 	 */
 	public float getAspect() {
-		return (pixelSize != null) ? pixelSize.getAspect() : 0;
+		return (pixelSize != null) ? pixelSize.getAspect() : 0f;
 	}
 	
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/src/digilib/pdf/DigilibInfoReader.java	Wed Jan 05 14:41:28 2011 +0100
@@ -0,0 +1,76 @@
+package digilib.pdf;
+
+/** 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.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+
+
+
+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;
+	}
+
+	/**
+	 * Returns the attribute defined by 'attr' as a String.
+	 * 
+	 * @param attr
+	 * @return
+	 */
+	@SuppressWarnings("unchecked") // Element.getChildren() returns naked List
+    public String getAsString(String attr){
+		try{
+			SAXBuilder builder = new SAXBuilder();
+			Document doc = builder.build(new File(filename));
+			Element root = doc.getRootElement();
+			List<Element> mainElements = root.getChildren();
+			// logger.debug("XML mainElements:"+mainElements.toString());
+
+			for(int i=0; i<mainElements.size(); i++){
+				Element elem = mainElements.get(i);
+				if(elem.getName()==attr){
+					// logger.debug(attr+" == "+(String)elem.getTextTrim());
+					return (String)elem.getTextTrim();
+				}
+			}
+
+		}
+		catch(Exception e){
+			logger.error(e.getMessage());
+		}
+		return null;
+	}
+	
+	
+	/**
+	 * Find out if the info.xml exists
+	 * @return
+	 */
+	public boolean hasInfo(){
+		try {
+			SAXBuilder builder = new SAXBuilder();
+			builder.build(new File(filename));
+			return true;
+		}
+		catch(Exception e){
+			return false;
+		}
+	}
+	
+}
--- a/servlet/src/digilib/pdf/PDFTitlePage.java	Wed Jan 05 12:12:19 2011 +0100
+++ b/servlet/src/digilib/pdf/PDFTitlePage.java	Wed Jan 05 14:41:28 2011 +0100
@@ -15,7 +15,6 @@
 import com.itextpdf.text.Paragraph;
 
 
-import digilib.io.DigilibInfoReader;
 import digilib.io.DocuDirCache;
 import digilib.servlet.PDFCache;
 import digilib.servlet.PDFRequest;
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java	Wed Jan 05 12:12:19 2011 +0100
+++ b/servlet/src/digilib/servlet/DigilibConfiguration.java	Wed Jan 05 14:41:28 2011 +0100
@@ -278,7 +278,7 @@
 	 * @return
 	 * @throws IOException
 	 */
-	public static ImageInput docuImageIdentify(ImageFile imgf) throws IOException {
+	public static ImageInput identifyDocuImage(ImageFile imgf) throws IOException {
 	    // use fresh DocuImage instance
 	    DocuImage di = getDocuImageInstance();
 		return di.identify(imgf);
--- a/servlet/src/digilib/servlet/DocumentBean.java	Wed Jan 05 12:12:19 2011 +0100
+++ b/servlet/src/digilib/servlet/DocumentBean.java	Wed Jan 05 14:41:28 2011 +0100
@@ -210,11 +210,7 @@
 		}
 		// get original pixel size
 		ImageInput origfile = fileset.getBiggest();
-		// check image for size if mo=hires
-		if ((! origfile.isChecked())&&dlRequest.hasOption("hires")) {
-			logger.debug("pre-checking image!");
-			DigilibConfiguration.docuImageIdentify((ImageFile) origfile);
-		}
+		// check image for size (TODO: just if mo=hires?)
 		ImageSize pixsize = origfile.getSize();
 		if (pixsize != null) {
 			// add pixel size