cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@cocoon.zones.apache.org
Subject [DAISY] Comment added to Write a Custom Generator
Date Wed, 20 Sep 2006 12:09:19 GMT
A comment has been created.

http://cocoon.zones.apache.org/daisy/legacydocs/632.html

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 java.io.IOException;
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.startDocument();
      
      contentHandler.startElement("", "example", "example", emptyAttr);
      
      contentHandler.characters("Hello World!".toCharArray(),0,
                                  "Hello World!".length());

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

      contentHandler.endDocument();

    } 
}

Mime
View raw message