[sword-svn] r393 - trunk/webapp

scribe at crosswire.org scribe at crosswire.org
Fri Oct 28 13:35:48 MST 2011


Author: scribe
Date: 2011-10-28 13:35:48 -0700 (Fri, 28 Oct 2011)
New Revision: 393

Added:
   trunk/webapp/simplegadget.jsp
   trunk/webapp/simplelookup.jsp
   trunk/webapp/simplesearch.jsp
Modified:
   trunk/webapp/fetchdata.jsp
Log:
Added simple opensocial gadget for swordweb


Modified: trunk/webapp/fetchdata.jsp
===================================================================
--- trunk/webapp/fetchdata.jsp	2011-10-26 20:27:23 UTC (rev 392)
+++ trunk/webapp/fetchdata.jsp	2011-10-28 20:35:48 UTC (rev 393)
@@ -174,6 +174,8 @@
 				}
 				if ((key != null) && (book != null)) {
 					String keyList[] = SwordOrb.BIBLES.equals(book.getCategory())?book.parseKeyList(key) : new String[] { key };
+					boolean startBookTag = false;
+					boolean startChapterTag = false;
 					for (String k1 : keyList) {
 						book.setKeyText(k1);
 						if (("StrongsGreek".equals(modName)) && ("3588".equals(k1))) {
@@ -207,9 +209,50 @@
 						}
 						else {
 							if ("raw".equals(format) || "tei".equals(format)) {
+
+								// ----- header for trier tinymce editor ------
+								if ("tei".equals(format)) {
+									if ("1".equals(book.getKeyChildren()[3])) {
+										if ("1".equals(book.getKeyChildren()[2])) {
 %>
+<div type="book" n="<%= book.getKeyChildren()[1] %>" xml:id="B<%= String.format("%02d", Integer.parseInt(book.getKeyChildren()[1])) %>-base">
+<%
+											startBookTag = true;
+										}
+%>
+<div type="chapter" n="<%= book.getKeyChildren()[2] %>" xml:id="B<%= String.format("%02d", Integer.parseInt(book.getKeyChildren()[1])) %>K<%= book.getKeyChildren()[2] %>-base">
+<%
+											startChapterTag = true;
+									}
+%>
+<ab n="<%= book.getKeyChildren()[3] %>" xml:id="B<%= String.format("%02d", Integer.parseInt(book.getKeyChildren()[1])) %>K<%= book.getKeyChildren()[2] %>V<%= book.getKeyChildren()[3] %>-base">
+<%
+								}
+								// --------------------------------------------
+%>
 <%= book.getRawEntry() %>
 <%
+								// ----- header for trier tinymce editor ------
+								if ("tei".equals(format)) {
+%>
+</ab>
+<%
+									// if last verse of chapter
+									if (book.getKeyChildren()[5].equals(book.getKeyChildren()[3])) {
+%>
+</div>
+<%
+										startChapterTag = false;
+										// if last chapter of book
+										if (book.getKeyChildren()[4].equals(book.getKeyChildren()[2]) && startBookTag) {
+%>
+</div>
+<%
+											startBookTag = false;
+										}
+									}
+								}
+								// --------------------------------------------
 							}
 							else {
 

Added: trunk/webapp/simplegadget.jsp
===================================================================
--- trunk/webapp/simplegadget.jsp	                        (rev 0)
+++ trunk/webapp/simplegadget.jsp	2011-10-28 20:35:48 UTC (rev 393)
@@ -0,0 +1,204 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<%@ page import="java.net.URL" %>
+<%@ page import="org.crosswire.sword.orb.*" %>
+<%
+response.setContentType("text/xml");
+
+String requestURI = request.getRequestURI();
+int pe = requestURI.lastIndexOf('/', requestURI.length()-2);
+requestURI = (pe > 0) ? requestURI.substring(0, pe) : "";
+URL baseURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), requestURI);
+URL appBaseURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), "/study/");
+
+SWMgr mgr = SwordOrb.getSWMgrInstance(request);
+
+%>
+<Module>
+  <ModulePrefs
+	title="Bible Viewer"
+	author_email="scribe777 at gmail.com"
+	author="CrossWire"
+	description="Bible Viewer"
+	screenshot="http://crosswire.org/images/crosswire.gif"
+	thumbnail="http://crosswire.org/images/crosswire.gif"
+	scrolling="true"
+   >
+  <Optional feature="dynamic-height"/>
+  <Optional feature="pubsub-2">
+  <Param name="topics">
+    <![CDATA[ 
+    <Topic title="Manuscript Selection" name="interedition.page.selected"
+            description="Select a Manuscript" type="string" subscribe="true"/>
+	
+    ]]>
+  </Param>
+</Optional>
+</ModulePrefs>
+<UserPref name="swordModule" datatype="enum" display_name="Bible Text" default_value="WHNU">
+<%
+	ModInfo[] modInfo = mgr.getModInfoList();
+	for (int i = 0; i < modInfo.length; i++) {
+		if (SwordOrb.BIBLES.equals(modInfo[i].category)) {
+			SWModule book = mgr.getModuleByName(modInfo[i].name);
+%><EnumValue value="<%= modInfo[i].name %>" display_value="[<%= modInfo[i].name %>]"/>
+<%
+		}
+	}
+%>
+</UserPref>
+<Content type="html">
+<![CDATA[
+<head>
+<!--
+        <link rel="stylesheet" type="text/css" href="../../js/jquery-ui/jquery-ui-1.8.16.css">
+        <script type="text/javascript" src="../../js/jquery/jquery-1.6.4.min.js"></script>
+        <script type="text/javascript" src="../../js/jquery-ui/jquery-ui-1.8.16.min.js"></script>
+-->
+        <link rel="stylesheet" type="text/css" href="<%=baseURL%>/sandy.css">
+        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
+        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
+        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
+
+<script type="text/javascript">
+        $(document).ready(function() {
+
+		$( "#tabs" ).tabs();
+
+        });
+</script>
+</head>
+
+<body>
+<div id="tabs">
+	<ul>
+		<li><a href="#tabs-1">Chapter</a></li>
+		<li><a href="#tabs-2">Search</a></li>
+	</ul>
+
+	<div id="tabs-1">
+		<div>
+			Quick Lookup: <input name="verseRef" style="width:100%" id="verseRef" onKeyPress="return lookup(this.value);"/><span id="currentVerse" style="float:right;display:inline-block;"></span>
+			<div style="clear:both;"></div>
+		</div>
+		<div id="chapterContent">
+		</div>
+	</div>
+
+	<div id="tabs-2">
+		<div>
+			Search Text: <input name="searchText" style="width:100%" id="searchText" onKeyPress="return search(this.value);"/><span id="searchResultsCount" style="float:right;display:inline-block;"></span>
+			<div style="clear:both;"></div>
+		</div>
+		<div id="searchContent">
+		</div>
+	</div>
+</div>
+</body>
+
+<script>
+
+var swordModule = "WHNU";
+
+function search_callback(o) {
+	var results = o.text.split('%%%');
+	content = document.getElementById('searchResultsCount');
+	content.innerHTML = '';
+	content.innerHTML = results[0];
+	content = document.getElementById('searchContent');
+	content.innerHTML = '';
+	content.innerHTML = results[1];
+}
+
+function lookup_callback(o) {
+	var results = o.text.split('%%%');
+	content = document.getElementById('currentVerse');
+	content.innerHTML = '';
+	content.innerHTML = results[0];
+	$('#verseRef').val(results[0]);
+	content = document.getElementById('chapterContent');
+	content.innerHTML = '';
+	content.innerHTML = results[1];
+
+	var new_position = $('#cv').offset();
+	window.scrollTo(new_position.left,new_position.top);
+}
+
+function lookup(verse) {
+	$('#tabs').tabs('select', 0);
+	result = document.getElementById('chapterContent');
+	result.innerHTML = '<center><image src="<%=baseURL%>/images/loading.gif"/></center><br/><center><h1>Loading.  Please wait...</h1></center>';
+
+	var params = {};
+	var postData = {};
+	postData.mod=swordModule;
+	postData.key=verse;
+	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
+	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postData);
+	var url = "<%=baseURL%>/simplelookup.jsp";
+	gadgets.io.makeRequest(url, lookup_callback, params);
+};
+
+function search(searchText) {
+	$('#tabs').tabs('select', 1);
+	result = document.getElementById('searchContent');
+	result.innerHTML = '<center><image src="<%=baseURL%>/images/loading.gif"/></center><br/><center><h1>Loading.  Please wait...</h1></center>';
+
+	var params = {};
+	var postData = {};
+	postData.mod=swordModule;
+	postData.searchTerm=searchText;
+	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
+	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postData);
+	var url = "<%=baseURL%>/simplesearch.jsp";
+	gadgets.io.makeRequest(url, search_callback, params);
+};
+
+function getURLParams() {
+    var vars = [], hash;
+    var hashes = parent.window.location.href.slice(parent.window.location.href.indexOf('?') + 1).split('&');
+    for(var i = 0; i < hashes.length; i++) {
+        hash = hashes[i].split('=');
+        vars.push(hash[0]);
+        vars[hash[0]] = hash[1];
+    }
+    return vars;
+}
+
+
+function positionFromURLParams() {
+	var mod = getURLParams()['mod'];
+	if (mod != null) {
+		swordModule = mod;
+	}
+	var key = getURLParams()['key'];
+	if (key != null) {
+		lookup(key);
+	}
+}
+
+function page_select_callback(topic, data, subscriberData) {
+	if (data.bibcont != null) {
+		lookup(data.bibcont);
+	}
+}
+
+function loaded() {
+	var prefs = new gadgets.Prefs();
+	swordModule = prefs.getString('swordModule');
+	subId = gadgets.Hub.subscribe("interedition.page.selected", page_select_callback);
+	gadgets.window.adjustHeight(500);
+	positionFromURLParams();
+}
+
+if (gadgets.util.hasFeature('pubsub-2')) {
+	gadgets.HubSettings.onConnect = function(hum, suc, err) { loaded(); };
+}
+else gadgets.util.registerOnLoadHandler(loaded);
+
+</script>
+
+]]>
+</Content>
+</Module>
+
+

