]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
1.) Deprecation of most constructors in XSLTInputHandler in favor of JAXP.
authorGlen Mazza <gmazza@apache.org>
Tue, 10 Feb 2004 23:51:26 +0000 (23:51 +0000)
committerGlen Mazza <gmazza@apache.org>
Tue, 10 Feb 2004 23:51:26 +0000 (23:51 +0000)
2.)  Removal of unused transformer member variable in XSLTInputHandler.
3.)  Partial modifications -- code from Xalan project -- in order to be
     able to handle command line parameters for XSLT stylesheet.  (Changes
     still needed in XSLTInputHandler.getXMLFilter() -- unsure how to set
     parameters to an XMLFilter.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197350 13f79535-47bb-0310-9956-ffa450edef68

fop.bat
src/java/org/apache/fop/apps/CommandLineOptions.java
src/java/org/apache/fop/apps/XSLTInputHandler.java
src/java/org/apache/fop/servlet/FopPrintServlet.java
src/java/org/apache/fop/tools/TestConverter.java

diff --git a/fop.bat b/fop.bat
index 6b62decaa049956c7e73775ed53a0aae0538a022..b4494dee184640db9f79e06eccb2f178c8e37312 100644 (file)
--- a/fop.bat
+++ b/fop.bat
@@ -15,5 +15,7 @@ set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\commons-io-dev-20040206.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jimi-1.0.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_core.jar
 set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_codec.jar
-java -cp "%LOCALCLASSPATH%" org.apache.fop.apps.Fop %1 %2 %3 %4 %5 %6 %7 %8
+rem 'shift' removes %0 (i.e., the fop.bat filename)
+shift
+java -cp "%LOCALCLASSPATH%" org.apache.fop.apps.Fop %*
 
index f31ba95961280331c2ae33ac5e7dfe354a5af30c..3276e5f4a65717995128616ce5f00eeac1487b5f 100644 (file)
@@ -54,6 +54,7 @@ package org.apache.fop.apps;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.Locale;
+import java.util.Vector;
 
 // Avalon
 import org.apache.avalon.framework.logger.ConsoleLogger;
@@ -116,6 +117,8 @@ public class CommandLineOptions {
 
     private Logger log;
 
+    private Vector xsltParams = null;
+    
     /**
      * Construct a command line option object from command line arguments
      * @param args command line parameters
@@ -208,6 +211,18 @@ public class CommandLineOptions {
                 i = i + parseUnknownOption(args, i);
             } else if (args[i].equals("-at")) {
                 i = i + parseAreaTreeOption(args, i);
+            } else if (args[i].equals("-param")) {
+                  if (i + 2 < args.length) {
+                      if (xsltParams == null) {
+                          xsltParams = new Vector();
+                      }
+                      String name = args[++i];
+                      xsltParams.addElement(name);
+                      String expression = args[++i];
+                      xsltParams.addElement(expression);
+                  } else {
+                    throw new FOPException("invalid param usage: use -param <name> <value>");
+                  }
             } else {
                 printUsage();
                 return false;
@@ -493,7 +508,7 @@ public class CommandLineOptions {
         case FO_INPUT:
             return new FOFileHandler(fofile);
         case XSLT_INPUT:
-            return new XSLTInputHandler(xmlfile, xsltfile);
+            return new XSLTInputHandler(xmlfile, xsltfile, xsltParams);
         default:
             throw new FOPException("Invalid inputmode setting!");
         }
@@ -621,6 +636,8 @@ public class CommandLineOptions {
             + "  -fo  infile       xsl:fo input file  \n"
             + "  -xml infile       xml input file, must be used together with -xsl \n"
             + "  -xsl stylesheet   xslt stylesheet \n \n"
+/*            + "  -param name value <value> to use for parameter <name> in xslt stylesheet\n"
+            + "                    (repeat '-param name value' for each parameter)\n \n" */
             + " [OUTPUT] \n"
             + "  outfile           input will be rendered as pdf file into outfile \n"
             + "  -pdf outfile      input will be rendered as pdf file (outfile req'd) \n"
index d2bd26788afc31decaa36aed782858a907e57526..5227ad6be376a3248b024ccf85ef7074dabf1115 100644 (file)
@@ -52,6 +52,7 @@ package org.apache.fop.apps;
 
 // Imported java.io classes
 import java.io.File;
+import java.util.Vector;
 
 // Imported TraX classes
 import javax.xml.transform.Source;
@@ -73,20 +74,34 @@ import org.xml.sax.XMLFilter;
  */
 public class XSLTInputHandler extends InputHandler {
 
-    private Transformer transformer;
     private StreamSource xmlSource;
     private Source xsltSource;
+    private Vector xsltParams = null; // not yet implemented
+    
+    /**
+     * Constructor for files as input
+     * @param xmlfile XML file
+     * @param xsltfile XSLT file
+     * @param params Vector of command-line parameters (name, value, 
+     *      name, value, ...) for XSL stylesheet
+     * @throws FOPException if initializing the Transformer fails
+     */
+    public XSLTInputHandler(File xmlfile, File xsltfile, Vector params) throws FOPException {
+        this.xmlSource  = new StreamSource(xmlfile);
+        this.xsltSource = new StreamSource(xsltfile);
+        xsltParams = params;
+    }
 
     /**
      * Constructor for files as input
      * @param xmlfile XML file
      * @param xsltfile XSLT file
      * @throws FOPException if initializing the Transformer fails
+     * @deprecated Use JAXP instead.
      */
     public XSLTInputHandler(File xmlfile, File xsltfile) throws FOPException {
         this.xmlSource  = new StreamSource(xmlfile);
         this.xsltSource = new StreamSource(xsltfile);
-        initTransformer();
     }
 
     /**
@@ -94,11 +109,11 @@ public class XSLTInputHandler extends InputHandler {
      * @param xmlURL XML URL
      * @param xsltURL XSLT URL
      * @throws FOPException if initializing the Transformer fails
+     * @deprecated Use JAXP instead.
      */
     public XSLTInputHandler(String xmlURL, String xsltURL) throws FOPException {
         this.xmlSource  = new StreamSource(xmlURL);
         this.xsltSource = new StreamSource(xsltURL);
-        initTransformer();
     }
 
     /**
@@ -106,6 +121,7 @@ public class XSLTInputHandler extends InputHandler {
      * @param xmlSource XML InputSource
      * @param xsltSource XSLT InputSource
      * @throws FOPException if initializing the Transformer fails
+     * @deprecated Use JAXP instead.
      */
     public XSLTInputHandler(InputSource xmlSource, InputSource xsltSource)
                 throws FOPException {
@@ -113,16 +129,6 @@ public class XSLTInputHandler extends InputHandler {
                                            xmlSource.getSystemId());
         this.xsltSource = new StreamSource(xsltSource.getByteStream(),
                                            xsltSource.getSystemId());
-        initTransformer();
-    }
-
-    private void initTransformer() throws FOPException {
-        try {
-            this.transformer = 
-                TransformerFactory.newInstance().newTransformer(xsltSource);
-        } catch (Exception ex) {
-            throw new FOPException(ex);
-        }
     }
 
     /**
@@ -141,7 +147,7 @@ public class XSLTInputHandler extends InputHandler {
      * @see org.apache.fop.apps.InputHandler#getParser()
      */
     public XMLReader getParser() throws FOPException {
-        return getXMLFilter(xsltSource);
+        return getXMLFilter(xsltSource, xsltParams);
     }
 
     /**
@@ -154,11 +160,11 @@ public class XSLTInputHandler extends InputHandler {
      * XMLReaders or XMLFilters
      * @throws FOPException if setting up the XMLFilter fails
      */
-    public static XMLFilter getXMLFilter(Source xsltSource) throws FOPException {
+    public static XMLFilter getXMLFilter(Source xsltSource, Vector inParams) throws FOPException {
         try {
             // Instantiate  a TransformerFactory.
             TransformerFactory tFactory = TransformerFactory.newInstance();
-            // Determine whether the TransformerFactory supports The use uf SAXSource
+            // Determine whether the TransformerFactory supports The use of SAXSource
             // and SAXResult
             if (tFactory.getFeature(SAXSource.FEATURE)
                     && tFactory.getFeature(SAXResult.FEATURE)) {
@@ -168,7 +174,18 @@ public class XSLTInputHandler extends InputHandler {
                 // Create an XMLFilter for each stylesheet.
                 XMLFilter xmlfilter =
                     saxTFactory.newXMLFilter(xsltSource);
-
+                    
+/*              if (inParams != null) { 
+                    Transformer transformer = ??? how to obtain from an XMLFilter?
+                    int nParams = inParams.size();
+            
+                    for (int i = 0; i < nParams; i += 2) {
+                        transformer.setParameter((String) inParams.elementAt(i),
+                            (String) inParams.elementAt(i + 1));
+                    }
+                }
+*/                  
+                
                 // Create an XMLReader.
                 XMLReader parser = FOFileHandler.createParser();
                 if (parser == null) {
index 4db2e4b45f40d9f31de5b35b64be470b16b66180..2e7abc44d0d640566b556910d07d483958f3926b 100644 (file)
@@ -133,7 +133,7 @@ public class FopPrintServlet extends HttpServlet {
             } else if ((xmlParam != null) && (xsltParam != null)) {
                 XSLTInputHandler input =
                   new XSLTInputHandler(new File(xmlParam),
-                                       new File(xsltParam));
+                                       new File(xsltParam), null);
                 renderXML(input, response);
             } else {
                 response.setContentType("text/html");
index b93cd7b308774dd0ddfe6241a91d08ee30bc3714..3569d8666688a0514f96066742b2f73ee340ac6b 100644 (file)
@@ -306,7 +306,7 @@ public class TestConverter extends AbstractLogEnabled {
             } else {
                 inputHandler = new XSLTInputHandler(xmlFile,
                                                     new File(baseDir + "/"
-                                                             + xsl));
+                                                             + xsl), null);
             }
 
             Driver driver = new Driver();