%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.utils.Utils" %>
<%@ page import="org.crosswire.utils.Sessions" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.xml.XMLTag" %>
<%@ page import="org.crosswire.repo.VersionedRepo" %>
<%@ page import="org.crosswire.utils.HTTPUtils" %>
<%@ page import="org.crosswire.sword.keys.VerseKey" %>
<%@ page import="org.crosswire.sword.keys.ListKey" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %>
<%@ 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.Map" %>
<%@ page import="java.util.Vector" %>
<%@ page import="org.apache.log4j.Logger" %>
<%
Logger logger = Logger.getLogger("transcript/import");
try {
String sessionHash = Sessions.getSessionHash(request);
String transcript = request.getParameter("text");
/*
if (transcript != null) { transcript = new String(transcript.getBytes("iso8859-1"), "UTF-8");
if (transcript.replaceAll("[a-z,A-Z,0-9<> .:;'\"!,]", "").indexOf("?") == 0) transcript = request.getParameter("text");}
*/
if (transcript != null && !transcript.trim().startsWith("")) transcript = "" + transcript;
if (transcript != null) {
response.setContentType("text/xml");
StringBuffer pages[] = Transcription.Convert.splitTEIIntoPages(transcript);
%>
<%
String document = null;
Document lastDocument = null;
for (StringBuffer pg : pages) {
String folio = null;
Document d = null;
String verses = null;
Integer pageNumber = null;
try {
XMLBlock b = XMLBlock.createXMLBlock(pg.toString());
XMLTag t[] = b.getTagsFromXPath("/t:TEI/t:teiHeader/t:fileDesc/t:titleStmt/t:title[@type='document']", "t", "http://www.tei-c.org/ns/1.0");
if (t != null && t.length > 0) document = t[0].getAttribute("n");
if (document.endsWith("S")) document = document.substring(0,document.length()-1);
logger.info("document: " + document);
t = b.getTagsFromXPath("/t:TEI/t:text/t:body/t:pb[@type='folio']", "t", "http://www.tei-c.org/ns/1.0");
if (t != null && t.length > 0) folio = t[0].getAttribute("n");
t = b.getTagsFromXPath("/t:TEI/t:text/t:body//t:ab", "t", "http://www.tei-c.org/ns/1.0");
if (t != null) {
verses = "";
getVerseFromBKV(null);
for (XMLTag vt : t) {
String v = vt.getAttribute("n");
verses += getVerseFromBKV(v);
}
}
if (lastDocument != null && document.equals(lastDocument.getGANumber())) {
d = lastDocument;
}
else d = Document.getDocumentByGANumber(document);
if (d != null) {
lastDocument = d;
Page p = getBestGuessPage(d, verses, folio);
pageNumber = p.getPageID();
d.setTranscriptionPage(p.getPageID(), pg.toString(), "tagriffitts", true, true, false, "tagriffitts");
%>
<%
continue;
}
}
catch (Exception e) { logger.error(e); }
%>
<%
/*
out.println("" + pg + "");
*/
}
%>
<%
VersionedRepo.push();
return;
}
} catch (Exception e) { e.printStackTrace(); return; }
%>
transcript/import
Import transcription XML
Parameters
| text | text of transcription |
<%!
public static Page getBestGuessPage(Document doc, String verses, String folio) {
Page lastPage = doc.getPages()[doc.getPages().length-1];
Vector outstandingVerses = new Vector();
if (verses != null) {
VerseKey parser = new VerseKey("mat");
ListKey listKey = parser.ParseVerseList(verses, parser.toString(), true);
for (; listKey.popError() == 0; listKey.increment()) {
outstandingVerses.add(new VerseTranscription(new VerseKey(listKey).getHashNumber(), ""));
}
}
Page p = Convert.getBestGuessPage(doc, folio, outstandingVerses, false); /* false - create pages if necessary */
return p;
}
static String books[] = {"",
"Matt",
"Mark",
"Luke",
"John",
"Acts",
"Rom",
"1Cor",
"2Cor",
"Gal",
"Eph",
"Phil",
"Col",
"1Thess",
"2Thess",
"1Tim",
"2Tim",
"Titus",
"Phlm",
"Heb",
"Jas",
"1Pet",
"2Pet",
"1John",
"2John",
"3John",
"Jude",
"Rev"
};
static String lastBook = "";
static String lastChap = "";
public static String getVerseFromBKV(String bkv) {
if (bkv == null) {
lastBook = lastChap = "";
return "";
}
if (bkv.lastIndexOf('_') > -1) bkv = bkv.substring(bkv.lastIndexOf('_')+1);
String book = bkv.substring(1,bkv.indexOf('K'));
String chap = bkv.substring(bkv.indexOf('K')+1, bkv.indexOf('V'));
String verse = bkv.substring(bkv.indexOf('V')+1);
String retVal = "";
if (!book.equals(lastBook)) {
retVal += books[Integer.parseInt(book)] + "."+Integer.parseInt(chap)+"."+Integer.parseInt(verse);
lastBook = book;
lastChap = chap;
}
else if (!chap.equals(lastChap)) {
retVal += "; "+Integer.parseInt(chap)+"."+Integer.parseInt(verse);
lastChap = chap;
}
else retVal += ","+Integer.parseInt(verse);
return retVal;
}
%>