518 lines
16 KiB
Java
518 lines
16 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 javax.servlet.*;
|
|
import javax.servlet.http.*;
|
|
import org.apache.log4j.*;
|
|
import com.silverwrist.venice.ValidationException;
|
|
import com.silverwrist.venice.core.*;
|
|
import com.silverwrist.venice.servlets.format.*;
|
|
|
|
public class ConfOperations extends VeniceServlet
|
|
{
|
|
/*--------------------------------------------------------------------------------
|
|
* Static data members
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
private static Category logger = Category.getInstance(ConfOperations.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 CreateConferenceDialog makeCreateConferenceDialog() throws ServletException
|
|
{
|
|
final String desired_name = "CreateConferenceDialog";
|
|
DialogCache cache = DialogCache.getDialogCache(getServletContext());
|
|
|
|
if (!(cache.isCached(desired_name)))
|
|
{ // create a template and save it off
|
|
CreateConferenceDialog template = new CreateConferenceDialog();
|
|
cache.saveTemplate(template);
|
|
|
|
} // end if
|
|
|
|
// return a new copy
|
|
return (CreateConferenceDialog)(cache.getNewDialog(desired_name));
|
|
|
|
} // 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
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
public String getServletInfo()
|
|
{
|
|
String rc = "ConfOperations servlet - General conference operations (list, create, 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 page_title = null;
|
|
Object content = null;
|
|
SIGContext sig = null;
|
|
|
|
try
|
|
{ // all conference commands require a SIG parameter as well
|
|
sig = getSIGParameter(request,user);
|
|
changeMenuSIG(request,sig);
|
|
|
|
} // end try
|
|
catch (ValidationException ve)
|
|
{ // no SIG specified
|
|
page_title = "Error";
|
|
content = new ErrorBox(null,ve.getMessage(),"top");
|
|
|
|
} // end catch
|
|
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)
|
|
{ // get the command we want to use
|
|
String cmd = request.getParameter("cmd");
|
|
if (cmd==null)
|
|
cmd = "???";
|
|
|
|
if (cmd.equals("C"))
|
|
{ // "C" = "Create conference"
|
|
if (sig.canCreateConference())
|
|
{ // make the create conference dialog!
|
|
CreateConferenceDialog dlg = makeCreateConferenceDialog();
|
|
dlg.setupDialog(getVeniceEngine(),sig);
|
|
content = dlg;
|
|
page_title = dlg.getTitle();
|
|
|
|
} // end if
|
|
else
|
|
{ // we can't create conferences
|
|
page_title = "Error";
|
|
content = new ErrorBox("SIG Error","You are not permitted to create conferences in this SIG.","top");
|
|
|
|
} // 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
|
|
{ // show the conference listing
|
|
content = new ConferenceListing(sig);
|
|
page_title = "Conference Listing: " + sig.getName();
|
|
|
|
} // end try
|
|
catch (DataException de)
|
|
{ // something wrong in the database
|
|
page_title = "Database Error";
|
|
content = new ErrorBox(page_title,"Database error finding conferences: " + de.getMessage(),
|
|
"sigprofile?sig=" + String.valueOf(sig.getSIGID()));
|
|
|
|
} // end catch
|
|
catch (AccessError ae)
|
|
{ // some lack of access is causing problems
|
|
page_title = "Access Error";
|
|
content = new ErrorBox(page_title,ae.getMessage(),
|
|
"sigprofile?sig=" + String.valueOf(sig.getSIGID()));
|
|
|
|
} // end catch
|
|
|
|
} // end else
|
|
|
|
} // end if (SIG parameter retrieved OK)
|
|
|
|
BaseJSPData basedat = new BaseJSPData(page_title,"confops?" + request.getQueryString(),content);
|
|
basedat.transfer(getServletContext(),rdat);
|
|
|
|
} // end doGet
|
|
|
|
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;
|
|
String location;
|
|
|
|
try
|
|
{ // all conference commands require a SIG parameter as well
|
|
sig = getSIGParameter(request,user);
|
|
changeMenuSIG(request,sig);
|
|
location = "confops?sig=" + String.valueOf(sig.getSIGID());
|
|
|
|
} // end try
|
|
catch (ValidationException ve)
|
|
{ // no SIG specified
|
|
page_title = "Error";
|
|
content = new ErrorBox(null,ve.getMessage(),"top");
|
|
location = "top";
|
|
|
|
} // end catch
|
|
catch (DataException de)
|
|
{ // error looking up the SIG
|
|
page_title = "Database Error";
|
|
content = new ErrorBox(page_title,"Database error finding SIG: " + de.getMessage(),"top");
|
|
location = "top";
|
|
|
|
} // end catch
|
|
|
|
if (content==null)
|
|
{ // get the command we want to use
|
|
String cmd = request.getParameter("cmd");
|
|
if (cmd==null)
|
|
cmd = "???";
|
|
|
|
if (cmd.equals("C"))
|
|
{ // "C" = "Create Conference"
|
|
if (sig.canCreateConference())
|
|
{ // load up the create conference dialog!
|
|
CreateConferenceDialog dlg = makeCreateConferenceDialog();
|
|
dlg.setupDialog(getVeniceEngine(),sig);
|
|
|
|
if (dlg.isButtonClicked(request,"cancel"))
|
|
{ // they chickened out - go back to the conference list
|
|
rdat.redirectTo(location);
|
|
return;
|
|
|
|
} // end if
|
|
|
|
if (dlg.isButtonClicked(request,"create"))
|
|
{ // OK, they actually want to create the new conference...
|
|
dlg.loadValues(request); // load the form data
|
|
|
|
try
|
|
{ // attempt to create the conference!
|
|
ConferenceContext conf = dlg.doDialog(sig);
|
|
|
|
// success! go to the conference's topic list
|
|
rdat.redirectTo("confdisp?sig=" + String.valueOf(sig.getSIGID()) + "&conf="
|
|
+ String.valueOf(conf.getConfID()));
|
|
return;
|
|
|
|
} // end try
|
|
catch (ValidationException ve)
|
|
{ // validation error - throw it back to the user
|
|
dlg.resetOnError(ve.getMessage() + " Please try again.");
|
|
content = dlg;
|
|
page_title = dlg.getTitle();
|
|
|
|
} // end catch
|
|
catch (AccessError ae)
|
|
{ // some sort of access error - display an error dialog
|
|
page_title = "Access Error";
|
|
content = new ErrorBox(page_title,ae.getMessage(),location);
|
|
|
|
} // end catch
|
|
catch (DataException de)
|
|
{ // database error creating the conference
|
|
page_title = "Database Error";
|
|
content = new ErrorBox(page_title,"Database error creating conference: " + de.getMessage(),
|
|
location);
|
|
|
|
} // end catch
|
|
|
|
} // end if
|
|
else
|
|
{ // error - don't know what button was clicked
|
|
page_title = "Internal Error";
|
|
logger.error("no known button click on ConfOperations.doPost, cmd=C");
|
|
content = new ErrorBox(page_title,"Unknown command button pressed",location);
|
|
|
|
} // end else
|
|
|
|
} // end if
|
|
else
|
|
{ // we can't create conferences
|
|
page_title = "Error";
|
|
content = new ErrorBox("SIG Error","You are not permitted to create conferences in this SIG.",
|
|
location);
|
|
|
|
} // end else
|
|
|
|
} // 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
|
|
TopicMessageContext msg = topic.getMessage(0); // load the "zero post"
|
|
|
|
content = new AttachmentForm(sig,conf,msg,on_error);
|
|
page_title = "Upload Attachment";
|
|
|
|
} // 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";
|
|
logger.error("invalid command to ConfOperations.doPost: " + cmd);
|
|
content = new ErrorBox(page_title,"Invalid command to ConfOperations.doPost",location);
|
|
|
|
} // end else
|
|
|
|
} // end if (SIG parameter retrieved OK)
|
|
|
|
BaseJSPData basedat = new BaseJSPData(page_title,location,content);
|
|
basedat.transfer(getServletContext(),rdat);
|
|
|
|
} // end doPost
|
|
|
|
} // end class ConfOperations
|