001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.tools.modules;
029
030import org.opencms.jsp.CmsJspActionElement;
031import org.opencms.workplace.CmsDialog;
032import org.opencms.workplace.CmsWorkplaceSettings;
033import org.opencms.workplace.tools.CmsToolDialog;
034import org.opencms.workplace.tools.CmsToolManager;
035
036import java.util.HashMap;
037import java.util.Map;
038
039import javax.servlet.http.HttpServletRequest;
040import javax.servlet.http.HttpServletResponse;
041import javax.servlet.jsp.JspException;
042import javax.servlet.jsp.PageContext;
043
044/**
045 * Provides an confirm screen for module deletion.<p>
046 *
047 * @since 6.0.0
048 */
049public class CmsModulesDelete extends CmsDialog {
050
051    /** The dialog type. */
052    public static final String DIALOG_TYPE = "DeleteModuleConfirm";
053
054    /** Modulename parameter. */
055    public static final String PARAM_MODULE = "module";
056
057    /** The delete action. */
058    private static final String DELETE_ACTION_REPORT = "/system/workplace/admin/modules/reports/delete.jsp";
059
060    /** Modulename. */
061    protected String m_paramModule;
062
063    /**
064     * Public constructor.<p>
065     *
066     * @param jsp an initialized JSP action element
067     */
068    public CmsModulesDelete(CmsJspActionElement jsp) {
069
070        super(jsp);
071    }
072
073    /**
074     * Public constructor with JSP variables.<p>
075     *
076     * @param context the JSP page context
077     * @param req the JSP request
078     * @param res the JSP response
079     */
080    public CmsModulesDelete(PageContext context, HttpServletRequest req, HttpServletResponse res) {
081
082        this(new CmsJspActionElement(context, req, res));
083    }
084
085    /**
086     * Performs the re-initialization report, will be called by the JSP page.<p>
087     *
088     * @throws JspException if including the error JSP element fails
089     */
090    public void actionReport() throws JspException {
091
092        // save initialized instance of this class in request attribute for included sub-elements
093        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
094        switch (getAction()) {
095            case ACTION_CONFIRMED:
096            default:
097                try {
098                    Map params = new HashMap();
099                    params.put(PARAM_MODULE, getParamModule());
100                    // set style to display report in correct layout
101                    params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
102                    // set close link to get back to overview after finishing the import
103                    params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/modules"));
104                    // redirect to the report output JSP
105                    getToolManager().jspForwardPage(this, DELETE_ACTION_REPORT, params);
106
107                    actionCloseDialog();
108                } catch (Throwable e) {
109                    // create a new Exception with custom message
110                    includeErrorpage(this, e);
111                }
112                break;
113        }
114    }
115
116    /**
117     * Gets the module parameter.<p>
118     *
119     * @return the module parameter
120     */
121    public String getParamModule() {
122
123        return m_paramModule;
124    }
125
126    /**
127     * Sets the module parameter.<p>
128     * @param paramModule the module parameter
129     */
130    public void setParamModule(String paramModule) {
131
132        m_paramModule = paramModule;
133    }
134
135    /**
136     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
137     */
138    @Override
139    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
140
141        // fill the parameter values in the get/set methods
142        fillParamValues(request);
143        // set the dialog type
144        setParamDialogtype(DIALOG_TYPE);
145        // set the action for the JSP switch
146        if (DIALOG_CONFIRMED.equals(getParamAction())) {
147            setAction(ACTION_CONFIRMED);
148        } else if (DIALOG_CANCEL.equals(getParamAction())) {
149            setAction(ACTION_CANCEL);
150        } else {
151            setAction(ACTION_DEFAULT);
152            // add the title for the dialog
153            setParamTitle(key(Messages.GUI_DELETEMODULE_ADMIN_TOOL_NAME_0));
154        }
155    }
156}