/* * 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 TopicOperations extends VeniceServlet { /*-------------------------------------------------------------------------------- * Static data members *-------------------------------------------------------------------------------- */ private static final String DELETE_CONFIRM_ATTR = "servlets.TopicOperations.delete.confirm"; private static final String DELETE_CONFIRM_PARAM = "confirm"; private static Category logger = Category.getInstance(TopicOperations.class.getName()); /*-------------------------------------------------------------------------------- * Overrides from class HttpServlet *-------------------------------------------------------------------------------- */ public String getServletInfo() { String rc = "TopicOperations servlet - General topic operations (freeze, archive, 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 locator = "sig=" + sig.getSIGID(); String location = "sigprofile?" + locator; // get the conference ConferenceContext conf = getConferenceParameter(request,sig,true,location); locator += "&conf=" + conf.getConfID(); location = "confdisp?" + locator; // get the topic TopicContext topic = getTopicParameter(request,conf,true,location); locator += "&top=" + topic.getTopicNumber(); location = "confdisp?" + locator; // figure out what command we want to perform... String cmd = getStandardCommandParam(request); if (cmd.equals("HY") || cmd.equals("HN")) { // we want to set the hide status of the topic try { // call down to set the topic! topic.setHidden(cmd.equals("HY")); } // end try catch (DataException de) { // there was a database error return new ErrorBox("Database Error","Database error setting hide status: " + de.getMessage(), location); } // end catch // go back to the topic view throw new RedirectResult(location); } // end if ("hide" or "show") if (cmd.equals("FY") || cmd.equals("FN")) { // we want to set the frozen status of the topic try { // call down to set the topic! topic.setFrozen(cmd.equals("FY")); } // end try catch (DataException de) { // there was a database error return new ErrorBox("Database Error","Database error setting freeze status: " + de.getMessage(), location); } // end catch catch (AccessError ae) { // naughty naughty = you can't do this! return new ErrorBox("Access Error",ae.getMessage(),location); } // end catch // go back to the topic view throw new RedirectResult(location); } // end if ("freeze" or "unfreeze") if (cmd.equals("AY") || cmd.equals("AN")) { // we want to change the archived status of the topic try { // call down to set the topic! topic.setArchived(cmd.equals("AY")); } // end try catch (DataException de) { // there was a database error return new ErrorBox("Database Error","Database error setting archive status: " + de.getMessage(), location); } // end catch catch (AccessError ae) { // naughty naughty = you can't do this! return new ErrorBox("Access Error",ae.getMessage(),location); } // end catch // go back to the topic view throw new RedirectResult(location); } // end if ("archive" or "unarchive") if (cmd.equals("DEL")) { // Delete Topic requires a confirmation! if (ConfirmBox.isConfirmed(request,DELETE_CONFIRM_ATTR,DELETE_CONFIRM_PARAM)) { // OK, go ahead, delete the topic! location = "confdisp?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID(); try { // delete the bloody topic! topic.delete(); } // end try catch (DataException de) { // there was a database error return new ErrorBox("Database Error","Database error deleting topic: " + de.getMessage(),location); } // end catch catch (AccessError ae) { // naughty naughty = you can't do this! return new ErrorBox("Access Error",ae.getMessage(),location); } // end catch // go back to the conference view throw new RedirectResult(location); } // end if (confirmed) else { // not a proper confirmation - better display one String message = "You are about to delete topic " + String.valueOf(topic.getTopicNumber()) + " from the \"" + conf.getName() + "\" conference! Are you sure you want to do this?"; return new ConfirmBox(request,DELETE_CONFIRM_ATTR,DELETE_CONFIRM_PARAM,"Delete Topic",message, "topicops?" + locator + "&cmd=DEL",location); } // end else } // end if (delete) // unrecognized command logger.error("invalid command to TopicOperations.doGet: " + cmd); return new ErrorBox("Internal Error","Invalid command to TopicOperations.doGet",location); } // end doVeniceGet } // end class TopicOperations