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;
16 import java.io.IOException;
18 import java.net.URISyntaxException;
19 import java.util.Date;
21 import java.util.Stack;
22 import java.util.regex.Pattern;
24 import org.xml.sax.SAXException;
26 import org.scilab.modules.helptools.image.ImageConverter;
27 import org.scilab.modules.helptools.image.LaTeXImageConverter;
28 import org.scilab.modules.helptools.image.MathMLImageConverter;
29 import org.scilab.modules.helptools.image.ScilabImageConverter;
30 import org.scilab.modules.helptools.image.SVGImageConverter;
31 import org.scilab.modules.helptools.scilab.ScilabLexer;
32 import org.scilab.modules.helptools.scilab.HTMLScilabCodeHandler;
33 import org.scilab.modules.helptools.scilab.AbstractScilabCodeHandler;
34 import org.scilab.modules.helptools.XML.XMLLexer;
35 import org.scilab.modules.helptools.XML.HTMLXMLCodeHandler;
36 import org.scilab.modules.helptools.c.CLexer;
37 import org.scilab.modules.helptools.c.HTMLCCodeHandler;
38 import org.scilab.modules.helptools.java.JavaLexer;
39 import org.scilab.modules.localization.Messages;
42 * Class to convert DocBook to HTML
43 * @author Calixte DENIZET
45 public class HTMLDocbookTagConverter extends DocbookTagConverter implements TemplateFiller {
47 private static final String SCILAB_URI = "http://www.scilab.org";
48 private static final String LATEXBASENAME = "Equation_LaTeX_";
49 private static final String VERSION = Messages.gettext("Version");
50 private static final String DESCRIPTION = Messages.gettext("Description");
52 private StringBuilder buffer = new StringBuilder(8192);
53 private int latexCompt;
54 private String imageDir;
55 private String outName;
56 private String urlBase;
57 private boolean linkToTheWeb;
58 private boolean hasExamples;
62 protected Map<String, String> mapId;
63 protected Map<String, String> tocitem;
64 protected HTMLDocbookLinkResolver.TreeId tree;
65 protected Map<String, HTMLDocbookLinkResolver.TreeId> mapTreeId;
66 protected Map<String, String> mapIdPurpose;
68 protected TemplateHandler templateHandler;
70 protected ScilabLexer scilabLexer;
71 protected XMLLexer xmlLexer;
72 protected CLexer cLexer;
73 protected JavaLexer javaLexer;
75 protected String bookTitle = "";
76 protected String partTitle = "";
77 protected String chapterTitle = "";
78 protected String sectionTitle = "";
79 protected String fileSubtitle = "";
81 protected String refpurpose = "";
82 protected String refname = "";
83 protected String version;
84 protected String appendToProgramListing;
85 protected String appendForExecToProgramListing;
86 protected String prependToProgramListing;
87 protected String currentId;
88 protected String indexFilename = "index" /*UUID.randomUUID().toString()*/ + ".html";
90 protected boolean isToolbox;
94 * @param inName the name of the input stream
95 * @param outName the output directory
96 * @param primConf the file containing the primitives of Scilab
97 * @param macroConf the file containing the macros of Scilab
98 * @param template the template to use
99 * @param version the version
100 * @param imageDir the image directory (relative to outName)
101 * @param isToolbox is true when compile a toolbox' help
102 * @param urlBase the base url for external link
104 public HTMLDocbookTagConverter(String inName, String outName, String[] primConf, String[] macroConf, String template, String version, String imageDir, boolean isToolbox, String urlBase) throws IOException, SAXException {
107 this.version = version;
108 this.imageDir = imageDir;
109 this.outName = outName + File.separator;
110 HTMLDocbookLinkResolver resolver = new HTMLDocbookLinkResolver(inName);
111 mapId = resolver.getMapId();
112 tocitem = resolver.getToc();
113 tree = resolver.getTree();
114 mapTreeId = resolver.getMapTreeId();
115 mapIdPurpose = resolver.getMapIdPurpose();
116 scilabLexer = new ScilabLexer(primConf, macroConf);
117 this.urlBase = urlBase;
118 this.linkToTheWeb = urlBase != null && !urlBase.equals("scilab://");
119 this.isToolbox = isToolbox;
120 if (isToolbox) {// we generate a toolbox's help
121 HTMLScilabCodeHandler.setLinkWriter(new AbstractScilabCodeHandler.LinkWriter() {
122 public String getLink(String id) {
123 if (id.length() > 0 && id.charAt(0) == '%') {
124 id = id.replace("%", "percent");
126 String link = mapId.get(id);
128 return HTMLDocbookTagConverter.this.urlBase + id;
134 } else {// we generate Scilab's help
135 HTMLScilabCodeHandler.setLinkWriter(new AbstractScilabCodeHandler.LinkWriter() {
136 public String getLink(String id) {
137 if (id.length() > 0 && id.charAt(0) == '%') {
138 id = id.replace("%", "percent");
140 return mapId.get(id);
145 xmlLexer = new XMLLexer();
146 cLexer = new CLexer();
147 javaLexer = new JavaLexer();
148 File tpl = new File(template);
149 templateHandler = new TemplateHandler(this, tpl);
150 ImageConverter.registerExternalImageConverter(LaTeXImageConverter.getInstance());
151 ImageConverter.registerExternalImageConverter(MathMLImageConverter.getInstance());
152 ImageConverter.registerExternalImageConverter(SVGImageConverter.getInstance());
153 ImageConverter.registerExternalImageConverter(ScilabImageConverter.getInstance());
157 * @return the buffer used
159 public StringBuilder getBuffer() {
164 * @param tag the tag name
165 * @param contents the contents to enclose between opening and closing tags
167 public String encloseContents(final String tag, final String contents) {
172 if (contents != null) {
173 buffer.append(contents);
179 return buffer.toString();
183 * @param tag the tag name
184 * @param attrs the attributes {attr1, value1, attr2, value2, ...}
185 * @param contents the contents to enclose between opening and closing tags
187 public String encloseContents(final String tag, final String[] attrs, final String contents) {
192 for (int i = 0; i < attrs.length; i += 2) {
194 buffer.append(attrs[i]);
195 buffer.append("=\"");
196 buffer.append(attrs[i + 1]);
202 if (contents != null) {
203 buffer.append(contents);
209 return buffer.toString();
213 * @param tag the tag name
214 * @param clazz the css class name
215 * @param contents the contents to enclose between opening and closing tags
217 public String encloseContents(final String tag, final String clazz, final String contents) {
221 buffer.append(" class=\"");
222 buffer.append(clazz);
223 buffer.append("\">");
224 if (contents != null) {
225 buffer.append(contents);
231 return buffer.toString();
237 public boolean isEscapable(final String tagName, final String uri) {
238 return !"latex".equals(tagName) && !"screen".equals(tagName) && !"programlisting".equals(tagName) && !"synopsis".equals(tagName) && !(uri.equals(SCILAB_URI) && tagName.equals("image"));
244 public boolean isTrimable(final String tagName) {
245 return !"screen".equals(tagName) && !"programlisting".equals(tagName) && !"synopsis".equals(tagName);
249 * @param fileName the file to create
250 * @param subtitle the subtitle of the file
251 * @param contents the contents of the file
253 public void createHTMLFile(final String id, final String fileName, final String subtitle, final String contents) {
255 fileSubtitle = subtitle;
257 templateHandler.generateFileFromTemplate(outName + fileName, id, contents);
264 public String makeTitle(final String id) {
265 if (refname.length() > 0) {
266 return tocitem.get(id);
275 public String makeSubtitle(final String id) {
282 public String makePrevious(final String id) {
284 buffer.append("<span class=\"previous\">");
285 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
289 HTMLDocbookLinkResolver.TreeId prev = leaf.getPrevious();
290 if (prev.parent != null) {
291 buffer.append("<a href=\"");
292 buffer.append(mapId.get(prev.id));
293 buffer.append("\"><< ");
294 buffer.append(tocitem.get(prev.id));
295 buffer.append("</a></span>\n");
297 return buffer.toString();
306 public String makePath(final String id) {
308 buffer.append("<span class=\"path\">");
309 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
313 String str = tocitem.get(id);
315 while (leaf != null && !leaf.isRoot()) {
316 str = "<a href=\"" + mapId.get(leaf.id) + "\">" + tocitem.get(leaf.id) + "</a> > " + str;
320 str = "<a href=\"" + indexFilename + "\">" + bookTitle + "</a> >> " + str;
322 buffer.append("</span>\n");
324 return buffer.toString();
330 public String makeTop(final String id) {
332 buffer.append("<span class=\"top\">");
333 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
340 buffer.append("<a href=\"");
341 if (!leaf.isRoot()) {
342 buffer.append(mapId.get(leaf.id));
343 buffer.append("\">");
344 buffer.append(tocitem.get(leaf.id));
346 buffer.append(indexFilename);
347 buffer.append("\">");
348 buffer.append(bookTitle);
350 buffer.append("</a></span>\n");
355 return buffer.toString();
361 public String makeNext(final String id) {
363 buffer.append("<span class=\"next\">");
364 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
368 HTMLDocbookLinkResolver.TreeId next = leaf.getNext();
370 buffer.append("<a href=\"");
371 buffer.append(mapId.get(next.id));
372 buffer.append("\">");
373 buffer.append(tocitem.get(next.id));
374 buffer.append(" >></a></span>\n");
376 return buffer.toString();
385 public String makeStart(final String id) {
387 buffer.append("<span class=\"start\">");
388 buffer.append("<a href=\"");
389 buffer.append(indexFilename);
390 buffer.append("\">");
391 buffer.append(bookTitle);
392 buffer.append("</a></span>\n");
394 return buffer.toString();
400 public String makeTocList(final String id) {
402 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
407 HTMLDocbookLinkResolver.TreeId parent = leaf.parent;
408 buffer.append("<ul class=\"toc\">\n");
410 while (parent != null && !parent.isRoot()) {
411 str = "<li class=\"parent\"><a href=\"" + mapId.get(parent.id) + "\">" + tocitem.get(parent.id) + "</a></li>\n" + str;
412 parent = parent.parent;
414 buffer.append("<li class=\"root\"><a href=\"");
415 buffer.append(indexFilename);
416 buffer.append("\">");
417 buffer.append(bookTitle);
418 buffer.append("</a></li>\n");
421 parent = leaf.parent;
423 for (HTMLDocbookLinkResolver.TreeId c : parent.children) {
425 buffer.append("<li class=\"list-active\"><a href=\"");
427 buffer.append("<li><a href=\"");
429 buffer.append(mapId.get(c.id));
430 buffer.append("\">");
431 buffer.append(tocitem.get(c.id));
432 buffer.append("</a></li>\n");
434 buffer.append("</ul>\n");
436 return buffer.toString();
442 public String makeLastModified(final String id) {
445 buffer.append("<span class=\"lastmodified\">");
446 buffer.append(new Date(new File(new URI(currentFileName)).lastModified()).toString());
447 buffer.append("</span>\n");
448 } catch (URISyntaxException e) {
451 return buffer.toString();
457 public String makeGenerationDate(final String id) {
459 buffer.append("<span class=\"generationdate\">");
460 buffer.append(new Date(System.currentTimeMillis()).toString());
461 buffer.append("</span>\n");
463 return buffer.toString();
469 public String makeVersion(final String id) {
471 buffer.append("<span class=\"version\">");
472 buffer.append(version);
473 buffer.append("</span>\n");
475 return buffer.toString();
480 * @param attributes the tag attributes
481 * @param contents the tag contents
482 * @return the HTML code
483 * @throws SAXEception if an error is encountered
485 public String handleRefentry(final Map<String, String> attributes, final String contents) throws SAXException {
486 String id = attributes.get("id");
490 String fileName = mapId.get(currentId);
491 createHTMLFile(currentId, fileName, refpurpose, contents);
494 //System.err.println("Warning (should be fixed): no example in " + currentFileName);
498 String rp = encloseContents("span", "refentry-description", refpurpose);
499 String str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "refentry"}, currentId) + " — " + rp);
509 * @param attributes the tag attributes
510 * @param contents the tag contents
511 * @return the HTML code
512 * @throws SAXEception if an error is encountered
514 public String handleSection(final Map<String, String> attributes, final String contents) throws SAXException {
515 String fileName = attributes.get("id") + ".html";
516 String str = encloseContents("ul", "list-refentry", contents);
517 String title = encloseContents("h3", "title-section", sectionTitle);
518 createHTMLFile(attributes.get("id"), fileName, sectionTitle, title + "\n" + str);
520 str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "section"}, sectionTitle) + "\n" + str);
528 * @param attributes the tag attributes
529 * @param contents the tag contents
530 * @return the HTML code
531 * @throws SAXEception if an error is encountered
533 public String handleBook(final Map<String, String> attributes, final String contents) throws SAXException {
534 String str = encloseContents("ul", "list-part", contents);
536 if (bookTitle.trim().equalsIgnoreCase("Scilab")) {
541 String title = encloseContents("h3", "book-title", btitle);
542 createHTMLFile("index", indexFilename, btitle, title + "\n" + str);
545 System.err.println("Total files without example: " + warnings);
546 System.err.println("Total generated html files: " + nbFiles);
549 return encloseContents("li", encloseContents("a", new String[] {"href", indexFilename, "class", "part"}, bookTitle) + "\n" + str);
554 * @param attributes the tag attributes
555 * @param contents the tag contents
556 * @return the HTML code
557 * @throws SAXEception if an error is encountered
559 public String handlePart(final Map<String, String> attributes, final String contents) throws SAXException {
560 String fileName = attributes.get("id") + ".html";
561 String str = encloseContents("ul", "list-chapter", contents);
562 String title = encloseContents("h3", "title-part", partTitle);
563 createHTMLFile(attributes.get("id"), fileName, partTitle, title + "\n" + str);
565 str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "part"}, partTitle) + "\n" + str);
573 * @param attributes the tag attributes
574 * @param contents the tag contents
575 * @return the HTML code
576 * @throws SAXEception if an error is encountered
578 public String handleChapter(final Map<String, String> attributes, final String contents) throws SAXException {
579 String fileName = attributes.get("id") + ".html";
580 String str = encloseContents("ul", "list-refentry", contents);
581 String title = encloseContents("h3", "title-chapter", chapterTitle);
582 createHTMLFile(attributes.get("id"), fileName, chapterTitle, title + "\n" + str);
584 str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "chapter"}, chapterTitle) + "\n" + str);
590 // partiellement merdique car le style de title depend du noeud pere.
593 * @param attributes the tag attributes
594 * @param contents the tag contents
595 * @return the HTML code
596 * @throws SAXEception if an error is encountered
598 public String handleTitle(final Map<String, String> attributes, final String contents) throws SAXException {
599 String clazz = "title";
600 String parent = getParentTagName();
601 if (parent.equals("chapter")) {
602 chapterTitle = contents;
603 } else if (parent.equals("part")) {
604 partTitle = contents;
605 } else if (parent.equals("info")) {
606 bookTitle = contents;
607 } else if (parent.equals("section")) {
608 sectionTitle = contents;
609 } else if (parent.equals("refsection") && Pattern.matches("^[ \\t]*ex[ea]mpl[eo].*", contents.toLowerCase())) {
611 return encloseContents("h3", clazz, contents);
613 return encloseContents("h3", clazz, contents);
621 * @param attributes the tag attributes
622 * @param contents the tag contents
623 * @return the HTML code
624 * @throws SAXEception if an error is encountered
626 public String handlePara(final Map<String, String> attributes, final String contents) throws SAXException {
627 return encloseContents("p", "para", contents);
632 * @param attributes the tag attributes
633 * @param contents the tag contents
634 * @return the HTML code
635 * @throws SAXEception if an error is encountered
637 public String handleLiteral(final Map<String, String> attributes, final String contents) throws SAXException {
638 return encloseContents("code", "literal", contents);
642 * Handle a refnamediv
643 * @param attributes the tag attributes
644 * @param contents the tag contents
645 * @return the HTML code
646 * @throws SAXEception if an error is encountered
648 public String handleRefnamediv(final Map<String, String> attributes, final String contents) throws SAXException {
649 String id = attributes.get("id");
654 return encloseContents("div", "refnamediv", contents);
659 * @param attributes the tag attributes
660 * @param contents the tag contents
661 * @return the HTML code
662 * @throws SAXEception if an error is encountered
664 public String handleRefname(final Map<String, String> attributes, final String contents) throws SAXException {
666 return encloseContents("h1", "refname", contents);
670 * Handle a refpurpose
671 * @param attributes the tag attributes
672 * @param contents the tag contents
673 * @return the HTML code
674 * @throws SAXEception if an error is encountered
676 public String handleRefpurpose(final Map<String, String> attributes, final String contents) throws SAXException {
677 refpurpose = contents;
678 return encloseContents("p", "refpurpose", contents);
682 * Handle a refsynopsisdiv
683 * @param attributes the tag attributes
684 * @param contents the tag contents
685 * @return the HTML code
686 * @throws SAXEception if an error is encountered
688 public String handleRefsynopsisdiv(final Map<String, String> attributes, final String contents) throws SAXException {
689 String id = attributes.get("id");
691 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "refsynopsisdiv", contents);
693 return encloseContents("div", "refsynopsisdiv", contents);
699 * @param attributes the tag attributes
700 * @param contents the tag contents
701 * @return the HTML code
702 * @throws SAXEception if an error is encountered
704 public String handleSynopsis(final Map<String, String> attributes, final String contents) throws SAXException {
705 String id = attributes.get("id");
706 String str = encloseContents("div", "synopsis", encloseContents("pre", SynopsisLexer.convert(refname, contents)));
708 return "<a name=\"" + id + "\"></a>" + str;
716 * @param attributes the tag attributes
717 * @param contents the tag contents
718 * @return the HTML code
719 * @throws SAXEception if an error is encountered
721 public String handleInfo(final Map<String, String> attributes, final String contents) throws SAXException {
722 String id = attributes.get("id");
724 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "info", contents);
726 return encloseContents("div", "info", contents);
731 * Handle a refsection
732 * @param attributes the tag attributes
733 * @param contents the tag contents
734 * @return the HTML code
735 * @throws SAXEception if an error is encountered
737 public String handleRefsection(final Map<String, String> attributes, final String contents) throws SAXException {
738 String id = attributes.get("id");
740 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "refsection", contents);
742 return encloseContents("div", "refsection", contents);
747 * Handle a progamlisting
748 * @param attributes the tag attributes
749 * @param contents the tag contents
750 * @return the HTML code
751 * @throws SAXEception if an error is encountered
753 public String handleProgramlisting(final Map<String, String> attributes, final String contents) throws SAXException {
754 String id = attributes.get("id");
755 String role = attributes.get("role");
758 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
759 if (prependToProgramListing != null) {
760 code = prependToProgramListing + code;
762 if (appendToProgramListing != null) {
763 code += appendToProgramListing;
765 str = encloseContents("div", "programlisting", code);
767 if (role.equals("xml")) {
768 str = encloseContents("div", "programlisting", encloseContents("pre", "xmlcode", xmlLexer.convert(HTMLXMLCodeHandler.getInstance(), contents)));
769 } else if (role.equals("c") || role.equals("cpp") || role.equals("code_gateway")) {
770 str = encloseContents("div", "programlisting", encloseContents("pre", "ccode", cLexer.convert(HTMLCCodeHandler.getInstance(), contents)));
771 } else if (role.equals("java")) {
772 str = encloseContents("div", "programlisting", encloseContents("pre", "ccode", javaLexer.convert(HTMLCCodeHandler.getInstance(), contents)));
773 } else if (role.equals("exec")) {
774 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
775 if (prependToProgramListing != null) {
776 code = prependToProgramListing + code;
778 if (appendForExecToProgramListing != null) {
779 code += appendForExecToProgramListing;
781 str = encloseContents("div", "programlisting", code);
782 } else if (role.equals("no-scilab-exec")) {
783 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
784 str = encloseContents("div", "programlisting", code);
786 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
787 if (prependToProgramListing != null) {
788 code = prependToProgramListing + code;
790 if (appendToProgramListing != null) {
791 code += appendToProgramListing;
793 str = encloseContents("div", "programlisting", code);
797 return "<a name=\"" + id + "\"></a>" + str;
805 * @param attributes the tag attributes
806 * @param contents the tag contents
807 * @return the HTML code
808 * @throws SAXEception if an error is encountered
810 public String handleScreen(final Map<String, String> attributes, final String contents) throws SAXException {
811 String id = attributes.get("id");
812 String str = encloseContents("div", "screen", encloseContents("pre", contents));
814 return "<a name=\"" + id + "\"></a>" + str;
822 * @param attributes the tag attributes
823 * @param contents the tag contents
824 * @return the HTML code
825 * @throws SAXEception if an error is encountered
827 public String handlePubdate(final Map<String, String> attributes, final String contents) throws SAXException {
832 * Handle a simplelist
833 * @param attributes the tag attributes
834 * @param contents the tag contents
835 * @return the HTML code
836 * @throws SAXEception if an error is encountered
838 public String handleSimplelist(final Map<String, String> attributes, final String contents) throws SAXException {
839 String style = "itemizedlist";
841 return encloseContents("ul", style, contents);
846 * @param attributes the tag attributes
847 * @param contents the tag contents
848 * @return the HTML code
849 * @throws SAXEception if an error is encountered
851 public String handleMember(final Map<String, String> attributes, final String contents) throws SAXException {
852 return encloseContents("li", "member", contents);
857 * @param attributes the tag attributes
858 * @param contents the tag contents
859 * @return the HTML code
860 * @throws SAXEception if an error is encountered
862 public String handleLink(final Map<String, String> attributes, final String contents) throws SAXException {
863 String link = attributes.get("linkend");
865 throw new SAXException("No linkend attribute in tag link");
868 String type = attributes.get("type");
870 if (type != null && type.equals("scilab")) {
871 id = resolvScilabLink(link);
872 } else if (type != null && type.equals("remote")) {
873 id = makeRemoteLink(link);
875 id = mapId.get(link);
880 System.err.println("Warning (should be fixed): invalid internal link to " + link + " in " + currentFileName + "\nat line " + locator.getLineNumber());
884 Stack<DocbookElement> stack = getStack();
885 int s = stack.size();
887 DocbookElement elem = stack.get(s - 3);
888 if (elem.getName().equals("refsection")) {
889 String role = elem.getAttributes().get("role");
890 if (role != null && role.equals("see also")) {
891 String purpose = mapIdPurpose.get(link);
892 if (purpose != null) {
893 return encloseContents("a", new String[] {"href", id, "class", "link"}, contents) + " — " + purpose;
895 return encloseContents("a", new String[] {"href", id, "class", "link"}, contents);
901 return encloseContents("a", new String[] {"href", id, "class", "link"}, contents);
905 * Rewrite a link when its type is "scilab"
906 * @param link the link
907 * @return the modified link with protocol scilab:// for example
909 protected String resolvScilabLink(String link) {
910 int pos = link.indexOf("/");
914 String first = link.substring(0, pos);
915 String second = link.substring(pos + 1);
916 String[] toks = first.split("\\.");
917 if (toks == null || toks.length != 2) {
922 return urlBase + link;
924 if (toks[0].equals("scilab") && toks[1].equals("help")) {
925 return urlBase + second + ".html";
934 * @param link the link
935 * @return the good link
937 protected String makeRemoteLink(String link) {
943 * @param attributes the tag attributes
944 * @param contents the tag contents
945 * @return the HTML code
946 * @throws SAXEception if an error is encountered
948 public String handleUlink(final Map<String, String> attributes, final String contents) throws SAXException {
949 String link = attributes.get("url");
951 throw new SAXException("No url attribute in tag ulink");
954 return encloseContents("a", new String[] {"href", link, "class", "ulink"}, contents);
959 * @param attributes the tag attributes
960 * @param contents the tag contents
961 * @return the HTML code
962 * @throws SAXEception if an error is encountered
964 public String handleXref(final Map<String, String> attributes, final String contents) throws SAXException {
965 String link = attributes.get("linkend");
967 throw new SAXException("No linkend attribute in tag link");
970 String id = mapId.get(link);
973 System.err.println("Warning (should be fixed): invalid internal link to " + link + " in " + currentFileName + "\nat line " + locator.getLineNumber());
977 return encloseContents("a", new String[] {"href", id, "class", "xref"}, contents);
981 * Handle a latex (not really a docbook tag...)
982 * @param attributes the tag attributes
983 * @param contents the tag contents
984 * @return the HTML code
985 * @throws SAXEception if an error is encountered
987 public String handleLatex(final Map<String, String> attributes, final String contents) throws SAXException {
988 File f = new File(outName + imageDir, LATEXBASENAME + (latexCompt++) + ".png");
989 String parent = getParentTagName();
990 if (parent.equals("para") && !attributes.containsKey("style")) {
991 attributes.put("style", "text");
993 String fs = attributes.get("fontsize");
995 attributes.put("fontsize", "16");
997 return ImageConverter.getImageByCode(currentFileName, contents, attributes, "image/latex", f, imageDir + "/" + f.getName());
1002 * @param attributes the tag attributes
1003 * @param contents the tag contents
1004 * @return the HTML code
1005 * @throws SAXEception if an error is encountered
1007 public String handleTerm(final Map<String, String> attributes, final String contents) throws SAXException {
1008 String id = attributes.get("id");
1010 return "<a name=\"" + id + "\"></a>" + encloseContents("span", "term", contents);
1012 return encloseContents("span", "term", contents);
1018 * @param attributes the tag attributes
1019 * @param contents the tag contents
1020 * @return the HTML code
1021 * @throws SAXEception if an error is encountered
1023 public String handleListitem(final Map<String, String> attributes, final String contents) throws SAXException {
1024 String parent = getParentTagName();
1025 if (parent.equals("varlistentry")) {
1026 return encloseContents("dd", contents);
1028 return encloseContents("li", contents);
1032 * Handle a varlistentry
1033 * @param attributes the tag attributes
1034 * @param contents the tag contents
1035 * @return the HTML code
1036 * @throws SAXEception if an error is encountered
1038 public String handleVarlistentry(final Map<String, String> attributes, final String contents) throws SAXException {
1039 return encloseContents("dt", contents);
1043 * Handle a variablelist
1044 * @param attributes the tag attributes
1045 * @param contents the tag contents
1046 * @return the HTML code
1047 * @throws SAXEception if an error is encountered
1049 public String handleVariablelist(final Map<String, String> attributes, final String contents) throws SAXException {
1050 return encloseContents("dl", contents);
1054 * Handle an itemizedlist
1055 * @param attributes the tag attributes
1056 * @param contents the tag contents
1057 * @return the HTML code
1058 * @throws SAXEception if an error is encountered
1060 public String handleItemizedlist(final Map<String, String> attributes, final String contents) throws SAXException {
1061 String id = attributes.get("id");
1063 return "<a name=\"" + id + "\"></a>" + encloseContents("ul", "itemizedlist", contents);
1065 return encloseContents("ul", "itemizedlist", contents);
1070 * Handle an emphasis
1071 * @param attributes the tag attributes
1072 * @param contents the tag contents
1073 * @return the HTML code
1074 * @throws SAXEception if an error is encountered
1076 public String handleEmphasis(final Map<String, String> attributes, final String contents) throws SAXException {
1077 String role = attributes.get("role");
1079 if (role.equals("bold")) {
1080 return encloseContents("b", contents);
1082 if (role.equals("italic")) {
1083 return encloseContents("i", contents);
1087 return encloseContents("em", contents);
1092 * @param attributes the tag attributes
1093 * @param contents the tag contents
1094 * @return the HTML code
1095 * @throws SAXEception if an error is encountered
1097 public String handleTr(final Map<String, String> attributes, final String contents) throws SAXException {
1098 return encloseContents("tr", contents);
1103 * @param attributes the tag attributes
1104 * @param contents the tag contents
1105 * @return the HTML code
1106 * @throws SAXEception if an error is encountered
1108 public String handleTd(final Map<String, String> attributes, final String contents) throws SAXException {
1109 String align = attributes.get("align");
1110 if (align == null) {
1111 return encloseContents("td", new String[] {"align", align}, contents);
1113 return encloseContents("td", contents);
1117 * Handle an informaltable
1118 * @param attributes the tag attributes
1119 * @param contents the tag contents
1120 * @return the HTML code
1121 * @throws SAXEception if an error is encountered
1123 public String handleInformaltable(final Map<String, String> attributes, final String contents) throws SAXException {
1124 String id = attributes.get("id");
1125 String border = attributes.get("border");
1126 if (border == null) {
1129 String cellpadding = attributes.get("cellpadding");
1130 if (cellpadding == null) {
1133 String width = attributes.get("width");
1134 if (width == null) {
1138 return "<a name=\"" + id + "\"></a>" + encloseContents("table", new String[] {"class", "informaltable", "border", border, "cellpadding", cellpadding, "width", width}, contents);
1140 return encloseContents("table", new String[] {"class", "informaltable", "border", border, "cellpadding", cellpadding, "width", width}, contents);
1145 * Handle an imagedata
1146 * @param attributes the tag attributes
1147 * @param contents the tag contents
1148 * @return the HTML code
1149 * @throws SAXEception if an error is encountered
1151 public String handleImagedata(final Map<String, String> attributes, final String contents) throws SAXException {
1152 String fileref = attributes.get("fileref");
1153 if (fileref == null) {
1154 if (contents == null || contents.length() == 0) {
1155 throw new SAXException("No fileref attribute or no data in tag imagedata");
1162 String path = new File(new URI(currentFileName)).getParent();
1163 if (!ImageConverter.imageExists(path, fileref)) {
1164 throw new SAXException("The given fileref is not on an existing image file:\n" + fileref);
1167 return ImageConverter.getImageByFile(attributes, path, fileref, outName, imageDir);
1168 } catch (URISyntaxException e) {
1169 System.err.println(e);
1176 * Handle an imageobject
1177 * @param attributes the tag attributes
1178 * @param contents the tag contents
1179 * @return the HTML code
1180 * @throws SAXEception if an error is encountered
1182 public String handleImageobject(final Map<String, String> attributes, final String contents) throws SAXException {
1187 * Handle an inlinemediaobject
1188 * @param attributes the tag attributes
1189 * @param contents the tag contents
1190 * @return the HTML code
1191 * @throws SAXEception if an error is encountered
1193 public String handleInlinemediaobject(final Map<String, String> attributes, final String contents) throws SAXException {
1194 return encloseContents("span", contents);
1198 * Handle a screenshot
1199 * @param attributes the tag attributes
1200 * @param contents the tag contents
1201 * @return the HTML code
1202 * @throws SAXEception if an error is encountered
1204 public String handleScreenshot(final Map<String, String> attributes, final String contents) throws SAXException {
1205 String id = attributes.get("id");
1207 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "screenshot", contents);
1209 return encloseContents("div", "screenshot", contents);
1214 * Handle a mediaobject
1215 * @param attributes the tag attributes
1216 * @param contents the tag contents
1217 * @return the HTML code
1218 * @throws SAXEception if an error is encountered
1220 public String handleMediaobject(final Map<String, String> attributes, final String contents) throws SAXException {
1221 String id = attributes.get("id");
1222 String c = contents.replaceFirst("top:([0-9]+)px;", "");
1224 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "mediaobject", c);
1226 return encloseContents("div", "mediaobject", c);
1231 * Handle an informalequation
1232 * @param attributes the tag attributes
1233 * @param contents the tag contents
1234 * @return the HTML code
1235 * @throws SAXEception if an error is encountered
1237 public String handleInformalequation(final Map<String, String> attributes, final String contents) throws SAXException {
1238 String id = attributes.get("id");
1240 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "informalequation", contents);
1242 return encloseContents("div", "informalequation", contents);
1247 * Handle an orderedlist
1248 * @param attributes the tag attributes
1249 * @param contents the tag contents
1250 * @return the HTML code
1251 * @throws SAXEception if an error is encountered
1253 public String handleOrderedlist(final Map<String, String> attributes, final String contents) throws SAXException {
1254 String numeration = "1";
1255 String numAttr = attributes.get("numeration");
1256 if (numAttr != null) {
1257 if (numAttr.equals("loweralpha")) {
1259 } else if (numAttr.equals("upperalpha")) {
1261 } else if (numAttr.equals("lowerroman")) {
1263 } else if (numAttr.equals("upperroman")) {
1268 String id = attributes.get("id");
1270 return "<a name=\"" + id + "\"></a>" + encloseContents("ol", new String[] {"type", numeration}, contents);
1272 return encloseContents("ol", new String[] {"type", numeration}, contents);
1277 * Handle a subscript
1278 * @param attributes the tag attributes
1279 * @param contents the tag contents
1280 * @return the HTML code
1281 * @throws SAXEception if an error is encountered
1283 public String handleSubscript(final Map<String, String> attributes, final String contents) throws SAXException {
1284 return encloseContents("sub", contents);
1288 * Handle a superscript
1289 * @param attributes the tag attributes
1290 * @param contents the tag contents
1291 * @return the HTML code
1292 * @throws SAXEception if an error is encountered
1294 public String handleSuperscript(final Map<String, String> attributes, final String contents) throws SAXException {
1295 return encloseContents("sup", contents);
1299 * Handle a replaceable
1300 * @param attributes the tag attributes
1301 * @param contents the tag contents
1302 * @return the HTML code
1303 * @throws SAXEception if an error is encountered
1305 public String handleReplaceable(final Map<String, String> attributes, final String contents) throws SAXException {
1306 return encloseContents("span", "replaceable", contents);
1311 * @param attributes the tag attributes
1312 * @param contents the tag contents
1313 * @return the HTML code
1314 * @throws SAXEception if an error is encountered
1316 public String handleQuestion(final Map<String, String> attributes, final String contents) throws SAXException {
1317 return encloseContents("dt", encloseContents("strong", contents));
1322 * @param attributes the tag attributes
1323 * @param contents the tag contents
1324 * @return the HTML code
1325 * @throws SAXEception if an error is encountered
1327 public String handleAnswer(final Map<String, String> attributes, final String contents) throws SAXException {
1328 return encloseContents("dd", contents);
1332 * Handle a qandaentry
1333 * @param attributes the tag attributes
1334 * @param contents the tag contents
1335 * @return the HTML code
1336 * @throws SAXEception if an error is encountered
1338 public String handleQandaentry(final Map<String, String> attributes, final String contents) throws SAXException {
1339 return encloseContents("dl", contents);
1344 * @param attributes the tag attributes
1345 * @param contents the tag contents
1346 * @return the HTML code
1347 * @throws SAXEception if an error is encountered
1349 public String handleQandaset(final Map<String, String> attributes, final String contents) throws SAXException {
1350 return encloseContents("div", "qandaset", contents);
1355 * @param attributes the tag attributes
1356 * @param contents the tag contents
1357 * @return the HTML code
1358 * @throws SAXEception if an error is encountered
1360 public String handleCaption(final Map<String, String> attributes, final String contents) throws SAXException {
1361 return encloseContents("caption", encloseContents("b", contents));
1366 * @param attributes the tag attributes
1367 * @param contents the tag contents
1368 * @return the HTML code
1369 * @throws SAXEception if an error is encountered
1371 public String handleTbody(final Map<String, String> attributes, final String contents) throws SAXException {
1372 return encloseContents("tbody", "tbody", contents);
1377 * @param attributes the tag attributes
1378 * @param contents the tag contents
1379 * @return the HTML code
1380 * @throws SAXEception if an error is encountered
1382 public String handleTable(final Map<String, String> attributes, final String contents) throws SAXException {
1383 String id = attributes.get("id");
1385 return "<a name=\"" + id + "\"></a>" + encloseContents("table", "doctable", contents);
1387 return encloseContents("table", "doctable", contents);
1393 * @param attributes the tag attributes
1394 * @param contents the tag contents
1395 * @return the HTML code
1396 * @throws SAXEception if an error is encountered
1398 public String handleSurname(final Map<String, String> attributes, final String contents) throws SAXException {
1399 return encloseContents("span", "surname", contents);
1403 * Handle a firstname
1404 * @param attributes the tag attributes
1405 * @param contents the tag contents
1406 * @return the HTML code
1407 * @throws SAXEception if an error is encountered
1409 public String handleFirstname(final Map<String, String> attributes, final String contents) throws SAXException {
1410 return encloseContents("span", "firstname", contents);
1414 * Handle a bibliomset
1415 * @param attributes the tag attributes
1416 * @param contents the tag contents
1417 * @return the HTML code
1418 * @throws SAXEception if an error is encountered
1420 public String handleBibliomset(final Map<String, String> attributes, final String contents) throws SAXException {
1421 String id = attributes.get("id");
1423 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "bibliomset", contents);
1425 return encloseContents("div", "bibliomset", contents);
1430 * Handle a bibliomixed
1431 * @param attributes the tag attributes
1432 * @param contents the tag contents
1433 * @return the HTML code
1434 * @throws SAXEception if an error is encountered
1436 public String handleBibliomixed(final Map<String, String> attributes, final String contents) throws SAXException {
1437 String id = attributes.get("id");
1439 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "bibliomixed", contents);
1441 return encloseContents("div", "bibliomixed", contents);
1447 * @param attributes the tag attributes
1448 * @param contents the tag contents
1449 * @return the HTML code
1450 * @throws SAXEception if an error is encountered
1452 public String handleTh(final Map<String, String> attributes, final String contents) throws SAXException {
1453 return encloseContents("th", contents);
1457 * Handle a revhistory
1458 * @param attributes the tag attributes
1459 * @param contents the tag contents
1460 * @return the HTML code
1461 * @throws SAXEception if an error is encountered
1463 public String handleRevhistory(final Map<String, String> attributes, final String contents) throws SAXException {
1464 String id = attributes.get("id");
1465 String str = "<table class=\"revhistory\"><tr class=\"title\"><td>" + VERSION + "</td><td>" + DESCRIPTION + "</td></tr>" + contents + "</table>";
1467 return "<a name=\"" + id + "\"></a>" + str;
1475 * @param attributes the tag attributes
1476 * @param contents the tag contents
1477 * @return the HTML code
1478 * @throws SAXEception if an error is encountered
1480 public String handleRevision(final Map<String, String> attributes, final String contents) throws SAXException {
1481 return encloseContents("tr", contents);
1485 * Handle a revnumber
1486 * @param attributes the tag attributes
1487 * @param contents the tag contents
1488 * @return the HTML code
1489 * @throws SAXEception if an error is encountered
1491 public String handleRevnumber(final Map<String, String> attributes, final String contents) throws SAXException {
1492 return encloseContents("td", "revnumber", contents);
1496 * Handle a revremark
1497 * @param attributes the tag attributes
1498 * @param contents the tag contents
1499 * @return the HTML code
1500 * @throws SAXEception if an error is encountered
1502 public String handleRevremark(final Map<String, String> attributes, final String contents) throws SAXException {
1503 return encloseContents("td", "revremark", contents);
1507 * Handle a revdescription
1508 * @param attributes the tag attributes
1509 * @param contents the tag contents
1510 * @return the HTML code
1511 * @throws SAXEception if an error is encountered
1513 public String handleRevdescription(final Map<String, String> attributes, final String contents) throws SAXException {
1514 return encloseContents("td", "revdescription", contents);
1519 * @param attributes the tag attributes
1520 * @param contents the tag contents
1521 * @return the HTML code
1522 * @throws SAXEception if an error is encountered
1524 public String handleNote(final Map<String, String> attributes, final String contents) throws SAXException {
1525 String id = attributes.get("id");
1526 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabNote.png\"/></td><td valign=\"top\">" + encloseContents("div", "note", contents) + "</tr></table>";
1528 return "<a name=\"" + id + "\"></a>" + code;
1536 * @param attributes the tag attributes
1537 * @param contents the tag contents
1538 * @return the HTML code
1539 * @throws SAXEception if an error is encountered
1541 public String handleWarning(final Map<String, String> attributes, final String contents) throws SAXException {
1542 String id = attributes.get("id");
1543 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabWarning.png\"/></td><td valign=\"top\">" + encloseContents("div", "warning", contents) + "</tr></table>";
1545 return "<a name=\"" + id + "\"></a>" + code;
1553 * @param attributes the tag attributes
1554 * @param contents the tag contents
1555 * @return the HTML code
1556 * @throws SAXEception if an error is encountered
1558 public String handleCaution(final Map<String, String> attributes, final String contents) throws SAXException {
1559 String id = attributes.get("id");
1560 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabCaution.png\"/></td><td valign=\"top\">" + encloseContents("div", "caution", contents) + "</tr></table>";
1562 return "<a name=\"" + id + "\"></a>" + code;
1570 * @param attributes the tag attributes
1571 * @param contents the tag contents
1572 * @return the HTML code
1573 * @throws SAXEception if an error is encountered
1575 public String handleTip(final Map<String, String> attributes, final String contents) throws SAXException {
1576 String id = attributes.get("id");
1577 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabTip.png\"/></td><td valign=\"top\">" + encloseContents("div", "tip", contents) + "</tr></table>";
1579 return "<a name=\"" + id + "\"></a>" + code;
1586 * Handle a important
1587 * @param attributes the tag attributes
1588 * @param contents the tag contents
1589 * @return the HTML code
1590 * @throws SAXEception if an error is encountered
1592 public String handleImportant(final Map<String, String> attributes, final String contents) throws SAXException {
1593 String id = attributes.get("id");
1594 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabImportant.png\"/></td><td valign=\"top\">" + encloseContents("div", "important", contents) + "</tr></table>";
1596 return "<a name=\"" + id + "\"></a>" + code;