KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > accounts > CmsUserOverviewDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsUserOverviewDialog.java,v $
3  * Date : $Date: 2006/03/27 14:52:49 $
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.accounts;
33
34 import org.opencms.file.CmsUser;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.util.CmsUUID;
38 import org.opencms.widgets.CmsDisplayWidget;
39 import org.opencms.workplace.CmsWidgetDialog;
40 import org.opencms.workplace.CmsWidgetDialogParameter;
41 import org.opencms.workplace.list.CmsListDateMacroFormatter;
42 import org.opencms.workplace.list.I_CmsListFormatter;
43
44 import java.util.ArrayList JavaDoc;
45 import java.util.Date JavaDoc;
46
47 import javax.servlet.http.HttpServletRequest JavaDoc;
48 import javax.servlet.http.HttpServletResponse JavaDoc;
49 import javax.servlet.jsp.PageContext JavaDoc;
50
51 /**
52  * Dialog to edit new or existing user in the administration view.<p>
53  *
54  * @author Michael Moossen
55  *
56  * @version $Revision: 1.12 $
57  *
58  * @since 6.0.0
59  */

60 public class CmsUserOverviewDialog extends CmsWidgetDialog {
61
62     /** localized messages Keys prefix. */
63     public static final String JavaDoc KEY_PREFIX = "user.ov";
64
65     /** Defines which pages are valid for this dialog. */
66     public static final String JavaDoc[] PAGES = {"page1"};
67
68     /** Request parameter name for the user id. */
69     public static final String JavaDoc PARAM_USERID = "userid";
70
71     /** Formatter for the last login property. */
72     private static final I_CmsListFormatter LAST_LOGIN_FORMATTER = CmsListDateMacroFormatter.getDefaultDateFormatter();
73
74     /** The user object that is edited on this dialog. */
75     protected CmsUser m_user;
76
77     /** Stores the value of the request parameter for the user id. */
78     private String JavaDoc m_paramUserid;
79
80     /**
81      * Public constructor with JSP action element.<p>
82      *
83      * @param jsp an initialized JSP action element
84      */

85     public CmsUserOverviewDialog(CmsJspActionElement jsp) {
86
87         super(jsp);
88     }
89
90     /**
91      * Public constructor with JSP variables.<p>
92      *
93      * @param context the JSP page context
94      * @param req the JSP request
95      * @param res the JSP response
96      */

97     public CmsUserOverviewDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
98
99         this(new CmsJspActionElement(context, req, res));
100     }
101
102     /**
103      * Commits the edited user to the db.<p>
104      */

105     public void actionCommit() {
106
107         // no saving is done
108
setCommitErrors(new ArrayList JavaDoc());
109     }
110
111     /**
112      * Returns the last login.<p>
113      *
114      * Auxiliary Property for better representation of the bean parentId property.<p>
115      *
116      * @return the last login
117      */

118     public String JavaDoc getLastlogin() {
119
120         return LAST_LOGIN_FORMATTER.format(new Date JavaDoc(m_user.getLastlogin()), getLocale());
121     }
122
123     /**
124      * Returns the user id parameter value.<p>
125      *
126      * @return the user id parameter value
127      */

128     public String JavaDoc getParamUserid() {
129
130         return m_paramUserid;
131     }
132
133     /**
134      * Sets the last login.<p>
135      *
136      * Auxiliary Property for better representation of the bean parentId property.<p>
137      *
138      * @param lastlogin the last login to set
139      */

140     public void setLastlogin(String JavaDoc lastlogin) {
141
142         // never used
143
lastlogin.length();
144     }
145
146     /**
147      * Sets the user id parameter value.<p>
148      *
149      * @param userId the user id parameter value
150      */

151     public void setParamUserid(String JavaDoc userId) {
152
153         m_paramUserid = userId;
154     }
155
156     /**
157      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
158      *
159      * This overwrites the method from the super class to create a layout variation for the widgets.<p>
160      *
161      * @param dialog the dialog (page) to get the HTML for
162      * @return the dialog HTML for all defined widgets of the named dialog (page)
163      */

