ovidiu      02/01/08 15:22:56

  Modified:    src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap
                        SitemapManager.java
  Log:
  Added support for using the sitemap components. Pass the sitemap components object 
as argument to the Scheme sitemap function instead of the ComponentManager. Setup the 
environment properly so the Scheme sitemap could work.
  
  Revision  Changes    Path
  1.2       +65 -5     
xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SitemapManager.java
  
  Index: SitemapManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SitemapManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SitemapManager.java       3 Jan 2002 12:31:35 -0000       1.1
  +++ SitemapManager.java       8 Jan 2002 23:22:56 -0000       1.2
  @@ -12,10 +12,12 @@
   import java.util.zip.GZIPInputStream;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  +import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
  @@ -25,10 +27,19 @@
   import org.apache.cocoon.Processor;
   import org.apache.cocoon.components.pipeline.EventPipeline;
   import org.apache.cocoon.components.pipeline.StreamPipeline;
  +import org.apache.cocoon.components.source.SourceHandler;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.environment.http.HttpContext;
   import org.apache.cocoon.environment.http.HttpEnvironment;
  +import org.apache.cocoon.generation.Generator;
  +import org.apache.cocoon.matching.Matcher;
  +import org.apache.cocoon.reading.Reader;
   import org.apache.cocoon.scheme.servlet.REPLGenericServlet;
  +import org.apache.cocoon.selection.Selector;
  +import org.apache.cocoon.serialization.Serializer;
  +import org.apache.cocoon.sitemap.AbstractSitemap;
  +import org.apache.cocoon.sitemap.SitemapComponentSelector;
  +import org.apache.cocoon.transformation.Transformer;
   import org.apache.cocoon.util.ClassUtils;
   import sisc.AppContext;
   import sisc.DynamicEnv;
  @@ -50,7 +61,7 @@
    */
   public class SitemapManager
     extends org.apache.cocoon.sitemap.SitemapManager
  -  implements ThreadSafe, Contextualizable, Composable
  +  implements Contextualizable, Composable
   {
     protected Symbol mainFunction;
     protected Stack interPool;
  @@ -58,6 +69,7 @@
     Context cocoonContext;
     HttpContext httpContext;
     J2S.JavaObject cm;
  +  SitemapComponents components;
   
     public void contextualize(Context context)
       throws ContextException
  @@ -94,6 +106,11 @@
       if (mainFunctionString == null)
         throw new ConfigurationException("Scheme entry point not specified");
   
  +    String componentsFileName = sconf.getAttribute("components");
  +    if (componentsFileName == null)
  +      throw new ConfigurationException("Components file not specified");
  +    setupComponents(componentsFileName);
  +
       String heapFileName = sconf.getAttribute("heap");
       if (heapFileName == null)
         throw new ConfigurationException("Heap Scheme file not specified");
  @@ -134,6 +151,38 @@
     }
   
     /**
  +   * Reads the components file and sets up the component manager
  +   * accordingly. For each component category we use a
  +   * ComponentSelector that stores the appropriate components using
  +   * their names.
  +   *
  +   * @param componentsFileName a <code>String</code> value
  +   */
  +  protected void setupComponents(String componentsFileName)
  +    throws ConfigurationException
  +  {
  +    try {
  +      components = new SitemapComponents();
  +      components.setLogger(getLogger());
  +//       components.setLogKitManager(sitemapLogKitManager);
  +//       components.setRoleManager(sitemapRoles, null);
  +      components.contextualize(cocoonContext);
  +      components.compose(manager);
  +
  +      org.apache.cocoon.environment.Context context =
  +        
(org.apache.cocoon.environment.Context)cocoonContext.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
  +
  +      InputStream is = context.getResource(componentsFileName).openStream();
  +      DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  +      Configuration conf = builder.build(is);
  +      components.configure(conf);
  +    } catch (Exception ex) {
  +      throw new ConfigurationException("Cannot load sitemap components file "
  +                                       + componentsFileName);
  +    }
  +  }
  +
  +  /**
      * Obtain a Scheme Interpreter from the internal pool of
      * interpreters.
      *
  @@ -190,20 +239,31 @@
     {
       String requestedURI = environment.getURI();
       
  +    J2S.JavaObject scomponents = new J2S.JavaObject(components);
       J2S.JavaObject senv = new J2S.JavaObject(environment);
   
       ImmutableString servletPath = new ImmutableString(requestedURI);
       Interpreter interp = getInterpreter();
  -    Value[] args = new Value[] {servletPath, cm, senv};
  +    Value[] args = new Value[] {servletPath, scomponents, senv};
  +    SourceHandler oldSourceHandler = environment.getSourceHandler();
  +    SourceHandler sourceHandler = null;
  +    Value result = sisc.Util.FALSE;
  +
       try {
  -      interp.eval((Procedure)interp.ctx.toplevel_env.lookup(mainFunction),
  -                  args);
  +      sourceHandler = (SourceHandler)manager.lookup(SourceHandler.ROLE);
  +      environment.setSourceHandler(sourceHandler);
  +      result
  +        = interp.eval((Procedure)interp.ctx.toplevel_env.lookup(mainFunction),
  +                      args);
       }
       finally {
         releaseInterpreter(interp);
  +      environment.setSourceHandler(oldSourceHandler);
  +      if (sourceHandler != null)
  +        manager.release(sourceHandler);
       }
   
  -    return true;
  +    return !result.eq(sisc.Util.FALSE);
     }
   
     public boolean process(Environment environment,
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to