cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Istvan Beszteri <>
Subject Re: own generator
Date Thu, 01 Aug 2002 09:35:51 GMT
Hi All,

Thanks for the help.
I tried Geoff's modified version, and it works with some small corrections.
Here is the code (Maybe some of the imports are not used at all):

import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLReaderFactory;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.generation.AbstractGenerator;
import java.lang.String;

// for the setup() method
import org.apache.cocoon.environment.SourceResolver;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;

// used to get and hold the request parameters.
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import java.util.Enumeration;

// SAX helper
import org.xml.sax.helpers.AttributesImpl;

public class NewAnyName extends AbstractGenerator 

    // will be initialized in the setup() method and used in generate()
    Request request = null;
    Enumeration paramNames = null;
    String uri = null;

     * Implement the generate() method from AbstractGenerator.
     * It simply generates SAX events using SAX methods.

    public void generate() throws IOException, SAXException, 
	// xspAttr will stay empty for this simple implementation
	// If we had any attributes in our tags, we would add them to this variable
	// before the call to startElement(), and either create a new AttributesImpl
	// instance for each element, or reuse one being careful to reset it before 
	// each use.
	AttributesImpl xspAttr = new AttributesImpl();

      // contentHandler is inherited from 
      // Do it with SAX:
      contentHandler.startElement("", "doc", "doc", xspAttr);

      contentHandler.startElement("", "uri", "uri", xspAttr);


      contentHandler.endElement("", "uri", "uri");
      contentHandler.startElement("", "params", "params", xspAttr);
      while (paramNames.hasMoreElements())
          contentHandler.startElement("", "param", "param", xspAttr);
	  String param = (String)paramNames.nextElement();

          contentHandler.endElement("","param", "param");
      contentHandler.endElement("","params", "params");

      contentHandler.startElement("", "source", "source", xspAttr);

      if(source != null)

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

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

   public void setup(SourceResolver resolver, Map objectModel, String src,
		     Parameters par)
       request = ObjectModelHelper.getRequest(objectModel);
       paramNames = request.getParameterNames();
       uri = request.getRequestURI();

The pipeline is the following:

    <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:transform src="stylesheets/system/error2html.xsl"/>
      <map:serialize status-code="500"/>

A test reqest:


<?xml version="1.0" encoding="UTF-8"?>

As you can see, the source filed is still null.
Anyway, my problem is solved. I can get the request in the generator. I'm 
just curious what is the solution for this "source" thing.


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