/* * 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 Community 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.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 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 /*-------------------------------------------------------------------------------- * 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 { // 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 back to the conference list // TODO: want to jump to the conference's "topic list" page if possible rdat.redirectTo(location); 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 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