From 97641c088c44dd60f63e697466c73613a1c63262 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Sat, 02 Jul 2022 21:37:01 +0800
Subject: [PATCH] Merge branch 'master' of http://120.27.238.55:7000/r/farmer-cms

---
 src/main/java/com/xcong/farmer/cms/cms/template/Configuration.java |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/xcong/farmer/cms/cms/template/Configuration.java b/src/main/java/com/xcong/farmer/cms/cms/template/Configuration.java
new file mode 100644
index 0000000..76a24e6
--- /dev/null
+++ b/src/main/java/com/xcong/farmer/cms/cms/template/Configuration.java
@@ -0,0 +1,111 @@
+package com.xcong.farmer.cms.cms.template;
+
+import com.xcong.farmer.cms.cms.node.AttrNode;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+public abstract class Configuration {
+
+    public String staticPath;
+    public String templatePath;
+    public String outputPath;
+
+    public Configuration() {
+    }
+
+    public Configuration(String templatePath, String staticPath, String outputPath) {
+        this.staticPath = staticPath;
+        this.templatePath = templatePath;
+        this.outputPath = outputPath;
+    }
+
+    public static Map<String, String> templateCode = new HashMap<>();
+
+    private final String PREFIX_DEFAULT = "{";
+    private final String SUFFIX_DEFAULT = "}";
+
+    public <T> T parserTag(String attr, Class<T> clazz) {
+        if (!attr.startsWith(PREFIX_DEFAULT) || !attr.endsWith(SUFFIX_DEFAULT)) {
+            return null;
+        }
+
+        int i = 1;
+        int length = attr.length();
+
+        int startIndex = 1;
+        int endIndex = 1;
+        T object = null;
+        try {
+            object = clazz.newInstance();
+        } catch (InstantiationException | IllegalAccessException e) {
+            e.printStackTrace();
+        }
+
+        boolean hasMulti = false;
+        for (; i <= length - 1; i++) {
+            if (attr.charAt(i) =='[') {
+                hasMulti = true;
+            } else if (attr.charAt(i) == ']') {
+                hasMulti = false;
+            }
+
+            if (!hasMulti) {
+                if (attr.charAt(i) == ',' || i == length - 1) {
+                    String columnStr = attr.substring(startIndex, endIndex);
+
+                    String[] columns = columnStr.split("=");
+                    if (columns.length != 2) {
+                        return null;
+                    }
+
+                    try {
+                        Field field = clazz.getDeclaredField(columns[0].trim());
+                        field.setAccessible(true);
+                        field.set(object, columns[1].replace("[", "").replace("]", "").trim());
+                    } catch (NoSuchFieldException | IllegalAccessException e) {
+                        e.printStackTrace();
+                        return null;
+                    }
+                    startIndex = i + 1;
+                }
+            }
+            endIndex++;
+        }
+
+        return object;
+    }
+
+    public void put(String key, String templateCode) {
+        Configuration.templateCode.put(key, templateCode);
+    }
+
+    public String get(String key) {
+        return Configuration.templateCode.get(key);
+    }
+
+    public String getStaticPath() {
+        return staticPath;
+    }
+
+    public void setStaticPath(String staticPath) {
+        this.staticPath = staticPath;
+    }
+
+    public String getTemplatePath() {
+        return templatePath;
+    }
+
+    public void setTemplatePath(String templatePath) {
+        this.templatePath = templatePath;
+    }
+
+    public String getOutputPath() {
+        return outputPath;
+    }
+
+    public void setOutputPath(String outputPath) {
+        this.outputPath = outputPath;
+    }
+}

--
Gitblit v1.9.1