KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > test > OpenCmsTestResourceFilter


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/test/OpenCmsTestResourceFilter.java,v $
3  * Date : $Date: 2005/06/29 14:22:49 $
4  * Version: $Revision: 1.23 $
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.test;
33
34 import org.opencms.file.CmsProperty;
35
36 import java.util.ArrayList JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.List JavaDoc;
39
40 /**
41  * Base filter class for OpenCms VFS access method tests.<p>
42  *
43  * A filter defines the attributes of a CmsResource which
44  * must not be changed after a method call in the CmsObject.<p>
45  *
46  * To use a filter, either use the static filters provided by this class,
47  * or create an instance of {@link org.opencms.test.OpenCmsTestResourceConfigurableFilter}.<p>
48  *
49  * @author Alexander Kandzior
50  * @author Michael Emmerich
51  *
52  * @version $Revision: 1.23 $
53  */

54 public abstract class OpenCmsTestResourceFilter {
55
56     /** Definition of a filter used for the chacc method. */
57     public static final OpenCmsTestResourceFilter FILTER_CHACC = getFilterChacc();
58
59     /** Definition of a filter used for the chflags method. */
60     public static final OpenCmsTestResourceFilter FILTER_CHFLAGS = getFilterChflags();
61
62     /** Definition of a filter used for the chtype method. */
63     public static final OpenCmsTestResourceFilter FILTER_CHTYPE = getFilterChtype();
64
65     /** Definition of a filter used for the "copy file as new" method. */
66     public static final OpenCmsTestResourceFilter FILTER_COPY_FILE_AS_NEW = getFilterCopyFileAsNew();
67
68     /** Definition of a filter used for the "copy folder" method. */
69     public static final OpenCmsTestResourceFilter FILTER_COPY_FOLDER = getFilterCopyFolder();
70
71     /** Definition of a filter used for the copy method. */
72     public static final OpenCmsTestResourceFilter FILTER_COPY_SOURCE_DESTINATION_AS_SIBLING = getFilterCopySourceDestinationAsSibling();
73
74     /** Definition of a filter used for the create resource method. */
75     public static final OpenCmsTestResourceFilter FILTER_CREATE_RESOURCE = getFilterCreateResource();
76
77     /** Definition of a equal filter. */
78     public static final OpenCmsTestResourceFilter FILTER_EQUAL = new OpenCmsTestResourceConfigurableFilter();
79
80     /** Definition of a filter used to validate the existing and the new sibling after a copy opreation. */
81     public static final OpenCmsTestResourceFilter FILTER_EXISTING_AND_NEW_SIBLING = getFilterExistingAndNewSibling();
82
83     /** Definition of a filter used to validate an existing sibling after a copy operation. */
84     public static final OpenCmsTestResourceFilter FILTER_EXISTING_SIBLING = getFilterExistingSibling();
85
86     /** Definition of a filter used for the move/reanme method. */
87     public static final OpenCmsTestResourceFilter FILTER_MOVE_DESTINATION = getFilterMoveDestination();
88
89     /** Definition of a filter used for the move/reanme method. */
90     public static final OpenCmsTestResourceFilter FILTER_MOVE_SOURCE = getFilterMoveSource();
91
92     /** Definition of a filter used for the publsihResource method. */
93     public static final OpenCmsTestResourceFilter FILTER_PUBLISHRESOURCE = getFilterPublishResource();
94
95     /** Definition of a filter used for the replaceResource method. */
96     public static final OpenCmsTestResourceFilter FILTER_REPLACERESOURCE = getFilterReplaceResource();
97
98     /** Definition of a filter used for the touch method. */
99     public static final OpenCmsTestResourceFilter FILTER_TOUCH = getFilterTouch();
100
101     /** Definition of a filter used for the undoChanges method. */
102     public static final OpenCmsTestResourceFilter FILTER_UNDOCHANGES = getFilterUndoChanges();
103
104     /** Definition of a filter used for the writeProperty method. */
105     public static final OpenCmsTestResourceFilter FILTER_WRITEPROPERTY = getFilterWriteProperty();
106
107     /** Flag to enable/disable access (ACE) tests. */
108     protected boolean m_ace;
109
110     /** Flag to enable/disable access (ACL) tests. */
111     protected boolean m_acl;
112
113     /** Flag to enable/disable content id tests. */
114     protected boolean m_contentId;
115
116     /** Flag to enable/disable content comparison tests. */
117     protected boolean m_contents;
118
119     /** Flag to enable/disable date created tests. */
120     protected boolean m_dateCreated;
121
122     /** Flag to enable/disable date expired tests. */
123     protected boolean m_dateExpired;
124
125     /** Flag to enable/disable date last modified tests. */
126     protected boolean m_dateLastModified;
127
128     /** Flag to enable/disable date released tests. */
129     protected boolean m_dateReleased;
130
131     /** Flag to enable/disable flags tests. */
132     protected boolean m_flags;
133
134     /** Flag to enable/disable "is touched" tests. */
135     protected boolean m_isTouched;
136
137     /** Flag to enable/disable length tests. */
138     protected boolean m_length;
139
140     /** Flag to enable/disable lock state tests. */
141     protected boolean m_lockstate;
142
143     /** Flag to enable/disable name tests. */
144     protected boolean m_name;
145
146     /** Flag to enable/disable project last modified tests. */
147     protected boolean m_projectLastModified;
148
149     /** Flag to enable/disable properties tests. */
150     protected boolean m_properties;
151
152     /** Flag to enable/disable resource id tests. */
153     protected boolean m_resourceId;
154
155     /** Flag to enable/disable sibling count tests. */
156     protected boolean m_siblingCount;
157
158     /** Flag to enable/disable state tests. */
159     protected boolean m_state;
160
161     /** Flag to enable/disable structure id tests. */
162     protected boolean m_structureId;
163
164     /** Flag to enable/disable resource type tests. */
165     protected boolean m_type;
166
167     /** Flag to enable/disable user created tests. */
168     protected boolean m_userCreated;
169
170     /** Flag to enable/disable use last modified tests. */
171     protected boolean m_userLastModified;
172
173     /**
174      * Compares two lists of properties and returns those
175      * that are included only in the source but not in the targer list and not
176      * part of a seperade exclude list.<p>
177      *
178      * @param source the source properties
179      * @param target the target properties
180      * @param exclude the exclude list
181      * @return list of not matching properties
182      */

183     public static List JavaDoc compareProperties(List JavaDoc source, List JavaDoc target, List JavaDoc exclude) {
184
185         List JavaDoc result = new ArrayList JavaDoc();
186         List JavaDoc targetClone = new ArrayList JavaDoc(target);
187         Iterator JavaDoc i = source.iterator();
188         while (i.hasNext()) {
189             boolean found = false;
190             CmsProperty sourceProperty = (CmsProperty)i.next();
191             Iterator JavaDoc j = targetClone.iterator();
192             CmsProperty targetProperty = null;
193             while (j.hasNext()) {
194                 targetProperty = (CmsProperty)j.next();
195                 if (sourceProperty.isIdentical(targetProperty)) {
196                     found = true;
197                     break;
198                 }
199             }
200             if (!found) {
201                 result.add(sourceProperty);
202             } else {
203                 targetClone.remove(targetProperty);
204             }
205         }
206
207         // finally match the result list with the exclude list
208
if (exclude != null) {
209             Iterator JavaDoc l = exclude.iterator();
210             while (l.hasNext()) {
211                 CmsProperty excludeProperty = (CmsProperty)l.next();
212                 if (result.contains(excludeProperty)) {
213                     result.remove(excludeProperty);
214                 }
215             }
216         }
217
218         return result;
219     }
220
221     /**
222      * Creates a new filter used for the "chacc" method.<p>
223      *
224      * @return the created filter
225      */

226     private static OpenCmsTestResourceConfigurableFilter getFilterChacc() {
227
228         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
229
230         filter.disableStateTest();
231         filter.disableProjectLastModifiedTest();
232         filter.disableAclTest();
233         filter.disableAceTest();
234
235         return filter;
236     }
237
238     /**
239      * Creates a new filter used for the "chflags" method.<p>
240      *
241      * @return the created filter
242      */

243     private static OpenCmsTestResourceConfigurableFilter getFilterChflags() {
244
245         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
246
247         filter.disableFlagsTest();
248         filter.disableStateTest();
249         filter.disableProjectLastModifiedTest();
250         filter.disableDateLastModifiedTest();
251         filter.disableUserLastModifiedTest();
252
253         return filter;
254     }
255
256     /**
257      * Creates a new filter used for the "chtype" method.<p>
258      *
259      * @return the created filter
260      */

261     private static OpenCmsTestResourceConfigurableFilter getFilterChtype() {
262
263         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
264
265         filter.disableTypeTest();
266         filter.disableDateLastModifiedTest();
267
268         return filter;
269     }
270
271     /**
272      * Creates a new filter used for the "copy a file as new" method.<p>
273      *
274      * @return the created filter
275      */

276     private static OpenCmsTestResourceConfigurableFilter getFilterCopyFileAsNew() {
277
278         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
279
280         filter.disableProjectLastModifiedTest();
281         filter.disableStateTest();
282         filter.disableStructureIdTest();
283         filter.disableContentIdTest();
284         filter.disableResourceIdTest();
285         filter.disableUserCreatedTest();
286         filter.disableDateCreatedTest();
287         filter.disableLockTest();
288         filter.disableNameTest();
289         filter.disableAceTest();
290         return filter;
291     }
292
293     /**
294      * Creates a new filter used for the "copy a folder" method.<p>
295      *
296      * @return the created filter
297      */

298     private static OpenCmsTestResourceConfigurableFilter getFilterCopyFolder() {
299
300         OpenCmsTestResourceConfigurableFilter filter = getFilterCopyFileAsNew();
301
302         // folder has the date last modified set to current date
303
filter.disableDateLastModifiedTest();
304         filter.disableUserLastModifiedTest();
305         return filter;
306     }
307
308     /**
309      * Creates a new filter used for the "copy as sibling" method.<p>
310      *
311      * @return the created filter
312      */

313     private static OpenCmsTestResourceConfigurableFilter getFilterCopySourceDestinationAsSibling() {
314
315         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
316
317         filter.disableProjectLastModifiedTest();
318         filter.disableStateTest();
319         filter.disableStructureIdTest();
320         filter.disableLockTest();
321         filter.disableNameTest();
322         return filter;
323     }
324
325     /**
326      * Creates a new filter used for the "create resource" method.<p>
327      *
328      * @return the created filter
329      */

330     private static OpenCmsTestResourceConfigurableFilter getFilterCreateResource() {
331
332         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
333
334         filter.disableProjectLastModifiedTest();
335         filter.disableStateTest();
336         filter.disableDateLastModifiedTest();
337         filter.disableUserLastModifiedTest();
338         filter.disableContentsTest();
339         filter.disableLengthTest();
340         filter.disableLockTest();
341         return filter;
342     }
343
344     /**
345      * Creates a new filter used to validate the fields of a new sibling
346      * different from the existing sibling(s) from which it was created.<p>
347      *
348      * @return the created filter
349      */

350     private static OpenCmsTestResourceConfigurableFilter getFilterExistingAndNewSibling() {
351
352         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
353
354         filter.disableStateTest();
355         filter.disableStructureIdTest();
356         filter.disableNameTest();
357         filter.disableLockTest();
358
359         return filter;
360     }
361
362     /**
363      * Creates a new filter used to validate the modified fields of an
364      * existing resource from which a new sibling was created.<p>
365      *
366      * @return the created filter
367      */

368     private static OpenCmsTestResourceConfigurableFilter getFilterExistingSibling() {
369
370         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
371
372         filter.disableProjectLastModifiedTest();
373         filter.disableSiblingCountTest();
374         filter.disableLockTest();
375
376         return filter;
377     }
378
379     /**
380      * Creates a new filter used for the "move/rename" method.<p>
381      *
382      * @return the created filter
383      */

384     private static OpenCmsTestResourceConfigurableFilter getFilterMoveDestination() {
385
386         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
387
388         filter.disableProjectLastModifiedTest();
389         filter.disableStateTest();
390         filter.disableStructureIdTest();
391         filter.disableLockTest();
392         filter.disableNameTest();
393         filter.disableSiblingCountTest();
394         return filter;
395     }
396
397     /**
398      * Creates a new filter used for the "move/rename" method.<p>
399      *
400      * @return the created filter
401      */

402     private static OpenCmsTestResourceConfigurableFilter getFilterMoveSource() {
403
404         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
405
406         filter.disableProjectLastModifiedTest();
407         filter.disableLockTest();
408         filter.disableStateTest();
409         filter.disablePropertiesTest();
410         filter.disableSiblingCountTest();
411         return filter;
412     }
413
414     /**
415      * Creates a new filter used for the "publishResource" method.<p>
416      *
417      * @return the created filter
418      */

419     private static OpenCmsTestResourceFilter getFilterPublishResource() {
420
421         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
422
423         filter.disableLockTest();
424         filter.disableStateTest();
425         filter.disableSiblingCountTest();
426         return filter;
427     }
428
429     /**
430      * Creates a new filter used for the "replaceResource" method.<p>
431      *
432      * @return the created filter
433      */

434     private static OpenCmsTestResourceFilter getFilterReplaceResource() {
435
436         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
437
438         filter.disableLockTest();
439         filter.disableStateTest();
440         filter.disableDateLastModifiedTest();
441         filter.disableUserLastModifiedTest();
442         filter.disableContentsTest();
443         filter.disableLengthTest();
444         filter.disableProjectLastModifiedTest();
445         return filter;
446     }
447
448     /**
449      * Creates a new filter used for the "touch" method.<p>
450      *
451      * @return the created filter
452      */

453     private static OpenCmsTestResourceConfigurableFilter getFilterTouch() {
454
455         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
456
457         filter.disableProjectLastModifiedTest();
458         filter.disableStateTest();
459         filter.disableDateLastModifiedTest();
460         filter.disableUserLastModifiedTest();
461         return filter;
462     }
463
464     /**
465      * Creates a new filter used for the "undoChanges" method.<p>
466      *
467      * @return the created filter
468      */

469     private static OpenCmsTestResourceFilter getFilterUndoChanges() {
470
471         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
472
473         filter.disableProjectLastModifiedTest();
474         filter.disableLockTest();
475         return filter;
476     }
477
478     /**
479      * Creates a new filter used for the "write property" method.<p>
480      *
481      * @return the created filter
482      */

483     private static OpenCmsTestResourceFilter getFilterWriteProperty() {
484
485         OpenCmsTestResourceConfigurableFilter filter = new OpenCmsTestResourceConfigurableFilter();
486
487         filter.disableProjectLastModifiedTest();
488         filter.disableStateTest();
489         filter.disableDateLastModifiedTest();
490         filter.disableUserLastModifiedTest();
491         filter.disablePropertiesTest();
492         return filter;
493     }
494
495     /**
496      * Returns true if the ace test is enabled.<p>
497      *
498      * @return true or false
499      */

500     public boolean testAce() {
501
502         return m_ace;
503     }
504
505     /**
506      * Returns true if the acl test is enabled.<p>
507      *
508      * @return true or false
509      */

510     public boolean testAcl() {
511
512         return m_acl;
513     }
514
515     /**
516      * Returns true if the Content Id test is enabled.<p>
517      *
518      * @return true or false
519      */

520     public boolean testContentId() {
521
522         return m_contentId;
523     }
524
525     /**
526      * Returns true if the Contents test is enabled.<p>
527      *
528      * @return true or false
529      */

530     public boolean testContents() {
531
532         return m_contents;
533     }
534
535     /**
536      * Returns true if the date created test is enabled.<p>
537      *
538      * @return true or false
539      */

540     public boolean testDateCreated() {
541
542         return m_dateCreated;
543     }
544
545     /**
546      * Returns true if the date expired test is enabled.<p>
547      *
548      * @return true or false
549      */

550     public boolean testDateExpired() {
551
552         return m_dateExpired;
553     }
554
555     /**
556      * Returns true if the date last modified test is enabled.<p>
557      *
558      * @return true or false
559      */

560     public boolean testDateLastModified() {
561
562         return m_dateLastModified;
563     }
564
565     /**
566      * Returns true if the date released test is enabled.<p>
567      *
568      * @return true or false
569      */

570     public boolean testDateReleased() {
571
572         return m_dateReleased;
573     }
574
575     /**
576      * Returns true if the flags test is enabled.<p>
577      *
578      * @return true or false
579      */

580     public boolean testFlags() {
581
582         return m_flags;
583     }
584
585     /**
586      * Returns true if the length test is enabled.<p>
587      *
588      * @return true or false
589      */

590     public boolean testLength() {
591
592         return m_length;
593     }
594
595     /**
596      * Returns true if the lockstate test is enabled.<p>
597      *
598      * @return true or false
599      */

600     public boolean testLock() {
601
602         return m_lockstate;
603     }
604
605     /**
606      * Returns true if the name test is enabled.<p>
607      *
608      * @return true or false
609      */

610     public boolean testName() {
611
612         return m_name;
613     }
614
615     /**
616      * Returns true if the project last modified test is enabled.<p>
617      *
618      * @return true or false
619      */

620     public boolean testProjectLastModified() {
621
622         return m_projectLastModified;
623     }
624
625     /**
626      * Returns true if the properties test is enabled.<p>
627      *
628      * @return true or false
629      */

630     public boolean testProperties() {
631
632         return m_properties;
633     }
634
635     /**
636      * Returns true if the resource Id test is enabled.<p>
637      *
638      * @return true or false
639      */

640     public boolean testResourceId() {
641
642         return m_resourceId;
643     }
644
645     /**
646      * Returns true if the sibling count test is enabled..<p>
647      *
648      * @return true or false
649      */

650     public boolean testSiblingCount() {
651
652         return m_siblingCount;
653     }
654
655     /**
656      * Returns true if the state test is enabled.<p>
657      *
658      * @return true or false
659      */

660     public boolean testState() {
661
662         return m_state;
663     }
664
665     /**
666      * Returns true if the structure Id test is enabled.<p>
667      *
668      * @return true or false
669      */

670     public boolean testStructureId() {
671
672         return m_structureId;
673     }
674
675     /**
676      * Returns true if the touched test is enabled.<p>
677      *
678      * @return true or false
679      */

680     public boolean testTouched() {
681
682         return m_isTouched;
683     }
684
685     /**
686      * Returns true if the type test is enabled.<p>
687      *
688      * @return true or false
689      */

690     public boolean testType() {
691
692         return m_type;
693     }
694
695     /**
696      * Returns true if the user created test is enabled.<p>
697      *
698      * @return true or false
699      */

700     public boolean testUserCreated() {
701
702         return m_userCreated;
703     }
704
705     /**
706      * Returns true if the user last modified test is enabled.<p>
707      *
708      * @return true or false
709      */

710     public boolean testUserLastModified() {
711
712         return m_userLastModified;
713     }
714 }
Popular Tags