From 51ea662e22121f9a0ddb5b40c4a8e93e098b34ec Mon Sep 17 00:00:00 2001
From: Hentua <wangdoubleone@gmail.com>
Date: Wed, 10 Jan 2024 22:22:44 +0800
Subject: [PATCH] fxi

---
 src/main/java/com/xcong/farmer/cms/core/node/Template.java |   47 ++++++++++++++++++++++++-----------------------
 1 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/xcong/farmer/cms/core/node/Template.java b/src/main/java/com/xcong/farmer/cms/core/node/Template.java
index 9e2e5b9..a2621db 100644
--- a/src/main/java/com/xcong/farmer/cms/core/node/Template.java
+++ b/src/main/java/com/xcong/farmer/cms/core/node/Template.java
@@ -2,6 +2,7 @@
 
 import cn.hutool.core.collection.CollUtil;
 import com.xcong.farmer.cms.core.node.PartNode;
+import lombok.extern.slf4j.Slf4j;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
@@ -16,6 +17,7 @@
  * @author wzy
  * @date 2022-06-22
  **/
+@Slf4j
 public class Template {
 
     // 文件名称
@@ -24,22 +26,15 @@
     private String path = "";
 
     private Document document;
-    private Map<String, Map<String, Object>> params = new HashMap<>();
     private Map<String, Object> system;
     private List<PartNode> partNodes = new ArrayList<>();
 
-
-    // 页面中包含的标签
-    public static Set<String> TAGS;
-    public static boolean HAS_PAGING = false;
+    public volatile static boolean HAS_PAGING = false;
 
     public Template() {
-        TAGS = new HashSet<>();
     }
 
     public Template(File file, Map<String, Object> system) {
-        TAGS = new HashSet<>();
-
         Document document = null;
         try {
             document = Jsoup.parse(file, "utf-8");
@@ -63,21 +58,33 @@
         if ("article".equals(templateType)) {
             Object templateName = system.get("templateName");
             if (templateName != null) {
-                this.name = (String) templateName;
+                this.name = String.valueOf(templateName);
             }
         } else if ("column".equals(templateType)) {
             Object page = system.get("page");
             if (!new Integer(1).equals(page)) {
                 this.name = name + "_" + page;
             }
-        } else {
-
+        } else if ("search".equals(templateType)){
+            Object templateName = system.get("templateName");
+            if (templateName != null) {
+                this.name = String.valueOf(templateName);
+            } else {
+                this.name = "search";
+            }
+        } else if ("message".equals(templateType)) {
+            Object templateName = system.get("templateName");
+            if (templateName != null) {
+                this.name = String.valueOf(templateName);
+            } else {
+                this.name = "message";
+            }
         }
 
     }
 
     public void parser() {
-        Elements children = document.body().children();
+        Elements children = document.children();
         if (CollUtil.isNotEmpty(children)) {
             for (Element child : children) {
                 PartNode partNode = new PartNode(child, this.system);
@@ -96,8 +103,8 @@
         for (PartNode partNode : partNodes) {
             sb.append(partNode.getHtml());
         }
-        document.body().empty().html(sb.toString());
-        String outPath = path(outputPath);
+        document = Jsoup.parse(sb.toString());
+        String outPath = path(outputPath) + system.get("companyCode");
 
         String html = document.html();
         try {
@@ -107,9 +114,11 @@
                 file.mkdirs();
             }
 
-            FileOutputStream outputStream = new FileOutputStream(path +this.name + suffix);
+            FileOutputStream outputStream = new FileOutputStream(path + this.name + suffix);
             outputStream.write(html.getBytes());
             outputStream.close();
+
+            document = null;
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -144,14 +153,6 @@
 
     public List<PartNode> getPartNodes() {
         return partNodes;
-    }
-
-    public Map<String, Map<String, Object>> getParams() {
-        return params;
-    }
-
-    public void putParams(String key, Map<String, Object> value) {
-        this.params.put(key, value);
     }
 
     public void systemData(Map<String, Object> data) {

--
Gitblit v1.9.1