Added: trunk/webapp/simplelookup.jsp
===================================================================
--- trunk/webapp/simplelookup.jsp	                        (rev 0)
+++ trunk/webapp/simplelookup.jsp	2011-10-28 20:35:48 UTC (rev 393)
@@ -0,0 +1,165 @@
+<%@ page
+    language="java"
+    contentType="text/html;charset=utf-8"
+%>
+<%@ page import="org.crosswire.sword.orb.*" %>
+<%@ page import="java.net.URLEncoder" %>
+<%@ page import="java.net.URL" %>
+<%
+
+	String requestURI = request.getRequestURI();
+	int pe = requestURI.lastIndexOf('/', requestURI.length()-2);
+	requestURI = (pe > 0) ? requestURI.substring(0, pe) : "";
+	URL baseURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), requestURI);
+	URL appBaseURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), "/study/");
+
+	SWMgr mgr = SwordOrb.getSWMgrInstance(request);
+
+	String activeModuleName = request.getParameter("mod");
+	if (activeModuleName == null) activeModuleName = "WHNU";
+	SWModule activeModule = mgr.getModuleByName(activeModuleName);
+
+	String promoLine = activeModule.getConfigEntry("ShortPromo");
+	if (promoLine.equalsIgnoreCase("<swnull>")) {
+		promoLine = "";
+	}
+
+	String activeKey = request.getParameter("key");
+	if (activeKey == null) {
+		activeKey = "jas 1:19";
+	}
+
+	String buf = request.getParameter("strongs");
+	boolean strongs = "on".equalsIgnoreCase(buf);
+
+	buf = request.getParameter("morph");
+	boolean morph =  "on".equalsIgnoreCase(buf);
+
+	activeModule.setKeyText(activeKey);
+	activeKey = activeModule.getKeyText(); 	// be sure it is formatted nicely
+%>
+<%= activeKey %>%%%
+		<div>
+
+		<%
+			if ((activeModule.getCategory().equals("Cults / Unorthodox / Questionable Material")) || (activeModule.getCategory().equals(SwordOrb.BIBLES))) {
+				String chapterPrefix = activeKey.substring(0, activeKey.indexOf(":"));
+				int activeVerse = Integer.parseInt(activeKey.substring(activeKey.indexOf(":")+1));
+				int anchorVerse = (activeVerse > 2)?activeVerse - 2: -1;
+				boolean first = true;
+				String lang = activeModule.getConfigEntry("Lang");
+				boolean rtol = ("RtoL".equalsIgnoreCase(activeModule.getConfigEntry("Direction")));
+				
+				for (activeModule.setKeyText("="+chapterPrefix + ":0"); (activeModule.error() == (char)0); activeModule.next()) {
+					String keyText = activeModule.getKeyText();
+					String keyProps[] = activeModule.getKeyChildren();
+					// book and chapter intros
+					// TODO: change 'chapterPrefix' to use keyProps so we can support book intros (e.g. Jn.0.0)
+					boolean intro = (keyProps[2].equals("0") || keyProps[3].equals("0"));
+					if (first) {
+			%>
+				<table class="<%= lang %>">
+			<%
+						first = false;
+					}
+					int curVerse = Integer.parseInt(keyText.substring(keyText.indexOf(":")+1));
+					if (!chapterPrefix.equals(keyText.substring(0, keyText.indexOf(":")))) {
+						break;
+					}
+					mgr.setGlobalOption("Strong's Numbers",
+							((strongs) && (curVerse >= activeVerse -1) && (curVerse <= activeVerse + 1)) ? "on" : "off");
+					mgr.setGlobalOption("Morphological Tags",
+							((morph) && (curVerse >= activeVerse -1) && (curVerse <= activeVerse + 1)) ? "on" : "off");
+					
+			%>
+			<%
+					String[] heads = activeModule.getEntryAttribute("Heading", "Preverse", "", true);
+					for (int h = 0; h < heads.length; ++h) {
+			%>
+					<tr><td colspan="2"><div <%= rtol ? "dir=\"rtl\"" : "" %> class="<%= (keyText.equals(activeKey)) ? "currentverse" : "verse" %>">
+				<h3>
+					<%= heads[h] %>
+				 </h3></div></td></tr>
+			<%
+					}
+			%>
+					<tr>
+
+			<%
+					if (!rtol) {
+			%>
+					<td valign="top" align="right"><div <%= rtol ? "dir=\"rtl\"" : "" %> class="<%= (keyText.equals(activeKey)) ? "currentverse" : "verse" %>">
+			<%
+					if (!intro) {
+			%>
+					<span class="versenum">
+					<a target="_blank" <%= (curVerse == anchorVerse)?"id=\"cv\"":"" %> href="<%= baseURL %>/passagestudy.jsp?key=<%= URLEncoder.encode(keyText)+"#cv" %>">
+						<%= keyText.substring(keyText.indexOf(":")+1) %></a>
+					</span>
+			<%
+					}
+			%>
+					</div></td>
+			<%
+					}
+			%>
+
+					<td><div <%= rtol ? "dir=\"rtl\"" : "" %> class="<%= (keyText.equals(activeKey)) ? "currentverse" : (intro) ? "intro" : "verse" %>">
+
+					<%
+					
+//					<div xml:lang="<%= (lang.equals("")) ? "en" : lang 
+					%>
+					<%= activeModule.getRenderText() %>
+<%
+//					</div>
+%>
+					</div></td>
+			<%
+					if (rtol) {
+			%>
+					<td valign="top" align="right"><div <%= rtol ? "dir=\"rtl\"" : "" %> class="<%= (keyText.equals(activeKey)) ? "currentverse" : "verse" %>">
+			<%
+					if (!intro) {
+			%>
+					<span class="versenum"><a <%= (curVerse == anchorVerse)?"id=\"cv\"":"" %> href="passagestudy.jsp?key=<%= URLEncoder.encode(keyText)+"#cv" %>">
+						<%= keyText.substring(keyText.indexOf(":")+1) %></a>
+					</span>
+			<%
+					}
+			%>
+					</div></td>
+			<%
+					}
+			%>
+
+
+					</tr>
+		<%
+				}
+				if (!first) {
+			%>
+				</table>
+			<%
+				}
+			}
+			else {
+			%>
+				<div class="verse">
+				<span class="versenum"><%= activeKey %></span>
+					<%= activeModule.getRenderText() %>
+				</div>
+			<%
+			}
+			String copyLine = activeModule.getConfigEntry("ShortCopyright");
+			if (copyLine.equalsIgnoreCase("<swnull>")) {
+				copyLine = "";
+			}
+			if (activeModule.getCategory().equals("Cults / Unorthodox / Questionable Material")) {
+				copyLine = "<t:t>WARNING: This text is considered unorthodox by most of Christendom.</t:t> " + copyLine;
+			}
+		%>
+		<div class="copyLine"><%= copyLine %></div>
+		<div class="promoLine"><%= promoLine %></div>
+		</div>
+</div>

