cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grzegorz Sikora <>
Subject Re: Could some help in this!
Date Wed, 06 Apr 2005 13:18:40 GMT
Hello fadi,

Tuesday, April 5, 2005, 5:01:15 PM, you wrote:
fq> The second match pattern builds a session context and loads
fq> its data from the first match pattern. How can I tell cocoon to
fq> automatically execute the second match pattern (i.e. without
fq> explicitly requesting it via the Internet explorer). is it
fq> possible to do this ?   

Maybe flowscript would be better approach ...  but I've written simple action
which can call another pipeline and eventually creates sitemap
parameter with returned XML as DOM tree:

import org.apache.avalon.excalibur.component.ComponentHandler;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.acting.ConfigurableComposerAction;
import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
import org.apache.cocoon.components.sax.XMLByteStreamFragment;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.generation.FileGenerator;
import org.apache.cocoon.xml.AbstractXMLConsumer;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;

public class CallPipelineAction extends ConfigurableComposerAction implements
    Disposable, ThreadSafe {

  ComponentHandler generatorHandler;

  public void configure(Configuration conf) throws ConfigurationException {
    try {
      this.generatorHandler = ComponentHandler.getComponentHandler(
          FileGenerator.class, conf, this.manager, null,


    } catch (Exception e) {
      throw new ConfigurationException("Cannot set up component handler", e);

  public void dispose() {
    if (this.generatorHandler != null) {
      this.generatorHandler = null;

  public Map act(Redirector redirector, SourceResolver resolver,
      Map objectModel, String source, Parameters parameters) throws Exception {

    String pipeline = parameters.getParameter("pipeline");
    String discard = parameters.getParameter("discard", "false");
    String outputParamName = parameters.getParameter("output", "output");

    FileGenerator generator = (FileGenerator) this.generatorHandler.get();

    XMLByteStreamCompiler compiler = null;

    Map map = new HashMap();

    try {
      Parameters genParams = new Parameters();


      generator.setup(resolver, objectModel, pipeline, genParams);

      if (discard.equals("true")) {
        generator.setConsumer(new AbstractXMLConsumer() {
      } else {
        compiler = new XMLByteStreamCompiler();
        XMLByteStreamFragment fragment = new XMLByteStreamFragment(compiler

        DocumentBuilder builder = DocumentBuilderFactory.newInstance()
        Document doc = builder.newDocument();
        Request request = ObjectModelHelper.getRequest(objectModel);
        request.setAttribute(outputParamName, doc);

    } catch (Exception e) {
      if (getLogger().isErrorEnabled())
        getLogger().error("Error while calling another pipeline " + e);
      map = null;
    } finally {

    return map;


Sample usage:
<map:act type="call-pipeline">
         <map:parameter name="pipeline"
         <map:parameter name="discard" value="true"/>

Best regards,
 Grzegorz Sikora

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

View raw message