cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [DAISY] Comment added to Write a Custom Generator
Date Tue, 19 Sep 2006 20:32:58 GMT
A comment has been created.

Document ID: 632
Name: Write a Custom Generator
Branch: main
Language: default

Created by: Ulli Kraemer
Created on: 9/19/06 8:32:48 PM
Visibility: public

The following version of the "Simple Example" worked better
for me (See signature of method "generate" in interface "Generator"):

import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.generation.AbstractGenerator;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.SAXException;

public class HelloWorldGenerator extends AbstractGenerator 

    AttributesImpl emptyAttr = new AttributesImpl();

     * Override the generate() method from AbstractGenerator.
     * It simply generates SAX events using SAX methods.  
     * I haven't done the comparison myself, but this 
     * has to be faster than parsing them from a string.

    public void generate() throws SAXException, IOException, ProcessingException
      // the org.xml.sax.ContentHandler is inherited 
      // through org.apache.cocoon.xml.AbstractXMLProducer 

      contentHandler.startElement("", "example", "example", emptyAttr);
      contentHandler.characters("Hello World!".toCharArray(),0,
                                  "Hello World!".length());

      contentHandler.endElement("","example", "example");



View raw message