cvs commit: xml-fop/src/org/apache/fop/xml SyncedFoXmlEventsBuffer.java
pbwest 2002/12/01 06:53:12 Modified:src/org/apache/fop/xml Tag: FOP_0-20-0_Alt-Design SyncedFoXmlEventsBuffer.java Log: Added getEndElement(boolean, ...). Revision ChangesPath No revision No revision 1.1.2.7 +70 -2 xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java Index: SyncedFoXmlEventsBuffer.java === RCS file: /home/cvs/xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- SyncedFoXmlEventsBuffer.java 29 Nov 2002 17:33:51 - 1.1.2.6 +++ SyncedFoXmlEventsBuffer.java 1 Dec 2002 14:53:11 - 1.1.2.7 @@ -29,6 +29,13 @@ public class SyncedFoXmlEventsBuffer extends SyncedCircularBuffer { /** + * Constant for discardEvent field of + * 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 int index. */ @@ -1151,6 +1158,67 @@ return expectTypedEvent (XMLEvent.ENDELEMENT, event.uriIndex, event.localName, discardWhiteSpace); +} + +/** + * Get the next ENDELEMENT event, with the same URI index and local name + * as the FoXMLEvent argument, from the buffer. + * Discard any other events preceding the ENDELEMENT event. + * @param discardEvent the argument event may be discarded. + * @param event an FoXMLEvent. 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 FoXMLEvent argument. 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 FoXMLEvent. 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 characters + * events which contain only whitespace. + * @return a matching ENDELEMENT event. If the next + * event detected is not an ENDELEMENT, null 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; } /** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: xml-fop/src/org/apache/fop/xml SyncedFoXmlEventsBuffer.java
pbwest 2002/11/29 09:33:51 Modified:src/org/apache/fop/xml Tag: FOP_0-20-0_Alt-Design SyncedFoXmlEventsBuffer.java Log: Set pool. Use surrenderEvent(). Revision ChangesPath No revision No revision 1.1.2.6 +23 -10 xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java Index: SyncedFoXmlEventsBuffer.java === RCS file: /home/cvs/xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- SyncedFoXmlEventsBuffer.java 23 Nov 2002 14:42:05 - 1.1.2.5 +++ SyncedFoXmlEventsBuffer.java 29 Nov 2002 17:33:51 - 1.1.2.6 @@ -50,7 +50,7 @@ { super(); namespaces = new XMLNamespaces(); -pool = new FoXMLEventPool(namespaces); +pool = new FoXMLEventPool(namespaces, DEFAULTBUFSIZE); } /** @@ -160,6 +160,7 @@ ! (ev.type == eventType && ev.uriIndex == uriIndex && ev.localName.equals(localName))) { +pool.surrenderEvent(ev); ev = getEvent(); } if (ev == null) @@ -185,6 +186,7 @@ FoXMLEvent ev = getEvent(); while (ev != null && ! (ev.type == eventType && ev.foType == foType)) { +pool.surrenderEvent(ev); ev = getEvent(); } if (ev == null) @@ -214,6 +216,7 @@ if (discardWhiteSpace) { while (ev != null && ev.type == XMLEvent.CHARACTERS && ev.chars.trim().equals("")) { +pool.surrenderEvent(ev); ev = getEvent(); } } @@ -251,6 +254,7 @@ if (discardWhiteSpace) { while (ev != null && ev.type == XMLEvent.CHARACTERS && ev.chars.trim().equals("")) { +pool.surrenderEvent(ev); ev = getEvent(); } } @@ -290,6 +294,7 @@ if (discardWhiteSpace) { while (ev != null && ev.type == XMLEvent.CHARACTERS && ev.chars.trim().equals("")) { +pool.surrenderEvent(ev); ev = getEvent(); } } @@ -329,6 +334,7 @@ if (discardWhiteSpace) { while (ev != null && ev.type == XMLEvent.CHARACTERS && ev.chars.trim().equals("")) { +pool.surrenderEvent(ev); ev = getEvent(); } } @@ -541,6 +547,7 @@ // getEvent() returns null, the expectStartElement() calls // return null. ev = getEvent(); +pool.surrenderEvent(ev); } while (ev != null); // Exit from this while loop is only by discovery of null event throw new NoSuchElementException @@ -618,6 +625,7 @@ // getEvent() returns null, the expectStartElement() calls // will throw a NoSuchElementException ev = getEvent(); +pool.surrenderEvent(ev); } while (ev != null); // Exit from this while loop is only by discovery of null event throw new NoSuchElementException @@ -678,6 +686,7 @@ // getEvent() returns null, the expectStartElement() calls // will throw a NoSuchElementException ev = getEvent(); +pool.surrenderEvent(ev); } while (ev != null); // Exit from this while loop is only by discovery of null event throw new NoSuchElementException @@ -736,6 +745,7 @@ // getEvent() returns null, the expectStartElement() calls // will throw a NoSuchElementException ev = getEvent(); +pool.surrenderEvent(ev); } while (ev != null); // Exit from this while loop is only by discovery of null event throw new NoSuchElementException @@ -788,15 +798,17 @@ FoXMLEvent ev; do { try { -ev = expectStartElement(set, 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(); +ev = expectStartElement(set, discardWhiteSpace); +if (ev != null) return ev; +// The non-matching event has been pushed back. +// Get it and discard. Note that if the firs
cvs commit: xml-fop/src/org/apache/fop/xml SyncedFoXmlEventsBuffer.java
pbwest 2002/11/13 07:29:36 Modified:src/org/apache/fop/xml Tag: FOP_0-20-0_Alt-Design SyncedFoXmlEventsBuffer.java Log: Adjusted for reversal of sense of normal and outOfLine in FObjectSets. Removed Normal from name of expectNormal... methods. Added expectOutOfLineBlock(). Revision ChangesPath No revision No revision 1.1.2.4 +71 -5 xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java Index: SyncedFoXmlEventsBuffer.java === RCS file: /home/cvs/xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- SyncedFoXmlEventsBuffer.java 11 Nov 2002 17:24:18 - 1.1.2.3 +++ SyncedFoXmlEventsBuffer.java 13 Nov 2002 15:29:36 - 1.1.2.4 @@ -825,6 +825,15 @@ ("Unexpected START element: " + ev.getQName()); } +/** + * Expect that the next element will be a STARTELEMENT for one of the + * flow objects which are members of %block; from + * 6.2 Formatting Object Content, including out-of-line flow + * objects which may occur except as descendents of out-of-line formatting + * objects. White space is discarded. + * @return the FoXMLEvent found. If any other events are encountered + * return null. + */ public FoXMLEvent expectBlock() throws FOPException, UnexpectedStartElementException { @@ -832,7 +841,33 @@ (FObjectSets.blockEntity, XMLEvent.DISCARD_W_SPACE); } -public FoXMLEvent expectNormalPcdataOrInline() +/** + * Expect that the next element will be a STARTELEMENT for one of the + * flow objects which are members of %block; from + * 6.2 Formatting Object Content, excluding out-of-line flow + * objects which may not occur as descendents of out-of-line formatting + * objects. White space is discarded. + * @return the FoXMLEvent found. If any other events are encountered + * return null. + */ +public FoXMLEvent expectOutOfLineBlock() +throws FOPException, UnexpectedStartElementException +{ +return expectStartElement +(FObjectSets.outOfLineBlockSet, XMLEvent.DISCARD_W_SPACE); +} + +/** + * Expect that the next element will be a STARTELEMENT for one of the + * flow objects which are members of (#PCDATA|%inline;) from + * 6.2 Formatting Object Content, including out-of-line flow + * objects which may occur except as descendents of out-of-line + * formatting objects. White space is retained, and + * will appear as #PCDATA, i.e, as an instance of FoCharacters. + * @return the FoXMLEvent found. If any other events are encountered + * return null. + */ +public FoXMLEvent expectPcdataOrInline() throws FOPException, UnexpectedStartElementException { FoXMLEvent ev = expectStartElement @@ -842,6 +877,16 @@ return ev; } +/** + * Expect that the next element will be a STARTELEMENT for one of the + * flow objects which are members of (#PCDATA|%inline;) from + * 6.2 Formatting Object Content, excluding out-of-line flow + * objects which may not occur as descendents of out-of-line formatting + * objects. White space is retained, and + * will appear as #PCDATA, i.e, as an instance of FoCharacters. + * @return the FoXMLEvent found. If any other events are encountered + * return null. + */ public FoXMLEvent expectOutOfLinePcdataOrInline() throws FOPException, UnexpectedStartElementException { @@ -852,7 +897,17 @@ return ev; } -public FoXMLEvent expectNormalPcdataOrInlineOrBlock() +/** + * Expect that the next element will be a STARTELEMENT for one of the + * flow objects which are members of (#PCDATA|%inline;|%block;) from + * 6.2 Formatting Object Content, including out-of-line flow + * objects which may occur except as descendents of out-of-line + * formatting objects. White space is retained, and + * will appear as #PCDATA, i.e, as an instance of FoCharacters. + * @return the FoXMLEvent found. If any other events are + * encountered return null. + */ +public FoXMLEvent expectPcdataOrInlineOrBlock() throws FOPException, UnexpectedStartElementException { FoXMLEvent ev = expectStartElement @@ -862,11 +917,22 @@ return ev; } +/** + * Expect that the next element will be a STARTELEMENT for one of the + * flow objects which are members of (#PCDATA|%inline;|%block;) from + * 6.2 Formattin
cvs commit: xml-fop/src/org/apache/fop/xml SyncedFoXmlEventsBuffer.java
pbwest 2002/11/11 09:24:18 Modified:src/org/apache/fop/xml Tag: FOP_0-20-0_Alt-Design SyncedFoXmlEventsBuffer.java Log: Added expectBlock(), expectNormalPcdataOrInline(), expectOutOfLinePcdataOrInline(), expectNormalPcdataOrInlineOrBlock(), expectOutOfLinePcdataOrInlineOrBlock(). Revision ChangesPath No revision No revision 1.1.2.3 +59 -5 xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java Index: SyncedFoXmlEventsBuffer.java === RCS file: /home/cvs/xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- SyncedFoXmlEventsBuffer.java 7 Nov 2002 15:30:50 - 1.1.2.2 +++ SyncedFoXmlEventsBuffer.java 11 Nov 2002 17:24:18 - 1.1.2.3 @@ -3,6 +3,7 @@ import org.apache.fop.datastructs.SyncedCircularBuffer; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FObjectNames; +import org.apache.fop.fo.FObjectSets; import java.util.NoSuchElementException; import java.util.LinkedList; @@ -771,6 +772,7 @@ { FoXMLEvent ev; do { +try { ev = expectStartElement(set, discardWhiteSpace); if (ev != null) return ev; // The non-matching event has been pushed back. @@ -778,6 +780,9 @@ // getEvent() returns null, the expectStartElement() calls // will throw a NoSuchElementException ev = getEvent(); +} catch(UnexpectedStartElementException e) { +ev = getEvent(); +} } while (ev != null); // Exit from this while loop is only by discovery of null event throw new NoSuchElementException @@ -803,7 +808,7 @@ */ public FoXMLEvent expectStartElement (BitSet set, boolean discardWhiteSpace) -throws FOPException +throws FOPException, UnexpectedStartElementException { FoXMLEvent ev; ev = expectTypedEvent(XMLEvent.STARTELEMENT, discardWhiteSpace); @@ -813,9 +818,58 @@ if (ev.foType == i) return ev; // Found it! } -// Not found - push the STARTELEMENT event back +// Not found - push the STARTELEMENT event back and throw an +// UnexpectedStartElementException pushBack(ev); -return null; +throw new UnexpectedStartElementException +("Unexpected START element: " + ev.getQName()); +} + +public FoXMLEvent expectBlock() +throws FOPException, UnexpectedStartElementException +{ +return expectStartElement +(FObjectSets.blockEntity, XMLEvent.DISCARD_W_SPACE); +} + +public FoXMLEvent expectNormalPcdataOrInline() +throws FOPException, UnexpectedStartElementException +{ +FoXMLEvent ev = expectStartElement +(FObjectSets.normalPcdataInlineSet, XMLEvent.RETAIN_W_SPACE); +if (ev == null) +ev = expectCharacters(); +return ev; +} + +public FoXMLEvent expectOutOfLinePcdataOrInline() +throws FOPException, UnexpectedStartElementException +{ +FoXMLEvent ev = expectStartElement +(FObjectSets.inlineEntity, XMLEvent.RETAIN_W_SPACE); +if (ev == null) +ev = expectCharacters(); +return ev; +} + +public FoXMLEvent expectNormalPcdataOrInlineOrBlock() +throws FOPException, UnexpectedStartElementException +{ +FoXMLEvent ev = expectStartElement +(FObjectSets.normalPcdataBlockInlineSet, XMLEvent.RETAIN_W_SPACE); +if (ev == null) +ev = expectCharacters(); +return ev; +} + +public FoXMLEvent expectOutOfLinePcdataOrInlineOrBlock() +throws FOPException, UnexpectedStartElementException +{ +FoXMLEvent ev = expectStartElement +(FObjectSets.pcdataBlockInlineSet, XMLEvent.RETAIN_W_SPACE); +if (ev == null) +ev = expectCharacters(); +return ev; } /** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: xml-fop/src/org/apache/fop/xml SyncedFoXmlEventsBuffer.java
pbwest 2002/11/07 07:30:50 Modified:src/org/apache/fop/xml Tag: FOP_0-20-0_Alt-Design SyncedFoXmlEventsBuffer.java Log: Added getStartElement(BitSet, boolean) and expectStartElement(BitSet, boolean) for processing of FO sets within fo:page-sequence descendants. Revision ChangesPath No revision No revision 1.1.2.2 +68 -2 xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java Index: SyncedFoXmlEventsBuffer.java === RCS file: /home/cvs/xml-fop/src/org/apache/fop/xml/Attic/SyncedFoXmlEventsBuffer.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- SyncedFoXmlEventsBuffer.java 24 Oct 2002 14:39:11 - 1.1.2.1 +++ SyncedFoXmlEventsBuffer.java 7 Nov 2002 15:30:50 - 1.1.2.2 @@ -7,6 +7,7 @@ import java.util.NoSuchElementException; import java.util.LinkedList; import java.util.Iterator; +import java.util.BitSet; /* * $Id$ @@ -749,6 +750,71 @@ // Found it! if (ev != null) return ev; } +return null; +} + +/** + * Get one of a BitSet 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 BitSet. + * @param set a BitSet containing FO types one of which is + * required. + * @param discardWhiteSpace - if true, discard any characters + * 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(BitSet set, boolean discardWhiteSpace) +throws FOPException +{ +FoXMLEvent ev; +do { +ev = expectStartElement(set, 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 BitSet not found."); +} + +/** + * Expect one of an BitSet 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 BitSet. + * TODO: + * This method should be retro-fitted to list and array versions. + * + * @param set a BitSet containing the FO types + * of possible events, one of which must be the next returned. + * @param discardWhiteSpace - if true, discard any characters + * events which contain only whitespace. + * @return the matching STARTELEMENT event.If the next + * event detected is not of the required type, null 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 +(BitSet set, boolean discardWhiteSpace) +throws FOPException +{ +FoXMLEvent ev; +ev = expectTypedEvent(XMLEvent.STARTELEMENT, discardWhiteSpace); +if (ev == null) return ev; + +for (int i = set.nextSetBit(0); i >= 0; i = set.nextSetBit(++i)) { +if (ev.foType == i) +return ev; // Found it! +} +// Not found - push the STARTELEMENT event back +pushBack(ev); return null; } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]