xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vhenneb...@apache.org
Subject svn commit: r1205935 [1/3] - in /xmlgraphics/fop/branches/Temp_ImproveAccessibility: src/documentation/intermediate-format-ng/ src/java/org/apache/fop/accessibility/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/area/ src/java/org/apache/fop/fo...
Date Thu, 24 Nov 2011 17:15:39 GMT
Author: vhennebert
Date: Thu Nov 24 17:15:28 2011
New Revision: 1205935

URL: http://svn.apache.org/viewvc?rev=1205935&view=rev
Log:
Removed the DOM representation of the structure tree.

The structure tree is now directly converted into corresponding PDF objects.
When going the IF route, the structure tree is stored in the form of SAX events that will be re-played when it's time to stream them into the output. This may still change.

* Extracted RFC3066 methods from XMLUtil into new LanguageTags class that can be re-used in a non-XML context.
* Dropped support for accessibility in the old Area Tree XML.
* Added support for the xml:lang property on fo:root, so that the global language can be set for the document without retrieving the language from the first page-sequence.
* Renamed StructureTreeBuilder into more appropriate StructureTreeEventHandler (same for applicable sub-classes)
* Renamed StructureTreeBuildingFOEventHandler into FO2StructureTreeConverter and added test case
* Added test cases for classes in the StructureTreeEventHandler hierarchy

Added:
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java   (with props)
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/FO2StructureTreeConverter.java
      - copied, changed from r1188205, xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuildingFOEventHandler.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java   (with props)
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java
      - copied, changed from r1187300, xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuilder.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFStructureTreeBuilder.java   (with props)
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java   (with props)
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/util/LanguageTags.java   (with props)
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/fop.xconf
      - copied unchanged from r1187300, xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/config-painter.xconf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/accessibility/
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/accessibility/FO2StructureTreeConverterTestCase.java   (with props)
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/accessibility/fo2StructureTree.xsl
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/fo/complete_document.fo
      - copied, changed from r1188205, xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.fo
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/render/intermediate/
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java   (with props)
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/render/intermediate/SAXEventRecorderTestCase.java   (with props)
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/util/LanguageTagsTestCase.java
      - copied, changed from r1187300, xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/util/XMLUtilTestCase.java
Removed:
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTree.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuilder.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuildingFOEventHandler.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/config-painter.xconf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/config-renderer.xconf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.fo
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/util/XMLUtilTestCase.java
Modified:
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/apps/FOUserAgent.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeHandler.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeModel.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeParser.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/RenderPagesModel.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/DelegatingFOEventHandler.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOElementMapping.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOEventHandler.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOTreeBuilder.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/pagination/Root.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFDocument.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFProfile.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFRoot.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFStructElem.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/AbstractRenderer.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/Renderer.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandler.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFConstants.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFDocumentHandler.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFParser.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFRenderer.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFSerializer.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFSerializerMaker.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/util/IFDocumentHandlerProxy.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/xml/XMLRenderer.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/util/XMLUtil.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/background-image_jpg_repeat.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/background-image_jpg_single.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/background-image_png_repeat.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/background-image_png_single.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/background-image_svg_repeat.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/background-image_svg_single.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/complete.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/image_jpg.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/image_png.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/image_svg.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/image_wmf.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/leader.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/links.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/role.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/role_non-standard.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/text_1.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/text_2.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/accessibility/pdf/text_font-embedding.pdf
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/StandardTestSuite.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/fo/DelegatingFOEventHandlerTestCase.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/fo/FODocumentParser.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/fo/extract-events.xsl
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/fo/properties/CommonAccessibilityHolderTestCase.java
    xmlgraphics/fop/branches/Temp_ImproveAccessibility/test/java/org/apache/fop/intermediate/IFParserTestCase.java

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd Thu Nov 24 17:15:28 2011
@@ -40,10 +40,17 @@
   </xs:element>
   <xs:element name="header">
     <xs:complexType>
-      <xs:choice minOccurs="0" maxOccurs="unbounded">
-        <!--xs:element ref="x:xmpmeta" xmlns:x="adobe:ns:meta/"/-->
-        <xs:any namespace="##other" processContents="lax"/>
-      </xs:choice>
+      <xs:sequence>
+        <xs:element name="locale" minOccurs="0" maxOccurs="1">
+          <xs:complexType>
+            <xs:attributeGroup ref="mf:foreignAtts"/>
+          </xs:complexType>
+        </xs:element>
+        <xs:choice minOccurs="0" maxOccurs="unbounded">
+          <!--xs:element ref="x:xmpmeta" xmlns:x="adobe:ns:meta/"/-->
+          <xs:any namespace="##other" processContents="lax"/>
+        </xs:choice>
+      </xs:sequence>
     </xs:complexType>
   </xs:element>
   <xs:element name="trailer">

