Documentation: remove the saxon dependency 04/12004/4
Clément DAVID [Wed, 10 Jul 2013 10:09:32 +0000 (12:09 +0200)]
This commit only remove the explicit saxon API dependency and only use the
JAXP API to handle the transform from docbook to fo. However as the OpenJDK
is unable to compile docbook xsl, saxon is always used as an implementation.

Change-Id: If3c3b6dfa148d08c49d6c1925d7db275f863aa48

scilab/build.incl.xml
scilab/configure
scilab/configure.ac
scilab/m4/docbook.m4
scilab/modules/helptools/src/java/org/scilab/modules/helptools/BuildDocObject.java

index 045ac76..8af88ad 100644 (file)
@@ -71,8 +71,6 @@
         <!-- Only useful for the documentation -->
         <pathelement location="${library.helptools.dir}/${library.helptools.name}"/>
         <pathelement location="${batik.jar}"/>
-        <pathelement location="${xml_apis_ext.jar}"/>
-        <pathelement location="${saxon.jar}"/>
         <pathelement location="${xmlgraphics-commons.jar}"/>
         <pathelement location="${fop.jar}"/>
         <pathelement location="${jlatexmath-fop.jar}"/>
index 853a0ef..19006d4 100755 (executable)
@@ -675,7 +675,6 @@ BUILD_HELP_FALSE
 BUILD_HELP_TRUE
 HELP_ENABLE
 DOCBOOK_ROOT
-JLATEXMATH_FOP
 SAXON
 MATIO_FALSE
 MATIO_TRUE
@@ -776,6 +775,7 @@ JUNIT4
 ANTLR
 COMMONS_BEANUTILS
 CHECKSTYLE
+JLATEXMATH_FOP
 JLATEXMATH
 COMMONS_LOGGING
 XML_APIS_EXT
@@ -16287,6 +16287,123 @@ EOF
    ac_java_classpath=$saved_ac_java_classpath
 
 
+                # JLaTeXMath FOP
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking jlatexmath-fop" >&5
+$as_echo_n "checking jlatexmath-fop... " >&6; }
+    PACKAGE_JAR_FILE=
+    found_jar=no
+    saved_ac_java_classpath=$ac_java_classpath
+    DEFAULT_JAR_DIR="/usr/share/java /usr/lib/java /usr/share/java /usr/share/java/jar /opt/java/lib /usr/local/java /usr/local/java/jar /usr/local/share/java /usr/local/share/java/jar /usr/local/lib/java $(find /usr/share/java/ -maxdepth 1 -type d 2>/dev/null) $(find /usr/lib64/ -maxdepth 1 -type d 2>/dev/null) $(find  /usr/lib/ -maxdepth 1 -type d 2>/dev/null)  $(find /usr/share/*/lib -maxdepth 1 -type d 2>/dev/null)"
+    for jardir in "`pwd`/thirdparty" "`pwd`/jar" $DEFAULT_JAR_DIR; do
+      for jar in "$jardir/jlatexmath-fop.jar" "$jardir/libjlatexmath-fop.jar" "$jardir/libjlatexmath-fop-java.jar" "$jardir/jlatexmath-fop*.jar"; do
+
+# TODO check the behaviour when spaces
+        jars_resolved=`ls $jar 2>/dev/null`
+        for jar_resolved in $jars_resolved; do # If several jars matches
+          if test -e "$jar_resolved"; then
+            export ac_java_classpath="$jar_resolved:$ac_java_classpath"
+
+    cat << \EOF > conftest.java
+// #line 16308 "configure"
+import java.util.regex.Pattern;
+
+import org.scilab.forge.jlatexmath.fop.JLaTeXMathObj;
+
+public class conftest {
+    public static void main(String[] argv) {
+
+    }
+
+    private static int compare(String v1, String v2) {
+        String s1 = normalisedVersion(v1);
+        String s2 = normalisedVersion(v2);
+        return s1.compareTo(s2);
+    }
+
+    private static String normalisedVersion(String version) {
+        return normalisedVersion(version, ".", 4);
+    }
+
+    private static String normalisedVersion(String version, String sep, int maxWidth) {
+        String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
+        StringBuilder sb = new StringBuilder();
+        for (String s : split) {
+            sb.append(String.format("%" + maxWidth + 's', s));
+        }
+        return sb.toString();
+    }
+}
+EOF
+
+    CLASSPATH=$ac_java_classpath
+    export CLASSPATH
+    cmd="$JAVAC ${JAVAC_FLAGS} conftest.java"
+    if (echo $cmd >&5 ; eval $cmd >conftest.java.output 2>&5) ; then
+       if test ""no"" = "no"; then
+           echo "yes" >&5
+
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $jar_resolved" >&5
+$as_echo "$jar_resolved" >&6; }
+              found_jar=yes
+              PACKAGE_JAR_FILE=$jar_resolved
+              break 3
+
+       else
+              cmd="$JAVA conftest"
+              if (echo $cmd >&5 ; eval $cmd >conftest.java.output 2>&5); then
+               echo "yes" >&5
+
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $jar_resolved" >&5
+$as_echo "$jar_resolved" >&6; }
+              found_jar=yes
+              PACKAGE_JAR_FILE=$jar_resolved
+              break 3
+
+            else
+                echo "configure: failed program was:" >&5
+                cat conftest.java >&5
+                if test -s conftest.java.output; then
+                   STDOUT=`cat conftest.java.output`
+                fi
+                echo "configure: CLASSPATH was $CLASSPATH" >&5
+
+            ac_java_classpath=$saved_ac_java_classpath
+
+
+                            fi
+        fi
+        if test -f conftest.java.output; then
+           rm conftest.java.output
+        fi
+    else
+        echo "configure: failed program was:" >&5
+        cat conftest.java >&5
+        echo "configure: CLASSPATH was $CLASSPATH" >&5
+
+            ac_java_classpath=$saved_ac_java_classpath
+
+
+            fi
+
+          fi
+        done
+      done
+    done
+    if test "$found_jar" = "no"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+      if test "" = "yes"; then
+         { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Could not find or use the Java package/jar jlatexmath-fop used by LaTex Rendering - FOP plugin (looking for package org.scilab.forge.jlatexmath.fop.JLaTeXMathObj)" >&5
+$as_echo "$as_me: WARNING: Could not find or use the Java package/jar jlatexmath-fop used by LaTex Rendering - FOP plugin (looking for package org.scilab.forge.jlatexmath.fop.JLaTeXMathObj)" >&2;}
+      else
+          as_fn_error $? "Could not find or use the Java package/jar jlatexmath-fop used by LaTex Rendering - FOP plugin (looking for package org.scilab.forge.jlatexmath.fop.JLaTeXMathObj)" "$LINENO" 5
+      fi
+    fi
+
+                JLATEXMATH_FOP=$PACKAGE_JAR_FILE
+
+
 
 $as_echo "#define WITH_GUI /**/" >>confdefs.h
 
