| | |
| | | import com.xcong.farmer.cms.core.handler.DataParserHandler; |
| | | import com.xcong.farmer.cms.core.tag.TagsEnum; |
| | | import com.xcong.farmer.cms.core.template.Configuration; |
| | | import com.xcong.farmer.cms.core.template.TemplateConfiguration; |
| | | import com.xcong.farmer.cms.utils.GroovySingleton; |
| | | import groovy.lang.Binding; |
| | | import groovy.lang.GroovyShell; |
| | | import org.apache.commons.text.StringSubstitutor; |
| | |
| | | this.element.attr("src", STATIC_URL + src); |
| | | } |
| | | } |
| | | |
| | | if ("link".equals(this.element.tagName())) { |
| | | String src = this.element.attr("href"); |
| | | if (StrUtil.isNotBlank(STATIC_URL)) { |
| | | this.element.attr("href", STATIC_URL + src); |
| | | } |
| | | } |
| | | |
| | | if ("script".equals(this.element.tagName())) { |
| | | String src = this.element.attr("src"); |
| | | if (StrUtil.isNotBlank(STATIC_URL)) { |
| | | this.element.attr("src", STATIC_URL + src); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void parser() { |
| | | staticPath(); |
| | | // 判断是否为最小节点,如果是且没有特殊标签,则跳过清空 |
| | | if (!isNeedEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | this.element.empty(); |
| | | |
| | | staticPath(); |
| | | Attributes attributes = this.element.attributes(); |
| | | if (attributes.isEmpty()) { |
| | | return; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | runDataInject(); |
| | | } |
| | | |
| | |
| | | String key = attribute.getKey().replaceAll("\\$", ""); |
| | | String value = attribute.getValue(); |
| | | |
| | | String result = attrValueFormat(value); |
| | | // @{} 为java表达式; ${}为需要注入的数据项 |
| | | if (value.startsWith("@{")) { |
| | | value = value.replaceAll("\\@\\{", "").replaceAll("}", ""); |
| | | value = result.replaceAll("\\@\\{", "").replaceAll("}", ""); |
| | | 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(); |
| | | binding.setProperty(fieldKey, data); |
| | | binding.setVariable(fieldKey + ".index", 1); |
| | | binding.setProperty(fieldKey, data.get("state")); |
| | | int index = (int) data.get("index"); |
| | | binding.setVariable( "index", index); |
| | | } |
| | | GroovyShell shell = new GroovyShell(binding); |
| | | String evaluate = (String) shell.evaluate(value); |
| | |
| | | this.element.removeAttr("class"); |
| | | this.element.attr("class", evaluate); |
| | | } else if (value.contains( "${")) { |
| | | String result = attrValueFormat(value); |
| | | if ("text".equals(key)) { |
| | | this.element.text(result); |
| | | } else if ("html".equals(key)) { |
| | | this.element.html(result); |
| | | } else { |
| | | this.element.attr(key, result); |
| | | } |
| | |
| | | // } |
| | | // } |
| | | |
| | | Binding binding = new Binding(); |
| | | GroovyShell groovyShell = GroovySingleton.getSingleton(); |
| | | Binding binding = groovyShell.getContext(); |
| | | for (Map.Entry<String, Object> entry : this.parserData.entrySet()) { |
| | | String fieldKey = entry.getKey(); |
| | | Map<String, Object> data = (Map<String, Object>) entry.getValue(); |
| | |
| | | binding.setProperty("system", systemData); |
| | | } |
| | | |
| | | GroovyShell shell = new GroovyShell(binding); |
| | | Object evaluate = shell.evaluate(group); |
| | | // GroovyShell shell = new GroovyShell(binding); |
| | | Object evaluate = groovyShell.evaluate(group); |
| | | if (evaluate == null) { |
| | | targetData.put(group, ""); |
| | | } else { |
| | | targetData.put(group, evaluate.toString()); |
| | | } |
| | | groovyShell.getClassLoader().clearCache(); |
| | | } |
| | | |
| | | StringSubstitutor str = new StringSubstitutor(targetData); |