changeset 753:39bd5128811c jquery

first real JSON jsp: ImgInfo-json.jsp
author robcast
date Sat, 05 Feb 2011 22:50:15 +0100
parents fce27a005445
children ce5a0e6b5ee9
files client/digitallibrary/ImgInfo-json.jsp client/digitallibrary/dlInfo-js.jsp client/digitallibrary/dlInfo-json.jsp
diffstat 3 files changed, 84 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/digitallibrary/ImgInfo-json.jsp	Sat Feb 05 22:50:15 2011 +0100
@@ -0,0 +1,48 @@
+<%@page language="java" 
+	import="digilib.io.FileOps, digilib.io.ImageFileset, digilib.io.ImageFile, 
+	digilib.image.ImageSize, digilib.servlet.DigilibConfiguration"
+	contentType="application/json"%><%!
+// create DocumentBean instance for all JSP requests
+digilib.servlet.DocumentBean docBean = new digilib.servlet.DocumentBean();
+
+// initialize DocumentBean instance in JSP init
+public void jspInit() {
+    try {
+        // set servlet init-parameter
+        docBean.setConfig(getServletConfig());
+    } catch (javax.servlet.ServletException e) {
+        System.out.println(e);
+    }
+}
+%><%
+// parsing the query
+digilib.servlet.DigilibRequest dlRequest = new digilib.servlet.DigilibRequest(request);
+docBean.setRequest(dlRequest);
+// dir cache
+digilib.servlet.DigilibConfiguration dlConfig = docBean.getDlConfig();
+digilib.io.DocuDirCache dirCache = (digilib.io.DocuDirCache) dlConfig.getValue("servlet.dir.cache");
+// get file
+FileOps.FileClass fc = FileOps.FileClass.IMAGE;
+ImageFileset imgFile = (ImageFileset) dirCache.getFile(dlRequest.getFilePath(), dlRequest.getAsInt("pn"), fc);
+
+%>// JSON format metadata about an image
+{ <% 
+    if (imgFile != null) {
+		ImageFile img = imgFile.getBiggest();
+		if (!img.isChecked()) {
+			DigilibConfiguration.docuImageIdentify(img);
+		}
+		ImageSize imgSize = img.getSize(); 
+		%>
+  "filename" : "<%= imgFile.getName() %>",
+  "aspect" : <%= imgFile.getAspect() %>,
+  "dpi_x" : <%= imgFile.getResX() %>,
+  "dpi_y" : <%= imgFile.getResY() %><%
+  
+        if (imgSize != null) { 
+            %>,
+  "width" : <%= imgSize.getWidth() %>,
+  "height" : <%= imgSize.getHeight() %>
+<% 		}
+  	} 
+%>}
--- a/client/digitallibrary/dlInfo-js.jsp	Sat Feb 05 22:48:57 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-<%@ page language="java" %>
-<%!
-// create DocumentBean instance for all JSP requests
-digilib.servlet.DocumentBean docBean = new digilib.servlet.DocumentBean();
-
-// initialize DocumentBean instance in JSP init
-public void jspInit() {
-    try {
-        // set servlet init-parameter
-        docBean.setConfig(getServletConfig());
-    } catch (javax.servlet.ServletException e) {
-        System.out.println(e);
-    }
-}
-%><%
-// parsing the query
-digilib.servlet.DigilibRequest dlRequest = new digilib.servlet.DigilibRequest(request);
-docBean.setRequest(dlRequest);
-%>
-// Automatically generated JavaScript snippet with parameters
-<%
-    Object[] keys = dlRequest.getParams().keySet().toArray();
-    java.util.Arrays.sort(keys);
-    int l = keys.length;
-    for (int i = 0; i < l; i++) {
-	String key = (String) keys[i];
-	String val = dlRequest.getAsString(key);
-	if (val.length() == 0) {
-	    val = "";
-	}
-	%>var dl_<%= key %> = "<%= val %>";
-<%
-       }
-%>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/digitallibrary/dlInfo-json.jsp	Sat Feb 05 22:50:15 2011 +0100
@@ -0,0 +1,36 @@
+<%@ page language="java" %>
+<%!
+// create DocumentBean instance for all JSP requests
+digilib.servlet.DocumentBean docBean = new digilib.servlet.DocumentBean();
+
+// initialize DocumentBean instance in JSP init
+public void jspInit() {
+    try {
+        // set servlet init-parameter
+        docBean.setConfig(getServletConfig());
+    } catch (javax.servlet.ServletException e) {
+        System.out.println(e);
+    }
+}
+%><%
+// parsing the query
+digilib.servlet.DigilibRequest dlRequest = new digilib.servlet.DigilibRequest(request);
+docBean.setRequest(dlRequest);
+%>
+// JSON format metadata about request and image
+{
+<%
+    Object[] keys = dlRequest.getParams().keySet().toArray();
+    java.util.Arrays.sort(keys);
+    int l = keys.length;
+    for (int i = 0; i < l; i++) {
+	String key = (String) keys[i];
+	String val = dlRequest.getAsString(key);
+	if (val.length() == 0) {
+	    val = "";
+	}
+	%>"<%= key %>" : "<%= val %>",
+<%
+       }
+%>
+}