# HG changeset patch
# User robcast
# Date 1292921536 -3600
# Node ID 1f666c2b4578d7e11dad1d5bfffa66222de105f5
# Parent 9936604d466e3c44d8a2609519848f33f2801629# Parent 8beefd1142b28ca9b2433205e7eea82a517bb215
Merge with PDF branch
8beefd1142b28ca9b2433205e7eea82a517bb215
diff -r 9936604d466e -r 1f666c2b4578 client/.classpath
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/.classpath Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 9936604d466e -r 1f666c2b4578 client/.project
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/.project Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,38 @@
+
+
+ digilib-client
+
+
+ digilib-servlet
+ digilib-client
+
+
+
+ org.eclipse.wst.jsdt.core.javascriptValidator
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
+
+ org.eclipse.wst.validation.validationbuilder
+
+
+
+
+
+ org.eclipse.jem.workbench.JavaEMFNature
+ org.eclipse.wst.common.modulecore.ModuleCoreNature
+ org.eclipse.wst.common.project.facet.core.nature
+ org.eclipse.jdt.core.javanature
+ org.eclipse.wst.jsdt.core.jsNature
+
+
diff -r 9936604d466e -r 1f666c2b4578 client/.settings/.jsdtscope
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/.settings/.jsdtscope Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 9936604d466e -r 1f666c2b4578 client/.settings/org.eclipse.jdt.core.prefs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/.settings/org.eclipse.jdt.core.prefs Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,8 @@
+#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
diff -r 9936604d466e -r 1f666c2b4578 client/.settings/org.eclipse.wst.common.component
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/.settings/org.eclipse.wst.common.component Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,14 @@
+
+
+
+
+
+ uses
+
+
+ consumes
+
+
+
+
+
diff -r 9936604d466e -r 1f666c2b4578 client/.settings/org.eclipse.wst.common.project.facet.core.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/.settings/org.eclipse.wst.common.project.facet.core.xml Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff -r 9936604d466e -r 1f666c2b4578 client/.settings/org.eclipse.wst.jsdt.ui.superType.container
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/.settings/org.eclipse.wst.jsdt.ui.superType.container Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,1 @@
+org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
diff -r 9936604d466e -r 1f666c2b4578 client/.settings/org.eclipse.wst.jsdt.ui.superType.name
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/.settings/org.eclipse.wst.jsdt.ui.superType.name Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,1 @@
+Window
\ No newline at end of file
diff -r 9936604d466e -r 1f666c2b4578 client/.settings/org.eclipse.wst.ws.service.policy.prefs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/.settings/org.eclipse.wst.ws.service.policy.prefs Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,3 @@
+#Fri Oct 08 14:56:13 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.wst.ws.service.policy.projectEnabled=false
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/META-INF/MANIFEST.MF
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/digitallibrary/META-INF/MANIFEST.MF Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/WEB-INF/classes/Relato.java
--- a/client/digitallibrary/WEB-INF/classes/Relato.java Wed Jul 14 16:36:42 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-import java.io.*;
-import java.net.*;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
-import javax.xml.transform.*;
-import javax.xml.transform.dom.*;
-import javax.xml.transform.stream.*;
-import org.apache.xerces.parsers.DOMParser;
-import org.apache.xpath.*;
-import org.w3c.dom.*;
-
-public class Relato extends HttpServlet {
-
- public final static String FS = System.getProperty("file.separator");
-
- // Respond to HTTP GET requests from browsers.
- public void doGet (HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
-
- Hashtable params = new Hashtable();
- Enumeration enum = request.getParameterNames();
- while (enum.hasMoreElements()) {
- String pName = (String) enum.nextElement();
- params.put(pName, request.getParameter(pName));
-
- }
- // Set content type for HTML.
- response.setContentType("text/html; charset=UTF-8");
- // Output goes to the response PrintWriter.
- PrintWriter out = response.getWriter();
- DOMParser parser = new DOMParser();
-
- try {
- TransformerFactory tFactory = TransformerFactory.newInstance();
- //get the real path for xml and xsl files.
- String ctx = getServletContext().getRealPath("") + FS;
-
- parser.parse(ctx + (String) params.get("xml"));
- Document document = parser.getDocument();
-
- Element topFrameset = (Element) XPathAPI.selectSingleNode(document, "/relato/frames/frameset");
- topFrameset.setAttribute("onload", "init();");
-
- NodeList nodelist = XPathAPI.selectNodeList(document, "//frameset/frame");
- for (int i = 0; i < nodelist.getLength(); i++) {
- Element elem = (Element)nodelist.item(i);
- String name = elem.getAttribute("name");
- if (name != "") {
- if (params.containsKey(name)) {
- String src = (String) params.get(name);
- elem.setAttribute("src", src);
- }
- }
- }
-
- Source xmlSource = new DOMSource (document);
- Source xslSource = new StreamSource (new URL("file", "", ctx+"relato/relato.xsl").openStream());
- // Generate the transformer.
- Transformer transformer = tFactory.newTransformer(xslSource);
- // Perform the transformation, sending the output to the response.
- transformer.transform(xmlSource, new StreamResult(out));
- }
-
- // If an Exception occurs, return the error to the client.
- catch (Exception e) {
- out.write(e.getMessage());
- e.printStackTrace(out);
- }
-
- // Close the PrintWriter.
- out.close();
- }
-}
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/WEB-INF/digilib-config.xml
--- a/client/digitallibrary/WEB-INF/digilib-config.xml Wed Jul 14 16:36:42 2010 +0200
+++ b/client/digitallibrary/WEB-INF/digilib-config.xml Tue Dec 21 09:52:16 2010 +0100
@@ -58,5 +58,15 @@
+
+
+
+
+
+
+
+
+
+
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/WEB-INF/lib/DigilibServlet.jar
Binary file client/digitallibrary/WEB-INF/lib/DigilibServlet.jar has changed
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/WEB-INF/lib/imageinfo.jar
Binary file client/digitallibrary/WEB-INF/lib/imageinfo.jar has changed
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/WEB-INF/web.xml
--- a/client/digitallibrary/WEB-INF/web.xml Wed Jul 14 16:36:42 2010 +0200
+++ b/client/digitallibrary/WEB-INF/web.xml Tue Dec 21 09:52:16 2010 +0100
@@ -54,40 +54,16 @@
digilib.servlet.Texter
-
-
-
- Raster
-
-
- The servlet for rastered SVG.
-
-
- digilib.servlet.Raster
-
-
-
+
- Mapper
+ PDFCache
- The servlet to create image maps.
+ The servlet for PDF.
- digilib.servlet.Mapper
-
-
-
-
-
- Relato
-
-
- The relato servlet
-
-
- Relato
+ digilib.servlet.PDFCache
@@ -145,47 +121,21 @@
/authenticated/servlet/Texter/*
-
+
- Raster
+ PDFCache
- /servlet/Raster/*
+ /servlet/PDFCache/*
- Raster
-
-
- /authenticated/servlet/Raster/*
-
-
-
-
-
- Mapper
+ PDFCache
- /servlet/Mapper/*
-
-
-
-
- Mapper
-
-
- /authenticated/servlet/Mapper/*
-
-
-
-
-
- Relato
-
-
- /Relato
+ /authenticated/servlet/PDFCache/*
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/digilib-new.html
--- a/client/digitallibrary/digilib-new.html Wed Jul 14 16:36:42 2010 +0200
+++ b/client/digitallibrary/digilib-new.html Tue Dec 21 09:52:16 2010 +0100
@@ -37,7 +37,7 @@
-
-
-
-
-
-
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/greyskin/digimage_img_inc.jsp
--- a/client/digitallibrary/greyskin/digimage_img_inc.jsp Wed Jul 14 16:36:42 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-<%@ page language="java" %><%
-// retrieve objects from context
-digilib.servlet.DocumentBean docBean = (digilib.servlet.DocumentBean) pageContext.getAttribute("docBean", pageContext.REQUEST_SCOPE);
-digilib.servlet.DigilibRequest dlRequest = docBean.getRequest();
-String ua = request.getHeader("User-Agent");
-boolean isN4 = ((ua.indexOf("Mozilla/4.") > -1)&&(ua.indexOf("MSIE") == -1));
-%>
-<%
- if (isN4) {
-%><%
- } else {
-%><%
- }
-%>
-
-<%
- if (isN4) {
-%><%
- } else {
-%>
<%
- }
-%>
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/greyskin/digimage_tbl_inc.jsp
--- a/client/digitallibrary/greyskin/digimage_tbl_inc.jsp Wed Jul 14 16:36:42 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-<%@ page language="java" %><%
-// retrieve objects from context
-digilib.servlet.DocumentBean docBean = (digilib.servlet.DocumentBean) pageContext.getAttribute("docBean", pageContext.REQUEST_SCOPE);
-digilib.servlet.DigilibRequest dlRequest = docBean.getRequest();
-String ua = request.getHeader("User-Agent");
-boolean isN4 = ((ua.indexOf("Mozilla/4.") > -1)&&(ua.indexOf("MSIE") == -1));
-%>
-
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/greyskin/diginew.jsp
--- a/client/digitallibrary/greyskin/diginew.jsp Wed Jul 14 16:36:42 2010 +0200
+++ b/client/digitallibrary/greyskin/diginew.jsp Tue Dec 21 09:52:16 2010 +0100
@@ -28,7 +28,7 @@
// add number of pages
dlRequest.setValue("pt", docBean.getNumPages());
// store objects for jsp:include
- pageContext.setAttribute("docBean", docBean, pageContext.REQUEST_SCOPE);
+ pageContext.setAttribute("docBean", docBean, PageContext.REQUEST_SCOPE);
%>
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/pdf/error.jsp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/digitallibrary/pdf/error.jsp Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,13 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+ pageEncoding="ISO-8859-1"%>
+
+
+
+
+Error
+
+
+Error
+There was an error while processing your request. Please check the parameters and try again.
+
+
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/pdf/wip.jsp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/digitallibrary/pdf/wip.jsp Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,14 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+ pageEncoding="ISO-8859-1"%>
+
+
+
+
+
+Work in progress ...
+
+
+Please wait ...
+your request is being processed. The download starts automatically when the document is finished.
+
+
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/server/dlConfig.jsp
--- a/client/digitallibrary/server/dlConfig.jsp Wed Jul 14 16:36:42 2010 +0200
+++ b/client/digitallibrary/server/dlConfig.jsp Tue Dec 21 09:52:16 2010 +0100
@@ -1,3 +1,4 @@
+<%@page import="digilib.util.DigilibJobCenter"%>
<%@ page language="java" %>
<%!
@@ -26,6 +27,9 @@
dlRequest.setValue("pt", docBean.getNumPages(dlRequest));
// dir cache
digilib.io.DocuDirCache dirCache = (digilib.io.DocuDirCache) dlConfig.getValue("servlet.dir.cache");
+// image JobCenter
+DigilibJobCenter imageProcessor = (DigilibJobCenter)dlConfig.getValue("servlet.worker.imageexecutor");
+
%>
@@ -38,7 +42,7 @@
<%
- Object[] keys = dlConfig.keySet().toArray();
+ Object[] keys = dlConfig.getParams().keySet().toArray();
java.util.Arrays.sort(keys);
int l = keys.length;
for (int i = 0; i < l; i++) {
@@ -70,11 +74,11 @@
- currently waiting | <%= digilib.servlet.DigilibWorker.getNumWaiting() %> |
+ currently waiting | <%= imageProcessor.getWaitingJobs() %> |
|
- currently running | <%= digilib.servlet.DigilibWorker.getNumRunning() %> |
+ currently running | <%= imageProcessor.getRunningJobs() %> |
|
diff -r 9936604d466e -r 1f666c2b4578 client/digitallibrary/server/dlRequest.jsp
--- a/client/digitallibrary/server/dlRequest.jsp Wed Jul 14 16:36:42 2010 +0200
+++ b/client/digitallibrary/server/dlRequest.jsp Tue Dec 21 09:52:16 2010 +0100
@@ -93,7 +93,7 @@
<%
- Object[] keys = dlRequest.keySet().toArray();
+ Object[] keys = dlRequest.getParams().keySet().toArray();
java.util.Arrays.sort(keys);
int l = keys.length;
for (int i = 0; i < l; i++) {
diff -r 9936604d466e -r 1f666c2b4578 servlet/.classpath
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/.classpath Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 9936604d466e -r 1f666c2b4578 servlet/.project
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/.project Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,30 @@
+
+
+ digilib-servlet
+
+
+
+
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.wst.validation.validationbuilder
+
+
+
+
+
+ org.eclipse.jem.workbench.JavaEMFNature
+ org.eclipse.wst.common.modulecore.ModuleCoreNature
+ org.eclipse.jdt.core.javanature
+ org.eclipse.wst.common.project.facet.core.nature
+
+
diff -r 9936604d466e -r 1f666c2b4578 servlet/.settings/org.eclipse.jdt.core.prefs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/.settings/org.eclipse.jdt.core.prefs Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,12 @@
+#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
diff -r 9936604d466e -r 1f666c2b4578 servlet/.settings/org.eclipse.wst.common.component
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/.settings/org.eclipse.wst.common.component Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff -r 9936604d466e -r 1f666c2b4578 servlet/.settings/org.eclipse.wst.common.project.facet.core.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/.settings/org.eclipse.wst.common.project.facet.core.xml Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/META-INF/MANIFEST.MF
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/src/META-INF/MANIFEST.MF Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/auth/AuthOps.java
--- a/servlet/src/digilib/auth/AuthOps.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/auth/AuthOps.java Tue Dec 21 09:52:16 2010 +0100
@@ -81,7 +81,7 @@
* @throws AuthOpException Exception thrown on error.
* @return List of Strings with role names.
*/
- public List rolesForPath(String filepath, HttpServletRequest request)
+ public List rolesForPath(String filepath, HttpServletRequest request)
throws AuthOpException;
/** Authorization roles needed for request.
@@ -95,7 +95,7 @@
* @throws AuthOpException Exception thrown on error.
* @return List of Strings with role names.
*/
- public List rolesForPath(DigilibRequest request)
+ public List rolesForPath(DigilibRequest request)
throws AuthOpException;
/** Test request authorization against a list of roles.
@@ -103,13 +103,13 @@
* @param request ServletRequest with address information.
* @return true if the user information in the request authorizes one of the roles.
*/
- public boolean isRoleAuthorized(List roles, HttpServletRequest request);
+ public boolean isRoleAuthorized(List roles, HttpServletRequest request);
/** Test request authorization against a list of roles.
* @param roles List of Strings with role names.
* @param request ServletRequest with address information.
* @return true if the user information in the request authorizes one of the roles.
*/
- public boolean isRoleAuthorized(List roles, DigilibRequest request);
+ public boolean isRoleAuthorized(List roles, DigilibRequest request);
}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/auth/AuthOpsImpl.java
--- a/servlet/src/digilib/auth/AuthOpsImpl.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/auth/AuthOpsImpl.java Tue Dec 21 09:52:16 2010 +0100
@@ -21,7 +21,6 @@
package digilib.auth;
import java.util.List;
-import java.util.ListIterator;
import javax.servlet.http.HttpServletRequest;
@@ -56,7 +55,7 @@
*/
public boolean isAuthRequired(String filepath, HttpServletRequest request) throws AuthOpException {
// check permissions
- List rolesRequired = rolesForPath(filepath, request);
+ List rolesRequired = rolesForPath(filepath, request);
return (rolesRequired != null);
}
@@ -66,7 +65,7 @@
public boolean isAuthRequired(DigilibRequest request)
throws AuthOpException {
// check permissions
- List rolesRequired = rolesForPath(request);
+ List rolesRequired = rolesForPath(request);
return (rolesRequired != null);
}
@@ -80,7 +79,7 @@
* @return List of Strings with role names.
*/
public boolean isAuthorized(String filepath, HttpServletRequest request) throws AuthOpException {
- List rolesAllowed = rolesForPath(filepath, request);
+ List rolesAllowed = rolesForPath(filepath, request);
return isRoleAuthorized(rolesAllowed, request);
}
@@ -89,7 +88,7 @@
*/
public boolean isAuthorized(DigilibRequest request)
throws AuthOpException {
- List rolesAllowed = rolesForPath(request);
+ List rolesAllowed = rolesForPath(request);
return isRoleAuthorized(rolesAllowed, request);
}
@@ -98,11 +97,8 @@
* @param request ServletRequest with address information.
* @return true if the user information in the request authorizes one of the roles.
*/
- public boolean isRoleAuthorized(List roles, HttpServletRequest request) {
- ListIterator r = roles.listIterator();
- String s = "";
- while (r.hasNext()) {
- s = (String)r.next();
+ public boolean isRoleAuthorized(List roles, HttpServletRequest request) {
+ for (String s: roles) {
logger.debug("Testing role: "+s);
if (request.isUserInRole(s)) {
logger.debug("Role Authorized");
@@ -115,11 +111,8 @@
/**
* @see digilib.auth.AuthOps#isRoleAuthorized(java.util.List, digilib.servlet.DigilibRequest)
*/
- public boolean isRoleAuthorized(List roles, DigilibRequest request) {
- ListIterator r = roles.listIterator();
- String s = "";
- while (r.hasNext()) {
- s = (String)r.next();
+ public boolean isRoleAuthorized(List roles, DigilibRequest request) {
+ for (String s: roles) {
logger.debug("Testing role: "+s);
if (((HttpServletRequest)request.getServletRequest()).isUserInRole(s)) {
logger.debug("Role Authorized");
@@ -131,8 +124,8 @@
public abstract void init() throws AuthOpException;
- public abstract List rolesForPath(String filepath, HttpServletRequest request) throws AuthOpException;
+ public abstract List rolesForPath(String filepath, HttpServletRequest request) throws AuthOpException;
- public abstract List rolesForPath(DigilibRequest request) throws AuthOpException;
+ public abstract List rolesForPath(DigilibRequest request) throws AuthOpException;
}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/auth/HashTree.java
--- a/servlet/src/digilib/auth/HashTree.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/auth/HashTree.java Tue Dec 21 09:52:16 2010 +0100
@@ -20,7 +20,10 @@
package digilib.auth;
-import java.util.*;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
/**
* Tree representation wrapper for a HashMap.
@@ -37,7 +40,7 @@
*/
public class HashTree {
- private Map table;
+ private Map table;
private String twigSep = "/";
@@ -53,7 +56,7 @@
* @param twig_separator
* @param leaf_separator
*/
- public HashTree(Map t, String twig_separator, String leaf_separator) {
+ public HashTree(Map t, String twig_separator, String leaf_separator) {
table = t;
twigSep = twig_separator;
leafSep = leaf_separator;
@@ -73,10 +76,10 @@
* @param branch
* @return
*/
- List match(String branch) {
+ List match(String branch) {
String b = "";
String m;
- LinkedList matches = new LinkedList();
+ LinkedList matches = new LinkedList();
// split branch
StringTokenizer twig = new StringTokenizer(branch, twigSep);
@@ -87,7 +90,7 @@
} else {
b += twigSep + twig.nextToken();
}
- m = (String) table.get(b);
+ m = table.get(b);
if (m != null) {
if (m.indexOf(leafSep) < 0) {
// single leaf
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/auth/XMLAuthOps.java
--- a/servlet/src/digilib/auth/XMLAuthOps.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/auth/XMLAuthOps.java Tue Dec 21 09:52:16 2010 +0100
@@ -69,8 +69,8 @@
*/
public void init() throws AuthOpException {
logger.debug("xmlauthops.init (" + configFile + ")");
- Map pathList = null;
- Map ipList = null;
+ Map pathList = null;
+ Map ipList = null;
try {
// load authPaths
XMLListLoader pathLoader =
@@ -105,7 +105,7 @@
* @throws AuthOpException Exception thrown on error.
* @return List of Strings with role names.
*/
- public List rolesForPath(String filepath, HttpServletRequest request)
+ public List rolesForPath(String filepath, HttpServletRequest request)
throws digilib.auth.AuthOpException {
logger.debug("rolesForPath ("
+ filepath
@@ -114,13 +114,13 @@
+ "]");
// check if the requests address provides a role
- List provided = authIPs.match(request.getRemoteAddr());
+ List provided = authIPs.match(request.getRemoteAddr());
if ((provided != null) && (provided.contains("ALL"))) {
// ALL switches off checking;
return null;
}
// which roles are required?
- List required = authPaths.match(filepath);
+ List required = authPaths.match(filepath);
// do any provided roles match?
if ((provided != null) && (required != null)) {
for (int i = 0; i < provided.size(); i++) {
@@ -136,7 +136,7 @@
/**
* @see digilib.auth.AuthOps#rolesForPath(digilib.servlet.DigilibRequest)
*/
- public List rolesForPath(DigilibRequest request) throws AuthOpException {
+ public List rolesForPath(DigilibRequest request) throws AuthOpException {
logger.debug("rolesForPath ("
+ request.getFilePath()
+ ") by ["
@@ -144,14 +144,14 @@
+ "]");
// check if the requests address provides a role
- List provided =
+ List provided =
authIPs.match(request.getServletRequest().getRemoteAddr());
if ((provided != null) && (provided.contains("ALL"))) {
// ALL switches off checking;
return null;
}
// which roles are required?
- List required = authPaths.match(request.getFilePath());
+ List required = authPaths.match(request.getFilePath());
// do any provided roles match?
if ((provided != null) && (required != null)) {
for (int i = 0; i < provided.size(); i++) {
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/image/DocuImage.java
--- a/servlet/src/digilib/image/DocuImage.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/image/DocuImage.java Tue Dec 21 09:52:16 2010 +0100
@@ -214,11 +214,17 @@
/**
* Check image size and type and store in ImageFile f
*/
- public boolean identify(ImageFile imgf) throws IOException;
+ public ImageFile identify(ImageFile imgf) throws IOException;
/**
* Returns a list of supported image formats
*/
- public Iterator getSupportedFormats();
+ public Iterator getSupportedFormats();
+
+ /**
+ * returns the underlying image as java.awt.Image (if possible, or null)
+ * @return
+ */
+ public java.awt.Image getAwtImage();
}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/image/DocuImageImpl.java
--- a/servlet/src/digilib/image/DocuImageImpl.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/image/DocuImageImpl.java Tue Dec 21 09:52:16 2010 +0100
@@ -20,16 +20,15 @@
package digilib.image;
+import java.awt.Image;
import java.awt.Rectangle;
-import java.io.File;
import java.io.IOException;
-import java.io.RandomAccessFile;
+import java.io.OutputStream;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.log4j.Logger;
-import org.marcoschmidt.image.ImageInfo;
import digilib.io.FileOpException;
import digilib.io.ImageFile;
@@ -37,7 +36,7 @@
/** Simple abstract implementation of the DocuImage
interface.
*
* This implementation provides basic functionality for the utility methods like
- * SetUtils
, and getKnownFileTypes
. Image methods like
+ * getKnownFileTypes
. Image methods like
* loadImage
, writeImage
, getWidth
,
* getHeight
, crop
and scale
must be
* implemented by derived classes.
@@ -72,34 +71,7 @@
this.quality = quality;
}
- /** Check image size and type and store in ImageFile f */
- public boolean identify(ImageFile imgf) throws IOException {
- // fileset to store the information
- File f = imgf.getFile();
- if (f == null) {
- throw new IOException("File not found!");
- }
- RandomAccessFile raf = new RandomAccessFile(f, "r");
- // set up ImageInfo object
- ImageInfo iif = new ImageInfo();
- iif.setInput(raf);
- iif.setCollectComments(false);
- iif.setDetermineImageNumber(false);
- logger.debug("identifying (ImageInfo) " + f);
- // try with ImageInfo first
- if (iif.check()) {
- ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight());
- imgf.setSize(d);
- imgf.setMimetype(iif.getMimeType());
- //logger.debug(" format:"+iif.getFormatName());
- raf.close();
- logger.debug("image size: " + imgf.getSize());
- return true;
- }
- return false;
- }
-
- /** Crop and scale the current image.
+ /** Crop and scale the current image.
*
* The current image is cropped to a rectangle of width, height at position
* x_off, y_off. The resulting image is scaled by the factor scale using the
@@ -116,7 +88,7 @@
public void cropAndScale(
int x_off, int y_off, int width, int height, double scale, int qual)
throws ImageOpException {
-
+ // default implementation: first crop, then scale
setQuality(qual);
crop(x_off, y_off, width, height);
scale(scale, scale);
@@ -126,6 +98,14 @@
return mimeType;
}
+ /* (non-Javadoc)
+ * @see digilib.image.DocuImage#identify(digilib.io.ImageFile)
+ */
+ public ImageFile identify(ImageFile imgf) throws IOException {
+ // just a do-nothing implementation
+ return null;
+ }
+
public void rotate(double angle) throws ImageOpException {
// just a do-nothing implementation
}
@@ -157,10 +137,44 @@
// emtpy implementation
}
- public Iterator getSupportedFormats() {
- List empty = new LinkedList();
+ public Iterator getSupportedFormats() {
+ List empty = new LinkedList();
return empty.iterator();
}
-
+
+ public void crop(int xoff, int yoff, int width, int height)
+ throws ImageOpException {
+ // TODO Auto-generated method stub
+ }
+
+ public Image getAwtImage() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getHeight() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+ public int getWidth() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public void loadImage(ImageFile f) throws FileOpException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void scale(double scaleX, double scaleY) throws ImageOpException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void writeImage(String mt, OutputStream ostream)
+ throws FileOpException {
+ // TODO Auto-generated method stub
+ }
+
}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/image/ImageInfoDocuImage.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/src/digilib/image/ImageInfoDocuImage.java Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,51 @@
+/**
+ *
+ */
+package digilib.image;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+import org.marcoschmidt.image.ImageInfo;
+
+import digilib.io.ImageFile;
+
+/** Simple abstract implementation of the DocuImage
interface.
+ * Implements only the identify method using the ImageInfo class.
+ * @author casties
+ *
+ */
+public abstract class ImageInfoDocuImage extends DocuImageImpl {
+
+ /** Check image size and type and store in ImageFile f */
+ public ImageFile identify(ImageFile imgf) throws IOException {
+ // fileset to store the information
+ File f = imgf.getFile();
+ if (f == null) {
+ throw new IOException("File not found!");
+ }
+ RandomAccessFile raf = new RandomAccessFile(f, "r");
+ // set up ImageInfo object
+ ImageInfo iif = new ImageInfo();
+ iif.setInput(raf);
+ iif.setCollectComments(false);
+ iif.setDetermineImageNumber(false);
+ logger.debug("identifying (ImageInfo) " + f);
+ // try with ImageInfo first
+ if (iif.check()) {
+ ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight());
+ imgf.setSize(d);
+ imgf.setMimetype(iif.getMimeType());
+ //logger.debug(" format:"+iif.getFormatName());
+ raf.close();
+ logger.debug("image size: " + imgf.getSize());
+ return imgf;
+ } else {
+ raf.close();
+ }
+ return null;
+ }
+
+
+}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/image/ImageJobDescription.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/src/digilib/image/ImageJobDescription.java Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,492 @@
+package digilib.image;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import digilib.io.DocuDirCache;
+import digilib.io.DocuDirectory;
+import digilib.io.FileOpException;
+import digilib.io.FileOps;
+import digilib.io.FileOps.FileClass;
+import digilib.io.ImageFile;
+import digilib.io.ImageFileset;
+import digilib.servlet.DigilibConfiguration;
+import digilib.util.OptionsSet;
+import digilib.util.Parameter;
+import digilib.util.ParameterMap;
+
+
+/**
+ * A container class for storing a set of instructional parameters
+ * used for content generating classes like MakePDF.
+ *
+ * This contains the functionality formerly found in Scaler, processRequest, only factorized.
+ *
+ * TODO clean up...
+ *
+ * @author cmielack, casties
+ *
+ */
+
+public class ImageJobDescription extends ParameterMap {
+
+ DigilibConfiguration dlConfig = null;
+ protected static Logger logger = Logger.getLogger("digilib.servlet");
+
+ ImageFile fileToLoad = null;
+ ImageFileset fileset = null;
+ DocuDirectory fileDir = null;
+ String filePath = null;
+ ImageSize expectedSourceSize = null;
+ Float scaleXY = null;
+ Rectangle2D userImgArea = null;
+ Rectangle2D outerUserImgArea= null;
+ Boolean imageSendable = null;
+ String mimeType;
+ Integer paramDW;
+ Integer paramDH;
+
+ /** create empty ImageJobDescription.
+ * @param dlcfg
+ */
+ public ImageJobDescription(DigilibConfiguration dlcfg) {
+ super(30);
+ dlConfig = dlcfg;
+ }
+
+
+ /** set up Parameters
+ * @see digilib.util.ParameterMap#initParams()
+ */
+ @Override
+ protected void initParams() {
+ // url of the page/document (second part)
+ newParameter("fn", "", null, 's');
+ // page number
+ newParameter("pn", new Integer(1), null, 's');
+ // width of client in pixels
+ newParameter("dw", new Integer(0), null, 's');
+ // height of client in pixels
+ newParameter("dh", new Integer(0), null, 's');
+ // left edge of image (float from 0 to 1)
+ newParameter("wx", new Float(0), null, 's');
+ // top edge in image (float from 0 to 1)
+ newParameter("wy", new Float(0), null, 's');
+ // width of image (float from 0 to 1)
+ newParameter("ww", new Float(1), null, 's');
+ // height of image (float from 0 to 1)
+ newParameter("wh", new Float(1), null, 's');
+ // scale factor
+ newParameter("ws", new Float(1), null, 's');
+ // special options like 'fit' for gifs
+ newParameter("mo", this.options, null, 's');
+ // rotation angle (degree)
+ newParameter("rot", new Float(0), null, 's');
+ // contrast enhancement factor
+ newParameter("cont", new Float(0), null, 's');
+ // brightness enhancement factor
+ newParameter("brgt", new Float(0), null, 's');
+ // color multiplicative factors
+ newParameter("rgbm", "0/0/0", null, 's');
+ // color additive factors
+ newParameter("rgba", "0/0/0", null, 's');
+ // display dpi resolution (total)
+ newParameter("ddpi", new Float(0), null, 's');
+ // display dpi X resolution
+ newParameter("ddpix", new Float(0), null, 's');
+ // display dpi Y resolution
+ newParameter("ddpiy", new Float(0), null, 's');
+ // scale factor for mo=ascale
+ newParameter("scale", new Float(1), null, 's');
+ }
+
+
+ /* (non-Javadoc)
+ * @see digilib.servlet.ParameterMap#initOptions()
+ */
+ @Override
+ protected void initOptions() {
+ String s = this.getAsString("mo");
+ options = new OptionsSet(s);
+ }
+
+
+ /** Creates new ImageJobDescription by merging Parameters from another ParameterMap.
+ * @param pm
+ * @param dlcfg
+ * @return
+ */
+ public static ImageJobDescription getInstance(ParameterMap pm, DigilibConfiguration dlcfg) {
+ ImageJobDescription newMap = new ImageJobDescription(dlcfg);
+ // add all params to this map
+ newMap.params.putAll(pm.getParams());
+ newMap.initOptions();
+ return newMap;
+ }
+
+
+ public String getMimeType() throws IOException {
+ if (mimeType == null) {
+ fileToLoad = getFileToLoad();
+ if(! fileToLoad.isChecked()){
+ DigilibConfiguration.docuImageIdentify(fileToLoad);
+ }
+ mimeType = fileToLoad.getMimetype();
+ }
+ return mimeType;
+ }
+
+ public ImageFile getFileToLoad() throws IOException {
+
+ if(fileToLoad == null){
+ fileset = getFileset();
+
+ /* select a resolution */
+ if (getHiresOnly()) {
+ // get first element (= highest resolution)
+ fileToLoad = fileset.getBiggest();
+ } else if (getLoresOnly()) {
+ // enforced lores uses next smaller resolution
+ fileToLoad = fileset.getNextSmaller(getExpectedSourceSize());
+ if (fileToLoad == null) {
+ // this is the smallest we have
+ fileToLoad = fileset.getSmallest();
+ }
+ } else {
+ // autores: use next higher resolution
+ fileToLoad = fileset.getNextBigger(getExpectedSourceSize());
+ if (fileToLoad == null) {
+ // this is the highest we have
+ fileToLoad = fileset.getBiggest();
+ }
+ }
+ logger.info("Planning to load: " + fileToLoad.getFile());
+ }
+
+ return fileToLoad;
+
+ }
+
+ public DocuDirectory getFileDirectory() throws FileOpException {
+ if(fileDir == null){
+ DocuDirCache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache");
+ String fp = getFilePath();
+ fileDir = dirCache.getDirectory(fp);
+ if (fileDir == null) {
+ throw new FileOpException("Directory " + getFilePath() + " not found.");
+ }
+ }
+ return fileDir;
+ }
+
+ public ImageFileset getFileset() throws FileOpException {
+ if(fileset==null){
+ DocuDirCache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache");
+
+ fileset = (ImageFileset) dirCache.getFile(getFilePath(), getAsInt("pn"), FileClass.IMAGE);
+ if (fileset == null) {
+ throw new FileOpException("File " + getFilePath() + "("
+ + getAsInt("pn") + ") not found.");
+ }
+ }
+ return fileset;
+ }
+
+ public String getFilePath() {
+ if(filePath == null){
+ String s = this.getAsString("request.path");
+ s += this.getAsString("fn");
+ filePath = FileOps.normalName(s);
+ }
+ return filePath;
+ }
+
+ public boolean getHiresOnly(){
+ return hasOption("clip") || hasOption("hires");
+ }
+
+ public boolean getLoresOnly(){
+ return hasOption("lores");
+ }
+
+ public boolean getScaleToFit() {
+ return !(hasOption("clip") || hasOption("osize") || hasOption("ascale"));
+ }
+
+ public boolean getAbsoluteScale(){
+ return hasOption("osize") || hasOption("ascale");
+ }
+
+
+ public ImageSize getExpectedSourceSize() throws IOException {
+ if (expectedSourceSize == null){
+ expectedSourceSize = new ImageSize();
+ if (getScaleToFit()) {
+ // scale to fit -- calculate minimum source size
+ float scale = (1 / Math.min(getAsFloat("ww"), getAsFloat("wh"))) * getAsFloat("ws");
+ expectedSourceSize.setSize((int) (getDw() * scale),
+ (int) (getDh() * scale));
+ } else if (getAbsoluteScale() && hasOption("ascale")) {
+ // absolute scale -- apply scale to hires size
+ expectedSourceSize = getHiresSize().getScaled(getAsFloat("scale"));
+ } else {
+ // clip to fit -- source = destination size
+ expectedSourceSize.setSize((int) (getDw() * getAsFloat("ws")),
+ (int) (getDh() * getAsFloat("ws")));
+ }
+ }
+ return expectedSourceSize;
+ }
+
+ public ImageSize getHiresSize() throws IOException {
+ logger.debug("get_hiresSize()");
+
+ ImageSize hiresSize = null;
+ ImageFileset fileset = getFileset();
+ if (getAbsoluteScale()) {
+ ImageFile hiresFile = fileset.getBiggest();
+ if (!hiresFile.isChecked()) {
+ DigilibConfiguration.docuImageIdentify(hiresFile);
+ }
+ hiresSize = hiresFile.getSize();
+ }
+ return hiresSize;
+ }
+
+ /** Returns image scaling factor.
+ * Uses image size and user parameters.
+ * Modifies scaleXY, userImgArea.
+ * @return
+ * @throws IOException
+ * @throws ImageOpException
+ */
+ public float getScaleXY() throws IOException, ImageOpException {
+ //logger.debug("get_scaleXY()");
+ if(scaleXY == null){
+ // coordinates and scaling
+ float areaWidth;
+ float areaHeight;
+ float ws = getAsFloat("ws");
+ ImageSize imgSize = getFileToLoad().getSize();
+ // user window area in [0,1] coordinates
+ Rectangle2D relUserArea = new Rectangle2D.Float(getAsFloat("wx"), getAsFloat("wy"),
+ getAsFloat("ww"), getAsFloat("wh"));
+ // transform from relative [0,1] to image coordinates.
+ AffineTransform imgTrafo = AffineTransform.getScaleInstance(imgSize
+ .getWidth(), imgSize.getHeight());
+ // transform user coordinate area to image coordinate area
+ userImgArea = imgTrafo.createTransformedShape(
+ relUserArea).getBounds2D();
+
+ if (getScaleToFit()) {
+ // calculate scaling factors based on inner user area
+ areaWidth = (float) userImgArea.getWidth();
+ areaHeight = (float) userImgArea.getHeight();
+ float scaleX = getDw() / areaWidth * ws;
+ float scaleY = getDh() / areaHeight * ws;
+ scaleXY = (scaleX > scaleY) ? scaleY : scaleX;
+ } else if (getAbsoluteScale()) {
+ // absolute scaling factor
+ if (hasOption("osize")) {
+ // get original resolution from metadata
+ fileset.checkMeta();
+ float origResX = fileset.getResX();
+ float origResY = fileset.getResY();
+ if ((origResX == 0) || (origResY == 0)) {
+ throw new ImageOpException("Missing image DPI information!");
+ }
+ if ((getAsFloat("ddpix") == 0) || (getAsFloat("ddpiy") == 0)) {
+ throw new ImageOpException("Missing display DPI information!");
+ }
+ // calculate absolute scale factor
+ float sx = getAsFloat("ddpix") / origResX;
+ float sy = getAsFloat("ddpiy") / origResY;
+ // currently only same scale -- mean value
+ scaleXY = (sx + sy) / 2f;
+ } else {
+ scaleXY = getAsFloat("scale");
+ }
+ // we need to correct the factor if we use a pre-scaled image
+ ImageSize hiresSize = getHiresSize();
+ if (imgSize.getWidth() != hiresSize.getWidth()) {
+ scaleXY *= (float)hiresSize.getWidth() / (float)imgSize.getWidth();
+ }
+ areaWidth = getDw() / scaleXY * ws;
+ areaHeight = getDh() / scaleXY * ws;
+ // reset user area size
+ userImgArea.setRect(userImgArea.getX(), userImgArea.getY(),
+ areaWidth, areaHeight);
+ } else {
+ // crop to fit -- don't scale
+ areaWidth = getDw() * ws;
+ areaHeight = getDh() * ws;
+ // reset user area size
+ userImgArea.setRect(userImgArea.getX(), userImgArea.getY(),
+ areaWidth, areaHeight);
+ scaleXY = 1f;
+ }
+ }
+ return (float) scaleXY;
+ }
+
+ public int getDw() throws IOException {
+ logger.debug("get_paramDW()");
+ if (paramDW == null) {
+
+ paramDW = getAsInt("dw");
+ paramDH = getAsInt("dh");
+
+ float imgAspect = getFileToLoad().getAspect();
+ if (paramDW == 0) {
+ // calculate dw
+ paramDW = Math.round(paramDH * imgAspect);
+ setValue("dw", paramDW);
+ } else if (paramDH == 0) {
+ // calculate dh
+ paramDH = Math.round(paramDW / imgAspect);
+ setValue("dh", paramDH);
+ }
+ }
+ return paramDW;
+ }
+
+ public int getDh() throws IOException {
+ logger.debug("get_paramDH()");
+ if (paramDH == null) {
+
+ paramDW = getAsInt("dw");
+ paramDH = getAsInt("dh");
+
+ float imgAspect = getFileToLoad().getAspect();
+ if (paramDW == 0) {
+ // calculate dw
+ paramDW = Math.round(paramDH * imgAspect);
+ setValue("dw", paramDW);
+ } else if (paramDH == 0) {
+ // calculate dh
+ paramDH = Math.round(paramDW / imgAspect);
+ setValue("dh", paramDH);
+ }
+ }
+ return paramDH;
+ }
+
+ public Integer getScaleQual(){
+ logger.debug("get_scaleQual()");
+ Integer qual = dlConfig.getAsInt("default-quality");
+ if(hasOption("q0"))
+ qual = 0;
+ else if(hasOption("q1"))
+ qual = 1;
+ else if(hasOption("q2"))
+ qual = 2;
+ return qual;
+ }
+
+
+ public Rectangle2D getUserImgArea() throws IOException, ImageOpException{
+ if(userImgArea == null) {
+ // getScaleXY sets userImgArea
+ getScaleXY();
+ }
+ return userImgArea;
+
+ }
+
+ public Rectangle2D getOuterUserImgArea() throws IOException, ImageOpException {
+ if(outerUserImgArea == null){
+ outerUserImgArea = getUserImgArea();
+
+ // image size in pixels
+ ImageSize imgSize = getFileToLoad().getSize();
+ Rectangle2D imgBounds = new Rectangle2D.Float(0, 0, imgSize.getWidth(),
+ imgSize.getHeight());
+
+ // clip area at the image border
+ outerUserImgArea = outerUserImgArea.createIntersection(imgBounds);
+
+ // check image parameters sanity
+ scaleXY = getScaleXY();
+ logger.debug("outerUserImgArea.getWidth()=" + outerUserImgArea.getWidth());
+ logger.debug("get_scaleXY() * outerUserImgArea.getWidth() = " + (scaleXY * outerUserImgArea.getWidth()));
+
+ if ((outerUserImgArea.getWidth() < 1)
+ || (outerUserImgArea.getHeight() < 1)
+ || (scaleXY * outerUserImgArea.getWidth() < 2)
+ || (scaleXY * outerUserImgArea.getHeight() < 2)) {
+ logger.error("ERROR: invalid scale parameter set!");
+ throw new ImageOpException("Invalid scale parameter set!");
+ }
+ }
+ return outerUserImgArea;
+ }
+
+
+ public float[] getRGBM(){
+ float[] paramRGBM = null;//{0f,0f,0f};
+ Parameter p = params.get("rgbm");
+ if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) {
+ return p.parseAsFloatArray("/");
+ }
+ return paramRGBM;
+ }
+
+ public float[] getRGBA(){
+ float[] paramRGBA = null;//{0f,0f,0f};
+ Parameter p = params.get("rgba");
+ if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) {
+ paramRGBA = p.parseAsFloatArray("/");
+ }
+ return paramRGBA;
+ }
+
+ /** Has send-as-file been requested?
+ * @return
+ */
+ public boolean getSendAsFile(){
+ return hasOption("file")
+ || hasOption("rawfile");
+ }
+
+ /** Could the image be sent without processing?
+ * Takes image type and additional image operations into account.
+ * Does not check requested size transformation.
+ * @return
+ * @throws IOException
+ */
+ public boolean isImageSendable() throws IOException {
+ // cached result?
+ if (imageSendable == null) {
+ String mimeType = getMimeType();
+ imageSendable = ( (mimeType.equals("image/jpeg")
+ || mimeType.equals("image/png")
+ || mimeType.equals("image/gif") )
+ &&
+ !(hasOption("hmir")
+ || hasOption("vmir")
+ || (getAsFloat("rot") != 0.0)
+ || (getRGBM() != null)
+ || (getRGBA() != null)
+ || (getAsFloat("cont") != 0.0)
+ || (getAsFloat("brgt") != 0.0)));
+ }
+
+ return imageSendable;
+ }
+
+
+ public boolean isTransformRequired() throws IOException {
+ ImageSize is = getFileToLoad().getSize();
+ ImageSize ess = getExpectedSourceSize();
+ // nt = no transform required
+ boolean nt = isImageSendable() && (
+ // lores: send if smaller
+ (getLoresOnly() && is.isSmallerThan(ess))
+ // else send if it fits
+ || (!(getLoresOnly() || getHiresOnly()) && is.fitsIn(ess)));
+ return ! nt;
+ }
+}
\ No newline at end of file
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/image/ImageLoaderDocuImage.java
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java Tue Dec 21 09:52:16 2010 +0100
@@ -52,7 +52,7 @@
import digilib.io.ImageFileset;
/** Implementation of DocuImage using the ImageLoader API of Java 1.4 and Java2D. */
-public class ImageLoaderDocuImage extends DocuImageImpl {
+public class ImageLoaderDocuImage extends ImageInfoDocuImage {
/** image object */
protected BufferedImage img;
@@ -117,20 +117,21 @@
}
/* returns a list of supported image formats */
- public Iterator getSupportedFormats() {
+ public Iterator getSupportedFormats() {
String[] formats = ImageIO.getReaderFormatNames();
return Arrays.asList(formats).iterator();
}
/** Check image size and type and store in ImageFile f */
- public boolean identify(ImageFile imgf) throws IOException {
+ public ImageFile identify(ImageFile imageFile) throws IOException {
// try parent method first
- if (super.identify(imgf)) {
- return true;
+ ImageFile imf = super.identify(imageFile);
+ if (imf != null) {
+ return imf;
}
// fileset to store the information
- ImageFileset imgfs = imgf.getParent();
- File f = imgf.getFile();
+ ImageFileset imgfs = imageFile.getParent();
+ File f = imageFile.getFile();
if (f == null) {
throw new IOException("File not found!");
}
@@ -138,47 +139,27 @@
/*
* try ImageReader
*/
- RandomAccessFile raf = new RandomAccessFile(f, "r");
- ImageInputStream istream = ImageIO.createImageInputStream(raf);
- Iterator readers = ImageIO.getImageReaders(istream);
- if (readers.hasNext()) {
- ImageReader reader = (ImageReader) readers.next();
- /* are there more readers? */
- logger.debug("ImageIO: this reader: " + reader.getClass());
- while (readers.hasNext()) {
- logger.debug("ImageIO: next reader: "
- + readers.next().getClass());
- }
- try {
- reader.setInput(istream);
- ImageSize d = new ImageSize(reader.getWidth(0), reader.getHeight(0));
- imgf.setSize(d);
- //String t = reader.getFormatName();
- String t = FileOps.mimeForFile(f);
- imgf.setMimetype(t);
- //logger.debug(" format:"+t);
- if (imgfs != null) {
- imgfs.setAspect(d);
- }
- return true;
- } finally {
- // dispose the reader to free resources
- reader.dispose();
- raf.close();
- }
+ if ((reader == null) || (imgFile != imageFile.getFile())) {
+ getReader(imageFile);
}
- throw new FileOpException("ERROR: unknown image file format!");
+ ImageSize d = new ImageSize(reader.getWidth(0), reader.getHeight(0));
+ imageFile.setSize(d);
+ // String t = reader.getFormatName();
+ String t = FileOps.mimeForFile(f);
+ imageFile.setMimetype(t);
+ // logger.debug(" format:"+t);
+ if (imgfs != null) {
+ imgfs.setAspect(d);
+ }
+ return imageFile;
}
-
/* load image file */
public void loadImage(ImageFile f) throws FileOpException {
logger.debug("loadImage " + f.getFile());
try {
img = ImageIO.read(f.getFile());
- if (img == null) {
- throw new FileOpException("Unable to load File!");
- }
+ mimeType = f.getMimetype();
} catch (IOException e) {
throw new FileOpException("Error reading image.");
}
@@ -196,23 +177,27 @@
// clean up old reader
dispose();
}
- // System.gc();
RandomAccessFile rf = new RandomAccessFile(f.getFile(), "r");
ImageInputStream istream = new FileImageInputStream(rf);
- // Iterator readers = ImageIO.getImageReaders(istream);
+ Iterator readers;
String mt = f.getMimetype();
- logger.debug("File type:" + mt);
- Iterator readers = ImageIO.getImageReadersByMIMEType(mt);
+ if (mt == null) {
+ logger.debug("No mime-type. Trying automagic.");
+ readers = ImageIO.getImageReaders(istream);
+ } else {
+ logger.debug("File type:" + mt);
+ readers = ImageIO.getImageReadersByMIMEType(mt);
+ }
if (!readers.hasNext()) {
- throw new FileOpException("Unable to load File!");
+ rf.close();
+ throw new FileOpException("Can't find Reader to load File!");
}
- reader = (ImageReader) readers.next();
+ reader = readers.next();
/* are there more readers? */
logger.debug("ImageIO: this reader: " + reader.getClass());
- while (readers.hasNext()) {
+ /* while (readers.hasNext()) {
logger.debug("ImageIO: next reader: " + readers.next().getClass());
- }
- // */
+ } */
reader.setInput(istream);
imgFile = f.getFile();
return reader;
@@ -222,7 +207,6 @@
public void loadSubimage(ImageFile f, Rectangle region, int prescale)
throws FileOpException {
logger.debug("loadSubimage");
- // System.gc();
try {
if ((reader == null) || (imgFile != f.getFile())) {
getReader(f);
@@ -236,13 +220,11 @@
// read image
logger.debug("loading..");
img = reader.read(0, readParam);
+ mimeType = f.getMimetype();
logger.debug("loaded");
} catch (IOException e) {
throw new FileOpException("Unable to load File!");
}
- if (img == null) {
- throw new FileOpException("Unable to load File!");
- }
}
/* write image of type mt to Stream */
@@ -325,15 +307,14 @@
AffineTransformOp scaleOp = new AffineTransformOp(AffineTransform
.getScaleInstance(scale, scale), renderHint);
BufferedImage scaledImg = null;
- // enforce destination image type (*Java2D BUG*)
+ /* enforce destination image type (*Java2D BUG*)
int type = img.getType();
- // FIXME: which type would be best?
if ((quality > 0) && (type != 0)) {
logger.debug("creating destination image");
Rectangle2D dstBounds = scaleOp.getBounds2D(img);
scaledImg = new BufferedImage((int) dstBounds.getWidth(),
(int) dstBounds.getHeight(), type);
- }
+ } */
logger.debug("scaling...");
scaledImg = scaleOp.filter(img, scaledImg);
if (scaledImg == null) {
@@ -344,7 +325,6 @@
logger.debug("SCALE: " + scale + " ->" + scaledImg.getWidth() + "x"
+ scaledImg.getHeight());
img = scaledImg;
- scaledImg = null;
}
public void blur(int radius) throws ImageOpException {
@@ -364,16 +344,14 @@
// blur with convolve operation
ConvolveOp blurOp = new ConvolveOp(blur, ConvolveOp.EDGE_NO_OP,
renderHint);
+ BufferedImage blurredImg = null;
// blur needs explicit destination image type for color *Java2D BUG*
- BufferedImage blurredImg = null;
if (img.getType() == BufferedImage.TYPE_3BYTE_BGR) {
+ logger.debug("blur: fixing destination image type");
blurredImg = new BufferedImage(img.getWidth(), img.getHeight(), img
.getType());
}
blurredImg = blurOp.filter(img, blurredImg);
- if (blurredImg == null) {
- throw new ImageOpException("Unable to scale");
- }
img = blurredImg;
}
@@ -381,9 +359,6 @@
throws ImageOpException {
// setup Crop
BufferedImage croppedImg = img.getSubimage(x_off, y_off, width, height);
- // DEBUG
- // util.dprintln(2, " time
- // "+(System.currentTimeMillis()-startTime)+"ms");
if (croppedImg == null) {
throw new ImageOpException("Unable to crop");
}
@@ -413,12 +388,10 @@
}
public void enhanceRGB(float[] rgbm, float[] rgba) throws ImageOpException {
-
/*
* The number of constants must match the number of bands in the image.
* We do only 3 (RGB) bands.
*/
-
int ncol = img.getColorModel().getNumColorComponents();
if ((ncol != 3) || (rgbm.length != 3) || (rgba.length != 3)) {
logger
@@ -491,17 +464,12 @@
double xoff = rotbounds.getX();
double yoff = rotbounds.getY();
// move image back in line
- trafo
- .preConcatenate(AffineTransform.getTranslateInstance(-xoff,
- -yoff));
+ trafo.preConcatenate(AffineTransform.getTranslateInstance(-xoff, -yoff));
// transform image
rotOp = new AffineTransformOp(trafo, renderHint);
BufferedImage rotImg = rotOp.filter(img, null);
// calculate new bounding box
// Rectangle2D bounds = rotOp.getBounds2D(img);
- if (rotImg == null) {
- throw new ImageOpException("Unable to rotate");
- }
img = rotImg;
// crop new image (with self-made rounding)
/*
@@ -536,9 +504,6 @@
AffineTransformOp mirOp = new AffineTransformOp(new AffineTransform(mx,
0, 0, my, tx, ty), renderHint);
BufferedImage mirImg = mirOp.filter(img, null);
- if (mirImg == null) {
- throw new ImageOpException("Unable to mirror");
- }
img = mirImg;
}
@@ -562,7 +527,7 @@
img = null;
}
- public Image getImage(){
+ public Image getAwtImage(){
return (Image) img;
}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/image/ImageOps.java
--- a/servlet/src/digilib/image/ImageOps.java Wed Jul 14 16:36:42 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-/* ImageOps -- convenience methods for images
-
- Digital Image Library servlet components
-
- Copyright (C) 2004 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 13.10.2004
- */
-package digilib.image;
-
-import java.io.IOException;
-
-import digilib.io.ImageFile;
-
-/**
- * convenience methods for images
- *
- * @author casties
- */
-public class ImageOps {
-
- public static final int TYPE_AUTO = 0;
- public static final int TYPE_JPEG = 1;
- public static final int TYPE_PNG = 2;
-
- private static DocuImage docuImg;
-
- public static boolean checkFile(ImageFile imgf) throws IOException {
- return docuImg.identify(imgf);
- }
-
- public static void setDocuImage(DocuImage di) {
- docuImg = di;
- }
-
- public static DocuImage getDocuImage() {
- return docuImg;
- }
-}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/image/ImageWorker.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/src/digilib/image/ImageWorker.java Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,154 @@
+/** Worker (Callable) that renders an image.
+ *
+ */
+package digilib.image;
+
+import java.awt.Rectangle;
+import java.io.IOException;
+import java.util.concurrent.Callable;
+
+import org.apache.log4j.Logger;
+
+import digilib.io.FileOpException;
+import digilib.servlet.DigilibConfiguration;
+
+/** Worker that renders an image.
+ *
+ * @author casties
+ *
+ */
+public class ImageWorker implements Callable {
+
+
+ protected static Logger logger = Logger.getLogger(ImageWorker.class);
+ private DigilibConfiguration dlConfig;
+ private ImageJobDescription jobinfo;
+
+ public ImageWorker(DigilibConfiguration dlConfig, ImageJobDescription jobinfo) {
+ super();
+ this.dlConfig = dlConfig;
+ this.jobinfo = jobinfo;
+ }
+
+ /**
+ * render and return the image
+ */
+ @Override
+ public DocuImage call() throws FileOpException, IOException, ImageOpException {
+
+ logger.debug("image worker starting");
+ long startTime = System.currentTimeMillis();
+
+ /* crop and scale image */
+
+ // new DocuImage instance
+ DocuImage docuImage = DigilibConfiguration.getDocuImageInstance();
+ if (docuImage == null) {
+ throw new ImageOpException("Unable to load DocuImage class!");
+ }
+
+ // set interpolation quality
+ docuImage.setQuality(jobinfo.getScaleQual());
+
+ Rectangle loadRect = jobinfo.getOuterUserImgArea().getBounds();
+ float scaleXY = jobinfo.getScaleXY();
+
+ // use subimage loading if possible
+ if (docuImage.isSubimageSupported()) {
+ logger.debug("Subimage: scale " + scaleXY + " = " + (1 / scaleXY));
+ float subf = 1f;
+ float subsamp = 1f;
+ if (scaleXY < 1) {
+ subf = 1 / scaleXY;
+ // for higher quality reduce subsample factor by minSubsample
+ if (jobinfo.getScaleQual() > 0) {
+ subsamp = (float) Math.max(Math.floor(subf / dlConfig.getAsFloat("subsample-minimum")), 1d);
+ } else {
+ subsamp = (float) Math.floor(subf);
+ }
+ scaleXY = subsamp / subf;
+ logger.debug("Using subsampling: " + subsamp + " rest "
+ + scaleXY);
+ }
+
+ docuImage.loadSubimage(jobinfo.getFileToLoad(), loadRect, (int) subsamp);
+
+ logger.debug("SUBSAMP: " + subsamp + " -> " + docuImage.getWidth()
+ + "x" + docuImage.getHeight());
+
+ docuImage.scale(scaleXY, scaleXY);
+
+ } else {
+ // else load and crop the whole file
+ docuImage.loadImage(jobinfo.getFileToLoad());
+ docuImage.crop((int) loadRect.getX(), (int) loadRect.getY(),
+ (int) loadRect.getWidth(), (int) loadRect.getHeight());
+
+ docuImage.scale(scaleXY, scaleXY);
+ }
+
+ // mirror image
+ // operation mode: "hmir": mirror horizontally, "vmir": mirror
+ // vertically
+ if (jobinfo.hasOption("hmir")) {
+ docuImage.mirror(0);
+ }
+ if (jobinfo.hasOption("vmir")) {
+ docuImage.mirror(90);
+ }
+
+ // rotate image
+ if (jobinfo.getAsFloat("rot") != 0d) {
+ docuImage.rotate(jobinfo.getAsFloat("rot"));
+ /* if (jobinfo.get_wholeRotArea()) {
+ // crop to the inner bounding box
+ float xcrop = (float) (docuImage.getWidth() - jobinfo.get_innerUserImgArea().getWidth()
+ * scaleXY);
+ float ycrop = (float) (docuImage.getHeight() - jobinfo.get_innerUserImgArea().getHeight()
+ * scaleXY);
+ if ((xcrop > 0) || (ycrop > 0)) {
+ // only crop smaller
+ xcrop = (xcrop > 0) ? xcrop : 0;
+ ycrop = (ycrop > 0) ? ycrop : 0;
+ // crop image
+ docuImage.crop((int) (xcrop / 2), (int) (ycrop / 2),
+ (int) (docuImage.getWidth() - xcrop),
+ (int) (docuImage.getHeight() - ycrop));
+ }
+ } */
+
+ }
+
+ // color modification
+ float[] paramRGBM = jobinfo.getRGBM();
+ float[] paramRGBA = jobinfo.getRGBA();
+ if ((paramRGBM != null) || (paramRGBA != null)) {
+ // make sure we actually have two arrays
+ if (paramRGBM == null) {
+ paramRGBM = new float[3];
+ }
+ if (paramRGBA == null) {
+ paramRGBA = new float[3];
+ }
+ // calculate "contrast" values (c=2^x)
+ float[] mult = new float[3];
+ for (int i = 0; i < 3; i++) {
+ mult[i] = (float) Math.pow(2, (float) paramRGBM[i]);
+ }
+ docuImage.enhanceRGB(mult, paramRGBA);
+ }
+
+ // contrast and brightness enhancement
+ float paramCONT = jobinfo.getAsFloat("cont");
+ float paramBRGT = jobinfo.getAsFloat("brgt");
+ if ((paramCONT != 0f) || (paramBRGT != 0f)) {
+ float mult = (float) Math.pow(2, paramCONT);
+ docuImage.enhance(mult, paramBRGT);
+ }
+
+ logger.debug("rendered in " + (System.currentTimeMillis() - startTime) + "ms");
+
+ return docuImage;
+ }
+
+}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/image/JAIDocuImage.java
--- a/servlet/src/digilib/image/JAIDocuImage.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/image/JAIDocuImage.java Tue Dec 21 09:52:16 2010 +0100
@@ -49,7 +49,7 @@
import digilib.io.ImageFileset;
/** A DocuImage implementation using Java Advanced Imaging Library. */
-public class JAIDocuImage extends DocuImageImpl {
+public class JAIDocuImage extends ImageInfoDocuImage {
protected RenderedImage img;
@@ -84,30 +84,30 @@
}
/* returns a list of supported image formats */
- public Iterator getSupportedFormats() {
- Enumeration codecs = ImageCodec.getCodecs();
- List formats = new ArrayList(5);
- for (Object codec = codecs.nextElement(); codecs.hasMoreElements(); codec = codecs
- .nextElement()) {
- logger
- .debug("known format:"
- + ((ImageCodec) codec).getFormatName());
- formats.add(((ImageCodec) codec).getFormatName());
- }
- logger.debug("tilecachesize:"
- + JAI.getDefaultInstance().getTileCache().getMemoryCapacity());
- return formats.iterator();
- }
+ @SuppressWarnings("unchecked") // ImageCodec.getCodecs() returns a naked Enumeration
+ public Iterator getSupportedFormats() {
+ Enumeration codecs = ImageCodec.getCodecs();
+ List formats = new ArrayList();
+ for (ImageCodec codec = codecs.nextElement(); codecs.hasMoreElements(); codec = codecs
+ .nextElement()) {
+ logger.debug("known format:"+codec.getFormatName());
+ formats.add(codec.getFormatName());
+ }
+ logger.debug("tilecachesize:"
+ + JAI.getDefaultInstance().getTileCache().getMemoryCapacity());
+ return formats.iterator();
+ }
/* Check image size and type and store in ImageFile f */
- public boolean identify(ImageFile imgf) throws IOException {
- // try parent method first
- if (super.identify(imgf)) {
- return true;
+ public ImageFile identify(ImageFile imageFile) throws IOException {
+ // try parent method first
+ ImageFile imf = super.identify(imageFile);
+ if (imf != null) {
+ return imf;
}
// fileset to store the information
- ImageFileset imgfs = imgf.getParent();
- File f = imgf.getFile();
+ ImageFileset imgfs = imageFile.getParent();
+ File f = imageFile.getFile();
if (f == null) {
throw new IOException("File not found!");
}
@@ -118,15 +118,15 @@
try {
RenderedOp img = JAI.create("fileload", f.getAbsolutePath());
ImageSize d = new ImageSize(img.getWidth(), img.getHeight());
- imgf.setSize(d);
+ imageFile.setSize(d);
String t = FileOps.mimeForFile(f);
- imgf.setMimetype(t);
+ imageFile.setMimetype(t);
// logger.debug(" format:"+t);
if (imgfs != null) {
imgfs.setAspect(d);
}
- logger.debug("image size: " + imgf.getSize());
- return true;
+ logger.debug("image size: " + imageFile.getSize());
+ return imageFile;
} catch (Exception e) {
throw new FileOpException("ERROR: unknown image file format!");
}
@@ -138,6 +138,7 @@
if (img == null) {
throw new FileOpException("Unable to load File!");
}
+ mimeType = f.getMimetype();
}
/* Load an image file into the Object. */
@@ -168,6 +169,7 @@
// scale
logger.debug("loadSubimage: scale");
img = JAI.create("scale", sp);
+ mimeType = f.getMimetype();
}
}
@@ -330,11 +332,6 @@
logger.debug("CROP: " + x_off + "," + y_off + ", " + width + ","
+ height + " ->" + croppedImg.getWidth() + "x"
+ croppedImg.getHeight());
- // DEBUG
-
- if (croppedImg == null) {
- throw new ImageOpException("Unable to crop");
- }
img = croppedImg;
}
@@ -384,11 +381,6 @@
logger.debug("ROTATE: " + x + "," + y + ", " + angle + " (" + rangle
+ ")" + " ->" + rotImg.getWidth() + "x" + rotImg.getHeight());
- // DEBUG
-
- if (rotImg == null) {
- throw new ImageOpException("Unable to rotate");
- }
img = rotImg;
}
@@ -442,10 +434,6 @@
logger.debug("ENHANCE: *" + mult + ", +" + add + " ->"
+ enhImg.getWidth() + "x" + enhImg.getHeight());
// DEBUG
-
- if (enhImg == null) {
- throw new ImageOpException("Unable to enhance");
- }
img = enhImg;
}
@@ -472,11 +460,6 @@
logger.debug("ENHANCE_RGB: *" + rgbm + ", +" + rgba + " ->"
+ enhImg.getWidth() + "x" + enhImg.getHeight());
- // DEBUG
-
- if (enhImg == null) {
- throw new ImageOpException("Unable to enhanceRGB");
- }
img = enhImg;
}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/image/JAIImageLoaderDocuImage.java
--- a/servlet/src/digilib/image/JAIImageLoaderDocuImage.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/image/JAIImageLoaderDocuImage.java Tue Dec 21 09:52:16 2010 +0100
@@ -20,6 +20,7 @@
package digilib.image;
+import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.renderable.ParameterBlock;
import java.io.File;
@@ -89,6 +90,7 @@
if (img == null) {
throw new FileOpException("Unable to load File!");
}
+ mimeType = f.getMimetype();
}
/* Get an ImageReader for the image file. */
@@ -98,11 +100,11 @@
RandomAccessFile rf = new RandomAccessFile(f.getFile(), "r");
ImageInputStream istream = new FileImageInputStream(rf);
//Iterator readers = ImageIO.getImageReaders(istream);
- Iterator readers = ImageIO.getImageReadersByMIMEType(f.getMimetype());
+ Iterator readers = ImageIO.getImageReadersByMIMEType(f.getMimetype());
if (! readers.hasNext()) {
throw new FileOpException("Unable to load File!");
}
- reader = (ImageReader) readers.next();
+ reader = readers.next();
logger.debug("JAIImageIO: this reader: " + reader.getClass());
while (readers.hasNext()) {
logger.debug(" next reader: " + readers.next().getClass());
@@ -139,6 +141,7 @@
throw new FileOpException("Unable to load File!");
}
imgFile = f.getFile();
+ mimeType = f.getMimetype();
}
@@ -166,7 +169,13 @@
}
}
- /* (non-Javadoc)
+ @Override
+ public Image getAwtImage() {
+ // TODO Auto-generated method stub
+ return (Image) img;
+ }
+
+ /* (non-Javadoc)
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/io/AliasingDocuDirCache.java
--- a/servlet/src/digilib/io/AliasingDocuDirCache.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/io/AliasingDocuDirCache.java Tue Dec 21 09:52:16 2010 +0100
@@ -23,9 +23,10 @@
package digilib.io;
import java.io.File;
-import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
+import digilib.io.FileOps.FileClass;
import digilib.servlet.DigilibConfiguration;
/**
@@ -36,16 +37,16 @@
/**
* @param baseDirs
- * @param fileClasses
+ * @param fcs
* @param confFileName
* @throws FileOpException
*/
- public AliasingDocuDirCache(String[] baseDirs, int[] fileClasses,
+ public AliasingDocuDirCache(String[] baseDirs, FileClass[] fcs,
File confFile, DigilibConfiguration dlConfig)
throws FileOpException {
// create standard DocuDirCache
- super(baseDirs, fileClasses, dlConfig);
- Map pathMap = null;
+ super(baseDirs, fcs, dlConfig);
+ Map pathMap = null;
// read alias config file
try {
// load into pathMap
@@ -63,18 +64,16 @@
* load map entries into cache
*/
- for (Iterator i = pathMap.keySet().iterator(); i.hasNext();) {
- String link = (String) i.next();
- String dir = (String) pathMap.get(link);
- if (dir == null) {
+ for (Entry linkdir: pathMap.entrySet()) {
+ if (linkdir.getValue() == null) {
logger.error("Key mismatch in mapping file!");
break;
}
- DocuDirectory destDir = new DocuDirectory(dir, this);
+ DocuDirectory destDir = new DocuDirectory(linkdir.getValue(), this);
if (destDir.isValid()) {
- logger.debug("Aliasing dir: " + link);
+ logger.debug("Aliasing dir: " + linkdir.getKey());
// add the alias name
- putName(FileOps.normalName(link), destDir);
+ putName(FileOps.normalName(linkdir.getKey()), destDir);
// add the real dir
putDir(destDir);
}
@@ -87,13 +86,12 @@
* @param name
* @param newdir
*/
- public void putName(String name, DocuDirectory newdir) {
- if (map.containsKey(name)) {
- logger
- .warn("Duplicate key in AliasingDocuDirCache.put -- ignored!");
- } else {
- map.put(name, newdir);
- }
- }
+ public void putName(String name, DocuDirectory newdir) {
+ if (map.containsKey(name)) {
+ logger.warn("Duplicate key in AliasingDocuDirCache.put -- ignored!");
+ } else {
+ map.put(name, newdir);
+ }
+ }
}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/io/DigilibInfoReader.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlet/src/digilib/io/DigilibInfoReader.java Tue Dec 21 09:52:16 2010 +0100
@@ -0,0 +1,76 @@
+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 mainElements = root.getChildren();
+ // logger.debug("XML mainElements:"+mainElements.toString());
+
+ for(int i=0; i map = null;
/** names of base directories */
String[] baseDirNames = null;
/** array of allowed file classes (image/text) */
- private int[] fileClasses = null;
+ private FileClass[] fileClasses = null;
/** number of files in the whole cache (approximate) */
long numFiles = 0;
@@ -59,9 +59,6 @@
/** number of cache misses */
long misses = 0;
- /** use safe (but slow) indexing */
- boolean safeDirIndex = false;
-
/** the root directory element */
public static Directory ROOT = null;
@@ -71,12 +68,11 @@
* @param bd
* base directory names
*/
- public DocuDirCache(String[] bd, int[] fileClasses,
+ public DocuDirCache(String[] bd, FileClass[] fcs,
DigilibConfiguration dlConfig) {
baseDirNames = bd;
- map = new HashMap();
- this.fileClasses = fileClasses;
- safeDirIndex = dlConfig.getAsBoolean("safe-dir-index");
+ map = new HashMap();
+ this.fileClasses = fcs;
}
/**
@@ -87,10 +83,9 @@
*/
public DocuDirCache(String[] bd) {
baseDirNames = bd;
- map = new HashMap();
+ map = new HashMap();
// default file class is CLASS_IMAGE
- fileClasses = new int[1];
- fileClasses[0] = FileOps.CLASS_IMAGE;
+ fileClasses = new FileClass[] { FileClass.IMAGE };
}
/**
@@ -127,7 +122,7 @@
String parent = FileOps.parent(newDir.getDirName());
if (parent != "") {
// check the parent in the cache
- DocuDirectory pd = (DocuDirectory) map.get(parent);
+ DocuDirectory pd = map.get(parent);
if (pd == null) {
// the parent is unknown
pd = new DocuDirectory(parent, this);
@@ -149,11 +144,9 @@
* find all children and their children.
* @return
*/
- public List getChildren(String dirname, boolean recurse) {
- List l = new LinkedList();
- for (Iterator i = map.keySet().iterator(); i.hasNext();) {
- String n = (String) i.next();
- DocuDirectory dd = (DocuDirectory) map.get(n);
+ public List getChildren(String dirname, boolean recurse) {
+ List l = new LinkedList();
+ for (DocuDirectory dd: map.values()) {
if (recurse) {
if (dd.getDirName().startsWith(dirname)) {
l.add(dd);
@@ -182,12 +175,12 @@
* file class
* @return
*/
- public DocuDirent getFile(String fn, int in, int fc) {
+ public DocuDirent getFile(String fn, int in, FileClass fc) {
DocuDirectory dd;
// file number is 1-based, vector index is 0-based
int n = in - 1;
// first, assume fn is a directory and look in the cache
- dd = (DocuDirectory) map.get(fn);
+ dd = map.get(fn);
// logger.debug("fn: " + fn);
// logger.debug("dd: " + dd);
if (dd == null) {
@@ -213,7 +206,7 @@
String d = FileOps.parent(fn);
// try it in the cache
// logger.debug(fn + " is a file in dir " + d);
- dd = (DocuDirectory) map.get(d);
+ dd = map.get(d);
if (dd == null) {
// try to read from disk
dd = new DocuDirectory(d, this);
@@ -262,7 +255,7 @@
public DocuDirectory getDirectory(String fn) {
DocuDirectory dd;
// first, assume fn is a directory and look in the cache
- dd = (DocuDirectory) map.get(fn);
+ dd = map.get(fn);
if (dd == null) {
// cache miss
misses++;
@@ -278,7 +271,7 @@
// maybe it's a file
if (f.canRead()) {
// try the parent directory in the cache
- dd = (DocuDirectory) map.get(f.getParent());
+ dd = map.get(f.getParent());
if (dd == null) {
// try to read from disk
dd = new DocuDirectory(f.getParent(), this);
@@ -350,14 +343,14 @@
/**
* @return
*/
- public int[] getFileClasses() {
+ public FileClass[] getFileClasses() {
return fileClasses;
}
/**
* @param fileClasses
*/
- public void setFileClasses(int[] fileClasses) {
+ public void setFileClasses(FileClass[] fileClasses) {
this.fileClasses = fileClasses;
}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/io/DocuDirectory.java
--- a/servlet/src/digilib/io/DocuDirectory.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/io/DocuDirectory.java Tue Dec 21 09:52:16 2010 +0100
@@ -25,19 +25,20 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.xml.sax.SAXException;
+import digilib.io.FileOps.FileClass;
+
/**
* @author casties
*/
public class DocuDirectory extends Directory {
/** list of files (DocuDirent) */
- private ArrayList[] list = null;
+ private List> list = null;
/** directory object is valid (exists on disk) */
private boolean isValid = false;
@@ -49,13 +50,13 @@
private String dirName = null;
/** directory metadata */
- private Map dirMeta = null;
+ private MetadataMap dirMeta = null;
/** state of metadata is valid */
private boolean metaChecked = false;
/** unresolved file metadata */
- private Map unresolvedFileMeta = null;
+ private Map unresolvedFileMeta = null;
/** time of last access of this object (not the filesystem) */
private long objectATime = 0;
@@ -89,8 +90,13 @@
*/
protected void initDir() {
String baseDirName = cache.getBaseDirNames()[0];
- // clear directory first
- list = new ArrayList[FileOps.NUM_CLASSES];
+ // clear directory list
+ FileClass[] fcs = FileClass.values();
+ list = new ArrayList>(fcs.length);
+ // create empty list for all classes
+ for (@SuppressWarnings("unused") FileClass fc: fcs) {
+ list.add(null);
+ }
isValid = false;
dirMTime = 0;
// the first directory has to exist
@@ -102,7 +108,7 @@
*
*/
public int size() {
- return ((list != null) && (list[0] != null)) ? list[0].size() : 0;
+ return ((list != null) && (list.get(0) != null)) ? list.get(0).size() : 0;
}
/**
@@ -111,21 +117,21 @@
* @param fc
* fileClass
*/
- public int size(int fc) {
- return ((list != null) && (list[fc] != null)) ? list[fc].size() : 0;
+ public int size(FileClass fc) {
+ return ((list != null) && (list.get(fc.ordinal()) != null)) ? list.get(fc.ordinal()).size() : 0;
}
/**
- * Returns the ImageFile at the index.
+ * Returns the ImageFileSet at the index.
*
* @param index
* @return
*/
public ImageFileset get(int index) {
- if ((list == null) || (list[0] == null) || (index >= list[0].size())) {
+ if ((list == null) || (list.get(0) == null) || (index >= list.get(0).size())) {
return null;
}
- return (ImageFileset) list[0].get(index);
+ return (ImageFileset) list.get(0).get(index);
}
/**
@@ -136,11 +142,11 @@
* fileClass
* @return
*/
- public DocuDirent get(int index, int fc) {
- if ((list == null) || (list[fc] == null) || (index >= list[fc].size())) {
+ public DocuDirent get(int index, FileClass fc) {
+ if ((list == null) || (list.get(fc.ordinal()) == null) || (index >= list.get(fc.ordinal()).size())) {
return null;
}
- return (DocuDirent) list[fc].get(index);
+ return (DocuDirent) list.get(fc.ordinal()).get(index);
}
/**
@@ -180,11 +186,8 @@
* extensions) but slower.
*/
File[] allFiles = null;
- if (cache.safeDirIndex) {
- allFiles = dir.listFiles(new FileOps.ReadableFileFilter());
- } else {
- allFiles = dir.listFiles();
- }
+ // allFiles = dir.listFiles(new FileOps.ReadableFileFilter());
+ allFiles = dir.listFiles();
//logger.debug(" done");
if (allFiles == null) {
// not a directory
@@ -210,10 +213,9 @@
}
// go through all file classes
- for (int classIdx = 0; classIdx < FileOps.NUM_CLASSES; classIdx++) {
- int fileClass = cache.getFileClasses()[classIdx];
- //logger.debug("filtering directory "+dir.getPath()+" for class
- // "+fc);
+ //for (int classIdx = 0; classIdx < FileOps.NUM_CLASSES; classIdx++) {
+ for (FileClass fileClass: cache.getFileClasses()) {
+ //fileClass = cache.getFileClasses()[classIdx];
File[] fileList = FileOps.listFiles(allFiles, FileOps
.filterForClass(fileClass));
//logger.debug(" done");
@@ -221,10 +223,10 @@
int numFiles = fileList.length;
if (numFiles > 0) {
// create new list
- list[fileClass] = new ArrayList(numFiles);
+ list.set(fileClass.ordinal(), new ArrayList(numFiles));
// sort the file names alphabetically and iterate the list
// Arrays.sort(fileList); // not needed
- Map hints = FileOps.newHints(FileOps.HINT_BASEDIRS, dirs);
+ Map hints = FileOps.newHints(FileOps.HINT_BASEDIRS, dirs);
hints.put(FileOps.HINT_FILEEXT, scalext);
for (int i = 0; i < numFiles; i++) {
DocuDirent f = FileOps.fileForClass(fileClass, fileList[i],
@@ -232,11 +234,12 @@
// add the file to our list
// logger.debug(f.getName());
- list[fileClass].add(f);
+ list.get(fileClass.ordinal()).add(f);
f.setParent(this);
}
- // we sort the ArrayList, not the Array, for binarySearch to work
- Collections.sort(list[fileClass]);
+ // we sort the inner ArrayList (the list of files not the list of file types)
+ // for binarySearch to work (DocuDirent's natural sort order is by filename)
+ Collections.sort(list.get(fileClass.ordinal()));
}
}
// clear the scaled directories
@@ -282,12 +285,12 @@
XMLMetaLoader ml = new XMLMetaLoader();
try {
// read directory meta file
- Map fileMeta = ml.loadURL(mf.getAbsolutePath());
+ Map fileMeta = ml.loadURL(mf.getAbsolutePath());
if (fileMeta == null) {
return;
}
// meta for the directory itself is in the "" bin
- dirMeta = (Map) fileMeta.remove("");
+ dirMeta = fileMeta.remove("");
// read meta for files in this directory
readFileMeta(fileMeta, null);
// is there meta for other files left?
@@ -334,25 +337,23 @@
* @param fc
* fileClass
*/
- protected void readFileMeta(Map fileMeta, String relPath) {
+ protected void readFileMeta(Map fileMeta, String relPath) {
if (list == null) {
// there are no files
return;
}
String path = (relPath != null) ? (relPath + "/") : "";
// go through all file classes
- for (int nc = 0; nc < list.length; nc++) {
- int fc = cache.getFileClasses()[nc];
- if (list[fc] == null) {
+ for (FileClass fc: FileClass.values()) {
+ if (list.get(fc.ordinal()) == null) {
continue;
}
// iterate through the list of files in this directory
- for (Iterator i = list[fc].iterator(); i.hasNext();) {
- DocuDirent f = (DocuDirent) i.next();
+ for (DocuDirent f: list.get(fc.ordinal())) {
// prepend path to the filename
String fn = path + f.getName();
// look up meta for this file and remove from dir
- Map meta = (Map) fileMeta.remove(fn);
+ MetadataMap meta = fileMeta.remove(fn);
if (meta != null) {
// store meta in file
f.setFileMeta(meta);
@@ -361,13 +362,13 @@
}
}
- protected void notifyChildMeta(Map childmeta) {
- List children = cache.getChildren(this.dirName, true);
+ protected void notifyChildMeta(MetadataMap childmeta) {
+ List children = cache.getChildren(this.dirName, true);
if (children.size() > 0) {
- for (Iterator i = children.iterator(); i.hasNext();) {
+ /*for (DocuDirectory d: children) {
// TODO: finish this!
//((DocuDirectory) i.next()).readFileMeta()
- }
+ }*/
}
}
@@ -395,7 +396,7 @@
* @return int index of file fn
*/
public int indexOf(String fn) {
- int fc = FileOps.classForFilename(fn);
+ FileClass fc = FileOps.classForFilename(fn);
return indexOf(fn, fc);
}
@@ -409,20 +410,20 @@
* filename
* @return int index of file fn
*/
- public int indexOf(String fn, int fc) {
+ public int indexOf(String fn, FileClass fc) {
if (!isRead()) {
// read directory now
if (!readDir()) {
return -1;
}
}
- List fileList = list[fc];
+ List fileList = list.get(fc.ordinal());
// empty directory?
if (fileList == null) {
return -1;
}
- // search for exact match
+ // search for exact match (DocuDirent does compareTo)
// OBS: fileList needs to be sorted first (see )!
int idx = Collections.binarySearch(fileList, fn);
if (idx >= 0) {
@@ -432,15 +433,15 @@
// try closest matches without extension
idx = -idx - 1;
if ((idx < fileList.size())
- && isBaseInList(fileList, idx, fn)) {
+ && isBasenameInList(fileList, idx, fn)) {
// idx matches
return idx;
} else if ((idx > 0)
- && isBaseInList(fileList, idx-1, fn)) {
+ && isBasenameInList(fileList, idx-1, fn)) {
// idx-1 matches
return idx - 1;
} else if ((idx + 1 < fileList.size())
- && isBaseInList(fileList, idx+1, fn)) {
+ && isBasenameInList(fileList, idx+1, fn)) {
// idx+1 matches
return idx + 1;
}
@@ -449,8 +450,8 @@
return -1;
}
- private boolean isBaseInList(List fl, int idx, String fn) {
- String dfn = FileOps.basename(((DocuDirent) fl.get(idx))
+ private boolean isBasenameInList(List fl, int idx, String fn) {
+ String dfn = FileOps.basename((fl.get(idx))
.getName());
return (dfn.equals(fn)||dfn.equals(FileOps.basename(fn)));
}
@@ -467,10 +468,10 @@
* @return DocuDirent
*/
public DocuDirent find(String fn) {
- int fc = FileOps.classForFilename(fn);
+ FileClass fc = FileOps.classForFilename(fn);
int i = indexOf(fn, fc);
if (i >= 0) {
- return (DocuDirent) list[0].get(i);
+ return (DocuDirent) list.get(0).get(i);
}
return null;
}
@@ -486,10 +487,10 @@
* filename
* @return DocuDirent
*/
- public DocuDirent find(String fn, int fc) {
+ public DocuDirent find(String fn, FileClass fc) {
int i = indexOf(fn, fc);
if (i >= 0) {
- return (DocuDirent) list[fc].get(i);
+ return (DocuDirent) list.get(fc.ordinal()).get(i);
}
return null;
}
@@ -531,7 +532,7 @@
/**
* @return Hashtable
*/
- public Map getDirMeta() {
+ public MetadataMap getDirMeta() {
return dirMeta;
}
@@ -560,7 +561,7 @@
* @param dirMeta
* The dirMeta to set
*/
- public void setDirMeta(Map dirMeta) {
+ public void setDirMeta(MetadataMap dirMeta) {
this.dirMeta = dirMeta;
}
diff -r 9936604d466e -r 1f666c2b4578 servlet/src/digilib/io/DocuDirent.java
--- a/servlet/src/digilib/io/DocuDirent.java Wed Jul 14 16:36:42 2010 +0200
+++ b/servlet/src/digilib/io/DocuDirent.java Tue Dec 21 09:52:16 2010 +0100
@@ -27,18 +27,20 @@
import org.apache.log4j.Logger;
+import digilib.io.FileOps.FileClass;
+
/**
* Abstract directory entry in a DocuDirectory.
*
* @author casties
*
*/
-public abstract class DocuDirent implements Comparable {
+public abstract class DocuDirent implements Comparable