changeset 577:3e3e1b7d659f stream

Merge from HEAD 5d80f333828a2305ea0cee84f70ad42b3847249b
author robcast
date Wed, 22 Dec 2010 20:32:41 +0100
parents dad720e9b12b (current diff) 5d80f333828a (diff)
children 42ac8c8e62fd
files client/.classpath client/.project client/.settings/org.eclipse.jdt.core.prefs client/.settings/org.eclipse.wst.common.component client/.settings/org.eclipse.wst.common.project.facet.core.xml client/.settings/org.eclipse.wst.jsdt.ui.superType.container client/.settings/org.eclipse.wst.jsdt.ui.superType.name client/.settings/org.eclipse.wst.ws.service.policy.prefs client/digitallibrary/WEB-INF/classes/Relato.class servlet/.classpath servlet/.project servlet/.settings/org.eclipse.jdt.core.prefs servlet/.settings/org.eclipse.wst.common.component servlet/.settings/org.eclipse.wst.common.project.facet.core.xml servlet/src/digilib/io/DocuDirectory.java servlet/src/digilib/servlet/Scaler.java servlet/src/digilib/servlet/Texter.java
diffstat 19 files changed, 70 insertions(+), 209 deletions(-) [+]
line wrap: on
line diff
--- a/client/.classpath	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
-	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/digilib-servlet"/>
-	<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
-		<attributes>
-			<attribute name="owner.project.facets" value="jst.web"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-6-openjdk">
-		<attributes>
-			<attribute name="owner.project.facets" value="java"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="output" path="build/classes"/>
-</classpath>
--- a/client/.project	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>digilib-client</name>
-	<comment></comment>
-	<projects>
-		<project>digilib-servlet</project>
-		<project>digilib-client</project>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.wst.common.project.facet.core.builder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.wst.validation.validationbuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
-		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
-		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
-	</natures>
-</projectDescription>
--- a/client/.settings/org.eclipse.jdt.core.prefs	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-#Fri Oct 08 14:51:02 CEST 2010
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
--- a/client/.settings/org.eclipse.wst.common.component	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-modules id="moduleCoreId" project-version="1.5.0">
-    <wb-module deploy-name="digilib-client">
-        <wb-resource deploy-path="/" source-path="/digitallibrary"/>
-        <dependent-module archiveName="digilib-servlet.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/digilib-servlet/digilib-servlet">
-            <dependency-type>uses</dependency-type>
-        </dependent-module>
-        <dependent-module deploy-path="/" handle="org.eclipse.jst.j2ee.componentcore.util.ClasspathDependencies">
-            <dependency-type>consumes</dependency-type>
-        </dependent-module>
-        <property name="context-root" value="digitallibrary"/>
-        <property name="java-output-path" value="/digilib-client/build/classes"/>
-    </wb-module>
-</project-modules>
--- a/client/.settings/org.eclipse.wst.common.project.facet.core.xml	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<faceted-project>
-  <runtime name="Apache Tomcat v7.0"/>
-  <fixed facet="wst.jsdt.web"/>
-  <fixed facet="java"/>
-  <fixed facet="jst.web"/>
-  <installed facet="java" version="1.5"/>
-  <installed facet="jst.web" version="2.5"/>
-  <installed facet="wst.jsdt.web" version="1.0"/>
-</faceted-project>
--- a/client/.settings/org.eclipse.wst.jsdt.ui.superType.container	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
--- a/client/.settings/org.eclipse.wst.jsdt.ui.superType.name	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-Window
\ No newline at end of file
--- a/client/.settings/org.eclipse.wst.ws.service.policy.prefs	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-#Fri Oct 08 14:56:13 CEST 2010
-eclipse.preferences.version=1
-org.eclipse.wst.ws.service.policy.projectEnabled=false
Binary file client/digitallibrary/WEB-INF/classes/Relato.class has changed
--- a/client/digitallibrary/dirInfo-xml.jsp	Wed Dec 22 20:19:06 2010 +0100
+++ b/client/digitallibrary/dirInfo-xml.jsp	Wed Dec 22 20:32:41 2010 +0100
@@ -1,3 +1,4 @@
+<%@page import="digilib.io.FileOps"%>
 <%@ page language="java" %><%!
 // create DocumentBean instance for all JSP requests
 digilib.servlet.DocumentBean docBean = new digilib.servlet.DocumentBean();
