You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by da...@cocoon.zones.apache.org on 2006/09/19 22:32:58 UTC
[DAISY] Comment added to Write a Custom Generator
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();
}
}