Source Code Cross Referenced for A_CmsEditGroupDialog.java in  » Content-Management-System » opencms » org » opencms » workplace » tools » accounts » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » org.opencms.workplace.tools.accounts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/A_CmsEditGroupDialog.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:25 $
004:         * Version: $Revision: 1.8 $
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.CmsGroup;
035:        import org.opencms.jsp.CmsJspActionElement;
036:        import org.opencms.main.CmsException;
037:        import org.opencms.main.CmsIllegalArgumentException;
038:        import org.opencms.main.OpenCms;
039:        import org.opencms.security.CmsOrganizationalUnit;
040:        import org.opencms.security.CmsRole;
041:        import org.opencms.security.I_CmsPrincipal;
042:        import org.opencms.util.CmsStringUtil;
043:        import org.opencms.util.CmsUUID;
044:        import org.opencms.widgets.CmsCheckboxWidget;
045:        import org.opencms.widgets.CmsDisplayWidget;
046:        import org.opencms.widgets.CmsGroupWidget;
047:        import org.opencms.widgets.CmsInputWidget;
048:        import org.opencms.widgets.CmsTextareaWidget;
049:        import org.opencms.workplace.CmsDialog;
050:        import org.opencms.workplace.CmsWidgetDialog;
051:        import org.opencms.workplace.CmsWidgetDialogParameter;
052:        import org.opencms.workplace.CmsWorkplaceSettings;
053:        import org.opencms.workplace.tools.CmsToolManager;
054:
055:        import java.util.ArrayList;
056:        import java.util.HashMap;
057:        import java.util.List;
058:        import java.util.Map;
059:
060:        import javax.servlet.http.HttpServletRequest;
061:
062:        /**
063:         * Skeleton dialog to create a new group or edit an existing group in the administration view.<p>
064:         * 
065:         * @author Michael Moossen 
066:         * 
067:         * @version $Revision: 1.8 $ 
068:         * 
069:         * @since 6.0.0 
070:         */
071:        public abstract class A_CmsEditGroupDialog extends CmsWidgetDialog {
072:
073:            /** localized messages Keys prefix. */
074:            public static final String KEY_PREFIX = "group";
075:
076:            /** Defines which pages are valid for this dialog. */
077:            public static final String[] PAGES = { "page1" };
078:
079:            /** Request parameter name for the group id. */
080:            public static final String PARAM_GROUPID = "groupid";
081:
082:            /** Request parameter name for the group name. */
083:            public static final String PARAM_GROUPNAME = "groupname";
084:
085:            /** The user object that is edited on this dialog. */
086:            protected CmsGroup m_group;
087:
088:            /** Stores the value of the request parameter for the group id. */
089:            private String m_paramGroupid;
090:
091:            /** Stores the value of the request parameter for the organizational unit fqn. */
092:            private String m_paramOufqn;
093:
094:            /** Auxiliary Property for better representation of the bean parentId property. */
095:            private String m_parentGroup;
096:
097:            /**
098:             * Public constructor with JSP action element.<p>
099:             * 
100:             * @param jsp an initialized JSP action element
101:             */
102:            public A_CmsEditGroupDialog(CmsJspActionElement jsp) {
103:
104:                super (jsp);
105:            }
106:
107:            /**
108:             * Commits the edited group to the db.<p>
109:             */
110:            public void actionCommit() {
111:
112:                List errors = new ArrayList();
113:
114:                try {
115:                    // if new create it first
116:                    if (m_group.getId() == null) {
117:                        CmsGroup newGroup = getCms()
118:                                .createGroup(
119:                                        m_paramOufqn + m_group.getSimpleName(),
120:                                        m_group.getDescription(),
121:                                        m_group.isEnabled() ? I_CmsPrincipal.FLAG_ENABLED
122:                                                : I_CmsPrincipal.FLAG_DISABLED,
123:                                        getParentGroup());
124:                        newGroup.setProjectManager(m_group.isProjectManager());
125:                        newGroup
126:                                .setProjectCoWorker(m_group.isProjectCoWorker());
127:                        m_group = newGroup;
128:                    } else {
129:                        if (getParentGroup() != null) {
130:                            m_group.setParentId(getCms().readGroup(
131:                                    getParentGroup()).getId());
132:                        } else {
133:                            m_group.setParentId(CmsUUID.getNullUUID());
134:                        }
135:                    }
136:                    // write the edited group
137:                    getCms().writeGroup(m_group);
138:                    // refresh the list
139:                    Map objects = (Map) getSettings().getListObject();
140:                    if (objects != null) {
141:                        objects.remove(getListClass());
142:                        objects.remove(A_CmsUsersList.class.getName());
143:                    }
144:                } catch (Throwable t) {
145:                    errors.add(t);
146:                }
147:
148:                if (errors.isEmpty() && isNewGroup()) {
149:                    if ((getParamCloseLink() != null)
150:                            && (getParamCloseLink().indexOf(
151:                                    "path=" + getListRootPath()) > -1)) {
152:                        // set closelink
153:                        Map argMap = new HashMap();
154:                        argMap.put("groupid", m_group.getId());
155:                        argMap.put("groupname", m_group.getName());
156:                        argMap.put("oufqn", m_paramOufqn);
157:                        setParamCloseLink(CmsToolManager.linkForToolPath(
158:                                getJsp(), getListRootPath() + "/edit", argMap));
159:                    }
160:                }
161:                // set the list of errors to display when saving failed
162:                setCommitErrors(errors);
163:            }
164:
165:            /**
166:             * Returns the description of the parent ou.<p>
167:             * 
168:             * @return the description of the parent ou
169:             */
170:            public String getAssignedOu() {
171:
172:                try {
173:                    return OpenCms.getOrgUnitManager().readOrganizationalUnit(
174:                            getCms(), getParamOufqn()).getDescription(
175:                            getLocale())
176:                            + " ("
177:                            + CmsOrganizationalUnit.SEPARATOR
178:                            + getParamOufqn() + ")";
179:                } catch (CmsException e) {
180:                    return null;
181:                }
182:            }
183:
184:            /**
185:             * Returns the localized description of a group.<p>
186:             * 
187:             * @return the localized description of a group
188:             */
189:            public String getDescription() {
190:
191:                return m_group.getDescription(getLocale());
192:            }
193:
194:            /**
195:             * Returns the simple name of the group object.<p>
196:             * 
197:             * @return the simple name of the group object
198:             */
199:            public String getName() {
200:
201:                return m_group.getSimpleName();
202:            }
203:
204:            /**
205:             * Returns the user id parameter value.<p>
206:             * 
207:             * @return the user id parameter value
208:             */
209:            public String getParamGroupid() {
210:
211:                return m_paramGroupid;
212:            }
213:
214:            /**
215:             * Returns the organizational unit parameter value.<p>
216:             * 
217:             * @return the organizational unit parameter value
218:             */
219:            public String getParamOufqn() {
220:
221:                return m_paramOufqn;
222:            }
223:
224:            /**
225:             * Returns the parent Group name.<p>
226:             *
227:             * @return the parent Group name
228:             */
229:            public String getParentGroup() {
230:
231:                return m_parentGroup;
232:            }
233:
234:            /**
235:             * The method is just needed for displaying reasons.<p>
236:             * 
237:             * @param assignedOu nothing to do with this parameter
238:             */
239:            public void setAssignedOu(String assignedOu) {
240:
241:                // nothing will be done here, just to avoid warnings
242:                assignedOu.length();
243:            }
244:
245:            /**
246:             * Sets the description for a group.<p>
247:             * 
248:             * @param description the description for a group
249:             */
250:            public void setDescription(String description) {
251:
252:                m_group.setDescription(description);
253:            }
254:
255:            /**
256:             * Sets the name of the group object.<p>
257:             * 
258:             * @param name the name of the group object
259:             */
260:            public void setName(String name) {
261:
262:                m_group.setName(name);
263:            }
264:
265:            /**
266:             * Sets the user id parameter value.<p>
267:             * 
268:             * @param userId the user id parameter value
269:             */
270:            public void setParamGroupid(String userId) {
271:
272:                m_paramGroupid = userId;
273:            }
274:
275:            /**
276:             * Sets the organizational unit parameter value.<p>
277:             * 
278:             * @param ouFqn the organizational unit parameter value
279:             */
280:            public void setParamOufqn(String ouFqn) {
281:
282:                if (ouFqn == null) {
283:                    ouFqn = "";
284:                }
285:                m_paramOufqn = ouFqn;
286:            }
287:
288:            /**
289:             * Sets the parent Group name.<p>
290:             *
291:             * @param parentGroup the parent Group name to set
292:             */
293:            public void setParentGroup(String parentGroup) {
294:
295:                if (CmsStringUtil.isEmpty(parentGroup)
296:                        || parentGroup.equals("null")
297:                        || parentGroup.equals("none")) {
298:                    parentGroup = null;
299:                }
300:                if (parentGroup != null) {
301:                    try {
302:                        getCms().readGroup(parentGroup);
303:                    } catch (CmsException e) {
304:                        throw new CmsIllegalArgumentException(e
305:                                .getMessageContainer());
306:                    }
307:                }
308:                m_parentGroup = parentGroup;
309:            }
310:
311:            /**
312:             * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
313:             * 
314:             * This overwrites the method from the super class to create a layout variation for the widgets.<p>
315:             * 
316:             * @param dialog the dialog (page) to get the HTML for
317:             * @return the dialog HTML for all defined widgets of the named dialog (page)
318:             */
319:            protected String createDialogHtml(String dialog) {
320:
321:                StringBuffer result = new StringBuffer(1024);
322:
323:                result.append(createWidgetTableStart());
324:                // show error header once if there were validation errors
325:                result.append(createWidgetErrorHeader());
326:
327:                if (dialog.equals(PAGES[0])) {
328:                    // create the widgets for the first dialog page
329:                    result
330:                            .append(dialogBlockStart(key(Messages.GUI_GROUP_EDITOR_LABEL_IDENTIFICATION_BLOCK_0)));
331:                    result.append(createWidgetTableStart());
332:                    result.append(createDialogRowsHtml(0, 4));
333:                    result.append(createWidgetTableEnd());
334:                    result.append(dialogBlockEnd());
335:                    boolean webuserOu = false;
336:                    try {
337:                        webuserOu = OpenCms.getOrgUnitManager()
338:                                .readOrganizationalUnit(getCms(),
339:                                        getParamOufqn()).hasFlagWebuser();
340:                    } catch (CmsException e) {
341:                        // ignore
342:                    }
343:                    if (!webuserOu) {
344:                        result
345:                                .append(dialogBlockStart(key(Messages.GUI_GROUP_EDITOR_LABEL_FLAGS_BLOCK_0)));
346:                        result.append(createWidgetTableStart());
347:                        result.append(createDialogRowsHtml(5, 6));
348:                        result.append(createWidgetTableEnd());
349:                        result.append(dialogBlockEnd());
350:                    }
351:                }
352:
353:                result.append(createWidgetTableEnd());
354:                return result.toString();
355:            }
356:
357:            /**
358:             * Creates the list of widgets for this dialog.<p>
359:             */
360:            protected void defineWidgets() {
361:
362:                // initialize the user object to use for the dialog
363:                initGroupObject();
364:                boolean webuserOu = false;
365:                try {
366:                    webuserOu = OpenCms.getOrgUnitManager()
367:                            .readOrganizationalUnit(getCms(), getParamOufqn())
368:                            .hasFlagWebuser();
369:                } catch (CmsException e) {
370:                    // ignore
371:                }
372:                setKeyPrefix(KEY_PREFIX);
373:
374:                // widgets to display
375:                if ((m_group.getId() == null) && isEditable(m_group)) {
376:                    addWidget(new CmsWidgetDialogParameter(this , "name",
377:                            PAGES[0], new CmsInputWidget()));
378:                } else {
379:                    addWidget(new CmsWidgetDialogParameter(this , "name",
380:                            PAGES[0], new CmsDisplayWidget()));
381:                }
382:                if (isEditable(m_group)) {
383:                    addWidget(new CmsWidgetDialogParameter(this , "description",
384:                            PAGES[0], new CmsTextareaWidget()));
385:                    addWidget(new CmsWidgetDialogParameter(this , "parentGroup",
386:                            PAGES[0], new CmsGroupWidget(null, null,
387:                                    getParamOufqn())));
388:                    addWidget(new CmsWidgetDialogParameter(this , "assignedOu",
389:                            PAGES[0], new CmsDisplayWidget()));
390:                    addWidget(new CmsWidgetDialogParameter(m_group, "enabled",
391:                            PAGES[0], new CmsCheckboxWidget()));
392:                    if (!webuserOu) {
393:                        addWidget(new CmsWidgetDialogParameter(m_group,
394:                                "projectManager", PAGES[0],
395:                                new CmsCheckboxWidget()));
396:                        addWidget(new CmsWidgetDialogParameter(m_group,
397:                                "projectCoWorker", PAGES[0],
398:                                new CmsCheckboxWidget()));
399:                    }
400:                } else {
401:                    addWidget(new CmsWidgetDialogParameter(this , "description",
402:                            PAGES[0], new CmsDisplayWidget()));
403:                    addWidget(new CmsWidgetDialogParameter(this , "parentGroup",
404:                            PAGES[0], new CmsDisplayWidget()));
405:                    addWidget(new CmsWidgetDialogParameter(this , "assignedOu",
406:                            PAGES[0], new CmsDisplayWidget()));
407:                    addWidget(new CmsWidgetDialogParameter(m_group, "enabled",
408:                            PAGES[0], new CmsDisplayWidget()));
409:                    if (!webuserOu) {
410:                        addWidget(new CmsWidgetDialogParameter(m_group,
411:                                "projectManager", PAGES[0],
412:                                new CmsDisplayWidget()));
413:                        addWidget(new CmsWidgetDialogParameter(m_group,
414:                                "projectCoWorker", PAGES[0],
415:                                new CmsDisplayWidget()));
416:                    }
417:                }
418:            }
419:
420:            /**
421:             * Returns the dialog class name of the list to refresh.<p> 
422:             * 
423:             * @return the list dialog class name
424:             */
425:            protected abstract String getListClass();
426:
427:            /**
428:             * Returns the root path for the list tool.<p>
429:             * 
430:             * @return the root path
431:             */
432:            protected abstract String getListRootPath();
433:
434:            /**
435:             * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
436:             */
437:            protected String[] getPageArray() {
438:
439:                return PAGES;
440:            }
441:
442:            /**
443:             * Initializes the group object to work with depending on the dialog state and request parameters.<p>
444:             * 
445:             * Two initializations of the group object on first dialog call are possible:
446:             * <ul>
447:             * <li>edit an existing group</li>
448:             * <li>create a new group</li>
449:             * <li>view an existing group overview</li>
450:             * <li>view an existing group short info</li>
451:             * </ul>
452:             */
453:            protected void initGroupObject() {
454:
455:                Object o = null;
456:
457:                try {
458:                    if (CmsStringUtil.isEmpty(getParamAction())
459:                            || CmsDialog.DIALOG_INITIAL
460:                                    .equals(getParamAction())) {
461:                        // edit an existing user, get the user object from db
462:                        m_group = getCms().readGroup(
463:                                new CmsUUID(getParamGroupid()));
464:                    } else {
465:                        // this is not the initial call, get the user object from session            
466:                        o = getDialogObject();
467:                        m_group = (CmsGroup) o;
468:                        // test
469:                        m_group.getId();
470:                    }
471:                    if ((m_group.getParentId() != null)
472:                            && !m_group.getParentId().isNullUUID()) {
473:                        setParentGroup(getCms().getParent(m_group.getName())
474:                                .getName());
475:                    }
476:                } catch (Exception e) {
477:                    // create a new user object
478:                    m_group = new CmsGroup();
479:                    setParentGroup(null);
480:                }
481:            }
482:
483:            /**
484:             * @see org.opencms.workplace.CmsWorkplace#initMessages()
485:             */
486:            protected void initMessages() {
487:
488:                // add specific dialog resource bundle
489:                addMessages(Messages.get().getBundleName());
490:                // add default resource bundles
491:                super .initMessages();
492:            }
493:
494:            /**
495:             * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
496:             */
497:            protected void initWorkplaceRequestValues(
498:                    CmsWorkplaceSettings settings, HttpServletRequest request) {
499:
500:                // initialize parameters and dialog actions in super implementation
501:                super .initWorkplaceRequestValues(settings, request);
502:
503:                // save the current state of the group (may be changed because of the widget values)
504:                setDialogObject(m_group);
505:            }
506:
507:            /**
508:             * Tests if the given group is editable or not.<p>
509:             * 
510:             * Not editable means that no property can be changed.<p>
511:             * 
512:             * @param group the group to test 
513:             * 
514:             * @return the editable flag
515:             */
516:            protected abstract boolean isEditable(CmsGroup group);
517:
518:            /**
519:             * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
520:             */
521:            protected void validateParamaters() throws Exception {
522:
523:                OpenCms.getRoleManager().checkRole(getCms(),
524:                        CmsRole.ACCOUNT_MANAGER.forOrgUnit(getParamOufqn()));
525:                if (!isNewGroup()) {
526:                    // test the needed parameters
527:                    getCms().readGroup(new CmsUUID(getParamGroupid()))
528:                            .getName();
529:                }
530:            }
531:
532:            /**
533:             * Checks if the new Group dialog has to be displayed.<p>
534:             * 
535:             * @return <code>true</code> if the new Group dialog has to be displayed
536:             */
537:            private boolean isNewGroup() {
538:
539:                return getCurrentToolPath().equals(getListRootPath() + "/new");
540:            }
541:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.