mirror of
https://github.com/apache/xmlgraphics-fop.git
synced 2024-09-14 00:01:49 +02:00
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
This commit is contained in:
parent
7859b3ed2d
commit
444ea54c14
@ -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);
|
||||
}
|
@ -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>
|
@ -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 Attributes pageSequenceAttributes;
|
||||
|
||||
private final class StructureTreeBuilderWrapper extends DelegatingContentHandler {
|
||||
|
||||
private Attributes pageSequenceAttributes;
|
||||
|
||||
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 {
|
||||
|
@ -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 Attributes pageSequenceAttributes;
|
||||
|
||||
private final class StructureTreeBuilderWrapper extends DelegatingContentHandler {
|
||||
|
||||
private Attributes pageSequenceAttributes;
|
||||
|
||||
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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user