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.list;
029
030import org.opencms.jsp.CmsJspActionElement;
031import org.opencms.report.I_CmsReportThread;
032import org.opencms.workplace.CmsReport;
033import org.opencms.workplace.CmsWorkplaceSettings;
034
035import javax.servlet.http.HttpServletRequest;
036import javax.servlet.http.HttpServletResponse;
037import javax.servlet.jsp.JspException;
038import javax.servlet.jsp.PageContext;
039
040/**
041 * Provides a report in the list widget.<p>
042 *
043 * @since 6.0.0
044 */
045public abstract class A_CmsListReport extends CmsReport {
046
047    /**
048     * Public constructor with JSP action element.<p>
049     *
050     * @param jsp an initialized JSP action element
051     */
052    public A_CmsListReport(CmsJspActionElement jsp) {
053
054        super(jsp);
055
056    }
057
058    /**
059     * Public constructor with JSP variables.<p>
060     *
061     * @param context the JSP page context
062     * @param req the JSP request
063     * @param res the JSP response
064     */
065    public A_CmsListReport(PageContext context, HttpServletRequest req, HttpServletResponse res) {
066
067        this(new CmsJspActionElement(context, req, res));
068
069    }
070
071    /**
072     * @see org.opencms.workplace.CmsDialog#actionCloseDialog()
073     */
074    @Override
075    public void actionCloseDialog() throws JspException {
076
077        getSettings().setListObject(null);
078        super.actionCloseDialog();
079    }
080
081    /**
082     * Performs the dialog actions depending on the initialized action.<p>
083     *
084     * @throws JspException if dialog actions fail
085     */
086    public void displayReport() throws JspException {
087
088        // save initialized instance of this class in request attribute for included sub-elements
089        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
090        switch (getAction()) {
091            case ACTION_REPORT_END:
092            case ACTION_CANCEL:
093                actionCloseDialog();
094                break;
095            case ACTION_REPORT_UPDATE:
096                setParamAction(REPORT_UPDATE);
097                getJsp().include(FILE_REPORT_OUTPUT);
098                break;
099            case ACTION_REPORT_BEGIN:
100            case ACTION_CONFIRMED:
101            case ACTION_DEFAULT:
102            default:
103                I_CmsReportThread thread = initializeThread();
104                thread.start();
105                setParamAction(REPORT_BEGIN);
106                setParamThread(thread.getUUID().toString());
107                getJsp().include(FILE_REPORT_OUTPUT);
108        }
109    }
110
111    /**
112     * Initializes the report thread to use for this report.<p>
113     *
114     * @return the reported thread to use for this report.
115     */
116    public abstract I_CmsReportThread initializeThread();
117
118    /**
119     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
120     */
121    @Override
122    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
123
124        // fill the parameter values in the get/set methods
125        fillParamValues(request);
126
127        if (REPORT_UPDATE.equals(getParamAction())) {
128            setAction(ACTION_REPORT_UPDATE);
129        } else if (REPORT_BEGIN.equals(getParamAction())) {
130            setAction(ACTION_REPORT_BEGIN);
131        } else if (REPORT_END.equals(getParamAction())) {
132            setAction(ACTION_REPORT_END);
133        } else if (DIALOG_CANCEL.equals(getParamAction())) {
134            setAction(ACTION_CANCEL);
135        } else {
136            // set the default action
137            setAction(ACTION_DEFAULT);
138        }
139        if (DIALOG_INITIAL.equals(getParamAction()) || (getParamAction() == null)) {
140            // test the needed parameters
141            try {
142                validateParameters();
143            } catch (Exception e) {
144                // redirect to parent if parameters not available
145                setAction(ACTION_CANCEL);
146                try {
147                    actionCloseDialog();
148                } catch (JspException e1) {
149                    // noop
150                }
151                return;
152            }
153        }
154    }
155
156    /**
157     * Should be overridden for parameter validation.<p>
158     *
159     * @throws Exception if the parameters are not valid
160     */
161    protected void validateParameters() throws Exception {
162
163        // valid by default
164    }
165}