ovidiu 02/02/12 17:55:34 Modified: src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap SchemeSitemapFunctions.java Log: (read-resource): New native Scheme function. Moved all the cast functions in CocoonModule. Revision Changes Path 1.3 +27 -141 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SchemeSitemapFunctions.java 1 Feb 2002 01:41:54 -0000 1.2 +++ SchemeSitemapFunctions.java 13 Feb 2002 01:55:34 -0000 1.3 @@ -11,6 +11,7 @@ import sisc.ContinuationException; import sisc.Interpreter; import sisc.ModuleAdapter; +import sisc.data.ImmutableString; import sisc.data.Pair; import sisc.data.Symbol; import sisc.data.Value; @@ -99,7 +100,7 @@ * @see org.apache.cocoon.components.pipeline.StreamPipeline * @see org.apache.cocoon.reading.Reader */ -public class SchemeSitemapFunctions extends ModuleAdapter +public class SchemeSitemapFunctions extends CocoonModule { public String getModuleName() { @@ -117,9 +118,8 @@ TRANSFORM = 3, SERIALIZE = 4, PROCESS = 5, - PARSE = 6; - - protected Parameters emptyParam = new Parameters(); + PARSE = 6, + LOAD_SCHEME = 7; /** * Creates a new <code>SchemeSitemapFunctions</code> instance. Defines @@ -133,6 +133,7 @@ define("sitemap:serialize", SERIALIZE); define("sitemap:process", PROCESS); define("sitemap:parse", PARSE); + define("sitemap:read-resource", LOAD_SCHEME); } /** @@ -143,18 +144,20 @@ * @param primid an <code>int</code> value * @param r an <code>Interpreter</code> value * @return a <code>Value</code> value + * @exception ContinuationException if an error occurs */ public Value eval(int primid, Interpreter r) throws ContinuationException { try { switch (r.vlr.length) { - // Two argument functions case 2: switch (primid) { case PARSE: return parse(r.vlr[0], r.vlr[1]); + case LOAD_SCHEME: + return readResource(r.vlr[0], r.vlr[1]); } // Three argument functions @@ -187,146 +190,29 @@ } /** - * Type cast function from a Scheme wrapper of a SchemeSitemap. + * Read a resource from the current Web application and return its + * content as a Scheme <code>ImmutableString</code>. * - * @param scm a Scheme wrapper instance of a SchemeSitemap. - * @return a <code>SchemeSitemap</code> value - */ - static public SchemeSitemap schemeSitemap(Value scm) + * @param sManager a <code>Value</code> wrapper for an Avalon + * <code>ComponentManager</code> + * @param ssource a Scheme <code>String</code> string representing + * the name of the resource to read. + * @return a Scheme <code>ImmutableString</code> value, containing + * the Scheme representation of the XML document read from + * <code>ssource</code> + * @exception Exception if an error occurs during reading of the + * resource + */ + public Value readResource(Value scm, Value ssource) + throws Exception { - try { - return (SchemeSitemap)(((J2S.JavaObject)scm).o); - } - catch (ClassCastException ex) { - typeError("SchemeSitemap", scm); - } - return null; - } - - /** - * 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); - } - catch (ClassCastException ex) { - typeError("Environment", scm); - } - return null; - } + SchemeSitemap sitemap = schemeSitemap(scm); + String source = string(ssource); - /** - * Type cast function from a Scheme wrapper of an StreamPipeline - * instance. - * - * @param scm a Scheme wrapper of an StreamPipeline instance. - * @return an <code>StreamPipeline</code> value - */ - static public StreamPipeline streamPipeline(Value scm) - { - try { - return (StreamPipeline)(((J2S.JavaObject)scm).o); - } - catch (ClassCastException ex) { - typeError("StreamPipeline", scm); - } - return null; + String content = sitemap.readResource(source); + return new ImmutableString(content); } - - /** - * Type cast function from a Scheme wrapper of - * <code>ComponentManager</code> instance. - * - * @param scm a Scheme wrapper of a Cocoon - * <code>ComponentManager</code> instance. - * @return an <code>ComponentManager</code> value - */ - static public ComponentManager componentManager(Value scm) - { - try { - return (ComponentManager)(((J2S.JavaObject)scm).o); - } - catch (ClassCastException ex) { - typeError("ComponentManager", scm); - } - return null; - } - - /** - * Type cast function from a Scheme wrapper of a Cocoon - * <code>Source</code> instance. - * - * @param scm a Scheme wrapper of a Cocoon <code>Source</code> - * instance. - * @return an <code>Source</code> value - */ - static public Source source(Value scm) - { - try { - return (Source)(((J2S.JavaObject)scm).o); - } - catch (ClassCastException ex) { - typeError("Source", scm); - } - return null; - } - - /** - * 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) - { - 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; - } - - /** - * 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) - { - Parameters params = emptyParam; - - 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); - } - } - - return params; - } - + /** * <p>Creates a new pipeline instance, and a new Generator * instance. Adds the Generator to the pipeline.
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]