Debian Codegraph @

src/dr/xml/WikiDocumentationHandler.java

raw symbols SCIP
1 /*
2 * WikiDocumentationHandler.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.xml;
27
28 import dr.app.beast.BeastParser;
29 import dr.app.tools.BeastParserDoc;
30
31 import java.io.*;
32 import java.text.SimpleDateFormat;
33 import java.util.*;
34
35 /**
36 * A subclass of XMLDocumentationHandler that creates output in MediaWiki format
37 */
38 public class WikiDocumentationHandler extends XMLDocumentationHandler {
39
40 private final static String WIKILINK = "[[Main Page|BEAST Documentation]]-> BEAST v1.5.x XML Reference";
41
42 public WikiDocumentationHandler(BeastParser parser) {
43 super(parser);
44 }
45
46 public void outputElements(PrintWriter writer) {
47
48 printDocWikiTitle(writer);
49
50 Iterator iterator = parser.getParsers();
51 while (iterator.hasNext()) {
52 XMLObjectParser xmlParser = (XMLObjectParser)iterator.next();
53 writer.println(xmlParser.toWiki(this));
54
55 // convert the html into wiki...
56
57 System.out.println(" outputting Wiki for element " + xmlParser.getParserName());
58 }
59
60 }
61
62 private void printDocWikiTitle(PrintWriter writer) {
63
64 Calendar date = Calendar.getInstance();
65 SimpleDateFormat dateformatter = new SimpleDateFormat("'updated on' d MMMM yyyy zzz");
66
67 writer.println(WIKILINK + "\n");
68 writer.println("==" + BeastParserDoc.TITLE + "==\n");
69
70 if (parser.parsers != null) {
71 if (parser.parsers.equalsIgnoreCase(BeastParser.RELEASE)) {
72 writer.println("Release Version (" + dateformatter.format(date.getTime()) + ")");
73 System.out.println("Release Version");
74 } else if (parser.parsers.equalsIgnoreCase(BeastParser.DEV)) {
75 writer.println("Development Version (" + dateformatter.format(date.getTime()) + ")");
76 System.out.println("Development Version");
77 }
78 }
79
80 writer.println("");
81 writer.println("The following is a list of valid elements in a beast file.");
82 writer.println("");
83
84 }
85
86 /**
87 * Outputs all types that appear as required attributes or elements in an HTML table to the given writer.
88 * @param writer PrintWriter
89 */
90 public void outputTypes(PrintWriter writer) {
91
92 writer.println("==BEAST types==");
93 writer.println("");
94 writer.println("The following is a list of generic types that elements represent in a beast file.");
95 writer.println("");
96
97
98 // iterate through the types
99 //Iterator iterator = requiredTypes.iterator();
100 for (Class requiredType : requiredTypes) {
101 if (requiredType != Object.class) {
102
103 String name = ClassComparator.getName(requiredType);
104
105 System.out.println(" outputting Wiki for generic type " + name);
106
107
108 TreeSet<String> matchingParserNames = new TreeSet<String>();
109
110 // find all parsers that match this required type
111 Iterator i = parser.getParsers();
112 while (i.hasNext()) {
113 XMLObjectParser xmlParser = (XMLObjectParser) i.next();
114 Class returnType = xmlParser.getReturnType();
115 if (requiredType.isAssignableFrom(returnType)) {
116 matchingParserNames.add(xmlParser.getParserName());
117 }
118 }
119
120 if (!(matchingParserNames.size() == 1 && matchingParserNames.iterator().next().equals(name))) {
121
122 // output table row containing the type and the matching parser names
123 writer.println("===" + name + "===");
124 writer.println();
125 writer.println("Elements of this type include:");
126 writer.println();
127 i = matchingParserNames.iterator();
128 while (i.hasNext()) {
129 String parserName = (String) i.next();
130 writer.println(":*" + getWikiLink(parserName));
131 }
132 writer.println();
133 }
134 }
135
136 }
137 }
138
139 public String getHTMLForClass(Class c) {
140 return getWikiLink(ClassComparator.getName(c));
141 }
142
143 public String getWikiLink(String name) {
144 if (Character.isUpperCase(name.charAt(0))) {
145 // linking to a 'type'
146 return "[[#" + name + "|" + name + "]]";
147 } else {
148 // linking to an 'element'
149 return "[[#&lt;" + name + "&gt; element|" + name + "]]";
150 }
151 }
152 }