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.link;
029
030import org.opencms.jsp.CmsJspActionElement;
031import org.opencms.report.I_CmsReportThread;
032import org.opencms.ui.apps.linkvalidation.CmsExternalLinksValidatorThread;
033import org.opencms.workplace.CmsWorkplaceSettings;
034import org.opencms.workplace.list.A_CmsListReport;
035import org.opencms.workplace.tools.CmsToolManager;
036
037import java.util.HashMap;
038import java.util.Map;
039
040import javax.servlet.http.HttpServletRequest;
041import javax.servlet.http.HttpServletResponse;
042import javax.servlet.jsp.JspException;
043import javax.servlet.jsp.PageContext;
044
045/**
046 * Provides an output window for a CmsReport.<p>
047 *
048 * @since 6.0.0
049 */
050public class CmsPointerLinkValidatorReport extends A_CmsListReport {
051
052    /** The dialog type. */
053    public static final String DIALOG_TYPE = "imp";
054
055    /**
056     * Public constructor.<p>
057     *
058     * @param jsp an initialized JSP action element
059     */
060    public CmsPointerLinkValidatorReport(CmsJspActionElement jsp) {
061
062        super(jsp);
063    }
064
065    /**
066     * Public constructor with JSP variables.<p>
067     *
068     * @param context the JSP page context
069     * @param req the JSP request
070     * @param res the JSP response
071     */
072    public CmsPointerLinkValidatorReport(PageContext context, HttpServletRequest req, HttpServletResponse res) {
073
074        this(new CmsJspActionElement(context, req, res));
075    }
076
077    /**
078     * Performs the pointer link validation report, will be called by the JSP page.<p>
079     *
080     * @throws JspException if problems including sub-elements occur
081     */
082    public void actionReport() throws JspException {
083
084        // save initialized instance of this class in request attribute for included sub-elements
085        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
086        switch (getAction()) {
087            case ACTION_REPORT_END:
088                actionCloseDialog();
089                break;
090            case ACTION_REPORT_UPDATE:
091                setParamAction(REPORT_UPDATE);
092                getJsp().include(FILE_REPORT_OUTPUT);
093                break;
094            case ACTION_REPORT_BEGIN:
095            case ACTION_CONFIRMED:
096            default:
097                CmsExternalLinksValidatorThread thread = new CmsExternalLinksValidatorThread(getCms(), null);
098                thread.start();
099                setParamAction(REPORT_BEGIN);
100                setParamThread(thread.getUUID().toString());
101                Map params = new HashMap(1);
102                params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/linkchecking"));
103                getJsp().include(FILE_REPORT_OUTPUT, null, params);
104                break;
105        }
106    }
107
108    /**
109     *
110     * @see org.opencms.workplace.list.A_CmsListReport#initializeThread()
111     */
112    @Override
113    public I_CmsReportThread initializeThread() {
114
115        return new CmsExternalLinksValidatorThread(getCms(), null);
116    }
117
118    /**
119     * @see org.opencms.workplace.CmsWorkplace#initMessages()
120     */
121    @Override
122    protected void initMessages() {
123
124        addMessages(Messages.get().getBundleName());
125        super.initMessages();
126    }
127
128    /**
129     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
130     */
131    @Override
132    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
133
134        // fill the parameter values in the get/set methods
135        fillParamValues(request);
136        // set the dialog type
137        setParamDialogtype(DIALOG_TYPE);
138        // set the action for the JSP switch
139        if (DIALOG_CONFIRMED.equals(getParamAction())) {
140            setAction(ACTION_CONFIRMED);
141        } else if (REPORT_UPDATE.equals(getParamAction())) {
142            setAction(ACTION_REPORT_UPDATE);
143        } else if (REPORT_BEGIN.equals(getParamAction())) {
144            setAction(ACTION_REPORT_BEGIN);
145        } else if (REPORT_END.equals(getParamAction())) {
146            setAction(ACTION_REPORT_END);
147        } else if (DIALOG_CANCEL.equals(getParamAction())) {
148            setAction(ACTION_CANCEL);
149        } else {
150            setAction(ACTION_DEFAULT);
151            // add the title for the dialog
152            setParamTitle(Messages.get().getBundle(getLocale()).key(Messages.GUI_EXTERNALLINK_ADMIN_TOOL_NAME_0));
153        }
154    }
155}