* landed code for viewing topics in a conference, and for adding a topic
(first workout of HTML Checker code) * modified the dictionary implementation to use a trie system rather than a set of HashSets, and also started using a new, much smaller dictionary * general bugfixes and cleanup on other items as needed
This commit is contained in:
@@ -213,6 +213,8 @@ public class ConfDisplay extends VeniceServlet
|
||||
{ // all commands require a SIG parameter
|
||||
sig = getSIGParameter(request,user);
|
||||
changeMenuSIG(request,sig);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("found SIG #" + String.valueOf(sig.getSIGID()));
|
||||
|
||||
} // end try
|
||||
catch (DataException de)
|
||||
@@ -222,11 +224,13 @@ public class ConfDisplay extends VeniceServlet
|
||||
|
||||
} // end catch
|
||||
|
||||
if (content!=null)
|
||||
if (content==null)
|
||||
{ // we got the SIG parameter OK
|
||||
try
|
||||
{ // all commands require a conference parameter
|
||||
conf = getConferenceParameter(request,sig);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("found conf #" + String.valueOf(conf.getConfID()));
|
||||
|
||||
} // end try
|
||||
catch (DataException de)
|
||||
@@ -238,11 +242,19 @@ public class ConfDisplay extends VeniceServlet
|
||||
|
||||
} // end if
|
||||
|
||||
if (content!=null)
|
||||
if (content==null)
|
||||
{ // we got the conference parameter OK
|
||||
try
|
||||
{ // there's an optional topic parameter
|
||||
topic = getTopicParameter(request,conf);
|
||||
if (logger.isDebugEnabled())
|
||||
{ // do a little debugging output
|
||||
if (topic!=null)
|
||||
logger.debug("found topic #" + String.valueOf(topic.getTopicID()));
|
||||
else
|
||||
logger.debug("no topic specified");
|
||||
|
||||
} // end if
|
||||
|
||||
} // end try
|
||||
catch (DataException de)
|
||||
@@ -268,26 +280,30 @@ public class ConfDisplay extends VeniceServlet
|
||||
|
||||
} // end catch
|
||||
|
||||
if (content!=null)
|
||||
if (content==null)
|
||||
{ // OK, let's handle the display now
|
||||
if (topic!=null)
|
||||
{ // we're handling messages within a single topic
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("MODE: display messages in topic");
|
||||
|
||||
// TODO: handle this somehow
|
||||
|
||||
} // end if
|
||||
else
|
||||
{ // we're displaying the conference's topic list
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("MODE: display topics in conference");
|
||||
|
||||
TopicSortHolder opts = TopicSortHolder.retrieve(request.getSession(true));
|
||||
try
|
||||
{ // get any changes to view or sort options
|
||||
getViewSortDefaults(request,conf.getConfID(),opts);
|
||||
|
||||
// get the topic list in the desired order!
|
||||
List topic_list = conf.getTopicList(opts.getViewOption(conf.getConfID()),
|
||||
opts.getSortOption(conf.getConfID()));
|
||||
|
||||
// TODO: create the "next topic" list to use for "read next"
|
||||
|
||||
// TODO: create the page view
|
||||
// create the topic list
|
||||
content = new TopicListing(request,sig,conf,opts.getViewOption(conf.getConfID()),
|
||||
opts.getSortOption(conf.getConfID()));
|
||||
page_title = "Topics in " + conf.getName();
|
||||
|
||||
} // end try
|
||||
catch (ValidationException ve)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Community System.
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
@@ -65,6 +65,32 @@ public class ConfOperations extends VeniceServlet
|
||||
|
||||
} // end getSIGParameter
|
||||
|
||||
private static ConferenceContext getConferenceParameter(ServletRequest request, SIGContext sig)
|
||||
throws ValidationException, DataException, AccessError
|
||||
{
|
||||
String str = request.getParameter("conf");
|
||||
if (str==null)
|
||||
{ // no conference parameter - bail out now!
|
||||
logger.error("Conference parameter not specified!");
|
||||
throw new ValidationException("No conference specified.");
|
||||
|
||||
} // end if
|
||||
|
||||
try
|
||||
{ // turn the string into a ConfID, and thence to a ConferenceContext
|
||||
int confid = Integer.parseInt(str);
|
||||
return sig.getConferenceContext(confid);
|
||||
|
||||
} // end try
|
||||
catch (NumberFormatException nfe)
|
||||
{ // error in Integer.parseInt
|
||||
logger.error("Cannot convert conference parameter '" + str + "'!");
|
||||
throw new ValidationException("Invalid conference parameter.");
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end getConferenceParameter
|
||||
|
||||
private CreateConferenceDialog makeCreateConferenceDialog() throws ServletException
|
||||
{
|
||||
final String desired_name = "CreateConferenceDialog";
|
||||
@@ -82,6 +108,28 @@ public class ConfOperations extends VeniceServlet
|
||||
|
||||
} // end makeCreateConferenceDialog
|
||||
|
||||
private static boolean validateNewTopic(ServletRequest request) throws ValidationException
|
||||
{
|
||||
boolean is_title_null, is_zp_null;
|
||||
|
||||
String foo = request.getParameter("title");
|
||||
if (foo==null)
|
||||
throw new ValidationException("Title parameter was not specified.");
|
||||
is_title_null = (foo.length()==0);
|
||||
|
||||
foo = request.getParameter("pseud");
|
||||
if (foo==null)
|
||||
throw new ValidationException("Pseud parameter was not specified.");
|
||||
|
||||
foo = request.getParameter("pb");
|
||||
if (foo==null)
|
||||
throw new ValidationException("Body text was not specified.");
|
||||
is_zp_null = (foo.length()==0);
|
||||
|
||||
return is_title_null || is_zp_null;
|
||||
|
||||
} // end validateNewTopic
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Overrides from class HttpServlet
|
||||
*--------------------------------------------------------------------------------
|
||||
@@ -147,6 +195,42 @@ public class ConfOperations extends VeniceServlet
|
||||
} // end else
|
||||
|
||||
} // end if
|
||||
else if (cmd.equals("T"))
|
||||
{ // "T" = "Create topic" (requires conference parameter)
|
||||
try
|
||||
{ // start by getting the conference parameter
|
||||
ConferenceContext conf = getConferenceParameter(request,sig);
|
||||
|
||||
// create the New Topic form
|
||||
NewTopicForm ntf = new NewTopicForm(sig,conf);
|
||||
ntf.setupNewRequest();
|
||||
content = ntf;
|
||||
page_title = "Create New Topic";
|
||||
|
||||
} // end try
|
||||
catch (ValidationException ve)
|
||||
{ // we can't get the conference parameter
|
||||
page_title = "Error";
|
||||
content = new ErrorBox(null,ve.getMessage(),
|
||||
"sigprofile?sig=" + String.valueOf(sig.getSIGID()));
|
||||
|
||||
} // end catch
|
||||
catch (AccessError ae)
|
||||
{ // we have some sort of access problem
|
||||
page_title = "Access Error";
|
||||
content = new ErrorBox(page_title,ae.getMessage(),
|
||||
"sigprofile?sig=" + String.valueOf(sig.getSIGID()));
|
||||
|
||||
} // end catch
|
||||
catch (DataException de)
|
||||
{ // some sort of error in the database
|
||||
page_title = "Database Error";
|
||||
content = new ErrorBox(page_title,"Database error finding conference: " + de.getMessage(),
|
||||
"sigprofile?sig=" + String.valueOf(sig.getSIGID()));
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end else
|
||||
else
|
||||
{ // any unrecognized command jumps us to "conference list"
|
||||
try
|
||||
@@ -239,9 +323,9 @@ public class ConfOperations extends VeniceServlet
|
||||
{ // attempt to create the conference!
|
||||
ConferenceContext conf = dlg.doDialog(sig);
|
||||
|
||||
// success! go back to the conference list
|
||||
// TODO: want to jump to the conference's "topic list" page if possible
|
||||
rdat.redirectTo(location);
|
||||
// success! go to the conference's topic list
|
||||
rdat.redirectTo("confdisp?sig=" + String.valueOf(sig.getSIGID()) + "&conf="
|
||||
+ String.valueOf(conf.getConfID()));
|
||||
return;
|
||||
|
||||
} // end try
|
||||
@@ -284,7 +368,136 @@ public class ConfOperations extends VeniceServlet
|
||||
|
||||
} // end else
|
||||
|
||||
} // end if
|
||||
} // end if ("C" command)
|
||||
else if (cmd.equals("T"))
|
||||
{ // "T" command = Create New Topic (requires conference parameter)
|
||||
ConferenceContext conf = null;
|
||||
|
||||
try
|
||||
{ // start by getting the conference parameter
|
||||
conf = getConferenceParameter(request,sig);
|
||||
|
||||
} // end try
|
||||
catch (ValidationException ve)
|
||||
{ // we can't get the conference parameter
|
||||
page_title = "Error";
|
||||
content = new ErrorBox(null,ve.getMessage(),location);
|
||||
|
||||
} // end catch
|
||||
catch (AccessError ae)
|
||||
{ // we have some sort of access problem
|
||||
page_title = "Access Error";
|
||||
content = new ErrorBox(page_title,ae.getMessage(),location);
|
||||
|
||||
} // end catch
|
||||
catch (DataException de)
|
||||
{ // some sort of error in the database
|
||||
page_title = "Database Error";
|
||||
content = new ErrorBox(page_title,"Database error finding conference: " + de.getMessage(),location);
|
||||
|
||||
} // end catch
|
||||
|
||||
if (content==null)
|
||||
{ // determine what to do based on the button pressed
|
||||
String on_error = "confdisp?sig=" + String.valueOf(sig.getSIGID()) + "&conf="
|
||||
+ String.valueOf(conf.getConfID());
|
||||
if (isImageButtonClicked(request,"cancel"))
|
||||
{ // the user chickened out - go back to the conference display
|
||||
rdat.redirectTo(on_error);
|
||||
return;
|
||||
|
||||
} // end if
|
||||
|
||||
if (isImageButtonClicked(request,"preview"))
|
||||
{ // generate a preview and redisplay the form
|
||||
NewTopicForm ntf = new NewTopicForm(sig,conf);
|
||||
|
||||
try
|
||||
{ // do a preview generation
|
||||
ntf.generatePreview(getVeniceEngine(),request);
|
||||
|
||||
if (ntf.isNullRequest())
|
||||
{ // no title or text specified - this is a "204 No Content" return
|
||||
rdat.nullResponse();
|
||||
return;
|
||||
|
||||
} // end if
|
||||
|
||||
content = ntf;
|
||||
page_title = "Preview New Topic";
|
||||
|
||||
} // end try
|
||||
catch (ValidationException ve)
|
||||
{ // something messed up in the preview generation
|
||||
page_title = "Error";
|
||||
content = new ErrorBox(null,ve.getMessage(),on_error);
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end if ("preview" button clicked)
|
||||
else if (isImageButtonClicked(request,"post"))
|
||||
{ // OK, let's do a post request!
|
||||
try
|
||||
{ // first validate that we've got all the parameters
|
||||
if (validateNewTopic(request))
|
||||
{ // this is a null request - send a null response
|
||||
rdat.nullResponse();
|
||||
return;
|
||||
|
||||
} // end if
|
||||
|
||||
// add the new topic!
|
||||
TopicContext topic = conf.addTopic(request.getParameter("title"),request.getParameter("pseud"),
|
||||
request.getParameter("pb"));
|
||||
|
||||
final String yes = "Y";
|
||||
if (yes.equals(request.getParameter("attach")))
|
||||
{ // we need to upload an attachment for this post
|
||||
// TODO: jump somewhere to upload an attachment
|
||||
rdat.redirectTo(on_error);
|
||||
return;
|
||||
|
||||
} // end if
|
||||
else
|
||||
{ // the post is complete, we need only jump to the topic
|
||||
// TODO: jump straight to the new topic
|
||||
rdat.redirectTo(on_error);
|
||||
return;
|
||||
|
||||
} // end else
|
||||
|
||||
} // end try
|
||||
catch (ValidationException ve)
|
||||
{ // the validation of parameters failed
|
||||
page_title = "Error";
|
||||
content = new ErrorBox(null,ve.getMessage(),on_error);
|
||||
|
||||
} // end catch
|
||||
catch (DataException de)
|
||||
{ // display a database error
|
||||
page_title = "Database Error";
|
||||
content = new ErrorBox(page_title,"Database error adding topic: " + de.getMessage(),on_error);
|
||||
|
||||
} // end catch
|
||||
catch (AccessError ae)
|
||||
{ // some sort of access problem
|
||||
page_title = "Access Error";
|
||||
content = new ErrorBox(page_title,ae.getMessage(),on_error);
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end else if
|
||||
else
|
||||
{ // we don't know what button was pressed
|
||||
page_title = "Internal Error";
|
||||
logger.error("no known button click on ConfOperations.doPost, cmd=T");
|
||||
content = new ErrorBox(page_title,"Unknown command button pressed",on_error);
|
||||
|
||||
} // end else
|
||||
|
||||
} // end if (we got the conference parameter OK)
|
||||
|
||||
} // end else if ("T" command)
|
||||
else
|
||||
{ // unrecognized command!
|
||||
page_title = "Internal Error";
|
||||
|
||||
@@ -48,6 +48,7 @@ public class Variables
|
||||
public static final String LOGIN_COOKIE = "VeniceLogin";
|
||||
|
||||
private static Category logger = Category.getInstance(Variables.class.getName());
|
||||
private static Integer engine_gate = new Integer(0);
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
@@ -56,32 +57,36 @@ public class Variables
|
||||
|
||||
public static VeniceEngine getVeniceEngine(ServletContext ctxt) throws ServletException
|
||||
{
|
||||
Object foo = ctxt.getAttribute(ENGINE_ATTRIBUTE);
|
||||
if (foo!=null)
|
||||
return (VeniceEngine)foo;
|
||||
synchronized(engine_gate)
|
||||
{ // we must synchronize efforts to access the engine
|
||||
Object foo = ctxt.getAttribute(ENGINE_ATTRIBUTE);
|
||||
if (foo!=null)
|
||||
return (VeniceEngine)foo;
|
||||
|
||||
String cfgfile = ctxt.getInitParameter(ENGINE_INIT_PARAM); // get the config file name
|
||||
logger.info("Initializing Venice engine using config file: " + cfgfile);
|
||||
String cfgfile = ctxt.getInitParameter(ENGINE_INIT_PARAM); // get the config file name
|
||||
logger.info("Initializing Venice engine using config file: " + cfgfile);
|
||||
|
||||
try
|
||||
{ // extract the configuration file name and create the engine
|
||||
VeniceEngine engine = Startup.createEngine(cfgfile);
|
||||
ctxt.setAttribute(ENGINE_ATTRIBUTE,engine);
|
||||
return engine;
|
||||
try
|
||||
{ // extract the configuration file name and create the engine
|
||||
VeniceEngine engine = Startup.createEngine(cfgfile);
|
||||
ctxt.setAttribute(ENGINE_ATTRIBUTE,engine);
|
||||
return engine;
|
||||
|
||||
} // end try
|
||||
catch (ConfigException e)
|
||||
{ // configuration failed! post an error message
|
||||
logger.fatal("Engine configuration failed: " + e.getMessage(),e);
|
||||
throw new ServletException("Venice engine configuration failed: " + e.getMessage(),e);
|
||||
} // end try
|
||||
catch (ConfigException e)
|
||||
{ // configuration failed! post an error message
|
||||
logger.fatal("Engine configuration failed: " + e.getMessage(),e);
|
||||
throw new ServletException("Venice engine configuration failed: " + e.getMessage(),e);
|
||||
|
||||
} // end catch
|
||||
catch (DataException e2)
|
||||
{ // configuration failed! post an error message
|
||||
logger.fatal("Engine data load failed: " + e2.getMessage(),e2);
|
||||
throw new ServletException("Venice engine data load failed: " + e2.getMessage(),e2);
|
||||
} // end catch
|
||||
catch (DataException e2)
|
||||
{ // configuration failed! post an error message
|
||||
logger.fatal("Engine data load failed: " + e2.getMessage(),e2);
|
||||
throw new ServletException("Venice engine data load failed: " + e2.getMessage(),e2);
|
||||
|
||||
} // end catch
|
||||
} // end catch
|
||||
|
||||
} // end synchronized block
|
||||
|
||||
} // end getVeniceEngine
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Community System.
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
|
||||
224
src/com/silverwrist/venice/servlets/format/NewTopicForm.java
Normal file
224
src/com/silverwrist/venice/servlets/format/NewTopicForm.java
Normal file
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.servlets.format;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.*;
|
||||
import com.silverwrist.venice.ValidationException;
|
||||
import com.silverwrist.venice.htmlcheck.*;
|
||||
import com.silverwrist.venice.core.*;
|
||||
|
||||
public class NewTopicForm implements JSPRender
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Attribute name for request attribute
|
||||
protected static final String ATTR_NAME = "com.silverwrist.venice.content.NewTopicForm";
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private SIGContext sig; // the SIG we're in
|
||||
private ConferenceContext conf; // the conference being created in
|
||||
private String topic_name; // the initial topic name
|
||||
private String pseud; // the pseud to display
|
||||
private boolean attach; // is there an attachment?
|
||||
private String post_box; // stuff from the post box
|
||||
private String preview = null; // the preview & spellchuck data
|
||||
private int num_errors = 0; // the number of spelling errors we get
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public NewTopicForm(SIGContext sig, ConferenceContext conf)
|
||||
{
|
||||
this.sig = sig;
|
||||
this.conf = conf;
|
||||
|
||||
} // end constrcutor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static functions
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static NewTopicForm retrieve(ServletRequest request)
|
||||
{
|
||||
return (NewTopicForm)(request.getAttribute(ATTR_NAME));
|
||||
|
||||
} // end retrieve
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface JSPRender
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void store(ServletRequest request)
|
||||
{
|
||||
request.setAttribute(ATTR_NAME,this);
|
||||
|
||||
} // end store
|
||||
|
||||
public String getTargetJSPName()
|
||||
{
|
||||
return "newtopic.jsp";
|
||||
|
||||
} // end getTargetJSPName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void setupNewRequest()
|
||||
{
|
||||
topic_name = "";
|
||||
pseud = conf.getDefaultPseud();
|
||||
attach = false;
|
||||
post_box = "";
|
||||
|
||||
} // end setupNewRequest
|
||||
|
||||
public void generatePreview(VeniceEngine engine, ServletRequest request) throws ValidationException
|
||||
{
|
||||
HTMLChecker check;
|
||||
|
||||
try
|
||||
{ // run the data through the HTML Checker
|
||||
check = engine.getEscapingChecker();
|
||||
|
||||
// sanitize the "title" parameter
|
||||
String foo = request.getParameter("title");
|
||||
if (foo==null)
|
||||
throw new ValidationException("Title parameter was not specified.");
|
||||
check.append(foo);
|
||||
check.finish();
|
||||
topic_name = check.getValue();
|
||||
check.reset();
|
||||
|
||||
// sanitize the "pseud" parameter
|
||||
foo = request.getParameter("pseud");
|
||||
if (foo==null)
|
||||
throw new ValidationException("Pseud parameter was not specified.");
|
||||
check.append(foo);
|
||||
check.finish();
|
||||
pseud = check.getValue();
|
||||
check.reset();
|
||||
|
||||
// sanitize the body text itself
|
||||
foo = request.getParameter("pb");
|
||||
if (foo==null)
|
||||
throw new ValidationException("Body text was not specified.");
|
||||
check.append(foo);
|
||||
check.finish();
|
||||
post_box = check.getValue();
|
||||
|
||||
// generate the body text preview
|
||||
check = engine.getPreviewChecker();
|
||||
check.append(foo);
|
||||
check.finish();
|
||||
preview = check.getValue();
|
||||
num_errors = check.getCounter("spelling");
|
||||
|
||||
} // end try
|
||||
catch (HTMLCheckerException e)
|
||||
{ // make sure we catch the HTML Checker exceptions
|
||||
throw new InternalStateError("spurious HTMLCheckerException in generatePreview",e);
|
||||
|
||||
} // end catch
|
||||
|
||||
// set the "attach" flag to save the checkbox state
|
||||
final String yes = "Y";
|
||||
attach = yes.equals(request.getParameter("attach"));
|
||||
|
||||
} // end generatePreview
|
||||
|
||||
public int getSIGID()
|
||||
{
|
||||
return sig.getSIGID();
|
||||
|
||||
} // end getSIGID
|
||||
|
||||
public int getConfID()
|
||||
{
|
||||
return conf.getConfID();
|
||||
|
||||
} // end getConfID
|
||||
|
||||
public String getConfName()
|
||||
{
|
||||
return conf.getName();
|
||||
|
||||
} // end getConfName
|
||||
|
||||
public String getTopicName()
|
||||
{
|
||||
return topic_name;
|
||||
|
||||
} // end getTopicName
|
||||
|
||||
public String getPseud()
|
||||
{
|
||||
return pseud;
|
||||
|
||||
} // end getPseud
|
||||
|
||||
public boolean getAttachCheck()
|
||||
{
|
||||
return attach;
|
||||
|
||||
} // end getAttachCheck
|
||||
|
||||
public String getPostBoxData()
|
||||
{
|
||||
return post_box;
|
||||
|
||||
} // end getPostBoxData
|
||||
|
||||
public boolean isPreview()
|
||||
{
|
||||
return (preview!=null);
|
||||
|
||||
} // end isPreview
|
||||
|
||||
public String getPreviewData()
|
||||
{
|
||||
return preview;
|
||||
|
||||
} // end getPreviewData
|
||||
|
||||
public int getNumSpellingErrors()
|
||||
{
|
||||
return num_errors;
|
||||
|
||||
} // end getNumSpellingErrors
|
||||
|
||||
public boolean isNullRequest()
|
||||
{
|
||||
return ((topic_name.length()==0) || (post_box.length()==0));
|
||||
|
||||
} // end isNullRequest
|
||||
|
||||
} // end class NewTopicForm
|
||||
@@ -293,4 +293,10 @@ public class RenderData
|
||||
|
||||
} // end getActivityString
|
||||
|
||||
public void nullResponse()
|
||||
{
|
||||
response.setStatus(response.SC_NO_CONTENT);
|
||||
|
||||
} // end nullResponse
|
||||
|
||||
} // end class RenderData
|
||||
|
||||
163
src/com/silverwrist/venice/servlets/format/TopicListing.java
Normal file
163
src/com/silverwrist/venice/servlets/format/TopicListing.java
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.servlets.format;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import com.silverwrist.venice.core.*;
|
||||
|
||||
public class TopicListing implements JSPRender
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Attribute name for request attribute
|
||||
protected static final String ATTR_NAME = "com.silverwrist.venice.content.TopicListing";
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private SIGContext sig; // the SIG we're in
|
||||
private ConferenceContext conf; // the conference being listed
|
||||
private int view_opt; // the view option used
|
||||
private int sort_opt; // the sort option used
|
||||
private List topic_list; // the topic list
|
||||
private TopicVisitOrder visit_order; // indicates order in which topics are visited
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public TopicListing(HttpServletRequest request, SIGContext sig, ConferenceContext conf, int view_opt,
|
||||
int sort_opt) throws DataException, AccessError
|
||||
{
|
||||
this.sig = sig;
|
||||
this.conf = conf;
|
||||
this.view_opt = view_opt;
|
||||
this.sort_opt = sort_opt;
|
||||
this.topic_list = conf.getTopicList(view_opt,sort_opt);
|
||||
this.visit_order = TopicVisitOrder.initialize(request.getSession(true),conf.getConfID(),this.topic_list);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static functions
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static TopicListing retrieve(ServletRequest request)
|
||||
{
|
||||
return (TopicListing)(request.getAttribute(ATTR_NAME));
|
||||
|
||||
} // end retrieve
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface JSPRender
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void store(ServletRequest request)
|
||||
{
|
||||
request.setAttribute(ATTR_NAME,this);
|
||||
|
||||
} // end store
|
||||
|
||||
public String getTargetJSPName()
|
||||
{
|
||||
return "topics.jsp";
|
||||
|
||||
} // end getTargetJSPName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public int getSIGID()
|
||||
{
|
||||
return sig.getSIGID();
|
||||
|
||||
} // end getSIGID
|
||||
|
||||
public int getConfID()
|
||||
{
|
||||
return conf.getConfID();
|
||||
|
||||
} // end getConfID
|
||||
|
||||
public String getConfName()
|
||||
{
|
||||
return conf.getName();
|
||||
|
||||
} // end getConfName
|
||||
|
||||
public boolean canDoReadNew()
|
||||
{
|
||||
return visit_order.isNext();
|
||||
|
||||
} // end canDoReadNew
|
||||
|
||||
public boolean canCreateTopic()
|
||||
{
|
||||
return conf.canCreateTopic();
|
||||
|
||||
} // end canCreateTopic
|
||||
|
||||
public boolean canAddToHotlist()
|
||||
{
|
||||
return false; // TODO: fix this
|
||||
|
||||
} // end canAddToHotlist
|
||||
|
||||
public boolean anyTopics()
|
||||
{
|
||||
return (topic_list.size()>0);
|
||||
|
||||
} // end anyTopics
|
||||
|
||||
public int getViewOption()
|
||||
{
|
||||
return view_opt;
|
||||
|
||||
} // end getViewOption
|
||||
|
||||
public boolean isView(int value)
|
||||
{
|
||||
return (view_opt==value);
|
||||
|
||||
} // end isSort
|
||||
|
||||
public boolean isSort(int value)
|
||||
{
|
||||
return (sort_opt==value);
|
||||
|
||||
} // end isSort
|
||||
|
||||
public Iterator getTopicIterator()
|
||||
{
|
||||
return topic_list.iterator();
|
||||
|
||||
} // end getTopicIterator
|
||||
|
||||
} // end class TopicListing
|
||||
172
src/com/silverwrist/venice/servlets/format/TopicVisitOrder.java
Normal file
172
src/com/silverwrist/venice/servlets/format/TopicVisitOrder.java
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.servlets.format;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import com.silverwrist.venice.core.*;
|
||||
|
||||
public class TopicVisitOrder
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected static final String ATTRIBUTE = "conf.display.topic.visitorder";
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private int confid;
|
||||
private short[] topics;
|
||||
private boolean[] unread;
|
||||
private int ndx_next;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected TopicVisitOrder(int confid, List topiclist)
|
||||
{
|
||||
this.confid = confid;
|
||||
this.topics = new short[topiclist.size()];
|
||||
this.unread = new boolean[topiclist.size()];
|
||||
|
||||
ndx_next = -1;
|
||||
for (int i=0; i<topiclist.size(); i++)
|
||||
{ // fill in topic numbers and unread states
|
||||
TopicContext t = (TopicContext)(topiclist.get(i));
|
||||
topics[i] = t.getTopicNumber();
|
||||
unread[i] = (t.getUnreadMessages()>0);
|
||||
if (unread[i] && (ndx_next<0))
|
||||
ndx_next = i;
|
||||
|
||||
} // end for
|
||||
|
||||
} // end constructor
|
||||
|
||||
private int moveNext()
|
||||
{
|
||||
int i = ndx_next;
|
||||
do
|
||||
{ // move forward to next "unread" topic
|
||||
if (unread[i])
|
||||
break;
|
||||
if (++i==unread.length)
|
||||
i = 0;
|
||||
|
||||
} while (i!=ndx_next); // end do
|
||||
|
||||
return i;
|
||||
|
||||
} // end moveNext
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static functions
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static TopicVisitOrder initialize(HttpSession session, int confid, List topic_list)
|
||||
{
|
||||
TopicVisitOrder tvo = new TopicVisitOrder(confid,topic_list);
|
||||
session.setAttribute(ATTRIBUTE,tvo);
|
||||
return tvo;
|
||||
|
||||
} // end initialize
|
||||
|
||||
public static TopicVisitOrder retrieve(HttpSession session, int confid)
|
||||
{
|
||||
TopicVisitOrder tvo = (TopicVisitOrder)(session.getAttribute(ATTRIBUTE));
|
||||
if (tvo!=null)
|
||||
{ // make sure the conference is OK
|
||||
if (tvo.confid!=confid)
|
||||
{ // wrong conference - remove this
|
||||
session.removeAttribute(ATTRIBUTE);
|
||||
tvo = null;
|
||||
|
||||
} // end if
|
||||
|
||||
} // end if
|
||||
|
||||
return tvo;
|
||||
|
||||
} // end retrieve
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public short getNext()
|
||||
{
|
||||
if (ndx_next<0)
|
||||
return -1;
|
||||
else if (unread[ndx_next])
|
||||
return topics[ndx_next];
|
||||
else
|
||||
return -1;
|
||||
|
||||
} // end getNext
|
||||
|
||||
public boolean isNext()
|
||||
{
|
||||
if (ndx_next>=0)
|
||||
return unread[ndx_next];
|
||||
else
|
||||
return false;
|
||||
|
||||
} // end isNext
|
||||
|
||||
public void visit(short topnum)
|
||||
{
|
||||
if (ndx_next<0)
|
||||
return;
|
||||
|
||||
if (topics[ndx_next]!=topnum)
|
||||
{ // go searching for the matching topic number
|
||||
for (int i=0; i<topics.length; i++)
|
||||
{ // simple linear search - can't be tricky because the topic numbers might be
|
||||
// in any order
|
||||
if (topnum==topics[i])
|
||||
{ // plant ourselves right there
|
||||
unread[i] = false;
|
||||
ndx_next = i;
|
||||
break;
|
||||
|
||||
} // end if
|
||||
|
||||
} // end for
|
||||
|
||||
} // end if
|
||||
else
|
||||
unread[ndx_next] = false;
|
||||
|
||||
// move the "next" pointer
|
||||
ndx_next = moveNext();
|
||||
|
||||
} // end visit
|
||||
|
||||
} // end class TopicVisitOrder
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user