cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r416391 - in /cocoon/trunk: blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/ blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/environment/ core...
Date Thu, 22 Jun 2006 15:13:56 GMT
Author: cziegeler
Date: Thu Jun 22 08:13:55 2006
New Revision: 416391

URL: http://svn.apache.org/viewvc?rev=416391&view=rev
Log:
Move javascript related stuff out of the TemplateObjectModelHelper

Modified:
    cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java
    cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java

Modified: cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java?rev=416391&r1=416390&r2=416391&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java
(original)
+++ cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java
Thu Jun 22 08:13:55 2006
@@ -26,6 +26,7 @@
 import org.apache.cocoon.components.expression.jexl.JSIntrospector;
 import org.apache.cocoon.components.flow.FlowHelper;
 import org.apache.cocoon.environment.TemplateObjectModelHelper;
+import org.apache.cocoon.template.environment.FlowObjectModelHelper;
 import org.apache.commons.jexl.util.introspection.Info;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.Script;
@@ -45,7 +46,7 @@
         Context ctx = Context.enter();
         try {
             // 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);
+            this.script = ctx.compileReader(FlowObjectModelHelper.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
@@ -62,7 +63,7 @@
     public Object evaluate(ExpressionContext context) throws ExpressionException {
         Context ctx = Context.enter();
         try {
-            Scriptable scope = ctx.newObject(TemplateObjectModelHelper.getScope());
+            Scriptable scope = ctx.newObject(FlowObjectModelHelper.getScope());
             // Populate the scope
             Iterator iter = context.entrySet().iterator();
             while (iter.hasNext()) {

Modified: cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java?rev=416391&r1=416390&r2=416391&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
(original)
+++ cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
Thu Jun 22 08:13:55 2006
@@ -20,7 +20,12 @@
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.components.flow.FlowHelper;
+import org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptFlowHelper;
 import org.apache.cocoon.environment.TemplateObjectModelHelper;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.NativeJavaPackage;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
 
 
 /**
@@ -30,17 +35,69 @@
  */
 public class FlowObjectModelHelper {
 
+    private static Scriptable rootScope;
+
+    /** Avoid instantiation. */
+    private FlowObjectModelHelper() {}
+
+    public static Scriptable getScope() {
+        Context ctx = Context.enter();
+        try {
+            // Create it if never used up to now
+            if (rootScope == null) {
+                rootScope = ctx.initStandardObjects(null);
+            }
+            Scriptable scope = ctx.newObject(rootScope);
+            scope.setPrototype(rootScope);
+            scope.setParentScope(null);
+            return scope;
+        } finally {
+            Context.exit();
+        }
+    }
+    
     /**
      * Create an expression context that contains the object model
      */
     public static ExpressionContext getFOMExpressionContext(final Map objectModel, 
                                                             final Parameters parameters)
{
         ExpressionContext context = new ExpressionContext();
-        Map expressionContext = (Map)TemplateObjectModelHelper.getTemplateObjectModel(objectModel,
parameters);
-        expressionContext = (Map) TemplateObjectModelHelper.addJavaPackages( expressionContext
);
+        Map expressionContext = TemplateObjectModelHelper.getTemplateObjectModel(objectModel,
parameters);
+        FlowObjectModelHelper.addJavaPackages( expressionContext );
         context.setVars( expressionContext );
         context.setContextBean(FlowHelper.getContextObject(objectModel));
 
         return context;
     }
+
+    /**
+     * Add java packages to object model. Allows to construct java objects.
+     * @param objectModel usually the result of invoking getTemplateObjectModel
+     */
+    public static void addJavaPackages( Map objectModel ) {
+        Object javaPkg = FOM_JavaScriptFlowHelper.getJavaPackage(objectModel);
+        Object pkgs = FOM_JavaScriptFlowHelper.getPackages(objectModel);
+        
+        // packages might have already been set up if flowscript is being used
+        if ( javaPkg != null && pkgs != null ) {
+            objectModel.put( "Packages", javaPkg );
+            objectModel.put( "java", pkgs );
+        } else { 
+            Context.enter();
+            try {
+                final String JAVA_PACKAGE = "JavaPackage";
+                ClassLoader cl = Thread.currentThread().getContextClassLoader();
+                // FIXME - NativeJavaPackage is an internal class which we should not use
+                Scriptable newPackages = new NativeJavaPackage( "", cl );
+                newPackages.setParentScope( getScope() );
+                newPackages.setPrototype( ScriptableObject.getClassPrototype(   getScope(),
+                                                                                JAVA_PACKAGE
) );
+                objectModel.put( "Packages", newPackages );
+                objectModel.put( "java", ScriptableObject.getProperty( getScope(), "java"
) );
+            } finally {
+                Context.exit();
+            }
+        }
+    }
+
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java?rev=416391&r1=416390&r2=416391&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
Thu Jun 22 08:13:55 2006
@@ -17,23 +17,14 @@
 
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Method;
-import java.util.Collection;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 
-import org.apache.avalon.framework.parameters.ParameterException;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.components.flow.FlowHelper;
-import org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptFlowHelper;
 import org.apache.commons.jxpath.DynamicPropertyHandler;
 import org.apache.commons.jxpath.JXPathBeanInfo;
 import org.apache.commons.jxpath.JXPathIntrospector;
-import org.mozilla.javascript.Context;
-import org.mozilla.javascript.NativeJavaPackage;
-import org.mozilla.javascript.Scriptable;
-import org.mozilla.javascript.ScriptableObject;
 
 
 /**
@@ -45,27 +36,10 @@
  * @version $Id$
  */
 public class TemplateObjectModelHelper {
-    private static Scriptable rootScope = null;
     
     /** Avoid instantiation */
     private TemplateObjectModelHelper() {}
 
-    public static Scriptable getScope() {
-        Context ctx = Context.enter();
-        try {
-            // Create it if never used up to now
-            if (rootScope == null) {
-                rootScope = ctx.initStandardObjects(null);
-            }
-            Scriptable scope = ctx.newObject(rootScope);
-            scope.setPrototype(rootScope);
-            scope.setParentScope(null);
-            return scope;
-        } finally {
-            Context.exit();
-        }
-    }
-    
     public static void fillContext(Object contextObject, Map map) {
         // Hack: I use jxpath to populate the context object's properties
         // in the jexl context
@@ -114,34 +88,27 @@
      *         + continuation    The Continuation (if available)
      *         + parameters      The parameters (if provided)
      */
-    public static Object getTemplateObjectModel(final Map objectModel, 
-                                                final Parameters parameters) {
+    public static Map getTemplateObjectModel(final Map objectModel, 
+                                             final Parameters parameters) {
 
         // first create the "cocoon object":
         final Map cocoon = new HashMap();
 
-        // Needed for the FOM wrappers
-        Context.enter();
-        try {
-            // cocoon.request
-            final Request request = ObjectModelHelper.getRequest( objectModel );
-            cocoon.put("request", request);
-            
-            // cocoon.session
-            final Session session = request.getSession(false);
-            if (session != null) {
-                cocoon.put("session", session);
-            }
-        
-            // cocoon.context
-            final org.apache.cocoon.environment.Context context =
-                ObjectModelHelper.getContext( objectModel );
-            cocoon.put("context", context);
-
-        } finally {
-            Context.exit();
+        // cocoon.request
+        final Request request = ObjectModelHelper.getRequest( objectModel );
+        cocoon.put("request", request);
+
+        // cocoon.session
+        final Session session = request.getSession(false);
+        if (session != null) {
+            cocoon.put("session", session);
         }
-            
+
+        // cocoon.context
+        final org.apache.cocoon.environment.Context context =
+            ObjectModelHelper.getContext( objectModel );
+        cocoon.put("context", context);
+
         // cocoon.continuation
         final Object cont = FlowHelper.getWebContinuation(objectModel);
         if ( cont != null ) {
@@ -165,36 +132,5 @@
         }
         
         return map;
-    }
-
-    /**
-     * Add java packages to object model. Allows to construct java objects.
-     * @param objectModel usually the result of invoking getTemplateObjectModel
-     */
-    public static Object addJavaPackages( Map objectModel ) {
-        Object javaPkg = FOM_JavaScriptFlowHelper.getJavaPackage(objectModel);
-        Object pkgs = FOM_JavaScriptFlowHelper.getPackages(objectModel);
-        
-        // packages might have already been set up if flowscript is being used
-        if ( javaPkg != null && pkgs != null ) {
-            objectModel.put( "Packages", javaPkg );
-            objectModel.put( "java", pkgs );
-        } else { 
-            Context.enter();
-            try {
-                final String JAVA_PACKAGE = "JavaPackage";
-                ClassLoader cl = Thread.currentThread().getContextClassLoader();
-                // FIXME - NativeJavaPackage is an internal class which we should not use
-                Scriptable newPackages = new NativeJavaPackage( "", cl );
-                newPackages.setParentScope( getScope() );
-                newPackages.setPrototype( ScriptableObject.getClassPrototype(   getScope(),
-                                                                                JAVA_PACKAGE
) );
-                objectModel.put( "Packages", newPackages );
-                objectModel.put( "java", ScriptableObject.getProperty( getScope(), "java"
) );
-            } finally {
-                Context.exit();
-            }
-        }
-        return objectModel;
     }
 }



Mime
View raw message