* landed support for reading topics and posting followup messages to a topic -

the basis of the conferencing engine is now firmly in place
* tweaks to the HTML Checker to make it better at breaking lines without
  leaving stranded punctuation at the beginning or end of a line
* also modified dictionary to better handle possessives and hyphenates
* as always, miscellaneous tweaks and bugfizes as I spot them
This commit is contained in:
Eric J. Bowersox
2001-02-07 21:12:38 +00:00
parent 8bcc80ddd7
commit 66b7fea53b
50 changed files with 3304 additions and 75 deletions

View File

@@ -29,6 +29,47 @@ import com.silverwrist.venice.servlets.format.*;
public class ConfDisplay extends VeniceServlet
{
/*--------------------------------------------------------------------------------
* Internal class used to get post number defaults
*--------------------------------------------------------------------------------
*/
static class PostInterval
{
private int first;
private int last;
public PostInterval(int f, int l)
{
if (f<=l)
{ // the sort is good
first = f;
last = l;
} // end if
else
{ // reverse the order
first = l;
last = f;
} // end else
} // end constructor
public int getFirst()
{
return first;
} // end getFirst
public int getLast()
{
return last;
} // end getLast
} // end class PostInterval
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
@@ -183,6 +224,106 @@ public class ConfDisplay extends VeniceServlet
} // end getViewSortDefaults
private static PostInterval getInterval(ServletRequest request, TopicContext topic)
throws ValidationException
{
int first, last;
String foo = request.getParameter("pxg");
if (!(StringUtil.isStringEmpty(foo)))
{ // we have a Go box parameter - try and decode it
try
{ // look for a range specifier
int p = foo.indexOf('-');
if (p<0)
{ // single post number - try and use it
first = Integer.parseInt(foo);
last = first;
} // end if
else if (p==0)
{ // "-number" - works like "0-number"
last = Integer.parseInt(foo.substring(1));
first = 0;
} // end if
else if (p==(foo.length()-1))
{ // "number-" - works like "number-end"
first = Integer.parseInt(foo.substring(0,p));
last = topic.getTotalMessages() - 1;
} // end else if
else
{ // two numbers to decode
first = Integer.parseInt(foo.substring(0,p));
last = Integer.parseInt(foo.substring(p+1));
} // end else
return new PostInterval(first,last);
} // end try
catch (NumberFormatException nfe)
{ // if numeric conversion fails, just fall out and try to redisplay the other way
} // end catch
} // end if
foo = request.getParameter("p1");
if (StringUtil.isStringEmpty(foo))
{ // no range specified - cook up a default one
last = topic.getTotalMessages();
int ur = topic.getUnreadMessages();
if ((ur==0) || (ur>=20)) // TODO: configurable
first = last - 20;
else
first = last - (ur+2);
last--;
} // end if
else
{ // we have at least one parameter...
try
{ // convert it to an integer and range-limit it
first = Integer.parseInt(foo);
if (first<0)
first = 0;
else if (first>=topic.getTotalMessages())
first = topic.getTotalMessages() - 1;
} // end try
catch (NumberFormatException nfe)
{ // we could not translate the parameter to a number
throw new ValidationException("Message parameter is invalid.");
} // end catch
foo = request.getParameter("p2");
if (StringUtil.isStringEmpty(foo))
last = first; // just specify ONE post...
else
{ // OK, we have an actual "last message" parameter...
try
{ // convert it to an integer and range-limit it
last = Integer.parseInt(foo);
if ((last<0) || (last>=topic.getTotalMessages()))
last = topic.getTotalMessages() - 1;
} // end try
catch (NumberFormatException nfe)
{ // we could not translate the parameter to a number
throw new ValidationException("Message parameter is invalid.");
} // end catch
} // end else
} // end else
return new PostInterval(first,last);
} // end getInterval
/*--------------------------------------------------------------------------------
* Overrides from class HttpServlet
*--------------------------------------------------------------------------------
@@ -287,7 +428,39 @@ public class ConfDisplay extends VeniceServlet
if (logger.isDebugEnabled())
logger.debug("MODE: display messages in topic");
// TODO: handle this somehow
try
{ // determine what the post interval is we want to display
PostInterval piv = getInterval(request,topic);
boolean read_new = !(StringUtil.isStringEmpty(request.getParameter("rnm")));
boolean show_adv = !(StringUtil.isStringEmpty(request.getParameter("shac")));
// create the post display
TopicPosts tpos = new TopicPosts(request,sig,conf,topic,piv.getFirst(),piv.getLast(),
read_new,show_adv);
content = tpos;
page_title = topic.getName() + ": " + String.valueOf(topic.getTotalMessages()) + " Total; "
+ String.valueOf(tpos.getNewMessages()) + " New; Last: "
+ rdat.formatDateForDisplay(topic.getLastUpdateDate());
} // end try
catch (ValidationException ve)
{ // there's an error in the parameters somewhere
page_title = "Error";
content = new ErrorBox(null,ve.getMessage(),"top");
} // end catch
catch (DataException de)
{ // there was a database error retrieving topics
page_title = "Database Error";
content = new ErrorBox(page_title,"Database error listing messages: " + de.getMessage(),"top");
} // end catch
catch (AccessError ae)
{ // we were unable to retrieve the topic list
page_title = "Access Error";
content = new ErrorBox(page_title,ae.getMessage(),"top");
} // end catch
} // end if
else

View File

@@ -0,0 +1,414 @@
/*
* 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;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.ValidationException;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.servlets.format.*;
public class PostMessage extends VeniceServlet
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(PostMessage.class.getName());
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private static SIGContext getSIGParameter(ServletRequest request, UserContext user)
throws ValidationException, DataException
{
String str = request.getParameter("sig");
if (str==null)
{ // no SIG parameter - bail out now!
logger.error("SIG parameter not specified!");
throw new ValidationException("No SIG specified.");
} // end if
try
{ // turn the string into a SIGID, and thence to a SIGContext
int sigid = Integer.parseInt(str);
return user.getSIGContext(sigid);
} // end try
catch (NumberFormatException nfe)
{ // error in Integer.parseInt
logger.error("Cannot convert SIG parameter '" + str + "'!");
throw new ValidationException("Invalid SIG parameter.");
} // end catch
} // 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 static TopicContext getTopicParameter(ServletRequest request, ConferenceContext conf)
throws ValidationException, DataException, AccessError
{
String str = request.getParameter("top");
if (StringUtil.isStringEmpty(str))
{ // no topic parameter - bail out now!
logger.error("Topic parameter not specified!");
throw new ValidationException("No topic specified.");
} // end if
try
{ // turn the string into a TopicID, and thence to a TopicContext
short topicid = Short.parseShort(str);
return conf.getTopic(topicid);
} // end try
catch (NumberFormatException nfe)
{ // error in Integer.parseInt
logger.error("Cannot convert topic parameter '" + str + "'!");
throw new ValidationException("Invalid topic parameter.");
} // end catch
} // end getTopicParameter
private static int getPostNumber(ServletRequest request) throws ValidationException
{
String str = request.getParameter("sd");
if (StringUtil.isStringEmpty(str))
throw new ValidationException("Invalid parameter.");
try
{ // get the number of posts we think he topic has
return Integer.parseInt(str);
} // end try
catch (NumberFormatException nfe)
{ // not a good integer...
throw new ValidationException("Invalid parameter.");
} // end catch
} // end getPostNumber
/*--------------------------------------------------------------------------------
* Overrides from class HttpServlet
*--------------------------------------------------------------------------------
*/
public String getServletInfo()
{
String rc = "PostMessage servlet - Handles posting messages to a conference\n"
+ "Part of the Venice Web Communities System\n";
return rc;
} // end getServletInfo
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
UserContext user = getUserContext(request);
RenderData rdat = createRenderData(request,response);
String page_title = null;
Object content = null;
SIGContext sig = null; // SIG context
ConferenceContext conf = null; // conference context
TopicContext topic = null; // topic context
try
{ // this outer try is to catch ValidationException
try
{ // 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)
{ // error looking up the SIG
page_title = "Database Error";
content = new ErrorBox(page_title,"Database error finding SIG: " + de.getMessage(),"top");
} // end catch
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)
{ // error looking up the conference
page_title = "Database Error";
content = new ErrorBox(page_title,"Database error finding conference: " + de.getMessage(),"top");
} // end catch
} // end if
if (content==null)
{ // we got the conference parameter OK
try
{ // now we need a topic parameter
topic = getTopicParameter(request,conf);
if (logger.isDebugEnabled())
logger.debug("found topic #" + String.valueOf(topic.getTopicID()));
} // end try
catch (DataException de)
{ // error looking up the conference
page_title = "Database Error";
content = new ErrorBox(page_title,"Database error finding topic: " + de.getMessage(),"top");
} // end catch
} // end if
} // end try
catch (ValidationException ve)
{ // these all get handled in pretty much the same way
page_title = "Error";
content = new ErrorBox(null,ve.getMessage(),"top");
} // end catch
catch (AccessError ae)
{ // these all get handled in pretty much the same way
page_title = "Access Error";
content = new ErrorBox(page_title,ae.getMessage(),"top");
} // end catch
if (content==null)
{ // make sure we've got some post data
String raw_postdata = request.getParameter("pb");
if (StringUtil.isStringEmpty(raw_postdata))
{ // don't allow zero-size posts
rdat.nullResponse();
return;
} // end if
final String yes = "Y";
// now decide what to do based on which button got clicked
if (isImageButtonClicked(request,"cancel"))
{ // canceled posting - take us back to familiar ground
rdat.redirectTo("confdisp?sig=" + String.valueOf(sig.getSIGID()) + "&conf="
+ String.valueOf(conf.getConfID()) + "&top="
+ String.valueOf(topic.getTopicNumber()));
return;
} // end if ("Cancel")
else if (isImageButtonClicked(request,"preview"))
{ // previewing the post!
try
{ // generate a preview view
content = new PostPreview(getVeniceEngine(),sig,conf,topic,request.getParameter("pseud"),
raw_postdata,request.getParameter("next"),getPostNumber(request),
yes.equals(request.getParameter("attach")));
page_title = "Previewing Post";
} // end try
catch (ValidationException ve)
{ // there was some sort of a parameter error in the display (getPostNumber can throw this)
page_title = "Error";
content = new ErrorBox(null,ve.getMessage(),"top");
} // end catch
} // end else if ("Preview & Spellcheck")
else if (isImageButtonClicked(request,"post"))
{ // post the message, and then reload the same topic
try
{ // first, check against slippage
int pn = getPostNumber(request);
if (pn==topic.getTotalMessages())
{ // no slippage - post the message!!!
TopicMessageContext msg = topic.postNewMessage(0,request.getParameter("pseud"),raw_postdata);
if (yes.equals(request.getParameter("attach")))
{ // we have an attachment to upload...
// TODO: do something to upload the attachment
rdat.redirectTo("confdisp?sig=" + String.valueOf(sig.getSIGID()) + "&conf="
+ String.valueOf(conf.getConfID()) + "&top="
+ String.valueOf(topic.getTopicNumber()) + "&rnm=1");
return;
} // end if
else
{ // no attachment - jump back to the topic
rdat.redirectTo("confdisp?sig=" + String.valueOf(sig.getSIGID()) + "&conf="
+ String.valueOf(conf.getConfID()) + "&top="
+ String.valueOf(topic.getTopicNumber()) + "&rnm=1");
return;
} // end else
} // end if
else
{ // slippage detected - show the slippage display
content = new PostSlippage(getVeniceEngine(),sig,conf,topic,pn,request.getParameter("next"),
request.getParameter("pseud"),raw_postdata,
yes.equals(request.getParameter("attach")));
page_title = "Slippage or Double-Click Detected";
} // end else
} // end try
catch (ValidationException ve)
{ // there was some sort of a parameter error in the display
page_title = "Error";
content = new ErrorBox(null,ve.getMessage(),"top");
} // end catch
catch (DataException de)
{ // there was a database error posting the message
page_title = "Database Error";
content = new ErrorBox(page_title,"Database error posting message: " + de.getMessage(),"top");
} // end catch
catch (AccessError ae)
{ // we were unable to retrieve the topic list
page_title = "Access Error";
content = new ErrorBox(page_title,ae.getMessage(),"top");
} // end catch
} // end else if ("Post & Reload")
else if (isImageButtonClicked(request,"postnext"))
{ // post the message, and then go to the "next" topic
try
{ // first, check against slippage
int pn = getPostNumber(request);
if (pn==topic.getTotalMessages())
{ // no slippage - post the message!
TopicMessageContext msg = topic.postNewMessage(0,request.getParameter("pseud"),raw_postdata);
short next;
try
{ // attempt to get the value of the "next topic" parameter
String foo = request.getParameter("next");
if (StringUtil.isStringEmpty(foo))
next = topic.getTopicNumber();
else
next = Short.parseShort(foo);
} // end try
catch (NumberFormatException nfe)
{ // just default me
next = topic.getTopicNumber();
} // end catch
if (yes.equals(request.getParameter("attach")))
{ // we have an attachment to upload...
// TODO: jump somewhere we can upload the attachment!
rdat.redirectTo("confdisp?sig=" + String.valueOf(sig.getSIGID()) + "&conf="
+ String.valueOf(conf.getConfID()) + "&top=" + String.valueOf(next) + "&rnm=1");
return;
} // end if
else
{ // no attachment - jump to the next topic
rdat.redirectTo("confdisp?sig=" + String.valueOf(sig.getSIGID()) + "&conf="
+ String.valueOf(conf.getConfID()) + "&top=" + String.valueOf(next) + "&rnm=1");
return;
} // end else
} // end if
else
{ // slippage detected - show the slippage display
content = new PostSlippage(getVeniceEngine(),sig,conf,topic,pn,request.getParameter("next"),
request.getParameter("pseud"),raw_postdata,
yes.equals(request.getParameter("attach")));
page_title = "Slippage or Double-Click Detected";
} // end else
} // end try
catch (ValidationException ve)
{ // there was some sort of a parameter error in the display
page_title = "Error";
content = new ErrorBox(null,ve.getMessage(),"top");
} // end catch
catch (DataException de)
{ // there was a database error posting the message
page_title = "Database Error";
content = new ErrorBox(page_title,"Database error posting message: " + de.getMessage(),"top");
} // end catch
catch (AccessError ae)
{ // we were unable to retrieve the topic list
page_title = "Access Error";
content = new ErrorBox(page_title,ae.getMessage(),"top");
} // end catch
} // end else if ("Post & Go Next")
else
{ // unknown button clicked
page_title = "Internal Error";
logger.error("no known button click on PostMessage.doPost");
content = new ErrorBox(page_title,"Unknown command button pressed","top");
} // end else
} // end if (got all parameters oK)
BaseJSPData basedat = new BaseJSPData(page_title,"post",content);
basedat.transfer(getServletContext(),rdat);
} // end doPost
} // end class PostMessage

