6bb4dfcd5ad1f42d0a577747ca74e264c73f9642
[jalview.git] / utils / help2Website.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 import java.io.*;
20 import java.util.*;
21
22 public class help2Website
23 {
24
25         public static void main(String [] args)
26         {
27                 String line = "";
28                 try{
29                         Hashtable targets = new Hashtable();
30
31                         File toc = new File("helpTOC.xml");
32                         File jhm = new File("help.jhm");
33
34                         BufferedReader in = new BufferedReader(new FileReader(jhm));
35
36                         PrintWriter out = new PrintWriter(new FileWriter("helpTOC.html"));
37                         out.println("<html><head><title>Jalview - Help </title></head>\n"
38                         +"<body bgcolor=#F1F1F1>\n"
39                         +"<p><center><strong>Contents</strong></center></p>\n");
40
41
42                         StringTokenizer st;
43                         StringBuffer indent = new StringBuffer();
44                         String target, url, text;
45                         while( (line = in.readLine()) != null)
46                         {
47                                 if(line.indexOf("target")==-1)
48                                         continue;
49
50
51                                 st = new StringTokenizer(line, "\"");
52                                 st.nextToken(); //<mapID target="
53
54                                 target = st.nextToken();
55                                 st.nextToken(); //" url="
56
57                                 url = st.nextToken();
58                                 targets.put(target, url);
59                         }
60
61                         in = new BufferedReader(new FileReader(toc));
62                         while( (line = in.readLine()) != null)
63                         {
64                                 if(line.indexOf("</tocitem>")!=-1)
65                                         indent.setLength(indent.length()-18);
66
67                                 if(line.indexOf("<tocitem")==-1)
68                                         continue;
69
70                                 st = new StringTokenizer(line, "\"");
71                                 st.nextToken();
72
73                                 text = st.nextToken();
74                                 st.nextToken();
75
76                                 target = st.nextToken();
77
78                                 if(targets.get(target)!=null)
79                                         out.println("<br>"+indent+"<a href=\""
80                                                         + targets.get(target)
81                                                         +"\" target=bodyframe>"
82                                                         +text
83                                                         +"</a>");
84                                 else
85                                         out.println("<br>"+indent+text);
86
87
88                                 if(line.indexOf("/>")==-1)
89                                         indent.append("&nbsp;&nbsp;&nbsp;");
90
91                         }
92
93                         out.println("</body>\n</html>");
94
95
96                         out.close();
97
98                 }
99
100                 catch(Exception ex)
101                 {
102
103                         ex.printStackTrace();
104
105                         System.out.println("\n"+line+"\n");
106
107                         System.out.println("Usage: move to Help directory. help2Website will read"
108                         +"\nhelpTOC.xml and help.jhm producing output helpTOC.html");
109                 }
110         }
111
112
113 }