[sword-cvs] swordweb bookdisplay.jsp,NONE,1.1 fulllibrary.jsp,NONE,1.1
sword@www.crosswire.org
sword@www.crosswire.org
Tue, 19 Aug 2003 16:15:05 -0700
Update of /usr/local/cvsroot/swordweb
In directory www:/tmp/cvs-serv18281
Added Files:
bookdisplay.jsp fulllibrary.jsp
Log Message:
Added full library and book display
--- NEW FILE: bookdisplay.jsp ---
<%@ include file="defines/tiles.jsp" %>
<%@ page import="java.util.Enumeration,java.util.Vector" %>
<%@ page import="gnu.regexp.RE" %>
<%
Vector bookTreeOpen = (Vector)session.getAttribute("bookTreeOpen");
String gbsBook = (String)request.getParameter("mod");
if (gbsBook != null)
session.setAttribute("gbsBook", gbsBook);
gbsBook = (String)session.getAttribute("gbsBook");
SWModule module = mgr.getModuleByName(gbsBook);
String gbsEntry = (String)request.getParameter("gbsEntry");
if (gbsEntry != null)
session.setAttribute("gbsEntry", gbsEntry);
gbsEntry = (String)session.getAttribute("gbsEntry");
if (gbsEntry == null)
gbsEntry = "/";
String action = (String)request.getParameter("action");
if ((action != null) && (action.equalsIgnoreCase("closeAll"))) {
bookTreeOpen = null;
}
if (bookTreeOpen == null) {
bookTreeOpen = new Vector();
session.setAttribute("bookTreeOpen", bookTreeOpen);
}
for (int i = 0; i < 2; i++) {
String []nodes = request.getParameterValues((i>0)?"close":"open");
if (nodes != null) {
for (int j = 0; j < nodes.length; j++) {
String node = nodes[j];
if (node != null) {
if (i>0)
bookTreeOpen.remove(node);
else {
if (!bookTreeOpen.contains(node)) {
bookTreeOpen.add(node);
}
}
}
}
}
}
%>
<tiles:insert beanName="basic" flush="true" >
<%-- override lookup URL, so this script is used to display the keys --%>
<tiles:put name="lookup_url" value="bookdisplay.jsp" />
<tiles:put name="title" value="General Book Display" />
<tiles:put name="sidebar_left" type="string">
<%
if (module != null) {
printTree(bookTreeOpen, out, module, "/", gbsEntry);
}
else {
out.print("no book selected");
}
%>
</tiles:put>
<tiles:put name="content" type="string">
<%
if (module != null) {
module.setKeyText(gbsEntry);
%>
<div class="verse">
<span class="versenum"><%= gbsEntry %></span>
<%= new String(module.getRenderText().getBytes("iso8859-1"), "UTF-8") %>
</div>
<%
}
%>
</tiles:put>
</tiles:insert>
<%!
private synchronized static void printTree(Vector bookTreeOpen, JspWriter out, SWModule module, String rootTreeKey, String target) {
try {
int offset = rootTreeKey.lastIndexOf("/");
module.setKeyText(rootTreeKey);
String[] children = module.getKeyChildren();
boolean open = bookTreeOpen.contains(rootTreeKey);
if (offset > 0) {
String localName = rootTreeKey.substring(offset+1);
out.print("<li>");
if (target.equals(rootTreeKey))
out.print("<b>");
if (children.length > 0) {
out.print("<a href=\"bookdisplay.jsp?" + ((open)?"close":"open") + "=" + URLEncoder.encode(rootTreeKey) + "\">" + ((open)?"[-]":"[+]") + "</a>");
}
if (target.equals(rootTreeKey))
out.print("</b>");
out.print(" <a href=\"bookdisplay.jsp?gbsEntry=" + URLEncoder.encode(rootTreeKey) + "\">" + localName + "</a></li>");
}
if ((open) || (offset < 1)) {
if (children.length > 0)
out.print("<ul>");
for (int i = 0; i < children.length; i++) {
printTree(bookTreeOpen, out, module, rootTreeKey+"/"+children[i], target);
}
if (children.length > 0)
out.print("</ul>");
}
}
catch (Exception e) {e.printStackTrace();}
}
%>
--- NEW FILE: fulllibrary.jsp ---
<%@ include file="defines/tiles.jsp" %>
<%@ page import="java.util.Enumeration,java.util.Vector" %>
<%@ page import="gnu.regexp.RE" %>
<%
Vector catTreeOpen = (Vector)session.getAttribute("catTreeOpen");
String action = (String)request.getParameter("action");
String show = (String)request.getParameter("show");
if (show != null)
session.setAttribute("catShow", show);
show = (String)session.getAttribute("catShow");
if ((action != null) && (action.equalsIgnoreCase("closeAll"))) {
catTreeOpen = null;
}
if (catTreeOpen == null) {
catTreeOpen = new Vector();
session.setAttribute("catTreeOpen", catTreeOpen);
}
for (int i = 0; i < 2; i++) {
String []nodes = request.getParameterValues((i>0)?"close":"open");
if (nodes != null) {
for (int j = 0; j < nodes.length; j++) {
String node = nodes[j];
if (node != null) {
if (i>0)
catTreeOpen.remove(node);
else {
if (!catTreeOpen.contains(node)) {
catTreeOpen.add(node);
}
}
}
}
}
}
%>
<tiles:insert beanName="basic" flush="true" >
<%-- override lookup URL, so this script is used to display the keys --%>
<tiles:put name="lookup_url" value="fulllibrary.jsp" />
<tiles:put name="title" value="Full Library Catalog" />
<tiles:put name="sidebar_left" type="string">
<ul>
<%
Vector leaves = new Vector();
for (int i = 0; i < modInfo.length; i++) {
if (!leaves.contains(modInfo[i].type)) {
leaves.add(modInfo[i].type);
boolean open = catTreeOpen.contains(modInfo[i].type);
%>
<li><b><a href="fulllibrary.jsp?<%= (open)?"close":"open" %>=<%= URLEncoder.encode(modInfo[i].type) %>"><%= ((open)?"[-]":"[+]") %></a> <%= modInfo[i].type %></b></li>
<%
if (open) {
%>
<ul>
<%
for (int j = 0; j < modInfo.length; j++) {
if (modInfo[i].type.equals(modInfo[j].type)) {
SWModule module = mgr.getModuleByName(modInfo[j].name);
if (module != null) {
%>
<li><a href="fulllibrary.jsp?show=<%= URLEncoder.encode(modInfo[j].name) %>"><%= modInfo[j].name %></a> <%= module.getDescription() %></li>
<%
}
}
}
%>
</ul>
<%
}
}
}
%>
</tiles:put>
<tiles:put name="content" type="string">
<%
if (show != null) {
SWModule module = mgr.getModuleByName(show);
if (module != null) {
String about = module.getConfigEntry("About");
if (about != null) {
RE pardRegex = new RE("\\\\pard");
about = pardRegex.substituteAll(about, "");
RE parRegex = new RE("\\\\par");
about = parRegex.substituteAll(about, "<br />");
RE rtfRegex = new RE("\\\\\\w+");
about = rtfRegex.substituteAll(about, "");
}
String type = module.getConfigEntry("Category");
if ((type == null) || (type.length() > 0))
type = module.getType();
String targetURL = "";
if ((SwordOrb.BIBLES.equals(type)) || (SwordOrb.COMMENTARIES.equals(type))) {
targetURL = "passagestudy.jsp?mod="+URLEncoder.encode(module.getName());
}
else if ("Daily Devotional".equals(type)) {
targetURL = "dailydevotion.jsp?mod="+URLEncoder.encode(module.getName());
}
else if ("Generic Books".equals(type)) {
targetURL = "bookdisplay.jsp?mod="+URLEncoder.encode(module.getName());
}
%>
<h2><a href="<%= targetURL %>"><%= module.getDescription() %></a></h2>
<%= about %>
<%
}
}
%>
</tiles:put>
</tiles:insert>