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.external;
16 import java.util.HashMap;
19 import org.xml.sax.Attributes;
21 import org.scilab.modules.helptools.image.ImageConverter;
24 * Handle the included SCILAB code
25 * @author Calixte DENIZET
27 public class HTMLScilabHandler extends ExternalXMLHandler {
29 private static final String SCILAB = "image";
30 private static final String BASENAME = "_";
32 private static HTMLScilabHandler instance;
34 private int compt = 1;
35 private StringBuilder buffer = new StringBuilder(8192);
36 private String baseDir;
37 private String outputDir;
41 * @param baseDir the base directory where to put the generated images
43 private HTMLScilabHandler(String outputDir, String baseDir) {
44 this.outputDir = outputDir + File.separator + baseDir;
45 this.baseDir = baseDir + "/";
48 public static HTMLScilabHandler getInstance(String outputDir, String baseDir) {
49 if (instance == null) {
50 instance = new HTMLScilabHandler(outputDir, baseDir);
56 public static HTMLScilabHandler getInstance() {
60 public void resetCompt() {
67 public String getURI() {
68 return "http://www.scilab.org";
74 public StringBuilder startExternalXML(String localName, Attributes attributes) {
75 recreateTag(buffer, localName, attributes);
76 if (SCILAB.equals(localName)) {
86 public String endExternalXML(String localName) {
87 if (SCILAB.equals(localName)) {
88 recreateTag(buffer, localName, null);
89 String currentFileName = getConverter().getCurrentFileName();
90 String baseName = new File(currentFileName).getName();
91 int dotpos = baseName.lastIndexOf('.');
93 baseName = baseName.substring(0, dotpos);
95 File f = new File(outputDir, baseName + BASENAME + (compt++) + ".png");
96 Map<String, String> attributes = new HashMap<String, String>();
98 String ret = ImageConverter.getImageByCode(currentFileName, buffer.toString(), attributes, "image/scilab", f, baseDir + f.getName());
104 recreateTag(buffer, localName, null);