2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - Calixte DENIZET
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
16 package org.scilab.modules.helptools;
19 import java.io.IOException;
21 import java.net.URISyntaxException;
22 import java.util.Date;
24 import java.util.Stack;
25 import java.util.regex.Pattern;
27 import org.scilab.modules.commons.ScilabCommonsUtils;
28 import org.scilab.modules.helptools.XML.HTMLXMLCodeHandler;
29 import org.scilab.modules.helptools.XML.XMLLexer;
30 import org.scilab.modules.helptools.c.CLexer;
31 import org.scilab.modules.helptools.c.HTMLCCodeHandler;
32 import org.scilab.modules.helptools.external.HTMLMathMLHandler;
33 import org.scilab.modules.helptools.external.HTMLSVGHandler;
34 import org.scilab.modules.helptools.external.HTMLScilabHandler;
35 import org.scilab.modules.helptools.image.Image;
36 import org.scilab.modules.helptools.image.ImageConverter;
37 import org.scilab.modules.helptools.java.JavaLexer;
38 import org.scilab.modules.helptools.scilab.AbstractScilabCodeHandler;
39 import org.scilab.modules.helptools.scilab.HTMLScilabCodeHandler;
40 import org.scilab.modules.helptools.scilab.ScilabLexer;
41 import org.scilab.modules.localization.Messages;
42 import org.xml.sax.InputSource;
43 import org.xml.sax.SAXException;
46 * Class to convert DocBook to HTML
47 * @author Calixte DENIZET
49 public class HTMLDocbookTagConverter extends DocbookTagConverter implements TemplateFiller {
51 public static enum GenerationType { WEB, JAVAHELP, CHM, HTML };
53 private static final String SCILAB_URI = "http://www.scilab.org";
54 private static final String LATEXBASENAME = "_LaTeX_";
55 private static final String VERSION = Messages.gettext("Version");
56 private static final String DESCRIPTION = Messages.gettext("Description");
58 private final StringBuilder buffer = new StringBuilder(8192);
59 private int latexCompt = 1;
60 private boolean hasExamples;
64 private final String imageDir;
65 protected String urlBase;
66 protected boolean linkToTheWeb;
67 protected final String outName;
68 protected String outImages;
70 protected final Map<String, String> mapId;
71 protected final Map<String, String> tocitem;
72 protected final HTMLDocbookLinkResolver.TreeId tree;
73 protected final Map<String, HTMLDocbookLinkResolver.TreeId> mapTreeId;
74 protected final Map<String, String> mapIdPurpose;
75 protected final Map<String, String> mapIdRefname;
77 protected final TemplateHandler templateHandler;
79 protected final ScilabLexer scilabLexer;
80 protected final XMLLexer xmlLexer;
81 protected final CLexer cLexer;
82 protected final JavaLexer javaLexer;
84 protected String bookTitle = "";
85 protected String partTitle = "";
86 protected String chapterTitle = "";
87 protected String sectionTitle = "";
88 protected String fileSubtitle = "";
90 protected String refpurpose = "";
91 protected String refname = "";
92 protected String version;
93 protected String appendToProgramListing;
94 protected String appendForExecToProgramListing;
95 protected String prependToProgramListing;
96 protected String currentId;
97 protected String indexFilename = "index" /*UUID.randomUUID().toString()*/ + ".html";
98 protected final String language;
100 protected final boolean isToolbox;
101 protected final Backend type;
105 * @param inName the name of the input stream
106 * @param sciDocMain provide useful doc generation properties
107 * @param imgConvert the shared image converter for all generation
109 public HTMLDocbookTagConverter(String inName, SciDocMain sciDocMain, ImageConverter imgConvert) throws IOException, SAXException {
110 super(inName, imgConvert);
112 this.version = sciDocMain.getConf().getVersion();
113 this.imageDir = sciDocMain.getImagedir();
114 this.outName = sciDocMain.getOutputDirectory() + File.separator;
115 this.outImages = this.outName;
117 imgConvert.setDocbookTagConverter(this);
118 HTMLDocbookLinkResolver resolver = new HTMLDocbookLinkResolver(inName);
120 mapId = resolver.getMapId();
121 tocitem = resolver.getToc();
122 tree = resolver.getTree();
123 mapTreeId = resolver.getMapTreeId();
124 mapIdPurpose = resolver.getMapIdPurpose();
125 mapIdRefname = resolver.getMapIdRefname();
127 this.isToolbox = sciDocMain.isToolbox();
128 this.language = sciDocMain.getLanguage();
129 this.type = sciDocMain.getFormat();
132 urlBase = sciDocMain.getConf().getWebSiteURL() + language + "/";
136 linkToTheWeb = false;
139 if (isToolbox) {// we generate a toolbox's help
140 HTMLScilabCodeHandler.setLinkWriter(new AbstractScilabCodeHandler.LinkWriter() {
141 public String getLink(String id) {
142 if (id.length() > 0 && id.charAt(0) == '%') {
143 id = id.replace("%", "percent");
145 String link = mapId.get(id);
147 return HTMLDocbookTagConverter.this.urlBase + id;
153 } else {// we generate Scilab's help
154 HTMLScilabCodeHandler.setLinkWriter(new AbstractScilabCodeHandler.LinkWriter() {
155 public String getLink(String id) {
156 if (id.length() > 0 && id.charAt(0) == '%') {
157 id = id.replace("%", "percent");
159 return mapId.get(id);
164 scilabLexer = new ScilabLexer(sciDocMain.getConf().getBuiltins(), sciDocMain.getConf().getMacros());
165 xmlLexer = new XMLLexer();
166 cLexer = new CLexer();
167 javaLexer = new JavaLexer();
169 final String template = sciDocMain.getConf().getTemplate(sciDocMain.getFormat().toString().toLowerCase());
170 File tpl = new File(template);
172 final String msg = "Could not find template document: " + template;
173 System.err.println(msg);
174 throw new RuntimeException();
176 templateHandler = new TemplateHandler(this, tpl, language);
179 public static boolean containsCJK(CharSequence seq) {
184 for (int i = 0; i < seq.length(); i++) {
185 Character.UnicodeBlock block = Character.UnicodeBlock.of(seq.charAt(i));
186 if (block == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
187 || block == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
188 || block == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
189 || block == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS
190 || block == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
191 || block == Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT
192 || block == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
193 || block == Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS) {
201 public static boolean containsCyrillic(CharSequence seq) {
206 for (int i = 0; i < seq.length(); i++) {
207 Character.UnicodeBlock block = Character.UnicodeBlock.of(seq.charAt(i));
208 if (block == Character.UnicodeBlock.CYRILLIC || block == Character.UnicodeBlock.CYRILLIC_SUPPLEMENTARY) {
217 * Replace special chars
219 public static final String replaceEntity(final String str) {
220 return str.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("\'", "'");
224 * Get the type of the generation
225 * @return the generation type
227 public final Backend getGenerationType() {
231 public String getLanguage() {
236 public void registerAllExternalXMLHandlers() {
237 super.registerAllExternalXMLHandlers();
239 registerExternalXMLHandler(new HTMLMathMLHandler(outImages, imageDir));
240 registerExternalXMLHandler(new HTMLSVGHandler(outImages, imageDir));
241 registerExternalXMLHandler(new HTMLScilabHandler(outImages, imageDir));
245 public void install() {
248 ScilabCommonsUtils.copyFile(new File(SCI + "/modules/helptools/data/css/scilab_code.css"), new File(outName + "/scilab_code.css"));
249 ScilabCommonsUtils.copyFile(new File(SCI + "/modules/helptools/data/css/xml_code.css"), new File(outName + "/xml_code.css"));
250 ScilabCommonsUtils.copyFile(new File(SCI + "/modules/helptools/data/css/c_code.css"), new File(outName + "/c_code.css"));
251 ScilabCommonsUtils.copyFile(new File(SCI + "/modules/helptools/data/css/style.css"), new File(outName + "/style.css"));
255 * @return the buffer used
257 public StringBuilder getBuffer() {
262 * @param tag the tag name
263 * @param contents the contents to enclose between opening and closing tags
265 public String encloseContents(final String tag, final String contents) {
270 if (contents != null) {
271 buffer.append(contents);
277 return buffer.toString();
281 * @param tag the tag name
282 * @param attrs the attributes {attr1, value1, attr2, value2, ...}
283 * @param contents the contents to enclose between opening and closing tags
285 public String encloseContents(final String tag, final String[] attrs, final String contents) {
290 for (int i = 0; i < attrs.length; i += 2) {
291 if (attrs[i + 1] != null && !attrs[i + 1].isEmpty()) {
293 buffer.append(attrs[i]);
294 buffer.append("=\"");
295 buffer.append(attrs[i + 1]);
302 if (contents != null) {
303 buffer.append(contents);
309 return buffer.toString();
313 * @param tag the tag name
314 * @param clazz the css class name
315 * @param contents the contents to enclose between opening and closing tags
317 public String encloseContents(final String tag, final String clazz, final String contents) {
321 buffer.append(" class=\"");
322 buffer.append(clazz);
323 buffer.append("\">");
324 if (contents != null) {
325 buffer.append(contents);
331 return buffer.toString();
337 public boolean isEscapable(final String tagName, final String uri) {
338 return !"latex".equals(tagName) && !"screen".equals(tagName) && !"programlisting".equals(tagName) && !"code".equals(tagName) && !"synopsis".equals(tagName) && !(uri.equals(SCILAB_URI) && tagName.equals("image"));
344 public boolean isTrimable(final String tagName) {
345 return !"screen".equals(tagName) && !"programlisting".equals(tagName) && !"code".equals(tagName) && !"synopsis".equals(tagName);
349 * @param fileName the file to create
350 * @param subtitle the subtitle of the file
351 * @param contents the contents of the file
353 public void createHTMLFile(final String id, final String fileName, final String subtitle, final String contents) {
355 fileSubtitle = subtitle;
357 templateHandler.generateFileFromTemplate(outName + fileName, id, contents);
364 * @param code the code to translate
365 * @param img image information
366 * @param fileName the filename
367 * @param attrs the attribute of the image
368 * @return the HTML code to insert the image
370 public String generateCode(Image img, String fileName, Map<String, String> attrs, final String tooltipString) {
371 String style = attrs.get("style");
373 boolean display = style != null && style.equals("display");
376 top = "top:" + img.descent + "px;";
379 String alignAttr = attrs.get("align");
382 if (alignAttr != null) {
383 align = " style=\'text-align:" + alignAttr + "\'";
384 } else if (display) {
385 align = " style=\'text-align:center\'";
390 return "<" + div + align + "><img src=\'" + fileName + "\' style=\'position:relative;" + top + "width:" + img.width + "px;height:" + img.height + "px\'/></" + div + ">";
396 public String makeTitle(final String id) {
397 if (refname.length() > 0) {
398 return tocitem.get(id);
407 public String makeSubtitle(final String id) {
414 public String makePrevious(final String id) {
416 buffer.append("<span class=\"previous\">");
417 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
421 HTMLDocbookLinkResolver.TreeId prev = leaf.getPrevious();
422 if (prev.parent != null) {
423 buffer.append("<a href=\"");
424 buffer.append(mapId.get(prev.id));
425 buffer.append("\"><< ");
426 buffer.append(tocitem.get(prev.id));
427 buffer.append("</a></span>\n");
429 return buffer.toString();
438 public String makePath(final String id) {
440 buffer.append("<span class=\"path\">");
441 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
445 String str = tocitem.get(id);
447 while (leaf != null && !leaf.isRoot()) {
448 str = "<a href=\"" + mapId.get(leaf.id) + "\">" + tocitem.get(leaf.id) + "</a> > " + str;
452 str = "<a href=\"" + indexFilename + "\">" + bookTitle + "</a> >> " + str;
454 buffer.append("</span>\n");
456 return buffer.toString();
462 public String makeTop(final String id) {
464 buffer.append("<span class=\"top\">");
465 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
472 buffer.append("<a href=\"");
473 if (!leaf.isRoot()) {
474 buffer.append(mapId.get(leaf.id));
475 buffer.append("\">");
476 buffer.append(tocitem.get(leaf.id));
478 buffer.append(indexFilename);
479 buffer.append("\">");
480 buffer.append(bookTitle);
482 buffer.append("</a></span>\n");
487 return buffer.toString();
493 public String makeNext(final String id) {
495 buffer.append("<span class=\"next\">");
496 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
500 HTMLDocbookLinkResolver.TreeId next = leaf.getNext();
502 buffer.append("<a href=\"");
503 buffer.append(mapId.get(next.id));
504 buffer.append("\">");
505 buffer.append(tocitem.get(next.id));
506 buffer.append(" >></a></span>\n");
508 return buffer.toString();
517 public String makeStart(final String id) {
519 buffer.append("<span class=\"start\">");
520 buffer.append("<a href=\"");
521 buffer.append(indexFilename);
522 buffer.append("\">");
523 buffer.append(bookTitle);
524 buffer.append("</a></span>\n");
526 return buffer.toString();
532 public String makeTocList(final String id) {
534 HTMLDocbookLinkResolver.TreeId leaf = mapTreeId.get(id);
539 HTMLDocbookLinkResolver.TreeId parent = leaf.parent;
540 buffer.append("<ul class=\"toc\">\n");
542 while (parent != null && !parent.isRoot()) {
543 str = "<li class=\"parent\"><a href=\"" + mapId.get(parent.id) + "\">" + tocitem.get(parent.id) + "</a></li>\n" + str;
544 parent = parent.parent;
546 buffer.append("<li class=\"root\"><a href=\"");
547 buffer.append(indexFilename);
548 buffer.append("\">");
549 buffer.append(bookTitle);
550 buffer.append("</a></li>\n");
553 parent = leaf.parent;
555 for (HTMLDocbookLinkResolver.TreeId c : parent.children) {
557 buffer.append("<li class=\"list-active\"><a href=\"");
559 buffer.append("<li><a href=\"");
561 buffer.append(mapId.get(c.id));
562 buffer.append("\">");
563 buffer.append(tocitem.get(c.id));
564 buffer.append("</a></li>\n");
566 buffer.append("</ul>\n");
568 return buffer.toString();
574 public String makeLastModified(final String id) {
577 buffer.append("<span class=\"lastmodified\">");
578 buffer.append(new Date(new File(new URI(currentFileName)).lastModified()).toString());
579 buffer.append("</span>\n");
580 } catch (URISyntaxException e) {
583 return buffer.toString();
589 public String makeGenerationDate(final String id) {
591 buffer.append("<span class=\"generationdate\">");
592 buffer.append(new Date(System.currentTimeMillis()).toString());
593 buffer.append("</span>\n");
595 return buffer.toString();
601 public String makeVersion(final String id) {
603 buffer.append("<span class=\"version\">");
604 buffer.append(version);
605 buffer.append("</span>\n");
607 return buffer.toString();
610 private boolean isLinkedImage() {
611 Stack<DocbookElement> stack = getStack();
612 return stack.size() >= 3 && stack.get(stack.size() - 3).getName().equals("link");
616 public String generateImageCode(String code, String fileName, Map<String, String> attrs) {
617 String alignAttr = attrs.get("align");
618 boolean addDiv = getGenerationType() != Backend.JAVAHELP || !isLinkedImage();
619 final StringBuilder buffer = new StringBuilder(128);
620 if (addDiv && alignAttr != null) {
621 buffer.append("<div style=\'text-align:").append(alignAttr).append("\'>");
623 buffer.append("<img src=\'").append(fileName).append("\'/>");
624 if (addDiv && alignAttr != null) {
625 buffer.append("</div>");
628 if (getGenerationType() == Backend.WEB) {
629 /* Prepare the code for the html inclusion */
630 code = convertCode(code);
631 /* Provide a tooltip */
632 return "<div rel='tooltip' title='" + code + "'>" + buffer.toString() + "</div>";
634 /* No tooltip in the javahelp browser ...
635 * too limited html capabilities */
636 return buffer.toString();
641 public String generateImageCode(Image img, String fileName, Map<String, String> attrs) {
642 String style = attrs.get("style");
644 boolean display = style != null && style.equals("display");
647 top = "top:" + img.descent + "px;";
650 String alignAttr = attrs.get("align");
653 if (alignAttr != null) {
654 align = " style=\'text-align:" + alignAttr + "\'";
655 } else if (display) {
656 align = " style=\'text-align:center\'";
661 if (getGenerationType() == Backend.JAVAHELP && isLinkedImage()) {
662 // Java HTML renderer is not good... so when the image is linked, we remove the div
663 return "<img src=\'" + fileName + "\' style=\'position:relative;" + top + "width:" + img.width + "px;height:" + img.height + "px\'/>>";
665 return "<" + div + align + "><img src=\'" + fileName + "\' style=\'position:relative;" + top + "width:" + img.width + "px;height:" + img.height + "px\'/></" + div + ">";
670 public String generateImageCode(String fileName, Map<String, String> attrs) {
671 String alignAttr = attrs.get("align");
672 boolean addDiv = getGenerationType() != Backend.JAVAHELP || !isLinkedImage();
673 final StringBuilder buffer = new StringBuilder(128);
674 if (addDiv && alignAttr != null) {
675 buffer.append("<div style=\'text-align:").append(alignAttr).append("\'>");
677 buffer.append("<img src=\'").append(fileName).append("\'/>");
678 if (addDiv && alignAttr != null) {
679 buffer.append("</div>");
682 return buffer.toString();
685 public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
687 return super.resolveEntity(publicId, systemId);
692 * @param attributes the tag attributes
693 * @param contents the tag contents
694 * @return the HTML code
695 * @throws SAXEception if an error is encountered
697 public String handleRefentry(final Map<String, String> attributes, final String contents) throws SAXException {
698 String id = attributes.get("id");
702 String fileName = mapId.get(currentId);
703 String needsExampleAttr = attributes.get("needs-examples");
704 createHTMLFile(currentId, fileName, refpurpose, contents);
705 if (!hasExamples && (needsExampleAttr == null || !needsExampleAttr.equals("no"))) {
707 //System.err.println("Warning (should be fixed): no example in " + currentFileName);
711 String rp = encloseContents("span", "refentry-description", refpurpose);
712 String str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "refentry"}, refname) + " — " + rp);
722 * @param attributes the tag attributes
723 * @param contents the tag contents
724 * @return the HTML code
725 * @throws SAXEception if an error is encountered
727 public String handleSection(final Map<String, String> attributes, final String contents) throws SAXException {
728 String fileName = attributes.get("id") + ".html";
729 String str = encloseContents("ul", "list-refentry", contents);
730 String title = encloseContents("h3", "title-section", sectionTitle);
731 createHTMLFile(attributes.get("id"), fileName, sectionTitle, title + "\n" + str);
733 str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "section"}, sectionTitle) + "\n" + str);
741 * @param attributes the tag attributes
742 * @param contents the tag contents
743 * @return the HTML code
744 * @throws SAXEception if an error is encountered
746 public String handleBook(final Map<String, String> attributes, final String contents) throws SAXException {
747 String str = encloseContents("ul", "list-part", contents);
749 if (bookTitle.trim().equalsIgnoreCase("Scilab")) {
754 String title = encloseContents("h3", "book-title", btitle);
755 createHTMLFile("index", indexFilename, btitle, title + "\n" + str);
758 System.err.println("Total files without example: " + warnings);
759 System.err.println("Total generated html files: " + nbFiles);
762 return encloseContents("li", encloseContents("a", new String[] {"href", indexFilename, "class", "part"}, bookTitle) + "\n" + str);
767 * @param attributes the tag attributes
768 * @param contents the tag contents
769 * @return the HTML code
770 * @throws SAXEception if an error is encountered
772 public String handlePart(final Map<String, String> attributes, final String contents) throws SAXException {
773 String fileName = attributes.get("id") + ".html";
774 String str = encloseContents("ul", "list-chapter", contents);
775 String title = encloseContents("h3", "title-part", partTitle);
776 createHTMLFile(attributes.get("id"), fileName, partTitle, title + "\n" + str);
777 str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "part"}, partTitle) + "\n" + str);
785 * @param attributes the tag attributes
786 * @param contents the tag contents
787 * @return the HTML code
788 * @throws SAXEception if an error is encountered
790 public String handleChapter(final Map<String, String> attributes, final String contents) throws SAXException {
791 String fileName = attributes.get("id") + ".html";
792 String str = encloseContents("ul", "list-refentry", contents);
793 String title = encloseContents("h3", "title-chapter", chapterTitle);
794 createHTMLFile(attributes.get("id"), fileName, chapterTitle, title + "\n" + str);
796 str = encloseContents("li", encloseContents("a", new String[] {"href", fileName, "class", "chapter"}, chapterTitle) + "\n" + str);
802 // partiellement merdique car le style de title depend du noeud pere.
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 handleTitle(final Map<String, String> attributes, final String contents) throws SAXException {
811 String clazz = "title";
812 String parent = getParentTagName();
813 if (parent.equals("chapter")) {
814 chapterTitle = contents;
815 } else if (parent.equals("part")) {
816 partTitle = contents;
817 } else if (parent.equals("info")) {
818 bookTitle = contents;
819 } else if (parent.equals("section")) {
820 sectionTitle = contents;
821 } else if (parent.equals("refsection") && Pattern.matches("^[ \\t]*ex[ea]mpl[eo].*", contents.toLowerCase())) {
823 return encloseContents("h3", clazz, contents);
824 } else if (parent.equals("refsect1")) {
825 return encloseContents("h3", clazz, contents);
826 } else if (parent.equals("refsect2")) {
827 return encloseContents("h4", clazz, contents);
828 } else if (parent.equals("refsect3")) {
829 return encloseContents("h5", clazz, contents);
831 return encloseContents("h3", clazz, contents);
839 * @param attributes the tag attributes
840 * @param contents the tag contents
841 * @return the HTML code
842 * @throws SAXEception if an error is encountered
844 public String handlePara(final Map<String, String> attributes, final String contents) throws SAXException {
845 return encloseContents("p", "para", contents);
850 * @param attributes the tag attributes
851 * @param contents the tag contents
852 * @return the HTML code
853 * @throws SAXEception if an error is encountered
855 public String handleLiteral(final Map<String, String> attributes, final String contents) throws SAXException {
856 return encloseContents("code", "literal", contents);
860 * Handle a literallayout
861 * @param attributes the tag attributes
862 * @param contents the tag contents
863 * @return the HTML code
864 * @throws SAXEception if an error is encountered
866 public String handleLiterallayout(final Map<String, String> attributes, final String contents) throws SAXException {
869 String s = contents.replace("\n", "<BR>");
870 //replace spaces by
871 s = s.replace(" ", " ");
873 return encloseContents("code", "literallayout", s);
878 * @param attributes the tag attributes
879 * @param contents the tag contents
880 * @return the HTML code
881 * @throws SAXEception if an error is encountered
883 public String handleVarname(final Map<String, String> attributes, final String contents) throws SAXException {
884 return encloseContents("code", "varname", contents);
889 * @param attributes the tag attributes
890 * @param contents the tag contents
891 * @return the HTML code
892 * @throws SAXEception if an error is encountered
894 public String handleCommand(final Map<String, String> attributes, final String contents) throws SAXException {
895 return encloseContents("code", "command", contents);
900 * @param attributes the tag attributes
901 * @param contents the tag contents
902 * @return the HTML code
903 * @throws SAXEception if an error is encountered
905 public String handleCode(final Map<String, String> attributes, final String contents) throws SAXException {
906 return encloseContents("code", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));//encloseContents("code", "code", contents);
911 * @param attributes the tag attributes
912 * @param contents the tag contents
913 * @return the HTML code
914 * @throws SAXEception if an error is encountered
916 public String handleFunction(final Map<String, String> attributes, final String contents) throws SAXException {
917 return encloseContents("code", "function", contents);
922 * @param attributes the tag attributes
923 * @param contents the tag contents
924 * @return the HTML code
925 * @throws SAXEception if an error is encountered
927 public String handleConstant(final Map<String, String> attributes, final String contents) throws SAXException {
928 return encloseContents("code", "constant", contents);
933 * @param attributes the tag attributes
934 * @param contents the tag contents
935 * @return the HTML code
936 * @throws SAXEception if an error is encountered
938 public String handleOption(final Map<String, String> attributes, final String contents) throws SAXException {
939 return encloseContents("code", "option", contents);
943 * Handle a refnamediv
944 * @param attributes the tag attributes
945 * @param contents the tag contents
946 * @return the HTML code
947 * @throws SAXEception if an error is encountered
949 public String handleRefnamediv(final Map<String, String> attributes, final String contents) throws SAXException {
950 String id = attributes.get("id");
955 return encloseContents("div", "refnamediv", contents);
960 * @param attributes the tag attributes
961 * @param contents the tag contents
962 * @return the HTML code
963 * @throws SAXEception if an error is encountered
965 public String handleRefname(final Map<String, String> attributes, final String contents) throws SAXException {
967 return encloseContents("h1", "refname", contents);
971 * Handle a refpurpose
972 * @param attributes the tag attributes
973 * @param contents the tag contents
974 * @return the HTML code
975 * @throws SAXEception if an error is encountered
977 public String handleRefpurpose(final Map<String, String> attributes, final String contents) throws SAXException {
978 refpurpose = contents;
979 return encloseContents("p", "refpurpose", contents);
983 * Handle a refsynopsisdiv
984 * @param attributes the tag attributes
985 * @param contents the tag contents
986 * @return the HTML code
987 * @throws SAXEception if an error is encountered
989 public String handleRefsynopsisdiv(final Map<String, String> attributes, final String contents) throws SAXException {
990 String id = attributes.get("id");
992 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "refsynopsisdiv", contents);
994 return encloseContents("div", "refsynopsisdiv", contents);
1000 * @param attributes the tag attributes
1001 * @param contents the tag contents
1002 * @return the HTML code
1003 * @throws SAXEception if an error is encountered
1005 public String handleSynopsis(final Map<String, String> attributes, final String contents) throws SAXException {
1006 String id = attributes.get("id");
1007 String str = encloseContents("div", "synopsis", encloseContents("pre", SynopsisLexer.convert(refname, contents)));
1009 return "<a name=\"" + id + "\"></a>" + str;
1017 * @param attributes the tag attributes
1018 * @param contents the tag contents
1019 * @return the HTML code
1020 * @throws SAXEception if an error is encountered
1022 public String handleInfo(final Map<String, String> attributes, final String contents) throws SAXException {
1023 String id = attributes.get("id");
1025 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "info", contents);
1027 return encloseContents("div", "info", contents);
1032 * Handle a refsection
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 handleRefsection(final Map<String, String> attributes, final String contents) throws SAXException {
1039 String id = attributes.get("id");
1041 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "refsection", contents);
1043 return encloseContents("div", "refsection", contents);
1049 * @param attributes the tag attributes
1050 * @param contents the tag contents
1051 * @return the HTML code
1052 * @throws SAXEception if an error is encountered
1054 public String handleRefsect1(final Map<String, String> attributes, final String contents) throws SAXException {
1055 String id = attributes.get("id");
1057 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "refsect1", contents);
1059 return encloseContents("div", "refsect1", contents);
1065 * @param attributes the tag attributes
1066 * @param contents the tag contents
1067 * @return the HTML code
1068 * @throws SAXEception if an error is encountered
1070 public String handleRefsect2(final Map<String, String> attributes, final String contents) throws SAXException {
1071 String id = attributes.get("id");
1073 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "refsect2", contents);
1075 return encloseContents("div", "refsect2", contents);
1081 * @param attributes the tag attributes
1082 * @param contents the tag contents
1083 * @return the HTML code
1084 * @throws SAXEception if an error is encountered
1086 public String handleRefsect3(final Map<String, String> attributes, final String contents) throws SAXException {
1087 String id = attributes.get("id");
1089 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "refsect3", contents);
1091 return encloseContents("div", "refsect3", contents);
1097 * @param attributes the tag attributes
1098 * @param contents the tag contents
1099 * @return the HTML code
1100 * @throws SAXEception if an error is encountered
1102 public String handleAnchor(final Map<String, String> attributes, final String contents) throws SAXException {
1103 String id = attributes.get("id");
1105 return "<a name=\"" + id + "\">" + contents + "</a>";
1112 * Handle a progamlisting
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 handleProgramlisting(final Map<String, String> attributes, final String contents) throws SAXException {
1119 String id = attributes.get("id");
1120 String role = attributes.get("role");
1123 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
1124 if (prependToProgramListing != null) {
1125 code = prependToProgramListing + code;
1127 if (appendToProgramListing != null) {
1128 code += appendToProgramListing;
1130 str = encloseContents("div", "programlisting", code);
1132 if (role.equals("xml")) {
1133 str = encloseContents("div", "programlisting", encloseContents("pre", "xmlcode", xmlLexer.convert(HTMLXMLCodeHandler.getInstance(), contents)));
1134 } else if (role.equals("c") || role.equals("cpp") || role.equals("code_gateway")) {
1136 str = encloseContents("div", "programlisting", encloseContents("pre", "ccode", cLexer.convert(HTMLCCodeHandler.getInstance(), contents)));
1137 } else if (role.equals("java")) {
1139 str = encloseContents("div", "programlisting", encloseContents("pre", "ccode", javaLexer.convert(HTMLCCodeHandler.getInstance(), contents)));
1140 } else if (role.equals("exec")) {
1141 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
1142 if (prependToProgramListing != null) {
1143 code = prependToProgramListing + code;
1145 if (appendForExecToProgramListing != null) {
1146 code += appendForExecToProgramListing;
1148 str = encloseContents("div", "programlisting", code);
1149 } else if (role.equals("no-scilab-exec")) {
1151 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
1152 str = encloseContents("div", "programlisting", code);
1154 String code = encloseContents("pre", "scilabcode", scilabLexer.convert(HTMLScilabCodeHandler.getInstance(refname, currentFileName), contents));
1155 if (prependToProgramListing != null) {
1156 code = prependToProgramListing + code;
1158 if (appendToProgramListing != null) {
1159 code += appendToProgramListing;
1161 str = encloseContents("div", "programlisting", code);
1165 return "<a name=\"" + id + "\"></a>" + str;
1173 * @param attributes the tag attributes
1174 * @param contents the tag contents
1175 * @return the HTML code
1176 * @throws SAXEception if an error is encountered
1178 public String handleScreen(final Map<String, String> attributes, final String contents) throws SAXException {
1179 String id = attributes.get("id");
1180 String str = encloseContents("div", "screen", encloseContents("pre", contents));
1182 return "<a name=\"" + id + "\"></a>" + str;
1190 * @param attributes the tag attributes
1191 * @param contents the tag contents
1192 * @return the HTML code
1193 * @throws SAXEception if an error is encountered
1195 public String handlePubdate(final Map<String, String> attributes, final String contents) throws SAXException {
1200 * Handle a simplelist
1201 * @param attributes the tag attributes
1202 * @param contents the tag contents
1203 * @return the HTML code
1204 * @throws SAXEception if an error is encountered
1206 public String handleSimplelist(final Map<String, String> attributes, final String contents) throws SAXException {
1207 String style = "itemizedlist";
1209 return encloseContents("ul", style, contents);
1214 * @param attributes the tag attributes
1215 * @param contents the tag contents
1216 * @return the HTML code
1217 * @throws SAXEception if an error is encountered
1219 public String handleMember(final Map<String, String> attributes, final String contents) throws SAXException {
1220 return encloseContents("li", "member", contents);
1225 * @param attributes the tag attributes
1226 * @param contents the tag contents
1227 * @return the HTML code
1228 * @throws SAXEception if an error is encountered
1230 public String handleLink(final Map<String, String> attributes, final String contents) throws SAXException {
1231 String link = attributes.get("linkend");
1233 throw new SAXException("No linkend attribute in tag link");
1236 String type = attributes.get("type");
1238 if (type != null && type.equals("scilab")) {
1239 if (this.type == Backend.JAVAHELP || this.type == Backend.HTML) {
1240 id = resolvScilabLink(link);
1244 } else if (type != null && type.equals("remote")) {
1245 id = makeRemoteLink(link);
1247 id = mapId.get(link);
1252 if (this.type == Backend.HTML) {
1253 id = urlBase + link;
1258 if (this.type == Backend.JAVAHELP) {
1259 id = urlBase + link;
1263 System.err.println("Warning (should be fixed): invalid internal link to " + link + " in " + currentFileName + "\nat line " + locator.getLineNumber());
1268 Stack<DocbookElement> stack = getStack();
1269 String refnameTarget = mapIdRefname.get(link);
1271 if (contents != null && !contents.isEmpty()) {
1274 str = refnameTarget;
1279 System.err.println("Warning (should be fixed): empty link (no text will be printed) to " + link + " in " + currentFileName + "\nat line " + locator.getLineNumber());
1282 String href = encloseContents("a", new String[] {"href", id, "class", "link"}, str);
1284 int s = stack.size();
1286 DocbookElement elem = stack.get(s - 3);
1287 if (elem.getName().equals("refsection")) {
1288 String role = elem.getAttributes().get("role");
1289 if (role != null && role.equals("see also")) {
1290 String purpose = mapIdPurpose.get(link);
1291 if (purpose != null) {
1292 return href + " — " + purpose;
1304 * Rewrite a link when its type is "scilab"
1305 * @param link the link
1306 * @return the modified link with protocol scilab:// for example
1308 protected String resolvScilabLink(String link) {
1309 int pos = link.indexOf("/");
1314 String first = link.substring(0, pos);
1315 String second = link.substring(pos + 1);
1316 String[] toks = first.split("\\.");
1317 if (toks == null || toks.length != 2) {
1321 if (!linkToTheWeb) {
1322 return urlBase + link;
1324 if (toks[0].equals("scilab") && toks[1].equals("help")) {
1325 return urlBase + second + ".html";
1333 * Make a remote link
1334 * @param link the link
1335 * @return the good link
1337 protected String makeRemoteLink(String link) {
1343 * @param attributes the tag attributes
1344 * @param contents the tag contents
1345 * @return the HTML code
1346 * @throws SAXEception if an error is encountered
1348 public String handleUlink(final Map<String, String> attributes, final String contents) throws SAXException {
1349 String link = attributes.get("url");
1351 throw new SAXException("No url attribute in tag ulink");
1354 return encloseContents("a", new String[] {"href", link, "class", "ulink"}, contents);
1359 * @param attributes the tag attributes
1360 * @param contents the tag contents
1361 * @return the HTML code
1362 * @throws SAXEception if an error is encountered
1364 public String handleXref(final Map<String, String> attributes, final String contents) throws SAXException {
1365 String link = attributes.get("linkend");
1367 throw new SAXException("No linkend attribute in tag link");
1370 String id = mapId.get(link);
1373 System.err.println("Warning (should be fixed): invalid internal link to " + link + " in " + currentFileName + "\nat line " + locator.getLineNumber());
1377 return encloseContents("a", new String[] {"href", id, "class", "xref"}, contents);
1381 * Handle a latex (not really a docbook tag...)
1382 * @param attributes the tag attributes
1383 * @param contents the tag contents
1384 * @return the HTML code
1385 * @throws SAXEception if an error is encountered
1387 public String handleLatex(final Map<String, String> attributes, final String contents) throws SAXException {
1388 boolean isLocalized = "true".equals(attributes.get("localized"));
1391 f = new File(outImages + "/" + imageDir, LATEXBASENAME + currentBaseName + "_" + language + "_" + (latexCompt++) + ".png");
1393 if ("ru_RU".equals(language) && HTMLDocbookTagConverter.containsCyrillic(contents)) {
1394 System.err.println("Warning: LaTeX code in " + getCurrentFileName() + " contains cyrillic character. The tag <latex> should contain the attribute scilab:localized=\"true\"");
1395 } else if ("ja_JP".equals(language) && HTMLDocbookTagConverter.containsCJK(contents)) {
1396 System.err.println("Warning: LaTeX code in " + getCurrentFileName() + " contains CJK character. The tag <latex> should contain the attribute scilab:localized=\"true\"");
1398 f = new File(outImages + "/" + imageDir, LATEXBASENAME + currentBaseName + "_" + (latexCompt++) + ".png");
1401 String parent = getParentTagName();
1402 if (parent.equals("para") && !attributes.containsKey("style")) {
1403 attributes.put("style", "text");
1405 String fs = attributes.get("fontsize");
1407 attributes.put("fontsize", "16");
1410 return getImageConverter().getImageByCode(currentFileName, contents, attributes, "image/latex", f, imageDir + "/" + f.getName(), getBaseImagePath(), locator.getLineNumber(), language, isLocalized);
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 handleTerm(final Map<String, String> attributes, final String contents) throws SAXException {
1421 String id = attributes.get("id");
1423 return "<a name=\"" + id + "\"></a>" + encloseContents("span", "term", contents);
1425 return encloseContents("span", "term", contents);
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 handleListitem(final Map<String, String> attributes, final String contents) throws SAXException {
1437 String parent = getParentTagName();
1438 if (parent.equals("varlistentry")) {
1439 return encloseContents("dd", contents);
1441 return encloseContents("li", contents);
1445 * Handle a varlistentry
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 handleVarlistentry(final Map<String, String> attributes, final String contents) throws SAXException {
1452 return encloseContents("dt", contents);
1456 * Handle a variablelist
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 handleVariablelist(final Map<String, String> attributes, final String contents) throws SAXException {
1463 return encloseContents("dl", contents);
1467 * Handle an itemizedlist
1468 * @param attributes the tag attributes
1469 * @param contents the tag contents
1470 * @return the HTML code
1471 * @throws SAXEception if an error is encountered
1473 public String handleItemizedlist(final Map<String, String> attributes, final String contents) throws SAXException {
1474 String id = attributes.get("id");
1476 return "<a name=\"" + id + "\"></a>" + encloseContents("ul", "itemizedlist", contents);
1478 return encloseContents("ul", "itemizedlist", contents);
1483 * Handle an emphasis
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 handleEmphasis(final Map<String, String> attributes, final String contents) throws SAXException {
1490 String role = attributes.get("role");
1492 if (role.equals("bold")) {
1493 return encloseContents("b", contents);
1495 if (role.equals("italic")) {
1496 return encloseContents("i", contents);
1500 return encloseContents("em", contents);
1505 * @param attributes the tag attributes
1506 * @param contents the tag contents
1507 * @return the HTML code
1508 * @throws SAXEception if an error is encountered
1510 public String handleTr(final Map<String, String> attributes, final String contents) throws SAXException {
1511 String bgcolor = attributes.get("bgcolor");
1513 return encloseContents("tr", new String[] {"bgcolor", bgcolor}, contents);
1518 * @param attributes the tag attributes
1519 * @param contents the tag contents
1520 * @return the HTML code
1521 * @throws SAXEception if an error is encountered
1523 public String handleTd(final Map<String, String> attributes, final String contents) throws SAXException {
1524 String align = attributes.get("align");
1525 String bgcolor = attributes.get("bgcolor");
1526 String colspan = attributes.get("colspan");
1527 String rowspan = attributes.get("rowspan");
1529 return encloseContents("td", new String[] {"align", align, "bgcolor", bgcolor, "colspan", colspan, "rowspan", rowspan}, contents);
1533 * Handle an informaltable
1534 * @param attributes the tag attributes
1535 * @param contents the tag contents
1536 * @return the HTML code
1537 * @throws SAXEception if an error is encountered
1539 public String handleInformaltable(final Map<String, String> attributes, final String contents) throws SAXException {
1540 String id = attributes.get("id");
1541 String border = attributes.get("border");
1542 String cellpadding = attributes.get("cellpadding");
1543 String width = attributes.get("width");
1545 return "<a name=\"" + id + "\"></a>" + encloseContents("table", new String[] {"class", "informaltable", "border", border, "cellpadding", cellpadding, "width", width}, contents);
1547 return encloseContents("table", new String[] {"class", "informaltable", "border", border, "cellpadding", cellpadding, "width", width}, contents);
1552 * Handle an imagedata
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 handleImagedata(final Map<String, String> attributes, final String contents) throws SAXException {
1559 String fileref = attributes.get("fileref");
1560 if (fileref == null) {
1561 if (contents == null || contents.length() == 0) {
1562 throw new SAXException("No fileref attribute or no data in tag imagedata");
1569 String path = new File(new URI(currentFileName)).getParent();
1570 File file = ImageConverter.imageExists(path, fileref);
1572 throw new SAXException("The given fileref is not on an existing image file:\n" + fileref + " [" + file + "]");
1575 return getImageConverter().getImageByFile(attributes, path, fileref, outImages, imageDir, getBaseImagePath());
1576 } catch (URISyntaxException e) {
1577 System.err.println(e);
1584 * Handle an imageobject
1585 * @param attributes the tag attributes
1586 * @param contents the tag contents
1587 * @return the HTML code
1588 * @throws SAXEception if an error is encountered
1590 public String handleImageobject(final Map<String, String> attributes, final String contents) throws SAXException {
1595 * Handle an textobject (as an alternative to imageobject)
1596 * @param attributes the tag attributes
1597 * @param contents the tag contents
1598 * @return the HTML code
1599 * @throws SAXEception if an error is encountered
1601 public String handleTextobject(final Map<String, String> attributes, final String contents) throws SAXException {
1602 return "<!-- " + contents + " -->";
1606 * Handle an inlinemediaobject
1607 * @param attributes the tag attributes
1608 * @param contents the tag contents
1609 * @return the HTML code
1610 * @throws SAXEception if an error is encountered
1612 public String handleInlinemediaobject(final Map<String, String> attributes, final String contents) throws SAXException {
1613 return encloseContents("span", contents);
1617 * Handle a screenshot
1618 * @param attributes the tag attributes
1619 * @param contents the tag contents
1620 * @return the HTML code
1621 * @throws SAXEception if an error is encountered
1623 public String handleScreenshot(final Map<String, String> attributes, final String contents) throws SAXException {
1624 String id = attributes.get("id");
1626 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "screenshot", contents);
1628 return encloseContents("div", "screenshot", contents);
1633 * Handle a mediaobject
1634 * @param attributes the tag attributes
1635 * @param contents the tag contents
1636 * @return the HTML code
1637 * @throws SAXEception if an error is encountered
1639 public String handleMediaobject(final Map<String, String> attributes, final String contents) throws SAXException {
1640 String id = attributes.get("id");
1641 String c = contents.replaceFirst("top:([0-9]+)px;", "");
1643 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "mediaobject", c);
1645 return encloseContents("div", "mediaobject", c);
1650 * Handle an informalequation
1651 * @param attributes the tag attributes
1652 * @param contents the tag contents
1653 * @return the HTML code
1654 * @throws SAXEception if an error is encountered
1656 public String handleInformalequation(final Map<String, String> attributes, final String contents) throws SAXException {
1657 String id = attributes.get("id");
1659 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "informalequation", contents);
1661 return encloseContents("div", "informalequation", contents);
1666 * Handle an orderedlist
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 handleOrderedlist(final Map<String, String> attributes, final String contents) throws SAXException {
1673 String numeration = "1";
1674 String numAttr = attributes.get("numeration");
1675 if (numAttr != null) {
1676 if (numAttr.equals("loweralpha")) {
1678 } else if (numAttr.equals("upperalpha")) {
1680 } else if (numAttr.equals("lowerroman")) {
1682 } else if (numAttr.equals("upperroman")) {
1687 String id = attributes.get("id");
1689 return "<a name=\"" + id + "\"></a>" + encloseContents("ol", new String[] {"type", numeration}, contents);
1691 return encloseContents("ol", new String[] {"type", numeration}, contents);
1696 * Handle a subscript
1697 * @param attributes the tag attributes
1698 * @param contents the tag contents
1699 * @return the HTML code
1700 * @throws SAXEception if an error is encountered
1702 public String handleSubscript(final Map<String, String> attributes, final String contents) throws SAXException {
1703 return encloseContents("sub", contents);
1707 * Handle a superscript
1708 * @param attributes the tag attributes
1709 * @param contents the tag contents
1710 * @return the HTML code
1711 * @throws SAXEception if an error is encountered
1713 public String handleSuperscript(final Map<String, String> attributes, final String contents) throws SAXException {
1714 return encloseContents("sup", contents);
1718 * Handle a replaceable
1719 * @param attributes the tag attributes
1720 * @param contents the tag contents
1721 * @return the HTML code
1722 * @throws SAXEception if an error is encountered
1724 public String handleReplaceable(final Map<String, String> attributes, final String contents) throws SAXException {
1725 return encloseContents("span", "replaceable", contents);
1730 * @param attributes the tag attributes
1731 * @param contents the tag contents
1732 * @return the HTML code
1733 * @throws SAXEception if an error is encountered
1735 public String handleQuestion(final Map<String, String> attributes, final String contents) throws SAXException {
1736 return encloseContents("dt", encloseContents("strong", contents));
1741 * @param attributes the tag attributes
1742 * @param contents the tag contents
1743 * @return the HTML code
1744 * @throws SAXEception if an error is encountered
1746 public String handleAnswer(final Map<String, String> attributes, final String contents) throws SAXException {
1747 return encloseContents("dd", contents);
1751 * Handle a qandaentry
1752 * @param attributes the tag attributes
1753 * @param contents the tag contents
1754 * @return the HTML code
1755 * @throws SAXEception if an error is encountered
1757 public String handleQandaentry(final Map<String, String> attributes, final String contents) throws SAXException {
1758 return encloseContents("dl", contents);
1763 * @param attributes the tag attributes
1764 * @param contents the tag contents
1765 * @return the HTML code
1766 * @throws SAXEception if an error is encountered
1768 public String handleQandaset(final Map<String, String> attributes, final String contents) throws SAXException {
1769 return encloseContents("div", "qandaset", contents);
1774 * @param attributes the tag attributes
1775 * @param contents the tag contents
1776 * @return the HTML code
1777 * @throws SAXEception if an error is encountered
1779 public String handleCaption(final Map<String, String> attributes, final String contents) throws SAXException {
1780 return encloseContents("caption", encloseContents("b", contents));
1785 * @param attributes the tag attributes
1786 * @param contents the tag contents
1787 * @return the HTML code
1788 * @throws SAXEception if an error is encountered
1790 public String handleTbody(final Map<String, String> attributes, final String contents) throws SAXException {
1791 return encloseContents("tbody", "tbody", contents);
1796 * @param attributes the tag attributes
1797 * @param contents the tag contents
1798 * @return the HTML code
1799 * @throws SAXEception if an error is encountered
1801 public String handleTable(final Map<String, String> attributes, final String contents) throws SAXException {
1802 String id = attributes.get("id");
1803 String bgcolor = attributes.get("bgcolor");
1804 String border = attributes.get("border");
1805 String cellpadding = attributes.get("cellpadding");
1808 return "<a name=\"" + id + "\"></a>" + encloseContents("table", new String[] {"class", "doctable", "bgcolor", bgcolor, "border", border, "cellpadding", cellpadding}, contents);
1810 return encloseContents("table", new String[] {"class", "doctable", "bgcolor", bgcolor, "border", border, "cellpadding", cellpadding}, contents);
1816 * @param attributes the tag attributes
1817 * @param contents the tag contents
1818 * @return the HTML code
1819 * @throws SAXEception if an error is encountered
1821 public String handleSurname(final Map<String, String> attributes, final String contents) throws SAXException {
1822 return encloseContents("span", "surname", contents);
1826 * Handle a firstname
1827 * @param attributes the tag attributes
1828 * @param contents the tag contents
1829 * @return the HTML code
1830 * @throws SAXEception if an error is encountered
1832 public String handleFirstname(final Map<String, String> attributes, final String contents) throws SAXException {
1833 return encloseContents("span", "firstname", contents);
1837 * Handle a bibliomset
1838 * @param attributes the tag attributes
1839 * @param contents the tag contents
1840 * @return the HTML code
1841 * @throws SAXEception if an error is encountered
1843 public String handleBibliomset(final Map<String, String> attributes, final String contents) throws SAXException {
1844 String id = attributes.get("id");
1846 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "bibliomset", contents);
1848 return encloseContents("div", "bibliomset", contents);
1853 * Handle a bibliomixed
1854 * @param attributes the tag attributes
1855 * @param contents the tag contents
1856 * @return the HTML code
1857 * @throws SAXEception if an error is encountered
1859 public String handleBibliomixed(final Map<String, String> attributes, final String contents) throws SAXException {
1860 String id = attributes.get("id");
1862 return "<a name=\"" + id + "\"></a>" + encloseContents("div", "bibliomixed", contents);
1864 return encloseContents("div", "bibliomixed", contents);
1870 * @param attributes the tag attributes
1871 * @param contents the tag contents
1872 * @return the HTML code
1873 * @throws SAXEception if an error is encountered
1875 public String handleTh(final Map<String, String> attributes, final String contents) throws SAXException {
1876 return encloseContents("th", contents);
1880 * Handle a revhistory
1881 * @param attributes the tag attributes
1882 * @param contents the tag contents
1883 * @return the HTML code
1884 * @throws SAXEception if an error is encountered
1886 public String handleRevhistory(final Map<String, String> attributes, final String contents) throws SAXException {
1887 String id = attributes.get("id");
1888 String str = "<table class=\"revhistory\"><tr class=\"title\"><td>" + VERSION + "</td><td>" + DESCRIPTION + "</td></tr>" + contents + "</table>";
1890 return "<a name=\"" + id + "\"></a>" + str;
1898 * @param attributes the tag attributes
1899 * @param contents the tag contents
1900 * @return the HTML code
1901 * @throws SAXEception if an error is encountered
1903 public String handleRevision(final Map<String, String> attributes, final String contents) throws SAXException {
1904 return encloseContents("tr", contents);
1908 * Handle a revnumber
1909 * @param attributes the tag attributes
1910 * @param contents the tag contents
1911 * @return the HTML code
1912 * @throws SAXEception if an error is encountered
1914 public String handleRevnumber(final Map<String, String> attributes, final String contents) throws SAXException {
1915 return encloseContents("td", "revnumber", contents);
1919 * Handle a revremark
1920 * @param attributes the tag attributes
1921 * @param contents the tag contents
1922 * @return the HTML code
1923 * @throws SAXEception if an error is encountered
1925 public String handleRevremark(final Map<String, String> attributes, final String contents) throws SAXException {
1926 return encloseContents("td", "revremark", contents);
1930 * Handle a revdescription
1931 * @param attributes the tag attributes
1932 * @param contents the tag contents
1933 * @return the HTML code
1934 * @throws SAXEception if an error is encountered
1936 public String handleRevdescription(final Map<String, String> attributes, final String contents) throws SAXException {
1937 return encloseContents("td", "revdescription", contents);
1942 * @param attributes the tag attributes
1943 * @param contents the tag contents
1944 * @return the HTML code
1945 * @throws SAXEception if an error is encountered
1947 public String handleNote(final Map<String, String> attributes, final String contents) throws SAXException {
1948 String id = attributes.get("id");
1949 String code = "<table><tr><td valign=\"top\"><img src=\"" + getBaseImagePath() + "ScilabNote.png\"/></td><td valign=\"top\">" + encloseContents("div", "note", contents) + "</td></tr></table>";
1951 return "<a name=\"" + id + "\"></a>" + code;
1959 * @param attributes the tag attributes
1960 * @param contents the tag contents
1961 * @return the HTML code
1962 * @throws SAXEception if an error is encountered
1964 public String handleWarning(final Map<String, String> attributes, final String contents) throws SAXException {
1965 String id = attributes.get("id");
1966 String code = "<table><tr><td valign=\"top\"><img src=\"" + getBaseImagePath() + "ScilabWarning.png\"/></td><td valign=\"top\">" + encloseContents("div", "warning", contents) + "</td></tr></table>";
1968 return "<a name=\"" + id + "\"></a>" + code;
1976 * @param attributes the tag attributes
1977 * @param contents the tag contents
1978 * @return the HTML code
1979 * @throws SAXEception if an error is encountered
1981 public String handleCaution(final Map<String, String> attributes, final String contents) throws SAXException {
1982 String id = attributes.get("id");
1983 String code = "<table><tr><td valign=\"top\"><img src=\"" + getBaseImagePath() + "ScilabCaution.png\"/></td><td valign=\"top\">" + encloseContents("div", "caution", contents) + "</td></tr></table>";
1985 return "<a name=\"" + id + "\"></a>" + code;
1993 * @param attributes the tag attributes
1994 * @param contents the tag contents
1995 * @return the HTML code
1996 * @throws SAXEception if an error is encountered
1998 public String handleTip(final Map<String, String> attributes, final String contents) throws SAXException {
1999 String id = attributes.get("id");
2000 String code = "<table><tr><td valign=\"top\"><img src=\"" + getBaseImagePath() + "ScilabTip.png\"/></td><td valign=\"top\">" + encloseContents("div", "tip", contents) + "</td></tr></table>";
2002 return "<a name=\"" + id + "\"></a>" + code;
2009 * Handle a important
2010 * @param attributes the tag attributes
2011 * @param contents the tag contents
2012 * @return the HTML code
2013 * @throws SAXEception if an error is encountered
2015 public String handleImportant(final Map<String, String> attributes, final String contents) throws SAXException {
2016 String id = attributes.get("id");
2017 String code = "<table><tr><td valign=\"top\"><img src=\"" + getBaseImagePath() + "ScilabImportant.png\"/></td><td valign=\"top\">" + encloseContents("div", "important", contents) + "</td></tr></table>";
2019 return "<a name=\"" + id + "\"></a>" + code;
2025 private static final String convertCode(String code) {
2026 if (code == null || code.length() == 0) {
2030 StringBuffer buffer = new StringBuffer(2 * code.length());
2032 int end = code.length() - 1;
2033 char c = code.charAt(0);
2036 while (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
2038 c = code.charAt(++start);
2043 c = code.charAt(end);
2044 while (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
2046 c = code.charAt(--end);
2052 // replace chars by their html entities equivalent
2053 for (int j = start; j <= end; j++) {
2057 buffer.append("&");
2060 buffer.append("<");
2063 buffer.append(">");
2066 buffer.append("<br />");
2069 buffer.append("'");
2072 buffer.append(""");
2079 return buffer.toString();