MyTree.java
1.95 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
58
59
60
61
62
63
64
65
66
/*
* 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.mcm.core.servlets;
import com.day.cq.mcm.core.servlets.MyNode;
import com.day.cq.mcm.core.servlets.TreeVisitor;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
class MyTree {
private TreeMap<String, MyNode> tree = new TreeMap();
public MyNode addGetNode(Resource resource) {
MyNode current = this.tree.get(resource.getPath());
if (current == null) {
current = new MyNode();
current.initFrom(resource);
this.addNode(current);
}
return current;
}
public void addNode(MyNode node) {
if (!"/".equals(node.resource.getPath())) {
MyNode parentNode;
Resource parent = node.resource.getResourceResolver().getResource(node.resource, "../");
if (parent == null) {
throw new RuntimeException("Could not find parent for '" + node.resource.getPath() + "'!");
}
node.parent = parentNode = this.addGetNode(parent);
parentNode.children.add(node.resource.getPath());
}
this.tree.put(node.resource.getPath(), node);
}
public boolean hasNode(String path) {
return this.tree.containsKey(path);
}
public MyNode getNode(String path) {
return this.tree.get(path);
}
public void depthFirstTraversal(TreeVisitor tv) {
MyNode root = this.getNode("/");
if (root != null) {
this.depthFirstTraversal(tv, root);
}
}
public void depthFirstTraversal(TreeVisitor tv, MyNode n) {
tv.enter(n);
for (String path : n.children) {
this.depthFirstTraversal(tv, this.getNode(path));
}
tv.leave(n);
}
}