Subject: [PATCH 01/20] container element for structure tree --- .../apache/fop/accessibility/StructureElement.java | 115 ++++++++++++++++++++ 1 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 src/java/org/apache/fop/accessibility/StructureElement.java diff --git a/src/java/org/apache/fop/accessibility/StructureElement.java b/src/java/org/apache/fop/accessibility/StructureElement.java new file mode 100644 index 0000000..f74d06b --- /dev/null +++ b/src/java/org/apache/fop/accessibility/StructureElement.java @@ -0,0 +1,115 @@ +/* + * 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.util.ArrayList; +import java.util.List; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +import org.apache.fop.util.XMLUtil; + +/** + * A reduced version of the document's FO tree element, containing only its logical + * structure. Used by accessible output formats. + */ +public final class StructureElement { + + private static final String FO = "http://www.w3.org/1999/XSL/Format"; + private static final String FOX = "http://xmlgraphics.apache.org/fop/extensions"; + private static final String FOI = "http://xmlgraphics.apache.org/fop/internal"; + + protected String name; + protected String ptr; + protected String role; + protected String alttext; + + protected List children; + + public StructureElement(String name) { + this.name = name; + children = new ArrayList(); + } + + public void setName(String name) { + this.name = name; + } + + public void setPtr(String ptr) { + this.ptr = ptr; + } + + public void setRole(String role) { + if ("none".equals(role)) + this.role = null; + else + this.role = role; + } + + public void setAltText(String alttext) { + this.alttext = alttext; + } + + public String getName() { + return name; + } + + public String getPtr() { + return ptr; + } + + public String getRole() { + return role; + } + + public String getAltText() { + return alttext; + } + + public int getLength() { + return children.size(); + } + + public void addChild(StructureElement e) { + children.add(e); + } + + public StructureElement getChild(int i) { + return (StructureElement)children.get(i); + } + + public void toXML(ContentHandler handler) throws SAXException { + AttributesImpl atts = new AttributesImpl(); + if (ptr != null) + atts.addAttribute(FOI, "ptr", "foi:ptr", XMLUtil.CDATA, ptr); + if (role != null) + atts.addAttribute(FO, "role", "fo:role", XMLUtil.CDATA, role); + if (alttext != null) + atts.addAttribute(FOX, "alt-text", "fox:alt-text", XMLUtil.CDATA, alttext); + + handler.startElement(FO, name, "fo:"+name, atts); + for(int i=0;i