Author: jeremias
Date: Fri Apr 17 07:54:38 2009
New Revision: 765889

URL: http://svn.apache.org/viewvc?rev=765889&view=rev
Log:
Incorporated some more of the feedback to #46705:
- String Constant for "accessibility"
- Removed unused constructors
- Remove unnecessary null-checks.

Modified:
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/AccessibilityUtil.java
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNode.java
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FOUserAgent.java
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FopFactory.java
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/cli/CommandLineOptions.java
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/AccessibilityUtil.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/AccessibilityUtil.java?rev=765889&r1=765888&r2=765889&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/AccessibilityUtil.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/AccessibilityUtil.java
 Fri Apr 17 07:54:38 2009
@@ -36,12 +36,23 @@
  */
 public class AccessibilityUtil {
 
+    /** Constant string for the rendering options key to enable accessibility 
features. */
+    public static final String ACCESSIBILITY = "accessibility";
+
     private static SAXTransformerFactory tfactory
         = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
 
     private static Templates addPtrTemplates;
     private static Templates reduceFOTemplates;
 
+    /**
+     * Decorates the given {...@link DefaultHandler} so the structure tree 
used for accessibility
+     * features can be branched off the main content stream.
+     * @param handler the handler to decorate
+     * @param userAgent the user agent
+     * @return the decorated handler
+     * @throws FOPException if an error occurs setting up the decoration
+     */
     public static DefaultHandler decorateDefaultHandler(DefaultHandler handler,
             FOUserAgent userAgent) throws FOPException {
         DefaultHandler transformNode = new TransformerNodeEndProcessing(

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNode.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNode.java?rev=765889&r1=765888&r2=765889&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNode.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNode.java
 Fri Apr 17 07:54:38 2009
@@ -19,17 +19,12 @@
 
 package org.apache.fop.accessibility;
 
-import java.io.File;
-
 import javax.xml.transform.Result;
-import javax.xml.transform.Source;
 import javax.xml.transform.Templates;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXResult;
 import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamSource;
 
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
@@ -47,70 +42,6 @@
     private TransformerHandler transformerHandler;
 
     /**
-     * happens after setParams have been broadcast.
-     *
-     * @param downstreamHandler
-     *            the handler passed in
-     * @param xsltFile
-     *            for transform
-     * @throws FOPException
-     *             for general errors
-     */
-    public TransformerNode(DefaultHandler downstreamHandler, File xsltFile) 
throws FOPException {
-        try {
-            TransformerFactory transFact = TransformerFactory.newInstance();
-            SAXTransformerFactory saxTFactory = 
((SAXTransformerFactory)transFact);
-            StreamSource ss = new StreamSource(xsltFile);
-            transformerHandler = saxTFactory.newTransformerHandler(ss);
-            SAXResult saxResult = new SAXResult();
-            saxResult.setHandler(downstreamHandler);
-            transformerHandler.setResult(saxResult);
-        } catch (TransformerConfigurationException t) {
-            throw new FOPException(t);
-        }
-    }
-
-    /**
-     *
-     * @param result
-     *            of transform
-     * @param xsltFile
-     *            for transform
-     * @throws FOPException
-     *             for general errors
-     */
-    public TransformerNode(Result result, File xsltFile) throws FOPException {
-        try {
-            TransformerFactory transFact = TransformerFactory.newInstance();
-            SAXTransformerFactory saxTFactory = 
((SAXTransformerFactory)transFact);
-            StreamSource ss = new StreamSource(xsltFile);
-            transformerHandler = saxTFactory.newTransformerHandler(ss);
-            transformerHandler.setResult(result);
-        } catch (TransformerConfigurationException t) {
-            throw new FOPException(t);
-        }
-    }
-
-    /**
-     * This is part of a two phase construction. Call this, then call
-     * initResult.
-     *
-     * @param xsltFile
-     *            for transform
-     * @throws FOPException
-     *             for general errors
-     */
-    public TransformerNode(Source xsltFile) throws FOPException {
-        try {
-            TransformerFactory transFact = TransformerFactory.newInstance();
-            SAXTransformerFactory saxTFactory = 
((SAXTransformerFactory)transFact);
-            transformerHandler = saxTFactory.newTransformerHandler(xsltFile);
-        } catch (TransformerConfigurationException t) {
-            throw new FOPException(t);
-        }
-    }
-
-    /**
      * This is part of a two phase construction. Call this, then call
      * initResult.
      *
@@ -142,81 +73,59 @@
     /******************** start of ContentHandler ***************************/
     /** {...@inheritdoc} */
     public void setDocumentLocator(Locator locator) {
-        if (transformerHandler != null) {
-            transformerHandler.setDocumentLocator(locator);
-        }
+        transformerHandler.setDocumentLocator(locator);
     }
 
     /** {...@inheritdoc} */
     public void startDocument() throws SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.startDocument();
-        }
+        transformerHandler.startDocument();
     }
 
     /** {...@inheritdoc} */
     public void endDocument() throws SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.endDocument();
-        }
+        transformerHandler.endDocument();
     }
 
     /** {...@inheritdoc} */
     public void processingInstruction(String target, String data) throws 
SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.processingInstruction(target, data);
-        }
+        transformerHandler.processingInstruction(target, data);
     }
 
     /** {...@inheritdoc} */
     public void startElement(String uri, String local, String raw, Attributes 
attrs)
             throws SAXException {
         AttributesImpl ai = new AttributesImpl(attrs);
-        if (transformerHandler != null) {
-            transformerHandler.startElement(uri, local, raw, ai);
-        }
+        transformerHandler.startElement(uri, local, raw, ai);
     }
 
     /** {...@inheritdoc} */
     public void characters(char[] ch, int start, int length) throws 
SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.characters(ch, start, length);
-        }
+        transformerHandler.characters(ch, start, length);
     }
 
     /** {...@inheritdoc} */
     public void ignorableWhitespace(char[] ch, int start, int length) throws 
SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.ignorableWhitespace(ch, start, length);
-        }
+        transformerHandler.ignorableWhitespace(ch, start, length);
     }
 
     /** {...@inheritdoc} */
     public void endElement(String uri, String local, String raw) throws 
SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.endElement(uri, local, raw);
-        }
+        transformerHandler.endElement(uri, local, raw);
     }
 
     /** {...@inheritdoc} */
     public void skippedEntity(String string) throws SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.skippedEntity(string);
-        }
+        transformerHandler.skippedEntity(string);
     }
 
     /** {...@inheritdoc} */
     public void startPrefixMapping(String string, String string1) throws 
SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.startPrefixMapping(string, string1);
-        }
+        transformerHandler.startPrefixMapping(string, string1);
     }
 
     /** {...@inheritdoc} */
     public void endPrefixMapping(String string) throws SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.endPrefixMapping(string);
-        }
+        transformerHandler.endPrefixMapping(string);
     }
 
     /***************************** LexicalHandlerImpl 
**************************/
@@ -231,9 +140,7 @@
      *             - if parser fails
      */
     public void startDTD(String name, String pid, String lid) throws 
SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.startDTD(name, pid, lid);
-        }
+        transformerHandler.startDTD(name, pid, lid);
     }
 
     /**
@@ -243,9 +150,7 @@
      *             - if parser fails
      */
     public void endDTD() throws SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.endDTD();
-        }
+        transformerHandler.endDTD();
     }
 
     /**
@@ -257,9 +162,7 @@
      *             - if parser fails
      */
     public void startEntity(String string) throws SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.startEntity(string);
-        }
+        transformerHandler.startEntity(string);
     }
 
     /**
@@ -271,9 +174,7 @@
      *             - if paser fails
      */
     public void endEntity(String string) throws SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.endEntity(string);
-        }
+        transformerHandler.endEntity(string);
     }
 
     /**
@@ -283,9 +184,7 @@
      *             - parser fails
      */
     public void startCDATA() throws SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.startCDATA();
-        }
+        transformerHandler.startCDATA();
     }
 
     /**
@@ -295,9 +194,7 @@
      *             - if paser fails
      */
     public void endCDATA() throws SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.endCDATA();
-        }
+        transformerHandler.endCDATA();
     }
 
     /**
@@ -312,9 +209,7 @@
      *             - if paser fails
      */
     public void comment(char[] charArray, int int1, int int2) throws 
SAXException {
-        if (transformerHandler != null) {
-            transformerHandler.comment(charArray, int1, int2);
-        }
+        transformerHandler.comment(charArray, int1, int2);
     }
 
     /******************** End of Lexical Handler ***********************/

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java?rev=765889&r1=765888&r2=765889&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java
 Fri Apr 17 07:54:38 2009
@@ -20,7 +20,6 @@
 package org.apache.fop.accessibility;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
 import javax.xml.parsers.SAXParser;
@@ -35,6 +34,8 @@
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
+import org.apache.commons.io.output.ByteArrayOutputStream;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 
@@ -66,25 +67,6 @@
         super.initResult(res1);
     }
 