@@ -16311,7 +16428,7 @@ $as_echo_n "checking checkstyle... " >&6; }
             export ac_java_classpath="$jar_resolved:$ac_java_classpath"
 
     cat << \EOF > conftest.java
-// #line 16314 "configure"
+// #line 16431 "configure"
 import java.util.regex.Pattern;
 
 import com.puppycrawl.tools.checkstyle.CheckStyleTask;
@@ -16428,7 +16545,7 @@ $as_echo_n "checking commons-beanutils... " >&6; }
             export ac_java_classpath="$jar_resolved:$ac_java_classpath"
 
     cat << \EOF > conftest.java
-// #line 16431 "configure"
+// #line 16548 "configure"
 import java.util.regex.Pattern;
 
 import org.apache.commons.beanutils.Converter;
@@ -16545,7 +16662,7 @@ $as_echo_n "checking antlr... " >&6; }
             export ac_java_classpath="$jar_resolved:$ac_java_classpath"
 
     cat << \EOF > conftest.java
-// #line 16548 "configure"
+// #line 16665 "configure"
 import java.util.regex.Pattern;
 
 import antlr.TokenStreamException;
@@ -16662,7 +16779,7 @@ $as_echo_n "checking junit4... " >&6; }
             export ac_java_classpath="$jar_resolved:$ac_java_classpath"
 
     cat << \EOF > conftest.java
-// #line 16665 "configure"
+// #line 16782 "configure"
 import java.util.regex.Pattern;
 
 import org.junit.Assert;
@@ -16779,7 +16896,7 @@ $as_echo_n "checking cobertura... " >&6; }
             export ac_java_classpath="$jar_resolved:$ac_java_classpath"
 
     cat << \EOF > conftest.java
-// #line 16782 "configure"
+// #line 16899 "configure"
 import java.util.regex.Pattern;
 
 import net.sourceforge.cobertura.merge.Main;
@@ -16896,7 +17013,7 @@ $as_echo_n "checking asm3... " >&6; }
             export ac_java_classpath="$jar_resolved:$ac_java_classpath"
 
     cat << \EOF > conftest.java
-// #line 16899 "configure"
+// #line 17016 "configure"
 import java.util.regex.Pattern;
 
 import org.objectweb.asm.Type;
