blob: 738b74b8c90afa148380d5994fdbb9603669a8fa [file] [log] [blame]
Ben Dodson920dbbb2010-08-04 15:21:06 -07001/*
2 * Copyright (C) 2010 Google Inc.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package com.google.doclava;
Ben Dodson920dbbb2010-08-04 15:21:06 -070018import com.google.clearsilver.jsilver.data.Data;
19
20import java.util.*;
21import java.io.*;
22
23
24public class SampleCode {
25 String mSource;
26 String mDest;
27 String mTitle;
Dirk Doughertyc11a4672013-08-23 19:14:10 -070028 String mProjectDir;
Dirk Dougherty25586c02013-08-30 16:21:15 -070029 String mTags;
Ben Dodson920dbbb2010-08-04 15:21:06 -070030
31 public SampleCode(String source, String dest, String title) {
32 mSource = source;
33 mTitle = title;
Dirk Dougherty25586c02013-08-30 16:21:15 -070034 mTags = null;
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070035
Ben Dodson920dbbb2010-08-04 15:21:06 -070036 int len = dest.length();
37 if (len > 1 && dest.charAt(len - 1) != '/') {
38 mDest = dest + '/';
39 } else {
40 mDest = dest;
41 }
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070042
Dirk Doughertyc11a4672013-08-23 19:14:10 -070043
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070044 //System.out.println("SampleCode init: source: " + mSource);
45 //System.out.println("SampleCode init: dest: " + mDest);
46 //System.out.println("SampleCode init: title: " + mTitle);
47
Ben Dodson920dbbb2010-08-04 15:21:06 -070048 }
49
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070050 public Node write(boolean offlineMode) {
51 List<Node> filelist = new ArrayList<Node>();
Ben Dodson920dbbb2010-08-04 15:21:06 -070052 File f = new File(mSource);
Dirk Doughertyc11a4672013-08-23 19:14:10 -070053 mProjectDir = f.getName();
54 String name = mProjectDir;
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070055 String startname = name;
56 String subdir = mDest;
57 String mOut = subdir + name;
Ben Dodson920dbbb2010-08-04 15:21:06 -070058 if (!f.isDirectory()) {
59 System.out.println("-samplecode not a directory: " + mSource);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070060 return null;
Ben Dodson920dbbb2010-08-04 15:21:06 -070061 }
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070062
63 if (offlineMode)
64 writeIndexOnly(f, mDest, offlineMode);
65 else {
66 Data hdf = Doclava.makeHDF();
67 hdf.setValue("samples", "true");
Dirk Doughertyc11a4672013-08-23 19:14:10 -070068 hdf.setValue("projectDir", mProjectDir);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070069 writeProjectDirectory(filelist, f, mDest, false, hdf, "Files.");
Dirk Doughertyc11a4672013-08-23 19:14:10 -070070 writeProjectStructure(name, hdf);
71 getSummaryFromDir(hdf, f, "Files.");
72 writeProjectIndex(hdf);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070073 hdf.removeTree("parentdirs");
74 hdf.setValue("parentdirs.0.Name", name);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070075 // return a root SC node for the sample with children appended
Dirk Dougherty25586c02013-08-30 16:21:15 -070076 return new Node(mProjectDir, "samples/" + startname + "/index.html", mTags, filelist, null);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070077 }
78 return null;
Ben Dodson920dbbb2010-08-04 15:21:06 -070079 }
80
81 public static String convertExtension(String s, String ext) {
82 return s.substring(0, s.lastIndexOf('.')) + ext;
83 }
84
85 public static String[] IMAGES = {".png", ".jpg", ".gif"};
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070086 public static String[] TEMPLATED = {".java", ".xml", ".aidl", ".rs",".txt", ".TXT"};
Ben Dodson920dbbb2010-08-04 15:21:06 -070087
88 public static boolean inList(String s, String[] list) {
89 for (String t : list) {
90 if (s.endsWith(t)) {
91 return true;
92 }
93 }
94 return false;
95 }
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -070096
97 public static String mapTypes(String name) {
98 String type = name.substring(name.lastIndexOf('.') + 1, name.length());
99 if (type.equals("xml") || type.equals("java")) {
100 if (name.equals("AndroidManifest.xml")) type = "manifest";
101 return type;
102 } else {
103 return type = "file";
104 }
105 }
106
107 public void writeProjectDirectory(List<Node> parent, File dir, String relative, Boolean recursed, Data hdf, String newkey) {
108 TreeSet<String> dirs = new TreeSet<String>(); //dirs for project structure and breadcrumb
109 TreeSet<String> files = new TreeSet<String>(); //files for project structure and breadcrumb
110
111 String subdir = relative;
112 String name = "";
113 String label = "";
114 String link = "";
115 String type = "";
116 int i = 0;
117 String expansion = ".Sub.";
118 String key = newkey;
119
120 if (recursed) {
121 key = (key + expansion);
122 } else {
123 expansion = "";
124 }
125
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700126 File[] dirContents = dir.listFiles();
127 Arrays.sort(dirContents, byTypeAndName);
128 for (File f: dirContents) {
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700129 name = f.getName();
130 // don't process certain types of files
131 if (name.startsWith(".") ||
132 name.startsWith("_") ||
133 name.equals("default.properties") ||
134 name.equals("build.properties") ||
135 name.endsWith(".ttf") ||
136 name.equals("Android.mk")) {
137 //System.out.println("Invalid File Type, bypassing: " + name);
138 continue;
139 }
140 if (f.isFile() && name.contains(".")){
141 String path = relative + name;
142 type = mapTypes(name);
143 link = convertExtension(path, ".html");
144 hdf.setValue("samples", "true");//dd needed?
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700145 if (inList(path, IMAGES)) {
146 // copy these files to output directly
147 type = "img";
148 ClearPage.copyFile(false, f, path);
149 writeImagePage(f, convertExtension(path, Doclava.htmlExtension), relative);
150 files.add(name);
151 hdf.setValue(key + i + ".Type", "img");
152 hdf.setValue(key + i + ".Name", name);
153 hdf.setValue(key + i + ".Href", link);
Dirk Dougherty25586c02013-08-30 16:21:15 -0700154 hdf.setValue(key + i + ".RelPath", relative);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700155 }
156 if (inList(path, TEMPLATED)) {
157 // copied and goes through the template
158 ClearPage.copyFile(false, f, path);
159 writePage(f, convertExtension(path, Doclava.htmlExtension), relative);
160 files.add(name);
161 hdf.setValue(key + i + ".Type", type);
162 hdf.setValue(key + i + ".Name", name);
163 hdf.setValue(key + i + ".Href", link);
Dirk Dougherty25586c02013-08-30 16:21:15 -0700164 hdf.setValue(key + i + ".RelPath", relative);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700165 }
166 // add file to the navtree
Dirk Dougherty25586c02013-08-30 16:21:15 -0700167 parent.add(new Node(name, link , null, null, type));
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700168 i++;
169 } else if (f.isDirectory()) {
170 List<Node> mchildren = new ArrayList<Node>();
171 type = "dir";
172 String dirpath = relative + name;
173 link = dirpath + "/index.html";
174 String hdfkeyName = (key + i + ".Name");
175 String hdfkeyType = (key + i + ".Type");
176 String hdfkeyHref = (key + i + ".Href");
177 hdf.setValue(hdfkeyName, name);
178 hdf.setValue(hdfkeyType, type);
179 hdf.setValue(hdfkeyHref, relative + name + "/" + "index.html");
180 //System.out.println("Found directory, recursing. Current key: " + hdfkeyName);
181 writeProjectDirectory(mchildren, f, relative + name + "/", true, hdf, (key + i));
182 if (mchildren.size() > 0) {
183 //dir is processed, now add it to the navtree
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700184 //don't link sidenav subdirs at this point (but can use "link" to do so)
Dirk Dougherty25586c02013-08-30 16:21:15 -0700185 parent.add(new Node(name, null, null, mchildren, type));
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700186 }
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700187 dirs.add(name);
188
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700189 i++;
190 }
Dirk Dougherty25586c02013-08-30 16:21:15 -0700191
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700192 }
193 //dd not working yet
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700194 //Get summary from any _index files in any project dirs (currently disabled)
195 // getSummaryFromDir(hdf, dir, newkey);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700196 //If this is an index for the project root (assumed root if split length is 3 (development/samples/nn)),
197 //then remove the root dir so that it won't appear in the breadcrumb. Else just pass it through to
198 //setParentDirs as usual.
199 String mpath = dir + "";
200 String sdir[] = mpath.split("/");
201 if (sdir.length == 3 ) {
202 System.out.println("-----------------> this must be the root: [sdir len]" + sdir.length + "[dir]" + dir);
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700203 hdf.setValue("showProjectPaths","true");//dd remove here?
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700204 }
205 setParentDirs(hdf, relative, name, false);
Dirk Dougherty25586c02013-08-30 16:21:15 -0700206 //concatenate dirs in the navtree. Comment out or remove to restore
207 //normal nav tree.
208 squashNodes(parent);
Scott Maine27c9502011-01-19 14:07:39 -0800209 }
210
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700211 public void writeProjectStructure(String dir, Data hdf) {
212 //System.out.println(">>-- writing project structure for " + dir );
213 hdf.setValue("projectStructure", "true");
214 hdf.setValue("projectDir", mProjectDir);
215 hdf.setValue("page.title", mProjectDir + " Structure");
216 hdf.setValue("projectTitle", mTitle);
217 ClearPage.write(hdf, "sampleindex.cs", mDest + "project" + Doclava.htmlExtension); //write the project.html file
218 hdf.setValue("projectStructure", "");
Ben Dodson920dbbb2010-08-04 15:21:06 -0700219 }
220
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700221 /**
222 * Write the project's templated _index.html
223 */
224 public void writeProjectIndex(Data hdf) {
Dirk Dougherty25586c02013-08-30 16:21:15 -0700225 //System.out.println(">>-- writing project index for " + mDest );
226 hdf.setValue("projectDir", mProjectDir);
227 hdf.setValue("page.title", mProjectDir + " Sample");
228 hdf.setValue("projectTitle", mTitle);
229 ClearPage.write(hdf, "sampleindex.cs", mDest + "index" + Doclava.htmlExtension);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700230 }
231
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700232 /**
233 * Grab the contents of an _index.html summary from a dir.
234 */
235 public void getSummaryFromDir(Data hdf, File dir, String key) {
236 //System.out.println("Getting summary for " + dir + "/_index.html");
237 hdf.setValue("summary", "");
238 hdf.setValue("summaryFlag", "");
Ben Dodson920dbbb2010-08-04 15:21:06 -0700239 String filename = dir.getPath() + "/_index.html";
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700240 String summary = SampleTagInfo.readFile(new SourcePositionInfo(filename,
241 -1,-1), filename, "sample code", true, false, false, true);
242 if (summary != null) {
243 hdf.setValue(key + "SummaryFlag", "true");
244 hdf.setValue("summary", summary);
245 //set the target for [info] link
246 //hdf.setValue(key + "Href", dir + "/index.html");
247 //return true;
248 }
249 }
Ben Dodson920dbbb2010-08-04 15:21:06 -0700250
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700251 /**
252 * Keep track of file parents
253 */
254 Data setParentDirs(Data hdf, String subdir, String name, Boolean isFile) {
255 isFile = false;
256 int iter;
257 hdf.removeTree("parentdirs");
258 //System.out.println("setParentDirs for " + subdir + name);
259 String s = subdir;
260 String urlParts[] = s.split("/");
261 int n, l = (isFile)?1:0;
262 for (iter=2; iter < urlParts.length - l; iter++) {
263 n = iter-2;
264 //System.out.println("parentdirs." + n + ".Name == " + urlParts[iter]);
265 hdf.setValue("parentdirs." + n + ".Name", urlParts[iter]);
Ben Dodson920dbbb2010-08-04 15:21:06 -0700266 }
Ben Dodson920dbbb2010-08-04 15:21:06 -0700267 return hdf;
268 }
269
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700270 /**
271 * Write a templated source code file to out.
272 */
Ben Dodson920dbbb2010-08-04 15:21:06 -0700273 public void writePage(File f, String out, String subdir) {
274 String name = f.getName();
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700275 String path = f.getPath();
Ben Dodson920dbbb2010-08-04 15:21:06 -0700276 String data =
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700277 SampleTagInfo.readFile(new SourcePositionInfo(path, -1, -1), path, "sample code",
278 true, true, true, true);
Ben Dodson920dbbb2010-08-04 15:21:06 -0700279 data = Doclava.escape(data);
280
281 Data hdf = Doclava.makeHDF();
Dirk Dougherty25586c02013-08-30 16:21:15 -0700282
283 String relative = subdir.replaceFirst("samples/", "");
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700284 hdf.setValue("samples", "true");
285 setParentDirs(hdf, subdir, name, true);
286 hdf.setValue("projectTitle", mTitle);
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700287 hdf.setValue("projectDir", mProjectDir);
Ben Dodson920dbbb2010-08-04 15:21:06 -0700288 hdf.setValue("page.title", name);
289 hdf.setValue("subdir", subdir);
Dirk Dougherty25586c02013-08-30 16:21:15 -0700290 hdf.setValue("relative", relative);
Ben Dodson920dbbb2010-08-04 15:21:06 -0700291 hdf.setValue("realFile", name);
292 hdf.setValue("fileContents", data);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700293 hdf.setValue("resTag", "sample");
294 hdf.setValue("resType", "Sample Code");
Ben Dodson920dbbb2010-08-04 15:21:06 -0700295
296 ClearPage.write(hdf, "sample.cs", out);
297 }
298
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700299 /**
300 * Write a templated image file to out.
301 */
Ben Dodson920dbbb2010-08-04 15:21:06 -0700302 public void writeImagePage(File f, String out, String subdir) {
303 String name = f.getName();
304
305 String data = "<img src=\"" + name + "\" title=\"" + name + "\" />";
306
307 Data hdf = Doclava.makeHDF();
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700308 hdf.setValue("samples", "true");
309 setParentDirs(hdf, subdir, name, true);
Ben Dodson920dbbb2010-08-04 15:21:06 -0700310 hdf.setValue("page.title", name);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700311 hdf.setValue("projectTitle", mTitle);
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700312 hdf.setValue("projectDir", mProjectDir);
Ben Dodson920dbbb2010-08-04 15:21:06 -0700313 hdf.setValue("subdir", subdir);
314 hdf.setValue("realFile", name);
315 hdf.setValue("fileContents", data);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700316 hdf.setValue("resTag", "sample");
317 hdf.setValue("resType", "Sample Code");
Ben Dodson920dbbb2010-08-04 15:21:06 -0700318 ClearPage.write(hdf, "sample.cs", out);
319 }
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700320
321 /**
322 * Render a SC node to a navtree js file.
323 */
324 public static void writeSamplesNavTree(List<Node> tnode) {
Dirk Dougherty25586c02013-08-30 16:21:15 -0700325 Node node = new Node("Reference", "packages.html", null, tnode, null);
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700326
327 StringBuilder buf = new StringBuilder();
328 if (false) {
329 // if you want a root node
330 buf.append("[");
331 node.render(buf);
332 buf.append("]");
333 } else {
334 // if you don't want a root node
335 node.renderChildren(buf);
336 }
337
338 Data data = Doclava.makeHDF();
339 data.setValue("reference_tree", buf.toString());
340 ClearPage.write(data, "samples_navtree_data.cs", "samples_navtree_data.js");
341 }
342
Dirk Dougherty25586c02013-08-30 16:21:15 -0700343 /**
344 * Sort by type and name (alpha), with manifest and src always at top.
345 */
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700346 Comparator<File> byTypeAndName = new Comparator<File>() {
347 public int compare (File one, File other) {
348 if (one.isDirectory() && !other.isDirectory()) {
349 return 1;
350 } else if (!one.isDirectory() && other.isDirectory()) {
351 return -1;
Dirk Dougherty25586c02013-08-30 16:21:15 -0700352 } else if (one.getName().equals("AndroidManifest.xml")) {
353 return -1;
354 } else if (one.getName().equals("src")) {
355 return -1;
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700356 } else {
357 return one.compareTo(other);
358 }
359 }
360 };
361
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700362 /**
Dirk Dougherty25586c02013-08-30 16:21:15 -0700363 * Concatenate dirs that only hold dirs to simplify nav tree
364 */
365 public static List<Node> squashNodes(List<Node> tnode){
366 List<Node> list = tnode;
367
368 for(int i = 0; i < list.size(); ++i) {
369 //only squash dirs that contain another dir whose list size is 1 and
370 //that don't contain endpoints
371 if ((list.get(i).getType().equals("dir")) &&
372 (list.size() == 1) &&
373 (list.get(i).getChildren().get(0).getChildren() != null)) {
374 String thisLabel = list.get(i).getLabel();
375 String childLabel = list.get(i).getChildren().get(0).getLabel();
376 String newLabel = thisLabel + "/" + childLabel;
377 //Set label of parent and mChildren to those of child-child, skipping
378 //squashed dir
379 list.get(i).setLabel(newLabel);
380 list.get(i).setChildren(list.get(i).getChildren().get(0).getChildren());
381 } else {
382 continue;
383 }
384 }
385 return list;
386 }
387
388 /**
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700389 * SampleCode variant of NavTree node.
390 */
391 public static class Node {
392 private String mLabel;
393 private String mLink;
Dirk Dougherty25586c02013-08-30 16:21:15 -0700394 private String mTags;
395 private List<Node> mChildren;
396 private String mType;
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700397
Dirk Dougherty25586c02013-08-30 16:21:15 -0700398 Node(String label, String link, String tags, List<Node> children, String type) {
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700399 mLabel = label;
400 mLink = link;
Dirk Dougherty25586c02013-08-30 16:21:15 -0700401 mTags = tags;
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700402 mChildren = children;
403 mType = type;
404 }
405
406 static void renderString(StringBuilder buf, String s) {
407 if (s == null) {
408 buf.append("null");
409 } else {
410 buf.append('"');
411 final int N = s.length();
412 for (int i = 0; i < N; i++) {
413 char c = s.charAt(i);
414 if (c >= ' ' && c <= '~' && c != '"' && c != '\\') {
415 buf.append(c);
416 } else {
417 buf.append("\\u");
418 for (int j = 0; i < 4; i++) {
419 char x = (char) (c & 0x000f);
420 if (x > 10) {
421 x = (char) (x - 10 + 'a');
422 } else {
423 x = (char) (x + '0');
424 }
425 buf.append(x);
426 c >>= 4;
427 }
428 }
429 }
430 buf.append('"');
431 }
432 }
433
434 void renderChildren(StringBuilder buf) {
435 List<Node> list = mChildren;
436 if (list == null || list.size() == 0) {
437 // We output null for no children. That way empty lists here can just
438 // be a byproduct of how we generate the lists.
439 buf.append("null");
440 } else {
441 buf.append("[ ");
442 final int N = list.size();
443 for (int i = 0; i < N; i++) {
444 list.get(i).render(buf);
445 if (i != N - 1) {
446 buf.append(", ");
447 }
448 }
449 buf.append(" ]\n");
450 }
451 }
452
453 void render(StringBuilder buf) {
454 buf.append("[ ");
455 renderString(buf, mLabel);
456 buf.append(", ");
457 renderString(buf, mLink);
458 buf.append(", ");
459 renderChildren(buf);
460 buf.append(", ");
461 renderString(buf, mType);
462 buf.append(" ]");
463 }
Dirk Dougherty25586c02013-08-30 16:21:15 -0700464
465 public List<Node> getChildren() {
466 if (mChildren != null) {
467 return mChildren;
468 } else {
469 return null;
470 }
471 }
472
473 public void setChildren(List<Node> node) {
474 mChildren = node;
475 }
476
477 public String getLabel() {
478 return mLabel;
479 }
480
481 public void setLabel(String label) {
482 mLabel = label;
483 }
484
485 public String getType() {
486 return mType.toString();
487 }
488
489 public String getHref() {
490 return mLink;
491 }
492
493 public void setHref(String link) {
494 mLink = link;
495 }
Dirk Dougherty1b45d1d2010-08-17 17:25:36 -0700496 }
497
Dirk Doughertyc11a4672013-08-23 19:14:10 -0700498 /**
499 * @deprecated
500 */
501 public void writeDirectory(File dir, String relative, boolean offline) {
502 TreeSet<String> dirs = new TreeSet<String>();
503 TreeSet<String> files = new TreeSet<String>();
504
505 String subdir = relative; // .substring(mDest.length());
506
507 for (File f : dir.listFiles()) {
508 String name = f.getName();
509 if (name.startsWith(".") || name.startsWith("_")) {
510 continue;
511 }
512 if (f.isFile()) {
513 String out = relative + name;
514 if (inList(out, IMAGES)) {
515 // copied directly
516 ClearPage.copyFile(false, f, out);
517 writeImagePage(f, convertExtension(out, Doclava.htmlExtension), subdir);
518 files.add(name);
519 }
520 if (inList(out, TEMPLATED)) {
521 // copied and goes through the template
522 ClearPage.copyFile(false, f, out);
523 writePage(f, convertExtension(out, Doclava.htmlExtension), subdir);
524 files.add(name);
525
526 }
527 // else ignored
528 } else if (f.isDirectory()) {
529 writeDirectory(f, relative + name + "/", offline);
530 dirs.add(name);
531 }
532 }
533
534 // write the index page
535 int i;
536
537 Data hdf = writeIndex(dir);
538 hdf.setValue("subdir", subdir);
539 i = 0;
540 for (String d : dirs) {
541 hdf.setValue("subdirs." + i + ".Name", d);
542 hdf.setValue("files." + i + ".Href", convertExtension(d, ".html"));
543 i++;
544 }
545 i = 0;
546 for (String f : files) {
547 hdf.setValue("files." + i + ".Name", f);
548 hdf.setValue("files." + i + ".Href", convertExtension(f, ".html"));
549 i++;
550 }
551
552 if (!offline) relative = "/" + relative;
553 ClearPage.write(hdf, "sampleindex.cs", relative + "index" + Doclava.htmlExtension);
554 }
555
556 /**
557 * @deprecated
558 */
559 public void writeIndexOnly(File dir, String relative, Boolean offline) {
560 Data hdf = writeIndex(dir);
561 if (!offline) relative = "/" + relative;
562
563 System.out.println("writing indexonly at " + relative + "/index" + Doclava.htmlExtension);
564 ClearPage.write(hdf, "sampleindex.cs", relative + "index" + Doclava.htmlExtension);
565 }
566
567 /**
568 * @deprecated
569 */
570 public Data writeIndex(File dir) {
571 Data hdf = Doclava.makeHDF();
572 hdf.setValue("page.title", dir.getName() + " - " + mTitle);
573 hdf.setValue("projectTitle", mTitle);
574
575 String filename = dir.getPath() + "/_index.html";
576 String summary =
577 SampleTagInfo.readFile(new SourcePositionInfo(filename, -1, -1), filename, "sample code",
578 true, false, false, true);
579
580 if (summary == null) {
581 summary = "";
582 }
583 hdf.setValue("summary", summary);
584
585 return hdf;
586 }
587
Ben Dodson920dbbb2010-08-04 15:21:06 -0700588}