X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=library%2FTemplate.java;fp=library%2FTemplate.java;h=3536d5f12efccf7da066ce4b1d140553c633e631;hp=0000000000000000000000000000000000000000;hb=258e065f81071a861711ef935dca3ec5563f4360;hpb=e992c260c059c53c4aabc980db85efd58f190205 diff --git a/library/Template.java b/library/Template.java new file mode 100644 index 0000000..3536d5f --- /dev/null +++ b/library/Template.java @@ -0,0 +1,100 @@ +package be.nikiroo.fanfix.library; + +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.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