@@ -17012,7 +17129,7 @@ $as_echo_n "checking asm... " >&6; }
             export ac_java_classpath="$jar_resolved:$ac_java_classpath"
 
     cat << \EOF > conftest.java
-// #line 17015 "configure"
+// #line 17132 "configure"
 import java.util.regex.Pattern;
 
 import org.objectweb.asm.Type;
@@ -25240,7 +25357,7 @@ CPPFLAGS="$CPPFLAGS -I$CHK_TCL_INCLUDE_PATH"
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if tcl is version $CHK_TCL_MAJOR.$CHK_TCL_MINOR or later" >&5
 $as_echo_n "checking if tcl is version $CHK_TCL_MAJOR.$CHK_TCL_MINOR or later... " >&6; }
 cat > conftest.$ac_ext <<EOF
-#line 25243 "configure"
+#line 25360 "configure"
 #include "confdefs.h"
 
 #include "$CHK_TCL_INCLUDE_PATH/$CHK_TCL_INC_NAME"
@@ -25551,7 +25668,7 @@ CPPFLAGS="$CPPFLAGS $TCL_INC_PATH -I$CHK_TK_INCLUDE_PATH $X_CFLAGS"
 $as_echo_n "checking if tk is version $CHK_TK_MAJOR.$CHK_TK_MINOR or later... " >&6; }
 
 cat > conftest.$ac_ext <<EOF
-#line 25554 "configure"
+#line 25671 "configure"
 #include "confdefs.h"
 
 #include "$CHK_TK_INCLUDE_PATH/$CHK_TK_INC_NAME"
@@ -26115,7 +26232,7 @@ fi
        fi
 
 
-       # Saxon XSLT Processor
+       # Saxon XSLT Processor, as the JVM implementation is unable to parse the docbook xsl files
 
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking saxon" >&5
 $as_echo_n "checking saxon... " >&6; }
@@ -26133,7 +26250,7 @@ $as_echo_n "checking saxon... " >&6; }
             export ac_java_classpath="$jar_resolved:$ac_java_classpath"
 
     cat << \EOF > conftest.java
-// #line 26136 "configure"
+// #line 26253 "configure"
 import java.util.regex.Pattern;
 
 import com.icl.saxon.Loader;
@@ -26232,123 +26349,6 @@ $as_echo "$as_me: WARNING: Could not find or use the Java package/jar saxon used
        SAXON=$PACKAGE_JAR_FILE
 
 
