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 public static enum GenerationType { WEB, JAVAHELP, CHM, HTML };
49 private static final String SCILAB_URI = "http://www.scilab.org";
50 private static final String LATEXBASENAME = "Equation_LaTeX_";
51 private static final String VERSION = Messages.gettext("Version");
52 private static final String DESCRIPTION = Messages.gettext("Description");
54 private StringBuilder buffer = new StringBuilder(8192);
55 private int latexCompt;
56 private String imageDir;
57 private String outName;
58 private String urlBase;
59 private boolean linkToTheWeb;
60 private boolean hasExamples;
64 protected Map<String, String> mapId;
65 protected Map<String, String> tocitem;
66 protected HTMLDocbookLinkResolver.TreeId tree;
67 protected Map<String, HTMLDocbookLinkResolver.TreeId> mapTreeId;
68 protected Map<String, String> mapIdPurpose;
70 protected TemplateHandler templateHandler;
72 protected ScilabLexer scilabLexer;
73 protected XMLLexer xmlLexer;
74 protected CLexer cLexer;
75 protected JavaLexer javaLexer;
77 protected String bookTitle = "";
78 protected String partTitle = "";
79 protected String chapterTitle = "";
80 protected String sectionTitle = "";
81 protected String fileSubtitle = "";
83 protected String refpurpose = "";
84 protected String refname = "";
85 protected String version;
86 protected String appendToProgramListing;
87 protected String appendForExecToProgramListing;
88 protected String prependToProgramListing;
89 protected String currentId;
90 protected String indexFilename = "index" /*UUID.randomUUID().toString()*/ + ".html";
91 protected String language;
93 protected boolean isToolbox;
94 protected final GenerationType type;
98 * @param inName the name of the input stream
99 * @param outName the output directory
100 * @param primConf the file containing the primitives of Scilab
101 * @param macroConf the file containing the macros of Scilab
102 * @param template the template to use
103 * @param version the version
104 * @param imageDir the image directory (relative to outName)
105 * @param isToolbox is true when compile a toolbox' help
106 * @param urlBase the base url for external link
108 public HTMLDocbookTagConverter(String inName, String outName, String[] primConf, String[] macroConf, String template, String version, String imageDir, boolean isToolbox, String urlBase, String language, GenerationType type) throws IOException, SAXException {
111 this.version = version;
112 this.imageDir = imageDir;
113 this.outName = outName + File.separator;
114 HTMLDocbookLinkResolver resolver = new HTMLDocbookLinkResolver(inName);
115 mapId = resolver.getMapId();
116 tocitem = resolver.getToc();
117 tree = resolver.getTree();
118 mapTreeId = resolver.getMapTreeId();
119 mapIdPurpose = resolver.getMapIdPurpose();
120 scilabLexer = new ScilabLexer(primConf, macroConf);
121 this.urlBase = urlBase;
122 this.linkToTheWeb = urlBase != null && !urlBase.equals("scilab://");
123 this.isToolbox = isToolbox;
124 this.language = language;
126 if (isToolbox) {// we generate a toolbox's help
127 HTMLScilabCodeHandler.setLinkWriter(new AbstractScilabCodeHandler.LinkWriter() {
128 public String getLink(String id) {
129 if (id.length() > 0 && id.charAt(0) == '%') {
130 id = id.replace("%", "percent");
132 String link = mapId.get(id);
134 return HTMLDocbookTagConverter.this.urlBase + id;
140 } else {// we generate Scilab's help
141 HTMLScilabCodeHandler.setLinkWriter(new AbstractScilabCodeHandler.LinkWriter() {
142 public String getLink(String id) {
143 if (id.length() > 0 && id.charAt(0) == '%') {
144 id = id.replace("%", "percent");
146 return mapId.get(id);
151 xmlLexer = new XMLLexer();
152 cLexer = new CLexer();
153 javaLexer = new JavaLexer();
154 File tpl = new File(template);
155 templateHandler = new TemplateHandler(this, tpl, language);
156 ImageConverter.registerExternalImageConverter(LaTeXImageConverter.getInstance(type));
157 ImageConverter.registerExternalImageConverter(MathMLImageConverter.getInstance(type));
158 ImageConverter.registerExternalImageConverter(SVGImageConverter.getInstance(type));
159 ImageConverter.registerExternalImageConverter(ScilabImageConverter.getInstance(type));
163 * Get the type of the generation
164 * @return the generation type
166 public final GenerationType getGenerationType() {
171 * @return the buffer used
173 public StringBuilder getBuffer() {
178 * @param tag the tag name
179 * @param contents the contents to enclose between opening and closing tags
181 public String encloseContents(final String tag, final String contents) {
186 if (contents != null) {
187 buffer.append(contents);
193 return buffer.toString();
197 * @param tag the tag name
198 * @param attrs the attributes {attr1, value1, attr2, value2, ...}
199 * @param contents the contents to enclose between opening and closing tags
201 public String encloseContents(final String tag, final String[] attrs, final String contents) {
206 for (int i = 0; i < attrs.length; i += 2) {
208 buffer.append(attrs[i]);
209 buffer.append("=\"");
210 buffer.append(attrs[i + 1]);
216 if (contents != null) {
217 buffer.append(contents);
223 return buffer.toString();
227 * @param tag the tag name
228 * @param clazz the css class name
229 * @param contents the contents to enclose between opening and closing tags
231 public String encloseContents(final String tag, final String clazz, final String contents) {
235 buffer.append(" class=\"");
236 buffer.append(clazz);
237 buffer.append("\">");
238 if (contents != null) {
239 buffer.append(contents);
245 return buffer.toString();
251 public boolean isEscapable(final String tagName, final String uri) {
252 return !"latex".equals(tagName) && !"screen".equals(tagName) && !"programlisting".equals(tagName) && !"code".equals(tagName) && !"synopsis".equals(tagName) && !(uri.equals(SCILAB_URI) && tagName.equals("image"));
258 public boolean isTrimable(final String tagName) {
259 return !"screen".equals(tagName) && !"programlisting".equals(tagName) && !"code".equals(tagName) && !"synopsis".equals(tagName);
263 * @param fileName the file to create
264 * @param subtitle the subtitle of the file
265 * @param contents the contents of the file
267 public void createHTMLFile(final String id, final String fileName, final String subtitle, final String contents) {
269 fileSubtitle = subtitle;
271 templateHandler.generateFileFromTemplate(outName + fileName, id, contents);
278 public String makeTitle(final String id) {
279 if (refname.length() > 0) {
280 return tocitem.get(id);
289 public String makeSubtitle(final String id) {
296 public String makePrevious(final String id) {
298 buffer.append("<span class=\"previous\">");
299 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
303 HTMLDocbookLinkResolver.TreeId prev = leaf.getPrevious();
304 if (prev.parent != null) {
305 buffer.append("<a href=\"");
306 buffer.append(mapId.get(prev.id));
307 buffer.append("\"><< ");
308 buffer.append(tocitem.get(prev.id));
309 buffer.append("</a></span>\n");
311 return buffer.toString();
320 public String makePath(final String id) {
322 buffer.append("<span class=\"path\">");
323 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
327 String str = tocitem.get(id);
329 while (leaf != null && !leaf.isRoot()) {
330 str = "<a href=\"" + mapId.get(leaf.id) + "\">" + tocitem.get(leaf.id) + "</a> > " + str;
334 str = "<a href=\"" + indexFilename + "\">" + bookTitle + "</a> >> " + str;
336 buffer.append("</span>\n");
338 return buffer.toString();
344 public String makeTop(final String id) {
346 buffer.append("<span class=\"top\">");
347 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
354 buffer.append("<a href=\"");
355 if (!leaf.isRoot()) {
356 buffer.append(mapId.get(leaf.id));
357 buffer.append("\">");
358 buffer.append(tocitem.get(leaf.id));
360 buffer.append(indexFilename);
361 buffer.append("\">");
362 buffer.append(bookTitle);
364 buffer.append("</a></span>\n");
369 return buffer.toString();
375 public String makeNext(final String id) {
377 buffer.append("<span class=\"next\">");
378 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
382 HTMLDocbookLinkResolver.TreeId next = leaf.getNext();
384 buffer.append("<a href=\"");
385 buffer.append(mapId.get(next.id));
386 buffer.append("\">");
387 buffer.append(tocitem.get(next.id));
388 buffer.append(" >></a></span>\n");
390 return buffer.toString();
399 public String makeStart(final String id) {
401 buffer.append("<span class=\"start\">");
402 buffer.append("<a href=\"");
403 buffer.append(indexFilename);
404 buffer.append("\">");
405 buffer.append(bookTitle);
406 buffer.append("</a></span>\n");
408 return buffer.toString();
414 public String makeTocList(final String id) {
416 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
421 HTMLDocbookLinkResolver.TreeId parent = leaf.parent;
422 buffer.append("<ul class=\"toc\">\n");
424 while (parent != null && !parent.isRoot()) {
425 str = "<li class=\"parent\"><a href=\"" + mapId.get(parent.id) + "\">" + tocitem.get(parent.id) + "</a></li>\n" + str;
426 parent = parent.parent;
428 buffer.append("<li class=\"root\"><a href=\"");
429 buffer.append(indexFilename);
430 buffer.append("\">");
431 buffer.append(bookTitle);
432 buffer.append("</a></li>\n");
435 parent = leaf.parent;
437 for (HTMLDocbookLinkResolver.TreeId c : parent.children) {
439 buffer.append("<li class=\"list-active\"><a href=\"");
441 buffer.append("<li><a href=\"");
443 buffer.append(mapId.get(c.id));
444 buffer.append("\">");
445 buffer.append(tocitem.get(c.id));
446 buffer.append("</a></li>\n");
448 buffer.append("</ul>\n");
450 return buffer.toString();
456 public String makeLastModified(final String id) {
459 buffer.append("<span class=\"lastmodified\">");
460 buffer.append(new Date(new File(new URI(currentFileName)).lastModified()).toString());
461 buffer.append("</span>\n");
462 } catch (URISyntaxException e) {
465 return buffer.toString();
471 public String makeGenerationDate(final String id) {
473 buffer.append("<span class=\"generationdate\">");
474 buffer.append(new Date(System.currentTimeMillis()).toString());
475 buffer.append("</span>\n");
477 return buffer.toString();
483 public String makeVersion(final String id) {
485 buffer.append("<span class=\"version\">");
486 buffer.append(version);
487 buffer.append("</span>\n");
489 return buffer.toString();
494 * @param attributes the tag attributes
495 * @param contents the tag contents
496 * @return the HTML code
497 * @throws SAXEception if an error is encountered
499 public String handleRefentry(final Map<String, String> attributes, final String contents) throws SAXException {
500 String id = attributes.get("id");
504 String fileName = mapId.get(currentId);
505 createHTMLFile(currentId, fileName, refpurpose, contents);
508 //System.err.println("Warning (should be fixed): no example in " + currentFileName);
512 String rp = encloseContents("span", "refentry-description", refpurpose);
513 String str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "refentry"}, currentId) + " — " + rp);
523 * @param attributes the tag attributes
524 * @param contents the tag contents
525 * @return the HTML code
526 * @throws SAXEception if an error is encountered
528 public String handleSection(final Map<String, String> attributes, final String contents) throws SAXException {
529 String fileName = attributes.get("id") + ".html";
530 String str = encloseContents("ul", "list-refentry", contents);
531 String title = encloseContents("h3", "title-section", sectionTitle);
532 createHTMLFile(attributes.get("id"), fileName, sectionTitle, title + "\n" + str);
534 str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "section"}, sectionTitle) + "\n" + str);
542 * @param attributes the tag attributes
543 * @param contents the tag contents
544 * @return the HTML code
545 * @throws SAXEception if an error is encountered
547 public String handleBook(final Map<String, String> attributes, final String contents) throws SAXException {
548 String str = encloseContents("ul", "list-part", contents);
550 if (bookTitle.trim().equalsIgnoreCase("Scilab")) {
555 String title = encloseContents("h3", "book-title", btitle);
556 createHTMLFile("index", indexFilename, btitle, title + "\n" + str);
559 System.err.println("Total files without example: " + warnings);
560 System.err.println("Total generated html files: " + nbFiles);
563 return encloseContents("li", encloseContents("a", new String[] {"href", indexFilename, "class", "part"}, bookTitle) + "\n" + str);
568 * @param attributes the tag attributes
569 * @param contents the tag contents
570 * @return the HTML code
571 * @throws SAXEception if an error is encountered
573 public String handlePart(final Map<String, String> attributes, final String contents) throws SAXException {
574 String fileName = attributes.get("id") + ".html";
575 String str = encloseContents("ul", "list-chapter", contents);
576 String title = encloseContents("h3", "title-part", partTitle);
577 createHTMLFile(attributes.get("id"), fileName, partTitle, title + "\n" + str);
579 str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "part"}, partTitle) + "\n" + str);
587 * @param attributes the tag attributes
588 * @param contents the tag contents
589 * @return the HTML code
590 * @throws SAXEception if an error is encountered
592 public String handleChapter(final Map<String, String> attributes, final String contents) throws SAXException {
593 String fileName = attributes.get("id") + ".html";
594 String str = encloseContents("ul", "list-refentry", contents);
595 String title = encloseContents("h3", "title-chapter", chapterTitle);
596 createHTMLFile(attributes.get("id"), fileName, chapterTitle, title + "\n" + str);
598 str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "chapter"}, chapterTitle) + "\n" + str);
604 // partiellement merdique car le style de title depend du noeud pere.
607 * @param attributes the tag attributes
608 * @param contents the tag contents
609 * @return the HTML code
610 * @throws SAXEception if an error is encountered
612 public String handleTitle(final Map<String, String> attributes, final String contents) throws SAXException {
613 String clazz = "title";
614 String parent = getParentTagName();
615 if (parent.equals("chapter")) {
616 chapterTitle = contents;
617 } else if (parent.equals("part")) {
618 partTitle = contents;
619 } else if (parent.equals("info")) {
620 bookTitle = contents;
621 } else if (parent.equals("section")) {
622 sectionTitle = contents;
623 } else if (parent.equals("refsection") && Pattern.matches("^[ \\t]*ex[ea]mpl[eo].*", contents.toLowerCase())) {
625 return encloseContents("h3", clazz, contents);
627 return encloseContents("h3", clazz, contents);
635 * @param attributes the tag attributes
636 * @param contents the tag contents
637 * @return the HTML code
638 * @throws SAXEception if an error is encountered
640 public String handlePara(final Map<String, String> attributes, final String contents) throws SAXException {
641 return encloseContents("p", "para", contents);
646 * @param attributes the tag attributes
647 * @param contents the tag contents
648 * @return the HTML code
649 * @throws SAXEception if an error is encountered
651 public String handleLiteral(final Map<String, String> attributes, final String contents) throws SAXException {
652 return encloseContents("code", "literal", contents);
657 * @param attributes the tag attributes
658 * @param contents the tag contents
659 * @return the HTML code
660 * @throws SAXEception if an error is encountered
662 public String handleVarname(final Map<String, String> attributes, final String contents) throws SAXException {
663 return encloseContents("code", "varname", contents);
668 * @param attributes the tag attributes
669 * @param contents the tag contents
670 * @return the HTML code
671 * @throws SAXEception if an error is encountered
673 public String handleCommand(final Map<String, String> attributes, final String contents) throws SAXException {
674 return encloseContents("code", "command", contents);
679 * @param attributes the tag attributes
680 * @param contents the tag contents
681 * @return the HTML code
682 * @throws SAXEception if an error is encountered
684 public String handleCode(final Map<String, String> attributes, final String contents) throws SAXException {
685 return encloseContents("code", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));//encloseContents("code", "code", contents);
690 * @param attributes the tag attributes
691 * @param contents the tag contents
692 * @return the HTML code
693 * @throws SAXEception if an error is encountered
695 public String handleFunction(final Map<String, String> attributes, final String contents) throws SAXException {
696 return encloseContents("code", "function", contents);
701 * @param attributes the tag attributes
702 * @param contents the tag contents
703 * @return the HTML code
704 * @throws SAXEception if an error is encountered
706 public String handleConstant(final Map<String, String> attributes, final String contents) throws SAXException {
707 return encloseContents("code", "constant", contents);
712 * @param attributes the tag attributes
713 * @param contents the tag contents
714 * @return the HTML code
715 * @throws SAXEception if an error is encountered
717 public String handleOption(final Map<String, String> attributes, final String contents) throws SAXException {
718 return encloseContents("code", "option", contents);
722 * Handle a refnamediv
723 * @param attributes the tag attributes
724 * @param contents the tag contents
725 * @return the HTML code
726 * @throws SAXEception if an error is encountered
728 public String handleRefnamediv(final Map<String, String> attributes, final String contents) throws SAXException {
729 String id = attributes.get("id");
734 return encloseContents("div", "refnamediv", contents);
739 * @param attributes the tag attributes
740 * @param contents the tag contents
741 * @return the HTML code
742 * @throws SAXEception if an error is encountered
744 public String handleRefname(final Map<String, String> attributes, final String contents) throws SAXException {
746 return encloseContents("h1", "refname", contents);
750 * Handle a refpurpose
751 * @param attributes the tag attributes
752 * @param contents the tag contents
753 * @return the HTML code
754 * @throws SAXEception if an error is encountered
756 public String handleRefpurpose(final Map<String, String> attributes, final String contents) throws SAXException {
757 refpurpose = contents;
758 return encloseContents("p", "refpurpose", contents);
762 * Handle a refsynopsisdiv
763 * @param attributes the tag attributes
764 * @param contents the tag contents
765 * @return the HTML code
766 * @throws SAXEception if an error is encountered
768 public String handleRefsynopsisdiv(final Map<String, String> attributes, final String contents) throws SAXException {
769 String id = attributes.get("id");
771 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "refsynopsisdiv", contents);
773 return encloseContents("div", "refsynopsisdiv", contents);
779 * @param attributes the tag attributes
780 * @param contents the tag contents
781 * @return the HTML code
782 * @throws SAXEception if an error is encountered
784 public String handleSynopsis(final Map<String, String> attributes, final String contents) throws SAXException {
785 String id = attributes.get("id");
786 String str = encloseContents("div", "synopsis", encloseContents("pre", SynopsisLexer.convert(refname, contents)));
788 return "<a name=\"" + id + "\"></a>" + str;
796 * @param attributes the tag attributes
797 * @param contents the tag contents
798 * @return the HTML code
799 * @throws SAXEception if an error is encountered
801 public String handleInfo(final Map<String, String> attributes, final String contents) throws SAXException {
802 String id = attributes.get("id");
804 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "info", contents);
806 return encloseContents("div", "info", contents);
811 * Handle a refsection
812 * @param attributes the tag attributes
813 * @param contents the tag contents
814 * @return the HTML code
815 * @throws SAXEception if an error is encountered
817 public String handleRefsection(final Map<String, String> attributes, final String contents) throws SAXException {
818 String id = attributes.get("id");
820 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "refsection", contents);
822 return encloseContents("div", "refsection", contents);
827 * Handle a progamlisting
828 * @param attributes the tag attributes
829 * @param contents the tag contents
830 * @return the HTML code
831 * @throws SAXEception if an error is encountered
833 public String handleProgramlisting(final Map<String, String> attributes, final String contents) throws SAXException {
834 String id = attributes.get("id");
835 String role = attributes.get("role");
838 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
839 if (prependToProgramListing != null) {
840 code = prependToProgramListing + code;
842 if (appendToProgramListing != null) {
843 code += appendToProgramListing;
845 str = encloseContents("div", "programlisting", code);
847 if (role.equals("xml")) {
848 str = encloseContents("div", "programlisting", encloseContents("pre", "xmlcode", xmlLexer.convert(HTMLXMLCodeHandler.getInstance(), contents)));
849 } else if (role.equals("c") || role.equals("cpp") || role.equals("code_gateway")) {
850 str = encloseContents("div", "programlisting", encloseContents("pre", "ccode", cLexer.convert(HTMLCCodeHandler.getInstance(), contents)));
851 } else if (role.equals("java")) {
852 str = encloseContents("div", "programlisting", encloseContents("pre", "ccode", javaLexer.convert(HTMLCCodeHandler.getInstance(), contents)));
853 } else if (role.equals("exec")) {
854 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
855 if (prependToProgramListing != null) {
856 code = prependToProgramListing + code;
858 if (appendForExecToProgramListing != null) {
859 code += appendForExecToProgramListing;
861 str = encloseContents("div", "programlisting", code);
862 } else if (role.equals("no-scilab-exec")) {
863 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
864 str = encloseContents("div", "programlisting", code);
866 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
867 if (prependToProgramListing != null) {
868 code = prependToProgramListing + code;
870 if (appendToProgramListing != null) {
871 code += appendToProgramListing;
873 str = encloseContents("div", "programlisting", code);
877 return "<a name=\"" + id + "\"></a>" + str;
885 * @param attributes the tag attributes
886 * @param contents the tag contents
887 * @return the HTML code
888 * @throws SAXEception if an error is encountered
890 public String handleScreen(final Map<String, String> attributes, final String contents) throws SAXException {
891 String id = attributes.get("id");
892 String str = encloseContents("div", "screen", encloseContents("pre", contents));
894 return "<a name=\"" + id + "\"></a>" + str;
902 * @param attributes the tag attributes
903 * @param contents the tag contents
904 * @return the HTML code
905 * @throws SAXEception if an error is encountered
907 public String handlePubdate(final Map<String, String> attributes, final String contents) throws SAXException {
912 * Handle a simplelist
913 * @param attributes the tag attributes
914 * @param contents the tag contents
915 * @return the HTML code
916 * @throws SAXEception if an error is encountered
918 public String handleSimplelist(final Map<String, String> attributes, final String contents) throws SAXException {
919 String style = "itemizedlist";
921 return encloseContents("ul", style, contents);
926 * @param attributes the tag attributes
927 * @param contents the tag contents
928 * @return the HTML code
929 * @throws SAXEception if an error is encountered
931 public String handleMember(final Map<String, String> attributes, final String contents) throws SAXException {
932 return encloseContents("li", "member", contents);
937 * @param attributes the tag attributes
938 * @param contents the tag contents
939 * @return the HTML code
940 * @throws SAXEception if an error is encountered
942 public String handleLink(final Map<String, String> attributes, final String contents) throws SAXException {
943 String link = attributes.get("linkend");
945 throw new SAXException("No linkend attribute in tag link");
948 String type = attributes.get("type");
950 if (type != null && type.equals("scilab")) {
951 id = resolvScilabLink(link);
952 } else if (type != null && type.equals("remote")) {
953 id = makeRemoteLink(link);
955 id = mapId.get(link);
960 System.err.println("Warning (should be fixed): invalid internal link to " + link + " in " + currentFileName + "\nat line " + locator.getLineNumber());
964 Stack<DocbookElement> stack = getStack();
965 int s = stack.size();
967 DocbookElement elem = stack.get(s - 3);
968 if (elem.getName().equals("refsection")) {
969 String role = elem.getAttributes().get("role");
970 if (role != null && role.equals("see also")) {
971 String purpose = mapIdPurpose.get(link);
972 if (purpose != null) {
973 return encloseContents("a", new String[] {"href", id, "class", "link"}, contents) + " — " + purpose;
975 return encloseContents("a", new String[] {"href", id, "class", "link"}, contents);
981 return encloseContents("a", new String[] {"href", id, "class", "link"}, contents);
985 * Rewrite a link when its type is "scilab"
986 * @param link the link
987 * @return the modified link with protocol scilab:// for example
989 protected String resolvScilabLink(String link) {
990 int pos = link.indexOf("/");
994 String first = link.substring(0, pos);
995 String second = link.substring(pos + 1);
996 String[] toks = first.split("\\.");
997 if (toks == null || toks.length != 2) {
1001 if (!linkToTheWeb) {
1002 return urlBase + link;
1004 if (toks[0].equals("scilab") && toks[1].equals("help")) {
1005 return urlBase + second + ".html";
1013 * Make a remote link
1014 * @param link the link
1015 * @return the good link
1017 protected String makeRemoteLink(String link) {
1023 * @param attributes the tag attributes
1024 * @param contents the tag contents
1025 * @return the HTML code
1026 * @throws SAXEception if an error is encountered
1028 public String handleUlink(final Map<String, String> attributes, final String contents) throws SAXException {
1029 String link = attributes.get("url");
1031 throw new SAXException("No url attribute in tag ulink");
1034 return encloseContents("a", new String[] {"href", link, "class", "ulink"}, contents);
1039 * @param attributes the tag attributes
1040 * @param contents the tag contents
1041 * @return the HTML code
1042 * @throws SAXEception if an error is encountered
1044 public String handleXref(final Map<String, String> attributes, final String contents) throws SAXException {
1045 String link = attributes.get("linkend");
1047 throw new SAXException("No linkend attribute in tag link");
1050 String id = mapId.get(link);
1053 System.err.println("Warning (should be fixed): invalid internal link to " + link + " in " + currentFileName + "\nat line " + locator.getLineNumber());
1057 return encloseContents("a", new String[] {"href", id, "class", "xref"}, contents);
1061 * Handle a latex (not really a docbook tag...)
1062 * @param attributes the tag attributes
1063 * @param contents the tag contents
1064 * @return the HTML code
1065 * @throws SAXEception if an error is encountered
1067 public String handleLatex(final Map<String, String> attributes, final String contents) throws SAXException {
1068 File f = new File(outName + imageDir, LATEXBASENAME + (latexCompt++) + ".png");
1069 String parent = getParentTagName();
1070 if (parent.equals("para") && !attributes.containsKey("style")) {
1071 attributes.put("style", "text");
1073 String fs = attributes.get("fontsize");
1075 attributes.put("fontsize", "16");
1077 return ImageConverter.getImageByCode(currentFileName, contents, attributes, "image/latex", f, imageDir + "/" + f.getName());
1082 * @param attributes the tag attributes
1083 * @param contents the tag contents
1084 * @return the HTML code
1085 * @throws SAXEception if an error is encountered
1087 public String handleTerm(final Map<String, String> attributes, final String contents) throws SAXException {
1088 String id = attributes.get("id");
1090 return "<a name=\"" + id + "\"></a>" + encloseContents("span", "term", contents);
1092 return encloseContents("span", "term", contents);
1098 * @param attributes the tag attributes
1099 * @param contents the tag contents
1100 * @return the HTML code
1101 * @throws SAXEception if an error is encountered
1103 public String handleListitem(final Map<String, String> attributes, final String contents) throws SAXException {
1104 String parent = getParentTagName();
1105 if (parent.equals("varlistentry")) {
1106 return encloseContents("dd", contents);
1108 return encloseContents("li", contents);
1112 * Handle a varlistentry
1113 * @param attributes the tag attributes
1114 * @param contents the tag contents
1115 * @return the HTML code
1116 * @throws SAXEception if an error is encountered
1118 public String handleVarlistentry(final Map<String, String> attributes, final String contents) throws SAXException {
1119 return encloseContents("dt", contents);
1123 * Handle a variablelist
1124 * @param attributes the tag attributes
1125 * @param contents the tag contents
1126 * @return the HTML code
1127 * @throws SAXEception if an error is encountered
1129 public String handleVariablelist(final Map<String, String> attributes, final String contents) throws SAXException {
1130 return encloseContents("dl", contents);
1134 * Handle an itemizedlist
1135 * @param attributes the tag attributes
1136 * @param contents the tag contents
1137 * @return the HTML code
1138 * @throws SAXEception if an error is encountered
1140 public String handleItemizedlist(final Map<String, String> attributes, final String contents) throws SAXException {
1141 String id = attributes.get("id");
1143 return "<a name=\"" + id + "\"></a>" + encloseContents("ul", "itemizedlist", contents);
1145 return encloseContents("ul", "itemizedlist", contents);
1150 * Handle an emphasis
1151 * @param attributes the tag attributes
1152 * @param contents the tag contents
1153 * @return the HTML code
1154 * @throws SAXEception if an error is encountered
1156 public String handleEmphasis(final Map<String, String> attributes, final String contents) throws SAXException {
1157 String role = attributes.get("role");
1159 if (role.equals("bold")) {
1160 return encloseContents("b", contents);
1162 if (role.equals("italic")) {
1163 return encloseContents("i", contents);
1167 return encloseContents("em", contents);
1172 * @param attributes the tag attributes
1173 * @param contents the tag contents
1174 * @return the HTML code
1175 * @throws SAXEception if an error is encountered
1177 public String handleTr(final Map<String, String> attributes, final String contents) throws SAXException {
1178 return encloseContents("tr", contents);
1183 * @param attributes the tag attributes
1184 * @param contents the tag contents
1185 * @return the HTML code
1186 * @throws SAXEception if an error is encountered
1188 public String handleTd(final Map<String, String> attributes, final String contents) throws SAXException {
1189 String align = attributes.get("align");
1190 if (align == null) {
1191 return encloseContents("td", new String[] {"align", align}, contents);
1193 return encloseContents("td", contents);
1197 * Handle an informaltable
1198 * @param attributes the tag attributes
1199 * @param contents the tag contents
1200 * @return the HTML code
1201 * @throws SAXEception if an error is encountered
1203 public String handleInformaltable(final Map<String, String> attributes, final String contents) throws SAXException {
1204 String id = attributes.get("id");
1205 String border = attributes.get("border");
1206 if (border == null) {
1209 String cellpadding = attributes.get("cellpadding");
1210 if (cellpadding == null) {
1213 String width = attributes.get("width");
1214 if (width == null) {
1218 return "<a name=\"" + id + "\"></a>" + encloseContents("table", new String[] {"class", "informaltable", "border", border, "cellpadding", cellpadding, "width", width}, contents);
1220 return encloseContents("table", new String[] {"class", "informaltable", "border", border, "cellpadding", cellpadding, "width", width}, contents);
1225 * Handle an imagedata
1226 * @param attributes the tag attributes
1227 * @param contents the tag contents
1228 * @return the HTML code
1229 * @throws SAXEception if an error is encountered
1231 public String handleImagedata(final Map<String, String> attributes, final String contents) throws SAXException {
1232 String fileref = attributes.get("fileref");
1233 if (fileref == null) {
1234 if (contents == null || contents.length() == 0) {
1235 throw new SAXException("No fileref attribute or no data in tag imagedata");
1242 String path = new File(new URI(currentFileName)).getParent();
1243 if (!ImageConverter.imageExists(path, fileref)) {
1244 throw new SAXException("The given fileref is not on an existing image file:\n" + fileref);
1247 return ImageConverter.getImageByFile(attributes, path, fileref, outName, imageDir);
1248 } catch (URISyntaxException e) {
1249 System.err.println(e);
1256 * Handle an imageobject
1257 * @param attributes the tag attributes
1258 * @param contents the tag contents
1259 * @return the HTML code
1260 * @throws SAXEception if an error is encountered
1262 public String handleImageobject(final Map<String, String> attributes, final String contents) throws SAXException {
1267 * Handle an inlinemediaobject
1268 * @param attributes the tag attributes
1269 * @param contents the tag contents
1270 * @return the HTML code
1271 * @throws SAXEception if an error is encountered
1273 public String handleInlinemediaobject(final Map<String, String> attributes, final String contents) throws SAXException {
1274 return encloseContents("span", contents);
1278 * Handle a screenshot
1279 * @param attributes the tag attributes
1280 * @param contents the tag contents
1281 * @return the HTML code
1282 * @throws SAXEception if an error is encountered
1284 public String handleScreenshot(final Map<String, String> attributes, final String contents) throws SAXException {
1285 String id = attributes.get("id");
1287 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "screenshot", contents);
1289 return encloseContents("div", "screenshot", contents);
1294 * Handle a mediaobject
1295 * @param attributes the tag attributes
1296 * @param contents the tag contents
1297 * @return the HTML code
1298 * @throws SAXEception if an error is encountered
1300 public String handleMediaobject(final Map<String, String> attributes, final String contents) throws SAXException {
1301 String id = attributes.get("id");
1302 String c = contents.replaceFirst("top:([0-9]+)px;", "");
1304 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "mediaobject", c);
1306 return encloseContents("div", "mediaobject", c);
1311 * Handle an informalequation
1312 * @param attributes the tag attributes
1313 * @param contents the tag contents
1314 * @return the HTML code
1315 * @throws SAXEception if an error is encountered
1317 public String handleInformalequation(final Map<String, String> attributes, final String contents) throws SAXException {
1318 String id = attributes.get("id");
1320 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "informalequation", contents);
1322 return encloseContents("div", "informalequation", contents);
1327 * Handle an orderedlist
1328 * @param attributes the tag attributes
1329 * @param contents the tag contents
1330 * @return the HTML code
1331 * @throws SAXEception if an error is encountered
1333 public String handleOrderedlist(final Map<String, String> attributes, final String contents) throws SAXException {
1334 String numeration = "1";
1335 String numAttr = attributes.get("numeration");
1336 if (numAttr != null) {
1337 if (numAttr.equals("loweralpha")) {
1339 } else if (numAttr.equals("upperalpha")) {
1341 } else if (numAttr.equals("lowerroman")) {
1343 } else if (numAttr.equals("upperroman")) {
1348 String id = attributes.get("id");
1350 return "<a name=\"" + id + "\"></a>" + encloseContents("ol", new String[] {"type", numeration}, contents);
1352 return encloseContents("ol", new String[] {"type", numeration}, contents);
1357 * Handle a subscript
1358 * @param attributes the tag attributes
1359 * @param contents the tag contents
1360 * @return the HTML code
1361 * @throws SAXEception if an error is encountered
1363 public String handleSubscript(final Map<String, String> attributes, final String contents) throws SAXException {
1364 return encloseContents("sub", contents);
1368 * Handle a superscript
1369 * @param attributes the tag attributes
1370 * @param contents the tag contents
1371 * @return the HTML code
1372 * @throws SAXEception if an error is encountered
1374 public String handleSuperscript(final Map<String, String> attributes, final String contents) throws SAXException {
1375 return encloseContents("sup", contents);
1379 * Handle a replaceable
1380 * @param attributes the tag attributes
1381 * @param contents the tag contents
1382 * @return the HTML code
1383 * @throws SAXEception if an error is encountered
1385 public String handleReplaceable(final Map<String, String> attributes, final String contents) throws SAXException {
1386 return encloseContents("span", "replaceable", contents);
1391 * @param attributes the tag attributes
1392 * @param contents the tag contents
1393 * @return the HTML code
1394 * @throws SAXEception if an error is encountered
1396 public String handleQuestion(final Map<String, String> attributes, final String contents) throws SAXException {
1397 return encloseContents("dt", encloseContents("strong", contents));
1402 * @param attributes the tag attributes
1403 * @param contents the tag contents
1404 * @return the HTML code
1405 * @throws SAXEception if an error is encountered
1407 public String handleAnswer(final Map<String, String> attributes, final String contents) throws SAXException {
1408 return encloseContents("dd", contents);
1412 * Handle a qandaentry
1413 * @param attributes the tag attributes
1414 * @param contents the tag contents
1415 * @return the HTML code
1416 * @throws SAXEception if an error is encountered
1418 public String handleQandaentry(final Map<String, String> attributes, final String contents) throws SAXException {
1419 return encloseContents("dl", contents);
1424 * @param attributes the tag attributes
1425 * @param contents the tag contents
1426 * @return the HTML code
1427 * @throws SAXEception if an error is encountered
1429 public String handleQandaset(final Map<String, String> attributes, final String contents) throws SAXException {
1430 return encloseContents("div", "qandaset", contents);
1435 * @param attributes the tag attributes
1436 * @param contents the tag contents
1437 * @return the HTML code
1438 * @throws SAXEception if an error is encountered
1440 public String handleCaption(final Map<String, String> attributes, final String contents) throws SAXException {
1441 return encloseContents("caption", encloseContents("b", contents));
1446 * @param attributes the tag attributes
1447 * @param contents the tag contents
1448 * @return the HTML code
1449 * @throws SAXEception if an error is encountered
1451 public String handleTbody(final Map<String, String> attributes, final String contents) throws SAXException {
1452 return encloseContents("tbody", "tbody", contents);
1457 * @param attributes the tag attributes
1458 * @param contents the tag contents
1459 * @return the HTML code
1460 * @throws SAXEception if an error is encountered
1462 public String handleTable(final Map<String, String> attributes, final String contents) throws SAXException {
1463 String id = attributes.get("id");
1465 return "<a name=\"" + id + "\"></a>" + encloseContents("table", "doctable", contents);
1467 return encloseContents("table", "doctable", contents);
1473 * @param attributes the tag attributes
1474 * @param contents the tag contents
1475 * @return the HTML code
1476 * @throws SAXEception if an error is encountered
1478 public String handleSurname(final Map<String, String> attributes, final String contents) throws SAXException {
1479 return encloseContents("span", "surname", contents);
1483 * Handle a firstname
1484 * @param attributes the tag attributes
1485 * @param contents the tag contents
1486 * @return the HTML code
1487 * @throws SAXEception if an error is encountered
1489 public String handleFirstname(final Map<String, String> attributes, final String contents) throws SAXException {
1490 return encloseContents("span", "firstname", contents);
1494 * Handle a bibliomset
1495 * @param attributes the tag attributes
1496 * @param contents the tag contents
1497 * @return the HTML code
1498 * @throws SAXEception if an error is encountered
1500 public String handleBibliomset(final Map<String, String> attributes, final String contents) throws SAXException {
1501 String id = attributes.get("id");
1503 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "bibliomset", contents);
1505 return encloseContents("div", "bibliomset", contents);
1510 * Handle a bibliomixed
1511 * @param attributes the tag attributes
1512 * @param contents the tag contents
1513 * @return the HTML code
1514 * @throws SAXEception if an error is encountered
1516 public String handleBibliomixed(final Map<String, String> attributes, final String contents) throws SAXException {
1517 String id = attributes.get("id");
1519 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "bibliomixed", contents);
1521 return encloseContents("div", "bibliomixed", contents);
1527 * @param attributes the tag attributes
1528 * @param contents the tag contents
1529 * @return the HTML code
1530 * @throws SAXEception if an error is encountered
1532 public String handleTh(final Map<String, String> attributes, final String contents) throws SAXException {
1533 return encloseContents("th", contents);
1537 * Handle a revhistory
1538 * @param attributes the tag attributes
1539 * @param contents the tag contents
1540 * @return the HTML code
1541 * @throws SAXEception if an error is encountered
1543 public String handleRevhistory(final Map<String, String> attributes, final String contents) throws SAXException {
1544 String id = attributes.get("id");
1545 String str = "<table class=\"revhistory\"><tr class=\"title\"><td>" + VERSION + "</td><td>" + DESCRIPTION + "</td></tr>" + contents + "</table>";
1547 return "<a name=\"" + id + "\"></a>" + str;
1555 * @param attributes the tag attributes
1556 * @param contents the tag contents
1557 * @return the HTML code
1558 * @throws SAXEception if an error is encountered
1560 public String handleRevision(final Map<String, String> attributes, final String contents) throws SAXException {
1561 return encloseContents("tr", contents);
1565 * Handle a revnumber
1566 * @param attributes the tag attributes
1567 * @param contents the tag contents
1568 * @return the HTML code
1569 * @throws SAXEception if an error is encountered
1571 public String handleRevnumber(final Map<String, String> attributes, final String contents) throws SAXException {
1572 return encloseContents("td", "revnumber", contents);
1576 * Handle a revremark
1577 * @param attributes the tag attributes
1578 * @param contents the tag contents
1579 * @return the HTML code
1580 * @throws SAXEception if an error is encountered
1582 public String handleRevremark(final Map<String, String> attributes, final String contents) throws SAXException {
1583 return encloseContents("td", "revremark", contents);
1587 * Handle a revdescription
1588 * @param attributes the tag attributes
1589 * @param contents the tag contents
1590 * @return the HTML code
1591 * @throws SAXEception if an error is encountered
1593 public String handleRevdescription(final Map<String, String> attributes, final String contents) throws SAXException {
1594 return encloseContents("td", "revdescription", contents);
1599 * @param attributes the tag attributes
1600 * @param contents the tag contents
1601 * @return the HTML code
1602 * @throws SAXEception if an error is encountered
1604 public String handleNote(final Map<String, String> attributes, final String contents) throws SAXException {
1605 String id = attributes.get("id");
1606 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabNote.png\"/></td><td valign=\"top\">" + encloseContents("div", "note", contents) + "</tr></table>";
1608 return "<a name=\"" + id + "\"></a>" + code;
1616 * @param attributes the tag attributes
1617 * @param contents the tag contents
1618 * @return the HTML code
1619 * @throws SAXEception if an error is encountered
1621 public String handleWarning(final Map<String, String> attributes, final String contents) throws SAXException {
1622 String id = attributes.get("id");
1623 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabWarning.png\"/></td><td valign=\"top\">" + encloseContents("div", "warning", contents) + "</tr></table>";
1625 return "<a name=\"" + id + "\"></a>" + code;
1633 * @param attributes the tag attributes
1634 * @param contents the tag contents
1635 * @return the HTML code
1636 * @throws SAXEception if an error is encountered
1638 public String handleCaution(final Map<String, String> attributes, final String contents) throws SAXException {
1639 String id = attributes.get("id");
1640 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabCaution.png\"/></td><td valign=\"top\">" + encloseContents("div", "caution", contents) + "</tr></table>";
1642 return "<a name=\"" + id + "\"></a>" + code;
1650 * @param attributes the tag attributes
1651 * @param contents the tag contents
1652 * @return the HTML code
1653 * @throws SAXEception if an error is encountered
1655 public String handleTip(final Map<String, String> attributes, final String contents) throws SAXException {
1656 String id = attributes.get("id");
1657 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabTip.png\"/></td><td valign=\"top\">" + encloseContents("div", "tip", contents) + "</tr></table>";
1659 return "<a name=\"" + id + "\"></a>" + code;
1666 * Handle a important
1667 * @param attributes the tag attributes
1668 * @param contents the tag contents
1669 * @return the HTML code
1670 * @throws SAXEception if an error is encountered
1672 public String handleImportant(final Map<String, String> attributes, final String contents) throws SAXException {
1673 String id = attributes.get("id");
1674 String code = "<table><tr><td valign=\"top\"><img src=\"ScilabImportant.png\"/></td><td valign=\"top\">" + encloseContents("div", "important", contents) + "</tr></table>";
1676 return "<a name=\"" + id + "\"></a>" + code;