From 8639c60de668b16a3aab1f673da58514c8430de9 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 19 May 2020 21:20:52 +0200 Subject: [PATCH] begin template system change --- src/be/nikiroo/fanfix/library/Template.java | 113 ++++++++++++ .../fanfix/library/WebLibraryServerHtml.java | 101 ++++------- .../templates/WebLibraryServerTemplates.java | 162 ++++++++++++++++++ .../fanfix/library/web/templates/index.html | 50 ++++++ .../fanfix/library/web/templates/viewer.html | 1 + 5 files changed, 356 insertions(+), 71 deletions(-) create mode 100644 src/be/nikiroo/fanfix/library/Template.java create mode 100644 src/be/nikiroo/fanfix/library/web/templates/index.html create mode 100644 src/be/nikiroo/fanfix/library/web/templates/viewer.html 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