<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.utils.Sessions" %> <%@ page import="org.crosswire.data.DataObject" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.xml.XMLDataElement" %> <%@ 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.Document.SearchFilter" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Document.SearchFilter.FeatureCriteria" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Page" %> <%@ page import="org.crosswire.sword.keys.VerseKey" %> <%@ page import="java.util.Vector" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashSet" %> <%@ page import="java.util.Date" %> <%@ page import="org.apache.log4j.Logger" %> <% Logger logger = Logger.getLogger("paratext/get"); String userName = Sessions.getSessionStringValue(request, "userName"); long featureID = -1; try {featureID = Long.parseLong(request.getParameter("featureID"));} catch (Exception e){} int docID = -1; try {docID = Integer.parseInt(request.getParameter("docID"));} catch (Exception e){} int diktyonNumber = -1; try {diktyonNumber = Integer.parseInt(request.getParameter("diktyonNumber"));} catch (Exception e){} if (docID > -1 || featureID > -1 || diktyonNumber > -1) { HashMapshelfToDiktyon = new HashMap(); response.setContentType("text/xml"); Vector texts = new Vector(); XMLBlock textsBlock = XMLBlock.createXMLBlock(""); XMLBlock outputBlock = null; Document document = null; if (diktyonNumber > -1) { SearchFilter sf = new SearchFilter(); FeatureCriteria fc = new FeatureCriteria("DiktyonNumber", Feature.AuxDataField.INTVAL1, FeatureCriteria.OPERATOR_EQUALS, new Integer(diktyonNumber)); sf.addFeatureCriteria(fc); if (docID > -1) sf.docID = docID; Document docs[] = Document.searchDocuments(true, sf); for (Document d : docs) { for (Feature f : Feature.getFeatures(d.getDocumentID())) { if (fc.matches(f)) { docID = d.getDocumentID(); shelfToDiktyon.put(f.getIntVal2(), diktyonNumber); } } } if (shelfToDiktyon.isEmpty()) { %> <% return; } } if (docID > -1) { document = Document.getDocument(docID); if (document == null) { %> <% return; } SearchFilter sf = new SearchFilter(); sf.docID=docID; FeatureCriteria fc = new FeatureCriteria("ParatexBib"); sf.addFeatureCriteria(fc); Document docs[] = Document.searchDocuments(true, sf); for (Document d : docs) { for (Page p : d.getPages()) { for (Feature f : Feature.getFeatures(p.getDocumentID(), p.getPageID())) { if (fc.matches(f)) { Page fullPage = Page.getPage(f.getDocumentID(), f.getPageID()); f.setIntValue("SHELFID", fullPage.getFirstShelfID()); texts.add(f); } } } } if (diktyonNumber < 0) { SearchFilter sf2 = new SearchFilter(); FeatureCriteria fc2 = new FeatureCriteria("DiktyonNumber", Feature.AuxDataField.INTVAL1, FeatureCriteria.OPERATOR_EQUALS, new Integer(diktyonNumber)); sf2.addFeatureCriteria(fc2); Document docs2[] = Document.searchDocuments(true, sf2); for (Document d : docs2) { for (Feature f : Feature.getFeatures(d.getDocumentID())) { if (fc2.matches(f)) { shelfToDiktyon.put(f.getIntVal2(), diktyonNumber); } } } } document = Document.getDocument(document.getDocumentID()); // do a full lookup to get aux data like shelf instances outputBlock = XMLBlock.createXMLBlock(document.toFormattedXML(DataObject.FORMAT_FULL | DataObject.DETAIL_COMPLETE)); textsBlock = outputBlock.createBlock("texts"); } else { Feature feature = Feature.getFeature(featureID); if (feature != null) { if ("ParatexBib".equals(feature.getFeatureCode())) { texts.add(feature); } else { %> <% return; } } else { %> <% return; } } for (Feature feature : texts) { Vector features = new Vector(); features.add(feature); SearchFilter sf = new SearchFilter(); FeatureCriteria fc = new FeatureCriteria("ParatexBibContinuation", Feature.AuxDataField.INTVAL2, FeatureCriteria.OPERATOR_EQUALS, new Integer(feature.getFeatureID())); sf.addFeatureCriteria(fc); Document docs[] = Document.searchDocuments(true, sf); long latestModified = feature.getCreateDate().getTime(); for (Document d : docs) { for (Page p : d.getPages()) { for (Feature f : Feature.getFeatures(p.getDocumentID(), p.getPageID())) { if (fc.matches(f)) { Page fullPage = Page.getPage(p.getDocumentID(), p.getPageID()); f.setIntValue("SHELFID", fullPage.getFirstShelfID()); features.add(f); if (f.getCreateDate().getTime() > latestModified) latestModified = f.getCreateDate().getTime(); } } } } XMLBlock text = textsBlock.createBlock("text"); text.setAttribute("featureID", Integer.toString(feature.getFeatureID())); text.setAttribute("timestampID", Long.toString(latestModified/1000)); XMLBlock featuresBlock = text.createBlock("features"); for (Feature f : features) { featuresBlock.addBlock(formatParatexBibXML(f.toFormattedXML(), shelfToDiktyon.get(f.getIntValue("SHELFID")))); } } if (docID > -1) { HashMap books = new HashMap(); HashMap openBooks = new HashMap(); Document doc = Document.getDocument(docID); for (Page p : doc.getPages(true)) { Integer verses[] = p.getVerses(); HashSet endBooks = new HashSet(); if (verses != null && verses.length > 0) { endBooks = new HashSet(openBooks.keySet()); for (int v : verses) { VerseKey vk = new VerseKey(); vk.setIntros(true); vk.setHashNumber(v); String bookName = vk.getOSISBookName(); endBooks.remove(bookName); if (openBooks.get(bookName) == null) { long fid = 970000000000L + docID * 10000 + vk.getTestament() * 1000 + vk.getBook() * 10; XMLBlock text = books.get(bookName); boolean first = false; if (text == null) { first = true; text = textsBlock.createBlock("text"); text.setAttribute("featureID", Long.toString(fid)); text.setAttribute("timestampID", Long.toString(System.currentTimeMillis()/1000)); text.setAttribute("biblicalBook", bookName); text.createBlock("features"); books.put(bookName, text); } XMLBlock features = text.getBlock("features"); XMLBlock feature = features.createBlock("feature"); feature.setAttribute("createDate", new Date().toString()); feature.setAttribute("docID", Integer.toString(docID)); feature.setAttribute("featureCode", "ParatexBib"+(first?"":"Continuation")); feature.setAttribute("featureID", Long.toString(fid+features.getBlocks("feature").length-1)); feature.setAttribute("pageID", Integer.toString(p.getPageID())); feature.setAttribute("lastSeenPageID", Integer.toString(p.getPageID())); feature.setAttribute("userID", p.getIndexerID()); feature.createValue("auxData", "single").setAttribute("fieldName", "type"); feature.createValue("auxData", bookName).setAttribute("fieldName", "biblicalBook"); addFolioTags(feature, p.getFolioNumber()); openBooks.put(bookName, feature); logger.debug("starting book: " + bookName + "; pageID: " + feature.getAttribute("pageID")); } else openBooks.get(bookName).setAttribute("lastSeenPageID", Integer.toString(p.getPageID())); } } for (String b : endBooks) { XMLBlock feature = openBooks.get(b); logger.debug("ending book: " + b+ "; pageID: " + feature.getAttribute("pageID")); if (Integer.parseInt(feature.getAttribute("pageID")) != Integer.parseInt(feature.getAttribute("lastSeenPageID"))) { Page prevPage = Page.getPage(docID, Integer.parseInt(feature.getAttribute("lastSeenPageID"))); String bookName = ""; for (XMLDataElement de : feature.getElements("auxData")) { if (de.getAttribute("fieldName").equals("type")) de.setText("open"); if (de.getAttribute("fieldName").equals("biblicalBook")) bookName = de.getText(); } long fid = Long.parseLong(feature.getAttribute("featureID")); XMLBlock closeFeature = books.get(bookName); XMLBlock features = closeFeature.getBlock("features"); closeFeature = features.createBlock("feature"); closeFeature.setAttribute("createDate", new Date().toString()); closeFeature.setAttribute("docID", Integer.toString(docID)); closeFeature.setAttribute("featureCode", "ParatexBibContinuation"); closeFeature.setAttribute("featureID", Long.toString(fid+features.getBlocks("feature").length-1)); closeFeature.setAttribute("pageID", feature.getAttribute("lastSeenPageID")); closeFeature.setAttribute("userID", prevPage.getIndexerID()); closeFeature.createValue("auxData", "close").setAttribute("fieldName", "type"); closeFeature.createValue("auxData", bookName).setAttribute("fieldName", "biblicalBook"); addFolioTags(closeFeature, prevPage.getFolioNumber()); closeFeature.createValue("auxData", Long.toString(fid+features.getBlocks("feature").length-2)).setAttribute("fieldName", "paratexBibFeatureID"); } feature.setAttribute("lastSeenPageID", null); openBooks.remove(b); } } for (String b : openBooks.keySet()) { XMLBlock feature = openBooks.get(b); if (Integer.parseInt(feature.getAttribute("pageID")) != Integer.parseInt(feature.getAttribute("lastSeenPageID"))) { Page prevPage = Page.getPage(docID, Integer.parseInt(feature.getAttribute("lastSeenPageID"))); String bookName = ""; for (XMLDataElement de : feature.getElements("auxData")) { if (de.getAttribute("fieldName").equals("type")) de.setText("open"); if (de.getAttribute("fieldName").equals("biblicalBook")) bookName = de.getText(); } long fid = Long.parseLong(feature.getAttribute("featureID")); //System.out.println("bookName: " + bookName); //System.out.println("books.size: " + books.size()); XMLBlock closeFeature = books.get(bookName); XMLBlock features = closeFeature.getBlock("features"); closeFeature = features.createBlock("feature"); closeFeature.setAttribute("createDate", new Date().toString()); closeFeature.setAttribute("docID", Integer.toString(docID)); closeFeature.setAttribute("featureCode", "ParatexBibContinuation"); closeFeature.setAttribute("featureID", Long.toString(fid+features.getBlocks("feature").length-1)); closeFeature.setAttribute("pageID", feature.getAttribute("lastSeenPageID")); closeFeature.setAttribute("userID", prevPage.getIndexerID()); closeFeature.createValue("auxData", "close").setAttribute("fieldName", "type"); closeFeature.createValue("auxData", bookName).setAttribute("fieldName", "biblicalBook"); addFolioTags(closeFeature, prevPage.getFolioNumber()); closeFeature.createValue("auxData", Long.toString(fid+features.getBlocks("feature").length-2)).setAttribute("fieldName", "paratexBibFeatureID"); openBooks.remove(b); } feature.setAttribute("lastSeenPageID", null); } out.print(outputBlock.toString()); } else { out.print(textsBlock.getBlock("text").toString()); } return; } %>

paratext/get

Retrieve information about a paratext

Parameters

featureIDfeatureID of a specific ParatexBib tag to retrieve
docIDdocument id from which to retrieve all ParatexBib tags
TODO: diktyonNumberDiktyon Number from which to retrieve all ParatexBib tags
<%! /** * take Feature xml and format it to ParatexBib XML */ static XMLBlock formatParatexBibXML(String featureXML, Integer diktyonNumber) { XMLBlock xml = XMLBlock.createXMLBlock(featureXML); if (diktyonNumber != null) { xml.setAttribute("diktyonNumber", diktyonNumber.toString()); } XMLDataElement v = xml.getElement("intVal1"); if (v != null) { String val = "1".equals(v.getText()) ? "open" : "2".equals(v.getText()) ? "close" : "single"; xml.createValue("auxData", val).setAttribute("fieldName", "type"); xml.removeChild(v); } v = xml.getElement("stringVal2"); if (v != null) { String vals[] = v.getText().split("\\|"); if (vals.length > 0) { if (vals[0].length() > 0 && !"undefined".equals(vals[0]) && !"null".equals(vals[0])) { xml.createValue("auxData", vals[0]).setAttribute("fieldName", "zone"); } if (vals.length > 1 && vals[1].length() > 0 && !"undefined".equals(vals[1]) && !"null".equals(vals[1])) { xml.createValue("auxData", vals[1]).setAttribute("fieldName", "position"); } } xml.removeChild(v); } v = xml.getElement("stringVal1"); if (v != null) { String vals[] = v.getText().split("\\|"); if (vals.length > 1) { xml.createValue("auxData", vals[0]).setAttribute("fieldName", "pageFolioNumberType"); xml.createValue("auxData", vals[1]).setAttribute("fieldName", "pageFolioNumberValue"); if (vals.length > 2 && vals[2].length() > 0 && !"undefined".equals(vals[2])) { xml.createValue("auxData", vals[2]).setAttribute("fieldName", "pageFolioNumberSide"); } } xml.removeChild(v); } v = xml.getElement("intVal2"); if (v != null) { if ("ParatexBib".equals(xml.getAttribute("featureCode"))) { String nvals[] = {"Prologus", "Capitula", "Imago", "Annotatio", "Subscriptio", "Eusebius", "Tabulae liturgicae", "Epigrammata", "Others", "Scholia exegetica"}; String nval = v.getText(); String nvalOrig = nval; int n = 0; try { n = Integer.parseInt(nval); } catch (Exception e) {} --n; if (n > -1 && n < nvals.length) nval = nvals[n]; XMLDataElement t = xml.createValue("auxData", nval); t.setAttribute("fieldName", "category"); t.setAttribute("value", nvalOrig); } else { xml.createValue("auxData", v.getText()).setAttribute("fieldName", "paratexBibFeatureID"); } xml.removeChild(v); } return xml; } static void addFolioTags(XMLBlock feature, String folio) { String ftype = "p."; String fval = feature.getAttribute("pageID"); String fside = null; if (folio != null && folio.length() > 0) { char last = folio.charAt(folio.length()-1); if (!Character.isDigit(last)) { ftype = "f."; fval = folio.substring(0, folio.length()-1); fside = ""+last; } } feature.createValue("auxData", ftype).setAttribute("fieldName", "pageFolioNumberType"); feature.createValue("auxData", fval).setAttribute("fieldName", "pageFolioNumberValue"); if (fside != null) { feature.createValue("auxData", fside).setAttribute("fieldName", "pageFolioNumberSide"); } } %>