KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > file > CmsResourceFilter


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/CmsResourceFilter.java,v $
3  * Date : $Date: 2006/09/21 09:34:47 $
4  * Version: $Revision: 1.24 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.file;
33
34 /**
35  * Provides filters for resource result sets obtained from requests to the OpenCms VFS.<p>
36  *
37  * Using the constant filters provided by this class
38  * you can control "special" behaviour
39  * of access to the VFS. For example, in the "Offline" project
40  * there can be deleted files, by using this filter you can control
41  * if deleted files should be included in a result set or not.<p>
42  *
43  * @author Michael Emmerich
44  * @author Alexander Kandzior
45  * @author Carsten Weinholz
46  * @author Jan Baudisch
47  *
48  * @version $Revision: 1.24 $
49  *
50  * @since 6.0.0
51  */

52 public final class CmsResourceFilter {
53
54     /**
55      * Filter to display all resources.<p>
56      *
57      * This filter uses the following rules:
58      * <ul>
59      * <li>Includes: Resources marked as deleted.</li>
60      * <li>Includes: Resources outside the 'time window' set with release and expiration date.</li>
61      * <li>Includes: Resources marked as 'invisible' using permissions.</li>
62      * </ul>
63      */

64     public static final CmsResourceFilter ALL = new CmsResourceFilter();
65
66     /**
67      * Filter to display all modified (new/changed/deleted) resources.<p>
68      */

69     public static final CmsResourceFilter ALL_MODIFIED = ALL.addExcludeState(CmsResource.STATE_UNCHANGED);
70
71     /**
72      * Default filter to display resources for the online project.<p>
73      *
74      * This filter uses the following rules:
75      * <ul>
76      * <li>Excludes: Resources marked as deleted.</li>
77      * <li>Excludes: Resources outside the 'time window' set with release and expiration date.</li>
78      * <li>Includes: Resources marked as 'invisible' using permissions.</li>
79      * </ul>
80      */

81     public static final CmsResourceFilter DEFAULT = ALL.addExcludeState(CmsResource.STATE_DELETED).addRequireTimerange();
82
83     /**
84      * Default filter to display files for the online project.<p>
85      */

86     public static final CmsResourceFilter DEFAULT_FILES = DEFAULT.addRequireFile();
87
88     /**
89      * Default filter to display folders for the online project.<p>
90      */

91     public static final CmsResourceFilter DEFAULT_FOLDERS = DEFAULT.addRequireFolder();
92
93     /**
94      * Filter to display resources ignoring the release and expiration dates.<p>
95      *
96      * This filter uses the following rules:
97      * <ul>
98      * <li>Excludes: Resources marked as deleted.</li>
99      * <li>Includes: Resources outside the 'time window' set with release and expiration date.</li>
100      * <li>Includes: Resources marked as 'invisible' using permissions.</li>
101      * </ul>
102      */

103     public static final CmsResourceFilter IGNORE_EXPIRATION = ALL.addExcludeState(CmsResource.STATE_DELETED);
104
105     /**
106      * Filter to display only visible resources.<p>
107      *
108      * This filter used the following rules:
109      * <ul>
110      * <li>Includes: Resources marked as deleted.</li>
111      * <li>Includes: Resources outside the 'time window' set with release and expiration date.</li>
112      * <li>Excludes: Resources marked as 'invisible' using permissions.</li>
113      * </ul>
114      */

115     public static final CmsResourceFilter ONLY_VISIBLE = ALL.addRequireVisible();
116
117     /**
118      * Filter to display only visible and not deleted resources.<p>
119      *
120      * This filter used the following rules:
121      * <ul>
122      * <li>Excludes: Resources marked as deleted.</li>
123      * <li>Includes: Resources outside the 'time window' set with release and expiration date.</li>
124      * <li>Excludes: Resources marked as 'invisible' using permissions.</li>
125      * </ul>
126      */

127     public static final CmsResourceFilter ONLY_VISIBLE_NO_DELETED = ONLY_VISIBLE.addExcludeState(CmsResource.STATE_DELETED);
128
129     private static final int EXCLUDED = 2;
130
131     private static final int IGNORED = 0;
132
133     private static final int REQUIRED = 1;
134
135     /** The cache id for this filter. */
136     private String JavaDoc m_cacheId;
137
138     /** The required start date for the timerange of the expire date. */
139     private long m_expireAfter;
140
141     /** The required end data for the timerange of the expire date. */
142     private long m_expireBefore;
143
144     /** Indicates if the expire date is used (true) or ignored (false). */
145     private boolean m_filterExpire;
146
147     /** Indicates if the resource flag is filtered (true) or not (false). */
148     private int m_filterFlags;
149
150     /** Indicates if the date of the last modification is used (true) or ignored (false). */
151     private boolean m_filterLastModified;
152
153     /** Indicates if the release date is used (true) or ignored (false). */
154     private boolean m_filterRelease;
155
156     /** Indicates if the resource state (unchanged/new/deleted/modified) is filtered (true) or not (false). */
157     private int m_filterState;
158
159     /** Indicates if the resource valid timerage is used (true) or ignored (false). */
160     private boolean m_filterTimerange;
161
162     /** Indicates if the resource type is filtered (true) or not (false). */
163     private int m_filterType;
164
165     /** Indicates if the visible permission is used (true) or ignored (false). */
166     private boolean m_filterVisible;
167
168     /** The required/excluded flags for filtering resources. */
169     private int m_flags;
170
171     /** The required start date for the timerange of the last modification date. */
172     private long m_modifiedAfter;
173
174     /** The required end data for the timerange of the last modification date. */
175     private long m_modifiedBefore;
176
177     /** Indicates if the filter should return only folders. */
178     private Boolean JavaDoc m_onlyFolders;
179
180     /** The required start date for the timerange of the release date. */
181     private long m_releaseAfter;
182
183     /** The required end data for the timerange of the release date. */
184     private long m_releaseBefore;
185
186     /** The required/excluded state for filtering resources. */
187     private int m_state;
188
189     /** The required/excluded type for filtering resources. */
190     private int m_type;
191
192     /**
193      * Hides the public contructor.<p>
194      */

195     private CmsResourceFilter() {
196
197         m_filterState = IGNORED;
198         m_state = -1;
199
200         m_filterType = IGNORED;
201         m_type = -1;
202
203         m_filterFlags = IGNORED;
204         m_flags = -1;
205
206         m_filterVisible = false;
207
208         m_filterTimerange = false;
209         m_filterLastModified = false;
210         m_filterRelease = false;
211         m_filterExpire = false;
212         m_modifiedAfter = 0L;
213         m_modifiedBefore = 0L;
214         m_releaseAfter = 0L;
215         m_releaseBefore = 0L;
216         m_expireAfter = 0L;
217         m_expireBefore = 0L;
218
219         updateCacheId();
220     }
221
222     /**
223      * Returns a new CmsResourceFilter requiring the given type.<p>
224      *
225      * @param type the required resource type
226      * @return a filter requiring the given type
227      */

228     public static CmsResourceFilter requireType(int type) {
229
230         return new CmsResourceFilter().addRequireType(type);
231     }
232
233     /**
234      * Returns an extended filter in order to avoid the given flags in the filtered resources.<p>
235      *
236      * @param flags the resource flags to exclude
237      * @return a filter excluding the given resource flags
238      */

239     public CmsResourceFilter addExcludeFlags(int flags) {
240
241         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
242
243         extendedFilter.m_flags = flags;
244         extendedFilter.m_filterFlags = EXCLUDED;
245         extendedFilter.updateCacheId();
246
247         return extendedFilter;
248     }
249
250     /**
251      * Returns an extended filter in order to avoid the given type in the filtered resources.<p>
252      *
253      * @param state the resource state to exclude
254      * @return a filter excluding the given resource state
255      */

256     public CmsResourceFilter addExcludeState(int state) {
257
258         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
259
260         extendedFilter.m_state = state;
261         extendedFilter.m_filterState = EXCLUDED;
262         extendedFilter.updateCacheId();
263
264         return extendedFilter;
265     }
266
267     /**
268      * Returns an extended filter to guarantee all filtered resources ignoring the time range (released and not expired) window.<p>
269      *
270      * This is the reverse of {@link #addRequireTimerange()}.<p>
271      *
272      * @return a filter excluding invalid resources
273      */

274     public CmsResourceFilter addExcludeTimerange() {
275
276         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
277
278         extendedFilter.m_filterTimerange = false;
279         extendedFilter.updateCacheId();
280
281         return extendedFilter;
282     }
283
284     /**
285      * Returns an extended filter in order to avoid the given type in the filtered resources.<p>
286      *
287      * @param type the resource type to exclude
288      * @return a filter excluding the given resource type
289      */

290     public CmsResourceFilter addExcludeType(int type) {
291
292         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
293
294         extendedFilter.m_type = type;
295         extendedFilter.m_filterType = EXCLUDED;
296         extendedFilter.updateCacheId();
297
298         return extendedFilter;
299     }
300
301     /**
302      * Returns an extended filter to restrict the results to resources that expire in the given timerange.<p>
303      *
304      * @param time the required time
305      * @return a filter to restrict the results to resources that expire in the given timerange
306      */

307     public CmsResourceFilter addRequireExpireAfter(long time) {
308
309         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
310
311         extendedFilter.m_filterExpire = true;
312         extendedFilter.m_expireAfter = time;
313         extendedFilter.updateCacheId();
314
315         return extendedFilter;
316     }
317
318     /**
319      * Returns an extended filter to restrict the results to resources that expire in the given timerange.<p>
320      *
321      * @param time the required time
322      * @return a filter to restrict the results to resources that expire in the given timerange
323      */

324     public CmsResourceFilter addRequireExpireBefore(long time) {
325
326         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
327
328         extendedFilter.m_filterExpire = true;
329         extendedFilter.m_expireBefore = time;
330         extendedFilter.updateCacheId();
331
332         return extendedFilter;
333     }
334
335     /**
336      * Returns an extended filter that requires all returned resources to be files.<p>
337      *
338      * @return an extended filter that requires all returned resources to be files
339      */

340     public CmsResourceFilter addRequireFile() {
341
342         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
343
344         extendedFilter.m_onlyFolders = Boolean.FALSE;
345         extendedFilter.updateCacheId();
346
347         return extendedFilter;
348     }
349
350     /**
351      * Returns an extended filter to guarantee a distinct resource flags of the filtered resources.<p>
352      *
353      * @param flags the required resource flags
354      * @return a filter requiring the given resource flags
355      */

356     public CmsResourceFilter addRequireFlags(int flags) {
357
358         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
359
360         extendedFilter.m_flags = flags;
361         extendedFilter.m_filterFlags = REQUIRED;
362         extendedFilter.updateCacheId();
363
364         return extendedFilter;
365     }
366
367     /**
368      * Returns an extended filter that requires all returned resources to be folders.<p>
369      *
370      * @return an extended filter that requires all returned resources to be folders
371      */

372     public CmsResourceFilter addRequireFolder() {
373
374         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
375
376         extendedFilter.m_onlyFolders = Boolean.TRUE;
377         extendedFilter.updateCacheId();
378
379         return extendedFilter;
380     }
381
382     /**
383      * Returns an extended filter to restrict the results to resources modified in the given timerange.<p>
384      *
385      * @param time the required time
386      * @return a filter to restrict the results to resources modified in the given timerange
387      */

388     public CmsResourceFilter addRequireLastModifiedAfter(long time) {
389
390         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
391
392         extendedFilter.m_filterLastModified = true;
393         extendedFilter.m_modifiedAfter = time;
394         extendedFilter.updateCacheId();
395
396         return extendedFilter;
397     }
398
399     /**
400      * Returns an extended filter to restrict the results to resources modified in the given timerange.<p>
401      *
402      * @param time the required time
403      * @return a filter to restrict the results to resources modified in the given timerange
404      */

405     public CmsResourceFilter addRequireLastModifiedBefore(long time) {
406
407         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
408
409         extendedFilter.m_filterLastModified = true;
410         extendedFilter.m_modifiedBefore = time;
411         extendedFilter.updateCacheId();
412
413         return extendedFilter;
414     }
415
416     /**
417      * Returns an extended filter to restrict the results to resources that are released in the given timerange.<p>
418      *
419      * @param time the required time
420      * @return a filter to restrict the results to resources that are released in the given timerange
421      */

422     public CmsResourceFilter addRequireReleaseAfter(long time) {
423
424         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
425
426         extendedFilter.m_filterRelease = true;
427         extendedFilter.m_releaseAfter = time;
428         extendedFilter.updateCacheId();
429
430         return extendedFilter;
431     }
432
433     /**
434      * Returns an extended filter to restrict the results to resources that are released in the given timerange.<p>
435      *
436      * @param time the required time
437      * @return a filter to restrict the results to resources that are released in the given timerange
438      */

439     public CmsResourceFilter addRequireReleaseBefore(long time) {
440
441         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
442
443         extendedFilter.m_filterRelease = true;
444         extendedFilter.m_releaseBefore = time;
445         extendedFilter.updateCacheId();
446
447         return extendedFilter;
448     }
449
450     /**
451      * Returns an extended filter to guarantee a distinct resource state of the filtered resources.<p>
452      *
453      * @param state the required resource state
454      * @return a filter requiring the given resource state
455      */

456     public CmsResourceFilter addRequireState(int state) {
457
458         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
459
460         extendedFilter.m_state = state;
461         extendedFilter.m_filterState = REQUIRED;
462         extendedFilter.updateCacheId();
463
464         return extendedFilter;
465     }
466
467     /**
468      * Returns an extended filter to guarantee all filtered resources are valid (released and not expired).<p>
469      *
470      * @return a filter excluding invalid resources
471      */

472     public CmsResourceFilter addRequireTimerange() {
473
474         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
475
476         extendedFilter.m_filterTimerange = true;
477         extendedFilter.updateCacheId();
478
479         return extendedFilter;
480     }
481
482     /**
483      * Returns an extended filter to guarantee a distinct resource type of the filtered resources.<p>
484      *
485      * @param type the required resource type
486      * @return a filter requiring the given resource type
487      */

488     public CmsResourceFilter addRequireType(int type) {
489
490         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
491
492         extendedFilter.m_type = type;
493         extendedFilter.m_filterType = REQUIRED;
494         extendedFilter.updateCacheId();
495
496         return extendedFilter;
497     }
498
499     /**
500      * Returns an extended filter to guarantee all filtered resources are visible.<p>
501      *
502      * @return a filter excluding invisible resources
503      */

504     public CmsResourceFilter addRequireVisible() {
505
506         CmsResourceFilter extendedFilter = (CmsResourceFilter)clone();
507
508         extendedFilter.m_filterVisible = true;
509         extendedFilter.updateCacheId();
510
511         return extendedFilter;
512     }
513
514     /**
515      * @see java.lang.Object#clone()
516      */

517     public Object JavaDoc clone() {
518
519         CmsResourceFilter filter = new CmsResourceFilter();
520
521         filter.m_cacheId = m_cacheId;
522         filter.m_expireAfter = m_expireAfter;
523         filter.m_expireBefore = m_expireBefore;
524         filter.m_filterExpire = m_filterExpire;
525         filter.m_filterFlags = m_filterFlags;
526         filter.m_filterLastModified = m_filterLastModified;
527         filter.m_filterRelease = m_filterRelease;
528         filter.m_filterState = m_filterState;
529         filter.m_filterTimerange = m_filterTimerange;
530         filter.m_filterType = m_filterType;
531         filter.m_filterVisible = m_filterVisible;
532         filter.m_flags = m_flags;
533         filter.m_modifiedAfter = m_modifiedAfter;
534         filter.m_modifiedBefore = m_modifiedBefore;
535         filter.m_onlyFolders = m_onlyFolders;
536         filter.m_releaseAfter = m_releaseAfter;
537         filter.m_releaseBefore = m_releaseBefore;
538         filter.m_state = m_state;
539         filter.m_type = m_type;
540
541         return filter;
542     }
543
544     /**
545      * return if the stored flags should be excluded while filtering resources.<p>
546      *
547      * @return if the flags should be excluded
548      */

549     public boolean excludeFlags() {
550
551         return m_filterFlags == EXCLUDED;
552     }
553
554     /**
555      * return if the stored state should be excluded while filtering resources.<p>
556      *
557      * @return if the state should be excluded
558      */

559     public boolean excludeState() {
560
561         return m_filterState == EXCLUDED;
562     }
563
564     /**
565      * Returns if the stored type should be excluded while filtering resources.<p>
566      *
567      * @return if the type should be excluded
568      */

569     public boolean excludeType() {
570
571         return m_filterType == EXCLUDED;
572     }
573
574     /**
575      * Returns the unique cache id for this filter.<p>
576      *
577      * @return the unique cache id for this filter
578      */

579     public String JavaDoc getCacheId() {
580
581         return m_cacheId;
582     }
583
584     /**
585      * Returns the start of the expire time range for this filter.<p>
586      *
587      * @return start of the expire time range for this filter
588      */

589     public long getExpireAfter() {
590
591         return m_expireAfter;
592     }
593
594     /**
595      * Returns the end of the expire time range for this filter.<p>
596      *
597      * @return the end of the expire time range for this filter
598      */

599     public long getExpireBefore() {
600
601         return m_expireBefore;
602     }
603
604     /**
605      * Returns the flags for this filter.<p>
606      *
607      * @return the flags for this filter
608      */

609     public int getFlags() {
610
611         return m_flags;
612     }
613
614     /**
615      * Returns the start of the modification time range for this filter.<p>
616      *
617      * @return start of the modification time range for this filter
618      */

619     public long getModifiedAfter() {
620
621         return m_modifiedAfter;
622     }
623
624     /**
625      * Returns the end of the modification time range for this filter.<p>
626      *
627      * @return the end of the modification time range for this filter
628      */

629     public long getModifiedBefore() {
630
631         return m_modifiedBefore;
632     }
633
634     /**
635      * Returns the state of the "only folders" flag.<p>
636      *
637      * If the result is <code>null</code>, then this flag is not set.<p>
638      *
639      * @return the state of the "only folders" flag
640      */

641     public Boolean JavaDoc getOnlyFolders() {
642
643         return m_onlyFolders;
644     }
645
646     /**
647      * Returns the start of the release time range for this filter.<p>
648      *
649      * @return start of the release time range for this filter
650      */

651     public long getReleaseAfter() {
652
653         return m_releaseAfter;
654     }
655
656     /**
657      * Returns the end of the release time range for this filter.<p>
658      *
659      * @return the end of the release time range for this filter
660      */

661     public long getReleaseBefore() {
662
663         return m_releaseBefore;
664     }
665
666     /**
667      * Returns the state for this filter.<p>
668      *
669      * @return the state for this filter
670      */

671     public int getState() {
672
673         return m_state;
674     }
675
676     /**
677      * Returns the type for this filter.<p>
678      *
679      * @return the type for this filter
680      */

681     public int getType() {
682
683         return m_type;
684     }
685
686     /**
687      * Check if deleted resources should be filtered.<p>
688      *
689      * @return true if deleted resources should be included, false otherwiese
690      */

691     public boolean includeDeleted() {
692
693         return (m_filterState == IGNORED)
694             || ((m_filterState == REQUIRED) && (m_state == CmsResource.STATE_DELETED))
695             || ((m_filterState == EXCLUDED) && (m_state != CmsResource.STATE_DELETED));
696     }
697
698     /**
699      * Validates if a CmsResource fits to all filer settings.<p>
700      *
701      * Please note that the "visible permission" setting of the filter is NOT checked
702      * in this method since the permission information is not part of the resource.
703      * The visible permission information in the filter will be used in the permission
704      * checks
705      *
706      * @param context the current request context
707      * @param resource the resource to be validated
708      * @return true if the resource passes all validations, false otherwise
709      */

710     public boolean isValid(CmsRequestContext context, CmsResource resource) {
711
712         if (this == ALL) {
713             // shortcut for "ALL" filter where nothing is filtered
714
return true;
715         }
716
717         // check for required resource state
718
switch (m_filterState) {
719             case EXCLUDED:
720                 if (resource.getState() == m_state) {
721                     return false;
722                 }
723                 break;
724             case REQUIRED:
725                 if (resource.getState() != m_state) {
726                     return false;
727                 }
728                 break;
729             default:
730         // ignored
731
}
732
733         // check for required resource state
734
switch (m_filterFlags) {
735             case EXCLUDED:
736                 if ((resource.getFlags() & m_flags) != 0) {
737                     return false;
738                 }
739                 break;
740             case REQUIRED:
741                 if ((resource.getFlags() & m_flags) != m_flags) {
742                     return false;
743                 }
744                 break;
745             default:
746         // ignored
747
}
748
749         // check for required resource type
750
switch (m_filterType) {
751             case EXCLUDED:
752                 if (resource.getTypeId() == m_type) {
753                     return false;
754                 }
755                 break;
756             case REQUIRED:
757                 if (resource.getTypeId() != m_type) {
758                     return false;
759                 }
760                 break;
761             default:
762         // ignored
763
}
764
765         if (m_onlyFolders != null) {
766             if (m_onlyFolders.booleanValue()) {
767                 if (!resource.isFolder()) {
768                     // only folder resource are allowed
769
return false;
770                 }
771             } else {
772                 if (resource.isFolder()) {
773                     // no folder resources are allowed
774
return false;
775                 }
776             }
777         }
778
779         // check if the resource was last modified within the given time range
780
if (m_filterLastModified) {
781             if (m_modifiedAfter > 0L && resource.getDateLastModified() < m_modifiedAfter) {
782                 return false;
783             }
784             if (m_modifiedBefore > 0L && resource.getDateLastModified() > m_modifiedBefore) {
785                 return false;
786             }
787         }
788
789         // check if the resource expires within the given time range
790
if (m_filterExpire) {
791             if (m_expireAfter > 0L && resource.getDateExpired() < m_expireAfter) {
792                 return false;
793             }
794             if (m_expireBefore > 0L && resource.getDateExpired() > m_expireBefore) {
795                 return false;
796             }
797         }
798
799         // check if the resource is released within the given time range
800
if (m_filterRelease) {
801             if (m_releaseAfter > 0L && resource.getDateReleased() < m_releaseAfter) {
802                 return false;
803             }
804             if (m_releaseBefore > 0L && resource.getDateReleased() > m_releaseBefore) {
805                 return false;
806             }
807         }
808
809         // check if the resource is currently released and not expired
810
if (m_filterTimerange
811             && ((resource.getDateReleased() > context.getRequestTime()) || (resource.getDateExpired() < context.getRequestTime()))) {
812             return false;
813         }
814
815         // everything is ok, so return true
816
return true;
817     }
818
819     /**
820      * Returns if the stored flags is required while filtering resources.<p>
821      *
822      * @return if the flags is required
823      */

824     public boolean requireFlags() {
825
826         return m_filterFlags == REQUIRED;
827     }
828
829     /**
830      * Returns if the stored state is required while filtering resources.<p>
831      *
832      * @return if the state is required
833      */

834     public boolean requireState() {
835
836         return m_filterState == REQUIRED;
837     }
838
839     /**
840      * Returns if the release timerange of the resource should be required.<p>
841      *
842      * @return true if the release timerange of the resource should be required
843      */

844     public boolean requireTimerange() {
845
846         return m_filterTimerange;
847     }
848
849     /**
850      * Returns if the stored type is required while filtering resources.<p>
851      *
852      * @return true if the type is required
853      */

854     public boolean requireType() {
855
856         return m_filterType == REQUIRED;
857     }
858
859     /**
860      * Returns if the visible permission should be required for resources.<p>
861      *
862      * @return true if the visible permission is required, false if the visible permission is ignored
863      */

864     public boolean requireVisible() {
865
866         return m_filterVisible;
867     }
868
869     /**
870      * Returns the name of the filter, if it is one of the filters used as a constant of this class and
871      * a default message otherwise.<p>
872      *
873      * @return the name of the filter
874      */

875     public String JavaDoc toString() {
876
877         if (this.equals(CmsResourceFilter.ALL)) {
878             return "ALL";
879         } else if (this.equals(CmsResourceFilter.ALL_MODIFIED)) {
880             return "ALL_MODIFIED";
881         } else if (this.equals(CmsResourceFilter.DEFAULT)) {
882             return "DEFAULT";
883         } else if (this.equals(CmsResourceFilter.DEFAULT_FILES)) {
884             return "DEFAULT_FILES";
885         } else if (this.equals(CmsResourceFilter.DEFAULT_FOLDERS)) {
886             return "DEFAULT_FOLDERS";
887         } else if (this.equals(CmsResourceFilter.IGNORE_EXPIRATION)) {
888             return "IGNORE_EXPIRATION";
889         } else if (this.equals(CmsResourceFilter.ONLY_VISIBLE)) {
890             return "ONLY_VISIBLE";
891         } else if (this.equals(CmsResourceFilter.ONLY_VISIBLE_NO_DELETED)) {
892             return "ONLY_VISIBLE_NO_DELETED";
893         } else {
894             return "Nonstandard Resource Filter";
895         }
896     }
897
898     /**
899      * Recalculates the cache id.<p>
900      */

901     private void updateCacheId() {
902
903         StringBuffer JavaDoc result = new StringBuffer JavaDoc(32);
904         if (m_filterVisible) {
905             result.append(" Vi");
906         }
907         if (m_filterTimerange) {
908             result.append(" Ti");
909         }
910         switch (m_filterState) {
911             case REQUIRED:
912                 result.append(" Sr");
913                 result.append(m_state);
914                 break;
915             case EXCLUDED:
916                 result.append(" Sx");
917                 result.append(m_state);
918                 break;
919             default:
920         // ignored
921
}
922         switch (m_filterFlags) {
923             case REQUIRED:
924                 result.append(" Fr");
925                 result.append(m_flags);
926                 break;
927             case EXCLUDED:
928                 result.append(" Fx");
929                 result.append(m_flags);
930                 break;
931             default:
932         // ignored
933
}
934         switch (m_filterType) {
935             case REQUIRED:
936                 result.append(" Tr");
937                 result.append(m_type);
938                 break;
939             case EXCLUDED:
940                 result.append(" Tx");
941                 result.append(m_type);
942                 break;
943             default:
944         // ignored
945
}
946         if (m_onlyFolders != null) {
947             if (m_onlyFolders.booleanValue()) {
948                 result.append(" Fo");
949             } else {
950                 result.append(" Fi");
951             }
952         }
953         if (m_filterLastModified) {
954             result.append(" Lt");
955             result.append(m_modifiedAfter);
956             result.append("-");
957             result.append(m_modifiedBefore);
958         }
959         if (m_filterExpire) {
960             result.append(" Ex");
961             result.append(m_expireAfter);
962             result.append("-");
963             result.append(m_expireBefore);
964         }
965         if (m_filterRelease) {
966             result.append(" Re");
967             result.append(m_releaseAfter);
968             result.append("-");
969             result.append(m_releaseBefore);
970         }
971         m_cacheId = result.toString();
972     }
973 }
Popular Tags