You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by co...@apache.org on 2003/02/23 20:26:57 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript JSCocoon.java JavaScriptInterpreter.java

coliver     2003/02/23 11:26:57

  Modified:    src/java/org/apache/cocoon/components/flow/javascript
                        JSCocoon.java JavaScriptInterpreter.java
  Log:
  Updated to support using the Cocoon flow layer with XMLForm
  
  Revision  Changes    Path
  1.16      +25 -9     xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/JSCocoon.java
  
  Index: JSCocoon.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/JSCocoon.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- JSCocoon.java	20 Feb 2003 18:22:43 -0000	1.15
  +++ JSCocoon.java	23 Feb 2003 19:26:57 -0000	1.16
  @@ -146,23 +146,39 @@
   
     public Request jsGet_request()
     {
  -    Map objectModel = environment.getObjectModel();
  -    return ObjectModelHelper.getRequest(objectModel);
  +      if (environment == null) {
  +	// context has been invalidated
  +	return null;
  +      }
  +      Map objectModel = environment.getObjectModel();
  +      return ObjectModelHelper.getRequest(objectModel);
     }
   
     public Response jsGet_response()
     {
  +      if (environment == null) {
  +	// context has been invalidated
  +	return null;
  +      }
       Map objectModel = environment.getObjectModel();
       return ObjectModelHelper.getResponse(objectModel);
     }
   
     public Session jsGet_session()
     {
  +      if (environment == null) {
  +	// context has been invalidated
  +	return null;
  +      }
       return jsGet_request().getSession();
     }
   
     public Context jsGet_context()
     {
  +      if (environment == null) {
  +	// context has been invalidated
  +	return null;
  +      }
       Map objectModel = environment.getObjectModel();
       return ObjectModelHelper.getContext(objectModel);
     }
  @@ -276,13 +292,13 @@
   
     public static Object jsobjectToObject(Object obj) 
     {
  -      // unwrap Scriptable wrappers of real Java objects
  -      if (obj instanceof Wrapper) {
  -	  obj = ((Wrapper) obj).unwrap();
  -      } else if (obj == Undefined.instance) {
  -	  obj = null;
  -      }
  -      return obj;
  +     // unwrap Scriptable wrappers of real Java objects
  +    if (obj instanceof Wrapper) {
  +      obj = ((Wrapper) obj).unwrap();
  +    } else if (obj == Undefined.instance) {
  +      obj = null;
  +    }
  +    return obj;
     }
   
       public Scriptable jsFunction_callAction(String type,
  
  
  
  1.18      +32 -9     xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java
  
  Index: JavaScriptInterpreter.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- JavaScriptInterpreter.java	20 Feb 2003 18:22:43 -0000	1.17
  +++ JavaScriptInterpreter.java	23 Feb 2003 19:26:57 -0000	1.18
  @@ -70,6 +70,7 @@
   import org.mozilla.javascript.Context;
   import org.mozilla.javascript.Function;
   import org.mozilla.javascript.NativeArray;
  +import org.mozilla.javascript.Wrapper;
   import org.mozilla.javascript.PropertyException;
   import org.mozilla.javascript.Script;
   import org.mozilla.javascript.ScriptRuntime;
  @@ -81,7 +82,7 @@
   /**
    * Interface with the JavaScript interpreter.
    *
  - * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
  + * @author <a href="mailto:ovidiu@apache.org">Ovidiu Predescu</a>
    * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
    * @since March 25, 2002
    */
  @@ -345,9 +346,12 @@
      */
     protected void exitContext(Scriptable thrScope)
     {
  -    JSCocoon cocoon = (JSCocoon)thrScope.get("cocoon", thrScope);
  -    cocoon.invalidateContext();
  -    Context.exit();
  +      // thrScope may be null if an exception occurred compiling a script
  +      if (thrScope != null) { 
  +	  JSCocoon cocoon = (JSCocoon)thrScope.get("cocoon", thrScope);
  +	  cocoon.invalidateContext();
  +      }
  +      Context.exit();
     }
   
     public void readScripts(Environment environment, List sources)
  @@ -373,7 +377,20 @@
             compiledScripts.add(compiledScript);
         }
       }
  -    catch (Exception ex) {
  +    catch (JavaScriptException ex) {
  +      Object value = ex.getValue();
  +      while (value instanceof Wrapper) {
  +	  value = ((Wrapper)value).unwrap();
  +      }
  +      if (value instanceof Exception) {
  +	  Exception e = (Exception)value;
  +	  e.printStackTrace();
  +	  throw e;
  +      } else if (value instanceof Error) {
  +	  throw (Error)value;
  +      }
  +      throw ex;
  +    } catch (Exception ex) {
         ex.printStackTrace();
         throw ex;
       }
  @@ -512,16 +529,22 @@
         ((Function) callFunction).call(context, thrScope, thrScope, callFunArgs);
       }
       catch (JavaScriptException ex) {
  -      ex.printStackTrace();
         Object value = ex.getValue();
  +      while (value instanceof Wrapper) {
  +	  value = ((Wrapper)value).unwrap();
  +      }
         if (value instanceof Exception) {
  -	  throw (Exception)value;
  +	  Exception e = (Exception)value;
  +	  e.printStackTrace();
  +	  throw e;
  +      } else if (value instanceof Error) {
  +	  throw (Error)value;
         }
         throw ex;
       }
       catch (Exception ex) {
  -      ex.printStackTrace();
  -      throw ex;
  +	ex.printStackTrace();
  +	throw ex;
       }
       finally {
         exitContext(thrScope);