[sword-svn] r458 - trunk/webapp

scribe at crosswire.org scribe at crosswire.org
Fri Oct 14 10:37:31 EDT 2022


Author: scribe
Date: 2022-10-14 10:37:31 -0400 (Fri, 14 Oct 2022)
New Revision: 458

Modified:
   trunk/webapp/fetchdata.jsp
Log:
Lots of updates since last commit.  Too many to enumerate here


Modified: trunk/webapp/fetchdata.jsp
===================================================================
--- trunk/webapp/fetchdata.jsp	2022-01-03 19:56:30 UTC (rev 457)
+++ trunk/webapp/fetchdata.jsp	2022-10-14 14:37:31 UTC (rev 458)
@@ -29,10 +29,17 @@
 	if (ks != null && !"betacode".equals(modName)) {
 		ks = new String(ks.getBytes("iso8859-1"), "UTF-8");
 	}
+//System.out.println("****");
+//System.out.println("ks: " + ks);
 //	if (ks != null) ks = new String(ks.getBytes("iso8859-1"), "UTF-8");
 	String fn = request.getParameter("fn");
 	String format = request.getParameter("format");
-	mgr.setGlobalOption("Footnotes", "Off");
+	boolean pages = "true".equals(request.getParameter("pages"));
+
+	String footnotes = request.getParameter("footnotes");
+	footnotes = (!"On".equals(footnotes)) ? "Off" : "On";
+	mgr.setGlobalOption("Footnotes", footnotes);
+
 	mgr.setGlobalOption("Cross-references", "Off");
 
 //System.out.println("****");
@@ -81,12 +88,14 @@
 
 			// ------ betacode lookup from perseus ------------------------------------------------
 			if ("betacode".equals(modName)) {
+//System.out.println("Perseus Lookup: " + key);
 				String ls = org.crosswire.swordweb.PerseusUtils.getLiddellScottDef(key);
+//System.out.println("Perseus returned: " + ls);
 				if (ls.length() > 0) {
 %>
 					<%= ls %>
 					<div class="copyLine">from Liddell and Scott, <i>An Intermediate Greek-English Lexicon</i><br/>
-					Courtesy of <a href="http://www.perseus.tufts.edu">Perseus Digital Library</a></div>
+					Courtesy of <a href="//www.perseus.tufts.edu">Perseus Digital Library</a></div>
 <%
 				}
 				else {
@@ -114,7 +123,7 @@
 					catch (Exception e) { activeKey = key; } // not an error, just hopefully have entire versekey already
 					String vk[] = book.parseKeyList(activeKey);
 					activeKey=vk[0];
-					StringBuffer vmrResponse = HTTPUtils.postURL("http://ntvmr.uni-muenster.de/community/vmr/api/metadata/liste/search/", "biblicalContent="+activeKey+"&detail=page&limit=40");
+					StringBuffer vmrResponse = HTTPUtils.postURL("https://ntvmr.uni-muenster.de/community/vmr/api/metadata/liste/search/", "biblicalContent="+activeKey+"&detail=page&limit=40");
 //System.out.println("**** response: " + vmrResponse);
 					XMLBlock manuscripts = new XMLBlock(vmrResponse.toString());
 %>
@@ -146,7 +155,7 @@
 									transURL = block.getAttribute("uri");
 								}
 							}
-							String mssURL = "http://ntvmr.uni-muenster.de/manuscript-workspace?docID=" + m.getAttribute("docID")+"&pageID="+p.getAttribute("pageID");
+							String mssURL = "//ntvmr.uni-muenster.de/manuscript-workspace?docID=" + m.getAttribute("docID")+"&pageID="+p.getAttribute("pageID");
 %>
 							<tr>
 								<td><a href="<%=mssURL%>" target="NTVMR">
@@ -196,7 +205,7 @@
 						</tbody>
 						</table>
 						</div>
