You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2012/04/13 07:53:54 UTC
svn commit: r1325620 -
/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java
Author: jacopoc
Date: Fri Apr 13 05:53:54 2012
New Revision: 1325620
URL: http://svn.apache.org/viewvc?rev=1325620&view=rev
Log:
Modified Groovy util methods that prepares the binding to add the ScriptHelper object (to be consistent with the Groovy service engine and event handler and the "Script" JSR223 engine and handler): now Groovy scripts can execute the same exact Grrovy codes that can be executed when they are run thru JSR223.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java?rev=1325620&r1=1325619&r2=1325620&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java Fri Apr 13 05:53:54 2012
@@ -35,6 +35,8 @@ import org.codehaus.groovy.runtime.Invok
import org.ofbiz.base.location.FlexibleLocation;
import org.ofbiz.base.util.cache.UtilCache;
+import javax.script.ScriptContext;
+
/**
* Groovy Utilities.
*
@@ -92,11 +94,16 @@ public class GroovyUtil {
* @param context A <code>Map</code> containing initial variables
* @return A <code>Binding</code> instance
*/
- public static Binding getBinding(Map<String, ? extends Object> context) {
+ public static Binding getBinding(Map<String, Object> context) {
Map<String, Object> vars = FastMap.newInstance();
if (context != null) {
vars.putAll(context);
vars.put("context", context);
+ ScriptContext scriptContext = ScriptUtil.createScriptContext(context);
+ ScriptHelper scriptHelper = (ScriptHelper)scriptContext.getAttribute(ScriptUtil.SCRIPT_HELPER_KEY);
+ if (scriptHelper != null) {
+ vars.put(ScriptUtil.SCRIPT_HELPER_KEY, scriptHelper);
+ }
}
return new Binding(vars);
}