Sitemap.java
2.63 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
/*
* 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
* 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 java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Iterator;
import java.util.LinkedList;
import org.apache.commons.lang3.StringEscapeUtils;
public class Sitemap {
private LinkedList<Link> links = new LinkedList();
public Sitemap(Page rootPage) {
this.buildLinkAndChildren(rootPage, 0);
}
private void buildLinkAndChildren(Page page, int level) {
if (page != null) {
String title = page.getTitle();
if (title == null) {
title = page.getName();
}
this.links.add(new Link(page.getPath(), title, level));
Iterator children = page.listChildren((Filter)new PageFilter());
while (children.hasNext()) {
Page child = (Page)children.next();
this.buildLinkAndChildren(child, level + 1);
}
}
}
public void draw(Writer w) throws IOException {
PrintWriter out = new PrintWriter(w);
int previousLevel = -1;
for (Link aLink : this.links) {
if (aLink.getLevel() > previousLevel) {
out.print("<div class=\"linkcontainer\">");
} else if (aLink.getLevel() < previousLevel) {
for (int i = aLink.getLevel(); i < previousLevel; ++i) {
out.print("</div>");
}
}
out.printf("<div class=\"link\"><a href=\"%s.html\">%s</a></div>", StringEscapeUtils.escapeHtml4((String)aLink.getPath()), StringEscapeUtils.escapeHtml4((String)aLink.getTitle()));
previousLevel = aLink.getLevel();
}
for (int i = -1; i < previousLevel; ++i) {
out.print("</div>");
}
}
public LinkedList<Link> getLinks() {
return this.links;
}
public class Link {
private String path;
private String title;
private int level;
public Link(String path, String title, int level) {
this.path = path;
this.title = title;
this.level = level;
}
public String getPath() {
return this.path;
}
public int getLevel() {
return this.level;
}
public String getTitle() {
return this.title;
}
}
}