[sword-svn] r229 - trunk/examples
scribe at crosswire.org
scribe at crosswire.org
Sun Nov 27 00:23:35 MST 2005
Author: scribe
Date: 2005-11-27 00:23:29 -0700 (Sun, 27 Nov 2005)
New Revision: 229
Added:
trunk/examples/suggest.jsp
Log:
Added suggest example
Added: trunk/examples/suggest.jsp
===================================================================
--- trunk/examples/suggest.jsp 2005-11-25 23:45:22 UTC (rev 228)
+++ trunk/examples/suggest.jsp 2005-11-27 07:23:29 UTC (rev 229)
@@ -0,0 +1,134 @@
+<%@ page
+ language="java"
+ contentType="text/html;charset=utf-8"
+%>
+<%@ page import="org.crosswire.sword.orb.*" %>
+<%
+ SWMgr mgr = SwordOrb.getSWMgrInstance(session);
+ String mod = request.getParameter("mod");
+ String key = request.getParameter("key");
+ String action = request.getParameter("action");
+ if ("keyList".equals(action)) {
+ String retVal = "<ul>";
+ if (mod != null && key != null) {
+ SWModule book = mgr.getModuleByName(mod);
+ book.setKeyText(key.toUpperCase());
+ book.getRenderText();
+ String currentKey = book.getKeyText();
+ for (int i = 0; ((i < 10) && (book.error() == 0)); i++) {
+ book.previous();
+ }
+ for (int i = 0; ((i < 20) && (book.error() == 0)); i++) {
+ key = book.getKeyText();
+ retVal += (currentKey.equals(key)) ? "<li style=\"display: block; background: #C3AB7F;\">" : "<li style=\"display: block;\">";
+ retVal += "<a href=\"#\" onclick=\"suggest('"+mod+"', '"+key+"'); return false;\">"+key+"</a></li>\n";
+ book.next();
+ }
+ out.print(retVal);
+ }
+ return;
+ }
+ else if ("entryBody".equals(action)) {
+ if (mod != null && key != null) {
+ SWModule book = mgr.getModuleByName(mod);
+ if (book != null) {
+ book.setKeyText(key.toUpperCase());
+ out.print(new String(book.getRenderText().getBytes("iso8859-1"), "UTF-8"));
+ }
+ }
+ return;
+ }
+%>
+
+<html>
+ <head>
+ <script type="text/javascript">
+<!--
+
+var xmlhttp=false;
+var xmlhttp2=false;
+/*@cc_on @*/
+/*@if (@_jscript_version >= 5)
+// JScript gives us Conditional compilation, we can cope with old IE versions.
+// and security blocked creation of the objects.
+ try {
+ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
+ xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e) {
+ try {
+ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
+ xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (E) {
+ xmlhttp = false;
+ xmlhttp2 = false;
+ }
+ }
+ at end @*/
+if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
+ xmlhttp = new XMLHttpRequest();
+ xmlhttp2 = new XMLHttpRequest();
+}
+
+
+var lexindex;
+var lexentry;
+
+function suggest(mod, key) {
+
+ lexindex=document.getElementById("lexindex");
+ lexentry=document.getElementById("lexentry");
+ lexentry.innerHTML="Please wait...";
+ xmlhttp.open("GET", "suggest.jsp?mod="+mod+"&key="+encodeURIComponent(key)+"&action=keyList",true);
+ xmlhttp.onreadystatechange=function() {
+ if (xmlhttp.readyState==4) {
+ lexindex.innerHTML=xmlhttp.responseText;
+ }
+ }
+ xmlhttp.send(null);
+ xmlhttp2.open("GET", "suggest.jsp?mod="+mod+"&key="+encodeURIComponent(key)+"&action=entryBody",true);
+ xmlhttp2.onreadystatechange=function() {
+ if (xmlhttp2.readyState==4) {
+ lexentry.innerHTML=xmlhttp2.responseText;
+ }
+ }
+ xmlhttp2.send(null);
+}
+-->
+
+ </script>
+ </head>
+<body>
+
+<h1>SWORDWeb suggest Example</h1>
+
+<form name="suggestForm" action="">
+ <select name="modName">
+<%
+ ModInfo[] modInfo = mgr.getModInfoList();
+ for (int i = 0; i < modInfo.length; i++) {
+ SWModule book = mgr.getModuleByName(modInfo[i].name);
+%>
+ <option value="<%= modInfo[i].name %>"><%=modInfo[i].description + " ("+modInfo[i].name+")" %></option>
+<%
+ }
+ %>
+ </select><br />
+ <input type="text" onkeyup="suggest(document.suggestForm.modName.value, this.value); return false;" />
+</form>
+
+<table width="100%">
+<tr>
+<td valign="top" width="20%">
+<div id="lexindex">
+</div>
+</td>
+<td valign="top" width="80%">
+<div id="lexentry">
+</div>
+</td>
+</tr>
+</table>
+
+
+</body>
+</html>
More information about the sword-cvs
mailing list