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