From 074a83257de30c3cd7409b0840ab6f27ed0e93b5 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 20 May 2020 13:33:25 +0200 Subject: [PATCH] use more template, use replace input stream --- src/be/nikiroo/fanfix/library/Template.java | 22 +++---- .../fanfix/library/WebLibraryServerHtml.java | 31 ++------- src/be/nikiroo/fanfix/library/web/style.css | 6 +- .../templates/WebLibraryServerTemplates.java | 65 +++++++++++-------- .../fanfix/library/web/templates/index.html | 10 +-- .../fanfix/library/web/templates/login.html | 6 ++ .../fanfix/library/web/templates/message.html | 1 + 7 files changed, 68 insertions(+), 73 deletions(-) create mode 100644 src/be/nikiroo/fanfix/library/web/templates/login.html create mode 100644 src/be/nikiroo/fanfix/library/web/templates/message.html diff --git a/src/be/nikiroo/fanfix/library/Template.java b/src/be/nikiroo/fanfix/library/Template.java index e247e279..2dfbacfe 100644 --- a/src/be/nikiroo/fanfix/library/Template.java +++ b/src/be/nikiroo/fanfix/library/Template.java @@ -1,6 +1,5 @@ package be.nikiroo.fanfix.library; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; @@ -8,7 +7,6 @@ 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 { @@ -60,26 +58,24 @@ public class Template { valueOne.close(); } } + from[i] = "${" + key + "}"; to[i] = value.toString(); i++; } - + InputStream in = IOUtils.openResource(location, name); - //TODO: pending fix in replace stream - String data = IOUtils.readSmallStream(in); - in.close(); - for(i = 0 ; i < from.length;i++) { - data=data.replace(from[i], to[i]); - } + InputStream stream; + + stream = IOUtils.openResource(location, name); + System.out.println("SOURCE = ((" + IOUtils.readSmallStream(stream) + "))"); + stream=new ReplaceInputStream(IOUtils.openResource(location, name), from, to); + System.out.println("RESULT = ((" + IOUtils.readSmallStream(stream) + "))"); - //in = new ReplaceInputStream(in, from, to); - in = new ByteArrayInputStream(StringUtils.getBytes(data)); - // END TODO - return in; + return new ReplaceInputStream(in, from, to); } public synchronized Template set(String key, String value) { diff --git a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java index f3432c38..42ebead1 100644 --- a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java +++ b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java @@ -316,35 +316,18 @@ abstract class WebLibraryServerHtml implements Runnable { private Response loginPage(WLoginResult login, String uri) throws IOException { - StringBuilder builder = new StringBuilder(); - - builder.append(getTemplateIndexPreBanner(true)); + List