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
47
48 public class FilteringPropertyIterator extends FilteringRangeIterator<Property> implements PropertyIterator {
49
50
51
52
53 private PropertyWrapperFactory wrapperFactory;
54 private AbstractPredicate<Property> predicate;
55 private ContentDecorator decorator;
56
57 public FilteringPropertyIterator(PropertyIterator propertyIterator, AbstractPredicate<Property> predicate) {
58 this(propertyIterator, predicate, (ContentDecorator) null);
59 }
60
61 public FilteringPropertyIterator(PropertyIterator propertyIterator, AbstractPredicate<Property> predicate, ContentDecorator decorator) {
62 super(propertyIterator);
63 this.predicate = predicate;
64 this.decorator = decorator;
65 }
66
67
68
69
70 public FilteringPropertyIterator(PropertyIterator propertyIterator, AbstractPredicate<Property> predicate, PropertyWrapperFactory wrapperFactory) {
71 super(propertyIterator);
72 this.wrapperFactory = wrapperFactory;
73 this.predicate = predicate;
74 }
75
76 @Override
77 public Property next() {
78 return wrapProperty(super.next());
79 }
80
81 @Override
82 public Property nextProperty() {
83 return wrapProperty(super.next());
84 }
85
86 protected Property wrapProperty(Property property) {
87 if (decorator != null) {
88 return decorator.wrapProperty(property);
89 } else if (wrapperFactory != null) {
90 return wrapProperty(property);
91 } else {
92 return property;
93 }
94 }
95
96 @Override
97 protected boolean evaluate(Property property) {
98 return predicate == null || predicate.evaluate(property);
99 }
100 }