diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2009-10-22 15:30:13 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2009-10-22 15:30:13 +0000 |
commit | 444ea54c14025e69be8a7e098a5b5de698d3fafc (patch) | |
tree | f7d470b6b4f11e2bc584c4810123f20011675c92 /src/java/org | |
parent | 7859b3ed2d10c712c35644164d7703192e3985d8 (diff) | |
download | xmlgraphics-fop-444ea54c14025e69be8a7e098a5b5de698d3fafc.tar.gz xmlgraphics-fop-444ea54c14025e69be8a7e098a5b5de698d3fafc.zip |
Issue an error when attempting to render an intermediate XML file in accessibility mode, but that file wasn't generated with accessibility (i.e., does not contain the structure tree)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@828747 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
4 files changed, 96 insertions, 10 deletions
diff --git a/src/java/org/apache/fop/accessibility/AccessibilityEventProducer.java b/src/java/org/apache/fop/accessibility/AccessibilityEventProducer.java new file mode 100644 index 000000000..9a74b7ca8 --- /dev/null +++ b/src/java/org/apache/fop/accessibility/AccessibilityEventProducer.java @@ -0,0 +1,54 @@ +/* + * 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 org.apache.fop.events.EventBroadcaster; +import org.apache.fop.events.EventProducer; + +/** + * Event producer for accessibility-related events. + */ +public interface AccessibilityEventProducer extends EventProducer { + + /** Provider class for the event producer. */ + public final class Provider { + + private Provider() { } + + /** + * Returns an event producer. + * + * @param broadcaster the event broadcaster to use + * @return the event producer + */ + public static AccessibilityEventProducer get(EventBroadcaster broadcaster) { + return (AccessibilityEventProducer) broadcaster.getEventProducerFor( + AccessibilityEventProducer.class); + } + } + + /** + * The structure tree is missing in the XML file. + * + * @param source the event source + * @event.severity FATAL + */ + void noStructureTreeInXML(Object source); +} diff --git a/src/java/org/apache/fop/accessibility/AccessibilityEventProducer.xml b/src/java/org/apache/fop/accessibility/AccessibilityEventProducer.xml new file mode 100644 index 000000000..70466c2e9 --- /dev/null +++ b/src/java/org/apache/fop/accessibility/AccessibilityEventProducer.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<catalogue xml:lang="en"> + <message key="org.apache.fop.accessibility.AccessibilityEventProducer.noStructureTreeInXML">Accessibility is enabled but structure tree is missing in XML file. Please disable accessibility, or re-generate XML file in accessibility mode.</message> +</catalogue> diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java index 784ca0684..ffffda7f4 100644 --- a/src/java/org/apache/fop/area/AreaTreeParser.java +++ b/src/java/org/apache/fop/area/AreaTreeParser.java @@ -57,6 +57,7 @@ import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.xmlgraphics.image.loader.ImageSessionContext; import org.apache.xmlgraphics.util.QName; +import org.apache.fop.accessibility.AccessibilityEventProducer; import org.apache.fop.accessibility.StructureTreeBuilder; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.area.Trait.Background; @@ -164,19 +165,19 @@ public class AreaTreeParser { private ContentHandler structureTreeBuilderWrapper; - private final class StructureTreeBuilderWrapper extends DelegatingContentHandler { + private Attributes pageSequenceAttributes; - private Attributes pageSequenceAttributes; + private final class StructureTreeBuilderWrapper extends DelegatingContentHandler { - private StructureTreeBuilderWrapper(Attributes pageSequenceAttributes) + private StructureTreeBuilderWrapper() throws SAXException { super(structureTreeBuilder.getHandlerForNextPageSequence()); - this.pageSequenceAttributes = new AttributesImpl(pageSequenceAttributes); } public void endDocument() throws SAXException { super.endDocument(); startAreaTreeElement("pageSequence", pageSequenceAttributes); + pageSequenceAttributes = null; } } @@ -297,7 +298,8 @@ public class AreaTreeParser { boolean handled = true; if ("".equals(uri)) { if (localName.equals("pageSequence") && userAgent.isAccessibilityEnabled()) { - structureTreeBuilderWrapper = new StructureTreeBuilderWrapper(attributes); + structureTreeBuilderWrapper = new StructureTreeBuilderWrapper(); + pageSequenceAttributes = new AttributesImpl(attributes); } else if (localName.equals("structureTree")) { if (userAgent.isAccessibilityEnabled()) { delegate = structureTreeBuilderWrapper; @@ -309,6 +311,18 @@ public class AreaTreeParser { delegate.startDocument(); delegate.startElement(uri, localName, qName, attributes); } else { + if (pageSequenceAttributes != null) { + /* + * This means that no structure-element tag was + * found in the XML, otherwise a + * StructureTreeBuilderWrapper object would have + * been created, which would have reset the + * pageSequenceAttributes field. + */ + AccessibilityEventProducer.Provider + .get(userAgent.getEventBroadcaster()) + .noStructureTreeInXML(this); + } handled = startAreaTreeElement(localName, attributes); } } else { diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java index 45b4816a5..da5d8a623 100644 --- a/src/java/org/apache/fop/render/intermediate/IFParser.java +++ b/src/java/org/apache/fop/render/intermediate/IFParser.java @@ -46,6 +46,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.xmlgraphics.util.QName; +import org.apache.fop.accessibility.AccessibilityEventProducer; import org.apache.fop.accessibility.StructureTreeBuilder; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fo.ElementMapping; @@ -155,19 +156,19 @@ public class IFParser implements IFConstants { private ContentHandler structureTreeBuilderWrapper; - private final class StructureTreeBuilderWrapper extends DelegatingContentHandler { + private Attributes pageSequenceAttributes; - private Attributes pageSequenceAttributes; + private final class StructureTreeBuilderWrapper extends DelegatingContentHandler { - private StructureTreeBuilderWrapper(Attributes pageSequenceAttributes) + private StructureTreeBuilderWrapper() throws SAXException { super(structureTreeBuilder.getHandlerForNextPageSequence()); - this.pageSequenceAttributes = new AttributesImpl(pageSequenceAttributes); } public void endDocument() throws SAXException { super.endDocument(); startIFElement(EL_PAGE_SEQUENCE, pageSequenceAttributes); + pageSequenceAttributes = null; } } @@ -227,7 +228,8 @@ public class IFParser implements IFConstants { boolean handled = true; if (NAMESPACE.equals(uri)) { if (localName.equals(EL_PAGE_SEQUENCE) && userAgent.isAccessibilityEnabled()) { - structureTreeBuilderWrapper = new StructureTreeBuilderWrapper(attributes); + pageSequenceAttributes = new AttributesImpl(attributes); + structureTreeBuilderWrapper = new StructureTreeBuilderWrapper(); } else if (localName.equals(EL_STRUCTURE_TREE)) { if (userAgent.isAccessibilityEnabled()) { delegate = structureTreeBuilderWrapper; @@ -239,6 +241,18 @@ public class IFParser implements IFConstants { delegate.startDocument(); delegate.startElement(uri, localName, qName, attributes); } else { + if (pageSequenceAttributes != null) { + /* + * This means that no structure-element tag was + * found in the XML, otherwise a + * StructureTreeBuilderWrapper object would have + * been created, which would have reset the + * pageSequenceAttributes field. + */ + AccessibilityEventProducer.Provider + .get(userAgent.getEventBroadcaster()) + .noStructureTreeInXML(this); + } handled = startIFElement(localName, attributes); } } else if (DocumentNavigationExtensionConstants.NAMESPACE.equals(uri)) { |