ovidiu 02/03/04 00:13:39 Modified: src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap SchemeSitemapFunctions.java Log: Added support for aggregation. New aggregate() and part() functions. Revision Changes Path 1.5 +122 -9 xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SchemeSitemapFunctions.java Index: SchemeSitemapFunctions.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/SchemeSitemapFunctions.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SchemeSitemapFunctions.java 22 Feb 2002 06:58:58 -0000 1.4 +++ SchemeSitemapFunctions.java 4 Mar 2002 08:13:39 -0000 1.5 @@ -57,6 +57,7 @@ import org.apache.cocoon.components.pipeline.StreamPipeline; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.Source; +import org.apache.cocoon.sitemap.ContentAggregator; import org.xml.sax.InputSource; import sisc.ContinuationException; import sisc.Interpreter; @@ -169,7 +170,9 @@ SERIALIZE = 4, PROCESS = 5, PARSE = 6, - LOAD_SCHEME = 7; + LOAD_SCHEME = 7, + AGGREGATE = 8, + PART = 9; /** * Creates a new <code>SchemeSitemapFunctions</code> instance. Defines @@ -178,6 +181,8 @@ public SchemeSitemapFunctions() { define("sitemap:generate", GENERATE); + define("sitemap:aggregate", AGGREGATE); + define("sitemap:part", PART); define("sitemap:read", READER); define("sitemap:transform", TRANSFORM); define("sitemap:serialize", SERIALIZE); @@ -215,6 +220,8 @@ switch (primid) { case GENERATE: return generate(r.vlr[0], r.vlr[1], r.vlr[2]); + case AGGREGATE: + return aggregate(r.vlr[0], r.vlr[1], r.vlr[2]); case READER: return read(r.vlr[0], r.vlr[1], r.vlr[2]); } @@ -228,6 +235,8 @@ 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]); + case PART: + return part(r.vlr[0], r.vlr[1], r.vlr[2], r.vlr[3]); } } } @@ -316,12 +325,6 @@ StreamPipeline pipeline = sitemap.getStreamPipeline(); 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 'generate'!"); - String src = string(pair(ssrc).cdr); - // Obtain the 'type' attribute Value stype = assq(sargs, Symbol.get("type")); String type; @@ -330,16 +333,126 @@ else type = sitemap.getDefaultGeneratorType(); + // We have a normal generator. + + // 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 parameters Value sparams = assq(sargs, Symbol.get("params")); Parameters params = getParameters(sparams); -// System.out.println("generate type " + type + ", src " + src -// + " params " + params); + // System.out.println("generate type " + type + ", src " + src + // + " params " + params); eventPipeline.setGenerator(type, src, params); + + return new J2S.JavaObject(pipeline); + } + + /** + * Create a new aggregate generator. Adds the aggregate generator to + * the pipeline and returns the pipeline. + * + * @param scm a <code>Value</code> value + * @param senv a <code>Value</code> value + * @param sargs a <code>Value</code> value + * @return a <code>Value</code> value + * @exception Exception if an error occurs + */ + public Value aggregate(Value scm, Value senv, Value sargs) + throws Exception + { + SchemeSitemap sitemap = schemeSitemap(scm); + StreamPipeline pipeline = sitemap.getStreamPipeline(); + EventPipeline eventPipeline = pipeline.getEventPipeline(); + + // We have an <aggregate> as the generator + eventPipeline.setGenerator ("!content-aggregator!", + null, Parameters.EMPTY_PARAMETERS); + // Get the element name of the top level element + String element = ""; + Value selement = assq(sargs, Symbol.get("element")); + if (!selement.eq(FALSE)) + element = string(pair(selement).cdr); + else + throw new RuntimeException("No 'element' attribute specified for 'aggregate'!"); + // Get the namespace of the top level element + String ns = ""; + Value sns = assq(sargs, Symbol.get("ns")); + if (!sns.eq(FALSE)) + ns = string(pair(sns).cdr); + + // Get the prefix of the top level element + String prefix = ""; + Value sprefix = assq(sargs, Symbol.get("prefix")); + if (!sprefix.eq(FALSE)) + prefix = string(pair(sprefix).cdr); + + ContentAggregator contentAggregator + = (ContentAggregator)eventPipeline.getGenerator(); + contentAggregator.setRootElement(element, ns, prefix); + return new J2S.JavaObject(pipeline); + } + + /** + * Sets up a new part in an aggregate generator. + * + * @param scm a <code>Value</code> value + * @param senv a <code>Value</code> value + * @param sargs a <code>Value</code> value + * @param spipeline a <code>Value</code> value + * @return a <code>Value</code> value + * @exception Exception if an error occurs + */ + public Value part(Value scm, Value senv, Value sargs, Value spipeline) + throws Exception + { + SchemeSitemap sitemap = schemeSitemap(scm); + StreamPipeline pipeline = sitemap.getStreamPipeline(); + EventPipeline eventPipeline = pipeline.getEventPipeline(); + + // Get the element for the top level element + String src = ""; + Value ssrc = assq(sargs, Symbol.get("src")); + if (!ssrc.eq(FALSE)) + src = string(pair(ssrc).cdr); + else + throw new RuntimeException("No 'src' attribute specified for <part>!"); + + // Get the element for the top level element + String element = ""; + Value selement = assq(sargs, Symbol.get("element")); + if (!selement.eq(FALSE)) + element = string(pair(selement).cdr); + + // Get the namespace for the top level element + String ns = ""; + Value sns = assq(sargs, Symbol.get("ns")); + if (!sns.eq(FALSE)) + ns = string(pair(sns).cdr); + + // Get the prefix for the top level element + String prefix = ""; + Value sprefix = assq(sargs, Symbol.get("prefix")); + if (!sprefix.eq(FALSE)) + prefix = string(pair(sprefix).cdr); + + // Whether to strip the root element of the document from src + String stripRoot = ""; + Value sstripRoot = assq(sargs, Symbol.get("strip-root")); + if (!sstripRoot.eq(FALSE)) + stripRoot = string(pair(sstripRoot).cdr); + + ContentAggregator contentAggregator + = (ContentAggregator)eventPipeline.getGenerator(); + contentAggregator.addPart(src, element, ns, stripRoot, prefix); + return spipeline; } /**
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]