@@ -22,17 +23,19 @@
 digilib.io.DocuDirCache dirCache = (digilib.io.DocuDirCache) dlConfig.getValue("servlet.dir.cache");
 // get directory
 digilib.io.DocuDirectory dir = dirCache.getDirectory(dlRequest.getFilePath());
+FileOps.FileClass fc = FileOps.FileClass.IMAGE;
+int dirSize = dir.size();
 
 %><!-- Automatically generated XML snippet with directory info -->
+<huhu/>
 <dir><% if (dir != null) { %>
-  <size><%= dir.size() %></size>
+  <size><%= dirSize %></size>
   <name><%= dir.getDirName() %></name>
   <fsname><%= dir.getDir().getPath() %></fsname> 
 <%
     if (!dlRequest.hasOption("mo", "dir")) {
-      int l = dir.size();
-      for (int i = 0; i < l; i++) {
-        digilib.io.DocuDirent f = dir.get(i);
+      for (int i = 0; i < dirSize; i++) {
+        digilib.io.DocuDirent f = dir.get(i, fc);
         String fn = (f != null) ? f.getName() : "null";
 %>  <file>
     <index><%= i+1 %></index>
--- a/servlet/.classpath	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"/>
-	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
-	<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/ImageInfo">
-		<attributes>
-			<attribute name="org.eclipse.jst.component.dependency" value="../"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/iText">
-		<attributes>
-			<attribute name="org.eclipse.jst.component.dependency" value="../"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/JAI">
-		<attributes>
-			<attribute name="org.eclipse.jst.component.dependency" value="../"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/JAI-ImageIO">
-		<attributes>
-			<attribute name="org.eclipse.jst.component.dependency" value="../"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/JDOM">
-		<attributes>
-			<attribute name="org.eclipse.jst.component.dependency" value="../"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/Log4J">
-		<attributes>
-			<attribute name="org.eclipse.jst.component.dependency" value="../"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="output" path="bin"/>
-</classpath>
--- a/servlet/.project	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>digilib-servlet</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.wst.common.project.facet.core.builder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.wst.validation.validationbuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
-		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
-	</natures>
-</projectDescription>
--- a/servlet/.settings/org.eclipse.jdt.core.prefs	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-#Tue Oct 12 18:02:03 CEST 2010
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.6
--- a/servlet/.settings/org.eclipse.wst.common.component	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-modules id="moduleCoreId" project-version="1.5.0">
-    <wb-module deploy-name="digilib-servlet">
-        <wb-resource deploy-path="/" source-path="/src"/>
-    </wb-module>
-</project-modules>
--- a/servlet/.settings/org.eclipse.wst.common.project.facet.core.xml	Wed Dec 22 20:19:06 2010 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<faceted-project>
-  <fixed facet="jst.utility"/>
-  <fixed facet="java"/>
-  <installed facet="java" version="1.6"/>
-  <installed facet="jst.utility" version="1.0"/>
-</faceted-project>
--- a/servlet/src/digilib/servlet/PDFCache.java	Wed Dec 22 20:19:06 2010 +0100
+++ b/servlet/src/digilib/servlet/PDFCache.java	Wed Dec 22 20:32:41 2010 +0100
@@ -182,7 +182,7 @@
         } else if (status == PDFStatus.DONE) {
         	// pdf created -- send it
             try {
-                ServletOps.sendFile(getCacheFile(docid), "application/pdf", getDownloadFilename(pdfji), response);
+                ServletOps.sendFile(getCacheFile(docid), "application/pdf", getDownloadFilename(pdfji), response, logger);
                 //sendFile(docid, getDownloadFilename(pdfji), response);
             } catch (Exception e) {
             	// sending didn't work
--- a/servlet/src/digilib/servlet/Scaler.java	Wed Dec 22 20:19:06 2010 +0100
+++ b/servlet/src/digilib/servlet/Scaler.java	Wed Dec 22 20:32:41 2010 +0100
@@ -44,7 +44,7 @@
     protected static Logger accountlog = Logger.getLogger("account.request");
 
     /** gengeral logger for this class */
-    protected static Logger logger = Logger.getLogger("digilib.servlet");
+    protected static Logger logger = Logger.getLogger("digilib.scaler");
 
     /** logger for authentication related */
     protected static Logger authlog = Logger.getLogger("digilib.auth");
@@ -220,7 +220,7 @@
                     mt = "application/octet-stream";
                 }
                 logger.debug("Sending RAW File as is.");
-                ServletOps.sendFile(fileToLoad.getFile(), mt, null, response);
+                ServletOps.sendFile(fileToLoad.getFile(), mt, null, response, logger);
                 logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms");
                 return;
             }
@@ -228,7 +228,7 @@
             // if possible, send the image without actually having to transform it
             if (! jobTicket.isTransformRequired()) {
                 logger.debug("Sending File as is.");
-                ServletOps.sendFile(fileToLoad.getFile(), null, null, response);
+                ServletOps.sendFile(fileToLoad.getFile(), null, null, response, logger);
                 logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms");
                 return;
             }
@@ -246,7 +246,7 @@
             // wait for result
             DocuImage img = jobResult.get();
             // send image
-            ServletOps.sendImage(img, null, response);
+            ServletOps.sendImage(img, null, response, logger);
             logger.debug("Job Processing Time: "
                     + (System.currentTimeMillis() - startTime) + "ms");
 
@@ -308,7 +308,7 @@
                 response.sendError(status, msg);
             } else if (img != null) {
                 // default: image
-                ServletOps.sendFile(img, null, null, response);
+                ServletOps.sendFile(img, null, null, response, logger);
             }
         } catch (Exception e) {
             logger.error("Error sending error!", e);
--- a/servlet/src/digilib/servlet/ServletOps.java	Wed Dec 22 20:19:06 2010 +0100
+++ b/servlet/src/digilib/servlet/ServletOps.java	Wed Dec 22 20:32:41 2010 +0100
@@ -23,7 +23,6 @@
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
@@ -37,7 +36,6 @@
 
 import digilib.image.DocuImage;
 import digilib.image.ImageOpException;
-import digilib.io.FileOpException;
 import digilib.io.FileOps;
 
 public class ServletOps {
@@ -182,6 +180,32 @@
      * The local file is copied to the <code>OutputStream</code> of the
      * <code>ServletResponse</code>. If mt is null then the mime-type is
      * auto-detected with mimeForFile.
+     * 
+     * @param f
+     *            Image file to be sent.
+     * @param mt
+     *            mime-type of the file.
+     * @param name
+     *            name of the download file (for application/x)
+     * @param res
+     *            ServletResponse where the image file will be sent.
+     * @throws ImageOpException
+     * @throws ServletException
+     *             Exception on sending data.
+     */
+    public static void sendFile(File f, String mt, String name,
+            HttpServletResponse response) throws ImageOpException,
+            ServletException {
+        // use default logger
+        ServletOps.sendFile(f, mt, name, response, ServletOps.logger);
+    }
+
+    /**
+     * Transfers an image file as-is with the mime type mt.
+     * 
+     * The local file is copied to the <code>OutputStream</code> of the
+     * <code>ServletResponse</code>. If mt is null then the mime-type is
+     * auto-detected with mimeForFile.
      * @param f
      *            Image file to be sent.
      * @param mt
@@ -190,10 +214,12 @@
      *            name of the download file (for application/x)
      * @param res
      *            ServletResponse where the image file will be sent.
+     * @param logger
+     *            Logger to use
      * @throws ImageOpException
      * @throws ServletException Exception on sending data.
      */
-    public static void sendFile(File f, String mt, String name, HttpServletResponse response)
+    public static void sendFile(File f, String mt, String name, HttpServletResponse response, Logger logger)
             throws ImageOpException, ServletException {
         logger.debug("sendRawFile(" + mt + ", " + f + ")");
         if (mt == null) {
@@ -243,6 +269,22 @@
     public static void sendImage(DocuImage img, String mimeType,
             HttpServletResponse response) throws ImageOpException,
             ServletException {
+        ServletOps.sendImage(img, mimeType, response, ServletOps.logger);
+    }
+
+    /**
+     * Write image img to ServletResponse response.
+     * 
+     * @param img
+     * @param mimeType
+     * @param response
+     * @param logger
+     * @throws ImageOpException
+     * @throws ServletException Exception on sending data.
+     */
+    public static void sendImage(DocuImage img, String mimeType,
+            HttpServletResponse response, Logger logger) throws ImageOpException,
+            ServletException {
         try {
             OutputStream outstream = response.getOutputStream();
             // setup output -- if mime type is set use that otherwise
--- a/servlet/src/digilib/servlet/Texter.java	Wed Dec 22 20:19:06 2010 +0100
+++ b/servlet/src/digilib/servlet/Texter.java	Wed Dec 22 20:32:41 2010 +0100
@@ -44,8 +44,6 @@
  */
 public class Texter extends HttpServlet {
 
-	private static final long serialVersionUID = -8539178734033662322L;
-
 	/** Servlet version */
 	public static String tlVersion = "0.1b2";
 
@@ -55,6 +53,9 @@
 	/** general logger */
 	Logger logger = Logger.getLogger("digilib.texter");
 
+    /** logger for accounting requests */
+    protected static Logger accountlog = Logger.getLogger("account.texter.request");
+
 	/** FileOps instance */
 	FileOps fileOp;
 
@@ -109,6 +110,7 @@
 	 */
 	protected void doGet(HttpServletRequest request,
 			HttpServletResponse response) throws ServletException, IOException {
+        accountlog.info("GET from " + request.getRemoteAddr());
 		// do the processing
 		processRequest(request, response);
 	}
@@ -121,6 +123,7 @@
 	 */
 	protected void doPost(HttpServletRequest request,
 			HttpServletResponse response) throws ServletException, IOException {
+        accountlog.info("POST from " + request.getRemoteAddr());
 		// do the processing
 		processRequest(request, response);
 	}
@@ -140,11 +143,11 @@
 			 */
 			TextFile f = getTextFile(dlRequest, "/txt");
 			if (f != null) {
-				ServletOps.sendFile(f.getInput(), null, null, response);
+				ServletOps.sendFile(f.getInput(), null, null, response, logger);
 			} else {
 				f = getTextFile(dlRequest, "");
 				if (f != null) {
-					ServletOps.sendFile(f.getInput(),	null, null, response);
+					ServletOps.sendFile(f.getInput(),	null, null, response, logger);
 				} else {
 					response.sendError(HttpServletResponse.SC_NOT_FOUND, "Text-File not found!");
 					//ServletOps.htmlMessage("No Text-File!", response);
@@ -152,13 +155,11 @@
 			}
 			
 		} catch (ImageOpException e) {
-			logger.error("ERROR: File IO Error: ", e);
-			try {
-				ServletOps.htmlMessage("ERROR: File IO Error: " + e, response);
-			} catch (FileOpException ex) {
-			} // so we don't get a loop
-		}
-	}
+            // most likely wrong file format...
+            logger.error("ERROR sending text file: ", e);
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+        }
+    }
 	
 
 	/**