Added: trunk/webapp/simplesearch.jsp
===================================================================
--- trunk/webapp/simplesearch.jsp	                        (rev 0)
+++ trunk/webapp/simplesearch.jsp	2011-10-28 20:35:48 UTC (rev 393)
@@ -0,0 +1,139 @@
+<%@ page
+    language="java"
+    contentType="text/html;charset=utf-8"
+%>
+<%@ page import="org.crosswire.sword.orb.*" %>
+<%@ page import="java.net.URLEncoder" %>
+<%@ page import="java.util.Arrays" %>
+<%@ page import="java.util.Comparator" %>
+<%@ page import="java.net.URL" %>
+<%
+	int MAX_RESULTS = 100;
+
+	String requestURI = request.getRequestURI();
+	int pe = requestURI.lastIndexOf('/', requestURI.length()-2);
+	requestURI = (pe > 0) ? requestURI.substring(0, pe) : "";
+	URL baseURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), requestURI);
+	URL appBaseURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), "/study/");
+
+	SWMgr mgr = SwordOrb.getSWMgrInstance(request);
+
+	String colorKeys[] = request.getParameterValues("colorKey");
+	String colorMorph  = request.getParameter("colorMorph");
+	String activeModuleName = request.getParameter("mod");
+	if (activeModuleName == null) activeModuleName = "WHNU";
+	SWModule activeModule = mgr.getModuleByName(activeModuleName);
+
+	String activeSearchTerm = request.getParameter("searchTerm");
+	// assert we have a search term
+	if (activeSearchTerm == null) return;
+	activeSearchTerm = new String(activeSearchTerm.getBytes("iso8859-1"), "UTF-8");
+	mgr.setGlobalOption("Greek Accents", "Off");
+	activeSearchTerm = mgr.filterText("Greek Accents", activeSearchTerm);
+	mgr.setGlobalOption("Greek Accents", "On");
+
+	String range = "";
+	String tmp = request.getParameter("range");
+	if (tmp != null) {
+		range = tmp;
+	}
+
+	SearchType stype = (activeModule.hasSearchFramework()) ? SearchType.LUCENE : SearchType.MULTIWORD;
+	tmp = request.getParameter("stype");
+	if (tmp != null) {
+		if (tmp.equalsIgnoreCase("P")) {
+			stype = SearchType.PHRASE;
+		}
+		if (tmp.equalsIgnoreCase("R")) {
+			stype = SearchType.REGEX;
+		}
+	}
+
+	int soptions = 0;	// default to NOT ignore case
+	tmp = request.getParameter("icase");
+	if ((tmp != null) && (tmp.equals("1"))) {
+		soptions = 2;
+	}
+
+	SearchHit[] results = null;
+	if ((activeSearchTerm != null) && (activeSearchTerm.trim().length() > 0)) {
+		mgr.setGlobalOption("Greek Accents", "Off");
+		results = activeModule.search(activeSearchTerm, stype, soptions, range);
+/*
+		// let's make some intuitive decisions on when to sort by score
+		if ((results.length > 100) && (activeSearchTerm.indexOf(" ") > 0)
+				 && (activeSearchTerm.indexOf("+") < 1)
+				 && (activeSearchTerm.indexOf("\"") < 1)
+				 && (activeSearchTerm.indexOf("~") < 1)
+				) {
+*/
+			Arrays.sort(results, new Comparator() {
+				public int compare(Object o1, Object o2) {
+					return ((SearchHit)o2).score - ((SearchHit)o1).score;
+				}
+			});
+//		}
+		mgr.setGlobalOption("Greek Accents", "On");
+
+		//save the search result into the session so it can be retrived later on to browse through it
+		session.setAttribute("SearchResults", results);
+	}
+	else if ( activeSearchTerm == null ) { //no search term given, try to see if we have a valid search result saved
+		results = (SearchHit[]) session.getAttribute("SearchResults");
+	}
+
+	if ( results == null ) {
+		results = new SearchHit[0];
+	}
+%>
+<%= (results.length > MAX_RESULTS) ? "Showing " + MAX_RESULTS : results.length %>%%%
+<div>
+<%
+	if (colorKeys != null) {
+%>
+    <script type="text/javascript" language="JavaScript">
+<!--
+function onPageLoad() {
+<%
+		for (int k = 0; k < colorKeys.length; k++) {
+%>
+	colorLemmas('x','<%=colorKeys[k]%>','<%=colorMorph%>', true);
+<%
+		}
+%>
+}
+// -->
+    </script>
+<%
+	}
+%>
+</div>
+<div>
+	<div>
+		<dl class="<%= activeModule.getConfigEntry("Lang")%>">
+		<%
+			Integer resultStart = new Integer(request.getParameter("start") != null ? request.getParameter("start") : "0");
+			Integer resultLimit = new Integer(MAX_RESULTS);
+			boolean rtol = ("RtoL".equalsIgnoreCase(activeModule.getConfigEntry("Direction")));
+
+			for (int i = resultStart.intValue(); i < results.length && i < resultStart.intValue() + resultLimit.intValue(); i++)
+			{
+				activeModule.setKeyText(results[i].key);
+				String dispKey = results[i].key;
+		%>
+				<dt>
+					<a href="#" onclick="lookup('<%= dispKey %>'); return false;" title="<%= dispKey %>"><%= dispKey %></a>
+				
+				</dt>
+				
+				<dd dir="<%= rtol ? "rtl" : "" %>">
+					<%= activeModule.getRenderText() %>
+				</dd>
+
+		<%
+			}
+		%>
+
+		</dl>
+	</div>
+</div>




More information about the sword-cvs mailing list