001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsRoleOverviewDialog.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.jsp.CmsJspActionElement;
035: import org.opencms.main.CmsException;
036: import org.opencms.main.OpenCms;
037: import org.opencms.security.CmsRole;
038: import org.opencms.widgets.CmsDisplayWidget;
039: import org.opencms.workplace.CmsWidgetDialog;
040: import org.opencms.workplace.CmsWidgetDialogParameter;
041:
042: import java.util.Iterator;
043:
044: import javax.servlet.http.HttpServletRequest;
045: import javax.servlet.http.HttpServletResponse;
046: import javax.servlet.jsp.PageContext;
047:
048: /**
049: * The role overview widget dialog.<p>
050: *
051: * @author Raphael Schnuck
052: *
053: * @version $Revision: 1.4 $
054: *
055: * @since 6.5.6
056: */
057: public class CmsRoleOverviewDialog extends CmsWidgetDialog {
058:
059: /** localized messages Keys prefix. */
060: public static final String KEY_PREFIX = "role";
061:
062: /** Defines which pages are valid for this dialog. */
063: public static final String[] PAGES = { "page1" };
064:
065: /** The role object that is viewed on this dialog. */
066: protected CmsRole m_role;
067:
068: /** Stores the value of the request parameter for the organizational unit. */
069: private String m_paramOufqn;
070:
071: /** Stores the value of the request parameter for the role name. */
072: private String m_paramRole;
073:
074: /**
075: * Public constructor with JSP action element.<p>
076: *
077: * @param jsp an initialized JSP action element
078: */
079: public CmsRoleOverviewDialog(CmsJspActionElement jsp) {
080:
081: super (jsp);
082:
083: }
084:
085: /**
086: * Public constructor with JSP variables.<p>
087: *
088: * @param context the JSP page context
089: * @param req the JSP request
090: * @param res the JSP response
091: */
092: public CmsRoleOverviewDialog(PageContext context,
093: HttpServletRequest req, HttpServletResponse res) {
094:
095: this (new CmsJspActionElement(context, req, res));
096: }
097:
098: /**
099: * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
100: */
101: public void actionCommit() {
102:
103: // noop
104: }
105:
106: /**
107: * Returns a String inculding all parent roles of the role object.<p>
108: *
109: * @return a String inculding all parent roles of the role object
110: */
111: public String getDependency() {
112:
113: String dependency = "";
114: CmsRole role = m_role;
115: while (role.getParentRole() != null) {
116: dependency = dependency
117: + role.getParentRole().getName(
118: getCms().getRequestContext().getLocale());
119: role = role.getParentRole();
120: if (role.getParentRole() != null) {
121: dependency = dependency + ", ";
122: }
123: }
124: if (m_role.forOrgUnit(null).equals(CmsRole.WORKPLACE_USER)) {
125: // add all roles as parent of the workplace user role
126: dependency = "";
127: Iterator itWuParents;
128: try {
129: itWuParents = OpenCms.getRoleManager().getRoles(
130: getCms(), getParamOufqn(), false).iterator();
131: } catch (CmsException e) {
132: // should never happen
133: return dependency;
134: }
135: while (itWuParents.hasNext()) {
136: CmsRole wuParent = (CmsRole) itWuParents.next();
137: if (wuParent.forOrgUnit(null).equals(
138: CmsRole.WORKPLACE_USER)) {
139: // skip the wu role itself
140: continue;
141: }
142: String roleName = wuParent.getName(getCms()
143: .getRequestContext().getLocale());
144: if (dependency.length() > 0) {
145: roleName += ", ";
146: }
147: dependency = roleName + dependency;
148: }
149: }
150: return dependency;
151: }
152:
153: /**
154: * Returns the localized description of the role object.<p>
155: *
156: * @return the localized description of the role object
157: */
158: public String getDescription() {
159:
160: return m_role.getDescription(getCms().getRequestContext()
161: .getLocale());
162: }
163:
164: /**
165: * Returns the localized name of the role object.<p>
166: *
167: * @return the localized name of the role object
168: */
169: public String getName() {
170:
171: return m_role.getName(getCms().getRequestContext().getLocale());
172: }
173:
174: /**
175: * Returns the organizational unit parameter value.<p>
176: *
177: * @return the organizational unit parameter value
178: */
179: public String getParamOufqn() {
180:
181: return m_paramOufqn;
182: }
183:
184: /**
185: * Returns the role name parameter value.<p>
186: *
187: * @return the role name parameter value
188: */
189: public String getParamRole() {
190:
191: return m_paramRole;
192: }
193:
194: /**
195: * This method is needed only for displaying reasons.<p>
196: *
197: * @param dependency nothing to do with this parameter
198: */
199: public void setDependency(String dependency) {
200:
201: // nothing will be done here, just to avoid warnings
202: dependency.length();
203: }
204:
205: /**
206: * This method is needed only for displaying reasons.<p>
207: *
208: * @param description nothing to do with this parameter
209: */
210: public void setDescription(String description) {
211:
212: // nothing will be done here, just to avoid warnings
213: description.length();
214: }
215:
216: /**
217: * This method is needed only for displaying reasons.<p>
218: *
219: * @param name nothing to do with this parameter
220: */
221: public void setName(String name) {
222:
223: // nothing will be done here, just to avoid warnings
224: name.length();
225: }
226:
227: /**
228: * Sets the user organizational unit value.<p>
229: *
230: * @param ouFqn the organizational unit parameter value
231: */
232: public void setParamOufqn(String ouFqn) {
233:
234: if (ouFqn == null) {
235: ouFqn = "";
236: }
237: m_paramOufqn = ouFqn;
238: }
239:
240: /**
241: * Sets the role name value.<p>
242: *
243: * @param role the role name parameter value
244: */
245: public void setParamRole(String role) {
246:
247: m_paramRole = role;
248: }
249:
250: /**
251: * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
252: *
253: * This overwrites the method from the super class to create a layout variation for the widgets.<p>
254: *
255: * @param dialog the dialog (page) to get the HTML for
256: * @return the dialog HTML for all defined widgets of the named dialog (page)
257: */
258: protected String createDialogHtml(String dialog) {
259:
260: StringBuffer result = new StringBuffer(1024);
261:
262: // create widget table
263: result.append(createWidgetTableStart());
264:
265: // show error header once if there were validation errors
266: result.append(createWidgetErrorHeader());
267:
268: if (dialog.equals(PAGES[0])) {
269: // create the widgets for the first dialog page
270: result
271: .append(dialogBlockStart(key(Messages.GUI_ROLE_OVERVIEW_LABEL_IDENTIFICATION_BLOCK_0)));
272: result.append(createWidgetTableStart());
273: result.append(createDialogRowsHtml(0, 2));
274: result.append(createWidgetTableEnd());
275: result.append(dialogBlockEnd());
276: }
277:
278: // close widget table
279: result.append(createWidgetTableEnd());
280:
281: return result.toString();
282: }
283:
284: /**
285: * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd()
286: */
287: protected String defaultActionHtmlEnd() {
288:
289: return "";
290: }
291:
292: /**
293: * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
294: */
295: protected void defineWidgets() {
296:
297: // initialize the user object to use for the dialog
298: initRoleObject();
299:
300: setKeyPrefix(KEY_PREFIX);
301:
302: // widgets to display
303: addWidget(new CmsWidgetDialogParameter(this , "name", PAGES[0],
304: new CmsDisplayWidget()));
305: addWidget(new CmsWidgetDialogParameter(this , "dependency",
306: PAGES[0], new CmsDisplayWidget()));
307: addWidget(new CmsWidgetDialogParameter(this , "description",
308: PAGES[0], new CmsDisplayWidget()));
309: }
310:
311: /**
312: * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
313: */
314: protected String[] getPageArray() {
315:
316: return PAGES;
317: }
318:
319: /**
320: * Initializes the group object.<p>
321: */
322: protected void initRoleObject() {
323:
324: try {
325: m_role = CmsRole.valueOf(getCms().readGroup(m_paramRole));
326: } catch (CmsException e) {
327: // noop
328: }
329: }
330:
331: /**
332: * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
333: */
334: protected void validateParamaters() throws Exception {
335:
336: // test the needed parameters
337: OpenCms.getRoleManager().checkRole(getCms(),
338: CmsRole.ACCOUNT_MANAGER.forOrgUnit(getParamOufqn()));
339: CmsRole.valueOf(getCms().readGroup(getParamRole()))
340: .getGroupName();
341: }
342: }
|