-    # JLaTeXMath FOP
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking jlatexmath-fop" >&5
-$as_echo_n "checking jlatexmath-fop... " >&6; }
-    PACKAGE_JAR_FILE=
-    found_jar=no
-    saved_ac_java_classpath=$ac_java_classpath
-    DEFAULT_JAR_DIR="/usr/share/java /usr/lib/java /usr/share/java /usr/share/java/jar /opt/java/lib /usr/local/java /usr/local/java/jar /usr/local/share/java /usr/local/share/java/jar /usr/local/lib/java $(find /usr/share/java/ -maxdepth 1 -type d 2>/dev/null) $(find /usr/lib64/ -maxdepth 1 -type d 2>/dev/null) $(find  /usr/lib/ -maxdepth 1 -type d 2>/dev/null)  $(find /usr/share/*/lib -maxdepth 1 -type d 2>/dev/null)"
-    for jardir in "`pwd`/thirdparty" "`pwd`/jar" $DEFAULT_JAR_DIR; do
-      for jar in "$jardir/jlatexmath-fop.jar" "$jardir/libjlatexmath-fop.jar" "$jardir/libjlatexmath-fop-java.jar" "$jardir/jlatexmath-fop*.jar"; do
-
-# TODO check the behaviour when spaces
-        jars_resolved=`ls $jar 2>/dev/null`
-        for jar_resolved in $jars_resolved; do # If several jars matches
-          if test -e "$jar_resolved"; then
-            export ac_java_classpath="$jar_resolved:$ac_java_classpath"
-
-    cat << \EOF > conftest.java
-// #line 26253 "configure"
-import java.util.regex.Pattern;
-
-import org.scilab.forge.jlatexmath.fop.JLaTeXMathObj;
-
-public class conftest {
-    public static void main(String[] argv) {
-
-    }
-
-    private static int compare(String v1, String v2) {
-        String s1 = normalisedVersion(v1);
-        String s2 = normalisedVersion(v2);
-        return s1.compareTo(s2);
-    }
-
-    private static String normalisedVersion(String version) {
-        return normalisedVersion(version, ".", 4);
-    }
-
-    private static String normalisedVersion(String version, String sep, int maxWidth) {
-        String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
-        StringBuilder sb = new StringBuilder();
-        for (String s : split) {
-            sb.append(String.format("%" + maxWidth + 's', s));
-        }
-        return sb.toString();
-    }
-}
-EOF
-
-    CLASSPATH=$ac_java_classpath
-    export CLASSPATH
-    cmd="$JAVAC ${JAVAC_FLAGS} conftest.java"
-    if (echo $cmd >&5 ; eval $cmd >conftest.java.output 2>&5) ; then
-       if test ""no"" = "no"; then
-           echo "yes" >&5
-
-              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $jar_resolved" >&5
-$as_echo "$jar_resolved" >&6; }
-              found_jar=yes
-              PACKAGE_JAR_FILE=$jar_resolved
-              break 3
-
-       else
-              cmd="$JAVA conftest"
-              if (echo $cmd >&5 ; eval $cmd >conftest.java.output 2>&5); then
-               echo "yes" >&5
-
-              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $jar_resolved" >&5
-$as_echo "$jar_resolved" >&6; }
-              found_jar=yes
-              PACKAGE_JAR_FILE=$jar_resolved
-              break 3
-
-            else
-                echo "configure: failed program was:" >&5
-                cat conftest.java >&5
-                if test -s conftest.java.output; then
-                   STDOUT=`cat conftest.java.output`
-                fi
-                echo "configure: CLASSPATH was $CLASSPATH" >&5
-
-            ac_java_classpath=$saved_ac_java_classpath
-
-
-                            fi
-        fi
-        if test -f conftest.java.output; then
-           rm conftest.java.output
-        fi
-    else
-        echo "configure: failed program was:" >&5
-        cat conftest.java >&5
-        echo "configure: CLASSPATH was $CLASSPATH" >&5
-
-            ac_java_classpath=$saved_ac_java_classpath
-
-
-            fi
-
-          fi
-        done
-      done
-    done
-    if test "$found_jar" = "no"; then
-      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-      if test "" = "yes"; then
-         { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Could not find or use the Java package/jar jlatexmath-fop used by LaTex Rendering - FOP plugin (looking for package org.scilab.forge.jlatexmath.fop.JLaTeXMathObj)" >&5
-$as_echo "$as_me: WARNING: Could not find or use the Java package/jar jlatexmath-fop used by LaTex Rendering - FOP plugin (looking for package org.scilab.forge.jlatexmath.fop.JLaTeXMathObj)" >&2;}
-      else
-          as_fn_error $? "Could not find or use the Java package/jar jlatexmath-fop used by LaTex Rendering - FOP plugin (looking for package org.scilab.forge.jlatexmath.fop.JLaTeXMathObj)" "$LINENO" 5
-      fi
-    fi
-
-    JLATEXMATH_FOP=$PACKAGE_JAR_FILE
-
-
 
 
 
index ed7519f..fc702cc 100644 (file)
@@ -1046,6 +1046,11 @@ interface for JOGL2 - or libGL (OpenGL library) are installed and if the version
 
                 AC_JAVA_CHECK_VERSION_PACKAGE([jlatexmath],[import org.scilab.forge.jlatexmath.TeXFormula;],$JLATEXMATH,[1.0.2],[TeXFormula.VERSION])
 
+                # JLaTeXMath FOP
+                AC_JAVA_CHECK_PACKAGE([jlatexmath-fop],[org.scilab.forge.jlatexmath.fop.JLaTeXMathObj],[LaTex Rendering - FOP plugin])
+                JLATEXMATH_FOP=$PACKAGE_JAR_FILE
+                AC_SUBST(JLATEXMATH_FOP)
+
                 AC_DEFINE([WITH_GUI],[],[With the JAVA stuff (GUI, Console, JOGL...)])
 
         fi
index 48b2414..0a23f73 100644 (file)
@@ -34,16 +34,11 @@ AC_ARG_WITH(docbook,
        fi
 
 
-       # Saxon XSLT Processor
+       # Saxon XSLT Processor, as the JVM implementation is unable to parse the docbook xsl files
        AC_JAVA_CHECK_PACKAGE([saxon],[com.icl.saxon.Loader],[Saxon XSLT Processor])
        SAXON=$PACKAGE_JAR_FILE
        AC_SUBST(SAXON)
 
-    # JLaTeXMath FOP
-    AC_JAVA_CHECK_PACKAGE([jlatexmath-fop],[org.scilab.forge.jlatexmath.fop.JLaTeXMathObj],[LaTex Rendering - FOP plugin])
-    JLATEXMATH_FOP=$PACKAGE_JAR_FILE
-    AC_SUBST(JLATEXMATH_FOP)
-
 AC_SUBST(DOCBOOK_ROOT)
 
 ])
