File saxon6-batch.patch of Package saxon6

---
 com/icl/saxon/StyleSheetBatch.java |  160 +++++++++++++++++++++++++++++++++++++
 1 file changed, 160 insertions(+)

Index: saxon6-6.5.5/com/icl/saxon/StyleSheetBatch.java
===================================================================
--- /dev/null
+++ saxon6-6.5.5/com/icl/saxon/StyleSheetBatch.java
@@ -0,0 +1,160 @@
+/**
+  * This <B>StyleSheetBatch</B> class supports multiple input/output files proceed by StyleSheet.main().
+  * It does work around the performance problems when running an extra saxon/JVM process for each file<p>
+  *
+  * The XSLT syntax supported conforms to the W3C XSLT 1.0 and XPath 1.0 recommendation.
+  * Only the transformation language is implemented (not the formatting objects).
+  * Saxon extensions are documented in the file extensions.html
+  *
+  * @author Michal Vyskocil
+  */
+
+package com.icl.saxon;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileNotFoundException;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Vector;
+
+public class StyleSheetBatch {
+
+    protected static String toString(List<String> lst) {
+        StringBuilder sb = new StringBuilder();
+        for (String s: lst) {
+            sb.append(s);
+            sb.append(", ");
+        }
+        return sb.toString();
+    }
+
+    public static void main (String args[])
+        throws java.lang.Exception {
+
+        int i = -1;
+        int bi = -1;    // -batch index
+        int si = -1;    // -style index
+        int pi = 65536; // param=value lowest index
+        String batchFileName = null;
+        String styleFileName = null;
+        String line = null;
+        String foo[] = null;
+        List<String> alist = null;
+        List<String> arglist = null;
+        File batchFile = null;
+        BufferedReader batchReader = null;
+
+        Boolean have_params = false;
+
+        if (args.length == 0) {
+            System.err.println("All arguments are missing, type saxon6 for help");
+            System.exit(1);
+        }
+
+        for(i = 0; i != args.length; i++) {
+            if (args[i].equals("-batch")) {
+                bi = i;
+                i++;
+                if (args.length < i+1) {
+                    System.err.println("No batch file specified after -batch argument");
+                    System.exit(1);
+                }
+                batchFileName = args[i];
+            }
+            if (args[i].equals("-style")) {
+                si = i;
+                i++;
+                if (args.length < i+1) {
+                    System.err.println("No xsl file specified after -style argument");
+                    System.exit(1);
+                }
+                styleFileName = args[i];
+            }
+        }
+
+        if (batchFileName == null) {
+            System.err.println("No batch file specified, call saxon6-batch with -batch <filename> -style <file.xsl> arguments");
+            System.exit(1);
+        }
+
+        // remove -batch <filename> from args
+        alist = new Vector<String>(args.length - 4);
+        for(i = 0; i != args.length; i++) {
+            //System.err.println(String.format("DEBUG: processing args[%d]: %s", i, args[i]));
+            if ((i == bi) || (i == bi + 1) || (i == si) || (i == si + 1)) {
+                //System.err.println(String.format("DEBUG: skipped args[%d]: %s", i, args[i]));
+                continue;
+            }
+            //System.err.println(String.format("DEBUG: added args[%d]: %s", i, args[i]));
+            alist.add(args[i]);
+        }
+
+        // get the index of first param
+        i = 0;
+        for (String s: alist) {
+            if (s.indexOf('=') != -1) {
+                pi = i;
+                have_params = true;
+                break;
+            }
+            i++;
+        }
+
+        batchFile = new File(batchFileName);
+
+        if (!batchFile.canRead()) {
+            System.err.println(String.format("Cannot read batch-file ``%s''", batchFileName));
+            return;
+        }
+
+        try {
+            batchReader = new BufferedReader(new FileReader(batchFile));
+        } catch (FileNotFoundException fnfe) {
+            System.err.println(String.format("Cannot read batch-file ``%s''", batchFileName));
+            return;
+        }
+
+        try {
+
+            while ((line = batchReader.readLine()) != null) {
+
+                foo = line.split(";", 2);
+                arglist = new Vector<String>(4+alist.size());
+                //output file
+                arglist.add("-o");
+                arglist.add(foo[1]);
+                if (have_params) {
+                    //System.err.println(String.format("DEBUG: arglist.addAll(alist.subList(0, %d))", pi-1));
+                    // everything up to first property
+                    arglist.addAll(alist.subList(0, pi-1));
+                }
+                else {
+                    arglist.addAll(alist);
+                }
+                // add inp file
+                arglist.add(foo[0]);
+                // add stylesheet
+                arglist.add(styleFileName);
+                if (have_params) {
+                    // add all properties
+                    arglist.addAll(alist.subList(pi, alist.size()));
+                }
+
+                //System.err.println("DEBUG: call com.icl.saxon.StyleSheet.main(" + toString(arglist));
+
+                StyleSheet.main(arglist.toArray(new String[0]));
+
+            }
+
+        } catch (IOException ioe) {
+            System.err.println(String.format("Can't read from ``%s''", batchFileName));
+            return;
+        }
+
+    }
+
+}
openSUSE Build Service is sponsored by