Author: erwan
Date: Sat Feb 11 07:48:54 2012 New Revision: 1243012 URL: http://svn.apache.org/viewvc?rev=1243012&view=rev Log: Moving from bshInterpreter to GroovyShell Modified: ofbiz/branches/20120209RemoveBsh/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java ofbiz/branches/20120209RemoveBsh/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelForm.java ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java Modified: ofbiz/branches/20120209RemoveBsh/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120209RemoveBsh/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java?rev=1243012&r1=1243011&r2=1243012&view=diff ============================================================================== --- ofbiz/branches/20120209RemoveBsh/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java (original) +++ ofbiz/branches/20120209RemoveBsh/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java Sat Feb 11 07:48:54 2012 @@ -266,10 +266,7 @@ public abstract class FlexibleStringExpa // append everything from the current index to the start of the expression strElems.add(new ConstOffsetElem(chars, currentInd, (escapedExpression ? start -1 : start) - currentInd)); } - if (expression.indexOf("bsh:", start + 2) == start + 2 && !escapedExpression) { - // checks to see if this starts with a "bsh:", if so treat the rest of the expression as a bsh scriptlet - strElems.add(new BshElem(chars, start, Math.min(end + 1, start + length) - start, start + 6, end - start - 6)); - } else if (expression.indexOf("groovy:", start + 2) == start + 2 && !escapedExpression) { + if (expression.indexOf("groovy:", start + 2) == start + 2 && !escapedExpression) { // checks to see if this starts with a "groovy:", if so treat the rest of the expression as a groovy scriptlet strElems.add(new GroovyElem(chars, start, Math.min(end + 1, start + length) - start, start + 9, end - start - 9)); } else { @@ -488,35 +485,6 @@ public abstract class FlexibleStringExpa } } - /** An object that represents a <code>${bsh:}</code> expression. */ - protected static class BshElem extends ArrayOffsetString { - private final int parseStart; - private final int parseLength; - - protected BshElem(char[] chars, int offset, int length, int parseStart, int parseLength) { - super(chars, offset, length); - this.parseStart = parseStart; - this.parseLength = parseLength; - } - - @Override - protected Object get(Map<String, ? extends Object> context, TimeZone timeZone, Locale locale) { - try { - Object obj = BshUtil.eval(new String(this.chars, this.parseStart, this.parseLength), UtilMisc.makeMapWritable(context)); - if (obj != null) { - return obj; - } else { - if (Debug.verboseOn()) { - Debug.logVerbose("BSH scriptlet evaluated to null [" + this + "], got no return so inserting nothing.", module); - } - } - } catch (EvalError e) { - Debug.logWarning(e, "Error evaluating BSH scriptlet [" + this + "], inserting nothing; error was: " + e, module); - } - return null; - } - } - /** An object that represents a <code>String</code> constant portion of an expression. */ protected static class ConstSimpleElem extends FlexibleStringExpander { protected ConstSimpleElem(char[] chars) { Modified: ofbiz/branches/20120209RemoveBsh/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120209RemoveBsh/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java?rev=1243012&r1=1243011&r2=1243012&view=diff ============================================================================== --- ofbiz/branches/20120209RemoveBsh/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java (original) +++ ofbiz/branches/20120209RemoveBsh/framework/minilang/src/org/ofbiz/minilang/method/callops/CallScript.java Sat Feb 11 07:48:54 2012 @@ -73,13 +73,7 @@ public class CallScript extends MethodOp } Map<String, Object> context = methodContext.getEnvMap(); - if (location.endsWith(".bsh")) { - try { - BshUtil.runBshAtLocation(location, context); - } catch (GeneralException e) { - messages.add("Error running BSH script at location [" + location + "]: " + e.getMessage()); - } - } else if (location.endsWith(".groovy")) { + if (location.endsWith(".groovy")) { try { groovy.lang.Script script = InvokerHelper.createScript(GroovyUtil.getScriptClassFromLocation(location), GroovyUtil.getBinding(context)); if (UtilValidate.isEmpty(method)) { Modified: ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java?rev=1243012&r1=1243011&r2=1243012&view=diff ============================================================================== --- ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java (original) +++ ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java Sat Feb 11 07:48:54 2012 @@ -403,13 +403,7 @@ public abstract class ModelWidgetAction @Override public void runAction(Map<String, Object> context) throws GeneralException { - if (location.endsWith(".bsh")) { - try { - BshUtil.runBshAtLocation(location, context); - } catch (GeneralException e) { - throw new GeneralException("Error running BSH script at location [" + location + "]", e); - } - } else if (location.endsWith(".groovy")) { + if (location.endsWith(".groovy")) { try { groovy.lang.Script script = InvokerHelper.createScript(GroovyUtil.getScriptClassFromLocation(location), GroovyUtil.getBinding(context)); if (UtilValidate.isEmpty(method)) { Modified: ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=1243012&r1=1243011&r2=1243012&view=diff ============================================================================== --- ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original) +++ ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Sat Feb 11 07:48:54 2012 @@ -30,19 +30,13 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import groovy.lang.GroovyShell; import javolution.util.FastList; import javolution.util.FastMap; import javolution.util.FastSet; -import org.ofbiz.base.util.BshUtil; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; +import org.codehaus.groovy.control.CompilationFailedException; +import org.ofbiz.base.util.*; import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.base.util.collections.MapStack; import org.ofbiz.base.util.string.FlexibleStringExpander; @@ -60,9 +54,6 @@ import org.ofbiz.widget.ModelWidget; import org.ofbiz.widget.WidgetWorker; import org.w3c.dom.Element; -import bsh.EvalError; -import bsh.Interpreter; - /** * Widget Library - Form model class */ @@ -1490,7 +1481,7 @@ public class ModelForm extends ModelWidg } // reset/remove the BshInterpreter now as well as later because chances are there is an interpreter at this level of the stack too - this.resetBshInterpreter(localContext); + this.resetGroovyShell(localContext); localContext.push(); localContext.put("previousItem", previousItem); previousItem = FastMap.newInstance(); @@ -1503,7 +1494,7 @@ public class ModelForm extends ModelWidg localContext.put("formUniqueId", "_"+context.get("renderFormSeqNumber")); } - this.resetBshInterpreter(localContext); + this.resetGroovyShell(localContext); if (Debug.verboseOn()) Debug.logVerbose("In form got another row, context is: " + localContext, module); @@ -2025,9 +2016,9 @@ public class ModelForm extends ModelWidg try { // use the same Interpreter (ie with the same context setup) for all evals - Interpreter bsh = this.getBshInterpreter(context); + GroovyShell shell = this.getGroovyShell(context); for (AltTarget altTarget: this.altTargets) { - Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(altTarget.useWhen)); + Object retVal = shell.evaluate(StringUtil.convertOperatorSubstitutions(altTarget.useWhen)); boolean condTrue = false; // retVal should be a Boolean, if not something weird is up... if (retVal instanceof Boolean) { @@ -2042,7 +2033,7 @@ public class ModelForm extends ModelWidg return altTarget.targetExdr.expandString(expanderContext); } } - } catch (EvalError e) { + } catch (CompilationFailedException e) { String errmsg = "Error evaluating BeanShell target conditions on form " + this.name; Debug.logError(e, errmsg, module); throw new IllegalArgumentException(errmsg); @@ -2098,17 +2089,17 @@ public class ModelForm extends ModelWidg return formLocation + "#" + name; } - public void resetBshInterpreter(Map<String, Object> context) { - context.remove("bshInterpreter"); + public void resetGroovyShell(Map<String, Object> context) { + context.remove("groovyShell"); } - public Interpreter getBshInterpreter(Map<String, Object> context) throws EvalError { - Interpreter bsh = (Interpreter) context.get("bshInterpreter"); - if (bsh == null) { - bsh = BshUtil.makeInterpreter(context); - context.put("bshInterpreter", bsh); + public GroovyShell getGroovyShell(Map<String, Object> context) throws CompilationFailedException { + GroovyShell shell = (GroovyShell) context.get("groovyShell"); + if (shell == null) { + shell = new GroovyShell(GroovyUtil.getBinding(context)); + context.put("groovyShell", shell); } - return bsh; + return shell; } /** @@ -2754,9 +2745,9 @@ public class ModelForm extends ModelWidg String styles = ""; try { // use the same Interpreter (ie with the same context setup) for all evals - Interpreter bsh = this.getBshInterpreter(context); + GroovyShell shell = this.getGroovyShell(context); for (AltRowStyle altRowStyle : this.altRowStyles) { - Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(altRowStyle.useWhen)); + Object retVal = shell.evaluate(StringUtil.convertOperatorSubstitutions(altRowStyle.useWhen)); // retVal should be a Boolean, if not something weird is up... if (retVal instanceof Boolean) { Boolean boolVal = (Boolean) retVal; @@ -2768,7 +2759,7 @@ public class ModelForm extends ModelWidg "Return value from style condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "] of form " + this.name); } } - } catch (EvalError e) { + } catch (CompilationFailedException e) { String errmsg = "Error evaluating BeanShell style conditions on form " + this.name; Debug.logError(e, errmsg, module); throw new IllegalArgumentException(errmsg); Modified: ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java?rev=1243012&r1=1243011&r2=1243012&view=diff ============================================================================== --- ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java (original) +++ ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java Sat Feb 11 07:48:54 2012 @@ -32,7 +32,6 @@ import javolution.util.FastList; import javolution.util.FastMap; import org.codehaus.groovy.runtime.InvokerHelper; -import org.ofbiz.base.util.BshUtil; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.GroovyUtil; @@ -285,15 +284,7 @@ public abstract class ModelFormAction { @Override public void runAction(Map<String, Object> context) { - if (location.endsWith(".bsh")) { - try { - BshUtil.runBshAtLocation(location, context); - } catch (GeneralException e) { - String errMsg = "Error running BSH script at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } else if (location.endsWith(".groovy")) { + if (location.endsWith(".groovy")) { try { groovy.lang.Script script = InvokerHelper.createScript(GroovyUtil.getScriptClassFromLocation(location), GroovyUtil.getBinding(context)); if (UtilValidate.isEmpty(method)) { Modified: ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=1243012&r1=1243011&r2=1243012&view=diff ============================================================================== --- ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original) +++ ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Sat Feb 11 07:48:54 2012 @@ -32,24 +32,15 @@ import java.util.Map; import java.util.StringTokenizer; import java.util.TimeZone; +import groovy.lang.GroovyShell; import javolution.util.FastList; import javolution.util.FastMap; +import org.codehaus.groovy.control.CompilationFailedException; import org.ofbiz.base.conversion.ConversionException; import org.ofbiz.base.conversion.DateTimeConverters; import org.ofbiz.base.conversion.DateTimeConverters.StringToTimestamp; -import org.ofbiz.base.util.BshUtil; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.ObjectType; -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilDateTime; -import org.ofbiz.base.util.UtilFormatOut; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.*; import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.base.util.collections.MapStack; import org.ofbiz.base.util.string.FlexibleStringExpander; @@ -71,9 +62,6 @@ import org.ofbiz.widget.WidgetWorker; import org.ofbiz.widget.form.ModelForm.UpdateArea; import org.w3c.dom.Element; -import bsh.EvalError; -import bsh.Interpreter; - /** * Widget Library - Form model class */ @@ -1014,8 +1002,8 @@ public class ModelFormField { if (UtilValidate.isEmpty(useWhenStr)) return true; try { - Interpreter bsh = this.modelForm.getBshInterpreter(context); - Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhenStr)); + GroovyShell shell = this.modelForm.getGroovyShell(context); + Object retVal = shell.evaluate(StringUtil.convertOperatorSubstitutions(useWhenStr)); boolean condTrue = false; // retVal should be a Boolean, if not something weird is up... if (retVal instanceof Boolean) { @@ -1027,7 +1015,7 @@ public class ModelFormField { } return condTrue; - } catch (EvalError e) { + } catch (CompilationFailedException e) { String errMsg = "Error evaluating BeanShell use-when condition [" + useWhenStr + "] on the field " + this.name + " of form " + this.modelForm.getName() + ": " + e.toString(); Debug.logError(e, errMsg, module); @@ -2508,13 +2496,13 @@ public class ModelFormField { String useWhen = this.getUseWhen(context); if (UtilValidate.isNotEmpty(useWhen)) { try { - Interpreter bsh = (Interpreter) context.get("bshInterpreter"); - if (bsh == null) { - bsh = BshUtil.makeInterpreter(context); - context.put("bshInterpreter", bsh); + GroovyShell shell = (GroovyShell) context.get("groovyShell"); + if (shell == null) { + shell = new GroovyShell(GroovyUtil.getBinding(context)); + context.put("groovyShell", shell); } - Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhen)); + Object retVal = shell.evaluate(StringUtil.convertOperatorSubstitutions(useWhen)); // retVal should be a Boolean, if not something weird is up... if (retVal instanceof Boolean) { @@ -2524,7 +2512,7 @@ public class ModelFormField { throw new IllegalArgumentException( "Return value from target condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "]"); } - } catch (EvalError e) { + } catch (CompilationFailedException e) { String errmsg = "Error evaluating BeanShell target conditions"; Debug.logError(e, errmsg, module); throw new IllegalArgumentException(errmsg); Modified: ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java?rev=1243012&r1=1243011&r2=1243012&view=diff ============================================================================== --- ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java (original) +++ ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java Sat Feb 11 07:48:54 2012 @@ -24,10 +24,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.ofbiz.base.util.BshUtil; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; +import groovy.lang.GroovyShell; +import org.codehaus.groovy.control.CompilationFailedException; +import org.ofbiz.base.util.*; import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.Delegator; @@ -35,9 +34,6 @@ import org.ofbiz.service.LocalDispatcher import org.ofbiz.widget.ModelWidget; import org.w3c.dom.Element; -import bsh.EvalError; -import bsh.Interpreter; - /** * Widget Library - Menu model class */ @@ -446,13 +442,13 @@ public class ModelMenu extends ModelWidg return menuLocation + "#" + name; } - public Interpreter getBshInterpreter(Map<String, Object> context) throws EvalError { - Interpreter bsh = (Interpreter) context.get("bshInterpreter"); - if (bsh == null) { - bsh = BshUtil.makeInterpreter(context); - context.put("bshInterpreter", bsh); + public GroovyShell getGroovyShell(Map<String, Object> context) throws CompilationFailedException { + GroovyShell shell = (GroovyShell) context.get("groovyShell"); + if (shell == null) { + shell = new GroovyShell(GroovyUtil.getBinding(context)); + context.put("groovyShell", shell); } - return bsh; + return shell; } /** Modified: ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java?rev=1243012&r1=1243011&r2=1243012&view=diff ============================================================================== --- ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java (original) +++ ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java Sat Feb 11 07:48:54 2012 @@ -364,15 +364,7 @@ public abstract class ModelMenuAction { @Override public void runAction(Map<String, Object> context) { - if (location.endsWith(".bsh")) { - try { - BshUtil.runBshAtLocation(location, context); - } catch (GeneralException e) { - String errMsg = "Error running BSH script at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } else if (location.endsWith(".groovy")) { + if (location.endsWith(".groovy")) { try { groovy.lang.Script script = InvokerHelper.createScript(GroovyUtil.getScriptClassFromLocation(location), GroovyUtil.getBinding(context)); if (UtilValidate.isEmpty(method)) { Modified: ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java?rev=1243012&r1=1243011&r2=1243012&view=diff ============================================================================== --- ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java (original) +++ ofbiz/branches/20120209RemoveBsh/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java Sat Feb 11 07:48:54 2012 @@ -28,14 +28,8 @@ import java.util.regex.PatternSyntaxExce import javolution.util.FastList; import javolution.util.FastMap; -import org.ofbiz.base.util.BshUtil; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.ObjectType; -import org.ofbiz.base.util.UtilFormatOut; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; +import org.codehaus.groovy.runtime.InvokerHelper; +import org.ofbiz.base.util.*; import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.finder.ByAndFinder; @@ -45,6 +39,7 @@ import org.ofbiz.entity.finder.PrimaryKe import org.ofbiz.entity.util.EntityListIterator; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.ModelService; +import org.ofbiz.widget.WidgetWorker; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -173,24 +168,35 @@ public abstract class ModelTreeAction { } public static class Script extends ModelTreeAction { + protected static final Object[] EMPTY_ARGS = {}; protected String location; + protected String method; public Script(ModelTree.ModelNode modelNode, Element scriptElement) { super (modelNode, scriptElement); - this.location = scriptElement.getAttribute("location"); + String scriptLocation = scriptElement.getAttribute("location"); + this.location = WidgetWorker.getScriptLocation(scriptLocation); + this.method = WidgetWorker.getScriptMethodName(scriptLocation); } public Script(ModelTree.ModelNode.ModelSubNode modelSubNode, Element scriptElement) { super (modelSubNode, scriptElement); - this.location = scriptElement.getAttribute("location"); + String scriptLocation = scriptElement.getAttribute("location"); + this.location = WidgetWorker.getScriptLocation(scriptLocation); + this.method = WidgetWorker.getScriptMethodName(scriptLocation); } @Override public void runAction(Map<String, Object> context) { - if (location.endsWith(".bsh")) { + if (location.endsWith(".groovy")) { try { context.put("_LIST_ITERATOR_", null); - BshUtil.runBshAtLocation(location, context); + groovy.lang.Script script = InvokerHelper.createScript(GroovyUtil.getScriptClassFromLocation(location), GroovyUtil.getBinding(context)); + if (UtilValidate.isEmpty(method)) { + script.run(); + } else { + script.invokeMethod(method, EMPTY_ARGS); + } Object obj = context.get("_LIST_ITERATOR_"); if (this.modelSubNode != null) { if (obj != null && (obj instanceof EntityListIterator || obj instanceof ListIterator<?>)) { @@ -204,7 +210,7 @@ public abstract class ModelTreeAction { } } } catch (GeneralException e) { - String errMsg = "Error running BSH script at location [" + location + "]: " + e.toString(); + String errMsg = "Error running Groovy script at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } |
Free forum by Nabble | Edit this page |