ovidiu 02/02/12 17:47:12 Added: src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap CocoonModule.java Log: Added. Common class for all the Schecoon SISC modules which implement native Scheme functions. Revision Changes Path 1.1 xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/scheme/sitemap/CocoonModule.java Index: CocoonModule.java =================================================================== package org.apache.cocoon.scheme.sitemap; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.components.pipeline.StreamPipeline; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.Source; import sisc.ModuleAdapter; import sisc.data.Pair; import sisc.data.Value; import sisc.modules.J2S; public abstract class CocoonModule extends ModuleAdapter { static protected Parameters emptyParam = new Parameters(); /** * Type cast function from a Scheme wrapper of a SchemeSitemap. * * @param scm a Scheme wrapper instance of a SchemeSitemap. * @return a <code>SchemeSitemap</code> value */ static public SchemeSitemap schemeSitemap(Value scm) { 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; } /** * 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; } /** * 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 */ static 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; } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]