Helius
2022-07-09 447f8f9a305ee8f304d48b0e63bdabc4acbbd826
src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java
@@ -11,6 +11,7 @@
import com.xcong.farmer.cms.utils.GroovySingleton;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import org.apache.commons.text.StringSubstitutor;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Attributes;
@@ -196,26 +197,9 @@
        Map<String, String> targetData = new HashMap<>();
        while (matcher.find()) {
            String group = matcher.group();
//            String splitValue = group.replaceAll("\\$\\{", "").replaceAll("}", "");
//            String[] split = splitValue.split("\\.");
//            if (split.length == 0) {
//                continue;
//            }
//
//            for (Map.Entry<String, Object> entry : this.parserData.entrySet()) {
//                String fieldKey = entry.getKey();
//                Map<String, Object> data = (Map<String, Object>) entry.getValue();
//                JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(data.get("state")));
//
//                for (Map.Entry<String, Object> map : jsonObject.entrySet()) {
//                    if (map.getValue() instanceof String) {
//                        targetData.put(fieldKey + "." + map.getKey(), (String) map.getValue());
//                    }
//                }
//            }
            GroovyShell groovyShell = GroovySingleton.getSingleton();
            Binding binding = groovyShell.getContext();
            Binding binding = new Binding();
            for (Map.Entry<String, Object> entry : this.parserData.entrySet()) {
                String fieldKey = entry.getKey();
                Map<String, Object> data = (Map<String, Object>) entry.getValue();
@@ -226,14 +210,17 @@
                binding.setProperty("system", systemData);
            }
//            GroovyShell shell = new GroovyShell(binding);
            Object evaluate = groovyShell.evaluate(group);
            if (evaluate == null) {
                targetData.put(group, "");
            } else {
                targetData.put(group, evaluate.toString());
            synchronized (this) {
                Script parse = groovyShell.parse(group);
                parse.setBinding(binding);
                Object evaluate = parse.run();
                if (evaluate == null) {
                    targetData.put(group, "");
                } else {
                    targetData.put(group, evaluate.toString());
                }
                groovyShell.getClassLoader().clearCache();
            }
            groovyShell.getClassLoader().clearCache();
        }
        StringSubstitutor str = new StringSubstitutor(targetData);