]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Added getEndElement(boolean, ...).
authorPeter Bernard West <pbwest@apache.org>
Sun, 1 Dec 2002 14:53:11 +0000 (14:53 +0000)
committerPeter Bernard West <pbwest@apache.org>
Sun, 1 Dec 2002 14:53:11 +0000 (14:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@195696 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/xml/SyncedFoXmlEventsBuffer.java

index 249d79bbc50f032ea7d49c68c85b96d4361e29a7..0f3886a19d5a9ba1e2169d4c5090969bb6861c0b 100644 (file)
@@ -28,6 +28,13 @@ import java.util.BitSet;
  */
 public class SyncedFoXmlEventsBuffer extends SyncedCircularBuffer {
 
+    /**
+     * Constant for <i>discardEvent</i> field of
+     * <i>getEndElement(boolean discardEvent, FoXMLEvent(, boolean)).
+     */
+    public static final boolean DISCARD_EV = true,
+                                 RETAIN_EV = false;
+
     /**
      * Maintains an index of namespace URIs.  These can then be referred to
      * by an <tt>int</tt> index.
@@ -1153,6 +1160,67 @@ public class SyncedFoXmlEventsBuffer extends SyncedCircularBuffer {
                                                          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 discardEvent the argument event may be discarded.
+     * @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(boolean discardEvent, FoXMLEvent event)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        if (event.foType != FObjectNames.NO_FO)
+            ev = getTypedEvent(XMLEvent.ENDELEMENT, event.foType);
+        else
+            ev = getTypedEvent
+                    (XMLEvent.ENDELEMENT, event.uriIndex, event.localName);
+        if (discardEvent) {
+            //System.out.println("discardEvent");
+            pool.surrenderEvent(event);
+        }
+        return ev;
+    }
+
+    /**
+     * 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 discardEvent the argument event may be discarded.
+     * @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
+        (boolean discardEvent, FoXMLEvent event, boolean discardWhiteSpace)
+        throws FOPException
+    {
+        FoXMLEvent ev;
+        if (event.foType != FObjectNames.NO_FO)
+            ev = expectTypedEvent
+                    (XMLEvent.ENDELEMENT, event.foType, discardWhiteSpace);
+        else
+            ev = expectTypedEvent
+                (XMLEvent.ENDELEMENT, event.uriIndex, event.localName,
+                                                         discardWhiteSpace);
+        if (discardEvent)
+            pool.surrenderEvent(event);
+        return ev;
+    }
+
     /**
      * @return a CHARACTERS event
      * @exception FOPException if buffer errors or interrupts occur