Author: vhennebert
Date: Thu Oct 15 10:47:34 2009
New Revision: 825461

URL: http://svn.apache.org/viewvc?rev=825461&view=rev
Log:
Made the structure tree processing chain more robust by removing any assumption 
about prefix names for namespaces.
Avoid warnings issued by reduceFOTree.xsl when FO file contains foreign 
elements (like MathML).
SimpleStructureTree: replaced XPath query with simple DOM method calls.
Cleaned up, simplified and re-organized reduceFOTree and addPtr stylesheets.

Modified:
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/ParsedStructureTree.java
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/SimpleStructureTree.java
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/addPtr.xsl
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/reduceFOTree.xsl
    
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/ParsedStructureTree.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/ParsedStructureTree.java?rev=825461&r1=825460&r2=825461&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/ParsedStructureTree.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/ParsedStructureTree.java
 Thu Oct 15 10:47:34 2009
@@ -82,7 +82,7 @@
 
             public void characters(char[] ch, int start, int length) throws 
SAXException {
                 /*
-                 * There's not text node in the structure tree. This is just
+                 * There's no text node in the structure tree. This is just
                  * whitespace => ignore
                  */
             }

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/SimpleStructureTree.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/SimpleStructureTree.java?rev=825461&r1=825460&r2=825461&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/SimpleStructureTree.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/SimpleStructureTree.java
 Thu Oct 15 10:47:34 2009
@@ -21,17 +21,11 @@
 
 import java.io.StringWriter;
 import java.io.Writer;
-import java.util.Iterator;
 
-import javax.xml.namespace.NamespaceContext;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
 
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -45,57 +39,16 @@
 
     private final Node reducedFOTree;
 
-    private static class NamespaceContextImpl implements NamespaceContext {
-
-        private String uri;
-        private String prefix;
-
-        public NamespaceContextImpl() {
-        }
-
-        public NamespaceContextImpl(String prefix, String uri) {
-            this.uri = uri;
-            this.prefix = prefix;
-        }
-
-        public String getNamespaceURI(String prefix) {
-            return uri;
-        }
-
-        public void setNamespaceURI(String uri) {
-            this.uri = uri;
-        }
-
-        public String getPrefix(String uri) {
-            return prefix;
-        }
-
-        public void setPrefix(String prefix) {
-            this.prefix = prefix;
-        }
-
-        public Iterator getPrefixes(String uri) {
-            return null;
-        }
-    }
-
     SimpleStructureTree(Node reducedFOTree) {
         this.reducedFOTree = reducedFOTree;
     }
 
     /** {...@inheritdoc} */
     public NodeList getPageSequence(int number) {
-        XPath xpath = XPathFactory.newInstance().newXPath();
-        NamespaceContext namespaceContext = new NamespaceContextImpl("fo",
-                "http://www.w3.org/1999/XSL/Format";);
-        xpath.setNamespaceContext(namespaceContext);
-        String xpathExpr = "/fo:root/fo:page-sequence[" + 
Integer.toString(number) + "]/*";
-
-        try {
-            return (NodeList) xpath.evaluate(xpathExpr, reducedFOTree, 
XPathConstants.NODESET);
-        } catch (XPathExpressionException e) {
-            throw new RuntimeException(e);
-        }
+        Node pageSequence = 
reducedFOTree.getFirstChild().getChildNodes().item(number - 1);
+        assert pageSequence.getNodeType() == Node.ELEMENT_NODE
+                && pageSequence.getLocalName().equals("page-sequence");
+        return pageSequence.getChildNodes();
     }
 
     /** {...@inheritdoc} */

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/addPtr.xsl
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/addPtr.xsl?rev=825461&r1=825460&r2=825461&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/addPtr.xsl
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/addPtr.xsl
 Thu Oct 15 10:47:34 2009
@@ -20,42 +20,69 @@
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:fo="http://www.w3.org/1999/XSL/Format";
   xmlns:foi="http://xmlgraphics.apache.org/fop/internal";>
