cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ovi...@apache.org
Subject cvs commit: xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/javascript JSCocoon.java
Date Tue, 19 Mar 2002 09:38:21 GMT
ovidiu      02/03/19 01:38:21

  Modified:    src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/javascript
                        JSCocoon.java
  Log:
  Save the InvokeContext instance in addition to Environment.
  
  Automatically convert JavaScript objects to Java Map instances.
  
  Revision  Changes    Path
  1.3       +43 -2     xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/javascript/JSCocoon.java
  
  Index: JSCocoon.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/javascript/JSCocoon.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JSCocoon.java	18 Mar 2002 06:43:46 -0000	1.2
  +++ JSCocoon.java	19 Mar 2002 09:38:21 -0000	1.3
  @@ -1,13 +1,18 @@
   package org.apache.cocoon.components.flow.javascript;
   
  +import java.util.HashMap;
   import java.util.Map;
   import org.apache.cocoon.components.flow.AbstractInterpreter;
  +import org.apache.cocoon.components.treeprocessor.InvokeContext;
   import org.apache.cocoon.environment.Context;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.environment.Response;
  +import org.mozilla.javascript.ScriptRuntime;
  +import org.mozilla.javascript.Scriptable;
   import org.mozilla.javascript.ScriptableObject;
  +import org.mozilla.javascript.Wrapper;
   
   /**
    * JavaScript interface to various Cocoon abstractions.
  @@ -19,6 +24,7 @@
   {
     protected AbstractInterpreter interp;
     protected Environment environment;
  +  protected InvokeContext context;
   
     public JSCocoon() {}
   
  @@ -32,9 +38,10 @@
       this.interp = interp;
     }
   
  -  public void setEnvironment(Environment environment)
  +  public void setContext(Environment environment, InvokeContext ctx)
     {
       this.environment = environment;
  +    this.context = ctx;
     }
   
     public AbstractInterpreter jsGet_interpreter()
  @@ -47,6 +54,11 @@
       return environment;
     }
   
  +  public InvokeContext jsGet_invokeContext()
  +  {
  +    return context;
  +  }
  +
     public Request jsGet_request()
     {
       Map objectModel = environment.getObjectModel();
  @@ -92,6 +104,35 @@
                                            Object bizData)
       throws Exception
     {
  -    interp.processPipeline(name, (Map)pipelineArgs, bizData);
  +    if (pipelineArgs instanceof Wrapper)
  +      pipelineArgs = ((Wrapper)pipelineArgs).unwrap();
  +    else if (pipelineArgs instanceof Scriptable)
  +      pipelineArgs = jsobjectToMap((Scriptable)pipelineArgs);
  +
  +    if (bizData instanceof Wrapper)
  +      bizData = ((Wrapper)bizData).unwrap();
  +    else if (bizData instanceof Scriptable)
  +      bizData = jsobjectToMap((Scriptable)bizData);
  +
  +    environment.setAttribute("bean-dict", bizData);
  +    try {
  +      interp.processPipeline(name, (Map)pipelineArgs, bizData,
  +                             environment, context);
  +    }
  +    finally {
  +      environment.removeAttribute("bean-dict");
  +    }
  +  }
  +
  +  public static Map jsobjectToMap(Scriptable jsobject)
  +  {
  +    HashMap hash = new HashMap();
  +    Object[] ids = jsobject.getIds();
  +    for (int i = 0; i < ids.length; i++) {
  +      String key = ScriptRuntime.toString(ids[i]);
  +      Object value = ScriptRuntime.toPrimitive(jsobject.get(key, jsobject));
  +      hash.put(key, value);
  +    }
  +    return hash;
     }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message