<%@ 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="org.crosswire.webtools.RightsAndRoles" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.Vector" %> <%@ page import="org.apache.log4j.Logger" %> <%@ page import="org.apache.commons.fileupload.*" %> <%@ page import="java.io.BufferedReader" %> <%@ page import="java.io.File" %> <%@ page import="java.io.InputStream" %> <%@ page import="java.io.BufferedOutputStream" %> <%@ page import="java.io.InputStreamReader" %> <%@ page import="java.util.List" %> <%@ page import="java.net.URL" %> <%@ page import="org.crosswire.utils.HTTPUtils" %> <% Logger logger = Logger.getLogger("transcript/import"); try { //dumpCallInfo(request, logger); String sessionHash = Sessions.getSessionHash(request); String format = request.getParameter("format"); String serverPath = request.getParameter("serverPath"); int docID = -1; try { docID = Integer.parseInt(request.getParameter("docID")); } catch (Exception e) {} String transcript = request.getParameter("text"); if (transcript != null && !transcript.trim().startsWith("" + transcript; // See if we're receiving an upload of a transcription if (transcript == null) { try { DiskFileUpload fu = new DiskFileUpload(); // maximum size before a FileUploadException will be thrown fu.setSizeMax(99000000); // maximum size that will be stored in memory fu.setSizeThreshold(4096); // the location for saving data that is larger than getSizeThreshold() fu.setRepositoryPath(session.getServletContext().getRealPath("tmp/")); List fileItems = fu.parseRequest(request); for (int i = 0; i < fileItems.size(); i++) { FileItem fi = (FileItem)fileItems.get(i); if (fi.isFormField()) { if ("docID".equals(fi.getFieldName())) { try { docID = Integer.parseInt(fi.getString()); } catch (Exception e) {} } if ("format".equals(fi.getFieldName())) { format = fi.getString(); } } else { response.setContentType("text/xml"); byte uploadBytes[] = fi.get(); String transcription = new String(uploadBytes); } } } catch (Exception e) { e.printStackTrace(); } } if (serverPath != null) { if (serverPath.startsWith("/data/")) { transcript = Transcription.readFile(serverPath); } } if (transcript != null) { if ("imp".equals(format) && docID != -1) { String role = "VMR Administrator"; // let's check to see if we're a privileged user boolean permission = RightsAndRoles.hasRole(request, response, role); Document doc = Document.getDocument(docID); Map pages = new HashMap(); int offset = 0; for (offset = transcript.indexOf("$$$"); offset > -1; offset = transcript.indexOf("$$$", offset + 1)) { int end = transcript.indexOf("$$$", offset + 1); if (end < 0) end = transcript.length(); int vend = transcript.indexOf("\n", offset); if (vend < 0) break; String verseRef = transcript.substring(offset+3, vend).trim(); String verseBody = transcript.substring(vend+1,end).trim(); VerseKey parser = new VerseKey(); parser.setIntros(true); parser.setText(verseRef); int hash = parser.getHashNumber(); hash = hash / 100 * 100; String p = pages.get(hash); if (p == null) p = ""; p += ""; p += verseBody; p += "\n"; pages.put(hash, p); } for (int hash : pages.keySet()) { String ptext = pages.get(hash); Page p = Page.getPage(docID, hash); if (p == null) { // we check permissions here instead of at the top because folio editing can be done by anyone logged in if (!permission) { %> <% return; } p = new Page(); p.setDocumentID(docID); p.setPageID(hash); p = p.saveNew(); VerseKey vk = new VerseKey(); vk.setIntros(true); vk.setHashNumber(hash); p.saveBiblicalContent(vk.getBookName() + "."+vk.getChapter(), "NA28"); } doc.setTranscriptionPage(hash, ptext, null, true, false, false, "NA28"); } } else { 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("import 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

texttext of transcription
dociduse this docID instead of one found in the manuscript
format(tei), imp
<%! 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, 1, 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; } public static void dumpCallInfo(HttpServletRequest request, Logger logger) { logger.info("collate called..."); logger.info("request.getContentType: " + request.getContentType()); logger.info("Headers: "); for (Object o: java.util.Collections.list(request.getHeaderNames())) { logger.info(o + "=" + request.getHeader(o.toString())); } logger.info("Attributes: "); for (Object o: java.util.Collections.list(request.getAttributeNames())) { logger.info(o + "=" + request.getAttribute(o.toString())); } logger.info("Parameters: "); for (Object o: java.util.Collections.list(request.getParameterNames())) { for (String v: request.getParameterValues(o.toString())) { logger.info(o + "=" + v); } } } %>