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.database;
029
030import org.opencms.jsp.CmsJspActionElement;
031import org.opencms.util.CmsStringUtil;
032import org.opencms.widgets.CmsDisplayWidget;
033import org.opencms.widgets.CmsVfsFileWidget;
034import org.opencms.workplace.CmsDialog;
035import org.opencms.workplace.CmsWidgetDialog;
036import org.opencms.workplace.CmsWidgetDialogParameter;
037import org.opencms.workplace.CmsWorkplaceSettings;
038import org.opencms.workplace.tools.CmsToolDialog;
039
040import java.util.ArrayList;
041import java.util.HashMap;
042import java.util.List;
043import java.util.Map;
044
045import javax.servlet.http.HttpServletRequest;
046import javax.servlet.http.HttpServletResponse;
047import javax.servlet.jsp.PageContext;
048
049/**
050 * Dialog to remove old publish locks.<p>
051 *
052 * @since 7.0.2
053 */
054public class CmsRemovePubLocksDialog extends CmsWidgetDialog {
055
056    /** The dialog type. */
057    public static final String DIALOG_TYPE = "dbpublocks";
058
059    /** Defines which pages are valid for this dialog. */
060    public static final String[] PAGES = {"page1"};
061
062    /** The notice text. */
063    private String m_notice;
064
065    /** the resources to unlock. */
066    private List m_resources;
067
068    /**
069     * Public constructor with JSP action element.<p>
070     *
071     * @param jsp an initialized JSP action element
072     */
073    public CmsRemovePubLocksDialog(CmsJspActionElement jsp) {
074
075        super(jsp);
076    }
077
078    /**
079     * Public constructor with JSP variables.<p>
080     *
081     * @param context the JSP page context
082     * @param req the JSP request
083     * @param res the JSP response
084     */
085    public CmsRemovePubLocksDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
086
087        this(new CmsJspActionElement(context, req, res));
088    }
089
090    /**
091     * @see org.opencms.workplace.tools.modules.CmsModulesEditBase#actionCommit()
092     */
093    @Override
094    public void actionCommit() {
095
096        try {
097            // forward to the report page
098            Map params = new HashMap();
099            params.put(CmsRemovePubLocksReport.PARAM_RESOURCES, CmsStringUtil.collectionAsString(m_resources, ","));
100            params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
101            getToolManager().jspForwardPage(this, "/system/workplace/admin/database/publishlocksreport.jsp", params);
102        } catch (Exception e) {
103            addCommitError(e);
104        }
105    }
106
107    /**
108     * Returns the notice text.<p>
109     *
110     * @return the notice text
111     */
112    public String getNotice() {
113
114        if (m_notice == null) {
115            m_notice = key(Messages.GUI_DB_PUBLOCKS_NOTICE_0);
116        }
117        return m_notice;
118    }
119
120    /**
121     * Returns the resources.<p>
122     *
123     * @return the resources
124     */
125    public List getResources() {
126
127        return m_resources;
128    }
129
130    /**
131     * Sets the notice text.<p>
132     *
133     * @param notice the notice text to set
134     */
135    public void setNotice(String notice) {
136
137        m_notice = notice;
138    }
139
140    /**
141     * Sets the resources.<p>
142     *
143     * @param resources the resources to set
144     */
145    public void setResources(List resources) {
146
147        m_resources = resources;
148    }
149
150    /**
151     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
152     *
153     * @param dialog the dialog (page) to get the HTML for
154     * @return the dialog HTML for all defined widgets of the named dialog (page)
155     */
156    @Override
157    protected String createDialogHtml(String dialog) {
158
159        StringBuffer result = new StringBuffer(1024);
160
161        // create table
162        result.append(createWidgetTableStart());
163
164        // show error header once if there were validation errors
165        result.append(createWidgetErrorHeader());
166
167        if (dialog.equals(PAGES[0])) {
168            result.append(dialogBlockStart(null));
169            result.append(createWidgetTableStart());
170            result.append(createDialogRowsHtml(0, 1));
171            result.append(createWidgetTableEnd());
172            result.append(dialogBlockEnd());
173        }
174        // close table
175        result.append(createWidgetTableEnd());
176
177        return result.toString();
178    }
179
180    /**
181     * Creates the list of widgets for this dialog.<p>
182     */
183    @Override
184    protected void defineWidgets() {
185
186        initObject();
187        addWidget(new CmsWidgetDialogParameter(this, "notice", PAGES[0], new CmsDisplayWidget()));
188        addWidget(new CmsWidgetDialogParameter(this, "resources", PAGES[0], new CmsVfsFileWidget()));
189    }
190
191    /**
192     * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
193     */
194    @Override
195    protected String[] getPageArray() {
196
197        return PAGES;
198    }
199
200    /**
201     * Initializes the session object.<p>
202     */
203    protected void initObject() {
204
205        Object o;
206
207        if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
208            // this is the initial dialog call
209            o = new ArrayList();
210            ((List)o).add("/");
211        } else {
212            // this is not the initial call, get module from session
213            o = getDialogObject();
214        }
215
216        if (!(o instanceof List)) {
217            m_resources = new ArrayList();
218            m_resources.add("/");
219        } else {
220            // reuse object stored in session
221            m_resources = (List)o;
222        }
223    }
224
225    /**
226     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
227     */
228    @Override
229    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
230
231        // set the dialog type
232        setParamDialogtype(DIALOG_TYPE);
233
234        super.initWorkplaceRequestValues(settings, request);
235
236        // save the current state of the module (may be changed because of the widget values)
237        setDialogObject(m_resources);
238    }
239}