Luca,

The only thing that I can tell is that some of the events in your consumer really 
aren't being passed along, you're just logging the event. I suppose this might affect 
the process. My consumer implements and passes along EVERY single event aside from 
start/end-Document. I'll show that code below. Just to note though, I didn't not 
extend AbstractXMLConsumer, I implemented the XMLConsumer interface. I'm not sure how 
this would change things. Also, your code to perform the parsing looks correct, but 
you directly create a XercesParser whereas I went on ahead and used the Avalon parsing 
component (after all, we are coding a new component for Cocoon). So here is that code 
snippet:

        Parser parser;
        try {
            parser = (Parser) this.manager.lookup(Parser.ROLE);
        } catch(ComponentException ce) {
            // Failed to get it, so no need to try releasing it (probably null anyway).
            throw new SAXException(ce);
        }
        try {
            InputSource source = new InputSource(new StringReader(content));
            // XMLConsumer implements both ContentHandler and LexicalHandler.
            ContentPassingXMLConsumer handler = 
            new ContentPassingXMLConsumer(super.xmlConsumer);
            parser.parse(source, handler, handler);
        } catch(Exception e) {
            throw new SAXException(e);
        } finally {
            this.manager.release(parser);
        }

And finally, here is my consumer:

public class ContentPassingXMLConsumer implements XMLConsumer {
    
    protected XMLConsumer xmlConsumer;
    
    public ContentPassingXMLConsumer(XMLConsumer xmlConsumer) {
        this.xmlConsumer = xmlConsumer;
    }
    
    public void startDocument() throws SAXException {
        // The document is going to be embedded, so don't send this event.
    }
    
    public void ignorableWhitespace(char[] ch, int start, int length) 
    throws SAXException {
        this.xmlConsumer.ignorableWhitespace(ch, start, length);
    }
    
    public void characters(char[] ch, int start, int length) 
    throws SAXException {
        this.xmlConsumer.characters(ch, start, length);
    }
    
    public void endEntity(String name) throws SAXException {
        this.xmlConsumer.endEntity(name);
    }
    
    public void processingInstruction(String target, String data) 
    throws SAXException {
        this.xmlConsumer.processingInstruction(target, data);
    }
    
    public void startPrefixMapping(String prefix, String uri) 
    throws SAXException {
        this.xmlConsumer.startPrefixMapping(prefix, uri);
    }
    
    public void endDTD() throws SAXException {
        this.xmlConsumer.endDTD();
    }
    
    public void skippedEntity(String name) throws SAXException {
        this.xmlConsumer.skippedEntity(name);
    }
    
    public void endDocument() throws SAXException {
        // As with startDocument, don't send this event.
    }
    
    public void startDTD(String name, String publicId, String systemId) 
    throws SAXException {
        this.xmlConsumer.startDTD(name, publicId, systemId);
    }
    
    public void endCDATA() throws SAXException {
        this.xmlConsumer.endCDATA();
    }
    
    public void startCDATA() throws SAXException {
        this.xmlConsumer.startCDATA();
    }
    
    public void comment(char[] ch, int start, int length) throws SAXException {
        this.xmlConsumer.comment(ch, start, length);
    }
    
    public void setDocumentLocator(Locator locator) {
        this.xmlConsumer.setDocumentLocator(locator);
    }
    
    public void endPrefixMapping(String prefix) throws SAXException {
        this.xmlConsumer.endPrefixMapping(prefix);
    }
    
    public void startElement(String namespaceURI, String localName, 
    String qName, Attributes atts) throws SAXException {
        this.xmlConsumer.startElement(namespaceURI, localName, qName, atts);
    }
    
    public void endElement(String namespaceURI, String localName, String qName) 
    throws SAXException {
        this.xmlConsumer.endElement(namespaceURI, localName, qName);
    }
    
    public void startEntity(String name) throws SAXException {
        this.xmlConsumer.startEntity(name);
    }
}

This implements absolutely every method of XMLConsumer (ContentHandler and 
LexicalHandler) and passes all but the document methods on. I really don't know what 
else to tell you about why your code won't work. Again, I suspect it's either because 
you extend AbstractXMLConsumer and don't quite implement all the methods or because 
you're directly using a XercesParser instead of the Avalon parser. Hope this helps.

/S


"Luca Morandini" <[EMAIL PROTECTED]> wrote:

