From: Niki Roo Date: Tue, 19 May 2020 19:20:52 +0000 (+0200) Subject: begin template system change X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=8639c60de668b16a3aab1f673da58514c8430de9;p=fanfix-swing.git begin template system change --- diff --git a/src/be/nikiroo/fanfix/library/Template.java b/src/be/nikiroo/fanfix/library/Template.java new file mode 100644 index 00000000..e247e279 --- /dev/null +++ b/src/be/nikiroo/fanfix/library/Template.java @@ -0,0 +1,113 @@ +package be.nikiroo.fanfix.library; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import be.nikiroo.utils.IOUtils; +import be.nikiroo.utils.StringUtils; +import be.nikiroo.utils.streams.ReplaceInputStream; + +public class Template { + private Class location; + private String name; + + private Map values = new HashMap(); + private Map valuesTemplate = new HashMap(); + private Map> valuesTemplateList = new HashMap>(); + + public Template(Class location, String name) { + this.location = location; + this.name = name; + } + + public synchronized InputStream read() throws IOException { + + String from[] = new String[values.size() + valuesTemplate.size() + + valuesTemplateList.size()]; + String to[] = new String[from.length]; + + int i = 0; + + for (String key : values.keySet()) { + from[i] = "${" + key + "}"; + to[i] = values.get(key); + + i++; + } + for (String key : valuesTemplate.keySet()) { + InputStream value = valuesTemplate.get(key).read(); + try { + from[i] = "${" + key + "}"; + to[i] = IOUtils.readSmallStream(value); + } finally { + value.close(); + } + + i++; + } + for (String key : valuesTemplateList.keySet()) { + List