ovidiu 02/01/18 17:07:13 Modified: src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap SchemeSitemap.java Log: Moved the old content to SchemeSitemapFunctions. This file is now an extension of the AbstractSitemap, which is responsible with reading the components that are to be used in a sitemap. It's responsible with starting the processing of the Environment. Another responsibility is triggering the parsing of the XML sitemap, and translating it into Scheme. The actual work is done by the SchemeSitemapFunctions#parse and the Schme code in scheme/sitemap.scm. Revision Changes Path 1.3 +220 -490 xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SchemeSitemap.java Index: SchemeSitemap.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SchemeSitemap.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SchemeSitemap.java 10 Jan 2002 05:19:30 -0000 1.2 +++ SchemeSitemap.java 19 Jan 2002 01:07:13 -0000 1.3 @@ -1,580 +1,310 @@ package org.apache.cocoon.scheme.sitemap; +import java.io.InputStream; +import java.util.Date; import org.apache.avalon.framework.component.Component; +import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.parameters.Parameters; +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.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; +import org.apache.cocoon.Constants; import org.apache.cocoon.components.pipeline.EventPipeline; import org.apache.cocoon.components.pipeline.StreamPipeline; import org.apache.cocoon.environment.Environment; -import sisc.ContinuationException; +import org.apache.cocoon.environment.Source; +import org.apache.cocoon.sitemap.AbstractSitemap; +import org.apache.cocoon.sitemap.Sitemap; import sisc.Interpreter; -import sisc.ModuleAdapter; -import sisc.data.Pair; +import sisc.data.ImmutableString; +import sisc.data.Procedure; import sisc.data.Symbol; import sisc.data.Value; import sisc.modules.J2S; /** - * This class contains the definition of the Scheme functions: * - * <ul> + * This is the main driver for the Scheme sitemap implementation. It + * is setup by the {@link SchemeSitemapHandler} class. It reads the + * <file>components.xconf</file> file, which describes what are the + * components that can be used in a sitemap. It sets up a pool of + * Scheme interpreters that handle the actual sitemap invocation. * - * <li><b>sitemap:generate</b> - create a new {@link - * org.apache.cocoon.components.pipeline.StreamPipeline}, and adds the - * generator specified by the function arguments to it. The prototype - * of Scheme function is: - * <pre> - * sitemap:generate: SitemapComponents Environment params -> StreamPipeline - * </pre> - * - * - * <li><b>sitemap:read</b> - creates a new {@link - * org.apache.cocoon.components.pipeline.StreamPipeline} and a new - * {@link org.apache.cocoon.reading.Reader}, adds the reader to the - * pipeline, and returns the pipeline. The prototype of the Scheme - * function is: - * <pre> - * sitemap:read: SitemapComponents Environment params -> StreamPipeline - * </pre> - * - * <li><b>sitemap:transform</b> - creates a transformer object of the - * type specified by the arguments, adds it to the pipeline passed as - * argument, and returns the pipeline. The prototype of the Scheme - * function is: - * <pre> - * sitemap:transform: SitemapComponents Environment params StreamPipeline - * -> StreamPipeline - * </pre> - * - * <li><b>sitemap:serialize</b> - creates a serializer object of the - * type specified by the arguments, adds it to the pipeline passed as - * argument, and returns the pipeline. The prototype of the Scheme - * function is: - * <pre> - * sitemap:serialize: SitemapComponents Environment params StreamPipeline - * -> StreamPipeline - * </pre> - * - * <li><b>sitemap:process</b> - processes the given pipeline passed - * as argument. This has the side effect of processing the pipeline, - * as it was specified in the sitemap. - * <pre> - * sitemap:process: SitemapComponents Environment params StreamPipeline - * -> void - * </pre> - * - * </ul> - * - * <p>With these Scheme functions, a pipeline processing setup would - * look like this: - * - * <pre> - * (match "some-url/(.*)" (sitemap env file . args) - * (sitemap:process sitemap env (list (cons 'type "xml")) - * (sitemap:transform sitemap env (list (cons 'type "xslt") - * (cons 'src "stylesheet/a.xsl")) - * (sitemap:generate sitemap env (list (cons 'src (concat "docs/" file)))) - * ))) - * </pre> + * <p>The actual sitemap handling is done in the Scheme code, look for + * it in the <file>sitemap.scm</file> file. * * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> - * @since December 20, 2001 - * - * @see org.apache.cocoon.components.pipeline.EventPipeline - * @see org.apache.cocoon.components.pipeline.StreamPipeline - * @see org.apache.cocoon.reading.Reader + * @since January 4, 2002 */ -public class SchemeSitemap extends ModuleAdapter +public class SchemeSitemap + extends AbstractSitemap + implements Configurable, Sitemap, Contextualizable, Composable { - public String getModuleName() - { - return "Apache Cocoon Sitemap Components"; - } - - public float getModuleVersion() - { - return 1.0f; - } - - public static final int - GENERATE = 1, - READER = 2, - TRANSFORM = 3, - SERIALIZE = 4, - PROCESS = 5; + protected String defaultGenerator; + protected String defaultTransformer; + protected String defaultReader; + protected String defaultSerializer; + protected String defaultSelector; - protected Parameters emptyParam = new Parameters(); + Context cocoonContext; - /** - * Creates a new <code>SchemeSitemap</code> instance. Defines - * the Scheme functions implemented by this module. - */ - public SchemeSitemap() + public void configure(Configuration confs) + throws ConfigurationException { - define("sitemap:generate", GENERATE); - define("sitemap:read", READER); - define("sitemap:transform", TRANSFORM); - define("sitemap:serialize", SERIALIZE); - define("sitemap:process", PROCESS); + String componentsFileName = confs.getAttribute("components"); + if (componentsFileName == null) + throw new ConfigurationException("Components file not specified"); + setupSitemap(componentsFileName); } /** - * The SISC evaluator function for this module. Executes the actual - * Java code corresponding to the Scheme functions defined by the - * module. + * 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 primid an <code>int</code> value - * @param r an <code>Interpreter</code> value - * @return a <code>Value</code> value + * @param componentsFileName a <code>String</code> value */ - public Value eval(int primid, Interpreter r) - throws ContinuationException + protected void setupSitemap(String componentsFileName) + throws ConfigurationException { try { - switch (r.vlr.length) { + org.apache.cocoon.environment.Context context = + (org.apache.cocoon.environment.Context)cocoonContext.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - // Three argument functions - case 3: - switch (primid) { - case GENERATE: - return generate(r.vlr[0], r.vlr[1], r.vlr[2]); - case READER: - return read(r.vlr[0], r.vlr[1], r.vlr[2]); - } - - case 4: - switch (primid) { - case TRANSFORM: - return transform (r.vlr[0], r.vlr[1], r.vlr[2], r.vlr[3]); - case SERIALIZE: - return serialize (r.vlr[0], r.vlr[1], r.vlr[2], r.vlr[3]); - case PROCESS: - return process (r.vlr[0], r.vlr[1], r.vlr[2], r.vlr[3]); - } - } - } - catch (Exception ex) { + InputStream is = context.getResource(componentsFileName).openStream(); + DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); + Configuration conf = builder.build(is); + loadComponents(conf); + } catch (Exception ex) { ex.printStackTrace(); - throw new RuntimeException(ex.toString()); + throw new ConfigurationException("Cannot load sitemap components file " + + componentsFileName + + ": " + ex.toString()); } - - throw new RuntimeException("Invalid number of arguments to function " - + r.acc + ", got " + r.vlr.length); } /** - * Type cast function from a Scheme wrapper of a ComponentManager. + * Initialize the sitemap components according to the configuration + * in components.xconf. * - * @param scm a Scheme wrapper instance of a ComponentManager. - * @return a <code>ComponentManager</code> value + * @param confs a <code>Configurations</code> value */ - static public SitemapComponents sitemapComponents(Value scm) + public void loadComponents(Configuration confs) + throws ConfigurationException { - try { - return (SitemapComponents)(((J2S.JavaObject)scm).o); - } - catch (ClassCastException ex) { - typeError("SitemapComponents", scm); - } - return null; - } + System.out.print("Loading the sitemap components... "); + System.out.flush(); - /** - * Type cast function from a Scheme wrapper of an Environment - * instance. - * - * @param scm a Scheme wrapper of an Environment instance. - * @return an <code>Environment</code> value - */ - static public Environment environment(Value scm) - { try { - return (Environment)(((J2S.JavaObject)scm).o); + Configuration generatorsConf = confs.getChild("generators"); + defaultGenerator = generatorsConf.getAttribute("default"); + Configuration[] gConf = generatorsConf.getChildren("generator"); + for (int i = 0; i < gConf.length; i++) + load_component(Sitemap.GENERATOR, + gConf[i].getAttribute("name", ""), + gConf[i].getAttribute("src"), + gConf[i], + gConf[i].getAttribute("mime-type", null)); + + Configuration readersConf = confs.getChild("readers"); + defaultReader = readersConf.getAttribute("default"); + Configuration[] rConf = readersConf.getChildren("reader"); + for (int i = 0; i < rConf.length; i++) + load_component(Sitemap.READER, + rConf[i].getAttribute("name", ""), + rConf[i].getAttribute("src"), + rConf[i], + rConf[i].getAttribute("mime-type", null)); + + Configuration transformersConf = confs.getChild("transformers"); + defaultTransformer = transformersConf.getAttribute("default"); + Configuration[] tConf = transformersConf.getChildren("transformer"); + for (int i = 0; i < tConf.length; i++) + load_component(Sitemap.TRANSFORMER, + tConf[i].getAttribute("name", ""), + tConf[i].getAttribute("src"), + tConf[i], + tConf[i].getAttribute("mime-type", null)); + + Configuration serializersConf = confs.getChild("serializers"); + defaultSerializer = serializersConf.getAttribute("default"); + Configuration[] sConf = serializersConf.getChildren("serializer"); + for (int i = 0; i < sConf.length; i++) + load_component(Sitemap.SERIALIZER, + sConf[i].getAttribute("name", ""), + sConf[i].getAttribute("src"), + sConf[i], + sConf[i].getAttribute("mime-type", null)); + + Configuration selectorsConf = confs.getChild("selectors"); + defaultSelector = selectorsConf.getAttribute("default"); + Configuration[] slConf = selectorsConf.getChildren("selector"); + for (int i = 0; i < slConf.length; i++) + load_component(Sitemap.SELECTOR, + slConf[i].getAttribute("name", ""), + slConf[i].getAttribute("src"), + slConf[i], + slConf[i].getAttribute("mime-type", null)); } - catch (ClassCastException ex) { - typeError("Environment", scm); + catch (Exception ex) { + ex.printStackTrace(); + throw new ConfigurationException(ex.toString()); } - return null; + + System.out.println("done"); } - /** - * Type cast function from a Scheme wrapper of an StreamPipeline - * instance. - * - * @param scm a Scheme wrapper of an StreamPipeline instance. - * @return an <code>Environment</code> value - */ - static public StreamPipeline streamPipeline(Value scm) + public void compose(ComponentManager manager) + throws ComponentException { - try { - return (StreamPipeline)(((J2S.JavaObject)scm).o); - } - catch (ClassCastException ex) { - typeError("StreamPipeline", scm); - } - return null; + super.compose(manager); } - /** - * Retrieve an entry from an association list. Uses eq? to compare - * the CAR of each entry. - * - * @param l the association list - * @param v the value to be searched for - * @return a <code>Pair</code> value representing the entry, or - * <tt>FALSE</tt> if no such entry is present. - */ - static public Value assq (Value l, Value v) + public void contextualize(Context context) + throws ContextException { - Pair list = pair(l); - while (list != EMPTYLIST) { - Pair entry = pair(list.car); - if (entry.car.eq(v)) - return entry; - list = pair(list.cdr); - } - return FALSE; + this.cocoonContext = context; } - /** - * Assumes the <tt>sparams</tt> is either an association list or the - * FALSE value. It returns either an empty Avalon - * <tt>Parameters</tt> instance, or a <tt>Parameters</tt> instance - * that contains the values extracted from the association list. - * - * @param sparams a <code>Value</code> value, either <tt>FALSE</tt> - * or an association list - * @return an Avalon <code>Parameters</code> instance - */ - public Parameters getParameters(Value sparams) + public StreamPipeline getStreamPipeline() + throws Exception { - Parameters params = emptyParam; + EventPipeline eventPipeline + = (EventPipeline)manager.lookup(EventPipeline.ROLE); + eventPipeline.recompose(manager); - if (!sparams.eq(FALSE)) { - params = new Parameters(); - Pair sparamValues = pair(pair(sparams).cdr); - while (sparamValues != EMPTYLIST) { - Pair entry = pair(sparamValues.car); - String name = string(entry.car); - String value = string(entry.cdr); - params.setParameter(name, value); - sparamValues = pair(sparamValues.cdr); - } - } + StreamPipeline pipeline + = (StreamPipeline)manager.lookup(StreamPipeline.ROLE); + pipeline.setEventPipeline(eventPipeline); + pipeline.recompose(manager); - return params; + return pipeline; } - /** - * <p>Creates a new pipeline instance, and a new Generator - * instance. Adds the Generator to the pipeline. - * - * <p>The type of the generator is specified in the <tt>sargs</tt> - * list, which is a Scheme association list. The parameters to be - * passed to the generators, if any, should be present in this - * association list as the value of the <it>params</it> entry. This - * value should be another association list, where the CAR of each - * entry is the name of the parameter, and the CDR of the entry is - * the actual value. - * - * <p>The recognized parameters are: - * - * <ul> - * - * <li><b>src</b> - (required) the source of the generator - * - * <li><b>type</b> - (optional) the type of generator. If not - * specified, the default generator specified using the - * <tt>default</tt> attribute of the <tt>generators</tt> XML - * element is used. - * - * <li><b>params</b> - (optional) the parameters to be passed to - * the generator. The CDR of this association entry should be - * another association entry, that contains the names and values of - * the parameters. - * - * </ul> - * - * <p><b>Example:</b> - * - * <pre> - * (match "generate/(.*)" (sitemap env file . args) - * (sitemap:generate sitemap env - * (list (cons 'src (concat "doc/samples" file ".xml"))))) - * </pre> - * - * @param scm the Scheme wrapper for the SitemapComponents instance - * @param senv the Scheme wrapper for the Environment instance - * @param sargs the Scheme arguments, as list - * @return a Scheme wrapper for the <tt>StreamPipeline</tt> instance - * @exception Exception if an error occurs - * - * @see SitemapComponents - */ - public Value generate(Value scm, Value senv, Value sargs) - throws Exception + public void releasePipeline(StreamPipeline pipeline) { - SitemapComponents sitemapComponents = sitemapComponents(scm); - StreamPipeline pipeline = sitemapComponents.getStreamPipeline(); EventPipeline eventPipeline = pipeline.getEventPipeline(); + manager.release((Component)eventPipeline); + manager.release((Component)pipeline); + } - // Obtain the 'src' attribute - Value ssrc = assq(sargs, Symbol.get("src")); - if (ssrc.eq(FALSE)) - throw new RuntimeException("No 'src' attribute specified for 'generate'!"); - String src = string(pair(ssrc).cdr); - - // Obtain the 'type' attribute - Value stype = assq(sargs, Symbol.get("type")); - String type; - if (!stype.eq(FALSE)) - type = string(pair(stype).cdr); - else - type = sitemapComponents.getDefaultGeneratorType(); - - // Obtain the parameters - Value sparams = assq(sargs, Symbol.get("params")); - Parameters params = getParameters(sparams); - -// System.out.println("generate type " + type + ", src " + src -// + " params " + params); - - eventPipeline.setGenerator(type, src, params); - - return new J2S.JavaObject(pipeline); + public String getDefaultGeneratorType() + { + return defaultGenerator; } - /** - * <p>Creates a new <tt>Reader</tt> and a new pipeline. Adds the - * reader to the pipeline and returns the pipeline newly created. - * - * <p>The parameters that describe the reader are specified in the - * <tt>sargs</tt> list, which is a Scheme association list. - * - * <p>The recognized parameters for a reader are: - * - * <ul> - * <li><b>src</b> - (required) the source for the reader - * - * <li><b>mime-type</b> - (optional) the MIME type associated with - * the source. If no MIME type is specified, text/html is assumed. - * - * <li><b>type</b> - (optional) The type of the reader to be - * used. If no type is specified, the default reader type is - * used. The default reader type is specified using the - * <tt>default</tt> attribute of the <tt>readers</tt> XML element. - * - * <li><b>params</b> - (optional) additional parameters to be - * specified when configuring the reader. The value of this entry - * should be a Scheme association list, which contains the - * additional parameters. - * - * </ul> - * - * @param scm the Scheme wrapper for the SitemapComponents instance - * @param senv the Scheme wrapper for the Environment instance - * @param sargs the Scheme arguments, as list - * @return a Scheme wrapper for the <tt>StreamPipeline</tt> instance - * @exception Exception if an error occurs - * - * @see SitemapComponents - */ - public Value read(Value scm, Value senv, Value sargs) - throws Exception + public String getDefaultTransformerType() { - SitemapComponents sitemapComponents = sitemapComponents(scm); - StreamPipeline pipeline = sitemapComponents.getStreamPipeline(); - EventPipeline eventPipeline = pipeline.getEventPipeline(); + return defaultTransformer; + } - // Obtain the 'src' attribute - Value ssrc = assq(sargs, Symbol.get("src")); - if (ssrc.eq(FALSE)) - throw new RuntimeException("No 'src' attribute specified for 'read'!"); - String src = string(pair(ssrc).cdr); - - // Obtain the 'mime-type' attribute - Value smimeType = assq(sargs, Symbol.get("mime-type")); - String mimeType = null; - if (!smimeType.eq(FALSE)) - mimeType = string(pair(smimeType).cdr); - - // Obtain the 'type' attribute - Value stype = assq(sargs, Symbol.get("type")); - String type; - if (!stype.eq(FALSE)) - type = string(pair(stype).cdr); - else - type = sitemapComponents.getDefaultReaderType(); - - // Obtain the parameters - Value sparams = assq(sargs, Symbol.get("params")); - Parameters params = getParameters(sparams); + public String getDefaultReaderType() + { + return defaultReader; + } - pipeline.setReader(type, src, params, mimeType); + public String getDefaultSerializerType() + { + return defaultSerializer; + } - return new J2S.JavaObject(pipeline); + public String getDefaultSelectorType() + { + return defaultSelector; } /** - * Creates a new <tt>transformer</tt> and adds it to the pipeline - * passed as argument. Returns the pipeline object passed as - * argument. - * - * <p>The recognized parameters for a transformer are: - * - * <ul> <li><b>src</b> - (required) the location of the XSLT - * stylesheet to be applied. - * - * <li><b>type</b> - (optional) The type of the transformer to be - * used, as defined in the <file>components.xconf</file>. If no - * type is specified, the default transformer is used. The default - * transformer type is specified using the <tt>default</tt> - * attribute of the <tt>transformers</tt> XML element. + * Translate the XML sitemap definition into a Scheme + * representation, and pass it to the Scheme interpreter for + * evaluation. This method is invoked via the {@link + * SchemeSitemapFunctions#parse(sisc.data.Value, sisc.data.Value)} + * method, from the Scheme layer (see <file>sitemap.scm</file>). * - * <li><b>params</b> - (optional) additional parameters to be - * specified when configuring the transformer. The value of this - * entry should be a Scheme association list, which contains the - * additional parameters. - * - * </ul> - * - * @param scm the Scheme wrapper for the SitemapComponents instance - * @param senv the Scheme wrapper for the Environment instance - * @param sargs the Scheme arguments, as list - * @return a Scheme wrapper for the <tt>StreamPipeline</tt> instance + * @param environment an <code>Environment</code> value * @exception Exception if an error occurs - * - * @see SitemapComponents */ - public Value transform(Value scm, Value senv, Value sargs, Value spipeline) + public void parseSitemap(Source sitemapSource) throws Exception { - SitemapComponents sitemapComponents = sitemapComponents(scm); - StreamPipeline pipeline = streamPipeline(spipeline); - EventPipeline eventPipeline = pipeline.getEventPipeline(); + System.out.print("Reading the sitemap... "); + System.out.flush(); - // Obtain the 'src' attribute - Value ssrc = assq(sargs, Symbol.get("src")); - if (ssrc.eq(FALSE)) - throw new RuntimeException("No 'src' attribute specified for 'transform'!"); - String src = string(pair(ssrc).cdr); - - // Obtain the 'type' attribute - Value stype = assq(sargs, Symbol.get("type")); - String type; - if (!stype.eq(FALSE)) - type = string(pair(stype).cdr); - else - type = sitemapComponents.getDefaultTransformerType(); - - // Obtain the parameters - Value sparams = assq(sargs, Symbol.get("params")); - Parameters params = getParameters(sparams); - -// System.out.println("transform type " + type + ", src " + src -// + " params " + params); - - eventPipeline.addTransformer(type, src, params); + Date start = new Date(); - return spipeline; - } + J2S.JavaObject sManager = new J2S.JavaObject(manager); + J2S.JavaObject ssource = new J2S.JavaObject(sitemapSource); + Value[] args = new Value[] { sManager, ssource }; + + SchemeInterpreter interpreters + = (SchemeInterpreter)manager.lookup(SchemeInterpreter.ROLE); + Interpreter interp = interpreters.getInterpreter(); + Symbol sitemapParseFunction = interpreters.getSitemapParseFunction(); - /** - * Creates a new <tt>serializer</tt> and adds it to the pipeline - * passed as argument. Returns the pipeline object passed as - * argument. - * - * <p>The recognized parameters for a transformer are: - * - * <li><b>type</b> - (optional) The type of the serializer to be - * used, as defined in the <file>components.xconf</file>. If no - * type is specified, the default serializer is used. The default - * serializer type is specified using the <tt>default</tt> - * attribute of the <tt>serializers</tt> XML element. - * - * <li><b>mime-type</b> - (optional) the MIME type associated with - * the generated result. If no MIME type is specified, the default - * used by the particular serializer is used. - * - * <li><b>params</b> - (optional) additional parameters to be - * specified when configuring the serializer. The value of this - * entry should be a Scheme association list, which contains the - * additional parameters. - * - * </ul> - * - * @param scm the Scheme wrapper for the SitemapComponents instance - * @param senv the Scheme wrapper for the Environment instance - * @param sargs the Scheme arguments, as list - * @return a Scheme wrapper for the <tt>StreamPipeline</tt> instance - * @exception Exception if an error occurs - * - * @see SitemapComponents - */ - public Value serialize(Value scm, Value senv, Value sargs, Value spipeline) - throws Exception - { - SitemapComponents sitemapComponents = sitemapComponents(scm); - StreamPipeline pipeline = streamPipeline(spipeline); + try { + interp.eval((Procedure)interp.ctx.toplevel_env.lookup(sitemapParseFunction), + args); + } + finally { + interpreters.releaseInterpreter(interp); + } + + Date end = new Date(); + Date duration = new Date(end.getTime() - start.getTime()); - // Obtain the 'type' attribute - Value stype = assq(sargs, Symbol.get("type")); - String type; - if (!stype.eq(FALSE)) - type = string(pair(stype).cdr); - else - type = sitemapComponents.getDefaultSerializerType(); - - // Obtain the 'mime-type' attribute - Value smimeType = assq(sargs, Symbol.get("mime-type")); - String mimeType = null; - if (!smimeType.eq(FALSE)) - mimeType = string(pair(smimeType).cdr); - - // Obtain the parameters - Value sparams = assq(sargs, Symbol.get("params")); - Parameters params = getParameters(sparams); - -// System.out.println("serialize type " + type -// + " params " + params + " mime-type " + mimeType); - - pipeline.setSerializer(type, null, params, mimeType); + System.out.println("done (" + ((double)duration.getTime())/1000 + " sec)"); - return spipeline; + // Set the creation date + dateCreated = (new Date()).getTime(); } /** - * Invokes the <tt>process</tt> method of the pipeline instance - * passed as argument. The pipeline instance passed between all the - * sitemap Scheme functions is always an instance of {@link - * org.apache.cocoon.components.pipeline.StreamPipeline}. If you - * need to obtain the {@link - * org.apache.cocoon.components.pipeline.EventPipeline} use the - * appropriate method from the {@link - * org.apache.cocoon.components.pipeline.StreamPipeline#getEventPipeline()} - * method to obtain it. - * - * <p>This function releases the pipeline, so it must be the last - * function you call on the pipeline. + * This method invokes the main Scheme function responsible with + * dispatching the request according to the sitemap definition. * - * @param scm the Scheme wrapper for the SitemapComponents instance - * @param senv the Scheme wrapper for the Environment instance - * @param sargs the Scheme arguments, as list - * @param spipeline the Scheme wrapper for pipeline object - * @return null + * @param environment an <code>Environment</code> value + * @return a <code>boolean</code> value * @exception Exception if an error occurs */ - public Value process(Value scm, Value senv, Value sargs, Value spipeline) + public boolean process(Environment environment) throws Exception { - SitemapComponents sitemapComponents = sitemapComponents(scm); - Environment env = environment(senv); - StreamPipeline pipeline = streamPipeline(spipeline); + String requestedURI = environment.getURI(); - pipeline.process(env); + J2S.JavaObject ssitemap = new J2S.JavaObject(this); + J2S.JavaObject senv = new J2S.JavaObject(environment); + ImmutableString servletPath = new ImmutableString(requestedURI); + Value[] args = new Value[] {servletPath, ssitemap, senv}; + + SchemeInterpreter interpreters + = (SchemeInterpreter)manager.lookup(SchemeInterpreter.ROLE); + Interpreter interp = interpreters.getInterpreter(); + Symbol mainFunction = interpreters.getMainFunction(); + Value result = sisc.Util.FALSE; - sitemapComponents.releasePipeline(pipeline); + try { + result + = interp.eval((Procedure)interp.ctx.toplevel_env.lookup(mainFunction), + args); + } + finally { + interpreters.releaseInterpreter(interp); + } - return null; + return !result.eq(sisc.Util.FALSE); + } + + public boolean process(Environment environment, + StreamPipeline pipeline, + EventPipeline eventPipeline) + throws Exception + { + System.out.println("process(environment, pipeline, eventPipeline)"); + return true; } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]