/* * 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 . * * 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 , * 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.util.StringUtil; 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 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 EditConferenceDialog makeEditConferenceDialog() throws ServletException { final String desired_name = "EditConferenceDialog"; DialogCache cache = DialogCache.getDialogCache(getServletContext()); if (!(cache.isCached(desired_name))) { // create a template and save it off EditConferenceDialog template = new EditConferenceDialog(); cache.saveTemplate(template); } // end if // return a new copy return (EditConferenceDialog)(cache.getNewDialog(desired_name)); } // end makeEditConferenceDialog private static boolean validateNewTopic(ServletRequest request, String on_error) throws ErrorBox { boolean is_title_null, is_zp_null; String foo = request.getParameter("title"); if (foo==null) throw new ErrorBox(null,"Title parameter was not specified.",on_error); is_title_null = (foo.length()==0); foo = request.getParameter("pseud"); if (foo==null) throw new ErrorBox(null,"Pseud parameter was not specified.",on_error); foo = request.getParameter("pb"); if (foo==null) throw new ErrorBox(null,"Body text was not specified.",on_error); 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 /*-------------------------------------------------------------------------------- * Overrides from class VeniceServlet *-------------------------------------------------------------------------------- */ protected VeniceContent doVeniceGet(HttpServletRequest request, VeniceEngine engine, UserContext user, RenderData rdat) throws ServletException, IOException, VeniceServletResult { // get the SIG SIGContext sig = getSIGParameter(request,user,true,"top"); changeMenuSIG(request,sig); String on_error = "confops?sig=" + sig.getSIGID(); // get the command we want to use String cmd = getStandardCommandParam(request); if (cmd.equals("C")) { // "C" = "Create conference" if (!(sig.canCreateConference())) return new ErrorBox("Access Error","You are not permitted to create conferences in this SIG.", on_error); // make the "create" dialog CreateConferenceDialog dlg = makeCreateConferenceDialog(); dlg.setupDialog(engine,sig); setMyLocation(request,on_error + "&cmd=C"); return dlg; } // end if ("C" command) if (cmd.equals("T")) { // "T" = "Create topic" (requires conference parameter) ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confdisp?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID(); // Create the new topic form. NewTopicForm ntf = new NewTopicForm(sig,conf); ntf.setupNewRequest(); setMyLocation(request,"confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=T"); return ntf; } // end if ("T" command) if (cmd.equals("Q")) { // "Q" = display Manage menu (requires conference parameter) ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confdisp?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID(); // display the "Manage Conference" display setMyLocation(request,"confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=Q"); return new ManageConference(sig,conf); } // end if ("Q" command) if (cmd.equals("FX")) { // "FX" = the dreaded fixseen :-) - catches up the entire conference ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confdisp?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID(); try { // do the fixseen operation conf.fixSeen(); } // end try catch (DataException de) { // some sort of error in the database return new ErrorBox("Database Error","Database error catching up conference: " + de.getMessage(), on_error); } // end catch return null; // null response here } // end if ("FX" command) if (cmd.equals("E")) { // "E" = "Edit Conference Settings" (requires conference parameter) ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=Q"; if (!(conf.canChangeConference())) return new ErrorBox("Access Error","You are not permitted to change this conference's settings.", on_error); // create and return the Edit Conference dialog EditConferenceDialog dlg = makeEditConferenceDialog(); try { // set up and return the dialog dlg.setupDialog(sig,conf); setMyLocation(request,"confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=E"); return dlg; } // end try catch (AccessError ae) { // some sort of access error - display an error dialog return new ErrorBox("Access Error",ae.getMessage(),on_error); } // end catch catch (DataException de) { // database error retrieving the conference information return new ErrorBox("Database Error","Database error getting conference information: " + de.getMessage(),on_error); } // end catch } // end if ("E" command) if (cmd.equals("A")) { // "A" = "Manage Aliases" (requires conference parameter) ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=Q"; if (!(conf.canChangeConference())) return new ErrorBox("Access Error","You are not permitted to change this conference's aliases.", on_error); // process alias removal link String remove = request.getParameter("rem"); if (!(StringUtil.isStringEmpty(remove))) { // do removal of an alias try { // go ahead and remove the alias! conf.removeAlias(remove); } // end try catch (AccessError ae) { // some sort of access error - display an error dialog return new ErrorBox("Access Error",ae.getMessage(),on_error); } // end catch catch (DataException de) { // database error creating the conference return new ErrorBox("Database Error","Database error removing alias: " + de.getMessage(), on_error); } // end catch } // end if (removing an alias) // display the "Manage Conference Aliases" display try { // generate the display box setMyLocation(request,"confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=A"); return new ManageConferenceAliases(sig,conf); } // end try catch (DataException de) { // error generating the display box return new ErrorBox("Database Error","Database error displaying aliases: " + de.getMessage(), on_error); } // end catch } // end if ("A" command) if (cmd.equals("RP") || cmd.equals("RR")) { // "RP" = "Report Posters," "RR" = "Report Readers" (requires conference parameter) ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=Q"; try { // generate the listing on this page setMyLocation(request,"confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=" + cmd); return new ConferenceActivity(sig,conf,cmd.equals("RP")); } // end try catch (DataException de) { // unable to get the data for the list return new ErrorBox("Database Error","Database error displaying conference users: " + de.getMessage(), on_error); } // end catch } // end if ("RP" and "RR" commands) // Any unrecognized command shows us the conference list. on_error = "sigprofile?sig=" + sig.getSIGID(); try { // make a conference listing setMyLocation(request,"confops?sig=" + sig.getSIGID()); return new ConferenceListing(sig); } // end try catch (DataException de) { // something wrong in the database return new ErrorBox("Database Error","Database error finding conferences: " + de.getMessage(),on_error); } // end catch catch (AccessError ae) { // some lack of access is causing problems return new ErrorBox("Access Error",ae.getMessage(),on_error); } // end catch } // end doVeniceGet protected VeniceContent doVenicePost(HttpServletRequest request, VeniceEngine engine, UserContext user, RenderData rdat) throws ServletException, IOException, VeniceServletResult { // get the SIG SIGContext sig = getSIGParameter(request,user,true,"top"); changeMenuSIG(request,sig); String on_error = "confops?sig=" + sig.getSIGID(); // get the command we want to use String cmd = getStandardCommandParam(request); if (cmd.equals("C")) { // "C" = "Create Conference" if (!(sig.canCreateConference())) return new ErrorBox("Access Error","You are not permitted to create conferences in this SIG.", on_error); // load up the create conference dialog! CreateConferenceDialog dlg = makeCreateConferenceDialog(); dlg.setupDialog(engine,sig); if (dlg.isButtonClicked(request,"cancel")) throw new RedirectResult(on_error); // they chickened out - go back to the conference list 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! redirect to the conference's topic list throw new RedirectResult("confdisp?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID()); } // end try catch (ValidationException ve) { // validation error - throw it back to the user dlg.resetOnError(ve.getMessage() + " Please try again."); } // end catch catch (AccessError ae) { // some sort of access error - display an error dialog return new ErrorBox("Access Error",ae.getMessage(),on_error); } // end catch catch (DataException de) { // database error creating the conference return new ErrorBox("Database Error","Database error creating conference: " + de.getMessage(), on_error); } // end catch setMyLocation(request,on_error + "&cmd=C"); return dlg; // redisplay the dialog } // end if ("create" button clicked) // error - don't know what button was clicked logger.error("no known button click on ConfOperations.doPost, cmd=C"); return new ErrorBox("Internal Error","Unknown command button pressed",on_error); } // end if ("C" command) if (cmd.equals("T")) { // "T" command = Create New Topic (requires conference parameter) ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confdisp?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID(); // determine what to do based on the button pressed if (isImageButtonClicked(request,"cancel")) throw new RedirectResult(on_error); // the user chickened out - go back to the conference display if (isImageButtonClicked(request,"preview")) { // generate a preview and redisplay the form NewTopicForm ntf = new NewTopicForm(sig,conf); try { // generate a preview display ntf.generatePreview(engine,conf,request); } // end try catch (ValidationException ve) { // something messed up in the preview generation return new ErrorBox(null,ve.getMessage(),on_error); } // end catch if (ntf.isNullRequest()) return null; // no title or text specified - "204 No Content" setMyLocation(request,"confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=T"); return ntf; } // end if ("preview" clicked) if (isImageButtonClicked(request,"post")) { // first validate that we've got all the parameters if (validateNewTopic(request,on_error)) return null; // this is a null request - send a null response try { // 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 setMyLocation(request,on_error); return new AttachmentForm(sig,conf,topic.getMessage(0),on_error); } // end if } // end try catch (DataException de) { // display a database error return new ErrorBox("Database Error","Database error adding topic: " + de.getMessage(),on_error); } // end catch catch (AccessError ae) { // some sort of access problem return new ErrorBox("Access Error",ae.getMessage(),on_error); } // end catch // jump back to the form under normal circumstances throw new RedirectResult(on_error); } // end if ("post" clicked) // we don't know what button was pressed logger.error("no known button click on ConfOperations.doPost, cmd=T"); return new ErrorBox("Internal Error","Unknown command button pressed",on_error); } // end if ("T" command) if (cmd.equals("P")) { // "P" = Set default pseud (requires conference parameter) ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confdisp?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID(); try { // go set the pseud! String pseud = request.getParameter("pseud"); if (pseud!=null) conf.setDefaultPseud(pseud); } // end try catch (DataException de) { // oops - there was a problem! return new ErrorBox("Database Error","Database error setting pseud: " + de.getMessage(),on_error); } // end catch return null; // don't change the view } // end if ("P" command) if (cmd.equals("E")) { // "E" = "Edit Conference Settings" (requires conference parameter) ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=Q"; if (!(conf.canChangeConference())) return new ErrorBox("Access Error","You are not permitted to change this conference's settings.", on_error); // create the dialog class EditConferenceDialog dlg = makeEditConferenceDialog(); if (dlg.isButtonClicked(request,"cancel")) throw new RedirectResult(on_error); // they chickened out - go back to the conference list if (dlg.isButtonClicked(request,"update")) { // they're changing the conference - do what you have to dlg.loadValues(request); // load the form data try { // run that baby! dlg.doDialog(conf); // success - return back to where we started from throw new RedirectResult(on_error); } // end try catch (ValidationException ve) { // validation error - throw it back to the user dlg.resetOnError(sig,conf,ve.getMessage() + " Please try again."); } // end catch catch (AccessError ae) { // some sort of access error - display an error dialog return new ErrorBox("Access Error",ae.getMessage(),on_error); } // end catch catch (DataException de) { // database error creating the conference return new ErrorBox("Database Error","Database error updating conference: " + de.getMessage(), on_error); } // end catch setMyLocation(request,"confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=E"); return dlg; // redisplay the dialog } // end if } // end if ("E" command) if (cmd.equals("A")) { // "A" = "Add Alias" (requires conference parameter) ConferenceContext conf = getConferenceParameter(request,sig,true,on_error); on_error = "confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=Q"; if (!(conf.canChangeConference())) return new ErrorBox("Access Error","You are not permitted to change this conference's settings.", on_error); String new_alias = request.getParameter("alias"); if (StringUtil.isStringEmpty(new_alias)) return null; // this is a no-op on_error = "confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=A"; String error_message = null; if (IDUtils.isValidVeniceID(new_alias)) { // the alias we have netered is perfectly valid... try { // go ahead and add the alias! conf.addAlias(new_alias); } // end try catch (AccessError ae) { // some sort of access error - display an error dialog return new ErrorBox("Access Error",ae.getMessage(),on_error); } // end catch catch (DataException de) { // database error creating the conference return new ErrorBox("Database Error","Database error adding alias: " + de.getMessage(), on_error); } // end catch } // end if else // alias is not valid error_message = "The alias you have entered is not a valid identifier. Please try again."; // redisplay the "Manage Conference Aliases" display try { // generate the display box setMyLocation(request,on_error); return new ManageConferenceAliases(sig,conf); } // end try catch (DataException de) { // error generating the display box return new ErrorBox("Database Error","Database error displaying aliases: " + de.getMessage(), "confops?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID() + "&cmd=Q"); } // end catch } // end if ("A" command) // unrecognized command! logger.error("invalid command to ConfOperations.doPost: " + cmd); return new ErrorBox("Internal Error","Invalid command to ConfOperations.doPost",on_error); } // end doVenicePost } // end class ConfOperations