1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.jcr.iterator;
35
36 import info.magnolia.jcr.decoration.ContentDecorator;
37 import info.magnolia.jcr.predicate.AbstractPredicate;
38 import info.magnolia.jcr.wrapper.PropertyWrapperFactory;
39
40 import javax.jcr.Property;
41 import javax.jcr.PropertyIterator;
42
43
44
45
46 public class FilteringPropertyIterator extends FilteringRangeIterator<Property> implements PropertyIterator {
47
48
49
50
51 private PropertyWrapperFactory wrapperFactory;
52 private AbstractPredicate<Property> predicate;
53 private ContentDecorator decorator;
54
55 public FilteringPropertyIterator(PropertyIterator propertyIterator, AbstractPredicate<Property> predicate) {
56 this(propertyIterator, predicate, (ContentDecorator) null);
57 }
58
59 public FilteringPropertyIterator(PropertyIterator propertyIterator, AbstractPredicate<Property> predicate, ContentDecorator decorator) {
60 super(propertyIterator);
61 this.predicate = predicate;
62 this.decorator = decorator;
63 }
64
65
66
67
68 public FilteringPropertyIterator(PropertyIterator propertyIterator, AbstractPredicate<Property> predicate, PropertyWrapperFactory wrapperFactory) {
69 super(propertyIterator);
70 this.wrapperFactory = wrapperFactory;
71 this.predicate = predicate;
72 }
73
74 @Override
75 public Property next() {
76 return wrapProperty(super.next());
77 }
78
79 @Override
80 public Property nextProperty() {
81 return wrapProperty(super.next());
82 }
83
84 protected Property wrapProperty(Property property) {
85 if (decorator != null) {
86 return decorator.wrapProperty(property);
87 } else if (wrapperFactory != null) {
88 return wrapProperty(property);
89 } else {
90 return property;
91 }
92 }
93
94 @Override
95 protected boolean evaluate(Property property) {
96 return predicate == null || predicate.evaluate(property);
97 }
98 }