cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Phillips <>
Subject cocoon2 generator implementation query
Date Sun, 21 Oct 2001 19:00:19 GMT
I have been looking at making a cocoon2 generator and would be
interested in advice or criticism about my strategy.

I have standalone sax2  test programs that implement a 'fake parser'
like michal kay's gedcom parser reading a text file, emitting sax events

written to an xml file that is (possibly) transformed. I am breaking up
a text file into <line><word>.

another, similar parser reads comma delimited files from (for example)

Looking at the ../generation sources, I chose the HTML generator as a
model. It, however, uses DOM
and then converts it into SAX events.

The 'PoemtxtParser' emits sax events & I expect to hook it into the
{pipeline?} that is defined in the
sitemap by

 <map:generator name="poemtxt"
src="org.apache.cocoon.generation.PoemtxtGenerator" label="content"/>

in the generator section


 <map:match pattern="poemtxt">
     <map:generate type="poemtxt" src="poemtxt/**.txt"/>

     <map:transform type="xslt"
     <map:serialize type="html"/>

The main program of my existing code writes to system.out and I need, I
believe to replace this output source with a connection to the cocoon2
pipeline. Here is the main excerpt:

 String poemtxtFileName = args[0];
      String xsltFileName = (args.length > 1) ? args[1] : null;

      TransformerFactory transFact = TransformerFactory.newInstance();
      if (transFact.getFeature(SAXTransformerFactory.FEATURE)) {
        SAXTransformerFactory saxTransFact = (SAXTransformerFactory)
        TransformerHandler transHand = null;
        if (xsltFileName == null) {
          transHand = saxTransFact.newTransformerHandler();
        } else {
          transHand = saxTransFact.newTransformerHandler(new
StreamSource(new File(xsltFileName)));

        // set the desitnation for the xslt transformation
        transHand.setResult(new StreamResult(System.out));

        //hook the poemtxtParser to the poemtxtFile
        PoemtxtParser poemtxtReader = new PoemtxtParser();
        InputSource poemtxtInputSrc = new InputSource(new

        // attach the XSLT processor to the poemtxtParser


The PoemtxtParser.parse  implements XMLReader and Locator

and emits calls to contentHandler.startDocument and .StartElement (and
so on).


Does this make sense or am I missing something already existing in
Cocoon2 that
would accomplish my goal/


Bob Phillips

Please check that your question has not already been answered in the
FAQ before posting. <>

To unsubscribe, e-mail: <>
For additional commands, e-mail: <>

View raw message