%@ page import="java.io.File,java.io.FilenameFilter,java.util.Arrays"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.utils.Utils" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.utils.HTTPUtils" %>
<%@ page import="org.json.JSONTokener" %>
<%@ page import="org.json.JSONTokener" %>
<%@ page import="org.json.JSONObject" %>
<%@ page import="org.json.JSONArray" %>
<%@ page import="java.net.URI" %>
<%
String dir = request.getParameter("dir");
if (dir == null) {
return;
}
String manifestURL = dir;
/*
int keySlash = dir.lastIndexOf("/");
if (keySlash > 0) manifestURL = dir.substring(0, keySlash);
if (manifestURL == null) {
return;
}
if (key.startsWith("http")) {
key = null;
}
else {
dir = dir.substring(keySlash);
}
*/
manifestURL = java.net.URLDecoder.decode(manifestURL, "UTF-8");
System.out.println("IIIF Manifest url: " + manifestURL);
if (manifestURL.endsWith("/")) manifestURL = manifestURL.substring(0, manifestURL.length()-1);
try {
java.lang.System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
URI uri = new URI(manifestURL);
JSONTokener tokener = new JSONTokener(uri.toURL().openStream());
JSONObject root = new JSONObject(tokener);
//System.out.println("IIIF Manifest root: " + root);
out.print("
");
JSONArray sequences = null;
JSONArray canvases = null;
try { sequences = root.getJSONArray("sequences"); } catch (Exception e) {}
if (sequences != null) {
JSONObject sequence = sequences.getJSONObject(0);
//System.out.println("IIIF Manifest sequence: " + sequence);
canvases = sequence.getJSONArray("canvases");
}
else {
canvases = root.getJSONArray("items");
}
//System.out.println("IIIF Manifest canvases: " + canvases);
for (int i = 0; i < canvases.length(); ++i) {
JSONObject canvas = canvases.getJSONObject(i);
JSONArray images = null;
try { images = canvas.getJSONArray("images"); } catch (Exception e) {}
String serviceURL = null;
String label = "";
if (images == null) {
JSONObject labelsI18n = canvas.getJSONObject("label");
System.out.println("*************** IIIF Manifest labelsI18n: " + labelsI18n);
JSONArray labelEn = labelsI18n.getJSONArray("en");
System.out.println("*************** IIIF Manifest labelEn: " + labelEn);
label = labelEn.getString(0);
System.out.println("*************** IIIF Manifest label: " + label);
images = canvas.getJSONArray("items");
JSONObject images2 = images.getJSONObject(0);
images = images2.getJSONArray("items");
JSONObject image = images.getJSONObject(0);
JSONObject body = image.getJSONObject("body");
System.out.println("*************** IIIF Manifest body: " + body);
String type = body.getString("type");
if (type.toUpperCase().equals("CHOICE")) {
images = body.getJSONArray("items");
body = images.getJSONObject(0);
}
System.out.println("*************** IIIF Manifest body final: " + body);
JSONArray services = body.getJSONArray("service");
JSONObject service = images.getJSONObject(0);
serviceURL = service.getString("id");
}
else {
label = canvas.getString("label");
System.out.println("IIIF Manifest label: " + label);
JSONObject image = images.getJSONObject(0);
JSONObject resource = image.getJSONObject("resource");
JSONObject service = resource.getJSONObject("service");
serviceURL = service.getString("@id");
}
String fullURL = "iiif://|"+manifestURL+"|"+i+"|"+serviceURL;
out.print("- " + label + "
");
}
out.print("
");
}
catch (Exception e) {
e.printStackTrace();
}
%>