Subject: [PATCH 08/20] Remove unused code --- .../apache/fop/accessibility/Accessibility.java | 54 ---------- .../accessibility/AccessibilityPreprocessor.java | 95 ------------------ .../apache/fop/accessibility/StructureTree.java | 102 -------------------- src/java/org/apache/fop/accessibility/addPtr.xsl | 88 ----------------- .../org/apache/fop/accessibility/reduceFOTree.xsl | 100 ------------------- src/java/org/apache/fop/apps/FOUserAgent.java | 24 ----- src/java/org/apache/fop/fo/FOPropertyMapping.java | 6 - 7 files changed, 0 insertions(+), 469 deletions(-) delete mode 100644 src/java/org/apache/fop/accessibility/AccessibilityPreprocessor.java delete mode 100644 src/java/org/apache/fop/accessibility/StructureTree.java delete mode 100644 src/java/org/apache/fop/accessibility/addPtr.xsl delete mode 100644 src/java/org/apache/fop/accessibility/reduceFOTree.xsl diff --git a/src/java/org/apache/fop/accessibility/Accessibility.java b/src/java/org/apache/fop/accessibility/Accessibility.java index 73bffe5..c1e4cf3 100644 --- a/src/java/org/apache/fop/accessibility/Accessibility.java +++ b/src/java/org/apache/fop/accessibility/Accessibility.java @@ -19,19 +19,6 @@ 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. */ @@ -40,48 +27,7 @@ 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 deleted file mode 100644 index 0ecd9ed..0000000 --- a/src/java/org/apache/fop/accessibility/AccessibilityPreprocessor.java +++ /dev/null @@ -1,95 +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: AccessibilityPreprocessor.java 830293 2009-10-27 19:07:52Z vhennebert $ */ - -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/StructureTree.java b/src/java/org/apache/fop/accessibility/StructureTree.java deleted file mode 100644 index 94e8b36..0000000 --- a/src/java/org/apache/fop/accessibility/StructureTree.java +++ /dev/null @@ -1,102 +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: StructureTree.java 830293 2009-10-27 19:07:52Z vhennebert $ */ - -package org.apache.fop.accessibility; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * A reduced version of the document's FO tree, containing only its logical - * structure. Used by accessible output formats. - */ -public final class StructureTree { - - private final List pageSequenceStructures = new ArrayList(); - - /** - * Package-private default constructor. - */ - StructureTree() { } - - private static boolean flowOrStaticContentNodes(NodeList nodes) { - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node.getNodeType() != Node.ELEMENT_NODE) { - return false; - } - String name = node.getLocalName(); - if (!(name.equals("flow") || name.equals("static-content"))) { - return false; - } - } - return true; - } - - void addPageSequenceStructure(NodeList structureTree) { - assert flowOrStaticContentNodes(structureTree); - pageSequenceStructures.add(structureTree); - } - - /** - * Returns the list of nodes that are the children of the given page sequence. - * - * @param index index of the page sequence, 0-based - * @return its children nodes - */ - public NodeList getPageSequence(int index) { - return (NodeList) pageSequenceStructures.get(index); - } - - /** - * Returns an XML-like representation of the structure trees. - *

- * Note: use only for debugging purpose, as this method - * performs non-trivial operations. - *

- * @return a string representation of this object - */ - public String toString() { - try { - Transformer t = TransformerFactory.newInstance().newTransformer(); - Writer str = new StringWriter(); - for (Iterator iter = pageSequenceStructures.iterator(); iter.hasNext();) { - NodeList nodes = (NodeList) iter.next(); - for (int i = 0, c = nodes.getLength(); i < c; i++) { - t.transform(new DOMSource(nodes.item(i)), new StreamResult(str)); - } - } - return str.toString(); - } catch (Exception e) { - return e.toString(); - } - } - -} diff --git a/src/java/org/apache/fop/accessibility/addPtr.xsl b/src/java/org/apache/fop/accessibility/addPtr.xsl deleted file mode 100644 index a236561..0000000 --- a/src/java/org/apache/fop/accessibility/addPtr.xsl +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/java/org/apache/fop/accessibility/reduceFOTree.xsl b/src/java/org/apache/fop/accessibility/reduceFOTree.xsl deleted file mode 100644 index 7786842..0000000 --- a/src/java/org/apache/fop/accessibility/reduceFOTree.xsl +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java index 3f1edab..c23ace7 100644 --- a/src/java/org/apache/fop/apps/FOUserAgent.java +++ b/src/java/org/apache/fop/apps/FOUserAgent.java @@ -39,7 +39,6 @@ import org.apache.xmlgraphics.util.UnitConv; import org.apache.fop.Version; import org.apache.fop.accessibility.Accessibility; -import org.apache.fop.accessibility.StructureTree; import org.apache.fop.events.DefaultEventBroadcaster; import org.apache.fop.events.Event; import org.apache.fop.events.EventBroadcaster; @@ -102,8 +101,6 @@ public class FOUserAgent { private boolean conserveMemoryPolicy = false; private EventBroadcaster eventBroadcaster = new FOPEventBroadcaster(); - private StructureTree structureTree; - /** Producer: Metadata element for the system/software that produces * the document. (Some renderers can store this in the document.) */ @@ -672,26 +669,5 @@ public class FOUserAgent { return false; } } - - /** - * Sets the document's structure tree, for use by accessible output formats. - * - * @param structureTree a simplified version of the FO tree, retaining only - * its logical structure - */ - public void setStructureTree(StructureTree structureTree) { - this.structureTree = structureTree; - } - - /** - * Returns the document's structure tree, for use by accessible output - * formats. - * - * @return a simplified version of the FO tree, retaining only its logical - * structure - */ - public StructureTree getStructureTree() { - return this.structureTree; - } } diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index b87e293..62ddbbd 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -2533,12 +2533,6 @@ public final class FOPropertyMapping implements Constants { m.setDefault(""); addPropertyMaker("id", m); - // foi:ptr, used for accessibility - m = new StringProperty.Maker(PR_X_PTR); - m.setInherited(false); - m.setDefault(""); - addPropertyMaker("foi:ptr", m); - // fox:alt-text, used for accessibility m = new StringProperty.Maker(PR_X_ALT_TEXT); m.setInherited(false); -- 1.6.4.2