-    /**
-     * Do a transform, but perform special processing at the end for the access
-     * stuff.
-     *
-     * @param xsltFile Transform to do.
-     * @param fopHandler Used in the end processing
-     * @param userAgent the userAgent
-     * @throws FOPException if transform fails
-     */
-
-    public TransformerNodeEndProcessing(Source xsltFile, DefaultHandler 
fopHandler,
-            FOUserAgent userAgent) throws FOPException {
-        super(xsltFile);
-        delegateHandler = fopHandler;
-        this.userAgent = userAgent;
-        Result res1 = new StreamResult(enrichedFOBuffer);
-        super.initResult(res1);
-    }
-
     /** {...@inheritdoc} */
     public void endDocument() throws SAXException {
         super.endDocument();

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FOUserAgent.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FOUserAgent.java?rev=765889&r1=765888&r2=765889&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FOUserAgent.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FOUserAgent.java
 Fri Apr 17 07:54:38 2009
@@ -37,6 +37,7 @@
 import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext;
 
 import org.apache.fop.Version;
+import org.apache.fop.accessibility.AccessibilityUtil;
 import org.apache.fop.events.DefaultEventBroadcaster;
 import org.apache.fop.events.Event;
 import org.apache.fop.events.EventBroadcaster;
@@ -155,8 +156,8 @@
         this.factory = factory;
         setBaseURL(factory.getBaseURL());
         setTargetResolution(factory.getTargetResolution());
-        if (this.getRendererOptions().get("accessibility") == null) {
-            this.rendererOptions.put("accessibility", Boolean.FALSE);
+        if (this.getRendererOptions().get(AccessibilityUtil.ACCESSIBILITY) == 
null) {
+            this.rendererOptions.put(AccessibilityUtil.ACCESSIBILITY, 
Boolean.FALSE);
         }
     }
 
@@ -654,7 +655,7 @@
      * @return true if accessibility is enabled
      */
     public boolean isAccessibilityEnabled() {
-        Boolean enabled = 
(Boolean)this.getRendererOptions().get("accessibility");
+        Boolean enabled = 
(Boolean)this.getRendererOptions().get(AccessibilityUtil.ACCESSIBILITY);
         if (enabled != null) {
             return enabled.booleanValue();
         } else {

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FopFactory.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FopFactory.java?rev=765889&r1=765888&r2=765889&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FopFactory.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/apps/FopFactory.java
 Fri Apr 17 07:54:38 2009
@@ -41,6 +41,7 @@
 import org.apache.xmlgraphics.image.loader.ImageContext;
 import org.apache.xmlgraphics.image.loader.ImageManager;
 
+import org.apache.fop.accessibility.AccessibilityUtil;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.fo.ElementMappingRegistry;
 import org.apache.fop.fonts.FontCache;
@@ -99,7 +100,7 @@
      *  external-graphics.
      */
     private String base = null;
-    
+
     /**
      *  Controls if accessibility is turned on or off
      */
@@ -186,7 +187,8 @@
      */
     public FOUserAgent newFOUserAgent() {
         FOUserAgent userAgent = new FOUserAgent(this);
-        userAgent.getRendererOptions().put("accessibility", 
Boolean.valueOf(this.accessibility));
+        userAgent.getRendererOptions().put(AccessibilityUtil.ACCESSIBILITY,
+                Boolean.valueOf(this.accessibility));
         return userAgent;
     }
 
@@ -197,7 +199,7 @@
     void setAccessibility(boolean value) {
         this.accessibility = value;
     }
-    
+
     /**
      * Returns a new {...@link Fop} instance. FOP will be configured with a 
default user agent
      * instance.

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/cli/CommandLineOptions.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/cli/CommandLineOptions.java?rev=765889&r1=765888&r2=765889&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/cli/CommandLineOptions.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/cli/CommandLineOptions.java
 Fri Apr 17 07:54:38 2009
@@ -36,6 +36,7 @@
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.Version;
+import org.apache.fop.accessibility.AccessibilityUtil;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
@@ -333,7 +334,7 @@
             } else if (args[i].equals("-if")) {
                 i = i + parseIntermediateFormatOption(args, i);
             } else if (args[i].equals("-a")) {
-                this.renderingOptions.put("accessibility", Boolean.TRUE);
+                this.renderingOptions.put(AccessibilityUtil.ACCESSIBILITY, 
Boolean.TRUE);
             } else if (args[i].equals("-v")) {
                 printVersion();
                 return false;

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java?rev=765889&r1=765888&r2=765889&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java
 Fri Apr 17 07:54:38 2009
@@ -19,6 +19,7 @@
 
 package org.apache.fop.render.pdf;
 
+
 /**
  * Constants used for configuring PDF output.
  */
@@ -49,6 +50,4 @@
      * PDF/X profile is active).
      */
     String KEY_DISABLE_SRGB_COLORSPACE = "disable-srgb-colorspace";
-    /** PDF Accessibility */
-    String ACCESSIBLITY = "accessibility";
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to