KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > history > CmsAdminHistorySettings


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/history/CmsAdminHistorySettings.java,v $
3  * Date : $Date: 2006/03/28 10:20:09 $
4  * Version: $Revision: 1.12 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.history;
33
34 import org.opencms.configuration.CmsSystemConfiguration;
35 import org.opencms.i18n.CmsMessages;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.CmsIllegalArgumentException;
38 import org.opencms.main.OpenCms;
39 import org.opencms.workplace.CmsDialog;
40 import org.opencms.workplace.CmsWorkplaceSettings;
41
42 import javax.servlet.http.HttpServletRequest JavaDoc;
43 import javax.servlet.http.HttpServletResponse JavaDoc;
44 import javax.servlet.jsp.JspException JavaDoc;
45 import javax.servlet.jsp.PageContext JavaDoc;
46
47 /**
48  * Provides methods for the history settings dialog.<p>
49  *
50  * The following files use this class:
51  * <ul>
52  * <li>/system/workplace/administration/history/settings/index.jsp
53  * </ul>
54  * <p>
55  *
56  * @author Andreas Zahner
57  *
58  * @version $Revision: 1.12 $
59  *
60  * @since 6.0.0
61  */

62 public class CmsAdminHistorySettings extends CmsDialog {
63
64     /** Value for the action: save the settings. */
65     public static final int ACTION_SAVE_EDIT = 300;
66
67     /** Request parameter value for the action: save the settings. */
68     public static final String JavaDoc DIALOG_SAVE_EDIT = "saveedit";
69
70     /** The dialog type. */
71     public static final String JavaDoc DIALOG_TYPE = "historysettings";
72
73     /**
74      * Public constructor with JSP action element.<p>
75      *
76      * @param jsp an initialized JSP action element
77      */

78     public CmsAdminHistorySettings(CmsJspActionElement jsp) {
79
80         super(jsp);
81     }
82
83     /**
84      * Public constructor with JSP variables.<p>
85      *
86      * @param context the JSP page context
87      * @param req the JSP request
88      * @param res the JSP response
89      */

90     public CmsAdminHistorySettings(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
91
92         this(new CmsJspActionElement(context, req, res));
93     }
94
95     /**
96      * Performs the change of the history settings, this method is called by the JSP.<p>
97      *
98      * @param request the HttpServletRequest
99      * @throws JspException if something goes wrong
100      */

101     public void actionEdit(HttpServletRequest JavaDoc request) throws JspException JavaDoc {
102
103         // save initialized instance of this class in request attribute for included sub-elements
104
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
105         try {
106             performEditOperation(request);
107             // set the request parameters before returning to the overview
108
actionCloseDialog();
109         } catch (CmsIllegalArgumentException e) {
110             // error setting history values, show error dialog
111

112             includeErrorpage(this, e);
113         }
114     }
115
116     /**
117      * Builds the HTML for the history settings input form.<p>
118      *
119      * @return the HTML code for the history settings input form
120      */

121     public String JavaDoc buildSettingsForm() {
122
123         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc(512);
124         boolean histEnabled = OpenCms.getSystemInfo().isVersionHistoryEnabled();
125         int maxVersions = OpenCms.getSystemInfo().getVersionHistoryMaxCount();
126         CmsMessages messages = Messages.get().getBundle(getLocale());
127         retValue.append("<table border=\"0\">\n");
128         retValue.append("<tr>\n");
129         retValue.append("<td>" + messages.key(Messages.GUI_INPUT_HISTENABLED_0) + "</td>\n");
130         retValue.append("<td><input type=\"radio\" name=\"enable\" id=\"enabled\" value=\"true\" onclick=\"checkEnabled();\"");
131         if (histEnabled) {
132             retValue.append(" checked=\"checked\"");
133         }
134         retValue.append("></td>\n");
135         retValue.append("<td>" + messages.key(Messages.GUI_INPUT_HISTENABLE_YES_0) + "</td>\n");
136         retValue.append("<td>&nbsp;</td>\n");
137         retValue.append("<td><input type=\"radio\" name=\"enable\" id=\"disabled\" value=\"false\" onclick=\"checkEnabled();\"");
138         if (!histEnabled) {
139             retValue.append(" checked=\"checked\"");
140         }
141         retValue.append("></td>\n");
142         retValue.append("<td>" + messages.key(Messages.GUI_INPUT_HISTENABLE_NO_0) + "</td>\n");
143         retValue.append("</tr>\n");
144         retValue.append("</table>\n");
145
146         retValue.append("<div class=\"hide\" id=\"settings\">\n");
147         retValue.append("<table border=\"0\">\n");
148         retValue.append("<tr>\n");
149         retValue.append("<td>" + messages.key(Messages.GUI_INPUT_HISTNUMBER_0) + "</td>\n");
150         retValue.append("<td colspan=\"5\"><input type=\"text\" name=\"versions\" value=\"");
151         if (maxVersions != -1) {
152             retValue.append(maxVersions);
153         }
154         retValue.append("\" onkeypress=\"event.returnValue=isDigit();\"></td>\n");
155         retValue.append("</tr>\n");
156         retValue.append("</table>\n");
157         retValue.append("</div>\n");
158
159         return retValue.toString();
160     }
161
162     /**
163      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
164      */

165     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
166
167         // fill the parameter values in the get/set methods
168
fillParamValues(request);
169         // set the dialog type
170
setParamDialogtype(DIALOG_TYPE);
171         // set the action for the JSP switch
172
if (DIALOG_SAVE_EDIT.equals(getParamAction())) {
173             setAction(ACTION_SAVE_EDIT);
174         } else if (DIALOG_CANCEL.equals(getParamAction())) {
175             setAction(ACTION_CANCEL);
176         } else {
177             // set the default action
178
setAction(ACTION_DEFAULT);
179             setParamTitle(Messages.get().getBundle(getLocale()).key(Messages.GUI_LABEL_ADMNIN_HISTORY_SETTINGS_0));
180         }
181     }
182
183     /**
184      * Performs the change of the history settings.<p>
185      *
186      * @param request the HttpServletRequest
187      * @return true if everything was ok
188      * @throws CmsIllegalArgumentException if the entered number is no positive integer
189      */

190     private boolean performEditOperation(HttpServletRequest JavaDoc request) throws CmsIllegalArgumentException {
191
192         // get the new settings from the request parameters
193
String JavaDoc paramEnabled = request.getParameter("enable");
194         String JavaDoc paramVersions = request.getParameter("versions");
195
196         // check the submitted values
197
boolean enabled = Boolean.valueOf(paramEnabled).booleanValue();
198         int versions = 0;
199         try {
200             versions = Integer.parseInt(paramVersions);
201         } catch (NumberFormatException JavaDoc e) {
202             // no int value submitted, throw exception
203
throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_NO_INT_ENTERED_0), e);
204         }
205         if (versions < 1) {
206             // version value too low, throw exception
207
throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_NO_POSITIVE_INT_0));
208         }
209
210         OpenCms.getSystemInfo().setVersionHistorySettings(enabled, versions);
211         OpenCms.writeConfiguration(CmsSystemConfiguration.class);
212
213         return true;
214     }
215
216 }
217
Popular Tags