changeset 566:50f291d808b1 digilibPDF

starting stream support
author robcast
date Mon, 20 Dec 2010 11:57:55 +0100
parents 8beefd1142b2
children 70c135bd17aa 9a054ba5b365
files servlet/src/digilib/image/DocuImage.java servlet/src/digilib/image/DocuImageImpl.java servlet/src/digilib/image/ImageInfoDocuImage.java servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/image/JAIDocuImage.java servlet/src/digilib/io/ImageFile.java servlet/src/digilib/io/ImageInput.java servlet/src/digilib/servlet/DigilibConfiguration.java
diffstat 8 files changed, 140 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/DocuImage.java	Mon Dec 20 09:39:14 2010 +0100
+++ b/servlet/src/digilib/image/DocuImage.java	Mon Dec 20 11:57:55 2010 +0100
@@ -27,6 +27,7 @@
 
 import digilib.io.ImageFile;
 import digilib.io.FileOpException;
+import digilib.io.ImageInput;
 
 /** The basic class for the representation of a digilib image.
  *
@@ -44,7 +45,7 @@
 	 */
 	public void loadImage(ImageFile f) throws FileOpException;
 
-	/** This DocuImage support the loadSubImage operation.
+	/** This DocuImage supports the loadSubImage operation.
 	 * 
 	 * @return boolean
 	 */
@@ -214,7 +215,7 @@
     /**
      * Check image size and type and store in ImageFile f
      */
-    public ImageFile identify(ImageFile imgf) throws IOException;
+    public ImageInput identify(ImageFile imgf) throws IOException;
 
     /**
      * Returns a list of supported image formats
--- a/servlet/src/digilib/image/DocuImageImpl.java	Mon Dec 20 09:39:14 2010 +0100
+++ b/servlet/src/digilib/image/DocuImageImpl.java	Mon Dec 20 11:57:55 2010 +0100
@@ -32,6 +32,7 @@
 
 import digilib.io.FileOpException;
 import digilib.io.ImageFile;
+import digilib.io.ImageInput;
 
 /** Simple abstract implementation of the <code>DocuImage</code> interface.
  *
@@ -101,7 +102,7 @@
     /* (non-Javadoc)
      * @see digilib.image.DocuImage#identify(digilib.io.ImageFile)
      */
