X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibraryServerHtml.java;h=d5ba533f27b5ac746c631ccb2457ea3c3aa3649f;hp=8895fb83a07b0eb6ff7116b3998a7a89a2acfb15;hb=1f1318b8c0ba0bc472c263e54079cbaa6e303fe0;hpb=9270c238808649b0b5212d3a0fe424efc8b03230 diff --git a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java index 8895fb8..d5ba533 100644 --- a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java +++ b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java @@ -5,6 +5,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.KeyStore; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,7 +16,6 @@ import javax.net.ssl.SSLServerSocketFactory; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.bundles.Config; -import be.nikiroo.fanfix.bundles.UiConfig; import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; @@ -22,6 +23,7 @@ import be.nikiroo.fanfix.data.Paragraph.ParagraphType; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.library.WebLibraryServer.WLoginResult; import be.nikiroo.fanfix.library.web.WebLibraryServerIndex; +import be.nikiroo.fanfix.library.web.templates.WebLibraryServerTemplates; import be.nikiroo.fanfix.reader.TextOutput; import be.nikiroo.utils.IOUtils; import be.nikiroo.utils.NanoHTTPD; @@ -35,6 +37,9 @@ abstract class WebLibraryServerHtml implements Runnable { private NanoHTTPD server; protected TraceHandler tracer = new TraceHandler(); + WebLibraryServerTemplates templates = WebLibraryServerTemplates + .getInstance(); + abstract protected WLoginResult login(String who, String cookie); abstract protected WLoginResult login(String who, String key, @@ -173,13 +178,13 @@ abstract class WebLibraryServerHtml implements Runnable { } Response rep = null; - if (!login.isSuccess() - && WebLibraryUrls.isSupportedUrl(uri, true)) { - rep = loginPage(login, uri); - } + try { + if (!login.isSuccess() + && WebLibraryUrls.isSupportedUrl(uri, true)) { + rep = loginPage(login, uri); + } - if (rep == null) { - try { + if (rep == null) { if (WebLibraryUrls.isSupportedUrl(uri, false)) { if (WebLibraryUrls.INDEX_URL.equals(uri)) { rep = root(session, cookies, login); @@ -253,13 +258,12 @@ abstract class WebLibraryServerHtml implements Runnable { NanoHTTPD.MIME_PLAINTEXT, "Not Found"); } } - } catch (Exception e) { - Instance.getInstance().getTraceHandler().error( - new IOException("Cannot process web request", - e)); - rep = newFixedLengthResponse(Status.INTERNAL_ERROR, - NanoHTTPD.MIME_PLAINTEXT, "An error occured"); } + } catch (Exception e) { + Instance.getInstance().getTraceHandler().error( + new IOException("Cannot process web request", e)); + rep = newFixedLengthResponse(Status.INTERNAL_ERROR, + NanoHTTPD.MIME_PLAINTEXT, "An error occured"); } return rep; @@ -309,43 +313,26 @@ abstract class WebLibraryServerHtml implements Runnable { this.tracer = tracer; } - private Response loginPage(WLoginResult login, String uri) { - StringBuilder builder = new StringBuilder(); - - appendPreHtml(builder, true); + private Response loginPage(WLoginResult login, String uri) + throws IOException { + List