changeset 139:11cfe4c89fdc

Servlet version 1.11b1 with improved original-size. - fixed lots of bugs in metadata handling.
author robcast
date Thu, 31 Jul 2003 20:56:51 +0200
parents d18b0ff52b07
children c878ea574c29
files client/digitallibrary/WEB-INF/lib/DigilibServlet.jar servlet/src/digilib/io/DocuFileset.java servlet/src/digilib/io/XMLMetaLoader.java servlet/src/digilib/servlet/Scaler.java
diffstat 4 files changed, 88 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
Binary file client/digitallibrary/WEB-INF/lib/DigilibServlet.jar has changed
--- a/servlet/src/digilib/io/DocuFileset.java	Sat Jul 12 01:26:56 2003 +0200
+++ b/servlet/src/digilib/io/DocuFileset.java	Thu Jul 31 20:56:51 2003 +0200
@@ -45,7 +45,6 @@
 	// parent directory
 	private DocuDirectory parent = null;
 
-
 	/*
 	 * constructors
 	 */
@@ -194,15 +193,21 @@
 			return;
 		}
 		if (fileMeta == null) {
-			// try to read meta-data file
+			// try to read metadata file
 			readMeta();
 			if (fileMeta == null) {
-				// there is no meta data
-				metaChecked = true;
-				return;
+				// try directory metadata
+				if (parent.getDirMeta() != null) {
+					fileMeta = parent.getDirMeta();
+				} else {
+					// no metadata available
+					metaChecked = true;
+					return;
+				}
 			}
 		}
 		metaChecked = true;
+		String s;
 		double dpi = 0;
 		double dpix = 0;
 		double dpiy = 0;
@@ -211,42 +216,58 @@
 		double pixx = 0;
 		double pixy = 0;
 		// DPI is valid for X and Y
-		try {
-			dpi = Double.parseDouble((String) fileMeta.get("dpi"));
-		} catch (NumberFormatException e) {
-		}
-		if (dpi != 0) {
-			resX = dpi;
-			resY = dpi;
-			return;
+		if (fileMeta.containsKey("original-dpi")) {
+			try {
+				dpi = Double.parseDouble((String) fileMeta.get("original-dpi"));
+			} catch (NumberFormatException e) {
+			}
+			if (dpi != 0) {
+				resX = dpi;
+				resY = dpi;
+				return;
+			}
 		}
 		// DPI-X and DPI-Y
-		try {
-			dpix = Double.parseDouble((String) fileMeta.get("dpi-x"));
-			dpiy = Double.parseDouble((String) fileMeta.get("dpi-y"));
-		} catch (NumberFormatException e) {
-		}
-		if ((dpix != 0) && (dpiy != 0)) {
-			resX = dpix;
-			resY = dpiy;
-			return;
+		if (fileMeta.containsKey("original-dpi-x")
+			&& fileMeta.containsKey("original-dpi-y")) {
+			try {
+				dpix =
+					Double.parseDouble((String) fileMeta.get("original-dpi-x"));
+				dpiy =
+					Double.parseDouble((String) fileMeta.get("original-dpi-y"));
+			} catch (NumberFormatException e) {
+			}
+			if ((dpix != 0) && (dpiy != 0)) {
+				resX = dpix;
+				resY = dpiy;
+				return;
+			}
 		}
 		// SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y
-		try {
-			sizex =
-				Double.parseDouble((String) fileMeta.get("original-size-x"));
-			sizey =
-				Double.parseDouble((String) fileMeta.get("original-size-y"));
-			pixx =
-				Double.parseDouble((String) fileMeta.get("original-pixel-x"));
-			pixy =
-				Double.parseDouble((String) fileMeta.get("original-pixel-y"));
-		} catch (NumberFormatException e) {
-		}
-		if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) {
-			resX = pixx / (sizex * 100 / 2.54);
-			resY = pixy / (sizey * 100 / 2.54);
-			return;
+		if (fileMeta.containsKey("original-size-x")
+			&& fileMeta.containsKey("original-size-y")
+			&& fileMeta.containsKey("original-pixel-x")
+			&& fileMeta.containsKey("original-pixel-y")) {
+			try {
+				sizex =
+					Double.parseDouble(
+						(String) fileMeta.get("original-size-x"));
+				sizey =
+					Double.parseDouble(
+						(String) fileMeta.get("original-size-y"));
+				pixx =
+					Double.parseDouble(
+						(String) fileMeta.get("original-pixel-x"));
+				pixy =
+					Double.parseDouble(
+						(String) fileMeta.get("original-pixel-y"));
+			} catch (NumberFormatException e) {
+			}
+			if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) {
+				resX = pixx / (sizex * 100 / 2.54);
+				resY = pixy / (sizey * 100 / 2.54);
+				return;
+			}
 		}
 	}
 
