KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > workplace > CmsEditLoginMessageDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/CmsEditLoginMessageDialog.java,v $
3  * Date : $Date: 2005/06/27 23:22:23 $
4  * Version: $Revision: 1.10 $
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.workplace;
33
34 import org.opencms.configuration.CmsSystemConfiguration;
35 import org.opencms.db.CmsLoginMessage;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.OpenCms;
38 import org.opencms.widgets.CmsCalendarWidget;
39 import org.opencms.widgets.CmsCheckboxWidget;
40 import org.opencms.widgets.CmsTextareaWidget;
41 import org.opencms.workplace.CmsWidgetDialog;
42 import org.opencms.workplace.CmsWidgetDialogParameter;
43 import org.opencms.workplace.CmsWorkplaceSettings;
44
45 import java.util.ArrayList JavaDoc;
46 import java.util.List JavaDoc;
47
48 import javax.servlet.http.HttpServletRequest JavaDoc;
49 import javax.servlet.http.HttpServletResponse JavaDoc;
50 import javax.servlet.jsp.PageContext JavaDoc;
51
52 /**
53  * Dialog to edit the login message of the OpenCms Workplace.<p>
54  *
55  * @author Alexander Kandzior
56  *
57  * @version $Revision: 1.10 $
58  *
59  * @since 6.0.0
60  */

61 public class CmsEditLoginMessageDialog extends CmsWidgetDialog {
62
63     /** localized messages Keys prefix. */
64     public static final String JavaDoc KEY_PREFIX = "loginmsg";
65     
66     /** Defines which pages are valid for this dialog. */
67     public static final String JavaDoc[] PAGES = {"page1"};
68
69     /** The login message that is edited with this dialog. */
70     private CmsLoginMessage m_loginMessage;
71
72     /**
73      * Public constructor with JSP action element.<p>
74      *
75      * @param jsp an initialized JSP action element
76      */

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

89     public CmsEditLoginMessageDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
90
91         this(new CmsJspActionElement(context, req, res));
92     }
93
94     /**
95      * Commits the edited login message to the login manager.<p>
96      */

97     public void actionCommit() {
98
99         List JavaDoc errors = new ArrayList JavaDoc();
100
101         try {
102             // set the edited message
103
OpenCms.getLoginManager().setLoginMessage(getCms(), m_loginMessage);
104             // update the system configuration
105
OpenCms.writeConfiguration(CmsSystemConfiguration.class);
106             // clear the message object
107
setDialogObject(null);
108         } catch (Throwable JavaDoc t) {
109             errors.add(t);
110         }
111
112         // set the list of errors to display when saving failed
113
setCommitErrors(errors);
114     }
115
116     /**
117      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
118      *
119      * This overwrites the method from the super class to create a layout variation for the widgets.<p>
120      *
121      * @param dialog the dialog (page) to get the HTML for
122      * @return the dialog HTML for all defined widgets of the named dialog (page)
123      */

124     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
125
126         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
127
128         // create widget table
129
result.append(createWidgetTableStart());
130
131         // show error header once if there were validation errors
132
result.append(createWidgetErrorHeader());
133
134         // create the widgets for the first dialog page
135
result.append(dialogBlockStart(key(Messages.GUI_EDITOR_LABEL_ACTIVATE_BLOCK_0)));
136         result.append(createWidgetTableStart());
137         result.append(createDialogRowsHtml(0, 0));
138         result.append(createWidgetTableEnd());
139         result.append(dialogBlockEnd());
140         result.append(dialogBlockStart(key(Messages.GUI_EDITOR_LABEL_CONFIGURATION_BLOCK_0)));
141         result.append(createWidgetTableStart());
142         result.append(createDialogRowsHtml(1, 4));
143         result.append(createWidgetTableEnd());
144         result.append(dialogBlockEnd());
145
146         // close widget table
147
result.append(createWidgetTableEnd());
148
149         return result.toString();
150     }
151
152     /**
153      * Creates the list of widgets for this dialog.<p>
154      */

155     protected void defineWidgets() {
156
157         // initialize the object to use for the dialog
158
initLoginMessageObject();
159
160         setKeyPrefix(KEY_PREFIX);
161         
162         // required to read the default values for the optional context parameters for the widgets
163
CmsLoginMessage def = new CmsLoginMessage();
164
165         addWidget(new CmsWidgetDialogParameter(m_loginMessage, "enabled", PAGES[0], new CmsCheckboxWidget()));
166         addWidget(new CmsWidgetDialogParameter(m_loginMessage, "message", PAGES[0], new CmsTextareaWidget()));
167         addWidget(new CmsWidgetDialogParameter(m_loginMessage, "loginForbidden", PAGES[0], new CmsCheckboxWidget()));
168         addWidget(new CmsWidgetDialogParameter(
169             m_loginMessage,
170             "timeStart",
171             String.valueOf(def.getTimeStart()),
172             PAGES[0],
173             new CmsCalendarWidget(),
174             0,
175             1));
176         addWidget(new CmsWidgetDialogParameter(
177             m_loginMessage,
178             "timeEnd",
179             String.valueOf(def.getTimeEnd()),
180             PAGES[0],
181             new CmsCalendarWidget(),
182             0,
183             1));
184     }
185
186     /**
187      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
188      */

189     protected String JavaDoc[] getPageArray() {
190
191         return PAGES;
192     }
193
194     /**
195      * Initializes the login message object for this dialog.<p>
196      */

197     protected void initLoginMessageObject() {
198
199         Object JavaDoc o = getDialogObject();
200
201         if ((o == null) || !(o instanceof CmsLoginMessage)) {
202             o = OpenCms.getLoginManager().getLoginMessage();
203         }
204
205         if (o != null) {
206             m_loginMessage = (CmsLoginMessage)((CmsLoginMessage)o).clone();
207         } else {
208             m_loginMessage = new CmsLoginMessage();
209         }
210     }
211
212     /**
213      * @see org.opencms.workplace.CmsWorkplace#initMessages()
214      */

215     protected void initMessages() {
216
217         // add specific dialog resource bundle
218
addMessages(Messages.get().getBundleName());
219         // add default resource bundles
220
super.initMessages();
221     }
222
223     /**
224      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
225      */

226     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
227
228         // initialize parameters and dialog actions in super implementation
229
super.initWorkplaceRequestValues(settings, request);
230
231         // save the current login message (may be changed because of the widget values)
232
setDialogObject(m_loginMessage);
233     }
234
235 }
Popular Tags