pbwest 2004/01/19 23:14:39 Modified: src/java/org/apache/fop/xml Tag: FOP_0-20-0_Alt-Design XmlEventReader.java Log: Modifications to allow element contents to be buffered Revision Changes Path No revision No revision 1.1.2.2 +150 -37 xml-fop/src/java/org/apache/fop/xml/Attic/XmlEventReader.java Index: XmlEventReader.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/xml/Attic/XmlEventReader.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- XmlEventReader.java 20 Jan 2004 05:45:54 -0000 1.1.2.1 +++ XmlEventReader.java 20 Jan 2004 07:14:39 -0000 1.1.2.2 @@ -126,27 +126,34 @@ } /** - * 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. + * Get the next event of the given SAX type, from the given namespace + * (<code>uriIndex</code>) with the given local name, from the buffer. + * Discard intervening events. + * @param eventType the SAX event type. + * @param uriIndex the URI index maintained in the + * <tt>Namespaces</tt> object. + * @param localName 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 getSaxQNameEvent(int eventType, String qName) + public XmlEvent getSaxUriLocalEvent + (int eventType, int uriIndex, String localName) throws FOPException { XmlEvent ev = source.getEvent(); while (ev != null && - ! (ev.type == eventType && ev.qName.equals(qName))) { + ! (ev.type == eventType + && ev.uriIndex == uriIndex + && ev.localName.equals(localName))) { + namespaces.relinquishEvent(ev); ev = source.getEvent(); } - if (ev == null) { + if (ev == null) throw new NoSuchElementException - (XmlEvent.eventTypeName(eventType) + " " + qName + " not found."); - } + (XmlEvent.eventTypeName(eventType) + + namespaces.getIndexURI(uriIndex) + + ":" + localName + " not found."); return ev; } @@ -158,27 +165,29 @@ * @param uriIndex the URI index maintained in the * <tt>Namespaces</tt> object. * @param localName of the required element. + * @param buffer into whcih to copy intervening events. * @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 getSaxUriLocalEvent - (int eventType, int uriIndex, String localName) - throws FOPException + public XmlEvent getSaxUriLocalEvent( + int eventType, int uriIndex, String localName, + ArrayXmlEventsBuffer buffer) + throws FOPException { XmlEvent ev = source.getEvent(); while (ev != null && - ! (ev.type == eventType - && ev.uriIndex == uriIndex - && ev.localName.equals(localName))) { - namespaces.relinquishEvent(ev); + ! (ev.type == eventType + && ev.uriIndex == uriIndex + && ev.localName.equals(localName))) { + buffer.pushEvent(ev); ev = source.getEvent(); } if (ev == null) throw new NoSuchElementException - (XmlEvent.eventTypeName(eventType) - + namespaces.getIndexURI(uriIndex) - + ":" + localName + " not found."); + (XmlEvent.eventTypeName(eventType) + + namespaces.getIndexURI(uriIndex) + + ":" + localName + " not found."); return ev; } @@ -230,7 +239,59 @@ + namespaces.getIndexURI(uriIndex) + " type " + nsType + " not found."); } - + + /** + * Get the next event with of the given SAX type, whose URI is matched + * by the namespaces URI indexed by <code>uriIndex</code>, and whose + * namespace-specific type matches <code>nsType</code>. + * Copy any intervening events into the specified buffer. + * @param eventType the SAX event type + * @param uriIndex of the URI in namespaces + * @param nsType the namespace-specific type + * @param buffer into whcih to copy intervening events + * @return the matching event + * @throws FOPException + */ + public XmlEvent getSaxUriTypedEvent( + int eventType, int uriIndex, int nsType, + ArrayXmlEventsBuffer buffer) + throws FOPException { + XmlEvent ev = source.getEvent(); + while (ev != null) { + if (ev.type == eventType && ev.uriIndex == uriIndex) { + switch (uriIndex) { + case Namespaces.DefAttrNSIndex: + throw new NoSuchElementException + ("No special types for default attribute namespace"); + case Namespaces.XSLNSpaceIndex: + // The FO namespace + if (ev.getFoType() == nsType) { + return ev; + } + break; + case Namespaces.FOXNSpaceIndex: + // The FOX namespace + if (ev.getFoxType() == nsType) { + return ev; + } + break; + case Namespaces.SVGNSpaceIndex: + // The SVG namespace + if (ev.getSvgType() == nsType) { + return ev; + } + break; + } + } + buffer.pushEvent(ev); + ev = source.getEvent(); + } + throw new NoSuchElementException + (XmlEvent.eventTypeName(eventType) + " " + + namespaces.getIndexURI(uriIndex) + + " type " + nsType + " not found."); + } + /** * Get the next event of the given type, from the fo: namespace, with * the given FO type. Discard intervening events. @@ -248,6 +309,25 @@ } /** + * Get the next event of the given type, from the fo: namespace, with + * the given FO type. Copy intervening events into the specified + * buffer. + * @param eventType - the <tt>int</tt> event type. + * @param foType - the <tt>int</tt> FO type. + * @param buffer the event buffer into which to copy intervening events + * @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 getSaxFoEvent( + int eventType, int foType, ArrayXmlEventsBuffer buffer) + throws FOPException + { + return getSaxUriTypedEvent( + eventType, Namespaces.XSLNSpaceIndex, foType, buffer); + } + + /** * 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. @@ -1007,20 +1087,6 @@ return expectSaxEvent(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 getSaxQNameEvent(XmlEvent.ENDELEMENT, qName); - } /** * Get the next ENDELEMENT event with the given URI index and local name @@ -1113,6 +1179,9 @@ public XmlEvent getEndElement(XmlEvent event) throws FOPException { int foType; + if (event.getType() == XmlEvent.CHARACTERS) { + throw new FOPException("CHARS event passed to getEndElement"); + } if ((foType = event.getFoType()) != FObjectNames.NO_FO) return getSaxFoEvent(XmlEvent.ENDELEMENT, foType); return getSaxUriLocalEvent @@ -1139,6 +1208,9 @@ throws FOPException { int foType; + if (event.getType() == XmlEvent.CHARACTERS) { + throw new FOPException("CHARS event passed to getEndElement"); + } if ((foType = event.getFoType()) != FObjectNames.NO_FO) return expectSaxFoEvent (XmlEvent.ENDELEMENT, foType, discardWhiteSpace); @@ -1164,6 +1236,9 @@ { XmlEvent ev; int foType; + if (event.getType() == XmlEvent.CHARACTERS) { + throw new FOPException("CHARS event passed to getEndElement"); + } if ((foType = event.getFoType()) != FObjectNames.NO_FO) ev = getSaxFoEvent(XmlEvent.ENDELEMENT, foType); else @@ -1177,6 +1252,41 @@ } /** + * Get the next ENDELEMENT event, with the same URI index and local name + * as the <tt>XmlEvent</tt> argument, from the buffer. + * Place references to all intervening events in the provided + * <code>ArrayXmlEventsBuffer</code>. + * @param buffer into which to copy the events + * @param discardEvent the argument event may be discarded. + * @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( + ArrayXmlEventsBuffer buffer, boolean discardEvent, XmlEvent event) + throws FOPException + { + XmlEvent ev; + int foType; + if (event.getType() == XmlEvent.CHARACTERS) { + throw new FOPException("CHARS event passed to getEndElement"); + } + if ((foType = event.getFoType()) != FObjectNames.NO_FO) + ev = getSaxFoEvent(XmlEvent.ENDELEMENT, foType, buffer); + else + ev = getSaxUriLocalEvent( + XmlEvent.ENDELEMENT, event.uriIndex, event.localName, + buffer); + if (discardEvent) { + namespaces.relinquishEvent(event); + } + return ev; + } + + /** * 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. @@ -1198,6 +1308,9 @@ { XmlEvent ev; int foType; + if (event.getType() == XmlEvent.CHARACTERS) { + throw new FOPException("CHARS event passed to getEndElement"); + } if ((foType = event.getFoType()) != FObjectNames.NO_FO) ev = expectSaxFoEvent (XmlEvent.ENDELEMENT, foType, discardWhiteSpace);
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]