Eric J. Bowersox 8bcc80ddd7 * 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
2001-02-06 04:50:04 +00:00

338 lines
10 KiB
Java

/*
* 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 ConfDisplay extends VeniceServlet
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(ConfDisplay.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))
return null; // no topic specified
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 void getViewSortDefaults(ServletRequest request, int confid, TopicSortHolder tsc)
throws ValidationException
{
String str = request.getParameter("view");
if (!(StringUtil.isStringEmpty(str)))
{ // we need to change the view parameter
try
{ // convert the parameter to an integer and then check it against defined values
int p = Integer.parseInt(str);
switch (p)
{
case ConferenceContext.DISPLAY_NEW:
case ConferenceContext.DISPLAY_ACTIVE:
case ConferenceContext.DISPLAY_ALL:
case ConferenceContext.DISPLAY_HIDDEN:
case ConferenceContext.DISPLAY_ARCHIVED:
tsc.setViewOption(confid,p);
break;
default:
throw new ValidationException("Invalid view parameter.");
} // end switch
} // end try
catch (NumberFormatException nfe)
{ // failure in parseInt
logger.error("Cannot convert view parameter '" + str + "'!");
throw new ValidationException("Invalid view parameter.");
} // end catch
} // end if
str = request.getParameter("sort");
if (!(StringUtil.isStringEmpty(str)))
{ // we need to change the sort parameter
try
{ // convert the parameter to an integer and then check it against defined values
int p = Integer.parseInt(str);
int real_p = ((p<0) ? -p : p);
switch (real_p)
{
case ConferenceContext.SORT_NUMBER:
case ConferenceContext.SORT_NAME:
case ConferenceContext.SORT_UNREAD:
case ConferenceContext.SORT_TOTAL:
case ConferenceContext.SORT_DATE:
tsc.setSortOption(confid,p);
break;
default:
throw new ValidationException("Invalid sort parameter.");
} // end switch
} // end try
catch (NumberFormatException nfe)
{ // failure in parseInt
logger.error("Cannot convert sort parameter '" + str + "'!");
throw new ValidationException("Invalid sort parameter.");
} // end catch
} // end if
} // end getViewSortDefaults
/*--------------------------------------------------------------------------------
* Overrides from class HttpServlet
*--------------------------------------------------------------------------------
*/
public String getServletInfo()
{
String rc = "ConfDisplay servlet - Display of conference topic and message lists\n"
+ "Part of the Venice Web Communities System\n";
return rc;
} // end getServletInfo
public void doGet(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
{ // 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)
{ // 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)
{ // 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);
// 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)
{ // 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 retrieving topics
page_title = "Database Error";
content = new ErrorBox(page_title,"Database error listing topics: " + 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
} // end if
BaseJSPData basedat = new BaseJSPData(page_title,"confdisp?" + request.getQueryString(),content);
basedat.transfer(getServletContext(),rdat);
} // end doGet
} // end class ConfDisplay