Source Code Cross Referenced for CmsOrganizationalUnit.java in  » Content-Management-System » opencms » org » opencms » security » 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.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/security/CmsOrganizationalUnit.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:29 $
004:         * Version: $Revision: 1.9 $
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.security;
033:
034:        import org.opencms.main.CmsIllegalArgumentException;
035:        import org.opencms.util.CmsMacroResolver;
036:        import org.opencms.util.CmsStringUtil;
037:        import org.opencms.util.CmsUUID;
038:
039:        import java.util.Locale;
040:
041:        /**
042:         * An organizational unit in OpenCms.<p>
043:         *
044:         * Be sure the flags does not conflict with the flags defined in {@link org.opencms.file.CmsResource}.<p>
045:         *
046:         * @author Michael Moossen 
047:         * 
048:         * @version $Revision: 1.9 $
049:         * 
050:         * @since 6.5.6 
051:         */
052:        public class CmsOrganizationalUnit {
053:
054:            /** The flag constant to hide the organizational units from the login form. */
055:            public static final int FLAG_HIDE_LOGIN = 1;
056:
057:            /** The flag constant to mark the organizational units as containing only webusers. */
058:            public static final int FLAG_WEBUSERS = 8;
059:
060:            /** The character used to separate each level in a fully qualified name. */
061:            public static final String SEPARATOR = "/";
062:
063:            /** The description of this organizational unit. */
064:            private String m_description;
065:
066:            /** The flags of this organizational unit. */
067:            private int m_flags;
068:
069:            /** The unique id of this organizational unit. */
070:            private final CmsUUID m_id;
071:
072:            /** The fully qualified name of this organizational unit. */
073:            private final String m_name;
074:
075:            /** The id of the related default project. */
076:            private final CmsUUID m_projectId;
077:
078:            /**
079:             * Creates a new OpenCms organizational unit principal.
080:             * 
081:             * @param id the unique id of the organizational unit
082:             * @param fqn the fully qualified name of the this organizational unit (should end with slash)
083:             * @param description the description of the organizational unit
084:             * @param flags the flags of the organizational unit
085:             * @param projectId the id of the related default project
086:             */
087:            public CmsOrganizationalUnit(CmsUUID id, String fqn,
088:                    String description, int flags, CmsUUID projectId) {
089:
090:                m_id = id;
091:                m_name = fqn;
092:                m_description = description;
093:                m_flags = flags;
094:                m_projectId = projectId;
095:            }
096:
097:            /**
098:             * Returns the parent fully qualified name.<p>
099:             * 
100:             * This is <code>null</code> for the root ou, and 
101:             * the empty string for first level ous.<p>
102:             * 
103:             * @param fqn the fully qualified name to get the parent from
104:             * 
105:             * @return the parent fully qualified name
106:             */
107:            public static final String getParentFqn(String fqn) {
108:
109:                if (CmsStringUtil.isEmptyOrWhitespaceOnly(fqn)) {
110:                    // in case of the root ou
111:                    return null;
112:                }
113:                int pos;
114:                if (fqn.endsWith(CmsOrganizationalUnit.SEPARATOR)) {
115:                    pos = fqn.substring(0, fqn.length() - 1).lastIndexOf(
116:                            CmsOrganizationalUnit.SEPARATOR);
117:                } else {
118:                    pos = fqn.lastIndexOf(CmsOrganizationalUnit.SEPARATOR);
119:                }
120:                if (pos <= 0) {
121:                    // in case of simple names assume root ou
122:                    return "";
123:                }
124:                return fqn.substring(0, pos + 1);
125:            }
126:
127:            /**
128:             * Returns the last name of the given fully qualified name.<p>
129:             * 
130:             * @param fqn the fully qualified name to get the last name from
131:             * 
132:             * @return the last name of the given fully qualified name
133:             */
134:            public static final String getSimpleName(String fqn) {
135:
136:                String parentFqn = getParentFqn(fqn);
137:                if (parentFqn != null) {
138:                    fqn = fqn.substring(parentFqn.length());
139:                }
140:                if ((fqn != null)
141:                        && fqn.startsWith(CmsOrganizationalUnit.SEPARATOR)) {
142:                    fqn = fqn.substring(CmsOrganizationalUnit.SEPARATOR
143:                            .length());
144:                }
145:                return fqn;
146:            }
147:
148:            /**
149:             * Returns the given fully qualified name without leading separator.<p> 
150:             * 
151:             * @param fqn the fully qualified name to fix
152:             * 
153:             * @return the given fully qualified name without leading separator
154:             */
155:            public static String removeLeadingSeparator(String fqn) {
156:
157:                if ((fqn != null)
158:                        && fqn.startsWith(CmsOrganizationalUnit.SEPARATOR)) {
159:                    return fqn.substring(1);
160:                }
161:                return fqn;
162:            }
163:
164:            /**
165:             * Adds the given flag to the flags for this organizational unit.<p>
166:             * 
167:             * @param flag the flag to add
168:             */
169:            public void addFlag(int flag) {
170:
171:                m_flags = (m_flags ^ flag);
172:            }
173:
174:            /**
175:             * @see java.lang.Object#clone()
176:             */
177:            public Object clone() {
178:
179:                return new CmsOrganizationalUnit(m_id, m_name, m_description,
180:                        m_flags, m_projectId);
181:            }
182:
183:            /**
184:             * @see java.lang.Object#equals(java.lang.Object)
185:             */
186:            public boolean equals(Object obj) {
187:
188:                if (obj == this ) {
189:                    return true;
190:                }
191:                if (obj instanceof  CmsOrganizationalUnit) {
192:                    if (m_id != null) {
193:                        return m_id.equals(((CmsOrganizationalUnit) obj)
194:                                .getId());
195:                    }
196:                }
197:                return false;
198:            }
199:
200:            /**
201:             * Returns the description of this organizational unit.<p>
202:             *
203:             * This could return also just a macro, so please use the 
204:             * {@link #getDescription(Locale)} method.<p>
205:             *
206:             * @return the description of this organizational unit
207:             */
208:            public String getDescription() {
209:
210:                return m_description;
211:            }
212:
213:            /**
214:             * Returns the description of this organizational unit.<p>
215:             *
216:             * @param locale the locale
217:             *
218:             * @return the description of this organizational unit
219:             */
220:            public String getDescription(Locale locale) {
221:
222:                CmsMacroResolver macroResolver = new CmsMacroResolver();
223:                macroResolver.setMessages(org.opencms.db.generic.Messages.get()
224:                        .getBundle(locale));
225:                return macroResolver.resolveMacros(m_description);
226:            }
227:
228:            /**
229:             * Returns the display name for this organizational unit.<p>
230:             * 
231:             * @param locale the locale
232:             * 
233:             * @return the display name for this organizational unit
234:             */
235:            public String getDisplayName(Locale locale) {
236:
237:                if (getParentFqn() == null) {
238:                    // for the root ou
239:                    return getDescription(locale);
240:                }
241:                return Messages.get().getBundle(locale).key(
242:                        Messages.GUI_ORGUNIT_DISPLAY_NAME_2,
243:                        getDescription(locale),
244:                        CmsOrganizationalUnit.SEPARATOR + getName());
245:            }
246:
247:            /**
248:             * Returns the flags of this organizational unit.<p>
249:             *
250:             * The organizational unit flags are used to store special information about the 
251:             * organizational unit state encoded bitwise. Usually the flags int value should not 
252:             * be directly accessed. <p>
253:             * 
254:             * @return the flags of this organizational unit
255:             */
256:            public int getFlags() {
257:
258:                return m_flags;
259:            }
260:
261:            /**
262:             * Returns the id of this organizational unit.
263:             *
264:             * @return the id of this organizational unit.
265:             */
266:            public CmsUUID getId() {
267:
268:                return m_id;
269:            }
270:
271:            /**
272:             * Returns the fully qualified name of this organizational unit.<p>
273:             * 
274:             * @return the fully qualified name of this organizational unit
275:             */
276:            public String getName() {
277:
278:                return m_name;
279:            }
280:
281:            /**
282:             * Returns the full qualified name of the parent organizational unit of this organizational unit.<p>
283:             * 
284:             * This is <code>null</code> for the root ou, and the empty string for first level ous.<p>
285:             * 
286:             * @return the full qualified name of the parent organizational unit of this organizational unit
287:             */
288:            public String getParentFqn() {
289:
290:                return getParentFqn(m_name);
291:            }
292:
293:            /**
294:             * Returns the id of the related default project.<p>
295:             *
296:             * @return the id of the related default project
297:             */
298:            public CmsUUID getProjectId() {
299:
300:                return m_projectId;
301:            }
302:
303:            /**
304:             * Returns the simple name of this organizational unit.
305:             *
306:             * @return the simple name of this organizational unit.
307:             */
308:            public String getSimpleName() {
309:
310:                return getSimpleName(m_name);
311:            }
312:
313:            /**
314:             * Checks if this organizational unit has the given flag set.<p>
315:             * 
316:             * @param flag the flag to check
317:             * 
318:             * @return <code>true</code> if this organizational unit has the given flag set
319:             */
320:            public boolean hasFlag(int flag) {
321:
322:                return (m_flags & flag) == flag;
323:            }
324:
325:            /**
326:             * Checks if this organizational unit has the "hide from login form" flag set.<p>
327:             * 
328:             * @return <code>true</code> if this organizational unit has the "hide from login form" flag set
329:             */
330:            public boolean hasFlagHideLogin() {
331:
332:                return hasFlag(FLAG_HIDE_LOGIN);
333:            }
334:
335:            /**
336:             * Checks if this organizational unit has the "webusers" flag set.<p>
337:             * 
338:             * @return <code>true</code> if this organizational unit has the "webusers" flag set
339:             */
340:            public boolean hasFlagWebuser() {
341:
342:                return hasFlag(FLAG_WEBUSERS);
343:            }
344:
345:            /**
346:             * @see java.lang.Object#hashCode()
347:             */
348:            public int hashCode() {
349:
350:                if (m_id != null) {
351:                    return m_id.hashCode();
352:                }
353:                return CmsUUID.getNullUUID().hashCode();
354:            }
355:
356:            /**
357:             * Sets the description of this organizational unit.<p>
358:             * 
359:             * @param description the principal organizational unit to set
360:             */
361:            public void setDescription(String description) {
362:
363:                if (CmsStringUtil.isEmptyOrWhitespaceOnly(description)) {
364:                    throw new CmsIllegalArgumentException(
365:                            org.opencms.db.Messages
366:                                    .get()
367:                                    .container(
368:                                            org.opencms.db.Messages.ERR_BAD_OU_DESCRIPTION_EMPTY_0));
369:                }
370:
371:                m_description = description;
372:            }
373:
374:            /**
375:             * Sets the "hide from login form" flag.<p>
376:             */
377:            public void setFlagHideLogin() {
378:
379:                addFlag(FLAG_HIDE_LOGIN);
380:            }
381:
382:            /**
383:             * Sets this organizational unit flags to the specified value.<p>
384:             *
385:             * The organizational unit flags are used to store special information about the 
386:             * organizational units state encoded bitwise. Usually the flags int value should not 
387:             * be directly accessed. <p>
388:             *
389:             * @param value the value to set this organizational units flags to
390:             */
391:            public void setFlags(int value) {
392:
393:                m_flags = value;
394:            }
395:
396:            /**
397:             * Sets the "webusers" flag.<p>
398:             */
399:            public void setFlagWebusers() {
400:
401:                addFlag(FLAG_WEBUSERS);
402:            }
403:
404:            /**
405:             * @see java.lang.Object#toString()
406:             */
407:            public String toString() {
408:
409:                StringBuffer result = new StringBuffer();
410:                result.append("[Organizational Unit]");
411:                result.append(" fqn:");
412:                result.append(getName());
413:                result.append(" id:");
414:                result.append(m_id);
415:                result.append(" description:");
416:                result.append(m_description);
417:                return result.toString();
418:            }
419:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.