* @param language the language to use ('en_US', 'fr_FR', ...)
*/
public CHMDocbookTagConverter(String inName, String outName, String[] primConf, String[] macroConf, String template, String version, String imageDir, String docWebsite, boolean isToolbox, String urlBase, String language) throws IOException, SAXException {
- super(inName, outName, primConf, macroConf, template, version, imageDir, isToolbox, urlBase);
+ super(inName, outName, primConf, macroConf, template, version, imageDir, isToolbox, urlBase, HTMLDocbookTagConverter.GenerationType.CHM);
this.outName = new File(outName).getCanonicalPath() + File.separator;
this.language = language;
this.docWebsite = docWebsite;
*/
public class HTMLDocbookTagConverter extends DocbookTagConverter implements TemplateFiller {
+ public static enum GenerationType { WEB, JAVAHELP, CHM, HTML };
+
private static final String SCILAB_URI = "http://www.scilab.org";
private static final String LATEXBASENAME = "Equation_LaTeX_";
private static final String VERSION = Messages.gettext("Version");
protected String indexFilename = "index" /*UUID.randomUUID().toString()*/ + ".html";
protected boolean isToolbox;
+ protected final GenerationType type;
/**
* Constructor
* @param isToolbox is true when compile a toolbox' help
* @param urlBase the base url for external link
*/
- public HTMLDocbookTagConverter(String inName, String outName, String[] primConf, String[] macroConf, String template, String version, String imageDir, boolean isToolbox, String urlBase) throws IOException, SAXException {
+ public HTMLDocbookTagConverter(String inName, String outName, String[] primConf, String[] macroConf, String template, String version, String imageDir, boolean isToolbox, String urlBase, GenerationType type) throws IOException, SAXException {
super(inName);
this.version = version;
this.urlBase = urlBase;
this.linkToTheWeb = urlBase != null && !urlBase.equals("scilab://");
this.isToolbox = isToolbox;
+ this.type = type;
if (isToolbox) {// we generate a toolbox's help
HTMLScilabCodeHandler.setLinkWriter(new AbstractScilabCodeHandler.LinkWriter() {
- public String getLink(String id) {
- if (id.length() > 0 && id.charAt(0) == '%') {
- id = id.replace("%", "percent");
- }
- String link = mapId.get(id);
- if (link == null) {
- return HTMLDocbookTagConverter.this.urlBase + id;
- } else {
- return link;
+ public String getLink(String id) {
+ if (id.length() > 0 && id.charAt(0) == '%') {
+ id = id.replace("%", "percent");
+ }
+ String link = mapId.get(id);
+ if (link == null) {
+ return HTMLDocbookTagConverter.this.urlBase + id;
+ } else {
+ return link;
+ }
}
- }
- });
+ });
} else {// we generate Scilab's help
HTMLScilabCodeHandler.setLinkWriter(new AbstractScilabCodeHandler.LinkWriter() {
- public String getLink(String id) {
- if (id.length() > 0 && id.charAt(0) == '%') {
- id = id.replace("%", "percent");
+ public String getLink(String id) {
+ if (id.length() > 0 && id.charAt(0) == '%') {
+ id = id.replace("%", "percent");
+ }
+ return mapId.get(id);
}
- return mapId.get(id);
- }
- });
+ });
}
xmlLexer = new XMLLexer();
javaLexer = new JavaLexer();
File tpl = new File(template);
templateHandler = new TemplateHandler(this, tpl);
- ImageConverter.registerExternalImageConverter(LaTeXImageConverter.getInstance());
- ImageConverter.registerExternalImageConverter(MathMLImageConverter.getInstance());
- ImageConverter.registerExternalImageConverter(SVGImageConverter.getInstance());
- ImageConverter.registerExternalImageConverter(ScilabImageConverter.getInstance());
+ ImageConverter.registerExternalImageConverter(LaTeXImageConverter.getInstance(type));
+ ImageConverter.registerExternalImageConverter(MathMLImageConverter.getInstance(type));
+ ImageConverter.registerExternalImageConverter(SVGImageConverter.getInstance(type));
+ ImageConverter.registerExternalImageConverter(ScilabImageConverter.getInstance(type));
+ }
+
+ /**
+ * Get the type of the generation
+ * @return the generation type
+ */
+ public final GenerationType getGenerationType() {
+ return type;
}
/**
* @param urlBase the base url for external link
*/
public JavaHelpDocbookTagConverter(String inName, String outName, String[] primConf, String[] macroConf, String template, String version, String imageDir, boolean isToolbox, String urlBase) throws IOException, SAXException {
- super(inName, outName, primConf, macroConf, template, version, imageDir, isToolbox, urlBase);
+ super(inName, outName, primConf, macroConf, template, version, imageDir, isToolbox, urlBase, HTMLDocbookTagConverter.GenerationType.JAVAHELP);
prependToProgramListing = "<table border=\"0\" width=\"100%\"><tr><td width=\"98%\">";
appendToProgramListing = "</td><td valign=\"top\"><a href=\"scilab://scilab.execexample/\"><img src=\"ScilabExecute.png\" border=\"0\"/></a></td><td valign=\"top\"><a href=\"scilab://scilab.editexample/\"><img src=\"ScilabEdit.png\" border=\"0\"/></a></td><td></td></tr></table>";
appendForExecToProgramListing = "</td><td valign=\"top\"><a href=\"scilab://scilab.execexample/\"><img src=\"ScilabExecute.png\" border=\"0\"/></a></td><td></td></tr></table>";
if (isToolbox) {
urlBase = conf.getWebSiteURL() + language + "/";
}
- if (format.equalsIgnoreCase("html") || format.equalsIgnoreCase("web")) {
- converter = new HTMLDocbookTagConverter(sourceDoc, outputDirectory, sciprim, scimacro, template, version, imagedir, isToolbox, urlBase);
+ if (format.equalsIgnoreCase("html")) {
+ converter = new HTMLDocbookTagConverter(sourceDoc, outputDirectory, sciprim, scimacro, template, version, imagedir, isToolbox, urlBase, HTMLDocbookTagConverter.GenerationType.HTML);
+ } else if (format.equalsIgnoreCase("web")) {
+ converter = new HTMLDocbookTagConverter(sourceDoc, outputDirectory, sciprim, scimacro, template, version, imagedir, isToolbox, urlBase, HTMLDocbookTagConverter.GenerationType.WEB);
} else if (format.equalsIgnoreCase("chm")) {
converter = new CHMDocbookTagConverter(sourceDoc, outputDirectory, sciprim, scimacro, template, version, imagedir, conf.getWebSiteURL(), isToolbox, urlBase, language);
}
converter.registerExternalXMLHandler(HTMLScilabHandler.getInstance(outputDirectory, imagedir));
converter.convert();
- fileToExec = ScilabImageConverter.getInstance().getFileWithScilabCode();
+ fileToExec = ScilabImageConverter.getFileWithScilabCode();
ScilabCommonsUtils.copyFile(new File(SCI + "/modules/helptools/data/css/scilab_code.css"), new File(outputDirectory + "/scilab_code.css"));
ScilabCommonsUtils.copyFile(new File(SCI + "/modules/helptools/data/css/xml_code.css"), new File(outputDirectory + "/xml_code.css"));
import org.scilab.forge.jlatexmath.TeXIcon;
import org.scilab.forge.jlatexmath.ParseException;
+import org.scilab.modules.helptools.HTMLDocbookTagConverter;
+
/**
* A LaTeX to PNG converter
* @author Calixte DENIZET
public class LaTeXImageConverter implements ExternalImageConverter {
private static LaTeXImageConverter instance;
+ private final HTMLDocbookTagConverter.GenerationType type;
- private LaTeXImageConverter() { }
+ private LaTeXImageConverter(HTMLDocbookTagConverter.GenerationType type) {
+ this.type = type;
+ }
/**
* {@inheritDoc}
* Since it is a singleton class...
* @return this
*/
- public static ExternalImageConverter getInstance() {
+ public static ExternalImageConverter getInstance(HTMLDocbookTagConverter.GenerationType type) {
if (instance == null) {
- instance = new LaTeXImageConverter();
+ instance = new LaTeXImageConverter(type);
}
return instance;
}
import net.sourceforge.jeuclid.context.LayoutContextImpl;
import net.sourceforge.jeuclid.context.Parameter;
+import org.scilab.modules.helptools.HTMLDocbookTagConverter;
+
/**
* A MathML to PNG converter
* @author Calixte DENIZET
private static final Graphics2D TEMPGRAPHIC = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics();
private static MathMLImageConverter instance;
+ private final HTMLDocbookTagConverter.GenerationType type;
- private MathMLImageConverter() { }
+ private MathMLImageConverter(HTMLDocbookTagConverter.GenerationType type) {
+ this.type = type;
+ }
/**
* {@inheritDoc}
* Since it is a singleton class...
* @return this
*/
- public static ExternalImageConverter getInstance() {
+ public static ExternalImageConverter getInstance(HTMLDocbookTagConverter.GenerationType type) {
if (instance == null) {
- instance = new MathMLImageConverter();
+ instance = new MathMLImageConverter(type);
}
return instance;
}
import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.batik.transcoder.image.PNGTranscoder;
+import org.scilab.modules.helptools.HTMLDocbookTagConverter;
+
/**
* SVG to PNG converter
*/
public class SVGImageConverter implements ExternalImageConverter {
private static SVGImageConverter instance;
+ private final HTMLDocbookTagConverter.GenerationType type;
- private SVGImageConverter() { }
+ private SVGImageConverter(HTMLDocbookTagConverter.GenerationType type) {
+ this.type = type;
+ }
/**
* {@inheritDoc}
* Since this a singleton class...
* @return this
*/
- public static ExternalImageConverter getInstance() {
+ public static ExternalImageConverter getInstance(HTMLDocbookTagConverter.GenerationType type) {
if (instance == null) {
- instance = new SVGImageConverter();
+ instance = new SVGImageConverter(type);
}
return instance;
import java.util.Map;
import org.scilab.modules.commons.ScilabCommons;
+import org.scilab.modules.helptools.HTMLDocbookTagConverter;
/**
* Scilab code to PNG converter
private static ScilabImageConverter instance;
private final StringBuilder buffer;
+ private final HTMLDocbookTagConverter.GenerationType type;
- private ScilabImageConverter() {
+ private ScilabImageConverter(HTMLDocbookTagConverter.GenerationType type) {
buffer = new StringBuilder(8192);
+ this.type = type;
}
public String getMimeType() {
return "image/scilab";
}
- public String getFileWithScilabCode() {
- if (buffer.length() != 0) {
+ public static String getFileWithScilabCode() {
+ if (instance.buffer.length() != 0) {
try {
File f = File.createTempFile("help-", ".sce", new File(ScilabCommons.getTMPDIR()));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
- byte[] arr = buffer.toString().getBytes();
+ byte[] arr = instance.buffer.toString().getBytes();
out.write(arr, 0, arr.length);
out.flush();
out.close();
* Since this a singleton class...
* @return this
*/
- public static ScilabImageConverter getInstance() {
+ public static ScilabImageConverter getInstance(HTMLDocbookTagConverter.GenerationType type) {
if (instance == null) {
- instance = new ScilabImageConverter();
+ instance = new ScilabImageConverter(type);
}
return instance;
return " <div rel='tooltip' title='" + code + "'><img src=\'" + imageName + "\'/></div>";
}
-}
\ No newline at end of file
+}