-						<div class="copyLine"><br/>This dataset is by no means exhaustive and is growing rapidly. Check back soon for more results.<br/><br/>Courtesy of <a href="http://egora.uni-muenster.de/intf/index_en.shtml">Institut für Neutestamentliche Textforschung</a></div>
+						<div class="copyLine"><br/>This dataset is by no means exhaustive and is growing rapidly. Check back soon for more results.<br/><br/>Courtesy of <a href="//egora.uni-muenster.de/intf/index_en.shtml">Institut für Neutestamentliche Textforschung</a></div>
 <%
 				}
 			}
@@ -233,6 +242,13 @@
 //System.out.println(key);
 //System.out.println(keyList[0]);
 					
+					if ("json".equals(format)) {
+						response.setContentType("application/json");
+						out.print("{ \"result\": [ ");
+					}
+					if ("raw".equals(format)) {
+						response.setContentType("text/plain");
+					}
 					if ("tei".equals(format)) {
 						response.setContentType("text/xml");
 %>
@@ -288,6 +304,7 @@
 
 					String lastBook = "";
 					String lastChapter = "";
+					String lastShownPBN = "";
 					for (int k = 0; k < keyList.length; ++k) {
 						String k1 = keyList[k];
 						if (k1 == null) continue;
@@ -304,6 +321,19 @@
 						}
 //System.out.println("key: " + k1);
 						book.setKeyText(k1);
+						String keyChildren[] = book.getKeyChildren();
+						String nowTestament = keyChildren.length > VERSEKEY_TESTAMENT ? keyChildren[VERSEKEY_TESTAMENT] : "";
+						String nowBook = keyChildren.length > VERSEKEY_BOOK ? keyChildren[VERSEKEY_BOOK] : "";
+						String nowChapter = keyChildren.length > VERSEKEY_CHAPTER ? keyChildren[VERSEKEY_CHAPTER] : "";
+						String nowVerse = keyChildren.length > VERSEKEY_VERSE ? keyChildren[VERSEKEY_VERSE] : "";
+						String nowBookAbbrev = keyChildren.length > VERSEKEY_BOOKABBREV ? keyChildren[VERSEKEY_BOOKABBREV] : "";
+						String nowBookName = keyChildren.length > VERSEKEY_BOOKNAME ? keyChildren[VERSEKEY_BOOKNAME] : "";
+						String nowOSISRef = keyChildren.length > VERSEKEY_OSISREF ? keyChildren[VERSEKEY_OSISREF] : "";
+						boolean hasEntry = book.getRawEntry().length() > 0;
+						// skip empty incipits and explicits
+						if (nowVerse.equals("0") && !hasEntry) {
+							continue;
+						}
 //System.out.println("book key: " + book.getKeyText());
 						if (("StrongsGreek".equals(modName)) && ("3588".equals(k1))) {
 							out.print("with Greek Article");
@@ -336,15 +366,9 @@
 						}
 						else {
 							if ("raw".equals(format) || "tei".equals(format)) {
-/*
-%>
-<milestone k="<%=k%>" key="<%=k1%>" keyText="<%=book.getKeyText()%>"/>
-<%
-*/
-
 								// ----- header for trier tinymce editor ------
 								if ("tei".equals(format)) {
-									if (inChapter != null && (!book.getKeyChildren()[VERSEKEY_CHAPTER].equals(inChapter) || !book.getKeyChildren()[VERSEKEY_BOOK].equals(inBook) || book.getKeyChildren()[VERSEKEY_VERSE].equals("0"))) {
+									if (inChapter != null && (!nowChapter.equals(inChapter) || !nowBook.equals(inBook) || nowVerse.equals("0"))) {
 	if (!"0".equals(inChapter)) {
 %>
 </div>
@@ -351,42 +375,70 @@
 <%
 	}
 									}
-									if (inBook != null && !book.getKeyChildren()[VERSEKEY_BOOK].equals(inBook)) {
+									if (inBook != null && !nowBook.equals(inBook)) {
 %>
 </div>
 <%
 									}
-									if (!book.getKeyChildren()[VERSEKEY_BOOK].equals(inBook)) {
+									if (!nowBook.equals(inBook)) {
+										if (pages) {
+											int t = Integer.parseInt(nowTestament);
+											int b = Integer.parseInt(nowBook);
+											int c = Integer.parseInt(nowChapter);
+											if (b == 0) b = 1;
+											if (c == 0) c = 1;
+											String n = String.format("%d%03d%03d000", t, b, c);
+											if (!n.equals(lastShownPBN)) {
+	%>
+	<pb n="<%=nowBookName + " " + c%>" osisID="<%=nowBookAbbrev + "." + c%>" pageID="<%=n%>" type="chapter"/>
+	<%
+												lastShownPBN = n;
+											}
+										}
 %>
-<div type="book" n="B<%= String.format("%02d", Integer.parseInt(book.getKeyChildren()[VERSEKEY_BOOK])) %>">
+<div type="book" n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>" osisID="<%=nowBookAbbrev%>">
 <%
 									}
-									if (!book.getKeyChildren()[VERSEKEY_CHAPTER].equals(inChapter) || !book.getKeyChildren()[VERSEKEY_BOOK].equals(inBook) || book.getKeyChildren()[VERSEKEY_VERSE].equals("0")) {
-										if (!book.getKeyChildren()[VERSEKEY_VERSE].equals("0")) {
+									if (!nowChapter.equals(inChapter) || !nowBook.equals(inBook) || nowVerse.equals("0")) {
+										if (!nowVerse.equals("0")) {
+											int t = Integer.parseInt(nowTestament);
+											int b = Integer.parseInt(nowBook);
+											int c = Integer.parseInt(nowChapter);
+											if (b == 0) b = 1;
+											if (c == 0) c = 1;
+											if (pages) {
+												String n = String.format("%d%03d%03d000", t, b, c);
+												if (!n.equals(lastShownPBN)) {
 %>
-<div type="chapter" n="B<%= String.format("%02d", Integer.parseInt(book.getKeyChildren()[VERSEKEY_BOOK])) %>K<%= book.getKeyChildren()[VERSEKEY_CHAPTER] %>">
+<pb n="<%=nowBookName + " " + c%>" osisID="<%=nowBookAbbrev + "." + c%>" pageID="<%=n%>" type="chapter"/>
 <%
+													lastShownPBN = n;
+												}
+											}
+%>
+<div type="chapter" n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>K<%= nowChapter %>" osisID="<%=nowBookAbbrev + "." + c%>">
+<%
 										}
 									}
-									inChapter = book.getKeyChildren()[VERSEKEY_CHAPTER];
-									inBook = book.getKeyChildren()[VERSEKEY_BOOK];
-									if (book.getKeyChildren()[VERSEKEY_VERSE].equals("0")) {
+									inChapter = nowChapter;
+									inBook = nowBook;
+									if (nowVerse.equals("0")) {
 										inChapter = "0";
-										if (book.getKeyChildren()[VERSEKEY_CHAPTER].equals("0")) {
-%><div type="incipit" n="B<%= String.format("%02d", Integer.parseInt(book.getKeyChildren()[VERSEKEY_BOOK])) %>incipit"><ab><%
+										if (nowChapter.equals("0")) {
+%><div type="incipit" n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>incipit" osisID="<%=nowOSISRef%>"><ab><%
 										}
-										else if (book.getKeyChildren()[VERSEKEY_CHAPTER].equals("1")) {
-%><div type="explicit" n="B<%= String.format("%02d", Integer.parseInt(book.getKeyChildren()[VERSEKEY_BOOK])) %>explicit"><ab><%
+										else if (nowChapter.equals("1")) {
+%><div type="explicit" n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>explicit" osisID="<%=nowOSISRef%>"><ab><%
 										}
 									}
 									else {
 %>
-<ab n="B<%= String.format("%02d", Integer.parseInt(book.getKeyChildren()[VERSEKEY_BOOK])) %>K<%= book.getKeyChildren()[VERSEKEY_CHAPTER] %>V<%= book.getKeyChildren()[VERSEKEY_VERSE] %>">
+<ab n="B<%= String.format("%02d", Integer.parseInt(nowBook)) %>K<%= nowChapter %>V<%= nowVerse %>" osisID="<%=nowOSISRef%>">
 <%
 									}
 								}
 								// --------------------------------------------
-									if ("WHNU".equals(modName) || "WLC".equals(modName) || "LXX".equals(modName) || "Vulgate".equals(modName)) {
+									if (!"raw".equals(format) && ("WHNU".equals(modName) || "WLC".equals(modName) || "LXX".equals(modName) || "Vulgate".equals(modName))) {
 %>
 <%= book.getStripText() %>
 <%
@@ -400,7 +452,7 @@
 										while (raw.indexOf("  ") > -1) raw = raw.replaceAll("  ", " ");
 										out.print(raw);
 									}
-									else if ("ThML".equals(book.getConfigEntry("SourceType"))) {
+									else if (!"raw".equals(format) && "ThML".equals(book.getConfigEntry("SourceType"))) {
 										mgr.setGlobalOption("Strong's Numbers", "Off");
 										mgr.setGlobalOption("Morphological Tags", "Off");
 										book.getRenderText();
@@ -410,6 +462,30 @@
 <%= raw %>
 <%
 									}
+									else if ("tei".equals(format)) {
+										String t = book.getRawEntry();
+										t = t.replaceAll("x-preverse\"/", "x-preverse\"");
+										if ("Off".equals(footnotes)) {
+											t = t.replaceAll("<note[^>]*[^/]>.*</note>", "");
+											t = t.replaceAll("<note[^>]*/>", "");
+											t = t.replaceAll("<note[^>]*>", "");
+											t = t.replaceAll("<ab [^>]*>", "");
+											t = t.replaceAll("</ab>", "");
+											t = t.replaceAll("</note>", "");
+											t = t.replaceAll("<hi[^>]*>", "");
+											t = t.replaceAll("</hi>", "");
+											t = t.replaceAll("<s [^>]*>", "");
+											t = t.replaceAll("</s>", "");
+											t = t.replaceAll("</w>([>:;,'ʼ˙··.\u2014\u2027])", "</w><pc>$1</pc>");
+											// if we're adding our own chapter <pb /> markers, then remove any <pb /> tags in the text
+											if (pages) {
+												t = t.replaceAll("<pb[^>]*/>", "");
+											}
+										}
+%>
+<%= t %>
+<%
+									}
 									else {
 %>
 <%= book.getRawEntry() %>
@@ -417,8 +493,8 @@
 									}
 								// ----- header for trier tinymce editor ------
 								if ("tei".equals(format)) {
-									if (book.getKeyChildren()[VERSEKEY_VERSE].equals("0")) {
-										if (book.getKeyChildren()[VERSEKEY_CHAPTER].equals("0") || book.getKeyChildren()[VERSEKEY_CHAPTER].equals("1")) {
+									if (nowVerse.equals("0")) {
+										if (nowChapter.equals("0") || nowChapter.equals("1")) {
 %></ab></div><%
 										}
 									} else {
@@ -433,15 +509,23 @@
 								// ----- header for trier tinymce editor ------
 								if ("basetext".equals(format)) {
 %>
-<span class="chapter_number" part="<%=("1".equals(book.getKeyChildren()[VERSEKEY_VERSE]))?"I":"Y"%>"> <%= book.getKeyChildren()[VERSEKEY_CHAPTER]%></span>
+<span class="chapter_number" part="<%=("1".equals(nowVerse))?"I":"Y"%>"> <%= nowChapter %></span>
 <%
 %>
-<span class="verse_number"> <%= book.getKeyChildren()[VERSEKEY_VERSE]%></span>
+<span class="verse_number"> <%= nowVerse %></span>
 <%
 								}
 								if ("strip".equals(format)) {
+									mgr.setGlobalOption("Greek Accents", "Off");
+									String raw = book.getStripText();
+									raw = raw.replaceAll("\\*", " ");
+									raw = raw.replaceAll("  ", " ");
+									raw = raw.replaceAll("  ", " ");
+									raw = raw.replaceAll("  ", " ");
+									// apparatus tags.  TODO: we need to add this to a filter proper rather than do this here
+									raw = raw.replaceAll("[⸆¹⸆²⸆⸇᾿˸¹˸²˸³˸·¹²⟦–ʹ°¹°²⸋¹⸋²⸋⸌¹⸌°*\\[\\];⸀¹⸀²⸀³⸁⸀◆⟧⸂¹⸂²⸄⸂⸅⸃⸉¹⸈⸉⸊]", "");
 %>
-<%= book.getStripText() %>
+<%= raw %>
 <%
 								}
 								else if ("plain".equals(format)) {
@@ -466,20 +550,25 @@
 <%
 								}
 								else {
-								// --------------------------------------------
+									// --------------------------------------------
 
 									String suggest = "";
+									StringBuffer verseText = new StringBuffer();
 									if (book.getKeyChildren().length > VERSEKEY_BOOKABBREV) {
 										suggest = book.getKeyChildren()[VERSEKEY_VERSE];
 										if (!lastChapter.equals(book.getKeyChildren()[VERSEKEY_CHAPTER]) || !lastBook.equals(book.getKeyChildren()[VERSEKEY_BOOKABBREV])) suggest = book.getKeyChildren()[VERSEKEY_CHAPTER] + ":" + suggest;
 										if (!lastBook.equals(book.getKeyChildren()[VERSEKEY_BOOKABBREV])) suggest = book.getKeyChildren()[VERSEKEY_BOOKABBREV] + " " + suggest;
-%>
-<span class="<%= "0".equals(book.getKeyChildren()[VERSEKEY_CHAPTER]) ? "book_intro" : "0".equals(book.getKeyChildren()[VERSEKEY_VERSE]) ? "chapter_intro" : "verse_number" %>" data-book="<%= book.getKeyChildren()[VERSEKEY_BOOKABBREV]%>" data-chapter="<%= book.getKeyChildren()[VERSEKEY_CHAPTER]%>" data-verse="<%=book.getKeyChildren()[VERSEKEY_VERSE]%>" data-verseKey="<%=book.getKeyChildren()[VERSEKEY_OSISREF]%>" data-suggested="<%= suggest %>"></span><%									}
-									else { %>
-<span class="verse_number" data-verseKey="<%= book.getKeyText()%>" data-suggested="<%= book.getKeyText() %>"></span>
-<%									} %>
-<%= book.getRenderText() %>
-<%
+										verseText.append("<span class=\""+ ("0".equals(book.getKeyChildren()[VERSEKEY_CHAPTER]) ? "book_intro" : "0".equals(book.getKeyChildren()[VERSEKEY_VERSE]) ? "chapter_intro" : "verse_number") + "\" data-book=\"" + book.getKeyChildren()[VERSEKEY_BOOKABBREV] + "\" data-chapter=\""+ book.getKeyChildren()[VERSEKEY_CHAPTER] + "\" data-verse=\"" + book.getKeyChildren()[VERSEKEY_VERSE] + "\" data-verseKey=\"" + book.getKeyChildren()[VERSEKEY_OSISREF] + "\" data-suggested=\"" + suggest + "\"></span>");
+									}
+									else {
+										verseText.append("<span class=\"verse_number\" data-verseKey=\"" + book.getKeyText() + "\" data-suggested=\"" + book.getKeyText() + "\"></span>");
+									} 
+									verseText.append(book.getRenderText());
+									if ("json".equals(format)) {
+										if (k > 0) out.print(", ");
+										out.print("{ \"verse\": \"" + book.getKeyText() + "\", \"text\": \"" + jsonEscape(verseText.toString()) + "\" }");
+									}
+									else out.print(verseText.toString());
 								}
 							}
 						}
@@ -498,6 +587,9 @@
 </TEI>
 <%
 					}
+					else if ("json".equals(format)) {
+						out.print(" ] }");
+					}
 				}
 			}
 		}
@@ -523,3 +615,16 @@
 <%
 	}
 %>
+<%!
+private static String jsonEscape(String raw) {
+    String escaped = raw;
+    escaped = escaped.replace("\\", "\\\\");
+    escaped = escaped.replace("\"", "\\\"");
+    escaped = escaped.replace("\b", "\\b");
+    escaped = escaped.replace("\f", "\\f");
+    escaped = escaped.replace("\n", "\\n");
+    escaped = escaped.replace("\r", "\\r");
+    escaped = escaped.replace("\t", "\\t");
+    return escaped;
+}
+%>



More information about the sword-cvs mailing list