Navigation.java
4.48 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.Filter
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageFilter
* com.day.text.Text
* org.apache.commons.lang3.StringEscapeUtils
*/
package com.day.cq.wcm.foundation;
import com.day.cq.commons.Filter;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageFilter;
import com.day.text.Text;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.StringEscapeUtils;
public class Navigation
implements Iterable<Element> {
private final PageFilter filter;
private final int depth;
private final Page root;
private final String currentPath;
private final String currentPathS;
public Navigation(Page current, int absParent, PageFilter filter, int depth) {
this.currentPath = current.getPath();
this.currentPathS = this.currentPath + "/";
Page r = current.getAbsoluteParent(absParent);
this.root = r == null ? current : r;
this.filter = filter;
this.depth = depth;
}
@Override
public Iterator<Element> iterator() {
ArrayList<Element> list = new ArrayList<Element>();
if (this.root != null) {
this.fillList(list, this.root.listChildren((Filter)this.filter), this.depth - 1);
}
return list.iterator();
}
private void fillList(List<Element> list, Iterator<Page> pages, int limit) {
boolean first = true;
while (pages.hasNext()) {
Page p = pages.next();
Element e = new Element(p);
e.first = first;
first = false;
e.last = !pages.hasNext();
String path = p.getPath();
if (path.equals(this.currentPath)) {
e.current = true;
e.onTrail = true;
} else if (this.currentPathS.startsWith(path + "/")) {
e.onTrail = true;
}
Iterator cs = null;
if (limit > 0) {
cs = p.listChildren((Filter)this.filter);
}
if (cs != null && cs.hasNext()) {
e.children = true;
}
e.type = Element.Type.ITEM_BEGIN;
list.add(e);
if (e.children) {
list.add(new Element(e, Element.Type.NODE_OPEN));
this.fillList(list, cs, limit - 1);
list.add(new Element(e, Element.Type.NODE_CLOSE));
}
list.add(new Element(e, Element.Type.ITEM_END));
}
}
public static class Element {
private Type type = Type.ITEM_BEGIN;
private final Page page;
private final String title;
private boolean children;
private boolean onTrail;
private boolean current;
private boolean first;
private boolean last;
private Element(Element e, Type type) {
this.type = type;
this.page = e.page;
this.title = e.title;
this.children = e.children;
this.onTrail = e.onTrail;
this.current = e.current;
this.first = e.first;
this.last = e.last;
}
private Element(Page page) {
this.page = page;
String t = page.getNavigationTitle();
if (t == null) {
t = page.getTitle();
}
this.title = t == null ? page.getName() : t;
}
public Type getType() {
return this.type;
}
public Page getPage() {
return this.page;
}
public String getPath() {
return Text.escape((String)this.page.getPath(), (char)'%', (boolean)true);
}
public String getRawTitle() {
return this.title;
}
public String getTitle() {
return StringEscapeUtils.escapeHtml4((String)this.title);
}
public boolean hasChildren() {
return this.children;
}
public boolean isOnTrail() {
return this.onTrail;
}
public boolean isCurrent() {
return this.current;
}
public boolean isFirst() {
return this.first;
}
public boolean isLast() {
return this.last;
}
public static enum Type {
NODE_OPEN,
ITEM_BEGIN,
ITEM_END,
NODE_CLOSE;
private Type() {
}
}
}
}