DeepResourceIterator.java
1.59 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
*/
package com.day.cq.wcm.commons;
import java.util.Iterator;
import java.util.Stack;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
public class DeepResourceIterator
implements Iterator<Resource> {
final ResourceResolver resolver;
final Stack<Iterator<Resource>> resourceTreeStack = new Stack();
Resource current;
public DeepResourceIterator(Resource resource) {
this.resolver = resource.getResourceResolver();
this.resourceTreeStack.push(this.resolver.listChildren(resource));
this.current = this.seek();
}
private Resource seek() {
while (this.resourceTreeStack.size() > 0) {
Iterator<Resource> iter = this.resourceTreeStack.peek();
if (iter.hasNext()) {
Resource res = iter.next();
this.resourceTreeStack.push(this.resolver.listChildren(res));
return res;
}
this.resourceTreeStack.pop();
}
return null;
}
@Override
public boolean hasNext() {
return this.current != null;
}
@Override
public Resource next() {
Resource resource = this.current;
this.current = this.seek();
return resource;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove not possible on event iterator returned by CqCalendar.getEvents()");
}
}