Doclava: Add support for building samples toc from contents of a target browsable dir.
(cherry picked from commit 7537229470687560714401104558abdf82f81441)
Change-Id: I26cbdde207040d1b5db5ccb1793d396567fd4163
diff --git a/src/com/google/doclava/DocFile.java b/src/com/google/doclava/DocFile.java
index 83d04e4..a00bac5 100644
--- a/src/com/google/doclava/DocFile.java
+++ b/src/com/google/doclava/DocFile.java
@@ -73,6 +73,47 @@
return outFrag;
}
+ public static Data getPageMetadata (String docfile, Data hdf) {
+ //utility method for extracting metadata without generating file output.
+ if (hdf == null) {
+ hdf = Doclava.makeHDF();
+ }
+ String filedata = readFile(docfile);
+
+ // The document is properties up until the line "@jd:body".
+ // Any blank lines are ignored.
+ int start = -1;
+ int lineno = 1;
+ Matcher lines = LINE.matcher(filedata);
+ String line = null;
+ while (lines.find()) {
+ line = lines.group(1);
+ if (line.length() > 0) {
+ if (line.equals("@jd:body")) {
+ start = lines.end();
+ break;
+ }
+ Matcher prop = PROP.matcher(line);
+ if (prop.matches()) {
+ String key = prop.group(1);
+ String value = prop.group(2);
+ hdf.setValue(key, value);
+ } else {
+ break;
+ }
+ }
+ lineno++;
+ }
+ if (start < 0) {
+ System.err.println(docfile + ":" + lineno + ": error parsing docfile");
+ if (line != null) {
+ System.err.println(docfile + ":" + lineno + ":" + line);
+ }
+ System.exit(1);
+ }
+ return hdf;
+ }
+
public static void writePage(String docfile, String relative, String outfile, Data hdf) {
/*
@@ -166,6 +207,9 @@
} else if (filename.indexOf("samples") == 0) {
hdf.setValue("samples", "true");
hdf.setValue("page.type", "samples");
+ if (Doclava.samplesNavTree != null) {
+ hdf.setValue("samples_toc_tree", Doclava.samplesNavTree.getValue("samples_toc_tree", ""));
+ }
} else if (filename.indexOf("distribute") == 0) {
hdf.setValue("distribute", "true");
hdf.setValue("page.type", "distribute");