+
+  <xsl:template name="addPtr">
+    <xsl:copy>
+      <xsl:apply-templates select="@*"/>
+      <xsl:attribute name="foi:ptr">
+        <xsl:value-of select="generate-id()"/>
+      </xsl:attribute>
+      <xsl:apply-templates/>
+    </xsl:copy>
+  </xsl:template>
+
+  <!-- Block-level Formatting Objects -->
   <xsl:template match="fo:block|fo:block-container">
     <xsl:call-template name="addPtr"/>
   </xsl:template>
-  <xsl:template 
match="fo:list-block|fo:list-item|fo:list-item-label|fo:list-item-body">
+
+  <!-- Inline-level Formatting Objects -->
+  <xsl:template match="fo:character|fo:inline|fo:inline-container">
+    <xsl:call-template name="addPtr"/>
+  </xsl:template>
+
+  <xsl:template match="fo:external-graphic|fo:instream-foreign-object">
     <xsl:call-template name="addPtr"/>
   </xsl:template>
-  <xsl:template 
match="fo:table-and-caption|fo:table-caption|fo:table|fo:table-body|fo:table-header|fo:table-footer|fo:table-row|fo:table-cell">
+
+  <xsl:template 
match="fo:page-number|fo:page-number-citation|fo:page-number-citation-last">
     <xsl:call-template name="addPtr"/>
   </xsl:template>
-  <xsl:template match="fo:inline|fo:wrapper|fo:basic-link|fo:character">
+
+  <!-- Formatting Objects for Tables -->
+  <xsl:template match="fo:table-and-caption|fo:table-caption|fo:table">
     <xsl:call-template name="addPtr"/>
   </xsl:template>
-  <xsl:template match="fo:instream-foreign-object|fo:external-graphic">
+
+  <xsl:template 
match="fo:table-header|fo:table-footer|fo:table-body|fo:table-row|fo:table-cell">
     <xsl:call-template name="addPtr"/>
   </xsl:template>
-  <xsl:template 
match="fo:page-number|fo:page-number-citation|fo:page-number-citation-last">
+
+  <!-- Formatting Objects for Lists -->
+  <xsl:template 
match="fo:list-block|fo:list-item|fo:list-item-label|fo:list-item-body">
     <xsl:call-template name="addPtr"/>
   </xsl:template>
-  <xsl:template match="fo:footnote|fo:footnote-body">
+
+  <!-- Dynamic Effects: Link and Multi Formatting Objects -->
+  <xsl:template match="fo:basic-link">
     <xsl:call-template name="addPtr"/>
   </xsl:template>
-  <xsl:template match="fo:marker">
+
+  <!-- Out-of-Line Formatting Objects -->
+  <xsl:template match="fo:float|fo:footnote|fo:footnote-body">
     <xsl:call-template name="addPtr"/>
   </xsl:template>
-  <xsl:template name="addPtr">
-    <xsl:element name="{name()}" namespace="{namespace-uri()}">
-      <xsl:apply-templates select="@*"/>
-      <xsl:attribute name="foi:ptr">
-        <xsl:value-of select="generate-id()"/>
-      </xsl:attribute>
-      <xsl:apply-templates/>
-    </xsl:element>
+
+  <!-- Other Formatting Objects -->
+  <xsl:template match="fo:wrapper|fo:marker">
+    <xsl:call-template name="addPtr"/>
   </xsl:template>
+
+
   <xsl:template match="@*|node()">
     <xsl:copy>
       <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
   </xsl:template>
+
 </xsl:stylesheet>

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/reduceFOTree.xsl
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/reduceFOTree.xsl?rev=825461&r1=825460&r2=825461&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/reduceFOTree.xsl
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/accessibility/reduceFOTree.xsl
 Thu Oct 15 10:47:34 2009