@@ -299,7 +320,7 @@
 	public boolean isMetaChecked() {
 		return metaChecked;
 	}
-	
+
 	/**
 	 * @return
 	 */
@@ -313,5 +334,5 @@
 	public double getResY() {
 		return resY;
 	}
-	
+
 }
--- a/servlet/src/digilib/io/XMLMetaLoader.java	Sat Jul 12 01:26:56 2003 +0200
+++ b/servlet/src/digilib/io/XMLMetaLoader.java	Thu Jul 31 20:56:51 2003 +0200
@@ -56,9 +56,22 @@
 		private String fileName;
 		private String filePath;
 
-		//		public HashMap getData() {
-		//			return meta;
-		//		}
+		/**
+		 * extracts the elements name from either localName ln or qName qn.
+		 * 
+		 * @param ln localName
+		 * @param qn qName
+		 * @return element name
+		 */
+		private String getName(String ln, String qn) {
+			if (ln != null) {
+				if (ln.length() > 0) {
+					return ln;
+				}
+			}
+			// else it's qName (or nothing)
+			return qn;
+		}
 
 		// Parser calls this once at the beginning of a document
 		public void startDocument() throws SAXException {
@@ -74,7 +87,7 @@
 			Attributes atts)
 			throws SAXException {
 
-			String name = (localName != null) ? localName : qName;
+			String name = getName(localName, qName);
 			// open a new tag
 			tags.addLast(name);
 			// start new content (no nesting of tags and content)
@@ -87,6 +100,7 @@
 				// new file tag
 				fileName = null;
 				filePath = null;
+				meta = new HashMap();
 			}
 		}
 
@@ -104,7 +118,7 @@
 			String qName)
 			throws SAXException {
 				
-			String name = (localName != null) ? localName : qName;
+			String name = getName(localName, qName);
 			// exit the tag
 			tags.removeLast();
 			
--- a/servlet/src/digilib/servlet/Scaler.java	Sat Jul 12 01:26:56 2003 +0200
+++ b/servlet/src/digilib/servlet/Scaler.java	Thu Jul 31 20:56:51 2003 +0200
@@ -58,7 +58,7 @@
 public class Scaler extends HttpServlet {
 
 	// digilib servlet version (for all components)
-	public static final String dlVersion = "1.11a1";
+	public static final String dlVersion = "1.11b1";
 
 	// Utils instance with debuglevel
 	Utils util;
@@ -401,6 +401,13 @@
 				fileset.checkMeta();
 				origResX = fileset.getResX();
 				origResY = fileset.getResY();
+				if ((origResX == 0) || (origResY == 0)) {
+					throw new ImageOpException("Missing image DPI information!");
+				}
+
+				if ((paramDDPIX == 0) || (paramDDPIY == 0)) {
+					throw new ImageOpException("Missing display DPI information!");
+				}
 			}
 
 			// check the source image
@@ -422,7 +429,7 @@
 					|| (paramRGBA != null)
 					|| (paramCONT != 0)
 					|| (paramBRGT != 0);
-			boolean imageSendable = mimetypeSendable && ! imagoOptions;
+			boolean imageSendable = mimetypeSendable && !imagoOptions;
 
 			/* if not autoRes and image smaller than requested 
 			 * size then send as is.