%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Document" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Page" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription.Convert" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription.Convert.VerseTranscription" %>
<%@ page import="java.util.Vector" %>
<%@ page import="org.crosswire.sword.keys.VerseKey" %>
<%@ page import="org.crosswire.sword.keys.ListKey" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="javax.validation.constraints.NotNull" %>
<%!
@Description(value = "Retrieve the best guess page given info about the page.", name = "transcription/getbestguesspage")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "manuscript id", example = "10046")
public Integer docID = null;
@Description(value = "folio number of the page, if available", example = "3r")
public String folio = null;
@Description(value = "verses found on the page, if available", example = "Jn.3.3-6,12-19")
public String verses = null;
@Description(value = "last pageID, for context if sequentially iterating a doc, if available", example = "10")
public Integer lastPageID = null;
@Description(value = "assures the guess page exists", defaultValue = "false", example = "true")
public Boolean createPageIfNecessary = false;
@Override
protected void customValidation() {
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
Document doc = Document.getDocument(params.docID);
if (doc != null) {
Page lastPage = doc.getPages()[doc.getPages().length-1];
Vector outstandingVerses = new Vector();
if (params.verses != null) {
VerseKey parser = new VerseKey("mat");
parser.setIntros(true);
ListKey listKey = parser.ParseVerseList(params.verses, parser.toString(), true);
for (; listKey.popError() == 0; listKey.increment()) {
outstandingVerses.add(new VerseTranscription(new VerseKey(listKey).getHashNumber(), ""));
}
}
Page p = Convert.getBestGuessPage(doc, params.folio, outstandingVerses, params.lastPageID, params.createPageIfNecessary);
Serializer.output(response, out, params, XMLBlock.createXMLBlock(" lastPage.getPageID() ? "new" : "found") + "\" value=\"" + p.getPageID() + "\" />"));
return;
}
else params.addError(-5, "docID: " + params.docID + ", not found.");
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>