Package org.apache.cocoon.components.treeprocessor.sitemap

Source Code of org.apache.cocoon.components.treeprocessor.sitemap.ContinueNode

package org.apache.cocoon.components.treeprocessor.sitemap;

import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.cocoon.components.flow.ContinuationsManager;
import org.apache.cocoon.components.flow.Interpreter;
import org.apache.cocoon.components.flow.InterpreterSelector;
import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
import org.apache.cocoon.components.treeprocessor.InvokeContext;
import org.apache.cocoon.components.treeprocessor.MapStackResolver;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.sitemap.PatternException;

public class ContinueNode
  extends AbstractProcessingNode
  implements Configurable, Composable
{
  protected String continuationId;
  protected MapStackResolver continuationIdResolver;
  protected ComponentManager manager;

  public ContinueNode(String contId)
  {
    this.continuationId = contId;
  }

  public void configure(Configuration config)
    throws ConfigurationException
  {
    try {
      if (MapStackResolver.needsResolve(continuationId)) {
        // This should happen all the time, but who knows...
        this.continuationIdResolver
          = MapStackResolver.getResolver(continuationId);
      }
    }
    catch (PatternException ex) {
      throw new ConfigurationException(ex.toString());
    }
  }

  public void compose(ComponentManager manager)
  {
    this.manager = manager;
  }

  public boolean invoke(Environment env, InvokeContext context)
      throws Exception
  {
    String contId = continuationId;

    if (continuationIdResolver != null) {
      contId = continuationIdResolver.resolve(context.getMapStack());
    }

    InterpreterSelector selector
      = (InterpreterSelector)manager.lookup(Interpreter.ROLE);

    // FIXME: How to detect the language associated with the
    // continuation object? Use the default language for now, but it
    // should be fixed ASAP.
    String language = selector.getDefaultLanguage();

    // Obtain the Interpreter instance for this language
    Interpreter interpreter = (Interpreter)selector.select(language);

    try {
      interpreter.handleContinuation(contId, env, context);
    }
    finally {
      selector.release((Component)interpreter);
    }

    return true;
  }
}
TOP

Related Classes of org.apache.cocoon.components.treeprocessor.sitemap.ContinueNode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.