JAL-1432 updated copyright notices
[jalview.git] / utils / help2Website.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
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                                 {
80                                         out.println("<br>"+indent+"<a href=\""
81                                                         + targets.get(target)
82                                                         +"\" target=bodyframe>"
83                                                         +text
84                                                         +"</a>");
85                                 }
86                                 else
87                                         out.println("<br>"+indent+text);
88
89
90                                 if(line.indexOf("/>")==-1)
91                                         indent.append("&nbsp;&nbsp;&nbsp;");
92
93                         }
94                         // Add Googletracker.
95
96
97                         out.close();
98
99                 }
100
101                 catch(Exception ex)
102                 {
103
104                         ex.printStackTrace();
105
106                         System.out.println("\n"+line+"\n");
107
108                         System.out.println("Usage: move to Help directory. help2Website will read"
109                         +"\nhelpTOC.xml and help.jhm producing output helpTOC.html");
110                 }
111         }
112
113
114 }