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


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/lock/CmsLockFilter.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:46 $
004:         * Version: $Revision: 1.5 $
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.lock;
033:
034:        import org.opencms.file.CmsUser;
035:        import org.opencms.util.CmsUUID;
036:
037:        import java.util.Collections;
038:        import java.util.HashSet;
039:        import java.util.Set;
040:
041:        /**
042:         * A filter to retrieve the locks.<p>
043:         * 
044:         * @author Michael Moossen 
045:         * 
046:         * @version $Revision: 1.5 $ 
047:         * 
048:         * @since 6.5.4 
049:         */
050:        public final class CmsLockFilter implements  Cloneable {
051:
052:            /** To filter all locks. */
053:            public static final CmsLockFilter FILTER_ALL = new CmsLockFilter(
054:                    true).filterIncludeChildren();
055:
056:            /** To filter all inherited locks. */
057:            public static final CmsLockFilter FILTER_INHERITED = new CmsLockFilter(
058:                    true);
059:
060:            /** To filter all non inherited locks. */
061:            public static final CmsLockFilter FILTER_NON_INHERITED = new CmsLockFilter(
062:                    false);
063:
064:            /** If set the filter restricts the result excluding locks owned by the given user. */
065:            private CmsUUID m_notOwnedByUserId = null;
066:
067:            /** If set the filter extends the result to non inherited locks. */
068:            private boolean m_includeChildren = false;
069:
070:            /** If set the filter restricts the result including only locks owned by the given user. */
071:            private CmsUUID m_ownedByUserId = null;
072:
073:            /** If set the filter extends the result to inherited locks. */
074:            private boolean m_includeParents = false;
075:
076:            /** If set the filter restricts the result to the given project. */
077:            private CmsUUID m_projectId = null;
078:
079:            /** If set the filter also matches shared exclusive locks. */
080:            private boolean m_sharedExclusive = false;
081:
082:            /** The types to filter. */
083:            private Set m_types = new HashSet();
084:
085:            /** If set the filter restricts the result excluding locks not lockable by the given user. */
086:            private CmsUser m_notLockableByUser = null;
087:
088:            /** If set the filter restricts the result including only locks lockable by the given user. */
089:            private CmsUser m_lockableByUser = null;
090:
091:            /**
092:             * Private constructor.<p>
093:             * 
094:             * @param inherited if the this lock filter should checks inherited locks or not
095:             */
096:            private CmsLockFilter(boolean inherited) {
097:
098:                m_includeChildren = !inherited;
099:                m_includeParents = inherited;
100:            }
101:
102:            /**
103:             * @see java.lang.Object#clone()
104:             */
105:            public Object clone() {
106:
107:                CmsLockFilter filter = new CmsLockFilter(false);
108:                filter.m_includeChildren = m_includeChildren;
109:                filter.m_includeParents = m_includeParents;
110:                filter.m_types = new HashSet(m_types);
111:                filter.m_ownedByUserId = m_ownedByUserId;
112:                filter.m_notOwnedByUserId = m_notOwnedByUserId;
113:                filter.m_projectId = m_projectId;
114:                filter.m_notLockableByUser = m_notLockableByUser;
115:                filter.m_lockableByUser = m_lockableByUser;
116:                return filter;
117:            }
118:
119:            /**
120:             * Returns an extended filter with the given user restriction.<p>
121:             *
122:             * @param userId the user id to filter
123:             *  
124:             * @return an extended filter with the given user restriction
125:             */
126:            public CmsLockFilter filterNotOwnedByUserId(CmsUUID userId) {
127:
128:                CmsLockFilter filter = (CmsLockFilter) this .clone();
129:                filter.m_notOwnedByUserId = userId;
130:                return filter;
131:            }
132:
133:            /**
134:             * Returns an extended filter with the given user restriction.<p>
135:             *
136:             * @param user the user to filter
137:             *  
138:             * @return an extended filter with the given user restriction
139:             */
140:            public CmsLockFilter filterNotLockableByUser(CmsUser user) {
141:
142:                CmsLockFilter filter = (CmsLockFilter) this .clone();
143:                filter.m_notLockableByUser = user;
144:                return filter;
145:            }
146:
147:            /**
148:             * Returns an extended filter with the given user restriction.<p>
149:             *
150:             * @param user the user to filter
151:             *  
152:             * @return an extended filter with the given user restriction
153:             */
154:            public CmsLockFilter filterLockableByUser(CmsUser user) {
155:
156:                CmsLockFilter filter = (CmsLockFilter) this .clone();
157:                filter.m_lockableByUser = user;
158:                return filter;
159:            }
160:
161:            /**
162:             * Returns an extended filter that will extend the result to the given path and all its children.<p>
163:             * 
164:             * @return an extended filter to search the subresources of the given path
165:             */
166:            public CmsLockFilter filterIncludeChildren() {
167:
168:                CmsLockFilter filter = (CmsLockFilter) this .clone();
169:                filter.m_includeChildren = true;
170:                return filter;
171:            }
172:
173:            /**
174:             * Returns an extended filter with the given user restriction.<p>
175:             *
176:             * @param userId the user id to filter
177:             *  
178:             * @return an extended filter with the given user restriction
179:             */
180:            public CmsLockFilter filterOwnedByUserId(CmsUUID userId) {
181:
182:                CmsLockFilter filter = (CmsLockFilter) this .clone();
183:                filter.m_ownedByUserId = userId;
184:                return filter;
185:            }
186:
187:            /**
188:             * Returns an extended filter that will extend the result to the given path and all its parents.<p>
189:             * 
190:             * @return an extended filter to search the subresources of the given path
191:             */
192:            public CmsLockFilter filterIncludeParents() {
193:
194:                CmsLockFilter filter = (CmsLockFilter) this .clone();
195:                filter.m_includeParents = true;
196:                return filter;
197:            }
198:
199:            /**
200:             * Returns an extended filter with the given project restriction.<p>
201:             * 
202:             * @param projectId the project to filter the locks with
203:             *  
204:             * @return an extended filter with the given project restriction
205:             */
206:            public CmsLockFilter filterProject(CmsUUID projectId) {
207:
208:                CmsLockFilter filter = (CmsLockFilter) this .clone();
209:                filter.m_projectId = projectId;
210:                return filter;
211:            }
212:
213:            /**
214:             * Returns an extended filter that also matches shared exclusive locks (siblings).<p> 
215:             * 
216:             * @return an extended filter that also matches shared exclusive locks
217:             */
218:            public CmsLockFilter filterSharedExclusive() {
219:
220:                CmsLockFilter filter = (CmsLockFilter) this .clone();
221:                filter.m_sharedExclusive = true;
222:                return filter;
223:            }
224:
225:            /**
226:             * Returns an extended filter with the given type restriction.<p>
227:             * 
228:             * @param type the lock type to filter
229:             *  
230:             * @return an extended filter with the given type restriction
231:             */
232:            public CmsLockFilter filterType(CmsLockType type) {
233:
234:                CmsLockFilter filter = (CmsLockFilter) this .clone();
235:                filter.m_types.add(type);
236:                return filter;
237:            }
238:
239:            /**
240:             * Returns the user that has to own the locks.<p>
241:             *
242:             * @return the user that has to own the locks
243:             */
244:            public CmsUUID getOwnedByUserId() {
245:
246:                return m_ownedByUserId;
247:            }
248:
249:            /**
250:             * Returns the user that has not to own the locks.<p>
251:             *
252:             * @return the user that has not to own the locks
253:             */
254:            public CmsUUID getNotOwnedByUserId() {
255:
256:                return m_notOwnedByUserId;
257:            }
258:
259:            /**
260:             * Returns the user that can overwrite the locks.<p>
261:             *
262:             * @return the user that can overwrite the locks
263:             */
264:            public CmsUser getLockableByUserId() {
265:
266:                return m_lockableByUser;
267:            }
268:
269:            /**
270:             * Returns the user that can not overwrite the locks.<p>
271:             *
272:             * @return the user that can not overwrite the locks
273:             */
274:            public CmsUser getNotLockableByUserId() {
275:
276:                return m_notLockableByUser;
277:            }
278:
279:            /**
280:             * Returns the project restriction.<p>
281:             *
282:             * @return the project restriction
283:             */
284:            public CmsUUID getProjectId() {
285:
286:                return m_projectId;
287:            }
288:
289:            /**
290:             * Returns the types to filter.<p>
291:             *
292:             * @return the types to filter
293:             */
294:            public Set getTypes() {
295:
296:                return Collections.unmodifiableSet(m_types);
297:            }
298:
299:            /**
300:             * Returns the include children flag.<p>
301:             * 
302:             * @return if set the filter extends the result to the given path and all its children
303:             */
304:            public boolean isIncludeChildren() {
305:
306:                return m_includeChildren;
307:            }
308:
309:            /**
310:             * Returns the include parents flag.<p>
311:             * 
312:             * @return if set the filter extends the result to the given path and all its parents
313:             */
314:            public boolean isIncludeParent() {
315:
316:                return m_includeParents;
317:            }
318:
319:            /**
320:             * Returns the <code>true</code> if this filter also matches shared exclusive locks.<p>
321:             *
322:             * @return the <code>true</code> if this filter also matches shared exclusive locks
323:             */
324:            public boolean isSharedExclusive() {
325:
326:                return m_sharedExclusive;
327:            }
328:
329:            /**
330:             * Matches the given lock against this filter and the given path.<p>
331:             * 
332:             * @param rootPath the path to match the lock against
333:             * @param lock the lock to match
334:             * 
335:             * @return <code>true</code> if the given lock matches
336:             */
337:            public boolean match(String rootPath, CmsLock lock) {
338:
339:                boolean match = false;
340:                if (m_includeChildren) {
341:                    // safe since rootPath always ends with slash if a folder
342:                    match = lock.getResourceName().startsWith(rootPath);
343:                }
344:                if (!match && m_includeParents) {
345:                    // since parents can only be folders, check it only for folders
346:                    if (lock.getResourceName().endsWith("/")) {
347:                        match = rootPath.startsWith(lock.getResourceName());
348:                    }
349:                }
350:                if (match && (m_projectId != null) && !m_projectId.isNullUUID()
351:                        && (lock.getProjectId() != null)) {
352:                    match = lock.getProjectId().equals(m_projectId);
353:                }
354:                if (match && (m_ownedByUserId != null)
355:                        && !m_ownedByUserId.isNullUUID()) {
356:                    match = lock.getUserId().equals(m_ownedByUserId);
357:                }
358:                if (match && (m_notOwnedByUserId != null)
359:                        && !m_notOwnedByUserId.isNullUUID()) {
360:                    match = !lock.getUserId().equals(m_notOwnedByUserId);
361:                }
362:                if (match && (m_lockableByUser != null)) {
363:                    match = lock.isLockableBy(m_lockableByUser);
364:                }
365:                if (match && (m_notLockableByUser != null)) {
366:                    match = !lock.isLockableBy(m_notLockableByUser);
367:                }
368:                if (match && !m_types.isEmpty()) {
369:                    match = m_types.contains(lock.getType());
370:                    match = match || (m_includeParents && lock.isInherited());
371:                }
372:                // check the related lock if available
373:                if (!match && !lock.getRelatedLock().isNullLock()) {
374:                    match = match(rootPath, lock.getRelatedLock());
375:                }
376:                return match;
377:            }
378:
379:            /**
380:             * @see java.lang.Object#toString()
381:             */
382:            public String toString() {
383:
384:                StringBuffer str = new StringBuffer(128);
385:                str.append("[");
386:                str.append("children").append("=").append(m_includeChildren)
387:                        .append(", ");
388:                str.append("parents").append("=").append(m_includeParents)
389:                        .append(", ");
390:                str.append("types").append("=").append(m_types).append(", ");
391:                str.append("includedUser").append("=").append(m_ownedByUserId)
392:                        .append(", ");
393:                str.append("excludedUser").append("=").append(
394:                        m_notOwnedByUserId).append(", ");
395:                str.append("project").append("=").append(m_projectId).append(
396:                        ", ");
397:                str.append("lockableBy").append("=").append(m_lockableByUser)
398:                        .append(", ");
399:                str.append("notLockableBy").append("=").append(
400:                        m_notLockableByUser).append(", ");
401:                str.append("includeShared").append("=").append(
402:                        m_sharedExclusive);
403:                str.append("]");
404:                return str.toString();
405:            }
406:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.