diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2009-10-15 10:47:34 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2009-10-15 10:47:34 +0000 |
commit | a3960ce47f877ae7c9d767dc3804be1bc4ffae24 (patch) | |
tree | 4e56f9a018213cd7fdeb8f98c933bef26445e002 | |
parent | 928e650d8c781448ca2c18cb74908592dcadf0bb (diff) | |
download | xmlgraphics-fop-a3960ce47f877ae7c9d767dc3804be1bc4ffae24.tar.gz xmlgraphics-fop-a3960ce47f877ae7c9d767dc3804be1bc4ffae24.zip |
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.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@825461 13f79535-47bb-0310-9956-ffa450edef68
5 files changed, 141 insertions, 145 deletions
diff --git a/src/java/org/apache/fop/accessibility/ParsedStructureTree.java b/src/java/org/apache/fop/accessibility/ParsedStructureTree.java index 3aa95b627..646496252 100644 --- a/src/java/org/apache/fop/accessibility/ParsedStructureTree.java +++ b/src/java/org/apache/fop/accessibility/ParsedStructureTree.java @@ -82,7 +82,7 @@ public class ParsedStructureTree implements StructureTree { 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 */ } diff --git a/src/java/org/apache/fop/accessibility/SimpleStructureTree.java b/src/java/org/apache/fop/accessibility/SimpleStructureTree.java index e67757207..c009b7b30 100644 --- a/src/java/org/apache/fop/accessibility/SimpleStructureTree.java +++ b/src/java/org/apache/fop/accessibility/SimpleStructureTree.java @@ -21,17 +21,11 @@ package org.apache.fop.accessibility; 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 @@ final class SimpleStructureTree implements StructureTree { 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} */ diff --git a/src/java/org/apache/fop/accessibility/addPtr.xsl b/src/java/org/apache/fop/accessibility/addPtr.xsl index 35645906a..b3984d426 100644 --- a/src/java/org/apache/fop/accessibility/addPtr.xsl +++ b/src/java/org/apache/fop/accessibility/addPtr.xsl @@ -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: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:external-graphic|fo:instream-foreign-object"> <xsl:call-template name="addPtr"/> </xsl:template> - <xsl:template match="fo:inline|fo:wrapper|fo:basic-link|fo:character"> + + <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:instream-foreign-object|fo:external-graphic"> + + <!-- 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:page-number|fo:page-number-citation|fo:page-number-citation-last"> + + <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:footnote|fo:footnote-body"> + + <!-- 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:marker"> + + <!-- Dynamic Effects: Link and Multi Formatting Objects --> + <xsl:template match="fo:basic-link"> <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> + + <!-- Out-of-Line Formatting Objects --> + <xsl:template match="fo:float|fo:footnote|fo:footnote-body"> + <xsl:call-template name="addPtr"/> </xsl:template> + + <!-- 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> diff --git a/src/java/org/apache/fop/accessibility/reduceFOTree.xsl b/src/java/org/apache/fop/accessibility/reduceFOTree.xsl index 84c500639..8e9bcfc13 100644 --- a/src/java/org/apache/fop/accessibility/reduceFOTree.xsl +++ b/src/java/org/apache/fop/accessibility/reduceFOTree.xsl @@ -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 "/> - - <xsl:template match="svg:svg | svg | fo:inline-container | fo:float | fo:bidi-override"/> - + 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:stylesheet> diff --git a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java index e1f1fae68..2313431f0 100644 --- a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java @@ -26,6 +26,8 @@ import java.util.Map; 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 @@ class PDFLogicalStructureHandler { 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 @@ class PDFLogicalStructureHandler { 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 { |