Merge branch 'patch/JAL-4036_uniprot_fts_legacy_endpoint' into develop
[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     {
32       Hashtable targets = new Hashtable();
33
34       File toc = new File("helpTOC.xml");
35       File jhm = new File("help.jhm");
36
37       BufferedReader in = new BufferedReader(new FileReader(jhm));
38
39       PrintWriter out = new PrintWriter(new FileWriter("helpTOC.html"));
40       out.println("<html><head><title>Jalview - Help </title></head>\n"
41               + "<body bgcolor=#F1F1F1>\n"
42               + "<p><center><strong>Contents</strong></center></p>\n");
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         st = new StringTokenizer(line, "\"");
53         st.nextToken(); // <mapID target="
54
55         target = st.nextToken();
56         st.nextToken(); // " url="
57
58         url = st.nextToken();
59         targets.put(target, url);
60       }
61
62       in = new BufferedReader(new FileReader(toc));
63       while ((line = in.readLine()) != null)
64       {
65         if (line.indexOf("</tocitem>") != -1)
66           indent.setLength(indent.length() - 18);
67
68         if (line.indexOf("<tocitem") == -1)
69           continue;
70
71         st = new StringTokenizer(line, "\"");
72         st.nextToken();
73
74         text = st.nextToken();
75         st.nextToken();
76
77         target = st.nextToken();
78
79         if (targets.get(target) != null)
80         {
81           out.println("<br>" + indent + "<a href=\"" + targets.get(target)
82                   + "\" target=bodyframe>" + text + "</a>");
83         }
84         else
85           out.println("<br>" + indent + text);
86
87         if (line.indexOf("/>") == -1)
88           indent.append("&nbsp;&nbsp;&nbsp;");
89
90       }
91       // Add Googletracker.
92
93       out.close();
94
95     }
96
97     catch (Exception ex)
98     {
99
100       ex.printStackTrace();
101
102       System.out.println("\n" + line + "\n");
103
104       System.out
105               .println("Usage: move to Help directory. help2Website will read"
106                       + "\nhelpTOC.xml and help.jhm producing output helpTOC.html");
107     }
108   }
109
110 }