-    public ImageFile identify(ImageFile imgf) throws IOException {
+    public ImageInput identify(ImageFile imgf) throws IOException {
         // just a do-nothing implementation
         return null;
     }
--- a/servlet/src/digilib/image/ImageInfoDocuImage.java	Mon Dec 20 09:39:14 2010 +0100
+++ b/servlet/src/digilib/image/ImageInfoDocuImage.java	Mon Dec 20 11:57:55 2010 +0100
@@ -10,6 +10,7 @@
 import org.marcoschmidt.image.ImageInfo;
 
 import digilib.io.ImageFile;
+import digilib.io.ImageInput;
 
 /** Simple abstract implementation of the <code>DocuImage</code> interface.
  * Implements only the identify method using the ImageInfo class.
@@ -19,7 +20,7 @@
 public abstract class ImageInfoDocuImage extends DocuImageImpl {
 
     /** Check image size and type and store in ImageFile f */
-    public ImageFile identify(ImageFile imgf) throws IOException {
+    public ImageInput identify(ImageFile imgf) throws IOException {
         // fileset to store the information
         File f = imgf.getFile();
         if (f == null) {
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java	Mon Dec 20 09:39:14 2010 +0100
+++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java	Mon Dec 20 11:57:55 2010 +0100
@@ -50,6 +50,7 @@
 import digilib.io.FileOps;
 import digilib.io.ImageFile;
 import digilib.io.ImageFileset;
+import digilib.io.ImageInput;
 
 /** Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D. */
 public class ImageLoaderDocuImage extends ImageInfoDocuImage {
@@ -123,9 +124,9 @@
 	}
 
     /** Check image size and type and store in ImageFile f */
-    public ImageFile identify(ImageFile imageFile) throws IOException {
+    public ImageInput identify(ImageFile imageFile) throws IOException {
         // try parent method first
-        ImageFile imf = super.identify(imageFile);
+        ImageInput imf = super.identify(imageFile);
         if (imf != null) {
             return imf;
         }
--- a/servlet/src/digilib/image/JAIDocuImage.java	Mon Dec 20 09:39:14 2010 +0100
+++ b/servlet/src/digilib/image/JAIDocuImage.java	Mon Dec 20 11:57:55 2010 +0100
@@ -47,6 +47,7 @@
 import digilib.io.FileOps;
 import digilib.io.ImageFile;
 import digilib.io.ImageFileset;
+import digilib.io.ImageInput;
 
 /** A DocuImage implementation using Java Advanced Imaging Library. */
 public class JAIDocuImage extends ImageInfoDocuImage {
@@ -99,9 +100,9 @@
     }
 
 	/* Check image size and type and store in ImageFile f */
-	public ImageFile identify(ImageFile imageFile) throws IOException {
+	public ImageInput identify(ImageFile imageFile) throws IOException {
         // try parent method first
-	    ImageFile imf = super.identify(imageFile);
+	    ImageInput imf = super.identify(imageFile);
 		if (imf != null) {
 			return imf;
 		}
--- a/servlet/src/digilib/io/ImageFile.java	Mon Dec 20 09:39:14 2010 +0100
+++ b/servlet/src/digilib/io/ImageFile.java	Mon Dec 20 11:57:55 2010 +0100
@@ -22,13 +22,14 @@
 package digilib.io;
 
 import java.io.File;
+import java.io.InputStream;
 
 import digilib.image.ImageSize;
 
 /**
  * @author casties
  */
-public class ImageFile {
+public class ImageFile implements ImageInput {
 	
 	// file name
 	private String filename = null;
@@ -53,6 +54,18 @@
 		this.filename = f.getName();
 	}
 	
+	
+	@Override
+	public boolean hasFile() {
+		// this is File-based
+		return true;
+	}
+
+	@Override
+	public boolean hasStream() {
+		return false;
+	}
+
 	/** Returns the file name (without path).
 	 * 
 	 * @return
@@ -65,6 +78,7 @@
 	/**
 	 * @return File
 	 */
+	@Override
 	public File getFile() {
 		if (dir == null) {
 			return null;
@@ -73,24 +87,26 @@
 		return f;
 	}
 
-	/**
-	 * @return ImageSize
+	/* (non-Javadoc)
+	 * @see digilib.io.ImageInput#getSize()
 	 */
+	@Override
 	public ImageSize getSize() {
 		return pixelSize;
 	}
 
-	/**
-	 * @return String
+	/* (non-Javadoc)
+	 * @see digilib.io.ImageInput#getMimetype()
 	 */
+	@Override
 	public String getMimetype() {
 		return mimetype;
 	}
 
-	/**
-	 * Sets the imageSize.
-	 * @param imageSize The imageSize to set
+	/* (non-Javadoc)
+	 * @see digilib.io.ImageInput#setSize(digilib.image.ImageSize)
 	 */
+	@Override
 	public void setSize(ImageSize imageSize) {
 		this.pixelSize = imageSize;
 		// pass on to parent
@@ -99,10 +115,10 @@
 		}
 	}
 
-	/**
-	 * Sets the mimetype.
-	 * @param mimetype The mimetype to set
+	/* (non-Javadoc)
+	 * @see digilib.io.ImageInput#setMimetype(java.lang.String)
 	 */
+	@Override
 	public void setMimetype(String filetype) {
 		this.mimetype = filetype;
 	}
@@ -122,19 +138,25 @@
 		this.parent = parent;
 	}
 
-	/**
-	 * @return boolean
+	/* (non-Javadoc)
+	 * @see digilib.io.ImageInput#isChecked()
 	 */
+	@Override
 	public boolean isChecked() {
 		return (pixelSize != null);
 	}
 	
-	/** Returns the aspect ratio of the image (width/height).
-	 * 
-	 * @return
+	/* (non-Javadoc)
+	 * @see digilib.io.ImageInput#getAspect()
 	 */
+	@Override
 	public float getAspect() {
 		return (pixelSize != null) ? pixelSize.getAspect() : 0;
 	}
 
+	@Override
+	public InputStream getStream() {
+		return null;
+	}
+
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/src/digilib/io/ImageInput.java	Mon Dec 20 11:57:55 2010 +0100
@@ -0,0 +1,87 @@
+/* ImageInput-- digilib image input interface.
+
+  Digital Image Library servlet components
+
+  Copyright (C) 2010 Robert Casties (robcast@mail.berlios.de)
+
+  This program is free software; you can redistribute  it and/or modify it
+  under  the terms of  the GNU General  Public License as published by the
+  Free Software Foundation;  either version 2 of the  License, or (at your
+  option) any later version.
+   
+  Please read license.txt for the full details. A copy of the GPL
+  may be found at http://www.gnu.org/copyleft/lgpl.html
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ * Created on 20.12.2010
+ */
+
+package digilib.io;
+
+import java.io.File;
+import java.io.InputStream;
+
+import digilib.image.ImageSize;
+
+public interface ImageInput {
+
+	/**
+	 * @return ImageSize
+	 */
+	public abstract ImageSize getSize();
+
+	/**
+	 * @return String
+	 */
+	public abstract String getMimetype();
+
+	/**
+	 * Sets the imageSize.
+	 * @param imageSize The imageSize to set
+	 */
+	public abstract void setSize(ImageSize imageSize);
+
+	/**
+	 * Sets the mimetype.
+	 * @param mimetype The mimetype to set
+	 */
+	public abstract void setMimetype(String filetype);
+
+	/** returns if this image has been checked 
+	 * (i.e. has size and mimetype) 
+	 * @return boolean
+	 */
+	public abstract boolean isChecked();
+
+	/** Returns the aspect ratio of the image (width/height).
+	 * 
+	 * @return
+	 */
+	public abstract float getAspect();
+
+	/** Returns if this ImageInput is File-based.
+	 * @return
+	 */
+	public abstract boolean hasFile();
+	
+	/** Returns the underlying File (if applicable)
+	 * 
+	 * @return
+	 */
+	public abstract File getFile();
+
+	/** Returns the underlying Stream (if applicable)
+	 * 
+	 * @return
+	 */
+	public abstract InputStream getStream();
+
+	/** Returns if this ImageInput is Stream-based.
+	 * @return
+	 */
+	public abstract boolean hasStream();
+	
+}
\ No newline at end of file
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java	Mon Dec 20 09:39:14 2010 +0100
+++ b/servlet/src/digilib/servlet/DigilibConfiguration.java	Mon Dec 20 11:57:55 2010 +0100
@@ -36,6 +36,7 @@
 import digilib.image.DocuImageImpl;
 import digilib.io.FileOps;
 import digilib.io.ImageFile;
+import digilib.io.ImageInput;
 import digilib.io.XMLListLoader;
 import digilib.util.Parameter;
 import digilib.util.ParameterMap;
@@ -277,7 +278,7 @@
 	 * @return
 	 * @throws IOException
 	 */
-	public static ImageFile docuImageIdentify(ImageFile imgf) throws IOException {
+	public static ImageInput docuImageIdentify(ImageFile imgf) throws IOException {
 	    // use fresh DocuImage instance
 	    DocuImage di = getDocuImageInstance();
 		return di.identify(imgf);