@@ -16,71 +16,85 @@
   limitations under the License.
 -->
 <!-- $Id$ -->
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:fo="http://www.w3.org/1999/XSL/Format";
-  xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"; 
-  xmlns:svg="http://www.w3.org/2000/svg";
-  xmlns:foi="http://xmlgraphics.apache.org/fop/internal"; 
-  version="1.0">
-    <xsl:output method="xml" indent="no"/>
-    
-    <xsl:template match="*">
-        <xsl:element name="{name()}">
-            <xsl:copy-of select="@foi:ptr"/>
-            <xsl:apply-templates/>
-        </xsl:element>
-    </xsl:template>
-    
-    <xsl:template match="@master-reference|@flow-name"></xsl:template>
-    
-    <xsl:template match="fo:block">
-        <xsl:element name="{name()}">
-            <xsl:copy-of select="@foi:ptr"/>
-            <xsl:apply-templates/>
-        </xsl:element>
-    </xsl:template>
-    
-    <xsl:template 
match="fo:inline|fo:wrapper|fo:page-number|fo:page-number-citation|fo:page-number-citation-last">
-        <xsl:element name="{name()}">
-            <xsl:copy-of select="@foi:ptr"/>
-            <xsl:apply-templates/>
-        </xsl:element>
-    </xsl:template>
-    
-    <xsl:template 
match="fo:table-cell|fo:table|fo:table-body|fo:table-footer|fo:table-row|fo:table-header">
-        <xsl:element name="{name()}">
-            <xsl:copy-of select="@foi:ptr"/>
-            <xsl:apply-templates/>
-        </xsl:element>
-    </xsl:template>
-    
-    <xsl:template 
match="fo:list-block|fo:list-item|fo:list-item-label|fo:list-item-body">
-        <xsl:element name="{name()}">
-            <xsl:copy-of select="@foi:ptr"/>
-            <xsl:apply-templates/>
-        </xsl:element>
-    </xsl:template>
-    
-    <xsl:template 
match="fo:basic-link|fo:block-container|fo:character|fo:instream-foreign-object|fo:marker">
-        <xsl:element name="{name()}">
-            <xsl:copy-of select="@foi:ptr"/>
-            <xsl:apply-templates/>
-        </xsl:element>
-    </xsl:template>
-    
-    <xsl:template match="fo:external-graphic|fo:instream-foreign-object">
-        <xsl:element name="{name()}">
-            <xsl:copy-of select="@fox:alt-text|@foi:ptr"/>
-            <xsl:apply-templates/>
-        </xsl:element>
-    </xsl:template>
-    
-    <!-- the following nodes are being ignored/filtered -->
-    
-    <xsl:template match="text()"/>
-    
-    <xsl:template match="fo:layout-master-set | comment() | 
processing-instruction() | fo:simple-page-master | fo:table-column | fo:leader 
| fo:retrieve-marker "/>
+  xmlns:fox="http://xmlgraphics.apache.org/fop/extensions";
+  xmlns:foi="http://xmlgraphics.apache.org/fop/internal";>
+
+  <xsl:output method="xml" indent="no"/>
+
+  <xsl:template name="copy">
+    <xsl:copy>
+      <xsl:apply-templates select="@*|node()"/>
+    </xsl:copy>
+  </xsl:template>
+
+  <!-- Declarations and Pagination and Layout Formatting Objects -->
+  <xsl:template match="fo:root|fo:page-sequence|fo:static-content|fo:flow">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <!-- Block-level Formatting Objects -->
+  <xsl:template match="fo:block|fo:block-container">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <!-- Inline-level Formatting Objects -->
+  <xsl:template match="fo:character|fo:inline|fo:inline-container">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <xsl:template match="fo:external-graphic|fo:instream-foreign-object">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <xsl:template 
match="fo:page-number|fo:page-number-citation|fo:page-number-citation-last">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <!-- Formatting Objects for Tables -->
+  <xsl:template match="fo:table-and-caption|fo:table-caption|fo:table">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <xsl:template 
match="fo:table-header|fo:table-footer|fo:table-body|fo:table-row|fo:table-cell">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <!-- Formatting Objects for Lists -->
+  <xsl:template 
match="fo:list-block|fo:list-item|fo:list-item-label|fo:list-item-body">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <!-- Dynamic Effects: Link and Multi Formatting Objects -->
+  <xsl:template match="fo:basic-link">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <!-- Out-of-Line Formatting Objects -->
+  <xsl:template match="fo:float|fo:footnote|fo:footnote-body">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+  <!-- Other Formatting Objects -->
+  <xsl:template match="fo:wrapper|fo:marker">
+    <xsl:call-template name="copy"/>
+  </xsl:template>
+
+
+  <!-- Discard descendants of fo:leader -->
+  <xsl:template match="fo:leader"/>
+      
+
+  <!-- Keep foi:ptr and fox:alt-text attributes, discard everything else -->
+  <xsl:template match="@foi:ptr|@fox:alt-text">
+    <xsl:copy-of select="."/>
+  </xsl:template>
+
+  <xsl:template match="@*"/>
+
+
+  <!-- Discard text -->
+  <xsl:template match="text()"/>
 
