394 lines
12 KiB
Java
394 lines
12 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 PostOperations extends VeniceServlet
|
||
|
{
|
||
|
/*--------------------------------------------------------------------------------
|
||
|
* Static data members
|
||
|
*--------------------------------------------------------------------------------
|
||
|
*/
|
||
|
|
||
|
private static final String NUKE_CONFIRM_ATTR = "servlets.PostOperations.nuke.confirm";
|
||
|
private static final String NUKE_CONFIRM_PARAM = "confirm";
|
||
|
|
||
|
private static Category logger = Category.getInstance(TopicOperations.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 TopicMessageContext getMessageParameter(ServletRequest request, TopicContext topic)
|
||
|
throws ValidationException, DataException, AccessError
|
||
|
{
|
||
|
String str = request.getParameter("msg");
|
||
|
if (StringUtil.isStringEmpty(str))
|
||
|
{ // no topic parameter - bail out now!
|
||
|
logger.error("Message parameter not specified!");
|
||
|
throw new ValidationException("No message specified.");
|
||
|
|
||
|
} // end if
|
||
|
|
||
|
try
|
||
|
{ // turn the string into a TopicID, and thence to a TopicContext
|
||
|
int message_num = Integer.parseInt(str);
|
||
|
return topic.getMessage(message_num);
|
||
|
|
||
|
} // end try
|
||
|
catch (NumberFormatException nfe)
|
||
|
{ // error in Integer.parseInt
|
||
|
logger.error("Cannot convert message parameter '" + str + "'!");
|
||
|
throw new ValidationException("Invalid message parameter.");
|
||
|
|
||
|
} // end catch
|
||
|
|
||
|
} // end getMessageParameter
|
||
|
|
||
|
/*--------------------------------------------------------------------------------
|
||
|
* Overrides from class HttpServlet
|
||
|
*--------------------------------------------------------------------------------
|
||
|
*/
|
||
|
|
||
|
public String getServletInfo()
|
||
|
{
|
||
|
String rc = "PostOperations servlet - General post operations (hide, scribble, etc.)\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 location = "top";
|
||
|
String locator = null;
|
||
|
String page_title = null;
|
||
|
Object content = null;
|
||
|
SIGContext sig = null; // SIG context
|
||
|
ConferenceContext conf = null; // conference context
|
||
|
TopicContext topic = null; // topic context
|
||
|
TopicMessageContext msg = null; // message 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()));
|
||
|
locator = "sig=" + String.valueOf(sig.getSIGID());
|
||
|
location = "sigprofile?" + locator;
|
||
|
|
||
|
} // 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(),location);
|
||
|
|
||
|
} // 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()));
|
||
|
locator += "&conf=" + String.valueOf(conf.getConfID());
|
||
|
location = "confdisp?" + locator;
|
||
|
|
||
|
} // 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(),location);
|
||
|
|
||
|
} // 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()));
|
||
|
locator += "&top=" + String.valueOf(topic.getTopicID());
|
||
|
location = "confdisp?" + locator;
|
||
|
|
||
|
} // 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(),location);
|
||
|
|
||
|
} // end catch
|
||
|
|
||
|
} // end if
|
||
|
|
||
|
if (content==null)
|
||
|
{ // we got the topic parameter OK
|
||
|
try
|
||
|
{ // now we need a message parameter
|
||
|
msg = getMessageParameter(request,topic);
|
||
|
if (logger.isDebugEnabled())
|
||
|
logger.debug("found message #" + String.valueOf(msg.getPostID()));
|
||
|
location = "confdisp?" + locator + "&p1=" + msg.getPostNumber() + "&shac=1";
|
||
|
|
||
|
} // end try
|
||
|
catch (DataException de)
|
||
|
{ // error looking up the conference
|
||
|
page_title = "Database Error";
|
||
|
content = new ErrorBox(page_title,"Database error finding message: " + de.getMessage(),location);
|
||
|
|
||
|
} // 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(),location);
|
||
|
|
||
|
} // 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(),location);
|
||
|
|
||
|
} // end catch
|
||
|
|
||
|
if (content==null)
|
||
|
{ // figure out what command we want to perform
|
||
|
String cmd = request.getParameter("cmd");
|
||
|
if (cmd==null)
|
||
|
cmd = "???";
|
||
|
|
||
|
if (cmd.equals("HY") || cmd.equals("HN"))
|
||
|
{ // we want to hide or show the message
|
||
|
try
|
||
|
{ // attempt to hide or show the message
|
||
|
msg.setHidden(cmd.equals("HY"));
|
||
|
|
||
|
// go back and display stuff
|
||
|
rdat.redirectTo(location);
|
||
|
return;
|
||
|
|
||
|
} // end try
|
||
|
catch (DataException de)
|
||
|
{ // there was a database error
|
||
|
page_title = "Database Error";
|
||
|
content = new ErrorBox(page_title,"Database error setting hidden status: " + de.getMessage(),
|
||
|
location);
|
||
|
|
||
|
} // end catch
|
||
|
catch (AccessError ae)
|
||
|
{ // naughty naughty = you can't do this!
|
||
|
page_title = "Access Error";
|
||
|
content = new ErrorBox(page_title,ae.getMessage(),location);
|
||
|
|
||
|
} // end catch
|
||
|
|
||
|
} // end if ("hide" or "show")
|
||
|
else if (cmd.equals("SCR"))
|
||
|
{ // we want to scribble the message
|
||
|
try
|
||
|
{ // attempt to scribble the message
|
||
|
msg.scribble();
|
||
|
|
||
|
// go back and display stuff
|
||
|
rdat.redirectTo(location);
|
||
|
return;
|
||
|
|
||
|
} // end try
|
||
|
catch (DataException de)
|
||
|
{ // there was a database error
|
||
|
page_title = "Database Error";
|
||
|
content = new ErrorBox(page_title,"Database error scribbling message: " + de.getMessage(),
|
||
|
location);
|
||
|
|
||
|
} // end catch
|
||
|
catch (AccessError ae)
|
||
|
{ // naughty naughty = you can't do this!
|
||
|
page_title = "Access Error";
|
||
|
content = new ErrorBox(page_title,ae.getMessage(),location);
|
||
|
|
||
|
} // end catch
|
||
|
|
||
|
} // end else if ("scribble")
|
||
|
else if (cmd.equals("NUKE"))
|
||
|
{ // nuking requires confirmation
|
||
|
try
|
||
|
{ // we need confirmation on this operation!
|
||
|
if (ConfirmBox.isConfirmed(request,NUKE_CONFIRM_ATTR,NUKE_CONFIRM_PARAM))
|
||
|
{ // OK, go ahead, nuke the message!
|
||
|
msg.nuke();
|
||
|
|
||
|
// after which, redirect to topic view
|
||
|
rdat.redirectTo("confdisp?" + locator);
|
||
|
return;
|
||
|
|
||
|
} // end if
|
||
|
else
|
||
|
{ // not a proper confirmation - better display one
|
||
|
List aliases = conf.getAliases();
|
||
|
String message = "You are about to nuke message <" + (String)(aliases.get(0)) + "."
|
||
|
+ String.valueOf(topic.getTopicNumber()) + "." + String.valueOf(msg.getPostNumber())
|
||
|
+ ">, originally composed by <" + msg.getCreatorName()
|
||
|
+ ">! Are you sure you want to do this?";
|
||
|
String confirm_url = "postops?" + locator + "&msg=" + msg.getPostNumber() + "&cmd=NUKE";
|
||
|
|
||
|
page_title = "Nuke Message";
|
||
|
content = new ConfirmBox(request,NUKE_CONFIRM_ATTR,NUKE_CONFIRM_PARAM,page_title,
|
||
|
message,confirm_url,location);
|
||
|
|
||
|
} // end else
|
||
|
|
||
|
} // end try
|
||
|
catch (DataException de)
|
||
|
{ // there was a database error
|
||
|
page_title = "Database Error";
|
||
|
content = new ErrorBox(page_title,"Database error nuking message: " + de.getMessage(),
|
||
|
location);
|
||
|
|
||
|
} // end catch
|
||
|
catch (AccessError ae)
|
||
|
{ // naughty naughty = you can't do this!
|
||
|
page_title = "Access Error";
|
||
|
content = new ErrorBox(page_title,ae.getMessage(),location);
|
||
|
|
||
|
} // end catch
|
||
|
|
||
|
} // end else if ("nuke")
|
||
|
else
|
||
|
{ // unrecognized command!
|
||
|
page_title = "Internal Error";
|
||
|
logger.error("invalid command to PostOperations.doGet: " + cmd);
|
||
|
content = new ErrorBox(page_title,"Invalid command to PostOperations.doGet",location);
|
||
|
|
||
|
} // end else
|
||
|
|
||
|
} // end if (got parameters OK)
|
||
|
|
||
|
BaseJSPData basedat = new BaseJSPData(page_title,location,content);
|
||
|
basedat.transfer(getServletContext(),rdat);
|
||
|
|
||
|
} // end doGet
|
||
|
|
||
|
} // end class PostOperations
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|