Added: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java?rev=1205935&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java Thu Nov 24 17:15:28 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.util.Locale;
+
+import org.xml.sax.Attributes;
+
+/**
+ * This implementation ignores all structure tree events.
+ */
+public final class DummyStructureTreeEventHandler implements StructureTreeEventHandler {
+
+    /** The singleton instance of this class. */
+    public static final StructureTreeEventHandler INSTANCE = new DummyStructureTreeEventHandler();
+
+    private DummyStructureTreeEventHandler() { }
+
+    /** {@inheritDoc} */
+    public void startPageSequence(Locale locale) {
+    }
+
+    /** {@inheritDoc} */
+    public void startNode(String name, Attributes attributes) {
+    }
+
+    /** {@inheritDoc} */
+    public void endNode(String name) {
+    }
+
+    /** {@inheritDoc} */
+    public void endPageSequence() {
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Copied: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/FO2StructureTreeConverter.java (from r1188205, xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuildingFOEventHandler.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/FO2StructureTreeConverter.java?p2=xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/FO2StructureTreeConverter.java&p1=xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuildingFOEventHandler.java&r1=1188205&r2=1205935&rev=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuildingFOEventHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/FO2StructureTreeConverter.java Thu Nov 24 17:15:28 2011
@@ -19,11 +19,7 @@
 
 package org.apache.fop.accessibility;
 
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
+import java.util.Locale;
 
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
@@ -63,34 +59,32 @@ import org.apache.fop.fo.flow.table.Tabl
 import org.apache.fop.fo.flow.table.TableRow;
 import org.apache.fop.fo.pagination.Flow;
 import org.apache.fop.fo.pagination.PageSequence;
+import org.apache.fop.fo.pagination.Root;
 import org.apache.fop.fo.pagination.StaticContent;
 import org.apache.fop.fo.properties.CommonAccessibilityHolder;
 import org.apache.fop.util.XMLUtil;
 
 /**
- * A class that builds the document's structure tree.
+ * Allows to create the structure tree of an FO document, by converting FO
+ * events into appropriate structure tree events.
  */
-public class StructureTreeBuildingFOEventHandler extends DelegatingFOEventHandler {
+public class FO2StructureTreeConverter extends DelegatingFOEventHandler {
 
     private int idCounter;
 
-    private final StructureTree structureTree;
+    /** Delegates to either {@link #foToStructureTreeEventAdapter} or {@link #eventSwallower}. */
+    private FOEventHandler converter;
 
-    private TransformerHandler structureTreeDOMBuilder;
-
-    private DOMResult result;
-
-    /** Delegates to either {@link #actualStructureTreeBuilder} or {@link #eventSwallower}. */
-    private FOEventHandler structureTreeBuilder;
-
-    private FOEventHandler actualStructureTreeBuilder;
+    private final FOEventHandler foToStructureTreeEventAdapter;
 
     /** The descendants of some elements like fo:leader must be ignored. */
     private final FOEventHandler eventSwallower;
 
-    private final class StructureTreeBuilder extends FOEventHandler {
+    private final StructureTreeEventHandler structureTreeEventHandler;
+
+    private final class FOToStructureTreeEventAdapter extends FOEventHandler {
 
-        public StructureTreeBuilder(FOUserAgent foUserAgent) {
+        public FOToStructureTreeEventAdapter(FOUserAgent foUserAgent) {
             super(foUserAgent);
         }
 
@@ -104,33 +98,20 @@ public class StructureTreeBuildingFOEven
 
         @Override
         public void startPageSequence(PageSequence pageSeq) {
-            SAXTransformerFactory transformerFactory =
-                    (SAXTransformerFactory) TransformerFactory.newInstance();
-            try {
-                structureTreeDOMBuilder = transformerFactory.newTransformerHandler();
-            } catch (TransformerConfigurationException e) {
-                throw new RuntimeException(e);
+            Locale locale = null;
+            if (pageSeq.getLanguage() != null) {
+                if (pageSeq.getCountry() != null) {
+                    locale = new Locale(pageSeq.getLanguage(), pageSeq.getCountry());
+                } else {
+                    locale = new Locale(pageSeq.getLanguage());
+                }
             }
-            result = new DOMResult();
-            structureTreeDOMBuilder.setResult(result);
-            try {
-                structureTreeDOMBuilder.startDocument();
-            } catch (SAXException e) {
-                throw new RuntimeException(e);
-            }
-            startElement(pageSeq);
+            structureTreeEventHandler.startPageSequence(locale);
         }
 
         @Override
         public void endPageSequence(PageSequence pageSeq) {
-            endElement(pageSeq);
-            try {
-                structureTreeDOMBuilder.endDocument();
-            } catch (SAXException e) {
-                throw new RuntimeException(e);
-            }
-            structureTree.addPageSequenceStructure(
-                    result.getNode().getFirstChild().getChildNodes());
+            structureTreeEventHandler.endPageSequence();
         }
 
         @Override
@@ -381,6 +362,7 @@ public class StructureTreeBuildingFOEven
             endElement(c);
         }
 
+
         private void startElement(FONode node) {
             startElement(node, new AttributesImpl());
         }
@@ -409,13 +391,7 @@ public class StructureTreeBuildingFOEven
             if (node instanceof CommonAccessibilityHolder) {
                 addRole((CommonAccessibilityHolder) node, attributes);
             }
-            try {
-                structureTreeDOMBuilder.startElement(node.getNamespaceURI(), localName,
-                        node.getNormalNamespacePrefix() + ":" + localName,
-                        attributes);
-            } catch (SAXException e) {
-                throw new RuntimeException(e);
-            }
+            structureTreeEventHandler.startNode(localName, attributes);
         }
 
         private void addNoNamespaceAttribute(AttributesImpl attributes, String name, String value) {
@@ -438,12 +414,7 @@ public class StructureTreeBuildingFOEven
 
         private void endElement(FONode node) {
             String localName = node.getLocalName();
-            try {
-                structureTreeDOMBuilder.endElement(node.getNamespaceURI(), localName,
-                        node.getNormalNamespacePrefix() + ":" + localName);
-            } catch (SAXException e) {
-                throw new RuntimeException(e);
-            }
+            structureTreeEventHandler.endNode(localName);
         }
 
     }
@@ -451,389 +422,401 @@ public class StructureTreeBuildingFOEven
     /**
      * Creates a new instance.
      *
-     * @param structureTree the object that will hold the structure tree
+     * @param structureTreeEventHandler the object that will hold the structure tree
      * @param delegate the FO event handler that must be wrapped by this instance
      */
-    public StructureTreeBuildingFOEventHandler(StructureTree structureTree,
+    public FO2StructureTreeConverter(StructureTreeEventHandler structureTreeEventHandler,
             FOEventHandler delegate) {
         super(delegate);
-        this.structureTree = structureTree;
-        this.actualStructureTreeBuilder = new StructureTreeBuilder(foUserAgent);
-        this.structureTreeBuilder = actualStructureTreeBuilder;
+        this.structureTreeEventHandler = structureTreeEventHandler;
+        this.foToStructureTreeEventAdapter = new FOToStructureTreeEventAdapter(foUserAgent);
+        this.converter = foToStructureTreeEventAdapter;
         this.eventSwallower = new FOEventHandler(foUserAgent) { };
     }
 
     @Override
     public void startDocument() throws SAXException {
-        structureTreeBuilder.startDocument();
+        converter.startDocument();
         super.startDocument();
     }
 
     @Override
     public void endDocument() throws SAXException {
-        structureTreeBuilder.endDocument();
+        converter.endDocument();
         super.endDocument();
     }
 
     @Override
+    public void startRoot(Root root) {
+       converter.startRoot(root);
+       super.startRoot(root);
+    }
+
+    @Override
+    public void endRoot(Root root) {
+        converter.endRoot(root);
+        super.endRoot(root);
+    }
+
+    @Override
     public void startPageSequence(PageSequence pageSeq) {
-        structureTreeBuilder.startPageSequence(pageSeq);
+        converter.startPageSequence(pageSeq);
         super.startPageSequence(pageSeq);
     }
 
     @Override
     public void endPageSequence(PageSequence pageSeq) {
-        structureTreeBuilder.endPageSequence(pageSeq);
+        converter.endPageSequence(pageSeq);
         super.endPageSequence(pageSeq);
     }
 
     @Override
     public void startPageNumber(PageNumber pagenum) {
-        structureTreeBuilder.startPageNumber(pagenum);
+        converter.startPageNumber(pagenum);
         super.startPageNumber(pagenum);
     }
 
     @Override
     public void endPageNumber(PageNumber pagenum) {
-        structureTreeBuilder.endPageNumber(pagenum);
+        converter.endPageNumber(pagenum);
         super.endPageNumber(pagenum);
     }
 
     @Override
     public void startPageNumberCitation(PageNumberCitation pageCite) {
-        structureTreeBuilder.startPageNumberCitation(pageCite);
+        converter.startPageNumberCitation(pageCite);
         super.startPageNumberCitation(pageCite);
     }
 
     @Override
     public void endPageNumberCitation(PageNumberCitation pageCite) {
-        structureTreeBuilder.endPageNumberCitation(pageCite);
+        converter.endPageNumberCitation(pageCite);
         super.endPageNumberCitation(pageCite);
     }
 
     @Override
     public void startPageNumberCitationLast(PageNumberCitationLast pageLast) {
-        structureTreeBuilder.startPageNumberCitationLast(pageLast);
+        converter.startPageNumberCitationLast(pageLast);
         super.startPageNumberCitationLast(pageLast);
     }
 
     @Override
     public void endPageNumberCitationLast(PageNumberCitationLast pageLast) {
-        structureTreeBuilder.endPageNumberCitationLast(pageLast);
+        converter.endPageNumberCitationLast(pageLast);
         super.endPageNumberCitationLast(pageLast);
     }
 
     @Override
     public void startFlow(Flow fl) {
-        structureTreeBuilder.startFlow(fl);
+        converter.startFlow(fl);
         super.startFlow(fl);
     }
 
     @Override
     public void endFlow(Flow fl) {
-        structureTreeBuilder.endFlow(fl);
+        converter.endFlow(fl);
         super.endFlow(fl);
     }
 
     @Override
     public void startBlock(Block bl) {
-        structureTreeBuilder.startBlock(bl);
+        converter.startBlock(bl);
         super.startBlock(bl);
     }
 
     @Override
     public void endBlock(Block bl) {
-        structureTreeBuilder.endBlock(bl);
+        converter.endBlock(bl);
         super.endBlock(bl);
     }
 
     @Override
     public void startBlockContainer(BlockContainer blc) {
-        structureTreeBuilder.startBlockContainer(blc);
+        converter.startBlockContainer(blc);
         super.startBlockContainer(blc);
     }
 
     @Override
     public void endBlockContainer(BlockContainer blc) {
-        structureTreeBuilder.endBlockContainer(blc);
+        converter.endBlockContainer(blc);
         super.endBlockContainer(blc);
     }
 
     @Override
     public void startInline(Inline inl) {
-        structureTreeBuilder.startInline(inl);
+        converter.startInline(inl);
         super.startInline(inl);
     }
 
     @Override
     public void endInline(Inline inl) {
-        structureTreeBuilder.endInline(inl);
+        converter.endInline(inl);
         super.endInline(inl);
     }
 
     @Override
     public void startTable(Table tbl) {
-        structureTreeBuilder.startTable(tbl);
+        converter.startTable(tbl);
         super.startTable(tbl);
     }
 
     @Override
     public void endTable(Table tbl) {
-        structureTreeBuilder.endTable(tbl);
+        converter.endTable(tbl);
         super.endTable(tbl);
     }
 
     @Override
     public void startColumn(TableColumn tc) {
-        structureTreeBuilder.startColumn(tc);
+        converter.startColumn(tc);
         super.startColumn(tc);
     }
 
     @Override
     public void endColumn(TableColumn tc) {
-        structureTreeBuilder.endColumn(tc);
+        converter.endColumn(tc);
         super.endColumn(tc);
     }
 
     @Override
     public void startHeader(TableHeader header) {
-        structureTreeBuilder.startHeader(header);
+        converter.startHeader(header);
         super.startHeader(header);
     }
 
     @Override
     public void endHeader(TableHeader header) {
-        structureTreeBuilder.endHeader(header);
+        converter.endHeader(header);
         super.endHeader(header);
     }
 
     @Override
     public void startFooter(TableFooter footer) {
-        structureTreeBuilder.startFooter(footer);
+        converter.startFooter(footer);
         super.startFooter(footer);
     }
 
     @Override
     public void endFooter(TableFooter footer) {
-        structureTreeBuilder.endFooter(footer);
+        converter.endFooter(footer);
         super.endFooter(footer);
     }
 
     @Override
     public void startBody(TableBody body) {
-        structureTreeBuilder.startBody(body);
+        converter.startBody(body);
         super.startBody(body);
     }
 
     @Override
     public void endBody(TableBody body) {
-        structureTreeBuilder.endBody(body);
+        converter.endBody(body);
         super.endBody(body);
     }
 
     @Override
     public void startRow(TableRow tr) {
-        structureTreeBuilder.startRow(tr);
+        converter.startRow(tr);
         super.startRow(tr);
     }
 
     @Override
     public void endRow(TableRow tr) {
-        structureTreeBuilder.endRow(tr);
+        converter.endRow(tr);
         super.endRow(tr);
     }
 
     @Override
     public void startCell(TableCell tc) {
-        structureTreeBuilder.startCell(tc);
+        converter.startCell(tc);
         super.startCell(tc);
     }
 
     @Override
     public void endCell(TableCell tc) {
-        structureTreeBuilder.endCell(tc);
+        converter.endCell(tc);
         super.endCell(tc);
     }
 
     @Override
     public void startList(ListBlock lb) {
-        structureTreeBuilder.startList(lb);
+        converter.startList(lb);
         super.startList(lb);
     }
 
     @Override
     public void endList(ListBlock lb) {
-        structureTreeBuilder.endList(lb);
+        converter.endList(lb);
         super.endList(lb);
     }
 
     @Override
     public void startListItem(ListItem li) {
-        structureTreeBuilder.startListItem(li);
+        converter.startListItem(li);
         super.startListItem(li);
     }
 
     @Override
     public void endListItem(ListItem li) {
-        structureTreeBuilder.endListItem(li);
+        converter.endListItem(li);
         super.endListItem(li);
     }
 
     @Override
     public void startListLabel(ListItemLabel listItemLabel) {
-        structureTreeBuilder.startListLabel(listItemLabel);
+        converter.startListLabel(listItemLabel);
         super.startListLabel(listItemLabel);
     }
 
     @Override
     public void endListLabel(ListItemLabel listItemLabel) {
-        structureTreeBuilder.endListLabel(listItemLabel);
+        converter.endListLabel(listItemLabel);
         super.endListLabel(listItemLabel);
     }
 
     @Override
     public void startListBody(ListItemBody listItemBody) {
-        structureTreeBuilder.startListBody(listItemBody);
+        converter.startListBody(listItemBody);
         super.startListBody(listItemBody);
     }
 
     @Override
     public void endListBody(ListItemBody listItemBody) {
-        structureTreeBuilder.endListBody(listItemBody);
+        converter.endListBody(listItemBody);
         super.endListBody(listItemBody);
     }
 
     @Override
     public void startStatic(StaticContent staticContent) {
-        structureTreeBuilder.startStatic(staticContent);
+        converter.startStatic(staticContent);
         super.startStatic(staticContent);
     }
 
     @Override
     public void endStatic(StaticContent statisContent) {
-        structureTreeBuilder.endStatic(statisContent);
+        converter.endStatic(statisContent);
         super.endStatic(statisContent);
     }
 
     @Override
     public void startMarkup() {
-        structureTreeBuilder.startMarkup();
+        converter.startMarkup();
         super.startMarkup();
     }
 
     @Override
     public void endMarkup() {
-        structureTreeBuilder.endMarkup();
+        converter.endMarkup();
         super.endMarkup();
     }
 
     @Override
     public void startLink(BasicLink basicLink) {
-        structureTreeBuilder.startLink(basicLink);
+        converter.startLink(basicLink);
         super.startLink(basicLink);
     }
 
     @Override
     public void endLink(BasicLink basicLink) {
-        structureTreeBuilder.endLink(basicLink);
+        converter.endLink(basicLink);
         super.endLink(basicLink);
     }
 
     @Override
     public void image(ExternalGraphic eg) {
-        structureTreeBuilder.image(eg);
+        converter.image(eg);
         super.image(eg);
     }
 
     @Override
     public void pageRef() {
-        structureTreeBuilder.pageRef();
+        converter.pageRef();
         super.pageRef();
     }
 
     @Override
     public void startInstreamForeignObject(InstreamForeignObject ifo) {
-        structureTreeBuilder.startInstreamForeignObject(ifo);
+        converter.startInstreamForeignObject(ifo);
         super.startInstreamForeignObject(ifo);
     }
 
     @Override
     public void endInstreamForeignObject(InstreamForeignObject ifo) {
-        structureTreeBuilder.endInstreamForeignObject(ifo);
+        converter.endInstreamForeignObject(ifo);
         super.endInstreamForeignObject(ifo);
     }
 
     @Override
     public void startFootnote(Footnote footnote) {
-        structureTreeBuilder.startFootnote(footnote);
+        converter.startFootnote(footnote);
         super.startFootnote(footnote);
     }
 
     @Override
     public void endFootnote(Footnote footnote) {
-        structureTreeBuilder.endFootnote(footnote);
+        converter.endFootnote(footnote);
         super.endFootnote(footnote);
     }
 
     @Override
     public void startFootnoteBody(FootnoteBody body) {
-        structureTreeBuilder.startFootnoteBody(body);
+        converter.startFootnoteBody(body);
         super.startFootnoteBody(body);
     }
 
     @Override
     public void endFootnoteBody(FootnoteBody body) {
-        structureTreeBuilder.endFootnoteBody(body);
+        converter.endFootnoteBody(body);
         super.endFootnoteBody(body);
     }
 
     @Override
     public void startLeader(Leader l) {
-        structureTreeBuilder = eventSwallower;
-        structureTreeBuilder.startLeader(l);
+        converter = eventSwallower;
+        converter.startLeader(l);
         super.startLeader(l);
     }
 
     @Override
     public void endLeader(Leader l) {
-        structureTreeBuilder.endLeader(l);
-        structureTreeBuilder = actualStructureTreeBuilder;
+        converter.endLeader(l);
+        converter = foToStructureTreeEventAdapter;
         super.endLeader(l);
     }
 
     @Override
     public void startWrapper(Wrapper wrapper) {
-        structureTreeBuilder.startWrapper(wrapper);
+        converter.startWrapper(wrapper);
         super.startWrapper(wrapper);
     }
 
     @Override
     public void endWrapper(Wrapper wrapper) {
-        structureTreeBuilder.endWrapper(wrapper);
+        converter.endWrapper(wrapper);
         super.endWrapper(wrapper);
     }
 
     @Override
     public void character(Character c) {
-        structureTreeBuilder.character(c);
+        converter.character(c);
         super.character(c);
     }
 
     @Override
     public void characters(char[] data, int start, int length) {
-        structureTreeBuilder.characters(data, start, length);
+        converter.characters(data, start, length);
         super.characters(data, start, length);
     }
 
     @Override
     public void startExternalDocument(ExternalDocument document) {
-        structureTreeBuilder.startExternalDocument(document);
+        converter.startExternalDocument(document);
         super.startExternalDocument(document);
     }
 
     @Override
     public void endExternalDocument(ExternalDocument document) {
-        structureTreeBuilder.endExternalDocument(document);
+        converter.endExternalDocument(document);
         super.endExternalDocument(document);
     }
 

Added: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java?rev=1205935&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java (added)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java Thu Nov 24 17:15:28 2011
@@ -0,0 +1,104 @@
+/*
+ * 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.util.Locale;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.fop.fo.FOElementMapping;
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
+import org.apache.fop.fo.extensions.InternalElementMapping;
+import org.apache.fop.render.intermediate.IFConstants;
+
+/**
+ * Converts structure tree events to SAX events.
+ */
+public final class StructureTree2SAXEventAdapter implements StructureTreeEventHandler {
+
+    private final ContentHandler contentHandler;
+
+    private StructureTree2SAXEventAdapter(ContentHandler currentContentHandler) {
+        this.contentHandler = currentContentHandler;
+    }
+
+    /**
+     * Factory method that creates a new instance.
+     * @param contentHandler The handler that receives SAX events
+     */
+    public static StructureTreeEventHandler newInstance(ContentHandler contentHandler) {
+        return new StructureTree2SAXEventAdapter(contentHandler);
+    }
+
+    /** {@inheritDoc} */
+    public void startPageSequence(Locale locale) {
+        try {
+
+            contentHandler.startPrefixMapping(
+                    InternalElementMapping.STANDARD_PREFIX, InternalElementMapping.URI);
+            contentHandler.startPrefixMapping(
+                    ExtensionElementMapping.STANDARD_PREFIX, ExtensionElementMapping.URI);
+            contentHandler.startElement(IFConstants.NAMESPACE,
+                    IFConstants.EL_STRUCTURE_TREE, IFConstants.EL_STRUCTURE_TREE,
+                    new AttributesImpl());
+        } catch (SAXException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void endPageSequence() {
+        try {
+            contentHandler.endElement(IFConstants.NAMESPACE, IFConstants.EL_STRUCTURE_TREE,
+                    IFConstants.EL_STRUCTURE_TREE);
+            contentHandler.endPrefixMapping(
+                    ExtensionElementMapping.STANDARD_PREFIX);
+            contentHandler.endPrefixMapping(
+                    InternalElementMapping.STANDARD_PREFIX);
+
+        } catch (SAXException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void startNode(String name, Attributes attributes) {
+        try {
+            contentHandler.startElement(FOElementMapping.URI, name,
+                    FOElementMapping.STANDARD_PREFIX + ":" + name,
+                    attributes);
+        } catch (SAXException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void endNode(String name) {
+        try {
+            contentHandler.endElement(FOElementMapping.URI, name,
+                    FOElementMapping.STANDARD_PREFIX + ":" + name);
+        } catch (SAXException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Copied: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java (from r1187300, xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuilder.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java?p2=xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java&p1=xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuilder.java&r1=1187300&r2=1205935&rev=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeBuilder.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java Thu Nov 24 17:15:28 2011
@@ -19,77 +19,38 @@
 
 package org.apache.fop.accessibility;
 
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
+import java.util.Locale;
 
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-import org.apache.fop.util.DelegatingContentHandler;
+import org.xml.sax.Attributes;
 
 /**
- * Helper class that re-builds a structure tree from what is stored in an
- * intermediate XML file (IF XML or Area Tree XML).
+ * Receive notifications relating to the structure tree of an FO document.
+ * A structure tree is a reduced version of the document's FO tree, containing only the logical
+ * structure that is used by accessible output formats.
  */
-public final class StructureTreeBuilder {
-
-    private final SAXTransformerFactory factory;
-
-    private final StructureTree structureTree = new StructureTree();
+public interface StructureTreeEventHandler {
 
     /**
-     * Creates a new instance.
-     *
-     * @param factory a factory internally used to build the structures of page
-     * sequences
+     * Starts a page sequence structure tree node.
+     * @param locale The locale of the page sequence
      */
-    public StructureTreeBuilder(SAXTransformerFactory factory) {
-        this.factory = factory;
-    }
+    void startPageSequence(Locale locale);
 
     /**
-     * Returns the structure tree that will result from the parsing.
-     *
-     * @return the structure tree built by this object
+     * Starts a structure tree node.
+     * @param name The name of the structure tree node
+     * @param attributes Map of node properties
      */
-    public StructureTree getStructureTree() {
-        return structureTree;
-    }
+    void startNode(String name, Attributes attributes);
 
     /**
-     * Returns a ContenHandler for parsing the structure of a new page sequence.
-     * It is assumed that page sequences are being parsed in the document order.
-     *
-     * @return a handler for parsing the &lt;structure-tree&gt; or
-     * &lt;structureTree&gt; element and its descendants
-     * @throws SAXException if there is an error when creating the handler
+     * Ends a structure tree node.
+     * @param name The name of the structure tree node
      */
-    public ContentHandler getHandlerForNextPageSequence() throws SAXException {
-        TransformerHandler structureTreeBuilder;
-        try {
-            structureTreeBuilder = factory.newTransformerHandler();
-        } catch (TransformerConfigurationException e) {
-            throw new SAXException(e);
-        }
-        final DOMResult domResult = new DOMResult();
-        structureTreeBuilder.setResult(domResult);
-        return new DelegatingContentHandler(structureTreeBuilder) {
-
-            public void characters(char[] ch, int start, int length) throws SAXException {
-                /*
-                 * There's no text node in the structure tree. This is just
-                 * whitespace => ignore
-                 */
-            }
-
-            public void endDocument() throws SAXException {
-                super.endDocument();
-                structureTree.addPageSequenceStructure(domResult.getNode().getFirstChild()
-                        .getChildNodes());
-            }
-        };
-    }
+    void endNode(String name);
 
+    /**
+     * Ends a page sequence structure tree node.
+     */
+    void endPageSequence();
 }

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/apps/FOUserAgent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/apps/FOUserAgent.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/apps/FOUserAgent.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/apps/FOUserAgent.java Thu Nov 24 17:15:28 2011
@@ -39,7 +39,8 @@ import org.apache.xmlgraphics.util.UnitC
 
 import org.apache.fop.Version;
 import org.apache.fop.accessibility.Accessibility;
-import org.apache.fop.accessibility.StructureTree;
+import org.apache.fop.accessibility.DummyStructureTreeEventHandler;
+import org.apache.fop.accessibility.StructureTreeEventHandler;
 import org.apache.fop.events.DefaultEventBroadcaster;
 import org.apache.fop.events.Event;
 import org.apache.fop.events.EventBroadcaster;
@@ -101,8 +102,7 @@ public class FOUserAgent {
     private boolean locatorEnabled = true; // true by default (for error messages).
     private boolean conserveMemoryPolicy = false;
     private EventBroadcaster eventBroadcaster = new FOPEventBroadcaster();
-
-    private StructureTree structureTree;
+    private StructureTreeEventHandler structureTreeEventHandler = DummyStructureTreeEventHandler.INSTANCE;
 
     /** Producer:  Metadata element for the system/software that produces
      * the document. (Some renderers can store this in the document.)
@@ -173,6 +173,9 @@ public class FOUserAgent {
      * @param documentHandler the document handler instance to use
      */
     public void setDocumentHandlerOverride(IFDocumentHandler documentHandler) {
+        if (isAccessibilityEnabled()) {
+            setStructureTreeEventHandler(documentHandler.getStructureTreeEventHandler());
+        }
         this.documentHandlerOverride = documentHandler;
 
     }
@@ -674,24 +677,23 @@ public class FOUserAgent {
     }
 
     /**
-     * Sets the document's structure tree, for use by accessible output formats.
+     * Sets the document's structure tree event handler, for use by accessible
+     * output formats.
      *
-     * @param structureTree a simplified version of the FO tree, retaining only
-     * its logical structure
+     * @param structureTreeEventHandler The structure tree event handler to set
      */
-    public void setStructureTree(StructureTree structureTree) {
-        this.structureTree = structureTree;
+    public void setStructureTreeEventHandler(StructureTreeEventHandler structureTreeEventHandler) {
+        this.structureTreeEventHandler = structureTreeEventHandler;
     }
 
     /**
-     * Returns the document's structure tree, for use by accessible output
-     * formats.
+     * Returns the document's structure tree event handler, for use by
+     * accessible output formats.
      *
-     * @return a simplified version of the FO tree, retaining only its logical
-     * structure
+     * @return The structure tree event handler
      */
-    public StructureTree getStructureTree() {
-        return this.structureTree;
+    public StructureTreeEventHandler getStructureTreeEventHandler() {
+        return this.structureTreeEventHandler;
     }
 }
 

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeHandler.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeHandler.java Thu Nov 24 17:15:28 2011
@@ -22,6 +22,7 @@ package org.apache.fop.area;
 // Java
 import java.io.OutputStream;
 import java.util.List;
+import java.util.Locale;
 
 import org.xml.sax.SAXException;
 
@@ -182,6 +183,14 @@ public class AreaTreeHandler extends FOE
         }
     }
 
+    @Override
+    public void startRoot(Root root) {
+        Locale locale = root.getLocale();
+        if (locale != null) {
+            model.setDocumentLocale(locale);
+        }
+    }
+
     /**
      * finish the previous pageSequence
      */

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeModel.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeModel.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeModel.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeModel.java Thu Nov 24 17:15:28 2011
@@ -21,6 +21,7 @@ package org.apache.fop.area;
 
 // Java
 import java.util.List;
+import java.util.Locale;
 
 import org.xml.sax.SAXException;
 
@@ -123,4 +124,11 @@ public class AreaTreeModel {
     public PageViewport getPage(int seq, int count) {
         return pageSequenceList.get(seq - 1).getPage(count);
     }
+
+    /**
+     *
+     * @param locale The locale of the document
+     */
+    public void setDocumentLocale(Locale locale) {
+    }
 }

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeParser.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeParser.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/AreaTreeParser.java Thu Nov 24 17:15:28 2011
@@ -58,8 +58,6 @@ import org.apache.xmlgraphics.image.load
 import org.apache.xmlgraphics.util.QName;
 
 import org.apache.fop.ResourceEventProducer;
-import org.apache.fop.accessibility.AccessibilityEventProducer;
-import org.apache.fop.accessibility.StructureTreeBuilder;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.Trait.Background;
 import org.apache.fop.area.Trait.InternalLink;
@@ -69,11 +67,11 @@ import org.apache.fop.area.inline.Image;
 import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.InlineBlockParent;
 import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.Leader;
 import org.apache.fop.area.inline.Space;
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.WordArea;
 import org.apache.fop.fo.ElementMappingRegistry;
 import org.apache.fop.fo.expr.PropertyException;
@@ -86,7 +84,6 @@ import org.apache.fop.util.ContentHandle
 import org.apache.fop.util.ContentHandlerFactoryRegistry;
 import org.apache.fop.util.ConversionUtils;
 import org.apache.fop.util.DefaultErrorListener;
-import org.apache.fop.util.DelegatingContentHandler;
 import org.apache.fop.util.XMLConstants;
 import org.apache.fop.util.XMLUtil;
 
@@ -166,27 +163,8 @@ public class AreaTreeParser {
         private DOMImplementation domImplementation;
         private Locator locator;
 
-
-        private StructureTreeBuilder structureTreeBuilder;
-
-        private ContentHandler structureTreeBuilderWrapper;
-
         private Attributes pageSequenceAttributes;
 
-        private final class StructureTreeBuilderWrapper extends DelegatingContentHandler {
-
-            private StructureTreeBuilderWrapper()
-                    throws SAXException {
-                super(structureTreeBuilder.getHandlerForNextPageSequence());
-            }
-
-            public void endDocument() throws SAXException {
-                super.endDocument();
-                startAreaTreeElement("pageSequence", pageSequenceAttributes);
-                pageSequenceAttributes = null;
-            }
-        }
-
         public Handler(AreaTreeModel treeModel, FOUserAgent userAgent,
                 ElementMappingRegistry elementMappingRegistry) {
             this.treeModel = treeModel;
@@ -223,11 +201,6 @@ public class AreaTreeParser {
             makers.put("bookmarkTree", new BookmarkTreeMaker());
             makers.put("bookmark", new BookmarkMaker());
             makers.put("destination", new DestinationMaker());
-
-            if (userAgent.isAccessibilityEnabled()) {
-                structureTreeBuilder = new StructureTreeBuilder(tFactory);
-                userAgent.setStructureTree(structureTreeBuilder.getStructureTree());
-            }
         }
 
         private Area findAreaType(Class clazz) {
@@ -308,32 +281,15 @@ public class AreaTreeParser {
             } else {
                 boolean handled = true;
                 if ("".equals(uri)) {
-                    if (localName.equals("pageSequence") && userAgent.isAccessibilityEnabled()) {
-                        structureTreeBuilderWrapper = new StructureTreeBuilderWrapper();
-                        pageSequenceAttributes = new AttributesImpl(attributes);
-                    } else if (localName.equals("structureTree")) {
-                        if (userAgent.isAccessibilityEnabled()) {
-                            delegate = structureTreeBuilderWrapper;
-                        } else {
-                            /* Delegate to a handler that does nothing */
-                            delegate = new DefaultHandler();
-                        }
+                    if (localName.equals("structureTree")) {
+
+                        /* The area tree parser no longer supports the structure tree. */
+                        delegate = new DefaultHandler();
+
                         delegateStack.push(qName);
                         delegate.startDocument();
                         delegate.startElement(uri, localName, qName, attributes);
                     } else {
-                        if (pageSequenceAttributes != null) {
-                            /*
-                             * This means that no structure-element tag was
-                             * found in the XML, otherwise a
-                             * StructureTreeBuilderWrapper object would have
-                             * been created, which would have reset the
-                             * pageSequenceAttributes field.
-                             */
-                            AccessibilityEventProducer.Provider
-                                    .get(userAgent.getEventBroadcaster())
-                                    .noStructureTreeInXML(this);
-                        }
                         handled = startAreaTreeElement(localName, attributes);
                     }
                 } else {

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/RenderPagesModel.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/RenderPagesModel.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/RenderPagesModel.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/area/RenderPagesModel.java Thu Nov 24 17:15:28 2011
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 
 import org.xml.sax.SAXException;
 
@@ -83,6 +84,11 @@ public class RenderPagesModel extends Ar
         }
     }
 
+    @Override
+    public void setDocumentLocale(Locale locale) {
+        renderer.setDocumentLocale(locale);
+    }
+
     /** {@inheritDoc} */
     @Override
     public void startPageSequence(PageSequence pageSequence) {

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/DelegatingFOEventHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/DelegatingFOEventHandler.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/DelegatingFOEventHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/DelegatingFOEventHandler.java Thu Nov 24 17:15:28 2011
@@ -50,6 +50,7 @@ import org.apache.fop.fo.flow.table.Tabl
 import org.apache.fop.fo.flow.table.TableRow;
 import org.apache.fop.fo.pagination.Flow;
 import org.apache.fop.fo.pagination.PageSequence;
+import org.apache.fop.fo.pagination.Root;
 import org.apache.fop.fo.pagination.StaticContent;
 import org.apache.fop.fonts.FontInfo;
 
@@ -91,6 +92,16 @@ public abstract class DelegatingFOEventH
     }
 
     @Override
+    public void startRoot(Root root) {
+        delegate.startRoot(root);
+    }
+
+    @Override
+    public void endRoot(Root root) {
+        delegate.endRoot(root);
+    }
+
+    @Override
     public void startPageSequence(PageSequence pageSeq) {
         delegate.startPageSequence(pageSeq);
     }

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOElementMapping.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOElementMapping.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOElementMapping.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOElementMapping.java Thu Nov 24 17:15:28 2011
@@ -32,6 +32,9 @@ public class FOElementMapping extends El
     /** The XSL-FO namespace URI */
     public static final String URI = "http://www.w3.org/1999/XSL/Format";
 
+     /** Standard prefix */
+    public static final String STANDARD_PREFIX = "fo";
+
     /**
      * Basic constructor; inititializes the namespace URI for the fo: namespace
      */
@@ -141,7 +144,7 @@ public class FOElementMapping extends El
 
     /** {@inheritDoc} */
     public String getStandardPrefix() {
-        return "fo";
+        return STANDARD_PREFIX;
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOEventHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOEventHandler.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOEventHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOEventHandler.java Thu Nov 24 17:15:28 2011
@@ -50,6 +50,7 @@ import org.apache.fop.fo.flow.table.Tabl
 import org.apache.fop.fo.flow.table.TableRow;
 import org.apache.fop.fo.pagination.Flow;
 import org.apache.fop.fo.pagination.PageSequence;
+import org.apache.fop.fo.pagination.Root;
 import org.apache.fop.fo.pagination.StaticContent;
 import org.apache.fop.fonts.FontEventAdapter;
 import org.apache.fop.fonts.FontInfo;
@@ -117,6 +118,12 @@ public abstract class FOEventHandler {
     public void endDocument() throws SAXException {
     }
 
+    public void startRoot(Root root) {
+    }
+
+    public void endRoot(Root root) {
+    }
+
     /**
      *
      * @param pageSeq PageSequence that is starting.

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOTreeBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOTreeBuilder.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOTreeBuilder.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/FOTreeBuilder.java Thu Nov 24 17:15:28 2011
@@ -33,8 +33,7 @@ import org.apache.commons.logging.LogFac
 
 import org.apache.xmlgraphics.util.QName;
 
-import org.apache.fop.accessibility.StructureTree;
-import org.apache.fop.accessibility.StructureTreeBuildingFOEventHandler;
+import org.apache.fop.accessibility.FO2StructureTreeConverter;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FormattingResults;
@@ -107,9 +106,8 @@ public class FOTreeBuilder extends Defau
         foEventHandler = foUserAgent.getRendererFactory().createFOEventHandler(
                 foUserAgent, outputFormat, stream);
         if (userAgent.isAccessibilityEnabled()) {
-            StructureTree structureTree = new StructureTree();
-            foEventHandler = new StructureTreeBuildingFOEventHandler(structureTree, foEventHandler);
-            userAgent.setStructureTree(structureTree);
+            foEventHandler = new FO2StructureTreeConverter(
+                    foUserAgent.getStructureTreeEventHandler(), foEventHandler);
         }
         builderContext = new FOTreeBuilderContext();
         builderContext.setPropertyListMaker(new PropertyListMaker() {

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/pagination/Root.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/pagination/Root.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/pagination/Root.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/fo/pagination/Root.java Thu Nov 24 17:15:28 2011
@@ -21,6 +21,7 @@ package org.apache.fop.fo.pagination;
 
 // java
 import java.util.List;
+import java.util.Locale;
 
 import org.xml.sax.Locator;
 
@@ -52,6 +53,7 @@ public class Root extends FObj implement
     private BookmarkTree bookmarkTree = null;
     private List<Destination> destinationList;
     private List<PageSequence> pageSequences;
+    private Locale locale;
 
     // temporary until above list populated
     private boolean pageSequenceFound = false;
@@ -88,6 +90,24 @@ public class Root extends FObj implement
         super.bind(pList);
         commonAccessibility = CommonAccessibility.getInstance(pList);
         mediaUsage = pList.get(PR_MEDIA_USAGE).getEnum();
+        String language = pList.get(PR_LANGUAGE).getString();
+        String country = pList.get(PR_COUNTRY).getString();
+        if (isLocalePropertySet(language)) {
+            if (isLocalePropertySet(country)) {
+                locale = new Locale(language, country);
+            } else {
+                locale = new Locale(language);
+            }
+        }
+    }
+
+    private boolean isLocalePropertySet(String property) {
+        return property != null && !property.equals("none");
+    }
+
+     /** {@inheritDoc} */
+    protected void startOfNode() throws FOPException {
+        foEventHandler.startRoot(this);
     }
 
     /** {@inheritDoc} */
@@ -96,6 +116,7 @@ public class Root extends FObj implement
             missingChildElementError("(layout-master-set, declarations?, "
                 + "bookmark-tree?, (page-sequence|fox:external-document)+)");
         }
+        foEventHandler.endRoot(this);
     }
 
     /**
@@ -343,4 +364,9 @@ public class Root extends FObj implement
         return FO_ROOT;
     }
 
+
+    public Locale getLocale() {
+        return locale;
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFDocument.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFDocument.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFDocument.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFDocument.java Thu Nov 24 17:15:28 2011
@@ -354,25 +354,6 @@ public class PDFDocument {
     }
 
     /**
-     * Makes sure a Lang entry has been set on the document catalog, setting it
-     * to a default value if necessary. When accessibility is enabled the
-     * language must be specified for any text element in the document.
-     */
-    public void enforceLanguageOnRoot() {
-        if (root.getLanguage() == null) {
-            String fallbackLanguage;
-            if (getProfile().getPDFAMode().isPDFA1LevelA()) {
-                //According to Annex B of ISO-19005-1:2005(E), section B.2
-                fallbackLanguage = "x-unknown";
-            } else {
-                //No language has been set on the first page-sequence, so fall back to "en".
-                fallbackLanguage = "en";
-            }
-            root.setLanguage(fallbackLanguage);
-        }
-    }
-
-    /**
      * Get the {@link PDFInfo} object for this document.
      *
      * @return the {@link PDFInfo} object

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFProfile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFProfile.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFProfile.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFProfile.java Thu Nov 24 17:15:28 2011
@@ -133,8 +133,12 @@ public class PDFProfile {
 
     //---------=== Info and validation methods ===---------
 
+    private String format(String pattern, Object[] args) {
+        return MessageFormat.format(pattern, args);
+    }
+
     private String format(String pattern, Object arg) {
-        return MessageFormat.format(pattern, new Object[] {arg});
+        return format(pattern, new Object[] {arg});
     }
 
     /** Checks if encryption is allowed. */

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFRoot.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFRoot.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFRoot.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFRoot.java Thu Nov 24 17:15:28 2011
@@ -21,6 +21,9 @@ package org.apache.fop.pdf;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Locale;
+
+import org.apache.fop.util.LanguageTags;
 
 /**
  * Class representing a Root (/Catalog) object.
@@ -69,6 +72,7 @@ public class PDFRoot extends PDFDictiona
         setObjectNumber(objnum);
         put("Type", new PDFName("Catalog"));
         setRootPages(pages);
+        setLanguage("x-unknown");
     }
 
     /** {@inheritDoc} */
@@ -254,10 +258,14 @@ public class PDFRoot extends PDFDictiona
      * Sets the language identifier of the document.
      * @param lang the language identifier of the document.
      */
-    public void setLanguage(String lang) {
-        if (lang == null) {
-            throw new NullPointerException("lang must not be null");
+    public void setLanguage(Locale locale) {
+        if (locale == null) {
+            throw new NullPointerException("locale must not be null");
         }
+        setLanguage(LanguageTags.toLanguageTag(locale));
+    }
+
+    private void setLanguage(String lang) {
         put("Lang", lang);
     }
 

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFStructElem.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFStructElem.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFStructElem.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/pdf/PDFStructElem.java Thu Nov 24 17:15:28 2011
@@ -21,7 +21,7 @@ package org.apache.fop.pdf;
 
 import java.util.Locale;
 
-import org.apache.fop.util.XMLUtil;
+import org.apache.fop.util.LanguageTags;
 
 /**
  * Class representing a PDF Structure Element.
@@ -145,7 +145,7 @@ public class PDFStructElem extends PDFDi
      * @param language a value for the Lang entry
      */
     public void setLanguage(Locale language) {
-        setLanguage(XMLUtil.toRFC3066(language));
+        setLanguage(LanguageTags.toLanguageTag(language));
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/AbstractRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/AbstractRenderer.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/AbstractRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/AbstractRenderer.java Thu Nov 24 17:15:28 2011
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.Set;
 
 import org.w3c.dom.Document;
@@ -61,11 +62,11 @@ import org.apache.fop.area.inline.Image;
 import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.InlineBlockParent;
 import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.Leader;
 import org.apache.fop.area.inline.Space;
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.WordArea;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fonts.FontInfo;
@@ -152,6 +153,10 @@ public abstract class AbstractRenderer
         return false;
     }
 
+    /** {@inheritDoc} */
+    public void setDocumentLocale(Locale locale) {
+    }
+
     /**
      * {@inheritDoc}
      */

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/Renderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/Renderer.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/Renderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/Renderer.java Thu Nov 24 17:15:28 2011
@@ -22,6 +22,7 @@ package org.apache.fop.render;
 // Java
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Locale;
 
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
@@ -116,6 +117,12 @@ public interface Renderer {
     boolean supportsOutOfOrder();
 
     /**
+     *
+     * @param locale Locale of the language
+     */
+    void setDocumentLocale(Locale locale);
+
+    /**
      * Tells the renderer to process an item not explicitly placed on the
      * document (e.g., PDF bookmarks).  Note - not all renderers will process
      * all off-document items.

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandler.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandler.java Thu Nov 24 17:15:28 2011
@@ -19,6 +19,13 @@
 
 package org.apache.fop.render.intermediate;
 
+import java.util.Locale;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.fop.accessibility.DummyStructureTreeEventHandler;
+import org.apache.fop.accessibility.StructureTreeEventHandler;
 import org.apache.fop.apps.FOUserAgent;
 
 /**
@@ -53,6 +60,11 @@ public abstract class AbstractIFDocument
     }
 
     /** {@inheritDoc} */
+    public StructureTreeEventHandler getStructureTreeEventHandler() {
+        return DummyStructureTreeEventHandler.INSTANCE;
+    }
+
+    /** {@inheritDoc} */
     public IFDocumentNavigationHandler getDocumentNavigationHandler() {
         return null; //By default, this is not supported
     }
@@ -66,6 +78,10 @@ public abstract class AbstractIFDocument
     }
 
     /** {@inheritDoc} */
+    public void setDocumentLocale(Locale locale) {
+    }
+
+    /** {@inheritDoc} */
     public void startDocumentHeader() throws IFException {
         //nop
     }
@@ -104,5 +120,4 @@ public abstract class AbstractIFDocument
     public void endPageTrailer() throws IFException {
         //nop
     }
-
 }

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFConstants.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFConstants.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFConstants.java Thu Nov 24 17:15:28 2011
@@ -39,6 +39,7 @@ public interface IFConstants extends XML
     String EL_HEADER = "header";
     /** element name trailer */
     String EL_TRAILER = "trailer";
+    String EL_LOCALE = "locale";
     /** element name page-sequence */
     String EL_PAGE_SEQUENCE = "page-sequence";
     /** element name page */

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFDocumentHandler.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFDocumentHandler.java Thu Nov 24 17:15:28 2011
@@ -20,9 +20,11 @@
 package org.apache.fop.render.intermediate;
 
 import java.awt.Dimension;
+import java.util.Locale;
 
 import javax.xml.transform.Result;
 
+import org.apache.fop.accessibility.StructureTreeEventHandler;
 import org.apache.fop.fonts.FontInfo;
 
 /**
@@ -32,6 +34,7 @@ import org.apache.fop.fonts.FontInfo;
  * <p>
  * <pre>
  * startDocument()
+ *   [setDocumentLocale()]
  *   startDocumentHeader()
  *   [handleExtension()]*
  *   endDocumentHeader()
@@ -118,6 +121,11 @@ public interface IFDocumentHandler {
     IFDocumentHandlerConfigurator getConfigurator();
 
     /**
+     * @return the structure tree builder
+     */
+    StructureTreeEventHandler getStructureTreeEventHandler();
+
+    /**
      * Returns a document navigation handler if this feature is supported.
      * @return the document navigation handler or null if not supported
      */
@@ -152,6 +160,11 @@ public interface IFDocumentHandler {
     void endDocument() throws IFException;
 
     /**
+    * @param locale Locale of the document.
+    */
+    void setDocumentLocale(Locale locale);
+
+    /**
      * Indicates the start of the document header. This method is called right after the
      * {@link #startDocument()} method. Extensions sent to this painter between
      * {@link #startDocumentHeader()} and {@link #endDocumentHeader()} apply to the document as
@@ -261,7 +274,4 @@ public interface IFDocumentHandler {
      * @throws IFException if an error occurs while handling this event
      */
     void handleExtensionObject(Object extension) throws IFException;
-
-    //TODO Prototype the following:
-    //ContentHandler handleExtension() throws Exception
 }

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFParser.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFParser.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFParser.java Thu Nov 24 17:15:28 2011
@@ -25,6 +25,7 @@ import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
@@ -48,7 +49,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.xmlgraphics.util.QName;
 
 import org.apache.fop.accessibility.AccessibilityEventProducer;
-import org.apache.fop.accessibility.StructureTreeBuilder;
+import org.apache.fop.accessibility.StructureTreeEventHandler;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.fo.ElementMappingRegistry;
@@ -62,7 +63,7 @@ import org.apache.fop.util.ContentHandle
 import org.apache.fop.util.ContentHandlerFactoryRegistry;
 import org.apache.fop.util.DOMBuilderContentHandlerFactory;
 import org.apache.fop.util.DefaultErrorListener;
-import org.apache.fop.util.DelegatingContentHandler;
+import org.apache.fop.util.LanguageTags;
 import org.apache.fop.util.XMLUtil;
 
 /**
@@ -153,24 +154,40 @@ public class IFParser implements IFConst
 
         private ContentHandler navParser;
 
-        private StructureTreeBuilder structureTreeBuilder;
-
-        private ContentHandler structureTreeBuilderWrapper;
+        private ContentHandler structureTreeHandler;
 
         private Attributes pageSequenceAttributes;
 
-        private final class StructureTreeBuilderWrapper extends DelegatingContentHandler {
+        private final class StructureTreeHandler extends DefaultHandler {
 
-            private StructureTreeBuilderWrapper()
-                    throws SAXException {
-                super(structureTreeBuilder.getHandlerForNextPageSequence());
+            private final StructureTreeEventHandler structureTreeEventHandler;
+
+            private StructureTreeHandler(StructureTreeEventHandler structureTreeEventHandler,
+                    Locale pageSequenceLanguage) throws SAXException {
+                this.structureTreeEventHandler = structureTreeEventHandler;
+                structureTreeEventHandler.startPageSequence(pageSequenceLanguage);
             }
 
             public void endDocument() throws SAXException {
-                super.endDocument();
                 startIFElement(EL_PAGE_SEQUENCE, pageSequenceAttributes);
                 pageSequenceAttributes = null;
             }
+
+            @Override
+            public void startElement(String uri, String localName, String qName,
+                    Attributes attributes) throws SAXException {
+                if (!"structure-tree".equals(localName)) {
+                    structureTreeEventHandler.startNode(localName, attributes);
+                }
+            }
+
+            @Override
+            public void endElement(String uri, String localName, String arqNameg2)
+                    throws SAXException {
+                if (!"structure-tree".equals(localName)) {
+                    structureTreeEventHandler.endNode(localName);
+                }
+            }
         }
 
         public Handler(IFDocumentHandler documentHandler, FOUserAgent userAgent,
@@ -180,6 +197,7 @@ public class IFParser implements IFConst
             this.elementMappingRegistry = elementMappingRegistry;
             elementHandlers.put(EL_DOCUMENT, new DocumentHandler());
             elementHandlers.put(EL_HEADER, new DocumentHeaderHandler());
+            elementHandlers.put(EL_LOCALE, new LocaleHandler());
             elementHandlers.put(EL_TRAILER, new DocumentTrailerHandler());
             elementHandlers.put(EL_PAGE_SEQUENCE, new PageSequenceHandler());
             elementHandlers.put(EL_PAGE, new PageHandler());
@@ -197,11 +215,6 @@ public class IFParser implements IFConst
             elementHandlers.put(EL_LINE, new LineHandler());
             elementHandlers.put(EL_BORDER_RECT, new BorderRectHandler());
             elementHandlers.put(EL_IMAGE, new ImageHandler());
-
-            if (userAgent.isAccessibilityEnabled()) {
-                structureTreeBuilder = new StructureTreeBuilder(tFactory);
-                userAgent.setStructureTree(structureTreeBuilder.getStructureTree());
-            }
         }
 
         private void establishForeignAttributes(Map<QName, String> foreignAttributes) {
@@ -231,10 +244,13 @@ public class IFParser implements IFConst
                 if (NAMESPACE.equals(uri)) {
                     if (localName.equals(EL_PAGE_SEQUENCE) && userAgent.isAccessibilityEnabled()) {
                         pageSequenceAttributes = new AttributesImpl(attributes);
-                        structureTreeBuilderWrapper = new StructureTreeBuilderWrapper();
+                        Locale language = getLanguage(attributes);
+                        structureTreeHandler = new StructureTreeHandler(
+                                userAgent.getStructureTreeEventHandler(), language);
+
                     } else if (localName.equals(EL_STRUCTURE_TREE)) {
                         if (userAgent.isAccessibilityEnabled()) {
-                            delegate = structureTreeBuilderWrapper;
+                            delegate = structureTreeHandler;
                         } else {
                             /* Delegate to a handler that does nothing */
                             delegate = new DefaultHandler();
@@ -299,6 +315,11 @@ public class IFParser implements IFConst
             }
         }
 
+        private static Locale getLanguage(Attributes attributes) {
+            String xmllang = attributes.getValue(XML_NAMESPACE, "lang");
+            return (xmllang == null) ? null : LanguageTags.toLocale(xmllang);
+        }
+
         private boolean startIFElement(String localName, Attributes attributes)
                 throws SAXException {
             lastAttributes = new AttributesImpl(attributes);
@@ -413,6 +434,12 @@ public class IFParser implements IFConst
 
         }
 
+        private class LocaleHandler extends AbstractElementHandler {
+            public void startElement(Attributes attributes) throws IFException {
+                documentHandler.setDocumentLocale(getLanguage(attributes));
+            }
+        }
+
         private class DocumentTrailerHandler extends AbstractElementHandler {
 
             public void startElement(Attributes attributes) throws IFException {
@@ -429,10 +456,9 @@ public class IFParser implements IFConst
 
             public void startElement(Attributes attributes) throws IFException {
                 String id = attributes.getValue("id");
-                String xmllang = attributes.getValue(XML_NAMESPACE, "lang");
-                if (xmllang != null) {
-                    documentHandler.getContext().setLanguage(
-                            XMLUtil.convertRFC3066ToLocale(xmllang));
+                Locale language = getLanguage(attributes);
+                if (language != null) {
+                    documentHandler.getContext().setLanguage(language);
                 }
                 Map<QName, String> foreignAttributes = getForeignAttributes(lastAttributes);
                 establishForeignAttributes(foreignAttributes);

Modified: xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFRenderer.java?rev=1205935&r1=1205934&r2=1205935&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ImproveAccessibility/src/java/org/apache/fop/render/intermediate/IFRenderer.java Thu Nov 24 17:15:28 2011
@@ -51,6 +51,7 @@ import org.apache.xmlgraphics.xmp.schema
 
 import org.apache.fop.Version;
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.AreaTreeObject;
@@ -70,10 +71,10 @@ import org.apache.fop.area.inline.Foreig
 import org.apache.fop.area.inline.Image;
 import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.Leader;
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.WordArea;
 import org.apache.fop.datatypes.URISpecification;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
@@ -227,7 +228,11 @@ public class IFRenderer extends Abstract
      */
     protected IFDocumentHandler createDefaultDocumentHandler() {
         IFSerializer serializer = new IFSerializer();
-        serializer.setContext(new IFContext(getUserAgent()));
+        FOUserAgent userAgent = getUserAgent();
+        serializer.setContext(new IFContext(userAgent));
+        if (userAgent.isAccessibilityEnabled()) {
+            userAgent.setStructureTreeEventHandler(serializer.getStructureTreeEventHandler());
+        }
         return serializer;
     }
 
@@ -294,6 +299,11 @@ public class IFRenderer extends Abstract
         log.debug("Rendering finished.");
     }
 
+    @Override
+    public void setDocumentLocale(Locale locale) {
+        documentHandler.setDocumentLocale(locale);
+    }
+
     /** {@inheritDoc} */
     public void processOffDocumentItem(OffDocumentItem odi) {
         if (odi instanceof DestinationData) {



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


Mime
View raw message