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 SVG code
25 * @author Calixte DENIZET
27 public class HTMLSVGHandler extends ExternalXMLHandler {
29 private static final String SVG = "svg";
30 private static final String BASENAME = "Equation_SVG_";
32 private static HTMLSVGHandler instance;
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 HTMLSVGHandler(String outputDir, String baseDir) {
44 this.outputDir = outputDir + File.separator + baseDir;
45 this.baseDir = baseDir + "/";
48 public static HTMLSVGHandler getInstance(String outputDir, String baseDir) {
49 if (instance == null) {
50 instance = new HTMLSVGHandler(outputDir, baseDir);
59 public String getURI() {
60 return "http://www.w3.org/2000/svg";
66 public StringBuilder startExternalXML(String localName, Attributes attributes) {
67 recreateTag(buffer, localName, attributes);
68 if (SVG.equals(localName)) {
78 public String endExternalXML(String localName) {
79 if (SVG.equals(localName)) {
80 recreateTag(buffer, localName, null);
81 File f = new File(outputDir, BASENAME + (compt++) + ".png");
82 Map<String, String> attributes = new HashMap();
84 String ret = ImageConverter.getImageByCode(getConverter().getCurrentFileName(), buffer.toString(), attributes, "image/svg", f, baseDir + f.getName());
90 recreateTag(buffer, localName, null);