| 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 |
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 |
|
| 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 |
|
| 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 |
|
| 88 |
|
| 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 |
|
| 99 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 146 |
return "[[#" + name + "|" + name + "]]"; |
| 147 |
} else { |
| 148 |
|
| 149 |
return "[[#<" + name + "> element|" + name + "]]"; |
| 150 |
} |
| 151 |
} |
| 152 |
} |