View File

@@ -0,0 +1,190 @@
/*
* 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.util.StringUtil;
import com.silverwrist.venice.htmlcheck.*;
import com.silverwrist.venice.core.*;
public class PostPreview implements JSPRender
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
// Attribute name for request attribute
protected static final String ATTR_NAME = "com.silverwrist.venice.content.PostPreview";
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private SIGContext sig;
private ConferenceContext conf;
private TopicContext topic;
private String next;
private String pseud;
private String data;
private String preview;
private int num_errors;
private int msgs;
private boolean attach;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public PostPreview(VeniceEngine engine, SIGContext sig, ConferenceContext conf, TopicContext topic,
String pseud, String data, String next, int msgs, boolean attach)
{
this.sig = sig;
this.conf = conf;
this.topic = topic;
this.next = next;
this.msgs = msgs;
this.attach = attach;
try
{ // sanitize the pseud data
HTMLChecker check = engine.getEscapingChecker();
check.append(pseud);
check.finish();
this.pseud = check.getValue();
// sanitize the post box data
check.reset();
check.append(data);
check.finish();
this.data = check.getValue();
// now generate the preview
check = engine.getPreviewChecker();
check.append(data);
check.finish();
this.preview = check.getValue();
this.num_errors = check.getCounter("spelling");
} // end try
catch (HTMLCheckerException e)
{ // this is a bad issue...
throw new InternalStateError("spurious HTMLCheckerException thrown");
} // end catch
} // end constructor
/*--------------------------------------------------------------------------------
* External static functions
*--------------------------------------------------------------------------------
*/
public static PostPreview retrieve(ServletRequest request)
{
return (PostPreview)(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 "preview.jsp";
} // end getTargetJSPName
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public int getNumSpellingErrors()
{
return num_errors;
} // end getNumSpellingErrors
public String getPreviewData()
{
return preview;
} // end getPreviewData
public int getSIGID()
{
return sig.getSIGID();
} // end getSIGID
public int getConfID()
{
return conf.getConfID();
} // end getConfID
public int getTopicNumber()
{
return topic.getTopicNumber();
} // end getTopicNumber
public int getTotalMessages()
{
return msgs;
} // end getTotalMessages
public String getNextVal()
{
return next;
} // end getNextVal
public String getPseud()
{
return pseud;
} // end getPseud
public boolean attachChecked()
{
return attach;
} // end attachChecked
public String getBodyText()
{
return data;
} // end getBodyText
} // end class PostPreview

