* 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:
354
src/com/silverwrist/venice/servlets/format/TopicPosts.java
Normal file
354
src/com/silverwrist/venice/servlets/format/TopicPosts.java
Normal 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
|
||||
Reference in New Issue
Block a user