<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.utils.HTTPUtils" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.List" %> <%@ page import="java.util.Comparator" %> <%@ page import="java.util.Collections" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Document.SearchFilter" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Feature" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Document" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.webtools.*" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="javax.validation.constraints.Pattern" %> <%! @Description(value = "Retrieve List of Coptic Biblical Manuscripts (LCBM).", name = "lcbm/get") public static class MyParameters extends Parameters { @Pattern(regexp = "^(xml|json|csv|html)?$", message = "Valid response formats: \"xml\", \"json\", \"csv\", or \"html\"") @Description(value = "specify the result format: xml, json, csv, html", defaultValue = "xml", example = "html") public String format = null; @Description(value = "include edit click for first column", defaultValue = "false", example = "true") public Boolean editClicks = false; @Description(value = "show usage for this web service", defaultValue = "false", example = "true") public Boolean usage = false; @Override protected void afterLoad() { } @Override protected void customValidation() { if (format != null) super.format = format; } } public static List getSMRDocs() { List retVal = new ArrayList(); String smrURL = "http://intf.uni-muenster.de/smr/smr-table.php"; String smrParams = "smr=&biblia=&Sigel=0&Ort=&button=Suche"; StringBuffer smrResult = HTTPUtils.postURL(smrURL, smrParams, HTTPUtils.POST); for (String row = Transcription.popElement(smrResult, "tr"); row != null; row = Transcription.popElement(smrResult, "tr")) { Document d = new Document(); StringBuffer r = new StringBuffer(row); String td = Transcription.popElement(r, "td"); String val = Transcription.getTagValue(td); d.setGANumber(val); d.setValue("SMRNUMBER", val); val = val.replaceAll("[A-Za-z {}]", ""); int docID = 0; try { docID = Integer.parseInt(val); } catch(Exception e) {e.printStackTrace();} if (docID == 0) continue; val = d.getGANumber(); if (val.startsWith("sa")) docID += 620000; else if (val.startsWith("bo")) docID += 600000; else if (val.startsWith("pbo")) docID += 600000; else if (val.startsWith("ac")) docID += 631000; else if (val.startsWith("fa")) docID += 632000; else if (val.startsWith("cv")) docID += 632500; else if (val.startsWith("cw")) docID += 632700; else if (val.startsWith("fa")) docID += 632000; else if (val.startsWith("mae")) docID += 633000; else if (val.startsWith("ly")) docID += 634000; if (docID < 600000) { System.out.println("Warning: " + val + " not recognized."); continue; } d.setDocumentID(docID); td = Transcription.popElement(r, "td"); if (td != null) { val = Transcription.getTagValue(td); d.setValue("BCID", val); } td = Transcription.popElement(r, "td"); if (td != null) { val = Transcription.getTagValue(td); d.setValue("HORNER", val); } td = Transcription.popElement(r, "td"); if (td != null) { val = Transcription.getTagValue(td); val = val.replaceAll("[^<]*", ""); val = val.replaceAll("
", ""); val = val.replaceAll("\n
", ";"); val = val.replaceAll("
", ""); val = val.replaceAll(" ", " "); d.setValue("SHELFDESC", val); } td = Transcription.popElement(r, "td"); td = Transcription.popElement(r, "td"); if (td != null) { val = Transcription.getTagValue(td); val = val.replaceAll("", ""); val = val.replaceAll("", ""); val = val.replaceAll("
", ";"); val = val.replaceAll(" ", " "); val = val.replaceAll(" ", " "); val = val.replaceAll(";$", ""); val = val.replaceAll(";([^ ])", "; $1"); d.setContentOverview(val); } retVal.add(d); } return retVal; } public static List getCoptOTDocs() { List retVal = new ArrayList(); Document.SearchFilter searchFilter = new Document.SearchFilter(); searchFilter.docID = 622000; searchFilter.maxDocID = 623999; Document otDocs[] = Document.searchDocuments(false, searchFilter); for (Document d : otDocs) { Feature f = null; String bcID = ""; f = d.getFeature("BCID"); if (f != null) bcID = f.getStringVal1(); String comment = ""; f = d.getFeature("Comment"); if (f != null) comment = f.getStringVal1(); String type = ""; f = d.getFeature("LectionBookTypeCopt"); if (f != null) comment = f.getStringVal1(); String smrNumber = ""; String horner = ""; d.setValue("CONTENTCOMPUTED", d.getComputedContentOverview()); d.setValue("SHELFDESC", d.getShelfInstancesDescription()); d.setValue("BCID", bcID); d.setValue("CODEXTYPE", type); d.setValue("COMMENTS", comment); retVal.add(d); } return retVal; } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response, false); if (params.getErrors().size() == 0 && !params.usage) { List docs = getSMRDocs(); docs.addAll(getCoptOTDocs()); Collections.sort(docs, new Comparator() { public int compare(Document o1, Document o2) { return o1.getDocumentID() - o2.getDocumentID(); } }); StringBuffer retVal = new StringBuffer(); retVal.append(""); for (Document d : docs) { String bcID = d.getStringValue("BCID"); String comment = d.getStringValue("COMMENTS"); String type = d.getStringValue("CODEXTYPE"); String smrNumber = d.getStringValue("SMRNUMBER"); String horner = d.getStringValue("HORNER"); retVal.append(""); retVal.append("" + HTTPUtils.canonize(d.getStringValue("SHELFDESC")) + ""); retVal.append("" + HTTPUtils.canonize(d.getContentOverview()) + ""); retVal.append("" + HTTPUtils.canonize(d.getStringValue("CONTENTCOMPUTED")) + ""); retVal.append("" + HTTPUtils.canonize(d.getPrimaryName()) + ""); retVal.append("" + HTTPUtils.canonize(smrNumber) + ""); retVal.append("" + HTTPUtils.canonize(bcID) + ""); retVal.append("" + HTTPUtils.canonize(horner) + ""); retVal.append("" + HTTPUtils.canonize(type) + ""); retVal.append("" + HTTPUtils.canonize(comment) + ""); retVal.append(""); } retVal.append(""); XMLBlock result = XMLBlock.createXMLBlock(retVal.toString()); if ("html".equals(params.format)) { response.setContentType("text/html"); %> <% for (XMLBlock r : result.getBlocks("cbm")) { %> <% } %>
LCBM number Collection call number Content CoptOT number Schüssler BC SMR number Horner sigla / GA number Codex type/Lectionary type Notes
><%=r.getAttribute("lcbmNumber")%> <%=r.getValue("collectionCallNumber")%> <%=r.getValue("content")%> ><%=r.getValue("coptOTNumber")%> <%=r.getValue("schuesslerBC")%> <%=r.getValue("smrNumber")%> <%=r.getValue("hornerGAID")%> <%=r.getValue("codexTypeLectType")%> <%=r.getValue("notes")%>
<% } else Serializer.output(response, out, params, result); return; } else ((Parameters)params).format = "html"; Serializer.reportErrors(request, response, out, params, true); %>