View File

@@ -0,0 +1,216 @@
/*
* 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.util.StringUtil;
import com.silverwrist.venice.htmlcheck.*;
import com.silverwrist.venice.core.*;
public class PostSlippage implements JSPRender
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
// Attribute name for request attribute
protected static final String ATTR_NAME = "com.silverwrist.venice.content.PostSlippage";
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private SIGContext sig;
private ConferenceContext conf;
private TopicContext topic;
private List messages;
private String next;
private String pseud;
private String text;
private boolean attach;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public PostSlippage(VeniceEngine engine, SIGContext sig, ConferenceContext conf, TopicContext topic,
int lastval, String next, String pseud, String text, boolean attach)
throws DataException, AccessError
{
this.sig = sig;
this.conf = conf;
this.topic = topic;
this.messages = topic.getMessages(lastval,topic.getTotalMessages()-1);
this.next = next;
this.attach = attach;
try
{ // run the text and pseud through an HTML checker to escape them
HTMLChecker ch = engine.getEscapingChecker();
ch.append(pseud);
ch.finish();
this.pseud = ch.getValue();
ch.reset();
ch.append(text);
ch.finish();
this.text = text;
} // end try
catch (HTMLCheckerException e)
{ // this shouldn't happen
throw new InternalStateError("spurious HTMLCheckerException thrown");
} // end catch
} // end constructor
/*--------------------------------------------------------------------------------
* External static functions
*--------------------------------------------------------------------------------
*/
public static PostSlippage retrieve(ServletRequest request)
{
return (PostSlippage)(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 "slippage.jsp";
} // end getTargetJSPName
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public static String getPosterName(TopicMessageContext msg)
{
try
{ // have to guard agains a DataException here
return msg.getCreatorName();
} // end try
catch (DataException de)
{ // just return "unknown" on failure
return "(unknown)";
} // end catch
} // end getPosterName
public static String getMessageBodyText(TopicMessageContext msg)
{
try
{ // have to guard against a DataException here
return msg.getBodyText();
} // end try
catch (DataException de)
{ // just return an error message
return "<EM>(Unable to retrieve message data: " + StringUtil.encodeHTML(de.getMessage()) + ")</EM>";
} // end catch
} // end getMessageBodyText
public int getSIGID()
{
return sig.getSIGID();
} // end getSIGID
public int getConfID()
{
return conf.getConfID();
} // end getConfID
public int getTopicNumber()
{
return topic.getTopicNumber();
} // end getTopicNumber
public String getTopicName()
{
return topic.getName();
} // end getTopicName
public String getIdentifyingData()
{
return "Slippage posting to topic " + String.valueOf(topic.getTopicID());
} // end getIdentifyingData
public int getTotalMessages()
{
return topic.getTotalMessages();
} // end getTotalMessages
public Iterator getMessageIterator()
{
return messages.iterator();
} // end getMessageIterator
public String getNextVal()
{
return next;
} // end getNextVal
public String getPseud()
{
return pseud;
} // end getPseud
public boolean attachChecked()
{
return attach;
} // end attachChecked
public String getBodyText()
{
return text;
} // end getBodyText
} // end class PostSlippage

