001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsUserRoleDialog.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
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.accounts;
033:
034: import org.opencms.file.CmsUser;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.util.CmsUUID;
037: import org.opencms.widgets.CmsDisplayWidget;
038: import org.opencms.workplace.CmsWidgetDialog;
039: import org.opencms.workplace.CmsWidgetDialogParameter;
040:
041: import javax.servlet.http.HttpServletRequest;
042: import javax.servlet.http.HttpServletResponse;
043: import javax.servlet.jsp.PageContext;
044:
045: /**
046: * Dialog to edit the roles of a user.<p>
047: *
048: * @author Raphael Schnuck
049: *
050: * @version $Revision: 1.4 $
051: *
052: * @since 6.5.6
053: */
054: public class CmsUserRoleDialog extends CmsWidgetDialog {
055:
056: /** localized messages Keys prefix. */
057: public static final String KEY_PREFIX = "user";
058:
059: /** Defines which pages are valid for this dialog. */
060: public static final String[] PAGES = { "page1" };
061:
062: /** The user object that is edited on this dialog. */
063: protected CmsUser m_user;
064:
065: /** Stores the value of the request parameter for the user id. */
066: private String m_paramUserid;
067:
068: /**
069: * Public constructor with JSP action element.<p>
070: *
071: * @param jsp an initialized JSP action element
072: */
073: public CmsUserRoleDialog(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 CmsUserRoleDialog(PageContext context,
086: HttpServletRequest req, HttpServletResponse res) {
087:
088: this (new CmsJspActionElement(context, req, res));
089: }
090:
091: /**
092: * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
093: */
094: public void actionCommit() {
095:
096: // noop
097: }
098:
099: /**
100: * Returns the simple name of the user object.<p>
101: *
102: * @return the simple name of the user object
103: */
104: public String getName() {
105:
106: return m_user.getSimpleName();
107: }
108:
109: /**
110: * Returns the user id parameter value.<p>
111: *
112: * @return the user id parameter value
113: */
114: public String getParamUserid() {
115:
116: return m_paramUserid;
117: }
118:
119: /**
120: * This method is needed only for displaying reasons.<p>
121: *
122: * @param name nothing to do with this parameter
123: */
124: public void setName(String name) {
125:
126: // nothing will be done here, just to avoid warnings
127: name.length();
128: }
129:
130: /**
131: * Sets the user id parameter value.<p>
132: *
133: * @param userId the user id parameter value
134: */
135: public void setParamUserid(String userId) {
136:
137: m_paramUserid = userId;
138: }
139:
140: /**
141: * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
142: *
143: * This overwrites the method from the super class to create a layout variation for the widgets.<p>
144: *
145: * @param dialog the dialog (page) to get the HTML for
146: * @return the dialog HTML for all defined widgets of the named dialog (page)
147: */
148: protected String createDialogHtml(String dialog) {
149:
150: StringBuffer result = new StringBuffer(1024);
151:
152: result.append(createWidgetTableStart());
153: // show error header once if there were validation errors
154: result.append(createWidgetErrorHeader());
155: if (dialog.equals(PAGES[0])) {
156: // create the widgets for the first dialog page
157: result
158: .append(dialogBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_IDENTIFICATION_BLOCK_0)));
159: result.append(createWidgetTableStart());
160: result.append(createDialogRowsHtml(0, 2));
161: result.append(createWidgetTableEnd());
162: result.append(dialogBlockEnd());
163: }
164:
165: result.append(createWidgetTableEnd());
166: return result.toString();
167: }
168:
169: /**
170: * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd()
171: */
172: protected String defaultActionHtmlEnd() {
173:
174: return "";
175: }
176:
177: /**
178: * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
179: */
180: protected void defineWidgets() {
181:
182: // initialize the user object to use for the dialog
183: initUserObject();
184:
185: setKeyPrefix(KEY_PREFIX);
186:
187: // widgets to display
188: addWidget(new CmsWidgetDialogParameter(this , "name", PAGES[0],
189: new CmsDisplayWidget()));
190: addWidget(new CmsWidgetDialogParameter(m_user, "lastname",
191: PAGES[0], new CmsDisplayWidget()));
192: addWidget(new CmsWidgetDialogParameter(m_user, "firstname",
193: PAGES[0], new CmsDisplayWidget()));
194: }
195:
196: /**
197: * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
198: */
199: protected String[] getPageArray() {
200:
201: return PAGES;
202: }
203:
204: /**
205: * Initializes the user object to work with depending on the dialog state and request parameters.<p>
206: */
207: protected void initUserObject() {
208:
209: try {
210: m_user = getCms().readUser(new CmsUUID(getParamUserid()));
211: return;
212: } catch (Exception e) {
213: // noop
214: }
215: }
216:
217: /**
218: * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
219: */
220: protected void validateParamaters() throws Exception {
221:
222: // test the needed parameters
223: getCms().readUser(new CmsUUID(getParamUserid())).getName();
224: }
225: }
|