164     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
165
166         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
167
168         result.append(createWidgetTableStart());
169         // show error header once if there were validation errors
170
result.append(createWidgetErrorHeader());
171
172         int n = (!isOverview() ? 2 : 4);
173         if (dialog.equals(PAGES[0])) {
174             // create the widgets for the first dialog page
175
result.append(dialogBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_IDENTIFICATION_BLOCK_0)));
176             result.append(createWidgetTableStart());
177             result.append(createDialogRowsHtml(0, n));
178             result.append(createWidgetTableEnd());
179             result.append(dialogBlockEnd());
180             if (!isOverview()) {
181                 result.append(createWidgetTableEnd());
182                 return result.toString();
183             }
184             result.append(dialogBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_ADDRESS_BLOCK_0)));
185             result.append(createWidgetTableStart());
186             result.append(createDialogRowsHtml(5, 8));
187             result.append(createWidgetTableEnd());
188             result.append(dialogBlockEnd());
189             result.append(dialogBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_AUTHENTIFICATION_BLOCK_0)));
190             result.append(createWidgetTableStart());
191             result.append(createDialogRowsHtml(9, 10));
192             result.append(createWidgetTableEnd());
193             result.append(dialogBlockEnd());
194         }
195
196         result.append(createWidgetTableEnd());
197         return result.toString();
198     }
199
200     /**
201      * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd()
202      */

203     protected String JavaDoc defaultActionHtmlEnd() {
204
205         return "";
206     }
207
208     /**
209      * Creates the list of widgets for this dialog.<p>
210      */

211     protected void defineWidgets() {
212
213         // initialize the user object to use for the dialog
214
initUserObject();
215
216         setKeyPrefix(KEY_PREFIX);
217
218         // widgets to display
219
if (isOverview()) {
220             addWidget(new CmsWidgetDialogParameter(m_user, "name", PAGES[0], new CmsDisplayWidget()));
221             addWidget(new CmsWidgetDialogParameter(m_user, "description", PAGES[0], new CmsDisplayWidget()));
222             addWidget(new CmsWidgetDialogParameter(m_user, "lastname", PAGES[0], new CmsDisplayWidget()));
223             addWidget(new CmsWidgetDialogParameter(m_user, "firstname", PAGES[0], new CmsDisplayWidget()));
224             addWidget(new CmsWidgetDialogParameter(m_user, "email", PAGES[0], new CmsDisplayWidget()));
225             addWidget(new CmsWidgetDialogParameter(m_user, "address", PAGES[0], new CmsDisplayWidget()));
226             addWidget(new CmsWidgetDialogParameter(m_user, "zipcode", PAGES[0], new CmsDisplayWidget()));
227             addWidget(new CmsWidgetDialogParameter(m_user, "city", PAGES[0], new CmsDisplayWidget()));
228             addWidget(new CmsWidgetDialogParameter(m_user, "country", PAGES[0], new CmsDisplayWidget()));
229             addWidget(new CmsWidgetDialogParameter(m_user, "enabled", PAGES[0], new CmsDisplayWidget()));
230             addWidget(new CmsWidgetDialogParameter(this, "lastlogin", PAGES[0], new CmsDisplayWidget()));
231         } else {
232             addWidget(new CmsWidgetDialogParameter(m_user, "name", PAGES[0], new CmsDisplayWidget()));
233             addWidget(new CmsWidgetDialogParameter(m_user, "lastname", PAGES[0], new CmsDisplayWidget()));
234             addWidget(new CmsWidgetDialogParameter(m_user, "firstname", PAGES[0], new CmsDisplayWidget()));
235         }
236     }
237
238     /**
239      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
240      */

241     protected String JavaDoc[] getPageArray() {
242
243         return PAGES;
244     }
245
246     /**
247      * @see org.opencms.workplace.CmsWorkplace#initMessages()
248      */

249     protected void initMessages() {
250
251         // add specific dialog resource bundle
252
addMessages(Messages.get().getBundleName());
253         // add default resource bundles
254
super.initMessages();
255     }
256
257     /**
258      * Initializes the user object.<p>
259      */

260     protected void initUserObject() {
261
262         try {
263             // edit an existing user, get the user object from db
264
m_user = getCms().readUser(new CmsUUID(getParamUserid()));
265         } catch (CmsException e) {
266             // should never happen
267
}
268     }
269
270     /**
271      * Overridden to set a custom online help path. <p>
272      *
273      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement)
274      */

275     protected void initWorkplaceMembers(CmsJspActionElement jsp) {
276
277         super.initWorkplaceMembers(jsp);
278         setOnlineHelpUriCustom("/accounts/users/overview/");
279     }
280
281     /**
282      * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
283      */

284     protected void validateParamaters() throws Exception JavaDoc {
285
286         // test the needed parameters
287
getCms().readUser(new CmsUUID(getParamUserid())).getName();
288     }
289
290     /**
291      * Checks if the User overview has to be displayed.<p>
292      *
293      * @return <code>true</code> if the user overview has to be displayed
294      */

295     private boolean isOverview() {
296
297         return getCurrentToolPath().endsWith("/users/edit");
298     }
299 }
Popular Tags