View File

@@ -106,6 +106,14 @@ public class TopicListing implements JSPRender
} // end getConfID
public String getLocator()
{
StringBuffer buf = new StringBuffer("sig=");
buf.append(sig.getSIGID()).append("&conf=").append(conf.getConfID());
return buf.toString();
} // end getLocator
public String getConfName()
{
return conf.getName();
@@ -118,6 +126,15 @@ public class TopicListing implements JSPRender
} // end canDoReadNew
public String getNextLocator()
{
StringBuffer buf = new StringBuffer("sig=");
buf.append(sig.getSIGID()).append("&conf=").append(conf.getConfID()).append("&top=");
buf.append(visit_order.getNext());
return buf.toString();
} // end getNextLocator
public boolean canCreateTopic()
{
return conf.canCreateTopic();

View File

@@ -0,0 +1,354 @@
/*
* 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.util.StringUtil;
import com.silverwrist.venice.core.*;
public class TopicPosts implements JSPRender
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
// Attribute name for request attribute
protected static final String ATTR_NAME = "com.silverwrist.venice.content.TopicPosts";
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private SIGContext sig;
private ConferenceContext conf;
private TopicContext topic;
private int first;
private int last;
private boolean show_advanced;
private int unread;
private List messages;
private TopicVisitOrder visit_order;
private String cache_locator = null;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public TopicPosts(HttpServletRequest request, SIGContext sig, ConferenceContext conf, TopicContext topic,
int first, int last, boolean read_new, boolean show_advanced)
throws DataException, AccessError
{
this.sig = sig;
this.conf = conf;
this.topic = topic;
this.first = first;
this.last = last;
this.show_advanced = show_advanced;
this.unread = topic.getUnreadMessages();
if (read_new)
topic.setUnreadMessages(0);
this.messages = topic.getMessages(first,last);
this.visit_order = TopicVisitOrder.retrieve(request.getSession(true),conf.getConfID());
visit_order.visit(topic.getTopicNumber());
} // end constructor
/*--------------------------------------------------------------------------------
* External static functions
*--------------------------------------------------------------------------------
*/
public static TopicPosts retrieve(ServletRequest request)
{
return (TopicPosts)(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 "posts.jsp";
} // end getTargetJSPName
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public static String getPosterName(TopicMessageContext msg)
{
try
{ // have to guard agains a DataException here
return msg.getCreatorName();
} // end try
catch (DataException de)
{ // just return "unknown" on failure
return "(unknown)";
} // end catch
} // end getPosterName
public static String getMessageBodyText(TopicMessageContext msg)
{
try
{ // have to guard against a DataException here
return msg.getBodyText();
} // end try
catch (DataException de)
{ // just return an error message
return "<EM>(Unable to retrieve message data: " + StringUtil.encodeHTML(de.getMessage()) + ")</EM>";
} // end catch
} // end getMessageBodyText
public int getSIGID()
{
return sig.getSIGID();
} // end getSIGID
public int getConfID()
{
return conf.getConfID();
} // end getConfID
public int getTopicNumber()
{
return topic.getTopicNumber();
} // end getTopicNumber
public int getNextTopicNumber()
{
return visit_order.getNext();
} // end getNextTopicNumber
public String getConfLocator()
{
StringBuffer buf = new StringBuffer("sig=");
buf.append(sig.getSIGID()).append("&conf=").append(conf.getConfID());
return buf.toString();
} // end getConfLocator
public String getLocator()
{
if (cache_locator==null)
{ // build up the standard locator
StringBuffer buf = new StringBuffer("sig=");
buf.append(sig.getSIGID()).append("&conf=").append(conf.getConfID()).append("&top=");
buf.append(topic.getTopicNumber());
cache_locator = buf.toString();
} // end if
return cache_locator;
} // end getLocator
public String getNextLocator()
{
StringBuffer buf = new StringBuffer("sig=");
buf.append(sig.getSIGID()).append("&conf=").append(conf.getConfID()).append("&top=");
buf.append(visit_order.getNext());
return buf.toString();
} // end getNextLocator
public String getIdentifyingData()
{
StringBuffer buf = new StringBuffer("Posts ");
buf.append(first).append(" through ").append(last).append(" in topic #").append(topic.getTopicID());
return buf.toString();
} // end getIdentifyingData
public String getTopicName()
{
return topic.getName();
} // end getTopicName
public int getTotalMessages()
{
return topic.getTotalMessages();
} // end getTotalMessages
public int getNewMessages()
{
return unread;
} // end getNewMessages
public Date getLastUpdate()
{
return topic.getLastUpdateDate();
} // end getLastUpdate
public boolean isTopicHidden()
{
return topic.isHidden();
} // end isTopicHidden
public boolean canDoNextTopic()
{
return visit_order.isNext();
} // end canDoNextTopic
public boolean canFreezeTopic()
{
return topic.canFreeze();
} // end canFreezeTopic
public boolean isTopicFrozen()
{
return topic.isFrozen();
} // end isTopicFrozen
public boolean canArchiveTopic()
{
return topic.canArchive();
} // end canArchiveTopic
public boolean isTopicArchived()
{
return topic.isArchived();
} // end isTopicArchived
public boolean canDeleteTopic()
{
return false; // TODO: fix me
} // end canDeleteTopic
public boolean canScrollUp()
{
return (first>0);
} // end canScrollUp
public String getScrollUpLocator()
{
int new_first = first - 20; // TODO: configurable
int new_last = last - 1;
if (new_first<0)
{ // normalize so we start at 0
new_last += (-new_first);
new_first = 0;
} // end if
StringBuffer buf = new StringBuffer("p1=");
buf.append(new_first).append("&p2=").append(new_last);
return buf.toString();
} // end getScrollUpLocator
public boolean canScrollDown()
{
return ((topic.getTotalMessages() - (1 + last))>=20); // TODO: configurable
} // end canScrollDown
public String getScrollDownLocator()
{
StringBuffer buf = new StringBuffer("p1=");
buf.append(last+1).append("&p2=").append(last+20); // TODO: configurable
return buf.toString();
} // end getScrollDownLocator
public boolean canScrollToEnd()
{
return ((topic.getTotalMessages() - (1 + last))>0);
} // end canScrollToEnd
public String getScrollToEndLocator()
{
int my_last = topic.getTotalMessages();
StringBuffer buf = new StringBuffer("p1=");
buf.append(my_last-20).append("&p2=").append(my_last-1); // TODO: configurable
return buf.toString();
} // end getScrollToEndLocator
public Iterator getMessageIterator()
{
return messages.iterator();
} // end getMessageIterator()
public boolean emitBreakLinePoint(int msg)
{
return (msg==(topic.getTotalMessages()-unread));
} // end emitBreakLinePoint
public boolean showAdvanced()
{
return show_advanced && (last==first);
} // end showAdvanced
public boolean displayPostBox()
{
boolean flag1 = conf.canPostToConference();
boolean flag2 = (topic.isFrozen() ? topic.canFreeze() : true);
boolean flag3 = (topic.isArchived() ? topic.canArchive() : true);
return flag1 && flag2 && flag3;
} // end displayPostBox
public String getDefaultPseud()
{
return conf.getDefaultPseud();
} // end getDefaultPseud
} // end class TopicPosts