package cn.cerc.ui.vcl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

import cn.cerc.ui.core.HtmlWriter;
import cn.cerc.ui.parts.UIComponent;

public class UIHtmlFile extends UIComponent {
    private String fileName;

    public UIHtmlFile() {
        super();
    }

    public UIHtmlFile(UIComponent owner) {
        super(owner);
    }

    @Override
    public void output(HtmlWriter html) {
        if (fileName == null) {
            html.println("fileName is null.");
            return;
        }
        // 加载项目文件配置
        InputStream file = UIHtmlFile.class.getResourceAsStream(fileName);

        if (file != null) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(file, StandardCharsets.UTF_8));
            try {
                String text = null;
                while ((text = reader.readLine()) != null) {
                    html.println(text);
                }
            } catch (IOException e) {
                html.println(e.getMessage());
            }
        } else {
            html.println("%s doesn't exist.", fileName);
        }
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

}

@@ -180,16 +180,64 @@
 harsets;
+%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0Aimport
@@ -377,16 +377,73 @@
 ileName;
+%0A    private Map%3CString, Object%3E items = new HashMap%3C%3E();
 %0A%0A    pu
@@ -1095,24 +1095,384 @@
     
-html.println(tex
+String result = text;%0A                    for (String key : this.items.keySet()) %7B%0A                        String flag = String.format(%22$%7B%25s%7D%22, key);%0A                        if (text.contains(flag)) %7B%0A                            result = text.replace(flag, String.valueOf(items.get(key)));%0A                        %7D%0A                    %7D%0A                    html.println(resul
 t);%0A
@@ -1755,20 +1755,26 @@
  public 
-void
+UIHtmlFile
  setFile
@@ -1835,13 +1835,223 @@
 me;%0A    
+    return this;%0A    %7D%0A%0A    public UIHtmlFile addItem(String key, Object value) %7B%0A        items.put(key, value);%0A        return this;%0A    %7D%0A%0A    public Map%3CString, Object%3E getItems() %7B%0A        return items;%0A    
 %7D
-%0A
 %0A%7D%0A

Update UIHtmlFile.java