From 7859b3ed2d10c712c35644164d7703192e3985d8 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Wed, 21 Oct 2009 16:31:59 +0000 Subject: Renamed TransformerNode into TransformerDefaultHandler and moved it into the a.o.f.util package. Renamed TransformerNodeEndProcessing into AccessibilityPreprocessor. Renamed AccessibilityUtil into Accessibility and simplified the code. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@828090 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/accessibility/Accessibility.java | 87 +++++++++ .../accessibility/AccessibilityPreprocessor.java | 95 +++++++++ .../fop/accessibility/AccessibilityUtil.java | 100 ---------- .../apache/fop/accessibility/TransformerNode.java | 216 --------------------- .../TransformerNodeEndProcessing.java | 103 ---------- src/java/org/apache/fop/apps/FOUserAgent.java | 6 +- src/java/org/apache/fop/apps/Fop.java | 4 +- .../org/apache/fop/cli/CommandLineOptions.java | 4 +- .../apache/fop/render/pdf/PDFRenderingUtil.java | 4 +- .../apache/fop/util/TransformerDefaultHandler.java | 160 +++++++++++++++ 10 files changed, 351 insertions(+), 428 deletions(-) create mode 100644 src/java/org/apache/fop/accessibility/Accessibility.java create mode 100644 src/java/org/apache/fop/accessibility/AccessibilityPreprocessor.java delete mode 100644 src/java/org/apache/fop/accessibility/AccessibilityUtil.java delete mode 100644 src/java/org/apache/fop/accessibility/TransformerNode.java delete mode 100644 src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java create mode 100644 src/java/org/apache/fop/util/TransformerDefaultHandler.java (limited to 'src/java/org/apache') diff --git a/src/java/org/apache/fop/accessibility/Accessibility.java b/src/java/org/apache/fop/accessibility/Accessibility.java new file mode 100644 index 000000000..d550b433a --- /dev/null +++ b/src/java/org/apache/fop/accessibility/Accessibility.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.accessibility; + +import javax.xml.transform.Source; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamSource; + +import org.xml.sax.helpers.DefaultHandler; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; + +/** + * Helper class for FOP's accessibility features. + */ +public final class Accessibility { + + /** Constant string for the rendering options key to enable accessibility features. */ + public static final String ACCESSIBILITY = "accessibility"; + + // TODO what if the default factory is not a SAXTransformerFactory? + private static SAXTransformerFactory tfactory + = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); + + private static Templates addPtrTemplates; + + private static Templates reduceFOTreeTemplates; + + private Accessibility() { } + + /** + * Decorates the given handler 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 { + try { + setupTemplates(); + TransformerHandler addPtr = tfactory.newTransformerHandler(addPtrTemplates); + Transformer reduceFOTree = reduceFOTreeTemplates.newTransformer(); + return new AccessibilityPreprocessor(addPtr, reduceFOTree, userAgent, handler); + } catch (TransformerConfigurationException e) { + throw new FOPException(e); + } + } + + private static synchronized void setupTemplates() throws TransformerConfigurationException { + if (addPtrTemplates == null) { + addPtrTemplates = loadTemplates("addPtr.xsl"); + } + if (reduceFOTreeTemplates == null) { + reduceFOTreeTemplates = loadTemplates("reduceFOTree.xsl"); + } + } + + private static Templates loadTemplates(String source) throws TransformerConfigurationException { + Source src = new StreamSource(Accessibility.class.getResource(source).toExternalForm()); + return tfactory.newTemplates(src); + } + +} diff --git a/src/java/org/apache/fop/accessibility/AccessibilityPreprocessor.java b/src/java/org/apache/fop/accessibility/AccessibilityPreprocessor.java new file mode 100644 index 000000000..1958b74a8 --- /dev/null +++ b/src/java/org/apache/fop/accessibility/AccessibilityPreprocessor.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.accessibility; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import org.apache.commons.io.output.ByteArrayOutputStream; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.util.TransformerDefaultHandler; + +/** + * This class prepares an XSL-FO document for accessibility. It adds a unique + * identifier to every applicable FO, then creates the structure tree, before + * handing the document over to the regular handler. + */ +class AccessibilityPreprocessor extends TransformerDefaultHandler { + + private final ByteArrayOutputStream enrichedFOBuffer = new ByteArrayOutputStream(); + + private final Transformer reduceFOTree; + + private final FOUserAgent userAgent; + + private final DefaultHandler fopHandler; + + public AccessibilityPreprocessor(TransformerHandler addPtr, Transformer reduceFOTree, + FOUserAgent userAgent, DefaultHandler fopHandler) { + super(addPtr); + this.reduceFOTree = reduceFOTree; + this.userAgent = userAgent; + this.fopHandler = fopHandler; + getTransformerHandler().setResult(new StreamResult(enrichedFOBuffer)); + } + + /** {@inheritDoc} */ + public void endDocument() throws SAXException { + super.endDocument(); + // do the second transform to struct + try { + //TODO this must be optimized, no buffering (ex. SAX-based tee-proxy) + byte[] enrichedFO = enrichedFOBuffer.toByteArray(); + Source src = new StreamSource(new ByteArrayInputStream(enrichedFO)); + DOMResult res = new DOMResult(); + reduceFOTree.transform(src, res); + StructureTree structureTree = new StructureTree(); + NodeList pageSequences = res.getNode().getFirstChild().getChildNodes(); + for (int i = 0; i < pageSequences.getLength(); i++) { + structureTree.addPageSequenceStructure(pageSequences.item(i).getChildNodes()); + } + userAgent.setStructureTree(structureTree); + + SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); + saxParserFactory.setNamespaceAware(true); + saxParserFactory.setValidating(false); + SAXParser saxParser = saxParserFactory.newSAXParser(); + InputStream in = new ByteArrayInputStream(enrichedFO); + saxParser.parse(in, fopHandler); + } catch (Exception e) { + throw new SAXException(e); + } + } + +} diff --git a/src/java/org/apache/fop/accessibility/AccessibilityUtil.java b/src/java/org/apache/fop/accessibility/AccessibilityUtil.java deleted file mode 100644 index 4063d3f9f..000000000 --- a/src/java/org/apache/fop/accessibility/AccessibilityUtil.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.accessibility; - -import javax.xml.transform.Source; -import javax.xml.transform.Templates; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.stream.StreamSource; - -import org.xml.sax.helpers.DefaultHandler; - -import org.apache.fop.apps.FOPException; -import org.apache.fop.apps.FOUserAgent; - -/** - * Utility class for FOP's accessibility features. It provides the stylesheets used for processing - * the incoming XSL-FO stream and for setting up the transformation. - */ -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( - getAddPtrTemplates(), handler, userAgent); - return transformNode; - } - - /** - * Returns the addPtr.xsl stylesheet. - * @return the addPtr.xsl stylesheet - * @throws FOPException if transform fails - */ - public static synchronized Templates getAddPtrTemplates() throws FOPException { - if (addPtrTemplates == null) { - //Load and cache stylesheet - Source src = new StreamSource( - AccessibilityUtil.class.getResource("addPtr.xsl").toExternalForm()); - try { - addPtrTemplates = tfactory.newTemplates(src); - } catch (TransformerConfigurationException e) { - throw new FOPException(e); - } - } - return addPtrTemplates; - } - - /** - * Returns the reduceFOTree.xsl stylesheet - * @return the reduceFOTree.xsl stylesheet - * @throws FOPException if an error occurs loading the stylesheet - */ - public static synchronized Templates getReduceFOTreeTemplates() throws FOPException { - if (reduceFOTemplates == null) { - //Load and cache stylesheet - Source src = new StreamSource( - AccessibilityUtil.class.getResource("reduceFOTree.xsl").toExternalForm()); - try { - reduceFOTemplates = tfactory.newTemplates(src); - } catch (TransformerConfigurationException e) { - throw new FOPException(e); - } - } - return reduceFOTemplates; - } - } \ No newline at end of file diff --git a/src/java/org/apache/fop/accessibility/TransformerNode.java b/src/java/org/apache/fop/accessibility/TransformerNode.java deleted file mode 100644 index b127a74b5..000000000 --- a/src/java/org/apache/fop/accessibility/TransformerNode.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.accessibility; - -import javax.xml.transform.Result; -import javax.xml.transform.Templates; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.sax.TransformerHandler; - -import org.xml.sax.Attributes; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; -import org.xml.sax.helpers.DefaultHandler; - -import org.apache.fop.apps.FOPException; - -/** - * Used for accessibility to run required xslt transforms - */ -class TransformerNode extends DefaultHandler { - - private TransformerHandler transformerHandler; - - /** - * This is part of a two phase construction. Call this, then call - * initResult. - * - * @param xsltTemplates - * for transform - * @throws FOPException - * for general errors - */ - public TransformerNode(Templates xsltTemplates) throws FOPException { - try { - TransformerFactory transFact = TransformerFactory.newInstance(); - SAXTransformerFactory saxTFactory = ((SAXTransformerFactory)transFact); - transformerHandler = saxTFactory.newTransformerHandler(xsltTemplates); - } catch (TransformerConfigurationException t) { - throw new FOPException(t); - } - } - - /** - * Call this after calling constructor for xsltFile only above. - * - * @param result - * of transform - */ - public void initResult(Result result) { - transformerHandler.setResult(result); - } - - /******************** start of ContentHandler ***************************/ - /** {@inheritDoc} */ - public void setDocumentLocator(Locator locator) { - transformerHandler.setDocumentLocator(locator); - } - - /** {@inheritDoc} */ - public void startDocument() throws SAXException { - transformerHandler.startDocument(); - } - - /** {@inheritDoc} */ - public void endDocument() throws SAXException { - transformerHandler.endDocument(); - } - - /** {@inheritDoc} */ - public void processingInstruction(String target, String data) throws SAXException { - transformerHandler.processingInstruction(target, data); - } - - /** {@inheritDoc} */ - public void startElement(String uri, String local, String raw, Attributes attrs) - throws SAXException { - AttributesImpl ai = new AttributesImpl(attrs); - transformerHandler.startElement(uri, local, raw, ai); - } - - /** {@inheritDoc} */ - public void characters(char[] ch, int start, int length) throws SAXException { - transformerHandler.characters(ch, start, length); - } - - /** {@inheritDoc} */ - public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { - transformerHandler.ignorableWhitespace(ch, start, length); - } - - /** {@inheritDoc} */ - public void endElement(String uri, String local, String raw) throws SAXException { - transformerHandler.endElement(uri, local, raw); - } - - /** {@inheritDoc} */ - public void skippedEntity(String string) throws SAXException { - transformerHandler.skippedEntity(string); - } - - /** {@inheritDoc} */ - public void startPrefixMapping(String string, String string1) throws SAXException { - transformerHandler.startPrefixMapping(string, string1); - } - - /** {@inheritDoc} */ - public void endPrefixMapping(String string) throws SAXException { - transformerHandler.endPrefixMapping(string); - } - - /***************************** LexicalHandlerImpl **************************/ - /** - * @param name - * - param1 - * @param pid - * - param2 - * @param lid - * - param3 - * @throws SAXException - * - if parser fails - */ - public void startDTD(String name, String pid, String lid) throws SAXException { - transformerHandler.startDTD(name, pid, lid); - } - - /** - * End of DTD - * - * @throws SAXException - * - if parser fails - */ - public void endDTD() throws SAXException { - transformerHandler.endDTD(); - } - - /** - * startEnitity. - * - * @param string - * - param 1 - * @throws SAXException - * - if parser fails - */ - public void startEntity(String string) throws SAXException { - transformerHandler.startEntity(string); - } - - /** - * end Entity - * - * @param string - * - param 1 - * @throws SAXException - * - if paser fails - */ - public void endEntity(String string) throws SAXException { - transformerHandler.endEntity(string); - } - - /** - * Start of CDATA section - * - * @throws SAXException - * - parser fails - */ - public void startCDATA() throws SAXException { - transformerHandler.startCDATA(); - } - - /** - * endCDATA section - * - * @throws SAXException - * - if paser fails - */ - public void endCDATA() throws SAXException { - transformerHandler.endCDATA(); - } - - /** - * - * @param charArray - * - the characters - * @param int1 - * - param 2 - * @param int2 - * - param 3 - * @throws SAXException - * - if paser fails - */ - public void comment(char[] charArray, int int1, int int2) throws SAXException { - 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 deleted file mode 100644 index 36f36fdef..000000000 --- a/src/java/org/apache/fop/accessibility/TransformerNodeEndProcessing.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.accessibility; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Templates; -import javax.xml.transform.Transformer; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; - -import org.w3c.dom.NodeList; -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; - -/** - * An extension of TransformerNode used to run 2nd transform after completion of first - */ -class TransformerNodeEndProcessing extends TransformerNode { - - private final ByteArrayOutputStream enrichedFOBuffer = new ByteArrayOutputStream(); - private DefaultHandler delegateHandler = null; - private final FOUserAgent userAgent; - - /** - * Do a transform, but perform special processing at the end for the access - * stuff. - * - * @param xsltTemplates Transform to do. - * @param fopHandler Used in the end processing - * @param userAgent the userAgent - * @throws FOPException - * if transform fails - */ - public TransformerNodeEndProcessing(Templates xsltTemplates, DefaultHandler fopHandler, - FOUserAgent userAgent) throws FOPException { - super(xsltTemplates); - delegateHandler = fopHandler; - this.userAgent = userAgent; - Result res1 = new StreamResult(enrichedFOBuffer); - super.initResult(res1); - } - - /** {@inheritDoc} */ - public void endDocument() throws SAXException { - super.endDocument(); - // do the second transform to struct - try { - //TODO this must be optimized, no buffering (ex. SAX-based tee-proxy) - byte[] enrichedFO = enrichedFOBuffer.toByteArray(); - Transformer transformer = AccessibilityUtil.getReduceFOTreeTemplates().newTransformer(); - Source src = new StreamSource(new ByteArrayInputStream(enrichedFO)); - DOMResult res = new DOMResult(); - transformer.transform(src, res); - StructureTree structureTree = new StructureTree(); - NodeList pageSequences = res.getNode().getFirstChild().getChildNodes(); - for (int i = 0; i < pageSequences.getLength(); i++) { - structureTree.addPageSequenceStructure(pageSequences.item(i).getChildNodes()); - } - userAgent.setStructureTree(structureTree); - - SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); - saxParserFactory.setNamespaceAware(true); - saxParserFactory.setValidating(false); - SAXParser saxParser = saxParserFactory.newSAXParser(); - InputStream in = new ByteArrayInputStream(enrichedFO); - saxParser.parse(in, delegateHandler); - } catch (Exception e) { - // TODO Auto-generated catch block - throw new SAXException(e); - } - - } - -} diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java index 11de99e33..0a65203cc 100644 --- a/src/java/org/apache/fop/apps/FOUserAgent.java +++ b/src/java/org/apache/fop/apps/FOUserAgent.java @@ -37,7 +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.accessibility.Accessibility; import org.apache.fop.accessibility.StructureTree; import org.apache.fop.events.DefaultEventBroadcaster; import org.apache.fop.events.Event; @@ -655,7 +655,7 @@ public class FOUserAgent { */ public void setAccessibility(boolean accessibility) { if (accessibility) { - getRendererOptions().put(AccessibilityUtil.ACCESSIBILITY, Boolean.TRUE); + getRendererOptions().put(Accessibility.ACCESSIBILITY, Boolean.TRUE); } } @@ -664,7 +664,7 @@ public class FOUserAgent { * @return true if accessibility is enabled */ public boolean isAccessibilityEnabled() { - Boolean enabled = (Boolean)this.getRendererOptions().get(AccessibilityUtil.ACCESSIBILITY); + Boolean enabled = (Boolean)this.getRendererOptions().get(Accessibility.ACCESSIBILITY); if (enabled != null) { return enabled.booleanValue(); } else { diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java index 9dfa70325..07fd4c0a4 100644 --- a/src/java/org/apache/fop/apps/Fop.java +++ b/src/java/org/apache/fop/apps/Fop.java @@ -24,7 +24,7 @@ import java.io.OutputStream; import org.xml.sax.helpers.DefaultHandler; -import org.apache.fop.accessibility.AccessibilityUtil; +import org.apache.fop.accessibility.Accessibility; import org.apache.fop.fo.FOTreeBuilder; /** @@ -112,7 +112,7 @@ public class Fop { createDefaultHandler(); } if (this.foUserAgent.isAccessibilityEnabled()) { - return AccessibilityUtil.decorateDefaultHandler(this.foTreeBuilder, foUserAgent); + return Accessibility.decorateDefaultHandler(this.foTreeBuilder, foUserAgent); } else { return this.foTreeBuilder; } diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index e0dc0a057..043dfe3c8 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -36,7 +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.accessibility.Accessibility; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FopFactory; @@ -342,7 +342,7 @@ public class CommandLineOptions { } else if (args[i].equals("-if")) { i = i + parseIntermediateFormatOption(args, i); } else if (args[i].equals("-a")) { - this.renderingOptions.put(AccessibilityUtil.ACCESSIBILITY, Boolean.TRUE); + this.renderingOptions.put(Accessibility.ACCESSIBILITY, Boolean.TRUE); } else if (args[i].equals("-v")) { /* Currently just print the version */ printVersion(); diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java index 52d97fa31..3d68812b1 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java @@ -37,7 +37,7 @@ import org.apache.xmlgraphics.xmp.Metadata; import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter; import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema; -import org.apache.fop.accessibility.AccessibilityUtil; +import org.apache.fop.accessibility.Accessibility; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fo.extensions.xmp.XMPMetadata; import org.apache.fop.pdf.PDFAMode; @@ -164,7 +164,7 @@ class PDFRenderingUtil implements PDFConfigurationConstants { } if (this.pdfAMode.isPDFA1LevelA()) { //Enable accessibility if PDF/A-1a is enabled because it requires tagged PDF. - userAgent.getRendererOptions().put(AccessibilityUtil.ACCESSIBILITY, Boolean.TRUE); + userAgent.getRendererOptions().put(Accessibility.ACCESSIBILITY, Boolean.TRUE); } s = (String)userAgent.getRendererOptions().get(PDF_X_MODE); if (s != null) { diff --git a/src/java/org/apache/fop/util/TransformerDefaultHandler.java b/src/java/org/apache/fop/util/TransformerDefaultHandler.java new file mode 100644 index 000000000..cf07cc836 --- /dev/null +++ b/src/java/org/apache/fop/util/TransformerDefaultHandler.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.util; + +import javax.xml.transform.sax.TransformerHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.ext.DefaultHandler2; +import org.xml.sax.helpers.AttributesImpl; + +/** + * A DefaultHandler implementation that delegates all the method calls to a + * {@link TransformerHandler} instance. + */ +public class TransformerDefaultHandler extends DefaultHandler2 { + + private TransformerHandler transformerHandler; + + /** + * Creates a new instance delegating to the given TransformerHandler object. + * + * @param transformerHandler the object to which all the method calls will + * be delegated + */ + public TransformerDefaultHandler(TransformerHandler transformerHandler) { + this.transformerHandler = transformerHandler; + } + + /** + * Returns the delegate TransformerHandler instance. + * + * @return the object to which all method calls are delegated + */ + public TransformerHandler getTransformerHandler() { + return transformerHandler; + } + + /** {@inheritDoc} */ + public void setDocumentLocator(Locator locator) { + transformerHandler.setDocumentLocator(locator); + } + + /** {@inheritDoc} */ + public void startDocument() throws SAXException { + transformerHandler.startDocument(); + } + + /** {@inheritDoc} */ + public void endDocument() throws SAXException { + transformerHandler.endDocument(); + } + + /** {@inheritDoc} */ + public void startPrefixMapping(String prefix, String uri) throws SAXException { + transformerHandler.startPrefixMapping(prefix, uri); + } + + /** {@inheritDoc} */ + public void endPrefixMapping(String string) throws SAXException { + transformerHandler.endPrefixMapping(string); + } + + /** {@inheritDoc} */ + public void startElement(String uri, String localName, String qName, Attributes attrs) + throws SAXException { + AttributesImpl ai = new AttributesImpl(attrs); + transformerHandler.startElement(uri, localName, qName, ai); + } + + /** {@inheritDoc} */ + public void endElement(String uri, String localName, String qName) throws SAXException { + transformerHandler.endElement(uri, localName, qName); + } + + /** {@inheritDoc} */ + public void characters(char[] ch, int start, int length) throws SAXException { + transformerHandler.characters(ch, start, length); + } + + /** {@inheritDoc} */ + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + transformerHandler.ignorableWhitespace(ch, start, length); + } + + /** {@inheritDoc} */ + public void processingInstruction(String target, String data) throws SAXException { + transformerHandler.processingInstruction(target, data); + } + + /** {@inheritDoc} */ + public void skippedEntity(String name) throws SAXException { + transformerHandler.skippedEntity(name); + } + + /** {@inheritDoc} */ + public void notationDecl(String name, String publicId, String systemId) throws SAXException { + transformerHandler.notationDecl(name, publicId, systemId); + } + + /** {@inheritDoc} */ + public void unparsedEntityDecl(String name, String publicId, String systemId, + String notationName) throws SAXException { + transformerHandler.unparsedEntityDecl(name, publicId, systemId, notationName); + } + + /** {@inheritDoc} */ + public void startDTD(String name, String pid, String lid) throws SAXException { + transformerHandler.startDTD(name, pid, lid); + } + + /** {@inheritDoc} */ + public void endDTD() throws SAXException { + transformerHandler.endDTD(); + } + + /** {@inheritDoc} */ + public void startEntity(String name) throws SAXException { + transformerHandler.startEntity(name); + } + + /** {@inheritDoc} */ + public void endEntity(String name) throws SAXException { + transformerHandler.endEntity(name); + } + + /** {@inheritDoc} */ + public void startCDATA() throws SAXException { + transformerHandler.startCDATA(); + } + + /** {@inheritDoc} */ + public void endCDATA() throws SAXException { + transformerHandler.endCDATA(); + } + + /** {@inheritDoc} */ + public void comment(char[] charArray, int start, int length) throws SAXException { + transformerHandler.comment(charArray, start, length); + } + +} -- cgit v1.2.3