Below is the "final" version of my patch to add previous/next links to the
question/answer screen. Everything I wanted to get in there is in there.
If somebody else sees something wrong, or something that could stand to be
changed, let me know and I will change it.
Jon, I am definitely interested in contributing more to the project. It
will probably take me a week or two to get familiar enough with everything
so that I can start making some more in-depth changes. I'll let you know
at that point. BTW, is there some tutorial-like documentation someplace
on the "Peer" model for database access? Or is that mostly a
javadoc/source deal at this point? Or is it something I could read about
in a decent book on design patterns?
-- Greg
Index: docs/INSTALL.txt
===================================================================
RCS file: /products/cvs/jyve/jyve/docs/INSTALL.txt,v
retrieving revision 1.20
diff -u -r1.20 INSTALL.txt
--- docs/INSTALL.txt 2000/04/10 22:34:34 1.20
+++ docs/INSTALL.txt 2000/07/07 06:42:26
@@ -157,6 +157,7 @@
# Those affect the appearance in the DisplayQuestionAnswer screen.
jyve.displayqa.showcreator=yes
jyve.displayqa.showlastmodifieddate=yes
+ jyve.displayqa.showprevnextnav=yes
Next install the database and database schema. The first schema
Index: src/java/org/apache/jyve/screens/DisplayQuestionAnswer.java
===================================================================
RCS file:
/products/cvs/jyve/jyve/src/java/org/apache/jyve/screens/DisplayQuestionAnswer.java,v
retrieving revision 1.24
diff -u -r1.24 DisplayQuestionAnswer.java
--- src/java/org/apache/jyve/screens/DisplayQuestionAnswer.java 2000/04/26 12:28:46
1.24
+++ src/java/org/apache/jyve/screens/DisplayQuestionAnswer.java 2000/07/07 06:42:38
@@ -130,6 +130,14 @@
NavigationLoader.getInstance().eval ( data, "TopBar" ) );
ec.addElement ( new P() );
+
+ if ( TurbineResources.getString("jyve.displayqa.showprevnextnav",
+"yes").equalsIgnoreCase("yes") )
+ {
+ Element prevNext = NavigationLoader.getInstance().eval ( data,
+"PrevNextQuestion" );
+ if ( prevNext != null )
+ ec.addElement ( prevNext );
+ }
+
// get a connection to the db
DBConnection db = DBBroker.getInstance().getConnection();
Connection connection = db.getConnection();
Index: src/java/org/apache/jyve/localization/JyveLocalization.java
===================================================================
RCS file:
/products/cvs/jyve/jyve/src/java/org/apache/jyve/localization/JyveLocalization.java,v
retrieving revision 1.13
diff -u -r1.13 JyveLocalization.java
--- src/java/org/apache/jyve/localization/JyveLocalization.java 2000/03/13 17:56:35
1.13
+++ src/java/org/apache/jyve/localization/JyveLocalization.java 2000/07/07 06:42:43
@@ -252,6 +252,17 @@
{"TOPBAR_FAQTITLE", "FAQ:"},
{"TOPBAR_TOPICTITLE", "Topic:"},
+ {"PREVNEXTQ_PREVQUESTION", "Previous: "},
+ {"PREVNEXTQ_PREVTOPIC", "Previous Topic: "},
+ {"PREVNEXTQ_FIRSTQUESTION", "First question in first topic"},
+ {"PREVNEXTQ_NEXTQUESTION", "Next: "},
+ {"PREVNEXTQ_NEXTTOPIC", "Next Topic: "},
+ {"PREVNEXTQ_LASTQUESTION", "Last question in last topic"},
+ {"PREVNEXTQ_CURRENTTOPIC", "Current Topic: "},
+ {"PREVNEXTQ_OPENBRACKET", "[ "},
+ {"PREVNEXTQ_CLOSEBRACKET", " ]"},
+ {"PREVNEXTQ_BRACKETSPLIT", " ] [ "},
+
// org.apache.jyve.screens
{"CONFIRMREGISTRATION_TITLE", "Jyve - Confirm Registration"},
Index: src/java/org/apache/jyve/localization/JyveLocalization_de.java
===================================================================
RCS file:
/products/cvs/jyve/jyve/src/java/org/apache/jyve/localization/JyveLocalization_de.java,v
retrieving revision 1.13
diff -u -r1.13 JyveLocalization_de.java
--- src/java/org/apache/jyve/localization/JyveLocalization_de.java 2000/03/08
12:09:57 1.13
+++ src/java/org/apache/jyve/localization/JyveLocalization_de.java 2000/07/07
+06:42:46
@@ -250,6 +250,17 @@
{"TOPBAR_FAQTITLE", "FAQ:"},
{"TOPBAR_TOPICTITLE", "Thema:"},
+ {"PREVNEXTQ_PREVQUESTION", "Previous: "},
+ {"PREVNEXTQ_PREVTOPIC", "Previous Topic: "},
+ {"PREVNEXTQ_FIRSTQUESTION", "First question in first topic"},
+ {"PREVNEXTQ_NEXTQUESTION", "Next: "},
+ {"PREVNEXTQ_NEXTTOPIC", "Next Topic: "},
+ {"PREVNEXTQ_LASTQUESTION", "Last question in last topic"},
+ {"PREVNEXTQ_CURRENTTOPIC", "Current Topic: "},
+ {"PREVNEXTQ_OPENBRACKET", "[ "},
+ {"PREVNEXTQ_CLOSEBRACKET", " ]"},
+ {"PREVNEXTQ_BRACKETSPLIT", " ] [ "},
+
// org.apache.jyve.screens
{"CONFIRMREGISTRATION_TITLE", "Jyve - Registrierung best�tigen"},
Index: src/java/org/apache/jyve/localization/JyveLocalization_fr.java
===================================================================
RCS file:
/products/cvs/jyve/jyve/src/java/org/apache/jyve/localization/JyveLocalization_fr.java,v
retrieving revision 1.1
diff -u -r1.1 JyveLocalization_fr.java
--- src/java/org/apache/jyve/localization/JyveLocalization_fr.java 2000/03/15
14:15:29 1.1
+++ src/java/org/apache/jyve/localization/JyveLocalization_fr.java 2000/07/07
+06:42:52
@@ -256,6 +256,17 @@
{"TOPBAR_FAQTITLE", "FAQ :"},
{"TOPBAR_TOPICTITLE", "Sujet :"},
+ {"PREVNEXTQ_PREVQUESTION", "Previous: "},
+ {"PREVNEXTQ_PREVTOPIC", "Previous Topic: "},
+ {"PREVNEXTQ_FIRSTQUESTION", "First question in first topic"},
+ {"PREVNEXTQ_NEXTQUESTION", "Next: "},
+ {"PREVNEXTQ_NEXTTOPIC", "Next Topic: "},
+ {"PREVNEXTQ_LASTQUESTION", "Last question in last topic"},
+ {"PREVNEXTQ_CURRENTTOPIC", "Current Topic: "},
+ {"PREVNEXTQ_OPENBRACKET", "[ "},
+ {"PREVNEXTQ_CLOSEBRACKET", " ]"},
+ {"PREVNEXTQ_BRACKETSPLIT", " ] [ "},
+
// org.apache.jyve.screens
{"CONFIRMREGISTRATION_TITLE", "Jyve - Confirmation d'Enregistrement"},
Index: src/java/org/apache/jyve/localization/JyveLocalization_ko.java
===================================================================
RCS file:
/products/cvs/jyve/jyve/src/java/org/apache/jyve/localization/JyveLocalization_ko.java,v
retrieving revision 1.2
diff -u -r1.2 JyveLocalization_ko.java
--- src/java/org/apache/jyve/localization/JyveLocalization_ko.java 2000/06/19
16:33:27 1.2
+++ src/java/org/apache/jyve/localization/JyveLocalization_ko.java 2000/07/07
+06:42:58
@@ -253,6 +253,17 @@
{"TOPBAR_FAQTITLE", "FAQ:"},
{"TOPBAR_TOPICTITLE", "����:"},
+ {"PREVNEXTQ_PREVQUESTION", "Previous: "},
+ {"PREVNEXTQ_PREVTOPIC", "Previous Topic: "},
+ {"PREVNEXTQ_FIRSTQUESTION", "First question in first topic"},
+ {"PREVNEXTQ_NEXTQUESTION", "Next: "},
+ {"PREVNEXTQ_NEXTTOPIC", "Next Topic: "},
+ {"PREVNEXTQ_LASTQUESTION", "Last question in last topic"},
+ {"PREVNEXTQ_CURRENTTOPIC", "Current Topic: "},
+ {"PREVNEXTQ_OPENBRACKET", "[ "},
+ {"PREVNEXTQ_CLOSEBRACKET", " ]"},
+ {"PREVNEXTQ_BRACKETSPLIT", " ] [ "},
+
// org.apache.jyve.screens
{"CONFIRMREGISTRATION_TITLE", "Jetspeed - ��� Ȯ��"},
@@ -310,7 +321,7 @@
{"DISPLAYUSER_WARNING", "������ ���� ��� ������ ���� ������� ���ñ�
�ٶ��ϴ�. " +
"������ �������� ������ ó���� ��ŭ�� �ð��� ���Դ�
�����ϴ�. " +
"�ý����� ���� ���� ��� ���� ���� ������ ���õ˴ϴ�.
������ ���ϸ� ����Ʈ�� " +
- "�����ϼż� �װ��� ������ �Ͻñ�
�ٶ��ϴ�." },
+ "�����ϼż� �װ��� ������ �Ͻñ�
+�ٶ��ϴ�." },
{"DISPLAYUSER_SENDMAILMSG", "������ ����ڿ��� �̸����� �����ϴ�:"},
{"DISPLAYUSER_USERNAMEMSG", "�� ��: "},
{"DISPLAYUSER_EMAILMSG", "�̸��� �ּ�: "},
Index: src/java/org/apache/jyve/localization/JyveLocalization_zh.java
===================================================================
RCS file:
/products/cvs/jyve/jyve/src/java/org/apache/jyve/localization/JyveLocalization_zh.java,v
retrieving revision 1.2
diff -u -r1.2 JyveLocalization_zh.java
--- src/java/org/apache/jyve/localization/JyveLocalization_zh.java 2000/05/30
04:50:46 1.2
+++ src/java/org/apache/jyve/localization/JyveLocalization_zh.java 2000/07/07
+06:43:33
@@ -257,6 +257,17 @@
{"TOPBAR_FAQTITLE", "FAQ:"},
{"TOPBAR_TOPICTITLE", "����:"},
+ {"PREVNEXTQ_PREVQUESTION", "Previous: "},
+ {"PREVNEXTQ_PREVTOPIC", "Previous Topic: "},
+ {"PREVNEXTQ_FIRSTQUESTION", "First question in first topic"},
+ {"PREVNEXTQ_NEXTQUESTION", "Next: "},
+ {"PREVNEXTQ_NEXTTOPIC", "Next Topic: "},
+ {"PREVNEXTQ_LASTQUESTION", "Last question in last topic"},
+ {"PREVNEXTQ_CURRENTTOPIC", "Current Topic: "},
+ {"PREVNEXTQ_OPENBRACKET", "[ "},
+ {"PREVNEXTQ_CLOSEBRACKET", " ]"},
+ {"PREVNEXTQ_BRACKETSPLIT", " ] [ "},
+
// org.apache.jyve.screens
{"CONFIRMREGISTRATION_TITLE", "Jyve - ע��ȷ��"},
--- src/java/org/apache/jyve/navigations/PrevNextQuestion.java.orig Sun Jul 2
11:31:36 2000
+++ src/java/org/apache/jyve/navigations/PrevNextQuestion.java Thu Jul 6 23:39:36
+2000
@@ -0,0 +1,341 @@
+package org.apache.jyve.navigations;
+
+/*
+ * Copyright (c) 1997-1999 The Java Apache Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the Java Apache
+ * Project for use in the Apache JServ servlet engine project
+ * <http://java.apache.org/>."
+ *
+ * 4. The names "Apache JServ", "Apache JServ Servlet Engine", "Jyve",
+ * "Apache Jyve", "Jyve Project", "Apache Jyve Project" and
+ * "Java Apache Project" must not be used to endorse or promote products
+ * derived from this software without prior written permission.
+ *
+ * 5. Products derived from this software may not be called "Apache JServ"
+ * nor may "Apache" nor "Apache JServ" appear in their names without
+ * prior written permission of the Java Apache Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the Java Apache
+ * Project for use in the Apache JServ servlet engine project
+ * <http://java.apache.org/>."
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Java Apache Group. For more information
+ * on the Java Apache Project and the Apache JServ Servlet Engine project,
+ * please see <http://java.apache.org/>.
+ *
+ */
+
+
+// Java Core Classes
+import java.sql.*;
+
+// External Stuff
+import org.apache.turbine.modules.*;
+import org.apache.turbine.services.localization.Localization;
+import org.apache.turbine.util.*;
+import org.apache.turbine.util.db.pool.*;
+import org.apache.jyve.util.*;
+import com.workingdogs.village.*;
+import org.apache.ecs.*;
+import org.apache.ecs.html.*;
+
+/**
+ * A navigation element providing previous/next navigation within
+ * question screens.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Greg Morris</a>
+ */
+
+public class PrevNextQuestion extends Navigation
+{
+ public ConcreteElement doBuild( RunData data ) throws Exception
+ {
+ int visitorid = data.getUser().getId();
+ Integer project_id = (Integer) data.getUser().getTemp("project_id",
+ data.getParameters().getInteger("project_id", -1));
+ Integer faq_id = (Integer) data.getUser().getTemp("faq_id",
+ data.getParameters().getInteger("faq_id", -1));
+ Integer topic_id = (Integer) data.getUser().getTemp("topic_id",
+ data.getParameters().getInteger("topic_id", -1));
+ Integer question_id = (Integer) data.getUser().getTemp("question_id",
+ data.getParameters().getInteger("question_id", -1));
+
+ JSecurityCheck secCheck = new JSecurityCheck(data);
+ boolean showUnreleasedQuestion =
+ ( secCheck.permissionToRelease("question") )
+ || ( secCheck.permissionToSeeUnreleased("question") );
+ boolean showUnreleasedTopic =
+ ( secCheck.permissionToRelease("topic") )
+ || ( secCheck.permissionToSeeUnreleased("topic") );
+
+ StringBuffer sql = new StringBuffer();
+ sql.append ( "select" );
+ sql.append ( " question.question_id, question.question_value,
+question.released" );
+ sql.append ( " from question" );
+ sql.append ( " where" );
+ sql.append ( " question.topic_id=" );
+ sql.append ( topic_id );
+ sql.append ( " and question.deleted='N'" );
+
+ if (!showUnreleasedQuestion)
+ {
+ // select if the question is released or it was created by the current
+visitor
+ sql.append ( " AND (question.released='Y' OR question.visitorid=");
+ sql.append ( visitorid );
+ sql.append ( ")");
+ }
+
+ sql.append ( " order by" );
+ sql.append ( " question.display_order" );
+ // Order alphabetical, if same order number
+ sql.append ( ",question.question_value" );
+
+ // get a connection to the db
+ DBConnection db = DBBroker.getInstance().getConnection();
+ Connection connection = db.getConnection();
+
+ // execute the query
+ QueryDataSet qds = new QueryDataSet( connection, sql.toString() );
+
+ try
+ {
+ qds.fetchRecords();
+ int size = qds.size();
+ if ( size == 0 )
+ {
+ // huh? no questions for the topic this question is
+ // supposedly in?
+ return null;
+ }
+
+ int qid = question_id.intValue();
+ int thisIndex = -1;
+ for ( int i = 0; i < size; ++i )
+ {
+ if ( qid == qds.getRecord(i).getValue("question_id").asInt() )
+ {
+ thisIndex = i;
+ break;
+ }
+ }
+
+ if ( thisIndex == -1 )
+ {
+ // our question was not found in the
+ // list of questions for this topic
+ return null;
+ }
+
+ Record prevQuestion;
+ Record nextQuestion;
+ if ( (thisIndex-1) >= 0 )
+ prevQuestion = qds.getRecord(thisIndex - 1);
+ else
+ prevQuestion = null; // the current question is the first question
+
+ if ( (thisIndex+1) < size )
+ nextQuestion = qds.getRecord(thisIndex + 1);
+ else
+ nextQuestion = null; // the current question is the last question
+
+ A prevLink = null;
+ String prevText = null; // locale key for the text appearing
+ // before the "previous" link
+ A nextLink = null;
+ String nextText = null; // locale key for the "next" text
+
+ if ( prevQuestion != null )
+ {
+ prevText = "PREVNEXTQ_PREVQUESTION";
+ prevLink = new A().setHref(
+ new DynamicURI(data, "DisplayQuestionAnswer", "SetAll")
+ .addPathInfo("project_id", project_id)
+ .addPathInfo("faq_id", faq_id)
+ .addPathInfo("topic_id", topic_id)
+ .addPathInfo("question_id",
+ prevQuestion.getValue("question_id").asInt())
+ .toString()
+
+).addElement(prevQuestion.getValue("question_value").asString());
+ }
+ if ( nextQuestion != null )
+ {
+ nextText = "PREVNEXTQ_NEXTQUESTION";
+ nextLink = new A().setHref(
+ new DynamicURI(data, "DisplayQuestionAnswer", "SetAll")
+ .addPathInfo("project_id", project_id)
+ .addPathInfo("faq_id", faq_id)
+ .addPathInfo("topic_id", topic_id)
+ .addPathInfo("question_id",
+ nextQuestion.getValue("question_id").asInt())
+ .toString()
+
+).addElement(nextQuestion.getValue("question_value").asString());
+ }
+
+
+ sql = new StringBuffer();
+ sql.append ( "select" );
+ sql.append ( " topic.topic_id, topic.topic_value, topic.released" );
+ sql.append ( " from topic, faq" );
+ sql.append ( " where" );
+ sql.append ( " faq.faq_id=topic.faq_id" );
+ sql.append ( " and topic.faq_id=" );
+ sql.append ( faq_id );
+ sql.append ( " and topic.deleted='N'" );
+
+ if ( !showUnreleasedTopic )
+ {
+ sql.append ( " AND (topic.released='Y' OR topic.visitorid=" );
+ sql.append ( visitorid );
+ sql.append ( ")" );
+ }
+
+ sql.append ( " and faq.deleted='N'" );
+ sql.append ( " order by" );
+ sql.append ( " topic.display_order,topic.topic_value" );
+
+ qds = new QueryDataSet ( connection, sql.toString() );
+ qds.fetchRecords();
+
+ size = qds.size();
+ if ( size == 0 )
+ {
+ // huh? no topics for the faq this topic is
+ // supposedly in?
+ return null;
+ }
+
+ int tid = topic_id.intValue();
+ thisIndex = -1;
+ for ( int i = 0; i < size; ++i )
+ {
+ if ( tid == qds.getRecord(i).getValue("topic_id").asInt() )
+ {
+ thisIndex = i;
+ break;
+ }
+ }
+
+ if ( thisIndex == -1 )
+ {
+ // our topic was not found in the
+ // list of topics for this faq
+ return null;
+ }
+
+ Record thisTopic = qds.getRecord(thisIndex);
+ Record prevTopic;
+ Record nextTopic;
+
+ if ( (thisIndex-1) < 0 )
+ prevTopic = null; // the current topic is the first topic
+ else
+ prevTopic = qds.getRecord(thisIndex - 1);
+
+ if ( (thisIndex+1) >= size )
+ nextTopic = null; // the current topic is the last topic
+ else
+ nextTopic = qds.getRecord(thisIndex + 1);
+
+ A topicLink = new A().setHref(
+ new DynamicURI(data, "DisplayOneTopic", "SetAll")
+ .addPathInfo("project_id", project_id)
+ .addPathInfo("faq_id", faq_id)
+ .addPathInfo("topic_id", topic_id)
+ .toString()
+ ).addElement(thisTopic.getValue("topic_value").asString());
+
+ if ( prevLink == null && prevTopic != null )
+ {
+ prevText = "PREVNEXTQ_PREVTOPIC";
+ prevLink = new A().setHref(
+ new DynamicURI(data, "DisplayOneTopic", "SetAll")
+ .addPathInfo("project_id", project_id)
+ .addPathInfo("faq_id", faq_id)
+ .addPathInfo("topic_id",
+ prevTopic.getValue("topic_id").asInt())
+ .toString()
+ ).addElement(prevTopic.getValue("topic_value").asString());
+ }
+ if ( nextLink == null && nextTopic != null )
+ {
+ nextText = "PREVNEXTQ_NEXTTOPIC";
+ nextLink = new A().setHref(
+ new DynamicURI(data, "DisplayOneTopic", "SetAll")
+ .addPathInfo("project_id", project_id)
+ .addPathInfo("faq_id", faq_id)
+ .addPathInfo("topic_id",
+ nextTopic.getValue("topic_id").asInt())
+ .toString()
+ ).addElement(nextTopic.getValue("topic_value").asString());
+ }
+
+ P navText = new P();
+ navText.addElement ( Localization.getString("PREVNEXTQ_OPENBRACKET") );
+ if ( prevLink != null )
+ {
+ navText.addElement ( Localization.getString(prevText) );
+ navText.addElement ( prevLink );
+ }
+ else
+ {
+ navText.addElement (
+Localization.getString("PREVNEXTQ_FIRSTQUESTION") );
+ }
+
+ navText.addElement ( Localization.getString("PREVNEXTQ_BRACKETSPLIT") );
+
+ navText.addElement ( Localization.getString("PREVNEXTQ_CURRENTTOPIC") );
+ navText.addElement ( topicLink );
+
+ navText.addElement ( Localization.getString("PREVNEXTQ_BRACKETSPLIT") );
+
+ if ( nextLink != null )
+ {
+ navText.addElement ( Localization.getString(nextText) );
+ navText.addElement ( nextLink );
+ }
+ else
+ {
+ navText.addElement ( Localization.getString("PREVNEXTQ_LASTQUESTION")
+);
+ }
+ navText.addElement ( Localization.getString("PREVNEXTQ_CLOSEBRACKET") );
+
+ return navText;
+ }
+ finally
+ {
+ qds.close();
+ DBBroker.getInstance().releaseConnection(db);
+ }
+ }
+}
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]