]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Added support for FO type to FoXMLEvent and related classes.
authorPeter Bernard West <pbwest@apache.org>
Thu, 24 Oct 2002 14:39:11 +0000 (14:39 +0000)
committerPeter Bernard West <pbwest@apache.org>
Thu, 24 Oct 2002 14:39:11 +0000 (14:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@195355 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/xml/FoXMLEvent.java [new file with mode: 0644]
src/org/apache/fop/xml/FoXMLSerialHandler.java [new file with mode: 0644]
src/org/apache/fop/xml/SyncedFoXmlEventsBuffer.java [new file with mode: 0644]
src/org/apache/fop/xml/SyncedXmlEventsBuffer.java [deleted file]
src/org/apache/fop/xml/XMLSerialHandler.java [deleted file]

diff --git a/src/org/apache/fop/xml/FoXMLEvent.java b/src/org/apache/fop/xml/FoXMLEvent.java
new file mode 100644 (file)
index 0000000..ee18b14
--- /dev/null
@@ -0,0 +1,91 @@
+package org.apache.fop.xml;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.FObjectNames;
+
+import org.xml.sax.helpers.AttributesImpl;
+
+/*
+ * $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ * @version $Revision$ $Name$
+ */
+/**
+ * This is a data class to encapsulate the data of an individual XML
+ * parse event in an XML-FO file. The current version, while defining
+ * accessor methods, leaves the component data of the event as protected.
+ * The <tt>XMLSerialHandler</tt> methods set the values directly.
+ */
+
+public class FoXMLEvent extends XMLEvent {
+
+    private static final String tag = "$Name$";
+    private static final String revision = "$Revision$";
+
+    /** The FO type, as defined in FObjectNames, of fo: XML events. */
+    protected int foType = FObjectNames.NO_FO;
+
+    /**
+     * The one-argument constructor uses the default initialization values:
+     * NOEVENT for the event <i>type</i>, and null references for all others
+     * except <i>namespaces</i>.
+     */
+    public FoXMLEvent (XMLNamespaces namespaces) {
+        super(namespaces);
+    }
+
+    /**
+     * The fully defined constructor takes values for each of the data
+     * elements.
+     */
+    public FoXMLEvent(int type, String chars, int uriIndex,
+                    String localName, String qName,
+                    AttributesImpl attributes, XMLNamespaces namespaces,
+                    int foType)
+    {
+        super
+            (type, chars, uriIndex, localName, qName, attributes, namespaces);
+        this.foType = foType;
+    }
+
+    /**
+     * The cloning constructor takes a reference to an existing
+     * <tt>FoXMLEvent</tt> object.
+     */
+    public FoXMLEvent(FoXMLEvent ev) {
+        super(ev);
+        foType = ev.foType;
+    }
+
+    public FoXMLEvent(int type, String chars, XMLNamespaces namespaces) {
+        super(type, chars, namespaces);
+    }
+
+    public FoXMLEvent(int type, int uriIndex, AttributesImpl attributes,
+                    XMLNamespaces namespaces, int foType) {
+        super(namespaces);
+        this.type = type;
+        this.uriIndex = uriIndex;
+        this.attributes = attributes;
+        this.foType = foType;
+    }
+
+    public int getFoType() { return foType; }
+
+    public void setFoType(int foType) { this.foType = foType; }
+
+    public String toString() {
+        String tstr;
+        try {
+            tstr = "FO type: " + FObjectNames.getFOName(foType) + "\n";
+        } catch (FOPException e) {
+            throw new RuntimeException(e.getMessage());
+        }
+        tstr = tstr + super.toString();
+        return tstr;
+    }
+
+}
diff --git a/src/org/apache/fop/xml/FoXMLSerialHandler.java b/src/org/apache/fop/xml/FoXMLSerialHandler.java
new file mode 100644 (file)
index 0000000..69c0b19
--- /dev/null
@@ -0,0 +1,209 @@
+package org.apache.fop.xml;
+
+import org.apache.fop.fo.FObjectNames;
+import org.apache.fop.xml.XMLNamespaces;
+import org.apache.fop.xml.SyncedFoXmlEventsBuffer;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.Driver;
+import org.apache.fop.configuration.Configuration;
+
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+
+import java.io.IOException;
+import java.util.NoSuchElementException;
+
+/*
+ * $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ *
+ * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ * @version $Revision$ $Name$
+ */
+/**
+ * <tt>FoXMLSerialHandler</tt> is the <tt>ContentHandler</tt> for the
+ * background <tt>XMLReader</tt> thread.
+ */
+
+public class FoXMLSerialHandler extends DefaultHandler implements Runnable {
+
+    private static final String tag = "$Name$";
+    private static final String revision = "$Revision$";
+
+    private SyncedFoXmlEventsBuffer events;
+    private XMLReader parser;
+    private XMLNamespaces namespaces;
+    private InputSource source;
+    private Thread foThread;
+    private boolean errorDump;
+
+    /**
+     * @param events the events buffer.
+     * @param parser the xml parser.
+     * @param source the parser input source.
+     */
+    public FoXMLSerialHandler
+        (SyncedFoXmlEventsBuffer events, XMLReader parser, InputSource source)
+    {
+        this.events = events;
+        this.parser = parser;
+        this.source = source;
+        namespaces = events.getNamespaces();
+        parser.setContentHandler(this);
+        errorDump = Configuration.getBooleanValue("debugMode").booleanValue();
+    }
+
+    public void setFoThread(Thread foThread) {
+        this.foThread = foThread;
+    }
+
+    /**
+     * This is the run method for the callback parser thread.
+     */
+    public void run() {
+        // I''m in the thread - run the parser
+        try {
+            parser.parse(source);
+            //System.out.println("Parser terminating.");
+        } catch (Exception e) {
+            if (errorDump) Driver.dumpError(e);
+            if (foThread != null) {
+                try {
+                    foThread.interrupt();
+                } catch (Exception ex) {} //ignore
+            }
+            throw new RuntimeException(e.getMessage());
+        }
+    }
+
+    /**
+     * Utility routine for the callback methods.  It captures the
+     * <tt>InterruptedException</tt> that is possible from the <i>put</i>
+     * method of a <tt>SyncedFoXmlEventsBuffer</tt>.
+     */
+    public void putEvent(FoXMLEvent event) throws NoSuchElementException {
+        synchronized (events) {
+            try {
+                events.put(event);
+            } catch (InterruptedException e) {
+                throw new RuntimeException
+                        ("Producer interrupted: " +e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * Callback routine for the parser.
+     */
+    public void startDocument() throws NoSuchElementException {
+        synchronized (events) {
+            FoXMLEvent event = new FoXMLEvent(namespaces);
+            //System.out.println("StartDocument thread "
+            //                   + Thread.currentThread().getName());
+            event.type = XMLEvent.STARTDOCUMENT;
+            //System.out.println("SerialHandler: " + event);
+            putEvent(event);
+        }
+    }
+
+    /**
+     * Callback routine for the parser.
+     */
+    public void endDocument() throws NoSuchElementException {
+        synchronized (events) {
+            FoXMLEvent event = new FoXMLEvent(namespaces);
+            //System.out.println("EndDocument thread "
+                               //+ Thread.currentThread().getName());
+            event.type = XMLEvent.ENDDOCUMENT;
+            //System.out.println("SerialHandler: " + event);
+            putEvent(event);
+            events.producerExhausted();
+        }
+    }
+
+    /**
+     * Callback routine for the parser.
+     * @param uri the URI of the element name
+     * @param localName the localname of the element
+     * @param qName the (prefix) qualified name of the element
+     * @param attributes the attribute set of the element, as an object
+     * implementing the <tt>Attributes</tt> interface.
+     */
+    public void startElement(String uri, String localName,
+                             String qName, Attributes attributes)
+        throws NoSuchElementException
+    {
+        synchronized (events) {
+            FoXMLEvent event = new FoXMLEvent(namespaces);
+            //System.out.println("StartElement thread "
+            //                   + Thread.currentThread().getName());
+            event.type = XMLEvent.STARTELEMENT;
+            // Is this from the fo: namespace?
+            event.uriIndex = namespaces.getURIIndex(uri);
+            if (event.uriIndex == XMLNamespaces.XSLNSpaceIndex) {
+                try {
+                    event.foType = FObjectNames.getFOIndex(localName);
+                } catch (FOPException e) {}
+            }
+            event.localName = localName;
+            event.qName = qName;
+            event.attributes = new AttributesImpl(attributes);
+            //System.out.println("SerialHandler: " + event);
+            putEvent(event);
+        }
+    }
+
+    /**
+     * Callback routine for parser.
+     * @param uri the URI of this element name
+     * @param localName the unqualified localname of this element
+     * @param qName the (prefix) qualified name of this element
+     */
+    public void endElement(String uri, String localName,
+                           String qName)
+        throws NoSuchElementException
+    {
+        synchronized (events) {
+            FoXMLEvent event = new FoXMLEvent(namespaces);
+            //System.out.println("EndElement thread "
+                               //+ Thread.currentThread().getName());
+            event.type = XMLEvent.ENDELEMENT;
+            event.uriIndex = namespaces.getURIIndex(uri);
+            if (event.uriIndex == XMLNamespaces.XSLNSpaceIndex) {
+                try {
+                    event.foType = FObjectNames.getFOIndex(localName);
+                } catch (FOPException e) {}
+            }
+            event.localName = localName;
+            event.qName = qName;
+            putEvent(event);
+        }
+    }
+
+    /**
+     * Callback routine for parser to handle characters.
+     * @param ch the array of characters
+     * @param start starting position of this set of characters in the
+     * <i>ch</i> array.
+     * @param length number of characters in this set
+     */
+    public void characters(char[] ch, int start, int length)
+        throws NoSuchElementException
+    {
+        synchronized (events) {
+            FoXMLEvent event = new FoXMLEvent(namespaces);
+            //System.out.println("characters thread "
+            //                   + Thread.currentThread().getName());
+            event.type = XMLEvent.CHARACTERS;
+            event.chars = new String(ch, start, length);
+            //System.out.println("SerialHandler: " + event);
+            putEvent(event);
+        }
+    }
+}
diff --git a/src/org/apache/fop/xml/SyncedFoXmlEventsBuffer.java b/src/org/apache/fop/xml/SyncedFoXmlEventsBuffer.java
new file mode 100644 (file)
index 0000000..e7f7790
--- /dev/null
@@ -0,0 +1,975 @@
+package org.apache.fop.xml;
+
+import org.apache.fop.datastructs.SyncedCircularBuffer;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.FObjectNames;
+
+import java.util.NoSuchElementException;
+import java.util.LinkedList;
+import java.util.Iterator;
+
+/*
+ * $Id$
+ * 
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ *
+ * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ * @version $Revision$ $Name$
+ */
+/**
+ * A synchronized circular buffer for FoXMLEvents.
+ * @see org.apache.fop.datastructs.SyncedCircularBuffer
+ */
+public class SyncedFoXmlEventsBuffer extends SyncedCircularBuffer {
+
+    /**
+     * Maintains an index of namespace URIs.  These can then be referred to
+     * by an <tt>int</tt> index.
+     */
+    private XMLNamespaces namespaces;
+
+    /**
+     * No-argument constructor sets up a buffer with the default number of
+     * elements.
+     * The producer and consumer <tt>Thread</tt>s default to the current
+     * thread at the time of instantiation.
+     */
+    public SyncedFoXmlEventsBuffer()
+        throws IllegalArgumentException
+    {
+        super();
+        namespaces = new XMLNamespaces();
+    }
+
+    /**
+     * Constructor taking one argument; the size of the buffer.
+     * @param size the size of the buffer.  Must be > 1.
+     */
+    public SyncedFoXmlEventsBuffer(int size)
+        throws IllegalArgumentException
+    {
+        super(size);
+        namespaces = new XMLNamespaces();
+    }
+
+    /**
+     * Get the <tt>XMLNamespaces</tt> from this buffer.
+     * @return - the namespaces object.
+     */
+    public XMLNamespaces getNamespaces() { return namespaces; }
+
+    /**
+     * @return next event from the SyncedCircularBuffer
+     * @exception FOPException.  The purpose of this method is to catch
+     * and transform any InterruptedException exceptions thrown by the
+     * <tt>SyncedCircularBuffer</tt>.
+     */
+    public FoXMLEvent getEvent() throws FOPException {
+        FoXMLEvent ev;
+        try {
+            ev = (FoXMLEvent)get();
+            //System.out.println("getEvent: " + ev);
+            return ev;
+        } catch (InterruptedException e) {
+            throw new FOPException(e);
+        }
+    }
+
+    /**
+     * Get the next event of the given type from the buffer.  Discard
+     * intervening events.
+     * @param eventType - the <tt>int</tt> event type.
+     * @return an event of the given type.
+     * @exception FOPException if buffer errors or interrupts occur.
+     * @exception NoSuchElementException if the event is not found.
+     */
+    public FoXMLEvent getTypedEvent(int eventType) throws FOPException {
+        FoXMLEvent ev = getEvent();
+        while (ev != null && ev.type != eventType) {
+            ev = getEvent();
+        }
+        if (ev == null) {
+            throw new NoSuchElementException
+                        (XMLEvent.eventTypeName(eventType) + " not found.");
+        }
+        return ev;
+    }
+
+    /**
+     * Get the next event of the given type and with the given <tt>QName</tt>
+     * from the buffer.  Discard intervening events.
+     * @param eventType - the <tt>int</tt> event type.
+     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
+     * required element.
+     * @return an event of the given type.
+     * @exception FOPException if buffer errors or interrupts occur.
+     * @exception NoSuchElementException if the event is not found.
+     */
+    public FoXMLEvent getTypedEvent(int eventType, String qName)
+                throws FOPException
+    {
+        FoXMLEvent ev = getEvent();
+        while (ev != null &&
+               ! (ev.type == eventType && ev.qName.equals(qName))) {
+            ev = getEvent();
+        }
+        if (ev == null) {
+            throw new NoSuchElementException
+            (XMLEvent.eventTypeName(eventType) + " " + qName + " not found.");
+        }
+        return ev;
+    }
+
+    /**
+     * Get the next event of the given type, and with the given URI index and
+     * local name, from the buffer.  Discard intervening events.
+     * @param eventType - the <tt>int</tt> event type.
+     * @param uriIndex - the <tt>int</tt> URI index maintained in the
+     * <tt>XMLNamespaces</tt> object.
+     * @param localName a <tt>String</tt> with the local name of the
+     * required element.
+     * @return an event of the given type.
+     * @exception FOPException if buffer errors or interrupts occur.
+     * @exception NoSuchElementException if the event is not found.
+     */
+    public FoXMLEvent getTypedEvent
+                            (int eventType, int uriIndex, String localName)
+                throws FOPException
+    {
+        FoXMLEvent ev = getEvent();
+        while (ev != null &&
+               ! (ev.type == eventType
+                  && ev.uriIndex == uriIndex
+                  && ev.localName.equals(localName))) {
+            ev = getEvent();
+        }
+        if (ev == null)
+            throw new NoSuchElementException
+                    (XMLEvent.eventTypeName(eventType)
+                             + namespaces.getIndexURI(uriIndex)
+                                       + ":" + localName + " not found.");
+        return ev;
+    }
+
+    /**
+     * Get the next event of the given type, from the fo: namespace, with
+     * the given FO type.  Discard intervening events.
+     * @param eventType - the <tt>int</tt> event type.
+     * @param foType - the <tt>int</tt> FO type.
+     * @return an event of the given type.
+     * @exception FOPException if buffer errors or interrupts occur.
+     * @exception NoSuchElementException if the event is not found.
+     */
+    public FoXMLEvent getTypedEvent(int eventType, int foType)
+                throws FOPException
+    {
+        FoXMLEvent ev = getEvent();
+        while (ev != null &&
+               ! (ev.type == eventType && ev.foType == foType)) {
+            ev = getEvent();
+        }
+        if (ev == null)
+            throw new NoSuchElementException
+                    (XMLEvent.eventTypeName(eventType)
+                             + " FO type " + foType + " not found.");
+        return ev;
+    }
+
+    /**
+     * Return the next element if it is of the required type.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param eventType - the <tt>int</tt> event type.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return an event of the required type.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur.
+     * @exception NoSuchElementException if the buffer is empty.
+     */
+    public FoXMLEvent expectTypedEvent
+                                    (int eventType, boolean discardWhiteSpace)
+                throws FOPException
+    {
+        FoXMLEvent ev = getEvent();
+        if (discardWhiteSpace) {
+            while (ev != null && ev.type == XMLEvent.CHARACTERS
+                   && ev.chars.trim().equals("")) {
+                ev = getEvent();
+            }
+        }
+        if (ev != null && ev.type == eventType) {
+            return ev;
+        }
+        if (ev == null)
+            throw new NoSuchElementException
+                        (XMLEvent.eventTypeName(eventType)
+                                           + " not found: end of buffer.");
+        pushBack(ev);
+        return null;
+    }
+
+    /**
+     * Return the next element if it is of the required type and has the
+     * required <tt>QName</tt>.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param eventType - the <tt>int</tt> event type.
+     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
+     * required element.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return an event of the required type.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur.
+     * @exception NoSuchElementException if the event is not found.
+     */
+    public FoXMLEvent expectTypedEvent
+                    (int eventType, String qName, boolean discardWhiteSpace)
+                throws FOPException
+    {
+        FoXMLEvent ev = getEvent();
+        if (discardWhiteSpace) {
+            while (ev != null && ev.type == XMLEvent.CHARACTERS
+                   && ev.chars.trim().equals("")) {
+                ev = getEvent();
+            }
+        }
+        if (ev != null && ev.type == eventType && ev.qName.equals(qName)) {
+            return ev;
+        }
+        if (ev == null)
+            throw new NoSuchElementException
+                        (XMLEvent.eventTypeName(eventType)
+                                           + " not found: end of buffer.");
+        pushBack(ev);
+        return null;
+    }
+
+    /**
+     * Return the next element if it is of the required type and has the
+     * required URI index and local name.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param eventType - the <tt>int</tt> event type.
+     * @param uriIndex - the <tt>int</tt> URI index.
+     * @param localName a <tt>String</tt> with the local name of the
+     * required element.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return an event of the required type.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur.
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectTypedEvent
+                            (int eventType, int uriIndex,
+                                 String localName, boolean discardWhiteSpace)
+                throws FOPException
+    {
+        FoXMLEvent ev = getEvent();
+        if (discardWhiteSpace) {
+            while (ev != null && ev.type == XMLEvent.CHARACTERS
+                   && ev.chars.trim().equals("")) {
+                ev = getEvent();
+            }
+        }
+        if (ev != null
+                && ev.type == eventType
+                   && ev.uriIndex == uriIndex
+                       && ev.localName.equals(localName)) {
+            return ev;
+        }
+        if (ev == null)
+            throw new NoSuchElementException
+                        (XMLEvent.eventTypeName(eventType)
+                                           + " not found: end of buffer.");
+        pushBack(ev);
+        return null;
+    }
+
+    /**
+     * Return the next element if it is of the required type and has the
+     * required FO type.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param eventType - the <tt>int</tt> event type.
+     * @param foType - the <tt>int</tt> FO type.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return an event of the required type.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur.
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectTypedEvent
+                    (int eventType, int foType, boolean discardWhiteSpace)
+                throws FOPException
+    {
+        FoXMLEvent ev = getEvent();
+        if (discardWhiteSpace) {
+            while (ev != null && ev.type == XMLEvent.CHARACTERS
+                   && ev.chars.trim().equals("")) {
+                ev = getEvent();
+            }
+        }
+        if (ev != null && ev.type == eventType && ev.foType == foType) {
+            return ev;
+        }
+        if (ev == null)
+            throw new NoSuchElementException
+                        (XMLEvent.eventTypeName(eventType)
+                                           + " not found: end of buffer.");
+        pushBack(ev);
+        return null;
+    }
+
+    /**
+     * Get the next ENDDOCUMENT event from the buffer.  Discard any other
+     * events preceding the ENDDOCUMENT event.
+     * @return an ENDDOCUMENT event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getEndDocument() throws FOPException {
+        return getTypedEvent(XMLEvent.ENDDOCUMENT);
+    }
+
+    /**
+     * Return the next element if it is an ENDDOCUMENT.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return an ENDDOCUMENT event. If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectEndDocument(boolean discardWhiteSpace)
+                throws FOPException
+    {
+        return expectTypedEvent(XMLEvent.ENDDOCUMENT, discardWhiteSpace);
+    }
+
+    /**
+     * Get the next STARTELEMENT event from the buffer.  Discard any other
+     * events preceding the STARTELEMENT event.
+     * @return a STARTELEMENT event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getStartElement() throws FOPException {
+        return getTypedEvent(XMLEvent.STARTELEMENT);
+    }
+
+    /**
+     * Return the next element if it is a STARTELEMENT.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a STARTELEMENT event.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectStartElement(boolean discardWhiteSpace)
+                throws FOPException
+    {
+        return expectTypedEvent(XMLEvent.STARTELEMENT, discardWhiteSpace);
+    }
+
+    /**
+     * Get the next STARTELEMENT event with the given <tt>QName</tt>
+     * from the buffer.  Discard any other events preceding the
+     * STARTELEMENT event.
+     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
+     * required STARTELEMENT
+     * @return a STARTELEMENT event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getStartElement(String qName) throws FOPException
+    {
+        return getTypedEvent(XMLEvent.STARTELEMENT, qName);
+    }
+
+    /**
+     * Return the next element if it is a STARTELEMENT with the given
+     * <tt>QName</tt>.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
+     * required STARTELEMENT
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a STARTELEMENT event.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectStartElement
+                                (String qName, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        return expectTypedEvent
+                        (XMLEvent.STARTELEMENT, qName, discardWhiteSpace);
+    }
+
+    /**
+     * Get the next STARTELEMENT event with the given URI index and local name
+     * from the buffer.  Discard any other events preceding the
+     * STARTELEMENT event.
+     * @param uriIndex an <tt>int</tt> with the index of the URI of the
+     * required URI
+     * @param localName a <tt>String</tt> with the local name of the
+     * required STARTELEMENT
+     * @return a STARTELEMENT event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getStartElement(int uriIndex, String localName)
+        throws FOPException
+    {
+        return getTypedEvent(XMLEvent.STARTELEMENT, uriIndex, localName);
+    }
+
+    /**
+     * Return the next element if it is a STARTELEMENT with the given
+     * URI index and local name.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param uriIndex an <tt>int</tt> URI index.
+     * @param localName a <tt>String</tt> with the local name of the
+     * required STARTELEMENT
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a STARTELEMENT event.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectStartElement
+                (int uriIndex, String localName, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        return expectTypedEvent
+            (XMLEvent.STARTELEMENT, uriIndex, localName, discardWhiteSpace);
+    }
+
+    /**
+     * From the buffer get the next STARTELEMENT event from the fo: namespace
+     * with the given FO object type.
+     *  Discard any other events preceding the
+     * STARTELEMENT event.
+     * @param foType - the <tt>int</tt> FO object type, as defined in
+     * <tt>FObjectNames</tt>.
+     * @return a matching STARTELEMENT event.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getStartElement(int foType)
+        throws FOPException
+    {
+        return getTypedEvent(XMLEvent.STARTELEMENT, foType);
+    }
+
+    /**
+     * From the buffer return the next STARTELEMENT event from the fo:
+     * namespace with the given FO object type.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param foType - the <tt>int</tt> FO object type, as defined in
+     * <tt>FObjectNames</tt>.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a matching STARTELEMENT event.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectStartElement
+                                    (int foType, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        return expectTypedEvent
+            (XMLEvent.STARTELEMENT, foType, discardWhiteSpace);
+    }
+
+    /**
+     * Get one of a list of possible STARTELEMENT events.
+     * @param list a <tt>LinkedList</tt> containing either <tt>String</tt>s
+     * with the <tt>QName</tt>, or <tt>UriLocalName</tt>
+     * objects with the URI index and local name of one of the required
+     * STARTELEMENT events.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a STARTELEMENT event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getStartElement
+                                (LinkedList list, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        do {
+            ev = expectStartElement(list, discardWhiteSpace);
+            if (ev != null) return ev;
+            // The non-matching event has been pushed back.
+            // Get it and discard.  Note that if the first attempt to
+            // getEvent() returns null, the expectStartElement() calls
+            // return null.
+            ev = getEvent();
+        } while (ev != null);
+        // Exit from this while loop is only by discovery of null event
+        throw new NoSuchElementException
+                    ("StartElement from list not found.");
+    }
+
+    /**
+     * Get one of a list of possible STARTELEMENT events.
+     * @param list a <tt>LinkedList</tt> containing either <tt>String</tt>s
+     * with the <tt>QName</tt>, or <tt>UriLocalName</tt>
+     * objects with the URI index and local name of one of the required
+     * STARTELEMENT events.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a STARTELEMENT event.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectStartElement
+                                (LinkedList list, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        Iterator elements = list.iterator();
+        while (elements.hasNext()) {
+            Object o = elements.next();
+            if (o instanceof String) {
+                ev = expectStartElement((String) o, discardWhiteSpace);
+                // Found it!
+                if (ev != null) return ev;
+            } else if (o instanceof UriLocalName) {
+                ev = expectStartElement
+                        (((UriLocalName) o).uriIndex,
+                         ((UriLocalName) o).localName,
+                         discardWhiteSpace);
+                // Found it!
+                if (ev != null) return ev;
+            } else if (o instanceof Integer) {
+                ev = expectStartElement(((Integer)o).intValue(),
+                                        discardWhiteSpace);
+                if (ev != null) return ev;
+            } else
+                throw new FOPException
+                        ("Invalid list elements for getStartElement");
+        }
+        return null;
+    }
+
+    /**
+     * Get one of a array of possible STARTELEMENT events.  Scan and discard
+     * events until a STARTELEMENT event is found whose URI index and
+     * local name matches one of those in the argument
+     * <tt>UriLocalName[]</tt> array.
+     * @param list an array containing <tt>UriLocalName</tt>
+     * objects with the URI index and local name of
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * STARTELEMENT events, one of which is required.
+     * @return the next matching STARTELEMENT event from the buffer.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getStartElement
+                    (UriLocalName[] list, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        do {
+            ev = expectStartElement(list, discardWhiteSpace);
+            if (ev != null) return ev;
+            // The non-matching event has been pushed back.
+            // Get it and discard.  Note that if the first attempt to
+            // getEvent() returns null, the expectStartElement() calls
+            // will throw a NoSuchElementException
+            ev = getEvent();
+        } while (ev != null);
+        // Exit from this while loop is only by discovery of null event
+        throw new NoSuchElementException
+                    ("StartElement from list not found.");
+    }
+
+    /**
+     * Expect one of an array of possible STARTELEMENT events.  The next
+     * STARTELEMENT must have a URI index and local name which match
+     * an element of the argument <tt>UriLocalName[]</tt> list.
+     * @param list an <tt>UriLocalName[]</tt> array containing the
+     * namespace Uri index and LocalName
+     * of possible events, one of which must be the next returned.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return the matching STARTELEMENT event. If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectStartElement
+                    (UriLocalName[] list, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        for (int i = 0; i < list.length; i++) {
+            ev = expectStartElement(list[i].uriIndex,
+                                    list[i].localName,
+                                    discardWhiteSpace);
+            // Found it!
+            if (ev != null) return ev;
+        }
+        return null;
+    }
+
+    /**
+     * Get one of a array of possible STARTELEMENT events.  Scan and discard
+     * events until a STARTELEMENT event is found whose <tt>QName</tt>
+     * matches one of those in the argument <tt>String[]</tt> array.
+     * @param list a <tt>String[]</tt> array containing <tt>QName</tt>s,
+     * one of which is required.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return the next matching STARTELEMENT event from the buffer.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getStartElement(String[] list, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        do {
+            ev = expectStartElement(list, discardWhiteSpace);
+            if (ev != null) return ev;
+            // The non-matching event has been pushed back.
+            // Get it and discard.  Note that if the first attempt to
+            // getEvent() returns null, the expectStartElement() calls
+            // will throw a NoSuchElementException
+            ev = getEvent();
+        } while (ev != null);
+        // Exit from this while loop is only by discovery of null event
+        throw new NoSuchElementException
+                    ("StartElement from array not found.");
+    }
+
+    /**
+     * Expect one of an array of possible STARTELEMENT events.  The next
+     * STARTELEMENT must have a <tt>QName</tt> which matches an element
+     * of the argument <tt>String[]</tt> list.
+     * @param list a <tt>String[]</tt> array containing <tt>QName</tt>s
+     * of possible events, one of which must be the next returned.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return the matching STARTELEMENT event.If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectStartElement
+                                    (String[] list, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        for (int i = 0; i < list.length; i++) {
+            ev = expectStartElement(list[i], discardWhiteSpace);
+            // Found it!
+            if (ev != null) return ev;
+        }
+        return null;
+    }
+
+    /**
+     * Get one of a array of possible STARTELEMENT events.  Scan and discard
+     * events until a STARTELEMENT event is found which is in the fo:
+     * namespace and whose FO type matches one of those in the argument
+     * <tt>int</tt> array.
+     * @param list an <tt>int[]</tt> array containing FO types
+     * one of which is required.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return the next matching STARTELEMENT event from the buffer.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getStartElement(int[] list, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        do {
+            ev = expectStartElement(list, discardWhiteSpace);
+            if (ev != null) return ev;
+            // The non-matching event has been pushed back.
+            // Get it and discard.  Note that if the first attempt to
+            // getEvent() returns null, the expectStartElement() calls
+            // will throw a NoSuchElementException
+            ev = getEvent();
+        } while (ev != null);
+        // Exit from this while loop is only by discovery of null event
+        throw new NoSuchElementException
+                    ("StartElement from array not found.");
+    }
+
+    /**
+     * Expect one of an array of possible STARTELEMENT events.  The next
+     * STARTELEMENT must be in the fo: namespace, and must have an FO type
+     * which matches one of those in the argument <tt>int[]</tt> list.
+     * @param list a <tt>int[]</tt> array containing the FO types
+     * of possible events, one of which must be the next returned.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return the matching STARTELEMENT event.If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectStartElement
+                                    (int[] list, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        for (int i = 0; i < list.length; i++) {
+            ev = expectStartElement(list[i], discardWhiteSpace);
+            // Found it!
+            if (ev != null) return ev;
+        }
+        return null;
+    }
+
+    /**
+     * Get the next ENDELEMENT event from the buffer.  Discard any other
+     * events preceding the ENDELEMENT event.
+     * @return an ENDELEMENT event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getEndElement() throws FOPException {
+        return getTypedEvent(XMLEvent.ENDELEMENT);
+    }
+
+    /**
+     * Return the next element if it is an ENDELEMENT.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a matching ENDELEMENT event.  If the next
+     * event detected is not of the required type, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if ENDELEMENT is not the next
+     * event detected.  The erroneous event is pushed back.
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectEndElement(boolean discardWhiteSpace)
+                throws FOPException
+    {
+        return expectTypedEvent(XMLEvent.ENDELEMENT, discardWhiteSpace);
+    }
+
+    /**
+     * Get the next ENDELEMENT event with the given <tt>QName</tt>
+     * from the buffer.  Discard any other events preceding the
+     * ENDELEMENT event.
+     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
+     * required STARTELEMENT
+     * @return an ENDELEMENT event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getEndElement(String qName) throws FOPException
+    {
+        return getTypedEvent(XMLEvent.ENDELEMENT, qName);
+    }
+
+    /**
+     * Return the next element if it is an ENDELEMENT with the given
+     * <tt>QName</tt>.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
+     * required ENDELEMENT
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return an ENDELEMENT with the given qname.  If the next
+     * event detected is not an ENDELEMENT, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectEndElement(String qName, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        return expectTypedEvent(XMLEvent.ENDELEMENT, qName, discardWhiteSpace);
+    }
+
+    /**
+     * Get the next ENDELEMENT event with the given URI index and local name
+     * from the buffer.  Discard any other events preceding the
+     * ENDELEMENT event.
+     * @param uriIndex an <tt>int</tt> with the index of the URI of the
+     * required URI
+     * @param localName a <tt>String</tt> with the local name of the
+     * required ENDELEMENT
+     * @return an ENDELEMENT event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getEndElement(int uriIndex, String localName)
+        throws FOPException
+    {
+        return getTypedEvent(XMLEvent.ENDELEMENT, uriIndex, localName);
+    }
+
+    /**
+     * Return the next element if it is an ENDELEMENT with the given
+     * URI index and local name.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param uriIndex an <tt>int</tt> with the index of the URI of the
+     * required URI
+     * @param localName a <tt>String</tt> with the local name of the
+     * required ENDELEMENT
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a matching ENDELEMENT event.
+     * If the next
+     * event detected is not an ENDELEMENT, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectEndElement
+                (int uriIndex, String localName, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        return expectTypedEvent
+                (XMLEvent.ENDELEMENT, uriIndex, localName, discardWhiteSpace);
+    }
+
+    /**
+     * Get the next ENDELEMENT event with the given Fo type
+     * from the buffer.  Discard any other events preceding the
+     * ENDELEMENT event.
+     * @param foType - the FO type of the required ENDELEMENT
+     * @return a matching ENDELEMENT event.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getEndElement(int foType) throws FOPException
+    {
+        return getTypedEvent(XMLEvent.ENDELEMENT, foType);
+    }
+
+    /**
+     * Return the next element if it is an ENDELEMENT with the given
+     * FO type.  If the next
+     * element is not of the required type, push it back onto the buffer.
+     * @param foType - the FO type of the required ENDELEMENT
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a matching ENDELEMENT.  If the next
+     * event detected is not an ENDELEMENT, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectEndElement(int foType, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        return expectTypedEvent
+                            (XMLEvent.ENDELEMENT, foType, discardWhiteSpace);
+    }
+
+    /**
+     * Get the next ENDELEMENT event, with the same URI index and local name
+     * as the <tt>FoXMLEvent</tt> argument, from the buffer.
+     * Discard any other events preceding the ENDELEMENT event.
+     * @param event an <tt>FoXMLEvent</tt>.  Only the uriIndex and the
+     * localName from the event are used.  It is intended that the FoXMLEvent
+     * returned to the corresponding get/expectStartElement() call be used.
+     * @return an ENDELEMENT event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getEndElement(FoXMLEvent event) throws FOPException
+    {
+        if (event.foType != FObjectNames.NO_FO)
+            return getTypedEvent(XMLEvent.ENDELEMENT, event.foType);
+        return getTypedEvent
+                    (XMLEvent.ENDELEMENT, event.uriIndex, event.localName);
+    }
+
+    /**
+     * Return the next element if it is an ENDELEMENT with the same
+     * URI index and local name as the <tt>FoXMLEvent argument</tt>.  If the
+     * next element is not of the required type, push it back onto the buffer.
+     * @param event an <tt>FoXMLEvent</tt>.  Only the uriIndex and the
+     * localName from the event are used.  It is intended that the FoXMLEvent
+     * returned to the corresponding get/expectStartElement() call be used.
+     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
+     * events which contain only whitespace.
+     * @return a matching ENDELEMENT event.  If the next
+     * event detected is not an ENDELEMENT, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectEndElement
+                                (FoXMLEvent event, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        if (event.foType != FObjectNames.NO_FO)
+            return expectTypedEvent
+                    (XMLEvent.ENDELEMENT, event.foType, discardWhiteSpace);
+        return expectTypedEvent
+                (XMLEvent.ENDELEMENT, event.uriIndex, event.localName,
+                                                         discardWhiteSpace);
+    }
+
+    /**
+     * @return a CHARACTERS event
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if the event is not found
+     */
+    public FoXMLEvent getCharacters() throws FOPException {
+        FoXMLEvent ev = getEvent();
+        while (ev != null && ev.type != XMLEvent.CHARACTERS) {
+            ev = getEvent();
+        }
+        if (ev == null) {
+            throw new NoSuchElementException("Characters not found.");
+        }
+        return ev;
+    }
+
+    /**
+     * @return a CHARACTERS event.  If the next event detected is not
+     * a CHARACTERS event, <tt>null</tt> is returned.
+     * The erroneous event is pushed back.
+     * @exception FOPException if buffer errors or interrupts occur
+     * @exception NoSuchElementException if end of buffer detected.
+     */
+    public FoXMLEvent expectCharacters() throws FOPException {
+        FoXMLEvent ev = getEvent();
+        if (ev != null && ev.type == XMLEvent.CHARACTERS) {
+            return ev;
+        }
+        pushBack(ev);
+        return null;
+    }
+
+}
diff --git a/src/org/apache/fop/xml/SyncedXmlEventsBuffer.java b/src/org/apache/fop/xml/SyncedXmlEventsBuffer.java
deleted file mode 100644 (file)
index 465d5c9..0000000
+++ /dev/null
@@ -1,778 +0,0 @@
-package org.apache.fop.xml;
-
-import org.apache.fop.datastructs.SyncedCircularBuffer;
-import org.apache.fop.apps.FOPException;
-
-import java.util.NoSuchElementException;
-import java.util.LinkedList;
-import java.util.Iterator;
-
-/*
- * $Id$
- * 
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- *
- * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
- * @version $Revision$ $Name$
- */
-/**
- * A synchronized circular buffer for XMLEvents.
- * @see org.apache.fop.datastructs.SyncedCircularBuffer
- */
-public class SyncedXmlEventsBuffer extends SyncedCircularBuffer {
-
-    /**
-     * Maintains an index of namespace URIs.  These can then be referred to
-     * by an <tt>int</tt> index.
-     */
-    private XMLNamespaces namespaces;
-
-    /**
-     * No-argument constructor sets up a buffer with the default number of
-     * elements.
-     * The producer and consumer <tt>Thread</tt>s default to the current
-     * thread at the time of instantiation.
-     */
-    public SyncedXmlEventsBuffer()
-        throws IllegalArgumentException
-    {
-        super();
-        namespaces = new XMLNamespaces();
-    }
-
-    /**
-     * Constructor taking one argument; the size of the buffer.
-     * @param size the size of the buffer.  Must be > 1.
-     */
-    public SyncedXmlEventsBuffer(int size)
-        throws IllegalArgumentException
-    {
-        super(size);
-        namespaces = new XMLNamespaces();
-    }
-
-    /**
-     * Get the <tt>XMLNamespaces</tt> from this buffer.
-     * @return - the namespaces object.
-     */
-    public XMLNamespaces getNamespaces() { return namespaces; }
-
-    /**
-     * @return next event from the SyncedCircularBuffer
-     * @exception FOPException.  The purpose of this method is to catch
-     * and transform any InterruptedException exceptions thrown by the
-     * <tt>SyncedCircularBuffer</tt>.
-     */
-    public XMLEvent getEvent() throws FOPException {
-        XMLEvent ev;
-        try {
-            ev = (XMLEvent)get();
-            //System.out.println("getEvent: " + ev);
-            return ev;
-        } catch (InterruptedException e) {
-            throw new FOPException(e);
-        }
-    }
-
-    /**
-     * Get the next event of the given type from the buffer.  Discard
-     * intervening events.
-     * @param eventType - the <tt>int</tt> event type.
-     * @return an event of the given type.
-     * @exception FOPException if buffer errors or interrupts occur.
-     * @exception NoSuchElementException if the event is not found.
-     */
-    public XMLEvent getTypedEvent(int eventType) throws FOPException {
-        XMLEvent ev = getEvent();
-        while (ev != null && ev.type != eventType) {
-            ev = getEvent();
-        }
-        if (ev == null) {
-            throw new NoSuchElementException
-                        (XMLEvent.eventTypeName(eventType) + " not found.");
-        }
-        return ev;
-    }
-
-    /**
-     * Get the next event of the given type and with the given <tt>QName</tt>
-     * from the buffer.  Discard intervening events.
-     * @param eventType - the <tt>int</tt> event type.
-     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
-     * required element.
-     * @return an event of the given type.
-     * @exception FOPException if buffer errors or interrupts occur.
-     * @exception NoSuchElementException if the event is not found.
-     */
-    public XMLEvent getTypedEvent(int eventType, String qName)
-                throws FOPException
-    {
-        XMLEvent ev = getEvent();
-        while (ev != null &&
-               ! (ev.type == eventType && ev.qName.equals(qName))) {
-            ev = getEvent();
-        }
-        if (ev == null) {
-            throw new NoSuchElementException
-            (XMLEvent.eventTypeName(eventType) + " " + qName + " not found.");
-        }
-        return ev;
-    }
-
-    /**
-     * Get the next event of the given type, and with the given URI index and
-     * local name, from the buffer.  Discard intervening events.
-     * @param eventType - the <tt>int</tt> event type.
-     * @param uriIndex - the <tt>int</tt> URI index maintained in the
-     * <tt>XMLNamespaces</tt> object.
-     * @param localName a <tt>String</tt> with the local name of the
-     * required element.
-     * @return an event of the given type.
-     * @exception FOPException if buffer errors or interrupts occur.
-     * @exception NoSuchElementException if the event is not found.
-     */
-    public XMLEvent getTypedEvent
-                            (int eventType, int uriIndex, String localName)
-                throws FOPException
-    {
-        XMLEvent ev = getEvent();
-        while (ev != null &&
-               ! (ev.type == eventType
-                  && ev.type == eventType
-                  && ev.localName.equals(localName))) {
-            ev = getEvent();
-        }
-        if (ev == null)
-            throw new NoSuchElementException
-                    (XMLEvent.eventTypeName(eventType)
-                             + namespaces.getIndexURI(uriIndex)
-                                       + ":" + localName + " not found.");
-        return ev;
-    }
-
-    /**
-     * Return the next element if it is of the required type.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param eventType - the <tt>int</tt> event type.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return an event of the required type.
-     * @exception FOPException if buffer errors or interrupts occur.
-     * @exception NoSuchElementException if the next
-     * event detected is not of the required type.
-     * The erroneous event is pushed back.
-     */
-    public XMLEvent expectTypedEvent(int eventType, boolean discardWhiteSpace)
-                throws FOPException
-    {
-        XMLEvent ev = getEvent();
-        if (discardWhiteSpace) {
-            while (ev != null && ev.type == XMLEvent.CHARACTERS
-                   && ev.chars.trim().equals("")) {
-                ev = getEvent();
-            }
-        }
-        if (ev != null && ev.type == eventType) {
-            return ev;
-        }
-        pushBack(ev);
-        throw new NoSuchElementException
-                        (XMLEvent.eventTypeName(eventType) + " not found.");
-    }
-
-    /**
-     * Return the next element if it is of the required type and has the
-     * required <tt>QName</tt>.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param eventType - the <tt>int</tt> event type.
-     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
-     * required element.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return an event of the required type.
-     * @exception FOPException if buffer errors or interrupts occur.
-     * @exception NoSuchElementException if the next
-     * event detected is not of the required type.
-     * The erroneous event is pushed back.
-     */
-    public XMLEvent expectTypedEvent
-                    (int eventType, String qName, boolean discardWhiteSpace)
-                throws FOPException
-    {
-        XMLEvent ev = getEvent();
-        if (discardWhiteSpace) {
-            while (ev != null && ev.type == XMLEvent.CHARACTERS
-                   && ev.chars.trim().equals("")) {
-                ev = getEvent();
-            }
-        }
-        if (ev != null && ev.type == eventType && ev.qName.equals(qName)) {
-            return ev;
-        }
-        pushBack(ev);
-        throw new NoSuchElementException
-            (XMLEvent.eventTypeName(eventType) + " " + qName + " not found.");
-    }
-
-    /**
-     * Return the next element if it is of the required type and has the
-     * required URI index and local name.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param eventType - the <tt>int</tt> event type.
-     * @param uriIndex - the <tt>int</tt> URI index.
-     * @param localName a <tt>String</tt> with the local name of the
-     * required element.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return an event of the required type.
-     * @exception FOPException if buffer errors or interrupts occur.
-     * @exception NoSuchElementException if the next
-     * event detected is not of the required type.
-     * The erroneous event is pushed back.
-     */
-    public XMLEvent expectTypedEvent
-                            (int eventType, int uriIndex,
-                                 String localName, boolean discardWhiteSpace)
-                throws FOPException
-    {
-        XMLEvent ev = getEvent();
-        if (discardWhiteSpace) {
-            while (ev != null && ev.type == XMLEvent.CHARACTERS
-                   && ev.chars.trim().equals("")) {
-                ev = getEvent();
-            }
-        }
-        if (ev != null
-                && ev.type == eventType
-                   && ev.uriIndex == uriIndex
-                       && ev.localName.equals(localName)) {
-            return ev;
-        }
-        pushBack(ev);
-        throw new NoSuchElementException
-                    (XMLEvent.eventTypeName(eventType)
-                             + namespaces.getIndexURI(uriIndex)
-                                       + ":" + localName + " not found.");
-    }
-
-    /**
-     * Get the next ENDDOCUMENT event from the buffer.  Discard any other
-     * events preceding the ENDDOCUMENT event.
-     * @return an ENDDOCUMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getEndDocument() throws FOPException {
-        return getTypedEvent(XMLEvent.ENDDOCUMENT);
-    }
-
-    /**
-     * Return the next element if it is an ENDDOCUMENT.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return an ENDDOCUMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if ENDDOCUMENT is not the next
-     * event detected.  The erroneous event is pushed back.
-     */
-    public XMLEvent expectEndDocument(boolean discardWhiteSpace)
-                throws FOPException
-    {
-        return expectTypedEvent(XMLEvent.ENDDOCUMENT, discardWhiteSpace);
-    }
-
-    /**
-     * Get the next STARTELEMENT event from the buffer.  Discard any other
-     * events preceding the STARTELEMENT event.
-     * @return a STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getStartElement() throws FOPException {
-        return getTypedEvent(XMLEvent.STARTELEMENT);
-    }
-
-    /**
-     * Return the next element if it is a STARTELEMENT.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return a STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if STARTELEMENT is not the next
-     * event detected.  The erroneous event is pushed back.
-     */
-    public XMLEvent expectStartElement(boolean discardWhiteSpace)
-                throws FOPException
-    {
-        return expectTypedEvent(XMLEvent.STARTELEMENT, discardWhiteSpace);
-    }
-
-    /**
-     * Get the next STARTELEMENT event with the given <tt>QName</tt>
-     * from the buffer.  Discard any other events preceding the
-     * STARTELEMENT event.
-     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
-     * required STARTELEMENT
-     * @return a STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getStartElement(String qName) throws FOPException
-    {
-        return getTypedEvent(XMLEvent.STARTELEMENT, qName);
-    }
-
-    /**
-     * Return the next element if it is a STARTELEMENT with the given
-     * <tt>QName</tt>.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
-     * required STARTELEMENT
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return a STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if STARTELEMENT is not the next
-     * event detected.  The erroneous event is pushed back.
-     */
-    public XMLEvent expectStartElement
-                                (String qName, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        return expectTypedEvent
-                        (XMLEvent.STARTELEMENT, qName, discardWhiteSpace);
-    }
-
-    /**
-     * Get the next STARTELEMENT event with the given URI index and local name
-     * from the buffer.  Discard any other events preceding the
-     * STARTELEMENT event.
-     * @param uriIndex an <tt>int</tt> with the index of the URI of the
-     * required URI
-     * @param localName a <tt>String</tt> with the local name of the
-     * required STARTELEMENT
-     * @return a STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getStartElement(int uriIndex, String localName)
-        throws FOPException
-    {
-        return getTypedEvent(XMLEvent.STARTELEMENT, uriIndex, localName);
-    }
-
-    /**
-     * Return the next element if it is a STARTELEMENT with the given
-     * URI index and local name.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param uriIndex an <tt>int</tt> URI index.
-     * @param localName a <tt>String</tt> with the local name of the
-     * required STARTELEMENT
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return a STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if STARTELEMENT is not the next
-     * event detected.  The erroneous event is pushed back.
-     */
-    public XMLEvent expectStartElement
-                (int uriIndex, String localName, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        return expectTypedEvent
-            (XMLEvent.STARTELEMENT, uriIndex, localName, discardWhiteSpace);
-    }
-
-    /**
-     * Get one of a list of possible STARTELEMENT events.
-     * @param list a <tt>LinkedList</tt> containing either <tt>String</tt>s
-     * with the <tt>QName</tt>, or <tt>UriLocalName</tt>
-     * objects with the URI index and local name of one of the required
-     * STARTELEMENT events.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return a STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getStartElement
-                                (LinkedList list, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        XMLEvent ev;
-        do {
-            try {
-                ev = expectStartElement(list, discardWhiteSpace);
-                return ev;
-            } catch (NoSuchElementException e) {
-                // keep trying
-            }
-            // The non-matching event has been pushed back.
-            // Get it and discard.  Note that if the first attempt to
-            // getEvent() returns null, the expectStartElement() calls
-            // will throw a NoSuchElementException
-            ev = getEvent();
-        } while (ev != null);
-        // Exit from this while loop is only by discovery of null event
-        throw new NoSuchElementException
-                    ("StartElement from list not found.");
-    }
-
-    /**
-     * Get one of a list of possible STARTELEMENT events.
-     * @param list a <tt>LinkedList</tt> containing either <tt>String</tt>s
-     * with the <tt>QName</tt>, or <tt>UriLocalName</tt>
-     * objects with the URI index and local name of one of the required
-     * STARTELEMENT events.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return a STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent expectStartElement
-                                (LinkedList list, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        XMLEvent ev;
-        Iterator elements = list.iterator();
-        while (elements.hasNext()) {
-            Object o = elements.next();
-            if (o instanceof String) {
-                try {
-                    ev = expectStartElement((String) o, discardWhiteSpace);
-                    // Found it!
-                    return ev;
-                } catch (NoSuchElementException e) {
-                    // Keep trying
-                }
-            } else if (o instanceof UriLocalName) {
-                try {
-                    ev = expectStartElement
-                            (((UriLocalName) o).uriIndex,
-                             ((UriLocalName) o).localName,
-                             discardWhiteSpace);
-                    // Found it!
-                    return ev;
-                } catch (NoSuchElementException e) {
-                    // Keep trying
-                }
-            } else
-                throw new FOPException
-                        ("Invalid list elements for getStartElement");
-        }
-        throw new NoSuchElementException
-                ("StartElement from list not found.");
-    }
-
-    /**
-     * Get one of a array of possible STARTELEMENT events.  Scan and discard
-     * events until a STARTELEMENT event is found whose URI index and
-     * local name matches one of those in the argument
-     * <tt>UriLocalName[]</tt> array.
-     * @param list an array containing <tt>UriLocalName</tt>
-     * objects with the URI index and local name of
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * STARTELEMENT events, one of which is required.
-     * @return the next matching STARTELEMENT event from the buffer.
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getStartElement
-                    (UriLocalName[] list, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        XMLEvent ev;
-        do {
-            try {
-                ev = expectStartElement(list, discardWhiteSpace);
-                return ev;
-            } catch (NoSuchElementException e) {
-                // keep trying
-            }
-            // The non-matching event has been pushed back.
-            // Get it and discard.  Note that if the first attempt to
-            // getEvent() returns null, the expectStartElement() calls
-            // will throw a NoSuchElementException
-            ev = getEvent();
-        } while (ev != null);
-        // Exit from this while loop is only by discovery of null event
-        throw new NoSuchElementException
-                    ("StartElement from list not found.");
-    }
-
-    /**
-     * Expect one of an array of possible STARTELEMENT events.  The next
-     * STARTELEMENT must have a URI index and local name which match
-     * an element of the argument <tt>UriLocalName[]</tt> list.
-     * @param list an <tt>UriLocalName[]</tt> array containing the
-     * namespace Uri index and LocalName
-     * of possible events, one of which must be the next returned.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return the matching STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent expectStartElement
-                    (UriLocalName[] list, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        XMLEvent ev;
-        for (int i = 0; i < list.length; i++) {
-            try {
-                ev = expectStartElement(list[i].uriIndex,
-                                        list[i].localName,
-                                        discardWhiteSpace);
-                // Found it!
-                return ev;
-            } catch (NoSuchElementException e) {
-                // Keep trying
-            }
-        }
-        throw new NoSuchElementException
-                ("StartElement from array not found.");
-    }
-
-    /**
-     * Get one of a array of possible STARTELEMENT events.  Scan and discard
-     * events until a STARTELEMENT event is found whose <tt>QName</tt>
-     * matches one of those in the argument <tt>String[]</tt> array.
-     * @param list a <tt>String[]</tt> array containing <tt>QName</tt>s,
-     * one of which is required.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return the next matching STARTELEMENT event from the buffer.
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getStartElement(String[] list, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        XMLEvent ev;
-        do {
-            try {
-                ev = expectStartElement(list, discardWhiteSpace);
-                return ev;
-            } catch (NoSuchElementException e) {
-                // keep trying
-            }
-            // The non-matching event has been pushed back.
-            // Get it and discard.  Note that if the first attempt to
-            // getEvent() returns null, the expectStartElement() calls
-            // will throw a NoSuchElementException
-            ev = getEvent();
-        } while (ev != null);
-        // Exit from this while loop is only by discovery of null event
-        throw new NoSuchElementException
-                    ("StartElement from array not found.");
-    }
-
-    /**
-     * Expect one of an array of possible STARTELEMENT events.  The next
-     * STARTELEMENT must have a <tt>QName</tt> which matches an element
-     * of the argument <tt>String[]</tt> list.
-     * @param list a <tt>String[]</tt> array containing <tt>QName</tt>s
-     * of possible events, one of which must be the next returned.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return the matching STARTELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent expectStartElement
-                                    (String[] list, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        XMLEvent ev;
-        for (int i = 0; i < list.length; i++) {
-            try {
-                ev = expectStartElement(list[i], discardWhiteSpace);
-                // Found it!
-                return ev;
-            } catch (NoSuchElementException e) {
-                // Keep trying
-            }
-        }
-        throw new NoSuchElementException
-                ("StartElement from array not found.");
-    }
-
-    /**
-     * Get the next ENDELEMENT event from the buffer.  Discard any other
-     * events preceding the ENDELEMENT event.
-     * @return an ENDELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getEndElement() throws FOPException {
-        return getTypedEvent(XMLEvent.ENDELEMENT);
-    }
-
-    /**
-     * Return the next element if it is an ENDELEMENT.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return an ENDELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if ENDELEMENT is not the next
-     * event detected.  The erroneous event is pushed back.
-     */
-    public XMLEvent expectEndElement(boolean discardWhiteSpace)
-                throws FOPException
-    {
-        return expectTypedEvent(XMLEvent.ENDELEMENT, discardWhiteSpace);
-    }
-
-    /**
-     * Get the next ENDELEMENT event with the given <tt>QName</tt>
-     * from the buffer.  Discard any other events preceding the
-     * ENDELEMENT event.
-     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
-     * required STARTELEMENT
-     * @return an ENDELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getEndElement(String qName) throws FOPException
-    {
-        return getTypedEvent(XMLEvent.ENDELEMENT, qName);
-    }
-
-    /**
-     * Return the next element if it is an ENDELEMENT with the given
-     * <tt>QName</tt>.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param qName a <tt>String</tt> with the <tt>QName</tt> of the
-     * required ENDELEMENT
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return an ENDELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if STARTELEMENT is not the next
-     * event detected.  The erroneous event is pushed back.
-     */
-    public XMLEvent expectEndElement(String qName, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        return expectTypedEvent(XMLEvent.ENDELEMENT, qName, discardWhiteSpace);
-    }
-
-    /**
-     * Get the next ENDELEMENT event with the given URI index and local name
-     * from the buffer.  Discard any other events preceding the
-     * ENDELEMENT event.
-     * @param uriIndex an <tt>int</tt> with the index of the URI of the
-     * required URI
-     * @param localName a <tt>String</tt> with the local name of the
-     * required ENDELEMENT
-     * @return an ENDELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getEndElement(int uriIndex, String localName)
-        throws FOPException
-    {
-        return getTypedEvent(XMLEvent.ENDELEMENT, uriIndex, localName);
-    }
-
-    /**
-     * Return the next element if it is an ENDELEMENT with the given
-     * URI index and local name.  If the next
-     * element is not of the required type, push it back onto the buffer.
-     * @param uriIndex an <tt>int</tt> with the index of the URI of the
-     * required URI
-     * @param localName a <tt>String</tt> with the local name of the
-     * required ENDELEMENT
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return an ENDELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if STARTELEMENT is not the next
-     * event detected.  The erroneous event is pushed back.
-     */
-    public XMLEvent expectEndElement
-                (int uriIndex, String localName, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        return expectTypedEvent
-                (XMLEvent.ENDELEMENT, uriIndex, localName, discardWhiteSpace);
-    }
-
-    /**
-     * Get the next ENDELEMENT event, with the same URI index and local name
-     * as the <tt>XMLEvent</tt> argument, from the buffer.
-     * Discard any other events preceding the ENDELEMENT event.
-     * @param event an <tt>XMLEvent</tt>.  Only the uriIndex and the
-     * localName from the event are used.  It is intended that the XMLEvent
-     * returned to the corresponding get/expectStartElement() call be used.
-     * @return an ENDELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getEndElement(XMLEvent event) throws FOPException
-    {
-        return getTypedEvent
-                    (XMLEvent.ENDELEMENT, event.uriIndex, event.localName);
-    }
-
-    /**
-     * Return the next element if it is an ENDELEMENT with the same
-     * URI index and local name as the <tt>XMLEvent argument</tt>.  If the
-     * next element is not of the required type, push it back onto the buffer.
-     * @param event an <tt>XMLEvent</tt>.  Only the uriIndex and the
-     * localName from the event are used.  It is intended that the XMLEvent
-     * returned to the corresponding get/expectStartElement() call be used.
-     * @param discardWhiteSpace - if true, discard any <tt>characters</tt>
-     * events which contain only whitespace.
-     * @return an ENDELEMENT event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if STARTELEMENT is not the next
-     * event detected.  The erroneous event is pushed back.
-     */
-    public XMLEvent expectEndElement(XMLEvent event, boolean discardWhiteSpace)
-        throws FOPException
-    {
-        return expectTypedEvent
-                (XMLEvent.ENDELEMENT, event.uriIndex, event.localName,
-                                                         discardWhiteSpace);
-    }
-
-    /**
-     * @return a CHARACTERS event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if the event is not found
-     */
-    public XMLEvent getCharacters() throws FOPException {
-        XMLEvent ev = getEvent();
-        while (ev != null && ev.type != XMLEvent.CHARACTERS) {
-            ev = getEvent();
-        }
-        if (ev == null) {
-            throw new NoSuchElementException("Characters not found.");
-        }
-        return ev;
-    }
-
-    /**
-     * @return a CHARACTERS event
-     * @exception FOPException if buffer errors or interrupts occur
-     * @exception NoSuchElementException if CHARACTERS is not the next
-     * event detected.  The erroneous event is pushed back.
-     */
-    public XMLEvent expectCharacters() throws FOPException {
-        XMLEvent ev = getEvent();
-        if (ev != null && ev.type == XMLEvent.CHARACTERS) {
-            return ev;
-        }
-        pushBack(ev);
-        throw new NoSuchElementException("Characters not found.");
-    }
-
-}
diff --git a/src/org/apache/fop/xml/XMLSerialHandler.java b/src/org/apache/fop/xml/XMLSerialHandler.java
deleted file mode 100644 (file)
index 7291594..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-package org.apache.fop.xml;
-
-import org.apache.fop.xml.XMLNamespaces;
-import org.apache.fop.xml.SyncedXmlEventsBuffer;
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.Driver;
-import org.apache.fop.configuration.Configuration;
-
-import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.Attributes;
-import org.xml.sax.helpers.AttributesImpl;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.InputSource;
-
-import java.io.IOException;
-import java.util.NoSuchElementException;
-
-/*
- * $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources.
- *
- * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
- * @version $Revision$ $Name$
- */
-/**
- * <tt>XMLSerialHandler</tt> is the <tt>ContentHandler</tt> for the
- * background <tt>XMLReader</tt> thread.
- */
-
-public class XMLSerialHandler extends DefaultHandler implements Runnable {
-
-    private static final String tag = "$Name$";
-    private static final String revision = "$Revision$";
-
-    private SyncedXmlEventsBuffer events;
-    private XMLReader parser;
-    private XMLNamespaces namespaces;
-    private InputSource source;
-    private Thread foThread;
-    private boolean errorDump;
-
-    /**
-     * @param events the events buffer.
-     * @param parser the xml parser.
-     * @param source the parser input source.
-     */
-    public XMLSerialHandler
-        (SyncedXmlEventsBuffer events, XMLReader parser, InputSource source) {
-        this.events = events;
-        this.parser = parser;
-        this.source = source;
-        namespaces = events.getNamespaces();
-        parser.setContentHandler(this);
-        errorDump = Configuration.getBooleanValue("debugMode").booleanValue();
-    }
-
-    public void setFoThread(Thread foThread) {
-        this.foThread = foThread;
-    }
-
-    /**
-     * This is the run method for the callback parser thread.
-     */
-    public void run() {
-        // I''m in the thread - run the parser
-        try {
-            parser.parse(source);
-        } catch (Exception e) {
-            if (errorDump) Driver.dumpError(e);
-            if (foThread != null) {
-                try {
-                    foThread.interrupt();
-                } catch (Exception ex) {} //ignore
-            }
-            throw new RuntimeException(e.getMessage());
-        }
-    }
-
-    /**
-     * Utility routine for the callback methods.  It captures the
-     * <tt>InterruptedException</tt> that is possible from the <i>put</i>
-     * method of a <tt>SyncedXmlEventsBuffer</tt>.
-     */
-    public void putEvent(XMLEvent event) throws NoSuchElementException {
-        synchronized (events) {
-            try {
-                events.put(event);
-            } catch (InterruptedException e) {
-                throw new RuntimeException
-                        ("Producer interrupted: " +e.getMessage());
-            }
-        }
-    }
-
-    /**
-     * Callback routine for the parser.
-     */
-    public void startDocument() throws NoSuchElementException {
-        synchronized (events) {
-            XMLEvent event = new XMLEvent(namespaces);
-            //System.out.println("StartDocument thread "
-            //                   + Thread.currentThread().getName());
-            event.type = XMLEvent.STARTDOCUMENT;
-            //System.out.println("SerialHandler: " + event);
-            putEvent(event);
-        }
-    }
-
-    /**
-     * Callback routine for the parser.
-     */
-    public void endDocument() throws NoSuchElementException {
-        synchronized (events) {
-            XMLEvent event = new XMLEvent(namespaces);
-            //System.out.println("EndDocument thread "
-            //                   + Thread.currentThread().getName());
-            event.type = XMLEvent.ENDDOCUMENT;
-            //System.out.println("SerialHandler: " + event);
-            putEvent(event);
-            events.flushBuffer();
-        }
-    }
-
-    /**
-     * Callback routine for the parser.
-     * @param uri the URI of the element name
-     * @param localName the localname of the element
-     * @param qName the (prefix) qualified name of the element
-     * @param attributes the attribute set of the element, as an object
-     * implementing the <tt>Attributes</tt> interface.
-     */
-    public void startElement(String uri, String localName,
-                             String qName, Attributes attributes)
-        throws NoSuchElementException
-    {
-        synchronized (events) {
-            XMLEvent event = new XMLEvent(namespaces);
-            //System.out.println("StartElement thread "
-            //                   + Thread.currentThread().getName());
-            event.type = XMLEvent.STARTELEMENT;
-            event.uriIndex = namespaces.getURIIndex(uri);
-            event.localName = localName;
-            event.qName = qName;
-            event.attributes = new AttributesImpl(attributes);
-            //System.out.println("SerialHandler: " + event);
-            putEvent(event);
-        }
-    }
-
-    /**
-     * Callback routine for parser.
-     * @param uri the URI of this element name
-     * @param localName the unqualified localname of this element
-     * @param qName the (prefix) qualified name of this element
-     */
-    public void endElement(String uri, String localName,
-                           String qName)
-        throws NoSuchElementException
-    {
-        synchronized (events) {
-            XMLEvent event = new XMLEvent(namespaces);
-            //System.out.println("EndElement thread "
-            //                   + Thread.currentThread().getName());
-            event.type = XMLEvent.ENDELEMENT;
-            event.uriIndex = namespaces.getURIIndex(uri);
-            event.localName = localName;
-            event.qName = qName;
-            putEvent(event);
-        }
-    }
-
-    /**
-     * Callback routine for parser to handle characters.
-     * @param ch the array of characters
-     * @param start starting position of this set of characters in the
-     * <i>ch</i> array.
-     * @param length number of characters in this set
-     */
-    public void characters(char[] ch, int start, int length)
-        throws NoSuchElementException
-    {
-        synchronized (events) {
-            XMLEvent event = new XMLEvent(namespaces);
-            //System.out.println("characters thread "
-            //                   + Thread.currentThread().getName());
-            event.type = XMLEvent.CHARACTERS;
-            event.chars = new String(ch, start, length);
-            //System.out.println("SerialHandler: " + event);
-            putEvent(event);
-        }
-    }
-}