You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Istvan Beszteri <is...@hut.fi> on 2002/07/31 19:36:25 UTC

own generator

Hi All,

I'd like to write my own generator. I have written the following generator 
according to the documents on the Cocoon 2 site, by extending an example.
I can start the generator properly, but I can not pass any parameter to it.
Somehow I'd like to reach the HTTP request itself (requested URI, headers 
etc.) within the generator.

public class AnyName extends AbstractGenerator
{
    /**
     * The only implemented method from AbstarctGenerator.
     * It simply generates SAX events from a string.
     */

    public void generate() throws IOException, SAXException, 
ProcessingException
    {
	//This string will be feeded to the transformer pipeline as sax events
        String xmlText = "<doc>\nMy first Cocoon 2 generator\n";

	//This object will read and parse the XML content
        XMLReader xmlReader = XMLReaderFactory.createXMLReader();

	//super.xmlConsumer will receive the SAX events
        xmlReader.setContentHandler(super.xmlConsumer);
        
        String paramNames[] = parameters.getNames();

        xmlText += "Number of parameters: " + paramNames.length + "\n";

	xmlText += "Parameter names:\n";

        for(int i = 0; i < paramNames.length; i++)
            xmlText += paramNames[i] + "\n";

        xmlText += "Source: " + source + "\n";

	xmlText += "</doc>";

        //Create an InputSource from the hardcoded string
        InputSource src = new InputSource(new StringReader(xmlText));

	//Parse the XML input and generate SAX events to the consumer
        xmlReader.parse(src);
    }
}

I use the following pipeline. In the generated XML I could see the 
parameters, and the source, but it seems that the source is null, and no 
parameters are passed to the generator.

<map:pipeline>
    <map:match pattern="foo/*">
      <map:act type="request">
        <map:parameter name="parameters" value="true"/>
        <map:generate type="ist" source="{1}"/>
        <map:serialize type="xml"/>
      </map:act>
    </map:match>

    <map:handle-errors>
      <map:transform src="stylesheets/system/error2html.xsl"/>
      <map:serialize status-code="500"/>
    </map:handle-errors>
  </map:pipeline>


How could I get the request data in the generator?

Thanks in advance!
Br,
  Istvan

---------------------------------------------------------------------
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:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


RE: own generator

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Istvan Beszteri [mailto:istvan.beszteri@hut.fi]
> 
> Hi All,
> 
> I'd like to write my own generator. I have written the following
generator
> according to the documents on the Cocoon 2 site, by extending an
example.
> I can start the generator properly, but I can not pass any parameter
to it.
> Somehow I'd like to reach the HTTP request itself (requested URI,
headers
> etc.) within the generator.
> 
> public class AnyName extends AbstractGenerator
> {

ServletGenerator has:

    protected Request request;

...

> I use the following pipeline. In the generated XML I could see the
> parameters, and the source, but it seems that the source is null, and
no
> parameters are passed to the generator.
> 
> <map:pipeline>
>     <map:match pattern="foo/*">
>       <map:act type="request">
>         <map:parameter name="parameters" value="true"/>
>         <map:generate type="ist" source="{1}"/>

http://xml.apache.org/cocoon/faq/faq-actions.html#faq-2

See also recent threads.

Vadim


>         <map:serialize type="xml"/>
>       </map:act>
>     </map:match>
> 
>     <map:handle-errors>
>       <map:transform src="stylesheets/system/error2html.xsl"/>
>       <map:serialize status-code="500"/>
>     </map:handle-errors>
>   </map:pipeline>
> 
> 
> How could I get the request data in the generator?
> 
> Thanks in advance!
> Br,
>   Istvan
> 


---------------------------------------------------------------------
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:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>