ovidiu 02/01/09 21:19:30 Modified: src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap SchemeSitemap.java Log: Added support for sitemap:transform and sitemap:serialize. Revision Changes Path 1.2 +183 -50 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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SchemeSitemap.java 8 Jan 2002 23:15:07 -0000 1.1 +++ SchemeSitemap.java 10 Jan 2002 05:19:30 -0000 1.2 @@ -20,11 +20,11 @@ * <ul> * * <li><b>sitemap:generate</b> - create a new {@link - * org.apache.cocoon.components.pipeline.EventPipeline}, and adds the + * 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 -> EventPipeline + * sitemap:generate: SitemapComponents Environment params -> StreamPipeline * </pre> * * @@ -42,8 +42,8 @@ * argument, and returns the pipeline. The prototype of the Scheme * function is: * <pre> - * sitemap:transform: SitemapComponents Environment params EventPipeline - * -> EventPipeline + * sitemap:transform: SitemapComponents Environment params StreamPipeline + * -> StreamPipeline * </pre> * * <li><b>sitemap:serialize</b> - creates a serializer object of the @@ -51,15 +51,15 @@ * argument, and returns the pipeline. The prototype of the Scheme * function is: * <pre> - * sitemap:serialize: SitemapComponents Environment params EventPipeline - * -> EventPipeline + * 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 EventPipeline + * sitemap:process: SitemapComponents Environment params StreamPipeline * -> void * </pre> * @@ -183,16 +183,34 @@ * Type cast function from a Scheme wrapper of an Environment * instance. * - * @param senv 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 senv) + static public Environment environment(Value scm) { try { - return (Environment)(((J2S.JavaObject)senv).o); + return (Environment)(((J2S.JavaObject)scm).o); } catch (ClassCastException ex) { - typeError("Environment", senv); + typeError("Environment", scm); + } + return null; + } + + /** + * 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) + { + try { + return (StreamPipeline)(((J2S.JavaObject)scm).o); + } + catch (ClassCastException ex) { + typeError("StreamPipeline", scm); } return null; } @@ -248,8 +266,8 @@ } /** - * <p>Creates a new <tt>EventPipeline</tt> instance, and a new - * Generator instance. Adds the Generator to the 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 @@ -288,7 +306,7 @@ * @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>EventPipeline</tt> instance + * @return a Scheme wrapper for the <tt>StreamPipeline</tt> instance * @exception Exception if an error occurs * * @see SitemapComponents @@ -297,7 +315,8 @@ throws Exception { SitemapComponents sitemapComponents = sitemapComponents(scm); - EventPipeline eventPipeline = sitemapComponents.getEventPipeline(); + StreamPipeline pipeline = sitemapComponents.getStreamPipeline(); + EventPipeline eventPipeline = pipeline.getEventPipeline(); // Obtain the 'src' attribute Value ssrc = assq(sargs, Symbol.get("src")); @@ -309,7 +328,7 @@ Value stype = assq(sargs, Symbol.get("type")); String type; if (!stype.eq(FALSE)) - type = string(pair(ssrc).cdr); + type = string(pair(stype).cdr); else type = sitemapComponents.getDefaultGeneratorType(); @@ -317,15 +336,17 @@ 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(eventPipeline); + return new J2S.JavaObject(pipeline); } /** - * <p>Creates a new <tt>Reader</tt> and a new - * <tt>StreamPipeline</tt>. Adds the reader to the pipeline and - * returns the pipeline newly created. + * <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. @@ -338,10 +359,10 @@ * <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) 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>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 @@ -362,10 +383,8 @@ throws Exception { SitemapComponents sitemapComponents = sitemapComponents(scm); - StreamPipeline streamPipeline = sitemapComponents.getStreamPipeline(); - EventPipeline eventPipeline = sitemapComponents.getEventPipeline(); - - streamPipeline.setEventPipeline(eventPipeline); + StreamPipeline pipeline = sitemapComponents.getStreamPipeline(); + EventPipeline eventPipeline = pipeline.getEventPipeline(); // Obtain the 'src' attribute Value ssrc = assq(sargs, Symbol.get("src")); @@ -375,17 +394,15 @@ // Obtain the 'mime-type' attribute Value smimeType = assq(sargs, Symbol.get("mime-type")); - String mimeType; - if (smimeType.eq(FALSE)) - mimeType = "text/html"; - else + 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(ssrc).cdr); + type = string(pair(stype).cdr); else type = sitemapComponents.getDefaultReaderType(); @@ -393,26 +410,149 @@ Value sparams = assq(sargs, Symbol.get("params")); Parameters params = getParameters(sparams); - streamPipeline.setReader(type, src, params, mimeType); + pipeline.setReader(type, src, params, mimeType); - return new J2S.JavaObject(streamPipeline); + return new J2S.JavaObject(pipeline); } + /** + * 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. + * + * <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 + * @exception Exception if an error occurs + * + * @see SitemapComponents + */ public Value transform(Value scm, Value senv, Value sargs, Value spipeline) + throws Exception { - return null; + SitemapComponents sitemapComponents = sitemapComponents(scm); + StreamPipeline pipeline = streamPipeline(spipeline); + EventPipeline eventPipeline = pipeline.getEventPipeline(); + + // 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); + + return spipeline; } + /** + * 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 { - return null; + SitemapComponents sitemapComponents = sitemapComponents(scm); + StreamPipeline pipeline = streamPipeline(spipeline); + + // 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); + + return spipeline; } /** * Invokes the <tt>process</tt> method of the pipeline instance - * passed as argument. The pipeline could be either an {@link - * org.apache.cocoon.components.pipeline.EventPipeline} or a {@link - * org.apache.cocoon.components.pipeline.StreamPipeline}. + * 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. @@ -429,18 +569,11 @@ { SitemapComponents sitemapComponents = sitemapComponents(scm); Environment env = environment(senv); - Object pipeline = ((J2S.JavaObject)spipeline).o; + StreamPipeline pipeline = streamPipeline(spipeline); - if (pipeline instanceof EventPipeline) - ((EventPipeline)pipeline).process(env); - else { - ((StreamPipeline)pipeline).process(env); - EventPipeline eventPipeline - = ((StreamPipeline)pipeline).getEventPipeline(); - sitemapComponents.releasePipeline((Component)eventPipeline); - } + pipeline.process(env); - sitemapComponents.releasePipeline((Component)pipeline); + sitemapComponents.releasePipeline(pipeline); return null; }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]