aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-04-17 07:54:38 +0000
committerJeremias Maerki <jeremias@apache.org>2009-04-17 07:54:38 +0000
commit2a16dbaa207c3e36a43dca0dceaaa1bea51eb87d (patch)
tree56f6993028a85802b3f142d95c7be76d5f01c48c /src/java/org
parent0fc0d56d8b7b2685ee39c433e1b26d926114d6e7 (diff)
downloadxmlgraphics-fop-2a16dbaa207c3e36a43dca0dceaaa1bea51eb87d.tar.gz
xmlgraphics-fop-2a16dbaa207c3e36a43dca0dceaaa1bea51eb87d.zip
Incorporated some more of the feedback to #46705:
- String Constant for "accessibility" - Removed unused constructors - Remove unnecessary null-checks. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@765889 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/fop/accessibility/AccessibilityUtil.java11
-rw-r--r--src/java/org/apache/fop/accessibility/TransformerNode.java141
-rw-r--r--src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java22
-rw-r--r--src/java/org/apache/fop/apps/FOUserAgent.java7
-rw-r--r--src/java/org/apache/fop/apps/FopFactory.java8
-rw-r--r--src/java/org/apache/fop/cli/CommandLineOptions.java3
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java3
7 files changed, 43 insertions, 152 deletions
diff --git a/src/java/org/apache/fop/accessibility/AccessibilityUtil.java b/src/java/org/apache/fop/accessibility/AccessibilityUtil.java
index 0dc5840b6..4063d3f9f 100644
--- a/src/java/org/apache/fop/accessibility/AccessibilityUtil.java
+++ b/src/java/org/apache/fop/accessibility/AccessibilityUtil.java
@@ -36,12 +36,23 @@ import org.apache.fop.apps.FOUserAgent;
*/
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(
diff --git a/src/java/org/apache/fop/accessibility/TransformerNode.java b/src/java/org/apache/fop/accessibility/TransformerNode.java
index 115c13703..b127a74b5 100644
--- a/src/java/org/apache/fop/accessibility/TransformerNode.java
+++ b/src/java/org/apache/fop/accessibility/TransformerNode.java
@@ -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 @@ class TransformerNode extends DefaultHandler {
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 @@ class TransformerNode extends DefaultHandler {
/******************** 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 @@ class TransformerNode extends DefaultHandler {
* - 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 @@ class TransformerNode extends DefaultHandler {
* - if parser fails
*/
public void endDTD() throws SAXException {
- if (transformerHandler != null) {
- transformerHandler.endDTD();
- }
+ transformerHandler.endDTD();
}
/**
@@ -257,9 +162,7 @@ class TransformerNode extends DefaultHandler {
* - if parser fails
*/
public void startEntity(String string) throws SAXException {
- if (transformerHandler != null) {
- transformerHandler.startEntity(string);
- }
+ transformerHandler.startEntity(string);
}
/**
@@ -271,9 +174,7 @@ class TransformerNode extends DefaultHandler {
* - if paser fails
*/
public void endEntity(String string) throws SAXException {
- if (transformerHandler != null) {
- transformerHandler.endEntity(string);
- }
+ transformerHandler.endEntity(string);
}
/**
@@ -283,9 +184,7 @@ class TransformerNode extends DefaultHandler {
* - parser fails
*/
public void startCDATA() throws SAXException {
- if (transformerHandler != null) {
- transformerHandler.startCDATA();
- }
+ transformerHandler.startCDATA();
}
/**
@@ -295,9 +194,7 @@ class TransformerNode extends DefaultHandler {
* - if paser fails
*/
public void endCDATA() throws SAXException {
- if (transformerHandler != null) {
- transformerHandler.endCDATA();
- }
+ transformerHandler.endCDATA();
}
/**
@@ -312,9 +209,7 @@ class TransformerNode extends DefaultHandler {
* - 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 ***********************/
diff --git a/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java b/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java
index 8e02c67cd..34974233a 100644
--- a/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java
+++ b/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java
@@ -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 javax.xml.transform.stream.StreamSource;
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 @@ class TransformerNodeEndProcessing extends TransformerNode {
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();
diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java
index 64ab413dc..13db8d5ef 100644
--- a/src/java/org/apache/fop/apps/FOUserAgent.java
+++ b/src/java/org/apache/fop/apps/FOUserAgent.java
@@ -37,6 +37,7 @@ import org.apache.xmlgraphics.image.loader.ImageSessionContext;
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 @@ public class FOUserAgent {
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 @@ public class FOUserAgent {
* @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 {
diff --git a/src/java/org/apache/fop/apps/FopFactory.java b/src/java/org/apache/fop/apps/FopFactory.java
index 1a5c3cfd4..6693f33c4 100644
--- a/src/java/org/apache/fop/apps/FopFactory.java
+++ b/src/java/org/apache/fop/apps/FopFactory.java
@@ -41,6 +41,7 @@ import org.apache.commons.logging.LogFactory;
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 @@ public class FopFactory implements ImageContext {
* external-graphics.
*/
private String base = null;
-
+
/**
* Controls if accessibility is turned on or off
*/
@@ -186,7 +187,8 @@ public class FopFactory implements ImageContext {
*/
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 @@ public class FopFactory implements ImageContext {
void setAccessibility(boolean value) {
this.accessibility = value;
}
-
+
/**
* Returns a new {@link Fop} instance. FOP will be configured with a default user agent
* instance.
diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java
index cb6756476..e82ce13a7 100644
--- a/src/java/org/apache/fop/cli/CommandLineOptions.java
+++ b/src/java/org/apache/fop/cli/CommandLineOptions.java
@@ -36,6 +36,7 @@ import org.apache.commons.logging.Log;
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 @@ public class CommandLineOptions {
} 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;
diff --git a/src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java b/src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java
index 2f4379795..d5e6b0b63 100644
--- a/src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java
+++ b/src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java
@@ -19,6 +19,7 @@
package org.apache.fop.render.pdf;
+
/**
* Constants used for configuring PDF output.
*/
@@ -49,6 +50,4 @@ public interface PDFConfigurationConstants {
* PDF/X profile is active).
*/
String KEY_DISABLE_SRGB_COLORSPACE = "disable-srgb-colorspace";
- /** PDF Accessibility */
- String ACCESSIBLITY = "accessibility";
}