You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by vh...@apache.org on 2009/10/20 12:04:09 UTC

svn commit: r827023 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java

Author: vhennebert
Date: Tue Oct 20 10:04:09 2009
New Revision: 827023

URL: http://svn.apache.org/viewvc?rev=827023&view=rev
Log:
Fixed checkstyle issues.
Factorized duplicated code into getXMLReader method.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java?rev=827023&r1=827022&r2=827023&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java Tue Oct 20 10:04:09 2009
@@ -19,7 +19,6 @@
 
 package org.apache.fop.cli;
 
-// Imported java.io classes
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
@@ -40,38 +39,40 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.render.awt.viewer.Renderable;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
 
 /**
  * Class for handling files input from command line
  * either with XML and XSLT files (and optionally xsl
- * parameters) or FO File input alone
+ * parameters) or FO File input alone.
  */
 public class InputHandler implements ErrorListener, Renderable {
 
     /** original source file */
-    protected File sourcefile = null;
-    private File stylesheet = null;  // for XML/XSLT usage
-    private Vector xsltParams = null; // for XML/XSLT usage
-    private EntityResolver entityResolver = null;
-    private URIResolver uriResolver = null;
+    protected File sourcefile;
+    private File stylesheet;  // for XML/XSLT usage
+    private Vector xsltParams; // for XML/XSLT usage
+    private EntityResolver entityResolver;
+    private URIResolver uriResolver;
 
     /** the logger */
     protected Log log = LogFactory.getLog(InputHandler.class);
 
     /**
      * Constructor for XML->XSLT->FO input
-     * 
+     *
      * @param xmlfile XML file
      * @param xsltfile XSLT file
      * @param params Vector of command-line parameters (name, value,
@@ -85,7 +86,7 @@
 
     /**
      * Constructor for XML->XSLT->FO input
-     * 
+     *
      * @param xmlfile XML file
      * @param xsltfile XSLT file
      * @param params Vector of command-line parameters (name, value,
@@ -186,10 +187,7 @@
         try {
             InputSource is = new InputSource(in);
             is.setSystemId(uri);
-            SAXParserFactory spf = SAXParserFactory.newInstance();
-            spf.setFeature("http://xml.org/sax/features/namespaces", true);
-            spf.setFeature("http://apache.org/xml/features/xinclude", true);
-            XMLReader xr = spf.newSAXParser().getXMLReader();
+            XMLReader xr = getXMLReader();
             if (entityResolver != null) {
                 xr.setEntityResolver(entityResolver);
             }
@@ -209,21 +207,23 @@
         }
         return source;
     }
-    
+
     /**
-     * Create a catalog resolver and use it for XML parsing and XSLT URI resolution
+     * Creates a catalog resolver and use it for XML parsing and XSLT URI resolution.
      * Try the Apache Commons Resolver, and if unsuccessful,
      * try the same built into Java 6
      */
-    protected void createCatalogResolver() {
-        String[] classNames =
-            new String[] {"org.apache.xml.resolver.tools.CatalogResolver",
-                          "com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver"};
+    private void createCatalogResolver() {
+        String[] classNames = new String[] {
+                "org.apache.xml.resolver.tools.CatalogResolver",
+                "com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver"};
         Class resolverClass = null;
         for (int i = 0; i < classNames.length && resolverClass == null; ++i) {
             try {
                 resolverClass = Class.forName(classNames[i]);
-            } catch (ClassNotFoundException e) { }
+            } catch (ClassNotFoundException e) {
+                // No worries
+            }
         }
         if (resolverClass == null) {
             log.error("Could not find catalog resolver in class path");
@@ -241,7 +241,7 @@
 
     /**
      * Creates a Source for the selected stylesheet.
-     * 
+     *
      * @return the Source for the selected stylesheet or null if there's no stylesheet
      */
     protected Source createXSLTSource() {
@@ -250,10 +250,7 @@
             if (entityResolver != null) {
                 try {
                     InputSource is = new InputSource(this.stylesheet.getPath());
-                    SAXParserFactory spf = SAXParserFactory.newInstance();
-                    spf.setFeature("http://xml.org/sax/features/namespaces", true);
-                    spf.setFeature("http://apache.org/xml/features/xinclude", true);
-                    XMLReader xr = spf.newSAXParser().getXMLReader();
+                    XMLReader xr = getXMLReader();
                     xr.setEntityResolver(entityResolver);
                     xslt = new SAXSource(xr, is);
                 } catch (SAXException e) {
@@ -262,12 +259,21 @@
                     // return StreamSource
                 }
             }
-            if (xslt == null)
+            if (xslt == null) {
                 xslt = new StreamSource(this.stylesheet);
+            }
         }
         return xslt;
     }
 
+    private XMLReader getXMLReader() throws ParserConfigurationException, SAXException {
+        SAXParserFactory spf = SAXParserFactory.newInstance();
+        spf.setFeature("http://xml.org/sax/features/namespaces", true);
+        spf.setFeature("http://apache.org/xml/features/xinclude", true);
+        XMLReader xr = spf.newSAXParser().getXMLReader();
+        return xr;
+    }
+
     /**
      * Transforms the input document to the input format expected by FOP using XSLT.
      * @param result the Result object where the result of the XSL transformation is sent to



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Re: svn commit: r827023 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java

Posted by Vincent Hennebert <vh...@gmail.com>.
Hi Simon,

Simon Pepping wrote:
> On Tue, Oct 20, 2009 at 10:04:09AM -0000, vhennebert@apache.org wrote:
>> Author: vhennebert
>> Date: Tue Oct 20 10:04:09 2009
>> New Revision: 827023
>>
>> URL: http://svn.apache.org/viewvc?rev=827023&view=rev
>> Log:
>> Fixed checkstyle issues.
>> Factorized duplicated code into getXMLReader method.
>>
>> Modified:
>>     xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java
>>
>>      /**
>> -     * Create a catalog resolver and use it for XML parsing and XSLT URI resolution
>> +     * Creates a catalog resolver and use it for XML parsing and XSLT URI resolution.
>>       * Try the Apache Commons Resolver, and if unsuccessful,
>>       * try the same built into Java 6
>>       */
> 
> The above text uses inconsistent language: creates, use, try.

Right. The original purpose of the change was to add the missing period
at the end of the first sentence, then I saw the missing ā€˜sā€™ [1] and
mechanically added it without checking the rest.

[1] http://java.sun.com/j2se/javadoc/writingdoccomments/index.html#styleguide


Thanks for double-checking,
Vincent

Re: svn commit: r827023 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java

Posted by Simon Pepping <sp...@leverkruid.eu>.
On Tue, Oct 20, 2009 at 10:04:09AM -0000, vhennebert@apache.org wrote:
> Author: vhennebert
> Date: Tue Oct 20 10:04:09 2009
> New Revision: 827023
> 
> URL: http://svn.apache.org/viewvc?rev=827023&view=rev
> Log:
> Fixed checkstyle issues.
> Factorized duplicated code into getXMLReader method.
> 
> Modified:
>     xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java
> 
>      /**
> -     * Create a catalog resolver and use it for XML parsing and XSLT URI resolution
> +     * Creates a catalog resolver and use it for XML parsing and XSLT URI resolution.
>       * Try the Apache Commons Resolver, and if unsuccessful,
>       * try the same built into Java 6
>       */

The above text uses inconsistent language: creates, use, try.

Simon

-- 
Simon Pepping
home page: http://www.leverkruid.eu