index 344122b..a9ca6a0 100644 (file)
@@ -17,15 +17,19 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.ArrayList;
 
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
 import org.xml.sax.SAXParseException;
 import org.xml.sax.SAXException;
 
-import com.icl.saxon.StyleSheet; /* saxon */
-
 /**
  * This classes intends to wrap Saxon features in a easy-to-use class.
  */
-public class BuildDocObject extends StyleSheet {
+public class BuildDocObject {
 
     /**
      * Windows version ?
@@ -289,8 +293,9 @@ public class BuildDocObject extends StyleSheet {
      * @param styleSheet Path to the CSS stylesheet
      * @return The path to the file/directory created.
      * @throws FileNotFoundException Raises an exception if no file/dir found
+     * @throws TransformerException
      */
-    public String process(String sourceDoc, String styleSheet) throws FileNotFoundException {
+    public String process(String sourceDoc, String styleSheet) throws FileNotFoundException, TransformerException {
         ArrayList<String> args = new ArrayList<String>();
 
         if (!new File(sourceDoc).isFile()) {
@@ -318,39 +323,25 @@ public class BuildDocObject extends StyleSheet {
             throw new FileNotFoundException("Unable to parse generated master file.");
         }
 
+        final StreamResult outputTarget;
         if (format.equalsIgnoreCase(PDF_FORMAT) || format.equalsIgnoreCase(POSTSCRIPT_FORMAT)) {
-            /* PDF & postscript take other args */
-            args.add("-o");
-            args.add(Helpers.getTemporaryNameFo(outputDirectory));
+            outputTarget = new StreamResult(new File(Helpers.getTemporaryNameFo(outputDirectory)));
         } else {
-            if (!new File(styleSheet).isFile()) {
-                throw new FileNotFoundException("Could not find CSS stylesheet: " + styleSheet);
-            }
-            /* Where it will be stored */
-            String out = this.outputDirectory + File.separator + new File(styleSheet).getName();
+            throw new RuntimeException("Invalid format");
+        }
 
-            try {
-                Helpers.copyFile(new File(styleSheet), new File(out));
-            } catch (java.io.FileNotFoundException e) {
-                System.err.println(ERROR_WHILE_COPYING + styleSheet + TO + out + COLON + e.getMessage());
-            } catch (java.io.IOException e) {
-                System.err.println(ERROR_WHILE_COPYING + styleSheet + TO + out + COLON + e.getMessage());
-            }
+        final StreamSource xmlSource = new StreamSource(new File(sourceDocProcessed));
 
-            args.add("html.stylesheet=" + new File(styleSheet).getName());
+        final TransformerFactory tfactory = TransformerFactory.newInstance();
+        final Transformer transform = tfactory.newTransformer(new StreamSource(new File(path)));
+
+        transform.setParameter("base.dir", this.outputDirectory);
+        for (String arg : specificArgs) {
+            String[] nameValue = arg.split("=");
+            transform.setParameter(nameValue[0], nameValue[1]);
         }
 
-        //args.add("-t");
-        args.add(sourceDocProcessed);
-        args.add(path);
-        args.add("base.dir=" + this.outputDirectory);
-        args.addAll(specificArgs);
-        /**
-         * We are calling directly the method as we were using a command line
-         * program because it is much easier ...
-         * However, this should be rewritted using the API
-         */
-        doMain(args.toArray(new String [args.size()]), new StyleSheet(), "java com.icl.saxon.StyleSheet");
+        transform.transform(xmlSource, outputTarget);
 
         if (new File(sourceDocProcessed).isDirectory()) {
             /* Delete the master temp file to avoid to be shipped with the rest */
@@ -364,22 +355,4 @@ public class BuildDocObject extends StyleSheet {
         return this.postProcess();
 
     }
-
-    /**
-     * The case to see if it working
-     *
-     * @param arg Useless arg
-     */
-    public static void main(String[] arg) {
-        try {
-            BuildDocObject d = new BuildDocObject();
-            d.setOutputDirectory("/tmp/");
-            d.setExportFormat(JH_FORMAT);
-            d.setDocbookPath("/usr/share/xml/docbook/stylesheet/nwalsh/");
-            d.process(SCI + "/modules/helptools/master_en_US_help.xml",
-                      SCI + "/modules/helptools/css/javahelp.css");
-        } catch (FileNotFoundException e) {
-            System.err.println("Exception catched: " + e.getMessage());
-        }
-    }
 }