2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - Calixte DENIZET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 package org.scilab.modules.helptools;
15 import java.io.FileOutputStream;
16 import java.io.IOException;
17 import java.io.OutputStreamWriter;
18 import java.nio.charset.Charset;
19 import java.util.Iterator;
21 import org.xml.sax.SAXException;
24 * Class to convert DocBook to JavaHelp
25 * @author Calixte DENIZET
27 public class JavaHelpDocbookTagConverter extends HTMLDocbookTagConverter {
29 private static final String XMLSTRING = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n";
31 private StringBuilder buffer = new StringBuilder(8192);
35 * @param inName the name of the input stream
36 * @param outName the output directory
37 * @param primConf the file containing the primitives of Scilab
38 * @param macroConf the file containing the macros of Scilab
39 * @param template the template to use
40 * @param version the version
41 * @param imageDir the image directory (relative to outName)
42 * @param isToolbox is true when compile a toolbox' help
43 * @param urlBase the base url for external link
45 public JavaHelpDocbookTagConverter(String inName, String outName, String[] primConf, String[] macroConf, String template, String version, String imageDir, boolean isToolbox, String urlBase, String language) throws IOException, SAXException {
46 super(inName, outName, primConf, macroConf, template, version, imageDir, isToolbox, urlBase, language, HTMLDocbookTagConverter.GenerationType.JAVAHELP);
47 prependToProgramListing = "<table border=\"0\" width=\"100%\"><tr><td width=\"98%\">";
48 appendToProgramListing = "</td><td valign=\"top\"><a href=\"scilab://scilab.execexample/\"><img src=\"ScilabExecute.png\" border=\"0\"/></a></td><td valign=\"top\"><a href=\"scilab://scilab.editexample/\"><img src=\"ScilabEdit.png\" border=\"0\"/></a></td><td></td></tr></table>";
49 appendForExecToProgramListing = "</td><td valign=\"top\"><a href=\"scilab://scilab.execexample/\"><img src=\"ScilabExecute.png\" border=\"0\"/></a></td><td></td></tr></table>";
55 public void endDocument() throws SAXException {
57 FileOutputStream outToc = new FileOutputStream("jhelptoc.xml");
58 FileOutputStream outMap = new FileOutputStream("jhelpmap.jhm");
59 FileOutputStream outSet = new FileOutputStream("jhelpset.hs");
60 FileOutputStream outIndex = new FileOutputStream("jhelpidx.xml");
61 OutputStreamWriter writerIndex = new OutputStreamWriter(outIndex, Charset.forName("UTF-8"));
62 OutputStreamWriter writerSet = new OutputStreamWriter(outSet, Charset.forName("UTF-8"));
63 OutputStreamWriter writerMap = new OutputStreamWriter(outMap, Charset.forName("UTF-8"));
64 OutputStreamWriter writerToc = new OutputStreamWriter(outToc, Charset.forName("UTF-8"));
65 writerMap.append(XMLSTRING);
66 writerMap.append("<!DOCTYPE map PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\" \"http://java.sun.com/products/javahelp/map_1_0.dtd\">\n");
67 writerMap.append(convertMapId());
73 writerToc.append(XMLSTRING);
74 writerToc.append("<!DOCTYPE toc PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN\" \"http://java.sun.com/products/javahelp/toc_1_0.dtd\">\n");
75 writerToc.append(convertTocItem());
81 writerSet.append(XMLSTRING);
82 String str = "<!DOCTYPE helpset\n PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN\" \"http://java.sun.com/products/javahelp/helpset_1_0.dtd\">\n<helpset version=\"1.0\">\n<title>TITLE</title>\n<maps>\n<homeID>top</homeID>\n<mapref location=\"jhelpmap.jhm\"/>\n</maps>\n<view>\n<name>TOC</name>\n<label>Table Of Contents</label>\n<type>javax.help.TOCView</type>\n<data>jhelptoc.xml</data>\n</view>\n<view>\n<name>Index</name>\n<label>Index</label>\n<type>javax.help.IndexView</type>\n<data>jhelpidx.xml</data>\n</view>\n<view>\n<name>Search</name>\n<label>Search</label>\n<type>javax.help.SearchView</type>\n<data engine=\"com.sun.java.help.search.DefaultSearchEngine\">JavaHelpSearch</data>\n</view>\n</helpset>".replaceFirst("TITLE", bookTitle);
83 writerSet.append(str);
89 writerIndex.append(XMLSTRING);
90 writerIndex.append("<!DOCTYPE index PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Index Version 1.0//EN\" \"http://java.sun.com/products/javahelp/index_1_0.dtd\">\n<index version=\"1.0\"/>");
95 } catch (IOException e) {
96 fatalExceptionOccured(e);
103 protected String makeRemoteLink(String link) {
104 return "file://SCI/modules/" + link;
107 private String convertMapId() {
109 buffer.append("<map version=\"1.0\">\n<mapID target=\"index\" url=\"index.html\"/>\n");
111 buffer.append("<mapID target=\"whatsnew\" url=\"ScilabHomePage.html\"/>\n");
113 Iterator<String> iter = mapId.keySet().iterator();
114 while (iter.hasNext()) {
115 String id = iter.next();
116 buffer.append("<mapID target=\"");
118 buffer.append("\" url=\"");
119 buffer.append(mapId.get(id));
120 buffer.append("\"/>\n");
122 buffer.append("</map>");
124 return buffer.toString();
127 private void convertTreeId(HTMLDocbookLinkResolver.TreeId leaf) {
128 if (leaf.children != null) {
129 for (HTMLDocbookLinkResolver.TreeId c : leaf.children) {
130 buffer.append("<tocitem target=\"");
132 buffer.append("\" text=\"");
133 buffer.append(tocitem.get(c.id));
134 if (c.children == null) {
135 buffer.append("\"/>\n");
137 buffer.append("\">\n");
139 buffer.append("</tocitem>\n");
145 private String convertTocItem() {
147 buffer.append("<toc version=\"1.0\">\n<tocitem target=\"index\" text=\"" + bookTitle + "\">\n");
149 buffer.append("<tocitem target=\"whatsnew\" text=\"Scilab Home\"/>\n");
152 buffer.append("</tocitem>\n</toc>");
154 return buffer.toString();