diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/context/KitScriptHelper.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/context/KitScriptHelper.java index def59dd9..9bd822eb 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/context/KitScriptHelper.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/context/KitScriptHelper.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package cn.odboy.framework.context; +import com.ezylang.evalex.EvaluationException; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.parser.ParseException; import java.util.Map; import lombok.extern.slf4j.Slf4j; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.Scriptable; import org.springframework.stereotype.Component; /** @@ -32,32 +33,10 @@ import org.springframework.stereotype.Component; @Component public class KitScriptHelper { - public Object evalObj(String script, Map args) { - try (Context rhino = Context.enter()) { - Scriptable scope = rhino.initStandardObjects(); - bindArgumentsToScope(scope, args); - Object result = rhino.evaluateString(scope, script, "JavaScript", 1, null); - log.info("执行结果: {}", Context.toString(result)); - return result; + public Object evalObj(String script, Map args) throws EvaluationException, ParseException { + Expression expression = new Expression(script); + expression.withValues(args); + EvaluationValue result = expression.evaluate(); + return result.getValue(); } - } - - private void bindArgumentsToScope(Scriptable scope, Map args) { - if (args == null) { - return; - } - for (Map.Entry entry : args.entrySet()) { - Object jsValue = Context.javaToJS(entry.getValue(), scope); - scope.put(entry.getKey().toString(), scope, jsValue); - } - } - - private void bindArgumentsToScope(Scriptable scope, Object args) { - if (args == null) { - return; - } - // 单个对象参数 - Object jsValue = Context.javaToJS(args, scope); - scope.put("args", scope, jsValue); - } } diff --git a/cutejava-springboot3/cutejava-starter/src/test/logback.xml b/cutejava-springboot3/cutejava-starter/src/main/resources/logback.xml similarity index 87% rename from cutejava-springboot3/cutejava-starter/src/test/logback.xml rename to cutejava-springboot3/cutejava-starter/src/main/resources/logback.xml index acdd235a..caac7410 100644 --- a/cutejava-springboot3/cutejava-starter/src/test/logback.xml +++ b/cutejava-springboot3/cutejava-starter/src/main/resources/logback.xml @@ -4,15 +4,16 @@ - + + - + + @@ -20,6 +21,7 @@ ${log.charset} + ${log.home}/${log.name}.log @@ -31,10 +33,11 @@ ${log.pattern} + - \ No newline at end of file + diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/context/KitScriptHelper.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/context/KitScriptHelper.java index 1e1bc040..9bd822eb 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/context/KitScriptHelper.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/context/KitScriptHelper.java @@ -15,10 +15,12 @@ */ package cn.odboy.framework.context; +import com.ezylang.evalex.EvaluationException; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.parser.ParseException; import java.util.Map; import lombok.extern.slf4j.Slf4j; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.Scriptable; import org.springframework.stereotype.Component; /** @@ -31,32 +33,10 @@ import org.springframework.stereotype.Component; @Component public class KitScriptHelper { - public Object evalObj(String script, Map args) { - try (Context rhino = Context.enter()) { - Scriptable scope = rhino.initStandardObjects(); - bindArgumentsToScope(scope, args); - Object result = rhino.evaluateString(scope, script, "JavaScript", 1, null); - log.info("执行结果: {}", Context.toString(result)); - return result; + public Object evalObj(String script, Map args) throws EvaluationException, ParseException { + Expression expression = new Expression(script); + expression.withValues(args); + EvaluationValue result = expression.evaluate(); + return result.getValue(); } - } - - private void bindArgumentsToScope(Scriptable scope, Map args) { - if (args == null) { - return; - } - for (Map.Entry entry : args.entrySet()) { - Object jsValue = Context.javaToJS(entry.getValue(), scope); - scope.put(entry.getKey().toString(), scope, jsValue); - } - } - - private void bindArgumentsToScope(Scriptable scope, Object args) { - if (args == null) { - return; - } - // 单个对象参数 - Object jsValue = Context.javaToJS(args, scope); - scope.put("args", scope, jsValue); - } }