2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 import org.clearsilver.HDF;
19 import java.util.ArrayList;
21 public class NavTree {
23 public static void writeNavTree(String dir) {
24 ArrayList<Node> children = new ArrayList();
25 for (PackageInfo pkg: DroidDoc.choosePackages()) {
26 children.add(makePackageNode(pkg));
28 Node node = new Node("Reference", dir + "packages.html", children);
30 StringBuilder buf = new StringBuilder();
32 // if you want a root node
37 // if you don't want a root node
38 node.renderChildren(buf);
41 HDF data = DroidDoc.makeHDF();
42 data.setValue("reference_tree", buf.toString());
43 ClearPage.write(data, "navtree_data.cs", "navtree_data.js");
46 private static Node makePackageNode(PackageInfo pkg) {
47 ArrayList<Node> children = new ArrayList();
49 children.add(new Node("Description", pkg.fullDescriptionHtmlPage(), null));
51 addClassNodes(children, "Interfaces", pkg.interfaces());
52 addClassNodes(children, "Classes", pkg.ordinaryClasses());
53 addClassNodes(children, "Enums", pkg.enums());
54 addClassNodes(children, "Exceptions", pkg.exceptions());
55 addClassNodes(children, "Errors", pkg.errors());
57 return new Node(pkg.name(), pkg.htmlPage(), children);
60 private static void addClassNodes(ArrayList<Node> parent, String label, ClassInfo[] classes) {
61 ArrayList<Node> children = new ArrayList();
63 for (ClassInfo cl: classes) {
64 if (cl.checkLevel()) {
65 children.add(new Node(cl.name(), cl.htmlPage(), null));
69 if (children.size() > 0) {
70 parent.add(new Node(label, null, children));
74 private static class Node {
75 private String mLabel;
77 ArrayList<Node> mChildren;
79 Node(String label, String link, ArrayList<Node> children) {
85 static void renderString(StringBuilder buf, String s) {
90 final int N = s.length();
91 for (int i=0; i<N; i++) {
93 if (c >= ' ' && c <= '~' && c != '"' && c != '\\') {
97 for (int j=0; i<4; i++) {
98 char x = (char)(c & 0x000f);
100 x = (char)(x - 10 + 'a');
113 void renderChildren(StringBuilder buf) {
114 ArrayList<Node> list = mChildren;
115 if (list == null || list.size() == 0) {
116 // We output null for no children. That way empty lists here can just
117 // be a byproduct of how we generate the lists.
121 final int N = list.size();
122 for (int i=0; i<N; i++) {
123 list.get(i).render(buf);
132 void render(StringBuilder buf) {
134 renderString(buf, mLabel);
136 renderString(buf, mLink);