treeFile = treeFile
[jalview.git] / utils / help2Website.java
1 import java.io.*;\r
2 import java.util.*;\r
3 \r
4 public class help2Website\r
5 {\r
6 \r
7         public static void main(String [] args)\r
8         {\r
9                 String line = "";\r
10                 try{\r
11                         Hashtable targets = new Hashtable();\r
12 \r
13                         File toc = new File("helpTOC.xml");\r
14                         File jhm = new File("help.jhm");\r
15 \r
16                         BufferedReader in = new BufferedReader(new FileReader(jhm));\r
17 \r
18                         PrintWriter out = new PrintWriter(new FileWriter("helpTOC.html"));\r
19                         out.println("<html><head></head><title>Jalview - Help </title></head>\n"\r
20                         +"<body bgcolor=#F1F1F1>\n"\r
21                         +"<p><center><strong>Contents</strong></center></p>\n");\r
22 \r
23 \r
24                         StringTokenizer st;\r
25                         StringBuffer indent = new StringBuffer();\r
26                         String target, url, text;\r
27                         while( (line = in.readLine()) != null)\r
28                         {\r
29                                 if(line.indexOf("target")==-1)\r
30                                         continue;\r
31 \r
32 \r
33                                 st = new StringTokenizer(line, "\"");\r
34                                 st.nextToken(); //<mapID target="\r
35 \r
36                                 target = st.nextToken();\r
37                                 st.nextToken(); //" url="\r
38 \r
39                                 url = st.nextToken();\r
40                                 targets.put(target, url);\r
41                         }\r
42 \r
43                         in = new BufferedReader(new FileReader(toc));\r
44                         while( (line = in.readLine()) != null)\r
45                         {\r
46                                 if(line.indexOf("</tocitem>")!=-1)\r
47                                         indent.setLength(indent.length()-18);\r
48 \r
49                                 if(line.indexOf("<tocitem")==-1)\r
50                                         continue;\r
51 \r
52                                 st = new StringTokenizer(line, "\"");\r
53                                 st.nextToken();\r
54 \r
55                                 text = st.nextToken();\r
56                                 st.nextToken();\r
57 \r
58                                 target = st.nextToken();\r
59 \r
60                                 if(targets.get(target)!=null)\r
61                                         out.println("<br>"+indent+"<a href=\""\r
62                                                         + targets.get(target)\r
63                                                         +"\" target=bodyframe>"\r
64                                                         +text\r
65                                                         +"</a>");\r
66                                 else\r
67                                         out.println("<br>"+indent+text);\r
68 \r
69 \r
70                                 if(line.indexOf("/>")==-1)\r
71                                         indent.append("&nbsp;&nbsp;&nbsp;");\r
72 \r
73                         }\r
74 \r
75                         out.println("</body>\n</html>");\r
76 \r
77 \r
78                         out.close();\r
79 \r
80                 }\r
81 \r
82                 catch(Exception ex)\r
83                 {\r
84 \r
85                         ex.printStackTrace();\r
86 \r
87                         System.out.println("\n"+line+"\n");\r
88 \r
89                         System.out.println("Usage: move to Help directory. help2Website will read"\r
90                         +"\nhelpTOC.xml and help.jhm producing output helpTOC.html");\r
91                 }\r
92         }\r
93 \r
94 \r
95 }