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.wrapper;
35
36 import info.magnolia.jcr.decoration.AbstractContentDecorator;
37 import info.magnolia.jcr.iterator.FilteringNodeIterator;
38 import info.magnolia.jcr.predicate.AbstractPredicate;
39
40 import javax.jcr.Node;
41 import javax.jcr.NodeIterator;
42
43
44
45
46
47 public class ChildFilteringContentDecorator extends AbstractContentDecorator {
48
49 private AbstractPredicate<Node> predicate;
50 private boolean filterDescendants;
51 private boolean multipleWrapEnabled;
52
53 public ChildFilteringContentDecorator(AbstractPredicate<Node> predicate, boolean filterDescendants) {
54 this(predicate, filterDescendants, true);
55 }
56
57 public ChildFilteringContentDecorator(AbstractPredicate<Node> predicate, boolean filterDescendants, boolean multipleWrapEnabled) {
58 this.predicate = predicate;
59 this.filterDescendants = filterDescendants;
60 this.multipleWrapEnabled = multipleWrapEnabled;
61 }
62
63 @Override
64 public Node wrapNode(Node node) {
65 return filterDescendants ? new ChildFilteringNodeWrapper(node, predicate, filterDescendants) : node;
66 }
67
68 @Override
69 public NodeIterator wrapNodeIterator(NodeIterator nodeIterator) {
70 return new FilteringNodeIterator(nodeIterator, predicate, filterDescendants ? this : null);
71 }
72
73 @Override
74 public boolean evaluateNode(Node node) {
75 return predicate.evaluate(node);
76 }
77
78 @Override
79 public boolean isMultipleWrapEnabled() {
80 return this.multipleWrapEnabled;
81 }
82
83 }