001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/history/CmsHistoryClearDialog.java,v $
003: * Date : $Date: 2008-02-27 12:05:33 $
004: * Version: $Revision: 1.4 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.history;
033:
034: import org.opencms.jsp.CmsJspActionElement;
035: import org.opencms.main.CmsIllegalArgumentException;
036: import org.opencms.main.OpenCms;
037: import org.opencms.util.CmsStringUtil;
038: import org.opencms.widgets.CmsCalendarWidget;
039: import org.opencms.widgets.CmsCheckboxWidget;
040: import org.opencms.widgets.CmsSelectWidget;
041: import org.opencms.widgets.CmsSelectWidgetOption;
042: import org.opencms.workplace.CmsWidgetDialog;
043: import org.opencms.workplace.CmsWidgetDialogParameter;
044: import org.opencms.workplace.tools.CmsToolDialog;
045: import org.opencms.workplace.tools.CmsToolManager;
046:
047: import java.io.IOException;
048: import java.util.ArrayList;
049: import java.util.HashMap;
050: import java.util.List;
051: import java.util.Map;
052:
053: import javax.servlet.ServletException;
054: import javax.servlet.http.HttpServletRequest;
055: import javax.servlet.http.HttpServletResponse;
056: import javax.servlet.jsp.PageContext;
057:
058: /**
059: * Dialog to enter the settings to clear the history in the administration view.<p>
060: *
061: * @author Peter Bonrad
062: *
063: * @version $Revision: 1.4 $
064: *
065: * @since 6.9.1
066: */
067: public class CmsHistoryClearDialog extends CmsWidgetDialog {
068:
069: /** localized messages Keys prefix. */
070: public static final String KEY_PREFIX = "histclear";
071:
072: /** Defines which pages are valid for this dialog. */
073: public static final String[] PAGES = { "page1" };
074:
075: /** The import JSP report workplace URI. */
076: protected static final String CLEAR_ACTION_REPORT = PATH_WORKPLACE
077: + "admin/history/reports/clearhistory.jsp";
078:
079: /** The history clear object that is edited on this dialog. */
080: protected CmsHistoryClear m_historyClear;
081:
082: /**
083: * Public constructor with JSP action element.<p>
084: *
085: * @param jsp an initialized JSP action element
086: */
087: public CmsHistoryClearDialog(CmsJspActionElement jsp) {
088:
089: super (jsp);
090: }
091:
092: /**
093: * Public constructor with JSP variables.<p>
094: *
095: * @param context the JSP page context
096: * @param req the JSP request
097: * @param res the JSP response
098: */
099: public CmsHistoryClearDialog(PageContext context,
100: HttpServletRequest req, HttpServletResponse res) {
101:
102: this (new CmsJspActionElement(context, req, res));
103: }
104:
105: /**
106: * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
107: */
108: public void actionCommit() throws IOException, ServletException {
109:
110: List errors = new ArrayList();
111: setDialogObject(m_historyClear);
112:
113: if (m_historyClear.getKeepVersions() < 0) {
114: errors
115: .add(new CmsIllegalArgumentException(
116: Messages
117: .get()
118: .container(
119: Messages.GUI_HISTORY_CLEAR_INVALID_SETTINGS_0)));
120: } else {
121:
122: Map params = new HashMap();
123:
124: // set the name of this class to get dialog object in report
125: params.put(CmsHistoryClearReport.PARAM_CLASSNAME, this
126: .getClass().getName());
127:
128: // set style to display report in correct layout
129: params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
130:
131: // set close link to get back to overview after finishing the import
132: params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(
133: getJsp(), "/history"));
134:
135: // redirect to the report output JSP
136: getToolManager().jspForwardPage(this , CLEAR_ACTION_REPORT,
137: params);
138: }
139:
140: // set the list of errors to display when saving failed
141: setCommitErrors(errors);
142: }
143:
144: /**
145: * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
146: */
147: protected String createDialogHtml(String dialog) {
148:
149: StringBuffer result = new StringBuffer(1024);
150:
151: result.append(createWidgetTableStart());
152:
153: // show error header once if there were validation errors
154: result.append(createWidgetErrorHeader());
155:
156: if (dialog.equals(PAGES[0])) {
157:
158: // create the widgets for the first dialog page
159: result
160: .append(createWidgetBlockStart(key(Messages.GUI_HISTORY_CLEAR_BLOCK_LABEL_0)));
161:
162: Object versionStr = (OpenCms.getSystemInfo()
163: .getHistoryVersions() == -1) ? key(Messages.GUI_HISTORY_SETTINGS_VERSIONS_UNLIMITED_0)
164: : String.valueOf(OpenCms.getSystemInfo()
165: .getHistoryVersions());
166: result.append(key(Messages.GUI_HISTORY_CLEAR_VERSIONINFO_1,
167: new Object[] { versionStr }));
168: result.append("<p>");
169:
170: result.append(createDialogRowsHtml(0, 2));
171: result.append(createWidgetBlockEnd());
172: }
173:
174: result.append(createWidgetTableEnd());
175: return result.toString();
176: }
177:
178: /**
179: * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
180: */
181: protected void defineWidgets() {
182:
183: initHistoryClearObject();
184: setKeyPrefix(KEY_PREFIX);
185:
186: addWidget(new CmsWidgetDialogParameter(m_historyClear,
187: "keepVersions", PAGES[0], new CmsSelectWidget(
188: getVersions())));
189: addWidget(new CmsWidgetDialogParameter(m_historyClear,
190: "clearDeleted", PAGES[0], new CmsCheckboxWidget()));
191: addWidget(new CmsWidgetDialogParameter(m_historyClear,
192: "clearOlderThan", PAGES[0], new CmsCalendarWidget()));
193: }
194:
195: /**
196: * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
197: */
198: protected String[] getPageArray() {
199:
200: return PAGES;
201: }
202:
203: /**
204: * Initializes this widget dialog's object.<p>
205: */
206: protected void initHistoryClearObject() {
207:
208: Object o;
209:
210: if (CmsStringUtil.isEmpty(getParamAction())) {
211: o = new CmsHistoryClear();
212: } else {
213: // this is not the initial call, get the job object from session
214: o = getDialogObject();
215: }
216:
217: if (!(o instanceof CmsHistoryClear)) {
218:
219: // create a new history settings handler object
220: m_historyClear = new CmsHistoryClear();
221: } else {
222:
223: // reuse html import handler object stored in session
224: m_historyClear = (CmsHistoryClear) o;
225: }
226: }
227:
228: /**
229: * @see org.opencms.workplace.CmsWorkplace#initMessages()
230: */
231: protected void initMessages() {
232:
233: // add specific dialog resource bundle
234: addMessages(Messages.get().getBundleName());
235:
236: // add default resource bundles
237: super .initMessages();
238: }
239:
240: /**
241: * Returns a list with the possible versions to choose from.<p>
242: *
243: * @return a list with the possible versions to choose from
244: */
245: private List getVersions() {
246:
247: ArrayList ret = new ArrayList();
248:
249: int defaultHistoryVersions = OpenCms.getSystemInfo()
250: .getHistoryVersions();
251: int historyVersions = 0;
252:
253: // Add the option for disabled version history
254: ret.add(new CmsSelectWidgetOption("-1", true, Messages.get()
255: .getBundle().key(
256: Messages.GUI_HISTORY_CLEAR_VERSION_SELECT_0)));
257:
258: // Iterate from 1 to 50 with a stepping of 1 for the first 10 entries and a stepping of five for the entries from 10 to 50
259: while (historyVersions < 50) {
260:
261: // increment the history version
262: historyVersions++;
263:
264: if (historyVersions % 5 == 0 || historyVersions <= 10) {
265:
266: ret.add(new CmsSelectWidgetOption(String
267: .valueOf(historyVersions), false, String
268: .valueOf(historyVersions)));
269: }
270: }
271:
272: // If the default setting for the version history is more than 50
273: if (defaultHistoryVersions > historyVersions) {
274: ret.add(new CmsSelectWidgetOption(String
275: .valueOf(defaultHistoryVersions), false, String
276: .valueOf(defaultHistoryVersions)));
277: }
278:
279: return ret;
280: }
281:
282: }
|