* Removed addPtr.xsl and reduceFOTree.xsl * Implemented Common Accessibility properties on objects that support them * Added a special implementation of FOEventHandler to build the structure tree * Added mockito library and its dependencies * Added mocks for some FO nodes and properties * Removed FOTreeUnitTester and converted it into a re-usable FODocumentParser class * Re-worked table FO test cases accordingly git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ImproveAccessibility@1188205 13f79535-47bb-0310-9956-ffa450edef68tags/fop-1_1rc1old
@@ -735,6 +735,7 @@ list of possible build targets. | |||
<include name="**/*.xml"/> | |||
<include name="**/*.fo"/> | |||
<include name="**/*.afp"/> | |||
<include name="**/*.xsl"/> | |||
</fileset> | |||
<fileset dir="${build.dir}/test-gensrc"> | |||
<include name="**/*.xml"/> |
@@ -0,0 +1,27 @@ | |||
BSD License | |||
Copyright (c) 2000-2006, www.hamcrest.org | |||
All rights reserved. | |||
Redistribution and use in source and binary forms, with or without | |||
modification, are permitted provided that the following conditions are met: | |||
Redistributions of source code must retain the above copyright notice, this list of | |||
conditions and the following disclaimer. Redistributions in binary form must reproduce | |||
the above copyright notice, this list of conditions and the following disclaimer in | |||
the documentation and/or other materials provided with the distribution. | |||
Neither the name of Hamcrest nor the names of its contributors may be used to endorse | |||
or promote products derived from this software without specific prior written | |||
permission. | |||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | |||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | |||
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | |||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY | |||
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | |||
DAMAGE. |
@@ -0,0 +1,21 @@ | |||
The MIT License | |||
Copyright (c) 2007 Mockito contributors | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
@@ -0,0 +1,11 @@ | |||
Mockito license - MIT. | |||
Libraries used: | |||
Cglib - Apache License 2.0 | |||
ASM - BSD license | |||
Mockito all distribution: | |||
Objenesis - MIT license | |||
Hamcrest - BSD license |
@@ -0,0 +1,18 @@ | |||
Copyright (c) 2003-2008, Objenesis Team and all contributors | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of | |||
this software and associated documentation files (the "Software"), to deal in | |||
the Software without restriction, including without limitation the rights to | |||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |||
the Software, and to permit persons to whom the Software is furnished to do so, | |||
subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -19,18 +19,6 @@ | |||
package org.apache.fop.accessibility; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Templates; | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerConfigurationException; | |||
import javax.xml.transform.sax.SAXTransformerFactory; | |||
import javax.xml.transform.sax.TransformerHandler; | |||
import javax.xml.transform.stream.StreamSource; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
/** | |||
* Helper class for FOP's accessibility features. | |||
@@ -40,48 +28,6 @@ public final class Accessibility { | |||
/** Constant string for the rendering options key to enable accessibility features. */ | |||
public static final String ACCESSIBILITY = "accessibility"; | |||
// TODO what if the default factory is not a SAXTransformerFactory? | |||
private static SAXTransformerFactory tfactory | |||
= (SAXTransformerFactory)SAXTransformerFactory.newInstance(); | |||
private static Templates addPtrTemplates; | |||
private static Templates reduceFOTreeTemplates; | |||
private Accessibility() { } | |||
/** | |||
* Decorates the given handler so the structure tree used for accessibility | |||
* features can be branched off the main content stream. | |||
* @param handler the handler to decorate | |||
* @param userAgent the user agent | |||
* @return the decorated handler | |||
* @throws FOPException if an error occurs setting up the decoration | |||
*/ | |||
public static DefaultHandler decorateDefaultHandler(DefaultHandler handler, | |||
FOUserAgent userAgent) throws FOPException { | |||
try { | |||
setupTemplates(); | |||
TransformerHandler addPtr = tfactory.newTransformerHandler(addPtrTemplates); | |||
Transformer reduceFOTree = reduceFOTreeTemplates.newTransformer(); | |||
return new AccessibilityPreprocessor(addPtr, reduceFOTree, userAgent, handler); | |||
} catch (TransformerConfigurationException e) { | |||
throw new FOPException(e); | |||
} | |||
} | |||
private static synchronized void setupTemplates() throws TransformerConfigurationException { | |||
if (addPtrTemplates == null) { | |||
addPtrTemplates = loadTemplates("addPtr.xsl"); | |||
} | |||
if (reduceFOTreeTemplates == null) { | |||
reduceFOTreeTemplates = loadTemplates("reduceFOTree.xsl"); | |||
} | |||
} | |||
private static Templates loadTemplates(String source) throws TransformerConfigurationException { | |||
Source src = new StreamSource(Accessibility.class.getResource(source).toExternalForm()); | |||
return tfactory.newTemplates(src); | |||
} | |||
} |
@@ -1,95 +0,0 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.accessibility; | |||
import java.io.ByteArrayInputStream; | |||
import java.io.InputStream; | |||
import javax.xml.parsers.SAXParser; | |||
import javax.xml.parsers.SAXParserFactory; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.dom.DOMResult; | |||
import javax.xml.transform.sax.TransformerHandler; | |||
import javax.xml.transform.stream.StreamResult; | |||
import javax.xml.transform.stream.StreamSource; | |||
import org.w3c.dom.NodeList; | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
import org.apache.commons.io.output.ByteArrayOutputStream; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.util.TransformerDefaultHandler; | |||
/** | |||
* This class prepares an XSL-FO document for accessibility. It adds a unique | |||
* identifier to every applicable FO, then creates the structure tree, before | |||
* handing the document over to the regular handler. | |||
*/ | |||
class AccessibilityPreprocessor extends TransformerDefaultHandler { | |||
private final ByteArrayOutputStream enrichedFOBuffer = new ByteArrayOutputStream(); | |||
private final Transformer reduceFOTree; | |||
private final FOUserAgent userAgent; | |||
private final DefaultHandler fopHandler; | |||
public AccessibilityPreprocessor(TransformerHandler addPtr, Transformer reduceFOTree, | |||
FOUserAgent userAgent, DefaultHandler fopHandler) { | |||
super(addPtr); | |||
this.reduceFOTree = reduceFOTree; | |||
this.userAgent = userAgent; | |||
this.fopHandler = fopHandler; | |||
getTransformerHandler().setResult(new StreamResult(enrichedFOBuffer)); | |||
} | |||
/** {@inheritDoc} */ | |||
public void endDocument() throws SAXException { | |||
super.endDocument(); | |||
// do the second transform to struct | |||
try { | |||
//TODO this must be optimized, no buffering (ex. SAX-based tee-proxy) | |||
byte[] enrichedFO = enrichedFOBuffer.toByteArray(); | |||
Source src = new StreamSource(new ByteArrayInputStream(enrichedFO)); | |||
DOMResult res = new DOMResult(); | |||
reduceFOTree.transform(src, res); | |||
StructureTree structureTree = new StructureTree(); | |||
NodeList pageSequences = res.getNode().getFirstChild().getChildNodes(); | |||
for (int i = 0; i < pageSequences.getLength(); i++) { | |||
structureTree.addPageSequenceStructure(pageSequences.item(i).getChildNodes()); | |||
} | |||
userAgent.setStructureTree(structureTree); | |||
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); | |||
saxParserFactory.setNamespaceAware(true); | |||
saxParserFactory.setValidating(false); | |||
SAXParser saxParser = saxParserFactory.newSAXParser(); | |||
InputStream in = new ByteArrayInputStream(enrichedFO); | |||
saxParser.parse(in, fopHandler); | |||
} catch (Exception e) { | |||
throw new SAXException(e); | |||
} | |||
} | |||
} |
@@ -44,7 +44,7 @@ public final class StructureTree { | |||
/** | |||
* Package-private default constructor. | |||
*/ | |||
StructureTree() { } | |||
public StructureTree() { } | |||
private static boolean flowOrStaticContentNodes(NodeList nodes) { | |||
for (int i = 0; i < nodes.getLength(); i++) { |
@@ -0,0 +1,840 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.accessibility; | |||
import javax.xml.transform.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 org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.AttributesImpl; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.fo.DelegatingFOEventHandler; | |||
import org.apache.fop.fo.FOEventHandler; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.extensions.ExtensionElementMapping; | |||
import org.apache.fop.fo.extensions.ExternalDocument; | |||
import org.apache.fop.fo.extensions.InternalElementMapping; | |||
import org.apache.fop.fo.flow.AbstractGraphics; | |||
import org.apache.fop.fo.flow.BasicLink; | |||
import org.apache.fop.fo.flow.Block; | |||
import org.apache.fop.fo.flow.BlockContainer; | |||
import org.apache.fop.fo.flow.Character; | |||
import org.apache.fop.fo.flow.ExternalGraphic; | |||
import org.apache.fop.fo.flow.Footnote; | |||
import org.apache.fop.fo.flow.FootnoteBody; | |||
import org.apache.fop.fo.flow.Inline; | |||
import org.apache.fop.fo.flow.InstreamForeignObject; | |||
import org.apache.fop.fo.flow.Leader; | |||
import org.apache.fop.fo.flow.ListBlock; | |||
import org.apache.fop.fo.flow.ListItem; | |||
import org.apache.fop.fo.flow.ListItemBody; | |||
import org.apache.fop.fo.flow.ListItemLabel; | |||
import org.apache.fop.fo.flow.PageNumber; | |||
import org.apache.fop.fo.flow.PageNumberCitation; | |||
import org.apache.fop.fo.flow.PageNumberCitationLast; | |||
import org.apache.fop.fo.flow.Wrapper; | |||
import org.apache.fop.fo.flow.table.Table; | |||
import org.apache.fop.fo.flow.table.TableBody; | |||
import org.apache.fop.fo.flow.table.TableCell; | |||
import org.apache.fop.fo.flow.table.TableColumn; | |||
import org.apache.fop.fo.flow.table.TableFooter; | |||
import org.apache.fop.fo.flow.table.TableHeader; | |||
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.StaticContent; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.util.XMLUtil; | |||
/** | |||
* A class that builds the document's structure tree. | |||
*/ | |||
public class StructureTreeBuildingFOEventHandler extends DelegatingFOEventHandler { | |||
private int idCounter; | |||
private final StructureTree structureTree; | |||
private TransformerHandler structureTreeDOMBuilder; | |||
private DOMResult result; | |||
/** Delegates to either {@link #actualStructureTreeBuilder} or {@link #eventSwallower}. */ | |||
private FOEventHandler structureTreeBuilder; | |||
private FOEventHandler actualStructureTreeBuilder; | |||
/** The descendants of some elements like fo:leader must be ignored. */ | |||
private final FOEventHandler eventSwallower; | |||
private final class StructureTreeBuilder extends FOEventHandler { | |||
public StructureTreeBuilder(FOUserAgent foUserAgent) { | |||
super(foUserAgent); | |||
} | |||
@Override | |||
public void startDocument() throws SAXException { | |||
} | |||
@Override | |||
public void endDocument() throws SAXException { | |||
} | |||
@Override | |||
public void startPageSequence(PageSequence pageSeq) { | |||
SAXTransformerFactory transformerFactory = | |||
(SAXTransformerFactory) TransformerFactory.newInstance(); | |||
try { | |||
structureTreeDOMBuilder = transformerFactory.newTransformerHandler(); | |||
} catch (TransformerConfigurationException e) { | |||
throw new RuntimeException(e); | |||
} | |||
result = new DOMResult(); | |||
structureTreeDOMBuilder.setResult(result); | |||
try { | |||
structureTreeDOMBuilder.startDocument(); | |||
} catch (SAXException e) { | |||
throw new RuntimeException(e); | |||
} | |||
startElement(pageSeq); | |||
} | |||
@Override | |||
public void endPageSequence(PageSequence pageSeq) { | |||
endElement(pageSeq); | |||
try { | |||
structureTreeDOMBuilder.endDocument(); | |||
} catch (SAXException e) { | |||
throw new RuntimeException(e); | |||
} | |||
structureTree.addPageSequenceStructure( | |||
result.getNode().getFirstChild().getChildNodes()); | |||
} | |||
@Override | |||
public void startPageNumber(PageNumber pagenum) { | |||
startElementWithID(pagenum); | |||
} | |||
@Override | |||
public void endPageNumber(PageNumber pagenum) { | |||
endElement(pagenum); | |||
} | |||
@Override | |||
public void startPageNumberCitation(PageNumberCitation pageCite) { | |||
startElementWithID(pageCite); | |||
} | |||
@Override | |||
public void endPageNumberCitation(PageNumberCitation pageCite) { | |||
endElement(pageCite); | |||
} | |||
@Override | |||
public void startPageNumberCitationLast(PageNumberCitationLast pageLast) { | |||
startElementWithID(pageLast); | |||
} | |||
@Override | |||
public void endPageNumberCitationLast(PageNumberCitationLast pageLast) { | |||
endElement(pageLast); | |||
} | |||
@Override | |||
public void startFlow(Flow fl) { | |||
startElement(fl); | |||
} | |||
@Override | |||
public void endFlow(Flow fl) { | |||
endElement(fl); | |||
} | |||
@Override | |||
public void startBlock(Block bl) { | |||
startElementWithID(bl); | |||
} | |||
@Override | |||
public void endBlock(Block bl) { | |||
endElement(bl); | |||
} | |||
@Override | |||
public void startBlockContainer(BlockContainer blc) { | |||
startElement(blc); | |||
} | |||
@Override | |||
public void endBlockContainer(BlockContainer blc) { | |||
endElement(blc); | |||
} | |||
@Override | |||
public void startInline(Inline inl) { | |||
startElementWithID(inl); | |||
} | |||
@Override | |||
public void endInline(Inline inl) { | |||
endElement(inl); | |||
} | |||
@Override | |||
public void startTable(Table tbl) { | |||
startElementWithID(tbl); | |||
} | |||
@Override | |||
public void endTable(Table tbl) { | |||
endElement(tbl); | |||
} | |||
@Override | |||
public void startHeader(TableHeader header) { | |||
startElementWithID(header); | |||
} | |||
@Override | |||
public void endHeader(TableHeader header) { | |||
endElement(header); | |||
} | |||
@Override | |||
public void startFooter(TableFooter footer) { | |||
startElementWithID(footer); | |||
} | |||
@Override | |||
public void endFooter(TableFooter footer) { | |||
endElement(footer); | |||
} | |||
@Override | |||
public void startBody(TableBody body) { | |||
startElementWithID(body); | |||
} | |||
@Override | |||
public void endBody(TableBody body) { | |||
endElement(body); | |||
} | |||
@Override | |||
public void startRow(TableRow tr) { | |||
startElementWithID(tr); | |||
} | |||
@Override | |||
public void endRow(TableRow tr) { | |||
endElement(tr); | |||
} | |||
@Override | |||
public void startCell(TableCell tc) { | |||
AttributesImpl attributes = new AttributesImpl(); | |||
int colSpan = tc.getNumberColumnsSpanned(); | |||
if (colSpan > 1) { | |||
addNoNamespaceAttribute(attributes, "number-columns-spanned", | |||
Integer.toString(colSpan)); | |||
} | |||
startElementWithID(tc, attributes); | |||
} | |||
@Override | |||
public void endCell(TableCell tc) { | |||
endElement(tc); | |||
} | |||
@Override | |||
public void startList(ListBlock lb) { | |||
startElement(lb); | |||
} | |||
@Override | |||
public void endList(ListBlock lb) { | |||
endElement(lb); | |||
} | |||
@Override | |||
public void startListItem(ListItem li) { | |||
startElement(li); | |||
} | |||
@Override | |||
public void endListItem(ListItem li) { | |||
endElement(li); | |||
} | |||
@Override | |||
public void startListLabel(ListItemLabel listItemLabel) { | |||
startElement(listItemLabel); | |||
} | |||
@Override | |||
public void endListLabel(ListItemLabel listItemLabel) { | |||
endElement(listItemLabel); | |||
} | |||
@Override | |||
public void startListBody(ListItemBody listItemBody) { | |||
startElement(listItemBody); | |||
} | |||
@Override | |||
public void endListBody(ListItemBody listItemBody) { | |||
endElement(listItemBody); | |||
} | |||
@Override | |||
public void startStatic(StaticContent staticContent) { | |||
startElement(staticContent); | |||
} | |||
@Override | |||
public void endStatic(StaticContent statisContent) { | |||
endElement(statisContent); | |||
} | |||
@Override | |||
public void startLink(BasicLink basicLink) { | |||
startElementWithID(basicLink); | |||
} | |||
@Override | |||
public void endLink(BasicLink basicLink) { | |||
endElement(basicLink); | |||
} | |||
@Override | |||
public void image(ExternalGraphic eg) { | |||
startElementWithIDAndAltText(eg); | |||
endElement(eg); | |||
} | |||
@Override | |||
public void startInstreamForeignObject(InstreamForeignObject ifo) { | |||
startElementWithIDAndAltText(ifo); | |||
} | |||
@Override | |||
public void endInstreamForeignObject(InstreamForeignObject ifo) { | |||
endElement(ifo); | |||
} | |||
@Override | |||
public void startFootnote(Footnote footnote) { | |||
startElement(footnote); | |||
} | |||
@Override | |||
public void endFootnote(Footnote footnote) { | |||
endElement(footnote); | |||
} | |||
@Override | |||
public void startFootnoteBody(FootnoteBody body) { | |||
startElement(body); | |||
} | |||
@Override | |||
public void endFootnoteBody(FootnoteBody body) { | |||
endElement(body); | |||
} | |||
@Override | |||
public void startWrapper(Wrapper wrapper) { | |||
startElement(wrapper); | |||
} | |||
@Override | |||
public void endWrapper(Wrapper wrapper) { | |||
endElement(wrapper); | |||
} | |||
@Override | |||
public void character(Character c) { | |||
startElementWithID(c); | |||
endElement(c); | |||
} | |||
private void startElement(FONode node) { | |||
startElement(node, new AttributesImpl()); | |||
} | |||
private void startElementWithID(FONode node) { | |||
startElementWithID(node, new AttributesImpl()); | |||
} | |||
private void startElementWithIDAndAltText(AbstractGraphics node) { | |||
AttributesImpl attributes = new AttributesImpl(); | |||
addAttribute(attributes, ExtensionElementMapping.URI, "alt-text", | |||
ExtensionElementMapping.STANDARD_PREFIX, node.getAltText()); | |||
startElementWithID(node, attributes); | |||
} | |||
private void startElementWithID(FONode node, AttributesImpl attributes) { | |||
String id = Integer.toHexString(idCounter++); | |||
node.setPtr(id); | |||
addAttribute(attributes, | |||
InternalElementMapping.URI, "ptr", InternalElementMapping.STANDARD_PREFIX, id); | |||
startElement(node, attributes); | |||
} | |||
private void startElement(FONode node, AttributesImpl attributes) { | |||
String localName = node.getLocalName(); | |||
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); | |||
} | |||
} | |||
private void addNoNamespaceAttribute(AttributesImpl attributes, String name, String value) { | |||
attributes.addAttribute("", name, name, XMLUtil.CDATA, value); | |||
} | |||
private void addAttribute(AttributesImpl attributes, | |||
String namespace, String localName, String prefix, String value) { | |||
assert namespace.length() > 0 && prefix.length() > 0; | |||
String qualifiedName = prefix + ":" + localName; | |||
attributes.addAttribute(namespace, localName, qualifiedName, XMLUtil.CDATA, value); | |||
} | |||
private void addRole(CommonAccessibilityHolder node, AttributesImpl attributes) { | |||
String role = node.getCommonAccessibility().getRole(); | |||
if (role != null) { | |||
addNoNamespaceAttribute(attributes, "role", role); | |||
} | |||
} | |||
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); | |||
} | |||
} | |||
} | |||
/** | |||
* Creates a new instance. | |||
* | |||
* @param structureTree 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, | |||
FOEventHandler delegate) { | |||
super(delegate); | |||
this.structureTree = structureTree; | |||
this.actualStructureTreeBuilder = new StructureTreeBuilder(foUserAgent); | |||
this.structureTreeBuilder = actualStructureTreeBuilder; | |||
this.eventSwallower = new FOEventHandler(foUserAgent) { }; | |||
} | |||
@Override | |||
public void startDocument() throws SAXException { | |||
structureTreeBuilder.startDocument(); | |||
super.startDocument(); | |||
} | |||
@Override | |||
public void endDocument() throws SAXException { | |||
structureTreeBuilder.endDocument(); | |||
super.endDocument(); | |||
} | |||
@Override | |||
public void startPageSequence(PageSequence pageSeq) { | |||
structureTreeBuilder.startPageSequence(pageSeq); | |||
super.startPageSequence(pageSeq); | |||
} | |||
@Override | |||
public void endPageSequence(PageSequence pageSeq) { | |||
structureTreeBuilder.endPageSequence(pageSeq); | |||
super.endPageSequence(pageSeq); | |||
} | |||
@Override | |||
public void startPageNumber(PageNumber pagenum) { | |||
structureTreeBuilder.startPageNumber(pagenum); | |||
super.startPageNumber(pagenum); | |||
} | |||
@Override | |||
public void endPageNumber(PageNumber pagenum) { | |||
structureTreeBuilder.endPageNumber(pagenum); | |||
super.endPageNumber(pagenum); | |||
} | |||
@Override | |||
public void startPageNumberCitation(PageNumberCitation pageCite) { | |||
structureTreeBuilder.startPageNumberCitation(pageCite); | |||
super.startPageNumberCitation(pageCite); | |||
} | |||
@Override | |||
public void endPageNumberCitation(PageNumberCitation pageCite) { | |||
structureTreeBuilder.endPageNumberCitation(pageCite); | |||
super.endPageNumberCitation(pageCite); | |||
} | |||
@Override | |||
public void startPageNumberCitationLast(PageNumberCitationLast pageLast) { | |||
structureTreeBuilder.startPageNumberCitationLast(pageLast); | |||
super.startPageNumberCitationLast(pageLast); | |||
} | |||
@Override | |||
public void endPageNumberCitationLast(PageNumberCitationLast pageLast) { | |||
structureTreeBuilder.endPageNumberCitationLast(pageLast); | |||
super.endPageNumberCitationLast(pageLast); | |||
} | |||
@Override | |||
public void startFlow(Flow fl) { | |||
structureTreeBuilder.startFlow(fl); | |||
super.startFlow(fl); | |||
} | |||
@Override | |||
public void endFlow(Flow fl) { | |||
structureTreeBuilder.endFlow(fl); | |||
super.endFlow(fl); | |||
} | |||
@Override | |||
public void startBlock(Block bl) { | |||
structureTreeBuilder.startBlock(bl); | |||
super.startBlock(bl); | |||
} | |||
@Override | |||
public void endBlock(Block bl) { | |||
structureTreeBuilder.endBlock(bl); | |||
super.endBlock(bl); | |||
} | |||
@Override | |||
public void startBlockContainer(BlockContainer blc) { | |||
structureTreeBuilder.startBlockContainer(blc); | |||
super.startBlockContainer(blc); | |||
} | |||
@Override | |||
public void endBlockContainer(BlockContainer blc) { | |||
structureTreeBuilder.endBlockContainer(blc); | |||
super.endBlockContainer(blc); | |||
} | |||
@Override | |||
public void startInline(Inline inl) { | |||
structureTreeBuilder.startInline(inl); | |||
super.startInline(inl); | |||
} | |||
@Override | |||
public void endInline(Inline inl) { | |||
structureTreeBuilder.endInline(inl); | |||
super.endInline(inl); | |||
} | |||
@Override | |||
public void startTable(Table tbl) { | |||
structureTreeBuilder.startTable(tbl); | |||
super.startTable(tbl); | |||
} | |||
@Override | |||
public void endTable(Table tbl) { | |||
structureTreeBuilder.endTable(tbl); | |||
super.endTable(tbl); | |||
} | |||
@Override | |||
public void startColumn(TableColumn tc) { | |||
structureTreeBuilder.startColumn(tc); | |||
super.startColumn(tc); | |||
} | |||
@Override | |||
public void endColumn(TableColumn tc) { | |||
structureTreeBuilder.endColumn(tc); | |||
super.endColumn(tc); | |||
} | |||
@Override | |||
public void startHeader(TableHeader header) { | |||
structureTreeBuilder.startHeader(header); | |||
super.startHeader(header); | |||
} | |||
@Override | |||
public void endHeader(TableHeader header) { | |||
structureTreeBuilder.endHeader(header); | |||
super.endHeader(header); | |||
} | |||
@Override | |||
public void startFooter(TableFooter footer) { | |||
structureTreeBuilder.startFooter(footer); | |||
super.startFooter(footer); | |||
} | |||
@Override | |||
public void endFooter(TableFooter footer) { | |||
structureTreeBuilder.endFooter(footer); | |||
super.endFooter(footer); | |||
} | |||
@Override | |||
public void startBody(TableBody body) { | |||
structureTreeBuilder.startBody(body); | |||
super.startBody(body); | |||
} | |||
@Override | |||
public void endBody(TableBody body) { | |||
structureTreeBuilder.endBody(body); | |||
super.endBody(body); | |||
} | |||
@Override | |||
public void startRow(TableRow tr) { | |||
structureTreeBuilder.startRow(tr); | |||
super.startRow(tr); | |||
} | |||
@Override | |||
public void endRow(TableRow tr) { | |||
structureTreeBuilder.endRow(tr); | |||
super.endRow(tr); | |||
} | |||
@Override | |||
public void startCell(TableCell tc) { | |||
structureTreeBuilder.startCell(tc); | |||
super.startCell(tc); | |||
} | |||
@Override | |||
public void endCell(TableCell tc) { | |||
structureTreeBuilder.endCell(tc); | |||
super.endCell(tc); | |||
} | |||
@Override | |||
public void startList(ListBlock lb) { | |||
structureTreeBuilder.startList(lb); | |||
super.startList(lb); | |||
} | |||
@Override | |||
public void endList(ListBlock lb) { | |||
structureTreeBuilder.endList(lb); | |||
super.endList(lb); | |||
} | |||
@Override | |||
public void startListItem(ListItem li) { | |||
structureTreeBuilder.startListItem(li); | |||
super.startListItem(li); | |||
} | |||
@Override | |||
public void endListItem(ListItem li) { | |||
structureTreeBuilder.endListItem(li); | |||
super.endListItem(li); | |||
} | |||
@Override | |||
public void startListLabel(ListItemLabel listItemLabel) { | |||
structureTreeBuilder.startListLabel(listItemLabel); | |||
super.startListLabel(listItemLabel); | |||
} | |||
@Override | |||
public void endListLabel(ListItemLabel listItemLabel) { | |||
structureTreeBuilder.endListLabel(listItemLabel); | |||
super.endListLabel(listItemLabel); | |||
} | |||
@Override | |||
public void startListBody(ListItemBody listItemBody) { | |||
structureTreeBuilder.startListBody(listItemBody); | |||
super.startListBody(listItemBody); | |||
} | |||
@Override | |||
public void endListBody(ListItemBody listItemBody) { | |||
structureTreeBuilder.endListBody(listItemBody); | |||
super.endListBody(listItemBody); | |||
} | |||
@Override | |||
public void startStatic(StaticContent staticContent) { | |||
structureTreeBuilder.startStatic(staticContent); | |||
super.startStatic(staticContent); | |||
} | |||
@Override | |||
public void endStatic(StaticContent statisContent) { | |||
structureTreeBuilder.endStatic(statisContent); | |||
super.endStatic(statisContent); | |||
} | |||
@Override | |||
public void startMarkup() { | |||
structureTreeBuilder.startMarkup(); | |||
super.startMarkup(); | |||
} | |||
@Override | |||
public void endMarkup() { | |||
structureTreeBuilder.endMarkup(); | |||
super.endMarkup(); | |||
} | |||
@Override | |||
public void startLink(BasicLink basicLink) { | |||
structureTreeBuilder.startLink(basicLink); | |||
super.startLink(basicLink); | |||
} | |||
@Override | |||
public void endLink(BasicLink basicLink) { | |||
structureTreeBuilder.endLink(basicLink); | |||
super.endLink(basicLink); | |||
} | |||
@Override | |||
public void image(ExternalGraphic eg) { | |||
structureTreeBuilder.image(eg); | |||
super.image(eg); | |||
} | |||
@Override | |||
public void pageRef() { | |||
structureTreeBuilder.pageRef(); | |||
super.pageRef(); | |||
} | |||
@Override | |||
public void startInstreamForeignObject(InstreamForeignObject ifo) { | |||
structureTreeBuilder.startInstreamForeignObject(ifo); | |||
super.startInstreamForeignObject(ifo); | |||
} | |||
@Override | |||
public void endInstreamForeignObject(InstreamForeignObject ifo) { | |||
structureTreeBuilder.endInstreamForeignObject(ifo); | |||
super.endInstreamForeignObject(ifo); | |||
} | |||
@Override | |||
public void startFootnote(Footnote footnote) { | |||
structureTreeBuilder.startFootnote(footnote); | |||
super.startFootnote(footnote); | |||
} | |||
@Override | |||
public void endFootnote(Footnote footnote) { | |||
structureTreeBuilder.endFootnote(footnote); | |||
super.endFootnote(footnote); | |||
} | |||
@Override | |||
public void startFootnoteBody(FootnoteBody body) { | |||
structureTreeBuilder.startFootnoteBody(body); | |||
super.startFootnoteBody(body); | |||
} | |||
@Override | |||
public void endFootnoteBody(FootnoteBody body) { | |||
structureTreeBuilder.endFootnoteBody(body); | |||
super.endFootnoteBody(body); | |||
} | |||
@Override | |||
public void startLeader(Leader l) { | |||
structureTreeBuilder = eventSwallower; | |||
structureTreeBuilder.startLeader(l); | |||
super.startLeader(l); | |||
} | |||
@Override | |||
public void endLeader(Leader l) { | |||
structureTreeBuilder.endLeader(l); | |||
structureTreeBuilder = actualStructureTreeBuilder; | |||
super.endLeader(l); | |||
} | |||
@Override | |||
public void startWrapper(Wrapper wrapper) { | |||
structureTreeBuilder.startWrapper(wrapper); | |||
super.startWrapper(wrapper); | |||
} | |||
@Override | |||
public void endWrapper(Wrapper wrapper) { | |||
structureTreeBuilder.endWrapper(wrapper); | |||
super.endWrapper(wrapper); | |||
} | |||
@Override | |||
public void character(Character c) { | |||
structureTreeBuilder.character(c); | |||
super.character(c); | |||
} | |||
@Override | |||
public void characters(char[] data, int start, int length) { | |||
structureTreeBuilder.characters(data, start, length); | |||
super.characters(data, start, length); | |||
} | |||
@Override | |||
public void startExternalDocument(ExternalDocument document) { | |||
structureTreeBuilder.startExternalDocument(document); | |||
super.startExternalDocument(document); | |||
} | |||
@Override | |||
public void endExternalDocument(ExternalDocument document) { | |||
structureTreeBuilder.endExternalDocument(document); | |||
super.endExternalDocument(document); | |||
} | |||
} |
@@ -1,88 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!-- | |||
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$ --> | |||
<xsl:stylesheet version="1.0" | |||
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> | |||
<!-- 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:page-number|fo:page-number-citation|fo:page-number-citation-last"> | |||
<xsl:call-template name="addPtr"/> | |||
</xsl:template> | |||
<!-- 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:table-header|fo:table-footer|fo:table-body|fo:table-row|fo:table-cell"> | |||
<xsl:call-template name="addPtr"/> | |||
</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="addPtr"/> | |||
</xsl:template> | |||
<!-- Dynamic Effects: Link and Multi Formatting Objects --> | |||
<xsl:template match="fo:basic-link"> | |||
<xsl:call-template name="addPtr"/> | |||
</xsl:template> | |||
<!-- 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> |
@@ -1,100 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!-- | |||
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$ --> | |||
<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: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, fox:alt-text and role attributes, discard everything else --> | |||
<xsl:template match="@foi:ptr|@fox:alt-text|@role"> | |||
<xsl:copy-of select="."/> | |||
</xsl:template> | |||
<xsl:template match="@*"/> | |||
<!-- Discard text --> | |||
<xsl:template match="text()"/> | |||
</xsl:stylesheet> |
@@ -24,7 +24,6 @@ import java.io.OutputStream; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
import org.apache.fop.accessibility.Accessibility; | |||
import org.apache.fop.fo.FOTreeBuilder; | |||
/** | |||
@@ -111,11 +110,7 @@ public class Fop { | |||
if (foTreeBuilder == null) { | |||
createDefaultHandler(); | |||
} | |||
if (this.foUserAgent.isAccessibilityEnabled()) { | |||
return Accessibility.decorateDefaultHandler(this.foTreeBuilder, foUserAgent); | |||
} else { | |||
return this.foTreeBuilder; | |||
} | |||
return this.foTreeBuilder; | |||
} | |||
/** |
@@ -771,18 +771,16 @@ public interface Constants { | |||
* multi-column layouts. | |||
*/ | |||
int PR_X_DISABLE_COLUMN_BALANCING = 273; | |||
/** Property constant - FOP proprietary: FOP internal use for accessibility */ | |||
int PR_X_PTR = 274; | |||
/** | |||
* Property constant - FOP proprietary: alternative text for e-g and i-f-o. | |||
* Used for accessibility. | |||
*/ | |||
int PR_X_ALT_TEXT = 275; | |||
int PR_X_ALT_TEXT = 274; | |||
/** Property constant - FOP proprietary prototype (in XSL-FO 2.0 Requirements) */ | |||
int PR_X_XML_BASE = 276; | |||
int PR_X_XML_BASE = 275; | |||
/** Number of property constants defined */ | |||
int PROPERTY_COUNT = 276; | |||
int PROPERTY_COUNT = 275; | |||
// compound property constants | |||
@@ -0,0 +1,393 @@ | |||
/* | |||
* 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.fo; | |||
import org.xml.sax.SAXException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.fo.extensions.ExternalDocument; | |||
import org.apache.fop.fo.flow.BasicLink; | |||
import org.apache.fop.fo.flow.Block; | |||
import org.apache.fop.fo.flow.BlockContainer; | |||
import org.apache.fop.fo.flow.Character; | |||
import org.apache.fop.fo.flow.ExternalGraphic; | |||
import org.apache.fop.fo.flow.Footnote; | |||
import org.apache.fop.fo.flow.FootnoteBody; | |||
import org.apache.fop.fo.flow.Inline; | |||
import org.apache.fop.fo.flow.InstreamForeignObject; | |||
import org.apache.fop.fo.flow.Leader; | |||
import org.apache.fop.fo.flow.ListBlock; | |||
import org.apache.fop.fo.flow.ListItem; | |||
import org.apache.fop.fo.flow.ListItemBody; | |||
import org.apache.fop.fo.flow.ListItemLabel; | |||
import org.apache.fop.fo.flow.PageNumber; | |||
import org.apache.fop.fo.flow.PageNumberCitation; | |||
import org.apache.fop.fo.flow.PageNumberCitationLast; | |||
import org.apache.fop.fo.flow.Wrapper; | |||
import org.apache.fop.fo.flow.table.Table; | |||
import org.apache.fop.fo.flow.table.TableBody; | |||
import org.apache.fop.fo.flow.table.TableCell; | |||
import org.apache.fop.fo.flow.table.TableColumn; | |||
import org.apache.fop.fo.flow.table.TableFooter; | |||
import org.apache.fop.fo.flow.table.TableHeader; | |||
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.StaticContent; | |||
import org.apache.fop.fonts.FontInfo; | |||
/** | |||
* This class delegates all FO events to another FOEventHandler instance. | |||
*/ | |||
public abstract class DelegatingFOEventHandler extends FOEventHandler { | |||
private final FOEventHandler delegate; | |||
/** | |||
* Creates a new instance that delegates events to the given object. | |||
* | |||
* @param delegate the object to which all FO events will be forwarded | |||
*/ | |||
public DelegatingFOEventHandler(FOEventHandler delegate) { | |||
super(delegate.getUserAgent()); | |||
this.delegate = delegate; | |||
} | |||
@Override | |||
public FOUserAgent getUserAgent() { | |||
return delegate.getUserAgent(); | |||
} | |||
@Override | |||
public FontInfo getFontInfo() { | |||
return delegate.getFontInfo(); | |||
} | |||
@Override | |||
public void startDocument() throws SAXException { | |||
delegate.startDocument(); | |||
} | |||
@Override | |||
public void endDocument() throws SAXException { | |||
delegate.endDocument(); | |||
} | |||
@Override | |||
public void startPageSequence(PageSequence pageSeq) { | |||
delegate.startPageSequence(pageSeq); | |||
} | |||
@Override | |||
public void endPageSequence(PageSequence pageSeq) { | |||
delegate.endPageSequence(pageSeq); | |||
} | |||
@Override | |||
public void startPageNumber(PageNumber pagenum) { | |||
delegate.startPageNumber(pagenum); | |||
} | |||
@Override | |||
public void endPageNumber(PageNumber pagenum) { | |||
delegate.endPageNumber(pagenum); | |||
} | |||
@Override | |||
public void startPageNumberCitation(PageNumberCitation pageCite) { | |||
delegate.startPageNumberCitation(pageCite); | |||
} | |||
@Override | |||
public void endPageNumberCitation(PageNumberCitation pageCite) { | |||
delegate.endPageNumberCitation(pageCite); | |||
} | |||
@Override | |||
public void startPageNumberCitationLast(PageNumberCitationLast pageLast) { | |||
delegate.startPageNumberCitationLast(pageLast); | |||
} | |||
@Override | |||
public void endPageNumberCitationLast(PageNumberCitationLast pageLast) { | |||
delegate.endPageNumberCitationLast(pageLast); | |||
} | |||
@Override | |||
public void startFlow(Flow fl) { | |||
delegate.startFlow(fl); | |||
} | |||
@Override | |||
public void endFlow(Flow fl) { | |||
delegate.endFlow(fl); | |||
} | |||
@Override | |||
public void startBlock(Block bl) { | |||
delegate.startBlock(bl); | |||
} | |||
@Override | |||
public void endBlock(Block bl) { | |||
delegate.endBlock(bl); | |||
} | |||
@Override | |||
public void startBlockContainer(BlockContainer blc) { | |||
delegate.startBlockContainer(blc); | |||
} | |||
@Override | |||
public void endBlockContainer(BlockContainer blc) { | |||
delegate.endBlockContainer(blc); | |||
} | |||
@Override | |||
public void startInline(Inline inl) { | |||
delegate.startInline(inl); | |||
} | |||
@Override | |||
public void endInline(Inline inl) { | |||
delegate.endInline(inl); | |||
} | |||
@Override | |||
public void startTable(Table tbl) { | |||
delegate.startTable(tbl); | |||
} | |||
@Override | |||
public void endTable(Table tbl) { | |||
delegate.endTable(tbl); | |||
} | |||
@Override | |||
public void startColumn(TableColumn tc) { | |||
delegate.startColumn(tc); | |||
} | |||
@Override | |||
public void endColumn(TableColumn tc) { | |||
delegate.endColumn(tc); | |||
} | |||
@Override | |||
public void startHeader(TableHeader header) { | |||
delegate.startHeader(header); | |||
} | |||
@Override | |||
public void endHeader(TableHeader header) { | |||
delegate.endHeader(header); | |||
} | |||
@Override | |||
public void startFooter(TableFooter footer) { | |||
delegate.startFooter(footer); | |||
} | |||
@Override | |||
public void endFooter(TableFooter footer) { | |||
delegate.endFooter(footer); | |||
} | |||
@Override | |||
public void startBody(TableBody body) { | |||
delegate.startBody(body); | |||
} | |||
@Override | |||
public void endBody(TableBody body) { | |||
delegate.endBody(body); | |||
} | |||
@Override | |||
public void startRow(TableRow tr) { | |||
delegate.startRow(tr); | |||
} | |||
@Override | |||
public void endRow(TableRow tr) { | |||
delegate.endRow(tr); | |||
} | |||
@Override | |||
public void startCell(TableCell tc) { | |||
delegate.startCell(tc); | |||
} | |||
@Override | |||
public void endCell(TableCell tc) { | |||
delegate.endCell(tc); | |||
} | |||
@Override | |||
public void startList(ListBlock lb) { | |||
delegate.startList(lb); | |||
} | |||
@Override | |||
public void endList(ListBlock lb) { | |||
delegate.endList(lb); | |||
} | |||
@Override | |||
public void startListItem(ListItem li) { | |||
delegate.startListItem(li); | |||
} | |||
@Override | |||
public void endListItem(ListItem li) { | |||
delegate.endListItem(li); | |||
} | |||
@Override | |||
public void startListLabel(ListItemLabel listItemLabel) { | |||
delegate.startListLabel(listItemLabel); | |||
} | |||
@Override | |||
public void endListLabel(ListItemLabel listItemLabel) { | |||
delegate.endListLabel(listItemLabel); | |||
} | |||
@Override | |||
public void startListBody(ListItemBody listItemBody) { | |||
delegate.startListBody(listItemBody); | |||
} | |||
@Override | |||
public void endListBody(ListItemBody listItemBody) { | |||
delegate.endListBody(listItemBody); | |||
} | |||
@Override | |||
public void startStatic(StaticContent staticContent) { | |||
delegate.startStatic(staticContent); | |||
} | |||
@Override | |||
public void endStatic(StaticContent statisContent) { | |||
delegate.endStatic(statisContent); | |||
} | |||
@Override | |||
public void startMarkup() { | |||
delegate.startMarkup(); | |||
} | |||
@Override | |||
public void endMarkup() { | |||
delegate.endMarkup(); | |||
} | |||
@Override | |||
public void startLink(BasicLink basicLink) { | |||
delegate.startLink(basicLink); | |||
} | |||
@Override | |||
public void endLink(BasicLink basicLink) { | |||
delegate.endLink(basicLink); | |||
} | |||
@Override | |||
public void image(ExternalGraphic eg) { | |||
delegate.image(eg); | |||
} | |||
@Override | |||
public void pageRef() { | |||
delegate.pageRef(); | |||
} | |||
@Override | |||
public void startInstreamForeignObject(InstreamForeignObject ifo) { | |||
delegate.startInstreamForeignObject(ifo); | |||
} | |||
@Override | |||
public void endInstreamForeignObject(InstreamForeignObject ifo) { | |||
delegate.endInstreamForeignObject(ifo); | |||
} | |||
@Override | |||
public void startFootnote(Footnote footnote) { | |||
delegate.startFootnote(footnote); | |||
} | |||
@Override | |||
public void endFootnote(Footnote footnote) { | |||
delegate.endFootnote(footnote); | |||
} | |||
@Override | |||
public void startFootnoteBody(FootnoteBody body) { | |||
delegate.startFootnoteBody(body); | |||
} | |||
@Override | |||
public void endFootnoteBody(FootnoteBody body) { | |||
delegate.endFootnoteBody(body); | |||
} | |||
@Override | |||
public void startLeader(Leader l) { | |||
delegate.startLeader(l); | |||
} | |||
@Override | |||
public void endLeader(Leader l) { | |||
delegate.endLeader(l); | |||
} | |||
@Override | |||
public void startWrapper(Wrapper wrapper) { | |||
delegate.startWrapper(wrapper); | |||
} | |||
@Override | |||
public void endWrapper(Wrapper wrapper) { | |||
delegate.endWrapper(wrapper); | |||
} | |||
@Override | |||
public void character(Character c) { | |||
delegate.character(c); | |||
} | |||
@Override | |||
public void characters(char[] data, int start, int length) { | |||
delegate.characters(data, start, length); | |||
} | |||
@Override | |||
public void startExternalDocument(ExternalDocument document) { | |||
delegate.startExternalDocument(document); | |||
} | |||
@Override | |||
public void endExternalDocument(ExternalDocument document) { | |||
delegate.endExternalDocument(document); | |||
} | |||
} |
@@ -35,9 +35,12 @@ import org.apache.fop.fo.flow.InstreamForeignObject; | |||
import org.apache.fop.fo.flow.Leader; | |||
import org.apache.fop.fo.flow.ListBlock; | |||
import org.apache.fop.fo.flow.ListItem; | |||
import org.apache.fop.fo.flow.ListItemBody; | |||
import org.apache.fop.fo.flow.ListItemLabel; | |||
import org.apache.fop.fo.flow.PageNumber; | |||
import org.apache.fop.fo.flow.PageNumberCitation; | |||
import org.apache.fop.fo.flow.PageNumberCitationLast; | |||
import org.apache.fop.fo.flow.Wrapper; | |||
import org.apache.fop.fo.flow.table.Table; | |||
import org.apache.fop.fo.flow.table.TableBody; | |||
import org.apache.fop.fo.flow.table.TableCell; | |||
@@ -47,6 +50,7 @@ import org.apache.fop.fo.flow.table.TableHeader; | |||
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.StaticContent; | |||
import org.apache.fop.fonts.FontEventAdapter; | |||
import org.apache.fop.fonts.FontInfo; | |||
@@ -359,39 +363,45 @@ public abstract class FOEventHandler { | |||
/** | |||
* Process start of a ListLabel. | |||
* @param listItemLabel ListItemLabel that is starting | |||
*/ | |||
public void startListLabel() { | |||
public void startListLabel(ListItemLabel listItemLabel) { | |||
} | |||
/** | |||
* Process end of a ListLabel. | |||
* @param listItemLabel ListItemLabel that is ending | |||
*/ | |||
public void endListLabel() { | |||
public void endListLabel(ListItemLabel listItemLabel) { | |||
} | |||
/** | |||
* Process start of a ListBody. | |||
* @param listItemBody ListItemBody that is starting | |||
*/ | |||
public void startListBody() { | |||
public void startListBody(ListItemBody listItemBody) { | |||
} | |||
/** | |||
* Process end of a ListBody. | |||
* @param listItemBody ListItemBody that is ending | |||
*/ | |||
public void endListBody() { | |||
public void endListBody(ListItemBody listItemBody) { | |||
} | |||
// Static Regions | |||
/** | |||
* Process start of a Static. | |||
* @param staticContent StaticContent that is starting | |||
*/ | |||
public void startStatic() { | |||
public void startStatic(StaticContent staticContent) { | |||
} | |||
/** | |||
* Process end of a Static. | |||
* @param statisContent StaticContent that is ending | |||
*/ | |||
public void endStatic() { | |||
public void endStatic(StaticContent statisContent) { | |||
} | |||
@@ -409,15 +419,16 @@ public abstract class FOEventHandler { | |||
/** | |||
* Process start of a Link. | |||
* @param basicLink BasicLink that is ending | |||
* @param basicLink BasicLink that is starting | |||
*/ | |||
public void startLink(BasicLink basicLink) { | |||
} | |||
/** | |||
* Process end of a Link. | |||
* @param basicLink BasicLink that is ending | |||
*/ | |||
public void endLink() { | |||
public void endLink(BasicLink basicLink) { | |||
} | |||
/** | |||
@@ -434,10 +445,17 @@ public abstract class FOEventHandler { | |||
} | |||
/** | |||
* Process an InstreamForeignObject. | |||
* @param ifo InstreamForeignObject to process. | |||
* Process the start of an InstreamForeignObject. | |||
* @param ifo InstreamForeignObject that is starting | |||
*/ | |||
public void startInstreamForeignObject(InstreamForeignObject ifo) { | |||
} | |||
/** | |||
* Process the end of an InstreamForeignObject. | |||
* @param ifo InstreamForeignObject that is ending | |||
*/ | |||
public void foreignObject(InstreamForeignObject ifo) { | |||
public void endInstreamForeignObject(InstreamForeignObject ifo) { | |||
} | |||
/** | |||
@@ -469,10 +487,33 @@ public abstract class FOEventHandler { | |||
} | |||
/** | |||
* Process a Leader. | |||
* @param l Leader to process. | |||
* Process the start of a Leader. | |||
* @param l Leader that is starting | |||
*/ | |||
public void startLeader(Leader l) { | |||
} | |||
/** | |||
* Process the end of a Leader. | |||
* @param l Leader that is ending | |||
*/ | |||
public void endLeader(Leader l) { | |||
} | |||
/** | |||
* Process the start of a wrapper. | |||
* | |||
* @param wrapper wrapper that is starting | |||
*/ | |||
public void startWrapper(Wrapper wrapper) { | |||
} | |||
/** | |||
* Process the ending of a wrapper. | |||
* | |||
* @param wrapper wrapper that is ending | |||
*/ | |||
public void leader(Leader l) { | |||
public void endWrapper(Wrapper wrapper) { | |||
} | |||
/** |
@@ -912,4 +912,8 @@ public abstract class FONode implements Cloneable { | |||
} | |||
public void setPtr(String ptr) { | |||
throw new UnsupportedOperationException(); | |||
} | |||
} |
@@ -2533,12 +2533,6 @@ public final class FOPropertyMapping implements Constants { | |||
m.setDefault(""); | |||
addPropertyMaker("id", m); | |||
// foi:ptr, used for accessibility | |||
m = new StringProperty.Maker(PR_X_PTR); | |||
m.setInherited(false); | |||
m.setDefault(""); | |||
addPropertyMaker("foi:ptr", m); | |||
// fox:alt-text, used for accessibility | |||
m = new StringProperty.Maker(PR_X_ALT_TEXT); | |||
m.setInherited(false); |
@@ -33,6 +33,8 @@ import org.apache.commons.logging.LogFactory; | |||
import org.apache.xmlgraphics.util.QName; | |||
import org.apache.fop.accessibility.StructureTree; | |||
import org.apache.fop.accessibility.StructureTreeBuildingFOEventHandler; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.FormattingResults; | |||
@@ -104,6 +106,11 @@ public class FOTreeBuilder extends DefaultHandler { | |||
//one of the RTF-, MIF- etc. Handlers. | |||
foEventHandler = foUserAgent.getRendererFactory().createFOEventHandler( | |||
foUserAgent, outputFormat, stream); | |||
if (userAgent.isAccessibilityEnabled()) { | |||
StructureTree structureTree = new StructureTree(); | |||
foEventHandler = new StructureTreeBuildingFOEventHandler(structureTree, foEventHandler); | |||
userAgent.setStructureTree(structureTree); | |||
} | |||
builderContext = new FOTreeBuilderContext(); | |||
builderContext.setPropertyListMaker(new PropertyListMaker() { | |||
public PropertyList make(FObj fobj, PropertyList parentPropertyList) { |
@@ -30,7 +30,6 @@ import org.apache.xmlgraphics.util.QName; | |||
import org.apache.fop.apps.FopFactory; | |||
import org.apache.fop.fo.expr.PropertyException; | |||
import org.apache.fop.fo.properties.CommonAbsolutePosition; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAural; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.CommonFont; | |||
@@ -600,15 +599,6 @@ public abstract class PropertyList { | |||
return new CommonMarginInline(this); | |||
} | |||
/** | |||
* Constructs a CommonAccessibility object. | |||
* @return the CommonAccessibility object | |||
* @throws PropertyException if there's a problem while processing the properties | |||
*/ | |||
public CommonAccessibility getAccessibilityProps() throws PropertyException { | |||
return new CommonAccessibility(this); | |||
} | |||
/** | |||
* Constructs a CommonAural object. | |||
* @return the CommonAural object |
@@ -37,6 +37,9 @@ public class ExtensionElementMapping extends ElementMapping { | |||
/** The FOP extension namespace URI */ | |||
public static final String URI = "http://xmlgraphics.apache.org/fop/extensions"; | |||
/** The standard XML prefix for elements and attributes in this namespace. */ | |||
public static final String STANDARD_PREFIX = "fox"; | |||
private static final Set<String> PROPERTY_ATTRIBUTES | |||
= new java.util.HashSet<String>(); | |||
@@ -85,7 +88,7 @@ public class ExtensionElementMapping extends ElementMapping { | |||
/** {@inheritDoc} */ | |||
public String getStandardPrefix() { | |||
return "fox"; | |||
return STANDARD_PREFIX; | |||
} | |||
/** {@inheritDoc} */ |
@@ -34,6 +34,9 @@ public class InternalElementMapping extends ElementMapping { | |||
/** The FOP extension namespace URI */ | |||
public static final String URI = "http://xmlgraphics.apache.org/fop/internal"; | |||
/** The standard XML prefix for elements and attributes in this namespace. */ | |||
public static final String STANDARD_PREFIX = "foi"; | |||
private static final Set<String> PROPERTY_ATTRIBUTES = new java.util.HashSet<String>(); | |||
static { | |||
@@ -59,7 +62,7 @@ public class InternalElementMapping extends ElementMapping { | |||
/** {@inheritDoc} */ | |||
public String getStandardPrefix() { | |||
return "foi"; | |||
return STANDARD_PREFIX; | |||
} | |||
/** {@inheritDoc} */ |
@@ -25,6 +25,8 @@ import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.GraphicsProperties; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.KeepProperty; | |||
import org.apache.fop.fo.properties.LengthRangeProperty; | |||
@@ -38,10 +40,11 @@ import org.apache.fop.fo.properties.StructurePointerPropertySet; | |||
* <code>fo:external-graphic</code></a> flow formatting objects. | |||
*/ | |||
public abstract class AbstractGraphics extends FObj | |||
implements GraphicsProperties, StructurePointerPropertySet { | |||
implements GraphicsProperties, StructurePointerPropertySet, CommonAccessibilityHolder { | |||
// The value of properties relevant for fo:instream-foreign-object | |||
// and external-graphics. | |||
private CommonAccessibility commonAccessibility; | |||
private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
private Length alignmentAdjust; | |||
private int alignmentBaseline; | |||
@@ -62,6 +65,7 @@ public abstract class AbstractGraphics extends FObj | |||
private int scaling; | |||
private int textAlign; | |||
private Length width; | |||
private String altText; | |||
private String ptr; // used for accessibility | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
@@ -85,6 +89,7 @@ public abstract class AbstractGraphics extends FObj | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); | |||
alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength(); | |||
alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum(); | |||
@@ -97,7 +102,6 @@ public abstract class AbstractGraphics extends FObj | |||
dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); | |||
height = pList.get(PR_HEIGHT).getLength(); | |||
id = pList.get(PR_ID).getString(); | |||
ptr = pList.get(PR_X_PTR).getString(); // used for accessibility | |||
inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange(); | |||
keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep(); | |||
keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep(); | |||
@@ -107,13 +111,17 @@ public abstract class AbstractGraphics extends FObj | |||
textAlign = pList.get(PR_TEXT_ALIGN).getEnum(); | |||
width = pList.get(PR_WIDTH).getLength(); | |||
if (getUserAgent().isAccessibilityEnabled()) { | |||
String altText = pList.get(PR_X_ALT_TEXT).getString(); | |||
altText = pList.get(PR_X_ALT_TEXT).getString(); | |||
if (altText.equals("")) { | |||
getFOValidationEventProducer().altTextMissing(this, getLocalName(), getLocator()); | |||
} | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** | |||
* @return the "id" property. | |||
*/ | |||
@@ -217,11 +225,20 @@ public abstract class AbstractGraphics extends FObj | |||
return keepWithPrevious; | |||
} | |||
@Override | |||
public void setPtr(String ptr) { | |||
this.ptr = ptr; | |||
} | |||
/** {@inheritDoc} */ | |||
public String getPtr() { | |||
return ptr; | |||
} | |||
public String getAltText() { | |||
return altText; | |||
} | |||
/** @return the graphic's intrinsic width in millipoints */ | |||
public abstract int getIntrinsicWidth(); | |||
@@ -26,6 +26,8 @@ import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.KeepProperty; | |||
/** | |||
@@ -33,8 +35,10 @@ import org.apache.fop.fo.properties.KeepProperty; | |||
* <code>fo:list-item-label</code></a> and <a href="http://www.w3.org/TR/xsl/#fo_list-item-body"> | |||
* <code>fo:list-item-body</code></a>. | |||
*/ | |||
public abstract class AbstractListItemPart extends FObj { | |||
// The value of properties relevant for fo:list-item-label and fo:list-item-body. | |||
public abstract class AbstractListItemPart extends FObj implements CommonAccessibilityHolder { | |||
private CommonAccessibility commonAccessibility; | |||
private KeepProperty keepTogether; | |||
// Valid properties, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
@@ -55,6 +59,7 @@ public abstract class AbstractListItemPart extends FObj { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep(); | |||
} | |||
@@ -86,6 +91,10 @@ public abstract class AbstractListItemPart extends FObj { | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** @return the "keep-together" property. */ | |||
public KeepProperty getKeepTogether() { | |||
return keepTogether; |
@@ -31,6 +31,8 @@ import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.CommonFont; | |||
import org.apache.fop.fo.properties.CommonTextDecoration; | |||
@@ -44,9 +46,10 @@ import org.apache.fop.fo.properties.StructurePointerPropertySet; | |||
* <code>fo:page-number-citation-last</code></a> objects. | |||
*/ | |||
public abstract class AbstractPageNumberCitation extends FObj | |||
implements StructurePointerPropertySet { | |||
implements StructurePointerPropertySet, CommonAccessibilityHolder { | |||
// The value of properties relevant for fo:page-number-citation(-last). | |||
private CommonAccessibility commonAccessibility; | |||
private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
private CommonFont commonFont; | |||
private Length alignmentAdjust; | |||
@@ -61,7 +64,6 @@ public abstract class AbstractPageNumberCitation extends FObj | |||
private CommonTextDecoration textDecoration; | |||
// private ToBeImplementedProperty textShadow; | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
// private CommonAural commonAural; | |||
// private CommonMarginInline commonMarginInline; | |||
// private CommonRelativePosition commonRelativePosition; | |||
@@ -91,6 +93,7 @@ public abstract class AbstractPageNumberCitation extends FObj | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); | |||
commonFont = pList.getFontProps(); | |||
alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength(); | |||
@@ -99,7 +102,6 @@ public abstract class AbstractPageNumberCitation extends FObj | |||
dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); | |||
// letterSpacing = pList.get(PR_LETTER_SPACING); | |||
lineHeight = pList.get(PR_LINE_HEIGHT).getSpace(); | |||
ptr = pList.get(PR_X_PTR).getString(); // used for accessibility | |||
refId = pList.get(PR_REF_ID).getString(); | |||
textDecoration = pList.getTextDecorationProps(); | |||
// textShadow = pList.get(PR_TEXT_SHADOW); | |||
@@ -129,6 +131,10 @@ public abstract class AbstractPageNumberCitation extends FObj | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** @return the {@link CommonFont} */ | |||
public CommonFont getCommonFont() { | |||
return commonFont; | |||
@@ -144,6 +150,11 @@ public abstract class AbstractPageNumberCitation extends FObj | |||
return textDecoration; | |||
} | |||
@Override | |||
public void setPtr(String ptr) { | |||
this.ptr = ptr; | |||
} | |||
/** {@inheritDoc} */ | |||
public String getPtr() { | |||
return ptr; |
@@ -76,7 +76,6 @@ public class BasicLink extends InlineLevel implements StructurePointerPropertySe | |||
alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum(); | |||
baselineShift = pList.get(PR_BASELINE_SHIFT).getLength(); | |||
dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); | |||
ptr = pList.get(PR_X_PTR).getString(); // used for accessibility | |||
// destinationPlacementOffset = pList.get(PR_DESTINATION_PLACEMENT_OFFSET); | |||
externalDestination = pList.get(PR_EXTERNAL_DESTINATION).getString(); | |||
// indicateDestination = pList.get(PR_INDICATE_DESTINATION); | |||
@@ -104,7 +103,7 @@ public class BasicLink extends InlineLevel implements StructurePointerPropertySe | |||
/** {@inheritDoc} */ | |||
protected void endOfNode() throws FOPException { | |||
super.endOfNode(); | |||
getFOEventHandler().endLink(); | |||
getFOEventHandler().endLink(this); | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -143,6 +142,11 @@ public class BasicLink extends InlineLevel implements StructurePointerPropertySe | |||
return dominantBaseline; | |||
} | |||
@Override | |||
public void setPtr(String ptr) { | |||
this.ptr = ptr; | |||
} | |||
/** {@inheritDoc} */ | |||
public String getPtr() { | |||
return ptr; |
@@ -33,6 +33,8 @@ import org.apache.fop.fo.NullCharIterator; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.BreakPropertySet; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.CommonFont; | |||
import org.apache.fop.fo.properties.CommonHyphenation; | |||
@@ -46,13 +48,15 @@ import org.apache.fop.fo.properties.StructurePointerPropertySet; | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_block"> | |||
* <code>fo:block object</code></a>. | |||
*/ | |||
public class Block extends FObjMixed implements BreakPropertySet, StructurePointerPropertySet { | |||
public class Block extends FObjMixed implements BreakPropertySet, StructurePointerPropertySet, | |||
CommonAccessibilityHolder { | |||
// used for FO validation | |||
private boolean blockOrInlineItemFound = false; | |||
private boolean initialPropertySetFound = false; | |||
// The value of properties relevant for fo:block. | |||
private CommonAccessibility commonAccessibility; | |||
private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
private CommonFont commonFont; | |||
private CommonHyphenation commonHyphenation; | |||
@@ -104,6 +108,7 @@ public class Block extends FObjMixed implements BreakPropertySet, StructurePoint | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); | |||
commonFont = pList.getFontProps(); | |||
commonHyphenation = pList.getHyphenationProps(); | |||
@@ -125,7 +130,6 @@ public class Block extends FObjMixed implements BreakPropertySet, StructurePoint | |||
lineHeightShiftAdjustment = pList.get(PR_LINE_HEIGHT_SHIFT_ADJUSTMENT).getEnum(); | |||
lineStackingStrategy = pList.get(PR_LINE_STACKING_STRATEGY).getEnum(); | |||
orphans = pList.get(PR_ORPHANS).getNumeric(); | |||
ptr = pList.get(PR_X_PTR).getString(); //used for accessibility | |||
whiteSpaceTreatment = pList.get(PR_WHITE_SPACE_TREATMENT).getEnum(); | |||
span = pList.get(PR_SPAN).getEnum(); | |||
textAlign = pList.get(PR_TEXT_ALIGN).getEnum(); | |||
@@ -149,6 +153,10 @@ public class Block extends FObjMixed implements BreakPropertySet, StructurePoint | |||
getFOEventHandler().endBlock(this); | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** @return the {@link CommonMarginBlock} */ | |||
public CommonMarginBlock getCommonMarginBlock() { | |||
return commonMarginBlock; | |||
@@ -175,6 +183,11 @@ public class Block extends FObjMixed implements BreakPropertySet, StructurePoint | |||
return breakAfter; | |||
} | |||
@Override | |||
public void setPtr(String ptr) { | |||
this.ptr = ptr; | |||
} | |||
/** {@inheritDoc} */ | |||
public String getPtr() { | |||
return ptr; |
@@ -110,7 +110,6 @@ public class Character extends FObj implements StructurePointerPropertySet { | |||
lineHeight = pList.get(PR_LINE_HEIGHT).getSpace(); | |||
textDecoration = pList.getTextDecorationProps(); | |||
wordSpacing = pList.get(PR_WORD_SPACING); | |||
ptr = pList.get(PR_X_PTR).getString(); // used for accessibility | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -210,6 +209,11 @@ public class Character extends FObj implements StructurePointerPropertySet { | |||
return keepWithPrevious; | |||
} | |||
@Override | |||
public void setPtr(String ptr) { | |||
this.ptr = ptr; | |||
} | |||
/** {@inheritDoc} */ | |||
public String getPtr() { | |||
return ptr; |
@@ -26,15 +26,16 @@ import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
/** | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_footnote"> | |||
* <code>fo:footnote</code></a> object. | |||
*/ | |||
public class Footnote extends FObj { | |||
// The value of properties relevant for fo:footnote (commented out for performance). | |||
// private CommonAccessibility commonAccessibility; | |||
// End of property values | |||
public class Footnote extends FObj implements CommonAccessibilityHolder { | |||
private CommonAccessibility commonAccessibility; | |||
private Inline footnoteCitation = null; | |||
private FootnoteBody footnoteBody; | |||
@@ -51,7 +52,7 @@ public class Footnote extends FObj { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
// No active properties -> do nothing. | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -110,6 +111,10 @@ public class Footnote extends FObj { | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** | |||
* Public accessor for inline FO | |||
* |
@@ -27,15 +27,16 @@ import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
/** | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_footnote-body"> | |||
* <code>fo:footnote-body</code></a> object. | |||
*/ | |||
public class FootnoteBody extends FObj { | |||
// The value of properties relevant for fo:footnote-body (commented out for perforance). | |||
// private CommonAccessibility commonAccessibility; | |||
// End of property values | |||
public class FootnoteBody extends FObj implements CommonAccessibilityHolder { | |||
private CommonAccessibility commonAccessibility; | |||
/** | |||
* Base constructor | |||
@@ -48,6 +49,7 @@ public class FootnoteBody extends FObj { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -93,4 +95,9 @@ public class FootnoteBody extends FObj { | |||
public int getNameId() { | |||
return FO_FOOTNOTE_BODY; | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
} |
@@ -27,19 +27,22 @@ import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.SpaceProperty; | |||
/** | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_initial-property-set"> | |||
* <code>fo:initial-property-set</code></a> object. | |||
*/ | |||
public class InitialPropertySet extends FObj { | |||
// The value of properties relevant for fo:initial-property-set. | |||
public class InitialPropertySet extends FObj implements CommonAccessibilityHolder { | |||
private CommonAccessibility commonAccessibility; | |||
// private ToBeImplementedProperty letterSpacing; | |||
private SpaceProperty lineHeight; | |||
// private ToBeImplementedProperty textShadow; | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
// private CommonAural commonAural; | |||
// private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
// private CommonFont commonFont; | |||
@@ -63,6 +66,7 @@ public class InitialPropertySet extends FObj { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
// letterSpacing = pList.get(PR_LETTER_SPACING); | |||
lineHeight = pList.get(PR_LINE_HEIGHT).getSpace(); | |||
// textShadow = pList.get(PR_TEXT_SHADOW); | |||
@@ -96,4 +100,9 @@ public class InitialPropertySet extends FObj { | |||
public int getNameId() { | |||
return FO_INITIAL_PROPERTY_SET; | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
} |
@@ -68,7 +68,6 @@ public class Inline extends InlineLevel implements StructurePointerPropertySet { | |||
alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum(); | |||
baselineShift = pList.get(PR_BASELINE_SHIFT).getLength(); | |||
dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum(); | |||
ptr = pList.get(PR_X_PTR).getString(); // used for accessibility | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -148,6 +147,11 @@ public class Inline extends InlineLevel implements StructurePointerPropertySet { | |||
return dominantBaseline; | |||
} | |||
@Override | |||
public void setPtr(String ptr) { | |||
this.ptr = ptr; | |||
} | |||
/** {@inheritDoc} */ | |||
public String getPtr() { | |||
return ptr; |
@@ -25,6 +25,8 @@ import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObjMixed; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.CommonFont; | |||
import org.apache.fop.fo.properties.CommonMarginInline; | |||
@@ -35,9 +37,10 @@ import org.apache.fop.fo.properties.SpaceProperty; | |||
* Class modelling the commonalities of several inline-level | |||
* formatting objects. | |||
*/ | |||
public abstract class InlineLevel extends FObjMixed { | |||
public abstract class InlineLevel extends FObjMixed implements CommonAccessibilityHolder { | |||
// The value of properties relevant for inline-level FOs. | |||
private CommonAccessibility commonAccessibility; | |||
private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
private CommonMarginInline commonMarginInline; | |||
private CommonFont commonFont; | |||
@@ -59,6 +62,7 @@ public abstract class InlineLevel extends FObjMixed { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); | |||
commonMarginInline = pList.getMarginInlineProps(); | |||
commonFont = pList.getFontProps(); | |||
@@ -68,6 +72,10 @@ public abstract class InlineLevel extends FObjMixed { | |||
lineHeight = pList.get(PR_LINE_HEIGHT).getSpace(); | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** @return the {@link CommonMarginInline} */ | |||
public CommonMarginInline getCommonMarginInline() { | |||
return commonMarginInline; |
@@ -59,6 +59,12 @@ public class InstreamForeignObject extends AbstractGraphics { | |||
super(parent); | |||
} | |||
@Override | |||
protected void startOfNode() throws FOPException { | |||
super.startOfNode(); | |||
getFOEventHandler().startInstreamForeignObject(this); | |||
} | |||
/** | |||
* Make sure content model satisfied, if so then tell the | |||
* {@link org.apache.fop.fo.FOEventHandler} that we are at | |||
@@ -69,7 +75,7 @@ public class InstreamForeignObject extends AbstractGraphics { | |||
if (firstChild == null) { | |||
missingChildElementError("one (1) non-XSL namespace child"); | |||
} | |||
getFOEventHandler().foreignObject(this); | |||
getFOEventHandler().endInstreamForeignObject(this); | |||
} | |||
/** |
@@ -158,4 +158,16 @@ public class Leader extends InlineLevel { | |||
public int getNameId() { | |||
return FO_LEADER; | |||
} | |||
@Override | |||
protected void startOfNode() throws FOPException { | |||
super.startOfNode(); | |||
getFOEventHandler().startLeader(this); | |||
} | |||
@Override | |||
protected void endOfNode() throws FOPException { | |||
super.endOfNode(); | |||
getFOEventHandler().endLeader(this); | |||
} | |||
} |
@@ -28,6 +28,8 @@ import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.BreakPropertySet; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.CommonMarginBlock; | |||
import org.apache.fop.fo.properties.KeepProperty; | |||
@@ -36,8 +38,9 @@ import org.apache.fop.fo.properties.KeepProperty; | |||
* Class modelling the <a href=http://www.w3.org/TR/xsl/#fo_list-block"> | |||
* <code>fo:list-block</code></a> object. | |||
*/ | |||
public class ListBlock extends FObj implements BreakPropertySet { | |||
public class ListBlock extends FObj implements BreakPropertySet, CommonAccessibilityHolder { | |||
// The value of properties relevant for fo:list-block. | |||
private CommonAccessibility commonAccessibility; | |||
private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
private CommonMarginBlock commonMarginBlock; | |||
private int breakAfter; | |||
@@ -46,7 +49,6 @@ public class ListBlock extends FObj implements BreakPropertySet { | |||
private KeepProperty keepWithNext; | |||
private KeepProperty keepWithPrevious; | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
// private CommonAural commonAural; | |||
// private CommonRelativePosition commonRelativePosition; | |||
// private int intrusionDisplace; | |||
@@ -73,6 +75,7 @@ public class ListBlock extends FObj implements BreakPropertySet { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); | |||
commonMarginBlock = pList.getMarginBlockProps(); | |||
breakAfter = pList.get(PR_BREAK_AFTER).getEnum(); | |||
@@ -123,6 +126,10 @@ public class ListBlock extends FObj implements BreakPropertySet { | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** @return the {@link CommonMarginBlock} */ | |||
public CommonMarginBlock getCommonMarginBlock() { | |||
return commonMarginBlock; |
@@ -27,6 +27,8 @@ import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.BreakPropertySet; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.CommonMarginBlock; | |||
import org.apache.fop.fo.properties.KeepProperty; | |||
@@ -35,8 +37,9 @@ import org.apache.fop.fo.properties.KeepProperty; | |||
* Class modelling the <a href=http://www.w3.org/TR/xsl/#fo_list-item"> | |||
* <code>fo:list-item</code></a> object. | |||
*/ | |||
public class ListItem extends FObj implements BreakPropertySet { | |||
public class ListItem extends FObj implements BreakPropertySet, CommonAccessibilityHolder { | |||
// The value of properties relevant for fo:list-item. | |||
private CommonAccessibility commonAccessibility; | |||
private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
private CommonMarginBlock commonMarginBlock; | |||
private int breakAfter; | |||
@@ -45,7 +48,6 @@ public class ListItem extends FObj implements BreakPropertySet { | |||
private KeepProperty keepWithNext; | |||
private KeepProperty keepWithPrevious; | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
// private CommonAural commonAural; | |||
// private CommonRelativePosition commonRelativePosition; | |||
// private int intrusionDisplace; | |||
@@ -67,6 +69,7 @@ public class ListItem extends FObj implements BreakPropertySet { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); | |||
commonMarginBlock = pList.getMarginBlockProps(); | |||
breakAfter = pList.get(PR_BREAK_AFTER).getEnum(); | |||
@@ -134,6 +137,10 @@ public class ListItem extends FObj implements BreakPropertySet { | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** @return the {@link CommonMarginBlock} */ | |||
public CommonMarginBlock getCommonMarginBlock() { | |||
return commonMarginBlock; |
@@ -38,13 +38,13 @@ public class ListItemBody extends AbstractListItemPart { | |||
/** {@inheritDoc} */ | |||
protected void startOfNode() throws FOPException { | |||
super.startOfNode(); | |||
getFOEventHandler().startListBody(); | |||
getFOEventHandler().startListBody(this); | |||
} | |||
/** {@inheritDoc} */ | |||
protected void endOfNode() throws FOPException { | |||
super.endOfNode(); | |||
getFOEventHandler().endListBody(); | |||
getFOEventHandler().endListBody(this); | |||
} | |||
/** {@inheritDoc} */ |
@@ -40,13 +40,13 @@ public class ListItemLabel extends AbstractListItemPart { | |||
/** {@inheritDoc} */ | |||
protected void startOfNode() throws FOPException { | |||
super.startOfNode(); | |||
getFOEventHandler().startListLabel(); | |||
getFOEventHandler().startListLabel(this); | |||
} | |||
/** {@inheritDoc} */ | |||
protected void endOfNode() throws FOPException { | |||
super.endOfNode(); | |||
getFOEventHandler().endListLabel(); | |||
getFOEventHandler().endListLabel(this); | |||
} | |||
/** {@inheritDoc} */ |
@@ -30,6 +30,8 @@ import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.CommonFont; | |||
import org.apache.fop.fo.properties.CommonTextDecoration; | |||
@@ -40,8 +42,10 @@ import org.apache.fop.fo.properties.StructurePointerPropertySet; | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_page-number"> | |||
* <code>fo:page-number</code></a> object. | |||
*/ | |||
public class PageNumber extends FObj implements StructurePointerPropertySet { | |||
public class PageNumber extends FObj | |||
implements StructurePointerPropertySet, CommonAccessibilityHolder { | |||
// The value of properties relevant for fo:page-number. | |||
private CommonAccessibility commonAccessibility; | |||
private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
private CommonFont commonFont; | |||
private Length alignmentAdjust; | |||
@@ -55,7 +59,6 @@ public class PageNumber extends FObj implements StructurePointerPropertySet { | |||
private CommonTextDecoration textDecoration; | |||
// private ToBeImplementedProperty textShadow; | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
// private CommonAural commonAural; | |||
// private CommonMarginInline commonMarginInline; | |||
// private CommonRelativePosition commonRelativePosition; | |||
@@ -85,6 +88,7 @@ public class PageNumber extends FObj implements StructurePointerPropertySet { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); | |||
commonFont = pList.getFontProps(); | |||
alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength(); | |||
@@ -94,7 +98,6 @@ public class PageNumber extends FObj implements StructurePointerPropertySet { | |||
// letterSpacing = pList.get(PR_LETTER_SPACING); | |||
lineHeight = pList.get(PR_LINE_HEIGHT).getSpace(); | |||
textDecoration = pList.getTextDecorationProps(); | |||
ptr = pList.get(PR_X_PTR).getString(); // used for accessibility | |||
// textShadow = pList.get(PR_TEXT_SHADOW); | |||
// implicit properties | |||
@@ -123,6 +126,10 @@ public class PageNumber extends FObj implements StructurePointerPropertySet { | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** @return the Common Font Properties. */ | |||
public CommonFont getCommonFont() { | |||
return commonFont; | |||
@@ -168,6 +175,11 @@ public class PageNumber extends FObj implements StructurePointerPropertySet { | |||
return lineHeight; | |||
} | |||
@Override | |||
public void setPtr(String ptr) { | |||
this.ptr = ptr; | |||
} | |||
/** {@inheritDoc} */ | |||
public String getPtr() { | |||
return ptr; |
@@ -51,6 +51,18 @@ public class Wrapper extends FObjMixed { | |||
super(parent); | |||
} | |||
@Override | |||
protected void startOfNode() throws FOPException { | |||
super.startOfNode(); | |||
getFOEventHandler().startWrapper(this); | |||
} | |||
@Override | |||
protected void endOfNode() throws FOPException { | |||
super.endOfNode(); | |||
getFOEventHandler().endWrapper(this); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
* <br>XSL Content Model: marker* (#PCDATA|%inline;|%block;)* |
@@ -32,6 +32,8 @@ import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.StaticPropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.BreakPropertySet; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.CommonMarginBlock; | |||
import org.apache.fop.fo.properties.KeepProperty; | |||
@@ -43,9 +45,11 @@ import org.apache.fop.fo.properties.TableColLength; | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table"> | |||
* <code>fo:table</code></a> object. | |||
*/ | |||
public class Table extends TableFObj implements ColumnNumberManagerHolder, BreakPropertySet { | |||
public class Table extends TableFObj implements ColumnNumberManagerHolder, BreakPropertySet, | |||
CommonAccessibilityHolder { | |||
/** properties */ | |||
private CommonAccessibility commonAccessibility; | |||
private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
private CommonMarginBlock commonMarginBlock; | |||
private LengthRangeProperty blockProgressionDimension; | |||
@@ -61,7 +65,6 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder, Break | |||
private int tableOmitFooterAtBreak; | |||
private int tableOmitHeaderAtBreak; | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
// private CommonAural commonAural; | |||
// private CommonRelativePosition commonRelativePosition; | |||
// private int intrusionDisplace; | |||
@@ -112,6 +115,7 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder, Break | |||
*/ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); | |||
commonMarginBlock = pList.getMarginBlockProps(); | |||
blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange(); | |||
@@ -301,6 +305,10 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder, Break | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** {@inheritDoc} */ | |||
public Table getTable() { | |||
return this; |
@@ -25,17 +25,22 @@ import org.xml.sax.Locator; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
/** | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-and-caption"> | |||
* <code>fo:table-and-caption</code></a> property. | |||
* TODO needs implementation | |||
*/ | |||
public class TableAndCaption extends FObj /*implements BreakPropertySet*/ { | |||
public class TableAndCaption extends FObj implements CommonAccessibilityHolder { | |||
private CommonAccessibility commonAccessibility; | |||
// The value of properties relevant for fo:table-and-caption. | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
// private CommonAural commonAural; | |||
// private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
// private CommonMarginBlock commonMarginBlock; | |||
@@ -50,7 +55,7 @@ public class TableAndCaption extends FObj /*implements BreakPropertySet*/ { | |||
// private int textAlign; | |||
// End of property values | |||
private static boolean notImplementedWarningGiven = false; | |||
static boolean notImplementedWarningGiven = false; // CSOK: VisibilityModifier | |||
/** used for FO validation */ | |||
private boolean tableCaptionFound = false; | |||
@@ -71,6 +76,12 @@ public class TableAndCaption extends FObj /*implements BreakPropertySet*/ { | |||
} | |||
} | |||
@Override | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
} | |||
/** | |||
* Make sure content model satisfied, if so then tell the | |||
* FOEventHandler that we are at the end of the flow. | |||
@@ -128,5 +139,10 @@ public class TableAndCaption extends FObj /*implements BreakPropertySet*/ { | |||
public int getNameId() { | |||
return FO_TABLE_AND_CAPTION; | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
} | |||
@@ -27,13 +27,18 @@ import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
/** | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-caption"> | |||
* <code>fo:table-caption</code></a> object. | |||
*/ | |||
public class TableCaption extends FObj { | |||
public class TableCaption extends FObj implements CommonAccessibilityHolder { | |||
private CommonAccessibility commonAccessibility; | |||
// The value of properties relevant for fo:table-caption. | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAural commonAural; | |||
@@ -49,7 +54,7 @@ public class TableCaption extends FObj { | |||
/** used for FO validation */ | |||
private boolean blockItemFound = false; | |||
private static boolean notImplementedWarningGiven = false; | |||
static boolean notImplementedWarningGiven = false; // CSOK: VisibilityModifier | |||
/** | |||
* Create a TableCaption instance with the given {@link FONode} | |||
@@ -69,6 +74,7 @@ public class TableCaption extends FObj { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -109,5 +115,10 @@ public class TableCaption extends FObj { | |||
public int getNameId() { | |||
return FO_TABLE_CAPTION; | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
} | |||
@@ -26,6 +26,8 @@ import org.apache.fop.datatypes.Length; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
import org.apache.fop.fo.properties.CommonBorderPaddingBackground; | |||
import org.apache.fop.fo.properties.LengthRangeProperty; | |||
@@ -33,8 +35,9 @@ import org.apache.fop.fo.properties.LengthRangeProperty; | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-cell"> | |||
* <code>fo:table-cell</code></a> object. | |||
*/ | |||
public class TableCell extends TableFObj { | |||
public class TableCell extends TableFObj implements CommonAccessibilityHolder { | |||
// The value of properties relevant for fo:table-cell. | |||
private CommonAccessibility commonAccessibility; | |||
private CommonBorderPaddingBackground commonBorderPaddingBackground; | |||
private LengthRangeProperty blockProgressionDimension; | |||
private int columnNumber; | |||
@@ -46,7 +49,6 @@ public class TableCell extends TableFObj { | |||
private int startsRow; | |||
private Length width; | |||
// Unused but valid items, commented out for performance: | |||
// private CommonAccessibility commonAccessibility; | |||
// private CommonAural commonAural; | |||
// private CommonRelativePosition commonRelativePosition; | |||
// private int relativeAlign; | |||
@@ -74,6 +76,7 @@ public class TableCell extends TableFObj { | |||
*/ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); | |||
blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange(); | |||
displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum(); | |||
@@ -145,6 +148,10 @@ public class TableCell extends TableFObj { | |||
return true; | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** | |||
* Get the {@link CommonBorderPaddingBackground} instance | |||
* attached to this TableCell. |
@@ -24,11 +24,17 @@ import java.util.List; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.datatypes.Length; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
/** | |||
* A common class for fo:table-body and fo:table-row which both can contain fo:table-cell. | |||
*/ | |||
public abstract class TableCellContainer extends TableFObj implements ColumnNumberManagerHolder { | |||
public abstract class TableCellContainer extends TableFObj | |||
implements ColumnNumberManagerHolder, CommonAccessibilityHolder { | |||
private CommonAccessibility commonAccessibility; | |||
/** list of pending spans */ | |||
protected List pendingSpans; | |||
@@ -44,6 +50,12 @@ public abstract class TableCellContainer extends TableFObj implements ColumnNumb | |||
super(parent); | |||
} | |||
@Override | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
} | |||
/** | |||
* Add cell to current row. | |||
* @param cell a table cell to add | |||
@@ -116,4 +128,8 @@ public abstract class TableCellContainer extends TableFObj implements ColumnNumb | |||
return columnNumberManager; | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
} |
@@ -74,7 +74,6 @@ public abstract class TableFObj extends FObj implements StructurePointerProperty | |||
borderBeforePrecedence = pList.get(PR_BORDER_BEFORE_PRECEDENCE).getNumeric(); | |||
borderEndPrecedence = pList.get(PR_BORDER_END_PRECEDENCE).getNumeric(); | |||
borderStartPrecedence = pList.get(PR_BORDER_START_PRECEDENCE).getNumeric(); | |||
ptr = pList.get(PR_X_PTR).getString(); | |||
if (getNameId() != FO_TABLE //Separate check for fo:table in Table.java | |||
&& getNameId() != FO_TABLE_CELL | |||
&& getCommonBorderPaddingBackground().hasPadding( | |||
@@ -241,6 +240,11 @@ public abstract class TableFObj extends FObj implements StructurePointerProperty | |||
} | |||
} | |||
@Override | |||
public void setPtr(String ptr) { | |||
this.ptr = ptr; | |||
} | |||
/** {@inheritDoc} */ | |||
public String getPtr() { | |||
return ptr; |
@@ -33,16 +33,19 @@ import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.extensions.destination.Destination; | |||
import org.apache.fop.fo.pagination.bookmarks.BookmarkTree; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
/** | |||
* Class modeling the <a href="http://www.w3.org/TR/xsl/#fo_root"> | |||
* <code>fo:root</code></a> formatting object. | |||
* Contains page masters, page-sequences. | |||
*/ | |||
public class Root extends FObj { | |||
// The value of properties relevant for fo:root. | |||
public class Root extends FObj implements CommonAccessibilityHolder { | |||
private CommonAccessibility commonAccessibility; | |||
private int mediaUsage; | |||
// End of property values | |||
private LayoutMasterSet layoutMasterSet; | |||
private Declarations declarations; | |||
@@ -83,6 +86,7 @@ public class Root extends FObj { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
mediaUsage = pList.get(PR_MEDIA_USAGE).getEnum(); | |||
} | |||
@@ -156,6 +160,10 @@ public class Root extends FObj { | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** | |||
* Sets the FOEventHandler object that this Root is attached to | |||
* @param foEventHandler the FOEventHandler object |
@@ -44,7 +44,7 @@ public class StaticContent extends Flow { | |||
if (getFlowName() == null || getFlowName().equals("")) { | |||
missingPropertyError("flow-name"); | |||
} | |||
getFOEventHandler().startFlow(this); | |||
getFOEventHandler().startStatic(this); | |||
} | |||
/** | |||
@@ -56,7 +56,7 @@ public class StaticContent extends Flow { | |||
if (firstChild == null && getUserAgent().validateStrictly()) { | |||
missingChildElementError("(%block;)+"); | |||
} | |||
getFOEventHandler().endFlow(this); | |||
getFOEventHandler().endStatic(this); | |||
} | |||
/** |
@@ -22,11 +22,14 @@ package org.apache.fop.fo.pagination.bookmarks; | |||
import java.util.ArrayList; | |||
import org.xml.sax.Locator; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
/** | |||
@@ -34,11 +37,12 @@ import org.apache.fop.fo.ValidationException; | |||
* <code>fo:bookmark</code></a> object, first introduced in the | |||
* XSL 1.1 WD. | |||
*/ | |||
public class Bookmark extends FObj { | |||
public class Bookmark extends FObj implements CommonAccessibilityHolder { | |||
private BookmarkTitle bookmarkTitle; | |||
private ArrayList childBookmarks = new ArrayList(); | |||
// The value of properties relevant for this FO | |||
private CommonAccessibility commonAccessibility; | |||
private String internalDestination; | |||
private String externalDestination; | |||
private boolean bShow = true; // from starting-state property | |||
@@ -59,6 +63,7 @@ public class Bookmark extends FObj { | |||
/** {@inheritDoc} */ | |||
public void bind(PropertyList pList) throws FOPException { | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
externalDestination = pList.get(PR_EXTERNAL_DESTINATION).getString(); | |||
internalDestination = pList.get(PR_INTERNAL_DESTINATION).getString(); | |||
bShow = (pList.get(PR_STARTING_STATE).getEnum() == EN_SHOW); | |||
@@ -112,6 +117,10 @@ public class Bookmark extends FObj { | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** | |||
* Get the bookmark title for this bookmark | |||
* |
@@ -21,17 +21,23 @@ package org.apache.fop.fo.pagination.bookmarks; | |||
import org.xml.sax.Locator; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.ValidationException; | |||
import org.apache.fop.fo.properties.CommonAccessibility; | |||
import org.apache.fop.fo.properties.CommonAccessibilityHolder; | |||
/** | |||
* Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_bookmark-title"> | |||
* <code>fo:bookmark-title</code></a> object, first introduced in the | |||
* XSL 1.1 WD. | |||
*/ | |||
public class BookmarkTitle extends FObj { | |||
public class BookmarkTitle extends FObj implements CommonAccessibilityHolder { | |||
private CommonAccessibility commonAccessibility; | |||
private String title = ""; | |||
/** | |||
@@ -44,6 +50,12 @@ public class BookmarkTitle extends FObj { | |||
super(parent); | |||
} | |||
@Override | |||
public void bind(PropertyList pList) throws FOPException { | |||
super.bind(pList); | |||
commonAccessibility = CommonAccessibility.getInstance(pList); | |||
} | |||
/** | |||
* Add the characters to this BookmarkTitle. | |||
* The text data inside the BookmarkTitle xml element | |||
@@ -72,6 +84,10 @@ public class BookmarkTitle extends FObj { | |||
} | |||
} | |||
public CommonAccessibility getCommonAccessibility() { | |||
return commonAccessibility; | |||
} | |||
/** | |||
* Get the title for this BookmarkTitle. | |||
* |
@@ -24,37 +24,62 @@ import org.apache.fop.fo.PropertyList; | |||
import org.apache.fop.fo.expr.PropertyException; | |||
/** | |||
* Store all common accessibility properties. | |||
* See Sec 7.4 of the XSL-FO Standard. | |||
* Public "structure" allows direct member access. | |||
* The "role" and "source-document" properties, see Section 7.5 of the XSL-FO 1.1 | |||
* Recommendation. | |||
*/ | |||
public class CommonAccessibility { | |||
/** | |||
* The "source-doc" property. | |||
*/ | |||
public String sourceDoc = null; // CSOK: VisibilityModifier | |||
public final class CommonAccessibility { | |||
/** | |||
* The "role" property. | |||
*/ | |||
public String role = null; // CSOK: VisibilityModifier | |||
private static final CommonAccessibility DEFAULT_INSTANCE = new CommonAccessibility(null, null); | |||
private final String sourceDocument; | |||
private final String role; | |||
private CommonAccessibility(String sourceDocument, String role) { | |||
this.sourceDocument = sourceDocument; | |||
this.role = role; | |||
} | |||
/** | |||
* Create a <code>CommonAccessibility</code> object. | |||
* @param pList The PropertyList with propery values. | |||
* @throws PropertyException if a property exception is raised | |||
* Returns an instance that matches the values (if any) in the given property list. | |||
* | |||
* @param propertyList a list from which to retrieve the accessibility properties | |||
* @return the corresponding instance | |||
* @throws PropertyException if a problem occurs while retrieving the properties | |||
*/ | |||
public CommonAccessibility(PropertyList pList) throws PropertyException { | |||
sourceDoc = pList.get(Constants.PR_SOURCE_DOCUMENT).getString(); | |||
if ("none".equals(sourceDoc)) { | |||
sourceDoc = null; | |||
public static CommonAccessibility getInstance(PropertyList propertyList) | |||
throws PropertyException { | |||
String sourceDocument = propertyList.get(Constants.PR_SOURCE_DOCUMENT).getString(); | |||
if ("none".equals(sourceDocument)) { | |||
sourceDocument = null; | |||
} | |||
role = pList.get(Constants.PR_ROLE).getString(); | |||
String role = propertyList.get(Constants.PR_ROLE).getString(); | |||
if ("none".equals(role)) { | |||
role = null; | |||
} | |||
if (sourceDocument == null && role == null) { | |||
return DEFAULT_INSTANCE; | |||
} else { | |||
return new CommonAccessibility(sourceDocument, role); | |||
} | |||
} | |||
/** | |||
* Returns the value of the source-document property. | |||
* | |||
* @return the source document, or null if the property was set to "none" | |||
*/ | |||
public String getSourceDocument() { | |||
return sourceDocument; | |||
} | |||
/** | |||
* Returns the value of the role property. | |||
* | |||
* @return the role, or null if the property was set to "none" | |||
*/ | |||
public String getRole() { | |||
return role; | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
/* | |||
* 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.fo.properties; | |||
/** | |||
* Classes that implement this interface support the common accessibility properties. | |||
* | |||
* @see CommonAccessibility | |||
*/ | |||
public interface CommonAccessibilityHolder { | |||
/** | |||
* Returns the accessibility properties. | |||
* | |||
* @return the accessibility properties | |||
*/ | |||
CommonAccessibility getCommonAccessibility(); | |||
} |
@@ -149,9 +149,6 @@ class PDFLogicalStructureHandler { | |||
} | |||
private void processNode(Node node, PDFStructElem parent, boolean addKid) { | |||
Node attr = node.getAttributes().getNamedItemNS(InternalElementMapping.URI, "ptr"); | |||
assert attr != null; | |||
String ptr = attr.getNodeValue(); | |||
PDFStructElem structElem = pdfDoc.getFactory().makeStructureElement( | |||
FOToPDFRoleMap.mapFormattingObject(node, parent, eventBroadcaster), parent); | |||
// TODO necessary? If a page-sequence is empty (e.g., contains a single | |||
@@ -170,7 +167,11 @@ class PDFLogicalStructureHandler { | |||
structElem.put("Alt", "No alternate text specified"); | |||
} | |||
} | |||
structTreeMap.put(ptr, structElem); | |||
Node attr = node.getAttributes().getNamedItemNS(InternalElementMapping.URI, "ptr"); | |||
if (attr != null) { | |||
String ptr = attr.getNodeValue(); | |||
structTreeMap.put(ptr, structElem); | |||
} | |||
NodeList nodes = node.getChildNodes(); | |||
for (int i = 0, n = nodes.getLength(); i < n; i++) { | |||
processNode(nodes.item(i), structElem, false); |
@@ -32,7 +32,6 @@ import java.util.Iterator; | |||
import java.util.Map; | |||
import org.w3c.dom.Document; | |||
import org.xml.sax.SAXException; | |||
import org.apache.commons.io.IOUtils; | |||
@@ -938,10 +937,10 @@ public class RTFHandler extends FOEventHandler { | |||
*/ | |||
//TODO: do this only, if the labels content <> previous labels content | |||
if (list.getChildCount() > 0) { | |||
this.endListBody(); | |||
this.endListBody(null); | |||
this.endList((ListBlock) li.getParent()); | |||
this.startList((ListBlock) li.getParent()); | |||
this.startListBody(); | |||
this.startListBody(null); | |||
list = (RtfList)builderContext.getContainer( | |||
RtfList.class, true, this); | |||
@@ -966,7 +965,7 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
/** {@inheritDoc} */ | |||
public void startListLabel() { | |||
public void startListLabel(ListItemLabel listItemLabel) { | |||
if (bDefer) { | |||
return; | |||
} | |||
@@ -986,7 +985,7 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
/** {@inheritDoc} */ | |||
public void endListLabel() { | |||
public void endListLabel(ListItemLabel listItemLabel) { | |||
if (bDefer) { | |||
return; | |||
} | |||
@@ -995,20 +994,20 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
/** {@inheritDoc} */ | |||
public void startListBody() { | |||
public void startListBody(ListItemBody listItemBody) { | |||
} | |||
/** {@inheritDoc} */ | |||
public void endListBody() { | |||
public void endListBody(ListItemBody listItemBody) { | |||
} | |||
// Static Regions | |||
/** {@inheritDoc} */ | |||
public void startStatic() { | |||
public void startStatic(StaticContent staticContent) { | |||
} | |||
/** {@inheritDoc} */ | |||
public void endStatic() { | |||
public void endStatic(StaticContent statisContent) { | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -1051,7 +1050,7 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
/** {@inheritDoc} */ | |||
public void endLink() { | |||
public void endLink(BasicLink basicLink) { | |||
if (bDefer) { | |||
return; | |||
} | |||
@@ -1091,7 +1090,7 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
/** {@inheritDoc} */ | |||
public void foreignObject(InstreamForeignObject ifo) { | |||
public void endInstreamForeignObject(InstreamForeignObject ifo) { | |||
if (bDefer) { | |||
return; | |||
} | |||
@@ -1338,7 +1337,7 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
/** {@inheritDoc} */ | |||
public void leader(Leader l) { | |||
public void startLeader(Leader l) { | |||
if (bDefer) { | |||
return; | |||
} | |||
@@ -1519,9 +1518,9 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
} else if (foNode instanceof StaticContent) { | |||
if (bStart) { | |||
startStatic(); | |||
startStatic(null); | |||
} else { | |||
endStatic(); | |||
endStatic(null); | |||
} | |||
} else if (foNode instanceof ExternalGraphic) { | |||
if (bStart) { | |||
@@ -1529,7 +1528,7 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
} else if (foNode instanceof InstreamForeignObject) { | |||
if (bStart) { | |||
foreignObject( (InstreamForeignObject) foNode ); | |||
endInstreamForeignObject( (InstreamForeignObject) foNode ); | |||
} | |||
} else if (foNode instanceof Block) { | |||
if (bStart) { | |||
@@ -1548,7 +1547,7 @@ public class RTFHandler extends FOEventHandler { | |||
if (bStart) { | |||
startLink( (BasicLink) foNode); | |||
} else { | |||
endLink(); | |||
endLink(null); | |||
} | |||
} else if (foNode instanceof Inline) { | |||
if (bStart) { | |||
@@ -1592,9 +1591,9 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
} else if (foNode instanceof ListItemBody) { | |||
if (bStart) { | |||
startListBody(); | |||
startListBody(null); | |||
} else { | |||
endListBody(); | |||
endListBody(null); | |||
} | |||
} else if (foNode instanceof ListItem) { | |||
if (bStart) { | |||
@@ -1604,9 +1603,9 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
} else if (foNode instanceof ListItemLabel) { | |||
if (bStart) { | |||
startListLabel(); | |||
startListLabel(null); | |||
} else { | |||
endListLabel(); | |||
endListLabel(null); | |||
} | |||
} else if (foNode instanceof Table) { | |||
if (bStart) { | |||
@@ -1652,7 +1651,7 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
} else if (foNode instanceof Leader) { | |||
if (bStart) { | |||
leader((Leader) foNode); | |||
startLeader((Leader) foNode); | |||
} | |||
} else if (foNode instanceof PageNumberCitation) { | |||
if (bStart) { |
@@ -1,11 +1,8 @@ | |||
This directory contains sample FO files for testing the accessibility features | |||
of FOP. | |||
To every FO file in this directory correspond two PDF files in the pdf/ | |||
sub-directory: one generated by the painter, one by the renderer. For example, | |||
the text_1.fo file has been rendered into pdf/text_1_painter_orig.pdf and | |||
pdf/text_1_renderer_orig.pdf. The configuration file config-painter.xconf (resp. | |||
config-renderer.xconf) was used. | |||
Every FO file in this directory has a corresponding PDF file in the pdf/ | |||
sub-directory. The fop.xconf configuration file was used. | |||
The PDF files have been checked with Adobe Acrobat Professional 9, using both | |||
the full accessibility checker and the read-aloud feature. The checker reports | |||
@@ -22,7 +19,7 @@ problem yet part or all of the document cannot be read aloud.) | |||
The purpose of this infrastructure is to be able to quickly re-test the | |||
accessibility processing chain when any change has been made to it. The | |||
configuration files disable the compression of the PDF streams, so it is | |||
configuration file disables the compression of the PDF streams, so it is | |||
possible to compare a re-generated PDF with the original one by using a simple | |||
diff tool. The files will not be identical because of the different creation | |||
dates (and the ID key in the trailer), but apart from that there should be no | |||
@@ -32,21 +29,13 @@ The rationale is that using a diff tool is much quicker and less tedious than | |||
running Acrobat's accessibility checker and read-aloud feature every time. | |||
To re-generate the PDF files using the painter: | |||
../../fop -c config-painter.xconf text_1.fo pdf/text_1_painter.pdf | |||
diff pdf/text_1_painter_orig.pdf pdf/text_1_painter.pdf | |||
To re-generate the PDF files: | |||
../../fop -c fop.xconf text_1.fo pdf/text_1.new.pdf | |||
diff pdf/text_1_painter.pdf pdf/text_1.new.pdf | |||
Or, going through the intermediate format: | |||
../../fop -c config-painter.xconf text_1.fo -if application/pdf text_1_if.xml | |||
../../fop -c config-painter.xconf -ifin text_1_if.xml pdf/text_1_painter.pdf | |||
diff pdf/text_1_painter_orig.pdf pdf/text_1_painter.pdf | |||
To re-generate the PDF files using the legacy renderer: | |||
../../fop -c config-renderer.xconf text_1.fo pdf/text_1_renderer.pdf | |||
diff pdf/text_1_renderer_orig.pdf pdf/text_1_renderer.pdf | |||
Or, going through the intermediate format: | |||
../../fop -c config-renderer.xconf text_1.fo -at application/pdf text_1_at.xml | |||
../../fop -c config-renderer.xconf -atin text_1_at.xml pdf/text_1_renderer.pdf | |||
diff pdf/text_1_renderer_orig.pdf pdf/text_1_renderer.pdf | |||
../../fop -c fop.xconf text_1.fo -if application/pdf text_1_if.xml | |||
../../fop -c fop.xconf -ifin text_1_if.xml pdf/text_1.new.pdf | |||
diff pdf/text_1.pdf pdf/text_1.new.pdf | |||
$Id$ |
@@ -0,0 +1,175 @@ | |||
<?xml version="1.0" standalone="no"?> | |||
<!-- | |||
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$ --> | |||
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" | |||
xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"> | |||
<fo:layout-master-set> | |||
<fo:simple-page-master master-name="page" | |||
page-height="400pt" page-width="300pt" margin="20pt" margin-top="10pt"> | |||
<fo:region-body margin-top="20pt"/> | |||
<fo:region-before extent="15pt"/> | |||
</fo:simple-page-master> | |||
</fo:layout-master-set> | |||
<fo:page-sequence master-reference="page"> | |||
<fo:static-content flow-name="xsl-region-before"> | |||
<fo:block id="1" font-size="7pt" text-align-last="justify" padding-bottom="2pt" | |||
border-bottom="0.25pt solid black">This is the page header<fo:leader/>Page <fo:page-number | |||
id="2"/></fo:block> | |||
</fo:static-content> | |||
<fo:static-content flow-name="xsl-footnote-separator"> | |||
<fo:block id="3"><fo:leader leader-length="100pt" leader-pattern="rule"/></fo:block> | |||
</fo:static-content> | |||
<fo:flow flow-name="xsl-region-body"> | |||
<fo:block id="4">This is a link to the <fo:wrapper id="5" color="blue"><fo:basic-link id="6" | |||
internal-destination="second-start">next page-sequence</fo:basic-link></fo:wrapper> | |||
(which starts on page <fo:page-number-citation id="7" ref-id="second-start"/> and ends on | |||
page <fo:page-number-citation-last id="8" ref-id="second-end"/>).</fo:block> | |||
<fo:block id="9" font-family="sans-serif" font-weight="bold" space-before="1em" | |||
space-after="0.2em" role="H1"><fo:block id="10">A Title Block</fo:block></fo:block> | |||
<fo:block id="11">This block of text contains a footnote<fo:footnote id="12"><fo:inline id="13" | |||
baseline-shift="super" font-size="70%">1</fo:inline><fo:footnote-body id="14"><fo:block | |||
id="15">A footnote with a link to the <fo:wrapper id="16" color="blue"><fo:basic-link | |||
id="17" external-destination="http://xmlgraphics.apache.org/fop/">FOP | |||
website</fo:basic-link></fo:wrapper></fo:block></fo:footnote-body></fo:footnote> | |||
call.</fo:block> | |||
<fo:table id="18" space-before="1em" width="100%" table-layout="fixed"> | |||
<fo:table-column id="19" column-width="proportional-column-width(1)"/> | |||
<fo:table-column id="20" column-width="proportional-column-width(2)"/> | |||
<fo:table-header id="21"> | |||
<fo:table-row id="22"> | |||
<fo:table-cell id="23" border="2pt solid black" padding="2pt 2pt 0"> | |||
<fo:block id="24">Header 1.1</fo:block> | |||
</fo:table-cell> | |||
<fo:table-cell id="25" border="2pt solid black" padding="2pt 2pt 0"> | |||
<fo:block id="26">Header 1.2</fo:block> | |||
</fo:table-cell> | |||
</fo:table-row> | |||
</fo:table-header> | |||
<fo:table-footer id="27"> | |||
<fo:table-row id="28"> | |||
<fo:table-cell id="29" border="2pt solid black" padding="2pt 2pt 0"> | |||
<fo:block id="30">Footer 1.1</fo:block> | |||
</fo:table-cell> | |||
<fo:table-cell id="31" border="2pt solid black" padding="2pt 2pt 0"> | |||
<fo:block id="32">Footer 1.2</fo:block> | |||
</fo:table-cell> | |||
</fo:table-row> | |||
</fo:table-footer> | |||
<fo:table-body id="33"> | |||
<fo:table-row id="34"> | |||
<fo:table-cell id="35" border="1pt solid black" padding="2pt 2pt 0"> | |||
<fo:block id="36">Cell 1.1</fo:block> | |||
</fo:table-cell> | |||
<fo:table-cell id="37" border="1pt solid black" padding="2pt 2pt 0"> | |||
<fo:block id="38">Cell 1.2</fo:block> | |||
</fo:table-cell> | |||
</fo:table-row> | |||
<fo:table-row id="39"> | |||
<fo:table-cell id="40" border="1pt solid black" padding="2pt 2pt 0"> | |||
<fo:block id="41">Cell 2.1</fo:block> | |||
</fo:table-cell> | |||
<fo:table-cell id="42" border="1pt solid black" padding="2pt 2pt 0"> | |||
<fo:block id="43">Cell 2.2</fo:block> | |||
</fo:table-cell> | |||
</fo:table-row> | |||
</fo:table-body> | |||
</fo:table> | |||
<fo:block-container id="44" space-before="1.2em"> | |||
<fo:block-container id="45" absolute-position="absolute" top="6pt" right="2.5pt" | |||
inline-progression-dimension="37%" padding="3pt 1pt 2pt 3pt" border="1.5pt solid | |||
darkblue"> | |||
<fo:block id="46" color="darkblue" font-size="80%">This is an absolutely positioned | |||
block-container. Nullam interdum mattis ipsum sit amet molestie.</fo:block> | |||
</fo:block-container> | |||
<fo:block id="47" end-indent="37% + 15pt">Lorem ipsum dolor sit amet, consectetur adipiscing | |||
elit. Integer vel lacinia diam. Etiam venenatis magna vel libero imperdiet | |||
rhoncus.</fo:block> | |||
</fo:block-container> | |||
</fo:flow> | |||
</fo:page-sequence> | |||
<fo:page-sequence master-reference="page"> | |||
<fo:static-content id="48" flow-name="xsl-region-before"> | |||
<fo:block id="49" font-size="7pt" text-align-last="justify" padding-bottom="2pt" | |||
border-bottom="0.25pt solid black">This is the page header<fo:leader id="50"/>Page | |||
<fo:page-number id="51"/></fo:block> | |||
</fo:static-content> | |||
<fo:flow flow-name="xsl-region-body" text-align="justify" space-before.minimum="8pt" | |||
space-before.optimum="10pt" space-before.maximum="12pt"> | |||
<fo:block id="second-start">Starting a new page-sequence.</fo:block> | |||
<fo:block id="52" text-align="center">The <fo:external-graphic id="53" | |||
src="test/resources/images/fop-logo-color-24bit.png" | |||
inline-progression-dimension.maximum="50%" content-width="scale-to-fit" | |||
alignment-adjust="-46%" alignment-baseline="middle" fox:alt-text="FOP Logo"/> | |||
logo.</fo:block> | |||
<fo:list-block id="54" provisional-distance-between-starts="15pt" | |||
provisional-label-separation="0" space-before="inherit"> | |||
<fo:list-item id="55"> | |||
<fo:list-item-label id="56" end-indent="label-end()"> | |||
<fo:block id="57">1.</fo:block> | |||
</fo:list-item-label> | |||
<fo:list-item-body id="58" start-indent="body-start()"> | |||
<fo:block id="59">First item of a list</fo:block> | |||
</fo:list-item-body> | |||
</fo:list-item> | |||
<fo:list-item id="60"> | |||
<fo:list-item-label id="61" end-indent="label-end()"> | |||
<fo:block id="62">2.</fo:block> | |||
</fo:list-item-label> | |||
<fo:list-item-body id="63" start-indent="body-start()"> | |||
<fo:block id="64">Second item of a list</fo:block> | |||
</fo:list-item-body> | |||
</fo:list-item> | |||
<fo:list-item id="65"> | |||
<fo:list-item-label id="66" end-indent="label-end()"> | |||
<fo:block id="67">3.</fo:block> | |||
</fo:list-item-label> | |||
<fo:list-item-body id="68" start-indent="body-start()"> | |||
<fo:block id="69">Third item of a list</fo:block> | |||
</fo:list-item-body> | |||
</fo:list-item> | |||
</fo:list-block> | |||
<fo:block id="70" text-align="center"><fo:instream-foreign-object id="71" | |||
inline-progression-dimension.maximum="50%" content-width="scale-to-fit"> | |||
<svg xmlns="http://www.w3.org/2000/svg" width="319" height="286.6"> | |||
<g style="fill-opacity:0.7; stroke:black; stroke-width:3" | |||
transform="translate(0, 286.6) scale(1, -1) translate(100, 100)"> | |||
<circle cx="50" cy="86.6" r="80" style="fill:red;"/> | |||
<circle cx="0" cy="0" r="80" style="fill:green;"/> | |||
<circle cx="100" cy="0" r="80" style="fill:blue;"/> | |||
</g> | |||
</svg> | |||
</fo:instream-foreign-object></fo:block> | |||
<fo:block id="72" space-before="inherit">A block containing an <fo:inline id="73" | |||
border="0.5pt solid black" padding="2pt" padding-bottom="0">inline</fo:inline> | |||
element.</fo:block> | |||
<fo:block id="74" space-before="inherit">A block containing a fancy <fo:character id="75" | |||
border="1pt solid black" padding="0 2pt 1pt 2pt" font-family="Symbol" character="♦"/> | |||
character.</fo:block> | |||
<fo:block id="76" space-before="inherit" text-align-last="justify">A leader with special | |||
content: <fo:leader id="77" leader-pattern="use-content"><fo:inline id="78"><fo:character | |||
id="79" character=" "/><fo:inline id="80" border="0.5pt solid black" | |||
padding-left="2pt" padding-right="2pt"><fo:character id="81" baseline-shift="-10%" | |||
character="•"/></fo:inline></fo:inline></fo:leader>.</fo:block> | |||
<fo:block id="second-end" space-before="inherit">Ending the page-sequence.</fo:block> | |||
</fo:flow> | |||
</fo:page-sequence> | |||
</fo:root> |
@@ -0,0 +1,522 @@ | |||
/* | |||
* 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.fo; | |||
import static org.junit.Assert.assertArrayEquals; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerConfigurationException; | |||
import javax.xml.transform.TransformerException; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.sax.SAXResult; | |||
import javax.xml.transform.stream.StreamSource; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.xml.sax.Attributes; | |||
import org.xml.sax.SAXException; | |||
import org.xml.sax.helpers.DefaultHandler; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.fo.FODocumentParser.FOEventHandlerFactory; | |||
import org.apache.fop.fo.flow.BasicLink; | |||
import org.apache.fop.fo.flow.Block; | |||
import org.apache.fop.fo.flow.BlockContainer; | |||
import org.apache.fop.fo.flow.Character; | |||
import org.apache.fop.fo.flow.ExternalGraphic; | |||
import org.apache.fop.fo.flow.Footnote; | |||
import org.apache.fop.fo.flow.FootnoteBody; | |||
import org.apache.fop.fo.flow.Inline; | |||
import org.apache.fop.fo.flow.InstreamForeignObject; | |||
import org.apache.fop.fo.flow.Leader; | |||
import org.apache.fop.fo.flow.ListBlock; | |||
import org.apache.fop.fo.flow.ListItem; | |||
import org.apache.fop.fo.flow.ListItemBody; | |||
import org.apache.fop.fo.flow.ListItemLabel; | |||
import org.apache.fop.fo.flow.PageNumber; | |||
import org.apache.fop.fo.flow.PageNumberCitation; | |||
import org.apache.fop.fo.flow.PageNumberCitationLast; | |||
import org.apache.fop.fo.flow.Wrapper; | |||
import org.apache.fop.fo.flow.table.Table; | |||
import org.apache.fop.fo.flow.table.TableBody; | |||
import org.apache.fop.fo.flow.table.TableCell; | |||
import org.apache.fop.fo.flow.table.TableColumn; | |||
import org.apache.fop.fo.flow.table.TableFooter; | |||
import org.apache.fop.fo.flow.table.TableHeader; | |||
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.StaticContent; | |||
/** | |||
* Tests that {@link DelegatingFOEventHandler} does forward every event to its delegate | |||
* event handler. | |||
*/ | |||
public class DelegatingFOEventHandlerTestCase { | |||
private InputStream document; | |||
private List<String> expectedEvents; | |||
private List<String> actualEvents; | |||
private FODocumentParser documentParser; | |||
private class DelegatingFOEventHandlerTester extends FOEventHandler { | |||
DelegatingFOEventHandlerTester(FOUserAgent foUserAgent) { | |||
super(foUserAgent); | |||
} | |||
private final StringBuilder eventBuilder = new StringBuilder(); | |||
@Override | |||
public void startDocument() throws SAXException { | |||
actualEvents.add("start root"); | |||
} | |||
@Override | |||
public void endDocument() throws SAXException { | |||
actualEvents.add("end root"); | |||
} | |||
@Override | |||
public void startPageSequence(PageSequence pageSeq) { | |||
startElement(pageSeq); | |||
} | |||
@Override | |||
public void endPageSequence(PageSequence pageSeq) { | |||
endElement(pageSeq); | |||
} | |||
@Override | |||
public void startPageNumber(PageNumber pagenum) { | |||
startElement(pagenum); | |||
} | |||
@Override | |||
public void endPageNumber(PageNumber pagenum) { | |||
endElement(pagenum); | |||
} | |||
@Override | |||
public void startPageNumberCitation(PageNumberCitation pageCite) { | |||
startElement(pageCite); | |||
} | |||
@Override | |||
public void endPageNumberCitation(PageNumberCitation pageCite) { | |||
endElement(pageCite); | |||
} | |||
@Override | |||
public void startPageNumberCitationLast(PageNumberCitationLast pageLast) { | |||
startElement(pageLast); | |||
} | |||
@Override | |||
public void endPageNumberCitationLast(PageNumberCitationLast pageLast) { | |||
endElement(pageLast); | |||
} | |||
@Override | |||
public void startFlow(Flow fl) { | |||
startElement(fl); | |||
} | |||
@Override | |||
public void endFlow(Flow fl) { | |||
endElement(fl); | |||
} | |||
@Override | |||
public void startBlock(Block bl) { | |||
startElement(bl); | |||
} | |||
@Override | |||
public void endBlock(Block bl) { | |||
endElement(bl); | |||
} | |||
@Override | |||
public void startBlockContainer(BlockContainer blc) { | |||
startElement(blc); | |||
} | |||
@Override | |||
public void endBlockContainer(BlockContainer blc) { | |||
endElement(blc); | |||
} | |||
@Override | |||
public void startInline(Inline inl) { | |||
startElement(inl); | |||
} | |||
@Override | |||
public void endInline(Inline inl) { | |||
endElement(inl); | |||
} | |||
@Override | |||
public void startTable(Table tbl) { | |||
startElement(tbl); | |||
} | |||
@Override | |||
public void endTable(Table tbl) { | |||
endElement(tbl); | |||
} | |||
@Override | |||
public void startColumn(TableColumn tc) { | |||
startElement(tc); | |||
} | |||
@Override | |||
public void endColumn(TableColumn tc) { | |||
endElement(tc); | |||
} | |||
@Override | |||
public void startHeader(TableHeader header) { | |||
startElement(header); | |||
} | |||
@Override | |||
public void endHeader(TableHeader header) { | |||
endElement(header); | |||
} | |||
@Override | |||
public void startFooter(TableFooter footer) { | |||
startElement(footer); | |||
} | |||
@Override | |||
public void endFooter(TableFooter footer) { | |||
endElement(footer); | |||
} | |||
@Override | |||
public void startBody(TableBody body) { | |||
startElement(body); | |||
} | |||
@Override | |||
public void endBody(TableBody body) { | |||
endElement(body); | |||
} | |||
@Override | |||
public void startRow(TableRow tr) { | |||
startElement(tr); | |||
} | |||
@Override | |||
public void endRow(TableRow tr) { | |||
endElement(tr); | |||
} | |||
@Override | |||
public void startCell(TableCell tc) { | |||
startElement(tc); | |||
} | |||
@Override | |||
public void endCell(TableCell tc) { | |||
endElement(tc); | |||
} | |||
@Override | |||
public void startList(ListBlock lb) { | |||
startElement(lb); | |||
} | |||
@Override | |||
public void endList(ListBlock lb) { | |||
endElement(lb); | |||
} | |||
@Override | |||
public void startListItem(ListItem li) { | |||
startElement(li); | |||
} | |||
@Override | |||
public void endListItem(ListItem li) { | |||
endElement(li); | |||
} | |||
@Override | |||
public void startListLabel(ListItemLabel listItemLabel) { | |||
startElement(listItemLabel); | |||
} | |||
@Override | |||
public void endListLabel(ListItemLabel listItemLabel) { | |||
endElement(listItemLabel); | |||
} | |||
@Override | |||
public void startListBody(ListItemBody listItemBody) { | |||
startElement(listItemBody); | |||
} | |||
@Override | |||
public void endListBody(ListItemBody listItemBody) { | |||
endElement(listItemBody); | |||
} | |||
@Override | |||
public void startStatic(StaticContent staticContent) { | |||
startElement(staticContent); | |||
} | |||
@Override | |||
public void endStatic(StaticContent statisContent) { | |||
endElement(statisContent); | |||
} | |||
@Override | |||
public void startLink(BasicLink basicLink) { | |||
startElement(basicLink); | |||
} | |||
@Override | |||
public void endLink(BasicLink basicLink) { | |||
endElement(basicLink); | |||
} | |||
@Override | |||
public void image(ExternalGraphic eg) { | |||
startElement(eg); | |||
endElement(eg); | |||
} | |||
@Override | |||
public void startInstreamForeignObject(InstreamForeignObject ifo) { | |||
startElement(ifo); | |||
} | |||
@Override | |||
public void endInstreamForeignObject(InstreamForeignObject ifo) { | |||
endElement(ifo); | |||
} | |||
@Override | |||
public void startFootnote(Footnote footnote) { | |||
startElement(footnote); | |||
} | |||
@Override | |||
public void endFootnote(Footnote footnote) { | |||
endElement(footnote); | |||
} | |||
@Override | |||
public void startFootnoteBody(FootnoteBody body) { | |||
startElement(body); | |||
} | |||
@Override | |||
public void endFootnoteBody(FootnoteBody body) { | |||
endElement(body); | |||
} | |||
@Override | |||
public void startLeader(Leader l) { | |||
startElement(l); | |||
} | |||
@Override | |||
public void endLeader(Leader l) { | |||
endElement(l); | |||
} | |||
@Override | |||
public void startWrapper(Wrapper wrapper) { | |||
startElement(wrapper); | |||
} | |||
@Override | |||
public void endWrapper(Wrapper wrapper) { | |||
endElement(wrapper); | |||
} | |||
@Override | |||
public void character(Character c) { | |||
startElement(c); | |||
endElement(c); | |||
} | |||
private void startElement(FObj node) { | |||
addEvent("start ", node); | |||
} | |||
private void endElement(FObj node) { | |||
addEvent("end ", node); | |||
} | |||
private void addEvent(String event, FObj node) { | |||
eventBuilder.append(event); | |||
eventBuilder.append(node.getLocalName()); | |||
addID(node); | |||
actualEvents.add(eventBuilder.toString()); | |||
eventBuilder.setLength(0); | |||
} | |||
private void addID(FObj node) { | |||
String id = node.getId(); | |||
if (id != null && id.length() > 0) { | |||
eventBuilder.append(" id=\""); | |||
eventBuilder.append(id); | |||
eventBuilder.append("\""); | |||
} | |||
} | |||
} | |||
@Before | |||
public void setUp() throws IOException { | |||
setUpEvents(); | |||
loadDocument(); | |||
createDocumentParser(); | |||
} | |||
private void setUpEvents() throws IOException { | |||
loadDocument(); | |||
loadExpectedEvents(); | |||
actualEvents = new ArrayList<String>(expectedEvents.size()); | |||
} | |||
private void loadDocument() { | |||
Class<?> clazz = getClass(); | |||
String documentName = clazz.getSimpleName() + ".fo"; | |||
document = clazz.getResourceAsStream(documentName); | |||
} | |||
private void loadExpectedEvents() throws IOException { | |||
expectedEvents = new ArrayList<String>(); | |||
InputStream xslt = getClass().getResourceAsStream("extract-events.xsl"); | |||
try { | |||
runXSLT(xslt); | |||
} finally { | |||
closeStream(xslt); | |||
closeStream(document); | |||
} | |||
} | |||
private void runXSLT(InputStream xslt) { | |||
Transformer transformer = createTransformer(xslt); | |||
Source fo = new StreamSource(document); | |||
Result result = createTransformOutputHandler(); | |||
try { | |||
transformer.transform(fo, result); | |||
} catch (TransformerException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
private Transformer createTransformer(InputStream xslt) { | |||
TransformerFactory transformerFactory = TransformerFactory.newInstance(); | |||
try { | |||
return transformerFactory.newTransformer(new StreamSource(xslt)); | |||
} catch (TransformerConfigurationException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
private Result createTransformOutputHandler() { | |||
return new SAXResult(new DefaultHandler() { | |||
private final StringBuilder event = new StringBuilder(); | |||
@Override | |||
public void startElement(String uri, String localName, String qName, | |||
Attributes attributes) throws SAXException { | |||
event.setLength(0); | |||
} | |||
@Override | |||
public void characters(char[] ch, int start, int length) throws SAXException { | |||
event.append(ch, start, length); | |||
} | |||
@Override | |||
public void endElement(String uri, String localName, String qName) throws SAXException { | |||
expectedEvents.add(event.toString()); | |||
} | |||
}); | |||
} | |||
private void closeStream(InputStream stream) { | |||
try { | |||
stream.close(); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
private void createDocumentParser() { | |||
documentParser = FODocumentParser.newInstance(new FOEventHandlerFactory() { | |||
public FOEventHandler newFOEventHandler(FOUserAgent foUserAgent) { | |||
return new DelegatingFOEventHandler( | |||
new DelegatingFOEventHandlerTester(foUserAgent)) { | |||
}; | |||
} | |||
}); | |||
} | |||
@Test | |||
public void testFOEventHandler() throws Exception { | |||
documentParser.parse(document); | |||
assertArrayEquals(expectedEvents.toArray(), actualEvents.toArray()); | |||
} | |||
@After | |||
public void unloadDocument() throws IOException { | |||
document.close(); | |||
} | |||
/** | |||
* Prints the given list to {@code System.out}, each element on a new line. For | |||
* debugging purpose. | |||
* | |||
* @param list a list | |||
*/ | |||
public void printList(List<?> list) { | |||
for (Object element : list) { | |||
System.out.println(element); | |||
} | |||
} | |||
} |
@@ -0,0 +1,145 @@ | |||
/* | |||
* 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.fo; | |||
import java.io.InputStream; | |||
import javax.xml.transform.Result; | |||
import javax.xml.transform.Source; | |||
import javax.xml.transform.Transformer; | |||
import javax.xml.transform.TransformerConfigurationException; | |||
import javax.xml.transform.TransformerException; | |||
import javax.xml.transform.TransformerFactory; | |||
import javax.xml.transform.sax.SAXResult; | |||
import javax.xml.transform.stream.StreamSource; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.Fop; | |||
import org.apache.fop.apps.FopFactory; | |||
import org.apache.fop.events.EventListener; | |||
/** | |||
* Parse an FO document and run the corresponding FO events through a given | |||
* {@link FOEventHandler} instance. That instance is created using the helper | |||
* {@link FOEventHandlerFactory}. | |||
* | |||
* <p>An instance of this class may not be used in multiple threads concurrently.<p> | |||
* | |||
* <p>An instance of this class may be used multiple times if the given | |||
* {@link FOEventHandler} implementation can be used multiple times. | |||
*/ | |||
public final class FODocumentParser { | |||
private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(); | |||
private static final FopFactory FOP_FACTORY = FopFactory.newInstance(); | |||
private final FOEventHandlerFactory foEventHandlerFactory; | |||
private Fop fop; | |||
private Transformer transformer; | |||
private EventListener eventListener; | |||
/** | |||
* A factory to create custom instances of {@link FOEventHandler}. | |||
*/ | |||
public static interface FOEventHandlerFactory { | |||
/** | |||
* Creates a new {@code FOEventHandler} instance parameterized with the given FO user agent. | |||
* | |||
* @param foUserAgent an FO user agent | |||
* @return a new {@code FOEventHandler} instance | |||
*/ | |||
FOEventHandler newFOEventHandler(FOUserAgent foUserAgent); | |||
} | |||
private FODocumentParser(FOEventHandlerFactory foeEventHandlerFactory) { | |||
this.foEventHandlerFactory = foeEventHandlerFactory; | |||
} | |||
/** | |||
* Creates and returns a new FO document parser. The given factory will be used to | |||
* customize the handler that will receive FO events, using the | |||
* {@link FOUserAgent#setFOEventHandlerOverride(FOEventHandler)} method. | |||
* | |||
* @param foEventHandlerFactory the factory to be used to create {@code | |||
* FOEventHandler} instances | |||
* @return a new parser | |||
*/ | |||
public static FODocumentParser newInstance(FOEventHandlerFactory foEventHandlerFactory) { | |||
return new FODocumentParser(foEventHandlerFactory); | |||
} | |||
/** | |||
* Sets the event listener to be used if events occurs when parsing the document. | |||
* | |||
* @param eventListener an event listener | |||
*/ | |||
public void setEventListener(EventListener eventListener) { | |||
this.eventListener = eventListener; | |||
} | |||
/** | |||
* Runs FOP on the given document. | |||
* | |||
* @param document XSL-FO document to parse | |||
* @throws FOPException if an error occurs when initializing FOP | |||
* @throws LoadingException if an error occurs when parsing the document | |||
*/ | |||
public void parse(InputStream document) throws FOPException, LoadingException { | |||
FOUserAgent foUserAgent = createFOUserAgent(); | |||
fop = FOP_FACTORY.newFop(foUserAgent); | |||
createTransformer(); | |||
runTransformer(document); | |||
} | |||
private FOUserAgent createFOUserAgent() { | |||
FOUserAgent userAgent = FOP_FACTORY.newFOUserAgent(); | |||
FOEventHandler foEventHandler = foEventHandlerFactory.newFOEventHandler(userAgent); | |||
userAgent.setFOEventHandlerOverride(foEventHandler); | |||
if (eventListener != null) { | |||
userAgent.getEventBroadcaster().addEventListener(eventListener); | |||
} | |||
return userAgent; | |||
} | |||
private void createTransformer() { | |||
try { | |||
transformer = TRANSFORMER_FACTORY.newTransformer(); | |||
} catch (TransformerConfigurationException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
private void runTransformer(InputStream input) throws LoadingException, FOPException { | |||
Source source = new StreamSource(input); | |||
Result result = new SAXResult(fop.getDefaultHandler()); | |||
try { | |||
transformer.transform(source, result); | |||
} catch (TransformerException e) { | |||
Throwable cause = e.getCause(); | |||
throw new LoadingException(cause == null ? e : cause); | |||
} | |||
} | |||
} |
@@ -0,0 +1,88 @@ | |||
/* | |||
* 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.fo; | |||
import static org.mockito.Matchers.any; | |||
import static org.mockito.Matchers.anyString; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import java.io.IOException; | |||
import org.apache.xmlgraphics.image.loader.ImageException; | |||
import org.apache.xmlgraphics.image.loader.ImageManager; | |||
import org.apache.xmlgraphics.image.loader.ImageSessionContext; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.FopFactory; | |||
/** | |||
* A helper class for creating mocks of {@link FONode} and its descendants. | |||
*/ | |||
public final class FONodeMocks { | |||
private FONodeMocks() { } | |||
/** | |||
* Creates and returns a mock {@link FONode} configured with a mock | |||
* {@link FOEventHandler}. The FO event handler returns a mock {@link FOUserAgent}, | |||
* which in turn returns a mock {@link FopFactory}, which returns a mock | |||
* {@link ImageManager}. | |||
* | |||
* @return a mock FO node | |||
*/ | |||
public static FONode mockFONode() { | |||
FONode mockFONode = mock(FONode.class); | |||
mockGetFOEventHandler(mockFONode); | |||
return mockFONode; | |||
} | |||
private static void mockGetFOEventHandler(FONode mockFONode) { | |||
FOEventHandler mockFOEventHandler = mock(FOEventHandler.class); | |||
mockGetUserAgent(mockFOEventHandler); | |||
when(mockFONode.getFOEventHandler()).thenReturn(mockFOEventHandler); | |||
} | |||
private static void mockGetUserAgent(FOEventHandler mockFOEventHandler) { | |||
FOUserAgent mockFOUserAgent = mock(FOUserAgent.class); | |||
mockGetFactory(mockFOUserAgent); | |||
when(mockFOEventHandler.getUserAgent()).thenReturn(mockFOUserAgent); | |||
} | |||
private static void mockGetFactory(FOUserAgent mockFOUserAgent) { | |||
FopFactory mockFopFactory = mock(FopFactory.class); | |||
mockGetImageManager(mockFopFactory); | |||
when(mockFOUserAgent.getFactory()).thenReturn(mockFopFactory); | |||
} | |||
private static void mockGetImageManager(FopFactory mockFopFactory) { | |||
try { | |||
ImageManager mockImageManager = mock(ImageManager.class); | |||
when(mockImageManager.getImageInfo(anyString(), any(ImageSessionContext.class))) | |||
.thenReturn(null); | |||
when(mockFopFactory.getImageManager()).thenReturn(mockImageManager); | |||
} catch (ImageException e) { | |||
throw new RuntimeException(e); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
/* | |||
* 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.fo; | |||
/** | |||
* This class specifies an exceptional condition that occurred while an XSL-FO document | |||
* was being parsed. | |||
*/ | |||
public class LoadingException extends Exception { | |||
private static final long serialVersionUID = 7529029475875542916L; | |||
LoadingException(Throwable cause) { | |||
super(cause); | |||
} | |||
} |