Doc generation: add a method HTMLDocbookTagConverter::getGenerationType() to know... 78/8478/3
Calixte DENIZET [Wed, 1 Aug 2012 18:15:55 +0000 (20:15 +0200)]
Change-Id: I64e6f324ecaf928efd727a15c8df0d56b613de74

scilab/modules/helptools/src/java/org/scilab/modules/helptools/CHMDocbookTagConverter.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/HTMLDocbookTagConverter.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/JavaHelpDocbookTagConverter.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/SciDocMain.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/image/LaTeXImageConverter.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/image/MathMLImageConverter.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/image/SVGImageConverter.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/image/ScilabImageConverter.java

index 7a58b68..d216c50 100644 (file)
@@ -50,7 +50,7 @@ public class CHMDocbookTagConverter extends HTMLDocbookTagConverter {
      * @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;
index a70efbb..ba48800 100644 (file)
@@ -44,6 +44,8 @@ import org.scilab.modules.localization.Messages;
  */
 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");
@@ -88,6 +90,7 @@ public class HTMLDocbookTagConverter extends DocbookTagConverter implements Temp
     protected String indexFilename = "index" /*UUID.randomUUID().toString()*/ + ".html";
 
     protected boolean isToolbox;
+    protected final GenerationType type;
 
     /**
      * Constructor
@@ -101,7 +104,7 @@ public class HTMLDocbookTagConverter extends DocbookTagConverter implements Temp
      * @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;
@@ -117,29 +120,30 @@ public class HTMLDocbookTagConverter extends DocbookTagConverter implements Temp
         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();
@@ -147,10 +151,18 @@ public class HTMLDocbookTagConverter extends DocbookTagConverter implements Temp
         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;
     }
 
     /**
index d8eb7d4..ae45c65 100644 (file)
@@ -43,7 +43,7 @@ public class JavaHelpDocbookTagConverter extends HTMLDocbookTagConverter {
      * @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>";
index 3c77222..3afde33 100644 (file)
@@ -114,8 +114,10 @@ public final class SciDocMain {
                 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);
                 }
@@ -126,7 +128,7 @@ public final class SciDocMain {
             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"));
index 0ea2b10..351b061 100644 (file)
@@ -26,6 +26,8 @@ import org.scilab.forge.jlatexmath.TeXFormula;
 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
@@ -33,8 +35,11 @@ import org.scilab.forge.jlatexmath.ParseException;
 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}
@@ -47,9 +52,9 @@ public class LaTeXImageConverter implements ExternalImageConverter {
      * 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;
     }
index 93f4f3b..ce0c5d8 100644 (file)
@@ -33,6 +33,8 @@ import net.sourceforge.jeuclid.layout.JEuclidView;
 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
@@ -41,8 +43,11 @@ public class MathMLImageConverter implements ExternalImageConverter {
 
     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}
@@ -55,9 +60,9 @@ public class MathMLImageConverter implements ExternalImageConverter {
      * 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;
     }
index c1b4907..44dd090 100644 (file)
@@ -28,14 +28,19 @@ import org.apache.batik.transcoder.Transcoder;
 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}
@@ -48,9 +53,9 @@ public class SVGImageConverter implements ExternalImageConverter {
      * 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;
index 3aa0407..06591eb 100644 (file)
@@ -24,6 +24,7 @@ import java.io.OutputStream;
 import java.util.Map;
 
 import org.scilab.modules.commons.ScilabCommons;
+import org.scilab.modules.helptools.HTMLDocbookTagConverter;
 
 /**
  * Scilab code to PNG converter
@@ -32,21 +33,23 @@ public class ScilabImageConverter implements ExternalImageConverter {
 
     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();
@@ -68,9 +71,9 @@ public class ScilabImageConverter implements ExternalImageConverter {
      * 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;
@@ -121,4 +124,4 @@ public class ScilabImageConverter implements ExternalImageConverter {
 
         return " <div rel='tooltip' title='" + code + "'><img src=\'" + imageName + "\'/></div>";
     }
-}
\ No newline at end of file
+}