From: Niki Roo Date: Wed, 20 May 2020 11:33:25 +0000 (+0200) Subject: use more template, use replace input stream X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=074a83257de30c3cd7409b0840ab6f27ed0e93b5;p=nikiroo-utils.git use more template, use replace input stream --- diff --git a/src/be/nikiroo/fanfix/library/Template.java b/src/be/nikiroo/fanfix/library/Template.java index e247e27..2dfbacf 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 f3432c3..42ebead 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