>Steven,
>
>first: we'd like to thank you for your help :)
>
>Second: we've tried to use your suggestion... to no avail :(
>
>Here's the failing code:
>
>InputSource source= new InputSource(new StringReader(svgs));
>XercesParser respParser;
>respParser= new XercesParser();
>ChartXMLConsumer cons= new ChartXMLConsumer((AbstractSAXTransformer)(this));
>respParser.setConsumer(cons);
>respParser.parse(source);
>
>It fails at the last statement with the dreaded "null pointer exc.".
>The parser we're using is an
>org.apache.cocoon.components.parser.XercesParser, while the ChartXMLConsumer
>is subclass of an org.apache.cocoon.xml.AbstractXMLConsumer, with suitable
>methods added.
>
>We think your idea is to trap some SAX events in the AbstractXMLConsumer
>subclass, and pass them along to the Transfomer class; while some SAX
>events, like StartDocument/EndDocument aren't passed along.
>
>Well, we've done that, but it fails before even passing a single SAX event
>to the transformer... any guess ?
>
>Best regards,
>
>P.S.
>Here's the AbstractXMLConsumer subclass code:
>
>    public class ChartXMLConsumer extends AbstractXMLConsumer {
>
>        AbstractSAXTransformer trasf;
>
>        ChartXMLConsumer(AbstractSAXTransformer trasfIn) {
>
>            this.trasf= trasfIn;
>        }
>
>        public void processingInstruction(String target, String data)
>                throws SAXException {
>
>            getLogger().debug("[CHART XML CONSUMER] RECEIVED AND IGNORED PI");
>        }
>
>        public void startDTD(String name, String publicId, String systemId)
>              throws SAXException {
>
>            getLogger().debug("[CHART XML CONSUMER] RECEIVED START DTD");
>        }
>
>        public void endDTD()
>            throws SAXException {
>
>            getLogger().debug("[CHART XML CONSUMER] RECEIVED START DTD");
>        }
>
>        public  void startDocument()
>                throws SAXException {
>
>            getLogger().debug("[CHART XML CONSUMER] RECEIVED START OF DOCUMENT
>V.02");
>        }
>
>        public  void endDocument()
>                throws SAXException {
>
>            getLogger().debug("[CHART XML CONSUMER] RECEIVED END OF DOCUMENT");
>        }
>
>        public void startElement(String uri, String name, String raw,
>                             Attributes attributes) throws SAXException {
>
>            getLogger().debug("[CHART XML CONSUMER] RECEIVED STARTELEMENT");
>            trasf.startElement(uri, name, raw, attributes);
>        }
>
>
>        public void endElement(String uri, String name, String raw)
>                throws SAXException {
>
>            getLogger().debug("[CHART XML CONSUMER] RECEIVED ENDELEMENT");
>            trasf.endElement(uri, name, raw);
>        }
>    }
>
>Luca Morandini
>[EMAIL PROTECTED]
>[EMAIL PROTECTED]
>
>> -----Messaggio originale-----
>> Da: Steven Cummings [mailto:cummingscs@;netscape.net]
>> Inviato: venerd́ 8 novembre 2002 17.43
>> A: [EMAIL PROTECTED]
>> Oggetto: RE: R: Strings to SAX events
>>
>>
>> Luca,
>>
>> I'm doing something very similar to implement a SOAPTransformer.
>> What I've done is implement an XMLConsumer so that it passes ALL
>> events that it recieves directly to the transformer's super-class
>> (super.startElement, super.endElement... etc.) Because you've
>> probably already started an output SAX stream that you want to
>> embed the content of the string in, you simply neglect to pass
>> along the startDocument and endDocument events. This is very
>> important. Otherwise, the solution is pretty simple. Hope this helps.
>>
>> /S
>>
>> "Luca Morandini" <[EMAIL PROTECTED]> wrote:
>>
>> >Ludovic,
>> >
>> >we're writing a Transformer to produce SVG (and JPEG/PNG
>> optionally) charts.
>> >The idea is having the chart description and associated data in XML as
>> >input, transform them, ending up with a nice SVG to be serialized.
>> >
>> >We're using a charting library which doesn't produce a SAX stream, but
>> >outputs the SVG element as a string, hence, the need to insert this XML
>> >elements in the output SAX stream.
>> >
>> >I hope this clears the matter :)
>> >
>> >Luca Morandini
>> >Istituto Poligrafico e Zecca dello Stato
>> >[EMAIL PROTECTED]
>> >[EMAIL PROTECTED]
>> >
>> >
>> >> -----Messaggio originale-----
>> >> Da: Ludovic de Beaurepaire [mailto:ludovic.debeaurepaire@;axonie.com]
>> >> Inviato: venerd́ 8 novembre 2002 11.26
>> >> A: [EMAIL PROTECTED]
>> >> Oggetto: Re: Strings to SAX events
>> >>
>> >>
>> >> Luca
>> >>
>> >> Sorry if it is NOK, but i didn't understand why you want to add
>> >> XML datas in
>> >> the transformer instead of in your pipeline's generator ?
>> >>
>> >> Ludovic
>> >> ----- Original Message -----
>> >> From: "Luca Morandini" <[EMAIL PROTECTED]>
>> >> To: <[EMAIL PROTECTED]>
>> >> Sent: Friday, November 08, 2002 11:11 AM
>> >> Subject: R: Strings to SAX events
>> >>
>> >>
>> >> > Ludovic,
>> >> >
>> >> > thanks for your kind answer, but we are not in an XSP page
>> >> (we're writing
>> >> a
>> >> > Transformer instead), hence, your suggestion is not truly
>> useful to us.
>> >> >
>> >> > Best regards,
>> >> >
>> >> > Luca Morandini
>> >> > [EMAIL PROTECTED]
>> >> >
>> >> > > -----Messaggio originale-----
>> >> > > Da: Ludovic de Beaurepaire
>> [mailto:ludovic.debeaurepaire@;axonie.com]
>> >> > > Inviato: venerd́ 8 novembre 2002 11.02
>> >> > > A: [EMAIL PROTECTED]
>> >> > > Oggetto: Re: Strings to SAX events
>> >> > >
>> >> > >
>> >> > > Try in a XSP the following, data is your xml string :
>> >> > >
>> >> > > <util:include-expr>
>> >> > > <util:expr><xsp:expr>
>> >> > > data
>> >> > > </xsp:expr></util:expr>
>> >> > > </util:include-expr>
>> >> > >
>> >> > >
>> >> > >
>> >> > > ----- Original Message -----
>> >> > > From: "Luca Morandini" <[EMAIL PROTECTED]>
>> >> > > To: <[EMAIL PROTECTED]>
>> >> > > Sent: Friday, November 08, 2002 10:55 AM
>> >> > > Subject: Strings to SAX events
>> >> > >
>> >> > >
>> >> > > > Folks,
>> >> > > >
>> >> > > >  We're in the process of writing a Transformer, which, of
>> >> > > course, outputs
>> >> > > > SAX
>> >> > > >  events... but, in the midst of this stream , we need to
>> insert an
>> >> > > >  XML element stored in a string.
>> >> > > >
>> >> > > >  To do this we're groping in the dark trying something like this:
>> >> > > >
>> >> > > >   JaxpParser respParser = new JaxpParser();
>> >> > > >   respParser.parse( new InputSource(new StringReader(str)),
>> >> > > >           new EmbeddedXMLPipe(contentHandler));
>> >> > > >
>> >> > > >  Which fails giving this:
>> >> > > >  org.apache.cocoon.ProcessingException: Failed to
>> execute pipeline.:
>> >> > > >  java.lang.ClassCastException
>> >> > > >  ...
>> >> > > >  Caused by: java.lang.ClassCastException
>> >> > > >   at
>> >> > > >
>> >> > > >
>> >> > > com.lucamorandini.charts.ChartTransformer.endElement(ChartTransfor
>> >> > > mer.java:6
>> >> > > > 55)
>> >> > > >   at
>> >> > > >
>> >> > > >
>> >> > > org.apache.cocoon.components.sax.XMLByteStreamInterpreter.parse(XM
>> >> > > LByteStrea
>> >> > > > mInterpreter.java:129)
>> >> > > >   at
>> >> > > >
>> >> > > >
>> >> > > org.apache.cocoon.components.sax.XMLByteStreamInterpreter.deserial
>> >> > > ize(XMLByt
>> >> > > > eStreamInterpreter.java:102)
>> >> > > >   at
>> >> > > >
>> org.apache.cocoon.components.pipeline.CachingEventPipeline.process
>> >> > > >  (CachingEventPipeline.java:219)
>> >> > > >   ... 44 more
>> >> > > >
>> >> > > >  java.lang.ClassCastException
>> >> > > >   at
>> >> > > >
>> >> > > >
>> >> > > com.lucamorandini.charts.ChartTransformer.endElement(ChartTransfor
>> >> > > mer.java:6
>> >> > > > 55)
>> >> > > >   at
>> >> > > >
>> >> > > >
>> >> > > org.apache.cocoon.components.sax.XMLByteStreamInterpreter.parse(XM
>> >> > > LByteStrea
>> >> > > > mInterpreter.java:129)
>> >> > > >   at
>> >> > > >
>> >> > > >
>> >> > > org.apache.cocoon.components.sax.XMLByteStreamInterpreter.deserial
>> >> > > ize(XMLByt
>> >> > > > eStreamInterpreter.java:102)
>> >> > > >   at
>> >> > > >
>> org.apache.cocoon.components.pipeline.CachingEventPipeline.process
>> >> > > >  (CachingEventPipeline.java:219)
>> >> > > >   at
>> >> > > >
>> >> > > >
>> >> > > org.apache.cocoon.components.pipeline.CachingStreamPipeline.proces
>> >> > > s(CachingS
>> >> > > > treamPipeline.java:399)
>> >> > > >
>> >> > > >  The classes we use are:
>> >> > > >   org.apache.avalon.excalibur.xml.JaxpParser;
>> >> > > >   org.xml.sax.InputSource;
>> >> > > >   java.io.StringReader;
>> >> > > >   org.apache.cocoon.xml.EmbeddedXMLPipe;
>> >> > > >
>> >> > > >  And the environment is:
>> >> > > >   Solaris 5.8
>> >> > > >   JDK 1.4.1_01
>> >> > > >   Tomcat 4.1.12-LE-jdk14
>> >> > > >   Cocoon 2.0.3
>> >> > > >
>> >> > > >  May someone please help us ?
>> >> > > >
>> >> > > >  Thanks in advance,
>> >> > > >
>> >> > > > Piero De Nicola & Luca Morandini
>> >> > > >
>> >> > > >
>> >> > > >      We are protected from the virus by Norton Antivirus
>> >> > > Corporate Edition
>> >> > > >
>> >> > > >
>> >> ---------------------------------------------------------------------
>> >> > > > Please check that your question  has not already been
>> >> answered in the
>> >> > > > FAQ before posting.
>> ><http://xml.apache.org/cocoon/faq/index.html>
>> >> > >
>> >> > > To unsubscribe, e-mail:
>> <[EMAIL PROTECTED]>
>> >> > > For additional commands, e-mail:
>> <[EMAIL PROTECTED]>
>> >> > >
>> >> > >
>> >> > >
>> >> >
>> >> >
>> >> > ---------------------------------------------------------------------
>> >> > Please check that your question  has not already been answered in the
>> >> > FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>> >> >
>> >> > To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
>> >> > For additional commands, e-mail:   <[EMAIL PROTECTED]>
>> >> >
>> >>
>> >>
>> >>      We are protected from the virus by Norton Antivirus
>> Corporate Edition
>> >>
>> >> ---------------------------------------------------------------------
>> >> Please check that your question  has not already been answered in the
>> >> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>> >>
>> >> To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
>> >> For additional commands, e-mail:   <[EMAIL PROTECTED]>
>> >>
>> >>
>> >>
>> >
>> >
>> >---------------------------------------------------------------------
>> >Please check that your question  has not already been answered in the
>> >FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>> >
>> >To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
>> >For additional commands, e-mail:   <[EMAIL PROTECTED]>
>> >
>> >
>> >     We are protected from the virus by Norton Antivirus
>> Corporate Edition
>> >
>> >---------------------------------------------------------------------
>> >Please check that your question  has not already been answered in the
>> >FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>> >
>> >To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
>> >For additional commands, e-mail:   <[EMAIL PROTECTED]>
>> >
>> >
>>
>>
>> --
>> Steven Cummings
>> Columbia, MO
>> Email: [EMAIL PROTECTED]
>> AIM:   cummingscs
>> ICQ:   3330114
>>
>>
>> __________________________________________________________________
>> The NEW Netscape 7.0 browser is now available. Upgrade now!
>> http://channels.netscape.com/ns/browsers/download.jsp
>>
>> Get your own FREE, personal Netscape Mail account today at
>> http://webmail.netscape.com/
>>
>> ---------------------------------------------------------------------
>> Please check that your question  has not already been answered in the
>> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>>
>> To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
>> For additional commands, e-mail:   <[EMAIL PROTECTED]>
>>
>>
>
>
>     We are protected from the virus by Norton Antivirus Corporate Edition
>
>---------------------------------------------------------------------
>Please check that your question  has not already been answered in the
>FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
>To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
>For additional commands, e-mail:   <[EMAIL PROTECTED]>
>
>


-- 
Steven Cummings
Columbia, MO
Email: [EMAIL PROTECTED]
AIM:   cummingscs
ICQ:   3330114


__________________________________________________________________
The NEW Netscape 7.0 browser is now available. Upgrade now! 
http://channels.netscape.com/ns/browsers/download.jsp 

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to