-    <xsl:template match="svg:svg | svg | fo:inline-container | fo:float | 
fo:bidi-override"/>
-    
 </xsl:stylesheet>

Modified: 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java?rev=825461&r1=825460&r2=825461&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
 (original)
+++ 
xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
 Thu Oct 15 10:47:34 2009
@@ -26,6 +26,8 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
+import org.apache.fop.fo.extensions.InternalElementMapping;
 import org.apache.fop.pdf.PDFArray;
 import org.apache.fop.pdf.PDFDictionary;
 import org.apache.fop.pdf.PDFDocument;
@@ -129,22 +131,21 @@
 
         for (int i = 0, n = structureTree.getLength(); i < n; i++) {
             Node node = structureTree.item(i);
-            if (node.getNodeName().equals("fo:flow")
-                    || node.getNodeName().equals("fo:static-content")) {
-                PDFStructElem structElemSect = 
pdfDoc.getFactory().makeStructureElement(
-                        
FOToPDFRoleMap.mapFormattingObject(node.getLocalName(), structElemPart),
-                        structElemPart);
-                structElemPart.addKid(structElemSect);
-                NodeList childNodes = node.getChildNodes();
-                for (int j = 0, m = childNodes.getLength(); j < m; j++) {
-                    processNode(childNodes.item(j), structElemSect, true);
-                }
+            assert node.getLocalName().equals("flow")
+                    || node.getLocalName().equals("static-content");
+            PDFStructElem structElemSect = 
pdfDoc.getFactory().makeStructureElement(
+                    FOToPDFRoleMap.mapFormattingObject(node.getLocalName(), 
structElemPart),
+                    structElemPart);
+            structElemPart.addKid(structElemSect);
+            NodeList childNodes = node.getChildNodes();
+            for (int j = 0, m = childNodes.getLength(); j < m; j++) {
+                processNode(childNodes.item(j), structElemSect, true);
             }
         }
     }
 
     private void processNode(Node node, PDFStructElem parent, boolean addKid) {
-        Node attr = node.getAttributes().getNamedItem("foi:ptr");
+        Node attr = 
node.getAttributes().getNamedItemNS(InternalElementMapping.URI, "ptr");
         assert attr != null;
         String ptr = attr.getNodeValue();
         String nodeName = node.getLocalName();
@@ -157,7 +158,8 @@
             parent.addKid(structElem);
         }
         if (nodeName.equals("external-graphic") || 
nodeName.equals("instream-foreign-object")) {
-            Node altTextNode = 
node.getAttributes().getNamedItem("fox:alt-text");
+            Node altTextNode = node.getAttributes().getNamedItemNS(
+                    ExtensionElementMapping.URI, "alt-text");
             if (altTextNode != null) {
                 structElem.put("Alt", altTextNode.getNodeValue());
             } else {



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

Reply via email to