You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2006/03/11 11:57:04 UTC

svn commit: r385057 - /cocoon/trunk/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java

Author: bruno
Date: Sat Mar 11 02:57:03 2006
New Revision: 385057

URL: http://svn.apache.org/viewcvs?rev=385057&view=rev
Log:
Sharing template block with 2.1: step 5: Fix JavaScriptExpression so that it compiles with the Rhino in C2.1 (didn't test yet -- will do once finished)

Modified:
    cocoon/trunk/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java

Modified: cocoon/trunk/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java?rev=385057&r1=385056&r2=385057&view=diff
==============================================================================
--- cocoon/trunk/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java (original)
+++ cocoon/trunk/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java Sat Mar 11 02:57:03 2006
@@ -22,6 +22,7 @@
 
 import java.util.Iterator;
 import java.util.Map;
+import java.io.StringReader;
 
 import org.apache.cocoon.components.expression.AbstractExpression;
 import org.apache.cocoon.components.expression.ExpressionContext;
@@ -46,7 +47,15 @@
     private void compile() {
         Context ctx = Context.enter();
         try {
-            this.script = ctx.compileString(getExpression(), getExpression(), 1, null);
+            // Note: used compileReader instead of compileString to work with the older Rhino in C2.1
+            this.script = ctx.compileReader(TemplateObjectModelHelper.getScope(), new StringReader(getExpression()), "", 1, null);
+        } catch (Exception e) {
+            // Note: this catch block is only needed for the Rhino in C2.1 where the older
+            //       Rhino does not throw RuntimeExceptions
+            if (e instanceof RuntimeException)
+                throw (RuntimeException)e;
+            else
+                throw new RuntimeException(e);
         } finally {
             Context.exit();
         }
@@ -67,6 +76,13 @@
 
             Object result = this.script.exec(ctx, scope);
             return FlowHelper.unwrap(result);
+        } catch (Exception e) {
+            // Note: this catch block is only needed for the Rhino in C2.1 where the older
+            //       Rhino does not throw RuntimeExceptions
+            if (e instanceof RuntimeException)
+                throw (RuntimeException)e;
+            else
+                throw new RuntimeException(e);
         } finally {
             Context.exit();
         }