cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jorg Heymans ...@domek.be>
Subject Re: Injecting a String XML document into a pipeline
Date Sat, 04 Jun 2005 18:48:52 GMT

Sebastien Arbogast wrote:

> 
> It depends on what you mean by "put the string in the request scope".
> I don't really understand how to translate that in code. Could you
> explain ?

1) Flow
// mystring contains your xml
cocoon.request.setAttribute("myxml", mystring);
// now forward to pipeline
cocoon.sendPage("mypipeline");

2) Custom generator pipeline
<map:match pattern="mypipeline">
  <map:generate type="customgen"/>
  <map:serialize type="xml"/>
</map:match>

3) in your custom generator
 - grab the "myxml" from request scope in setup(). You can get the
request object from the objectModel map.
 - in generate() you do something like
XMLReader parser = XMLReaderFactory.createXMLReader(
                    "org.apache.xerces.parsers.SAXParser");
parser.setContentHandler(this.contentHandler);
parser.parse(new InputSource(new BufferedInputStream(
    new ByteArrayInputStream(this.myXml.getBytes()))));

I've seen people asking for this quite often. This little snippet is key
in understanding how to send xml content from a string or byte[] down
the pipeline. It probably warrants an entry in the FAQ under "How to
write my own generator" , but i'll leave that one up to you ;-)


HTH
Jorg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message