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.content.check;
029
030import org.opencms.file.collectors.I_CmsResourceCollector;
031import org.opencms.jsp.CmsJspActionElement;
032import org.opencms.report.I_CmsReportThread;
033import org.opencms.workplace.list.A_CmsListReport;
034
035import java.util.Hashtable;
036import java.util.Map;
037
038import javax.servlet.http.HttpServletRequest;
039import javax.servlet.http.HttpServletResponse;
040import javax.servlet.jsp.JspException;
041import javax.servlet.jsp.PageContext;
042
043/**
044 * Provides a report for checking the content of resources in the OpenCms VFS.<p>
045 *
046 * @since 6.1.2
047 */
048public class CmsContentCheckReport extends A_CmsListReport {
049
050    /** The object edited with this widget dialog. */
051    protected Object m_dialogObject;
052
053    /** The Content Check object. */
054    private CmsContentCheck m_contentCheck;
055
056    /** Request parameter for the class name to get the dialog object from. */
057    private String m_paramClassname;
058
059    /**
060     * Public constructor with JSP action element.<p>
061     *
062     * @param jsp an initialized JSP action element
063     */
064    public CmsContentCheckReport(CmsJspActionElement jsp) {
065
066        super(jsp);
067    }
068
069    /**
070     * Public constructor with JSP variables.<p>
071     *
072     * @param context the JSP page context
073     * @param req the JSP request
074     * @param res the JSP response
075     */
076    public CmsContentCheckReport(PageContext context, HttpServletRequest req, HttpServletResponse res) {
077
078        this(new CmsJspActionElement(context, req, res));
079    }
080
081    /**
082     * Performs the dialog actions depending on the initialized action.<p>
083     *
084     * @throws JspException if dialog actions fail
085     */
086    @Override
087    public void displayReport() throws JspException {
088
089        // save initialized instance of this class in request attribute for included sub-elements
090        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
091        switch (getAction()) {
092            case ACTION_REPORT_END:
093                // set the results of the content check
094                m_contentCheck = (CmsContentCheck)((Map)getSettings().getDialogObject()).get(getParamClassname());
095                I_CmsResourceCollector collector = new CmsContentCheckCollector(null, m_contentCheck.getResults());
096                getSettings().setCollector(collector);
097                try {
098                    getToolManager().jspForwardTool(this, "/contenttools/check/result", null);
099                } catch (Exception e) {
100                    actionCloseDialog();
101                }
102                break;
103            case ACTION_CANCEL:
104                actionCloseDialog();
105                break;
106            case ACTION_REPORT_UPDATE:
107                setParamAction(REPORT_UPDATE);
108                getJsp().include(FILE_REPORT_OUTPUT);
109                break;
110            case ACTION_REPORT_BEGIN:
111            case ACTION_CONFIRMED:
112            case ACTION_DEFAULT:
113            default:
114                I_CmsReportThread m_thread = initializeThread();
115                m_thread.start();
116                setParamAction(REPORT_BEGIN);
117                setParamThread(m_thread.getUUID().toString());
118                getJsp().include(FILE_REPORT_OUTPUT);
119        }
120    }
121
122    /**
123     * Returns the request parameter value for the class name to get the dialog object from.<p>
124     *
125     * @return the request parameter value for the class name to get the dialog object from
126     */
127    public String getParamClassname() {
128
129        return m_paramClassname;
130    }
131
132    /**
133     *
134     * @see org.opencms.workplace.list.A_CmsListReport#initializeThread()
135     */
136    @Override
137    public I_CmsReportThread initializeThread() {
138
139        m_contentCheck = (CmsContentCheck)((Map)getSettings().getDialogObject()).get(getParamClassname());
140
141        I_CmsReportThread contentCheckThread = new CmsContentCheckThread(getCms(), m_contentCheck);
142
143        return contentCheckThread;
144    }
145
146    /**
147     * Stores the given object as "dialog object" for this widget dialog in the current users session.<p>
148     *
149     * @param dialogObject the object to store
150     */
151    public void setDialogObject(Object dialogObject) {
152
153        m_dialogObject = dialogObject;
154        if (dialogObject == null) {
155            // null object: remove the entry from the map
156            getDialogObjectMap().remove(getClass().getName());
157        } else {
158            getDialogObjectMap().put(getClass().getName(), dialogObject);
159        }
160    }
161
162    /**
163     * Sets the request parameter value for the class name to get the dialog object from.<p>
164     *
165     * @param className the request parameter value for the class name to get the dialog object from
166     */
167    public void setParamClassname(String className) {
168
169        m_paramClassname = className;
170    }
171
172    /**
173     * Returns the (internal use only) map of dialog objects.<p>
174     *
175     * @return the (internal use only) map of dialog objects
176     */
177    private Map getDialogObjectMap() {
178
179        Map objects = (Map)getSettings().getDialogObject();
180        if (objects == null) {
181            // using hashtable as most efficient version of a synchronized map
182            objects = new Hashtable();
183            getSettings().setDialogObject(objects);
184        }
185        return objects;
186    }
187
188}