X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibraryServer.java;h=7c5cf425bd0dd21394c9e4e881c33c5657530ae2;hp=4abd438b6046a31053d71f5f7e772afb825f1314;hb=4bd7d202930dd0ba9129c7bd6af7dd83bc294c24;hpb=db9146bc53fcfd0912910f5bd21a6cc917018b36 diff --git a/src/be/nikiroo/fanfix/library/WebLibraryServer.java b/src/be/nikiroo/fanfix/library/WebLibraryServer.java index 4abd438..7c5cf42 100644 --- a/src/be/nikiroo/fanfix/library/WebLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/WebLibraryServer.java @@ -93,8 +93,8 @@ public class WebLibraryServer implements Runnable { subkeys.add(""); for (String subkey : subkeys) { - if (CookieUtils.validateCookie( - wookie + subkey + opts, rehashed)) { + if (CookieUtils.validateCookie(wookie + subkey + + opts, rehashed)) { this.wookie = wookie; this.token = token; this.success = true; @@ -148,8 +148,7 @@ public class WebLibraryServer implements Runnable { Integer port = Instance.getInstance().getConfig() .getInteger(Config.SERVER_PORT); if (port == null) { - throw new IOException( - "Cannot start web server: port not specified"); + throw new IOException("Cannot start web server: port not specified"); } int cacheMb = Instance.getInstance().getConfig() @@ -173,8 +172,8 @@ public class WebLibraryServer implements Runnable { if (!keystorePath.isEmpty()) { File keystoreFile = new File(keystorePath); try { - KeyStore keystore = KeyStore - .getInstance(KeyStore.getDefaultType()); + KeyStore keystore = KeyStore.getInstance(KeyStore + .getDefaultType()); InputStream keystoreStream = new FileInputStream( keystoreFile); try { @@ -226,8 +225,8 @@ public class WebLibraryServer implements Runnable { params.get("login"), whitelist); } else { String token = cookies.get("token"); - login = login(who, token, Instance.getInstance().getConfig() - .getList(Config.SERVER_ALLOWED_SUBKEYS)); + login = login(who, token, Instance.getInstance() + .getConfig().getList(Config.SERVER_ALLOWED_SUBKEYS)); } if (login.isSuccess()) { @@ -236,8 +235,9 @@ public class WebLibraryServer implements Runnable { } // refresh token - session.getCookies().set(new Cookie("token", - login.getToken(), "30; path=/")); + session.getCookies() + .set(new Cookie("token", login.getToken(), + "30; path=/")); // set options String optionName = params.get("optionName"); @@ -247,8 +247,9 @@ public class WebLibraryServer implements Runnable { session.getCookies().delete(optionName); cookies.remove(optionName); } else { - session.getCookies().set(new Cookie(optionName, - optionValue, "; path=/")); + session.getCookies().set( + new Cookie(optionName, optionValue, + "; path=/")); cookies.put(optionName, optionValue); } } @@ -258,7 +259,7 @@ public class WebLibraryServer implements Runnable { if (!login.isSuccess() && (uri.equals("/") // || uri.startsWith(STORY_URL_BASE) // || uri.startsWith(VIEWER_URL_BASE) // - || uri.startsWith(LIST_URL))) { + || uri.startsWith(LIST_URL))) { rep = loginPage(login, uri); } @@ -302,9 +303,10 @@ public class WebLibraryServer implements Runnable { NanoHTTPD.MIME_PLAINTEXT, "Not Found"); } } catch (Exception e) { - Instance.getInstance().getTraceHandler().error( - new IOException("Cannot process web request", - e)); + Instance.getInstance() + .getTraceHandler() + .error(new IOException( + "Cannot process web request", e)); rep = newFixedLengthResponse(Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "An error occured"); } @@ -413,8 +415,8 @@ public class WebLibraryServer implements Runnable { wl = false; } - rw = Instance.getInstance().getConfig().getBoolean(Config.SERVER_RW, - rw); + rw = Instance.getInstance().getConfig() + .getBoolean(Config.SERVER_RW, rw); if (!subkey.isEmpty()) { List allowed = Instance.getInstance().getConfig() .getList(Config.SERVER_ALLOWED_SUBKEYS); @@ -448,10 +450,9 @@ public class WebLibraryServer implements Runnable { uri = "/"; } - builder.append( - "
\n"); - builder.append( - "

You must be logged into the system to see the stories.

"); + builder.append("\n"); + builder.append("

You must be logged into the system to see the stories.

"); builder.append("\t\n"); builder.append("\t\n"); builder.append("\t\n"); @@ -474,8 +475,8 @@ public class WebLibraryServer implements Runnable { } return newInputStreamResponse("application/json", - new ByteArrayInputStream( - new JSONArray(jsons).toString().getBytes())); + new ByteArrayInputStream(new JSONArray(jsons).toString() + .getBytes())); } return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST, @@ -489,20 +490,24 @@ public class WebLibraryServer implements Runnable { result = new MetaResultList(result.filter(whitelist, null, null)); StringBuilder builder = new StringBuilder(); + appendPreHtml(builder, true); + Map params = session.getParms(); + String filter = cookies.get("filter"); + if (params.get("clear") != null) + filter = null; if (filter == null) { filter = ""; } - Map params = session.getParms(); - String browser = params.get("browser") == null ? "" - : params.get("browser"); - String browser2 = params.get("browser2") == null ? "" - : params.get("browser2"); - String browser3 = params.get("browser3") == null ? "" - : params.get("browser3"); + String browser = params.get("browser") == null ? "" : params + .get("browser"); + String browser2 = params.get("browser2") == null ? "" : params + .get("browser2"); + String browser3 = params.get("browser3") == null ? "" : params + .get("browser3"); String filterSource = null; String filterAuthor = null; @@ -586,31 +591,29 @@ public class WebLibraryServer implements Runnable { // TODO: javascript in realtime, using visible=false + hide [submit] builder.append("
\n"); builder.append("\tFilter: \n"); - builder.append( - "\t\n"); + builder.append("\t\n"); builder.append("\t\n"); - builder.append( - "\t\n"); + builder.append("\t"); + builder.append("\t\n"); builder.append("
\n"); builder.append("\n"); builder.append("\t
"); for (MetaData meta : result.getMetas()) { - if (!filter.isEmpty() && !meta.getTitle().toLowerCase() - .contains(filter.toLowerCase())) { + if (!filter.isEmpty() + && !meta.getTitle().toLowerCase() + .contains(filter.toLowerCase())) { continue; } // TODO Sub sources - if (filterSource != null - && !filterSource.equals(meta.getSource())) { + if (filterSource != null && !filterSource.equals(meta.getSource())) { continue; } // TODO: sub authors - if (filterAuthor != null - && !filterAuthor.equals(meta.getAuthor())) { + if (filterAuthor != null && !filterAuthor.equals(meta.getAuthor())) { continue; } @@ -626,12 +629,10 @@ public class WebLibraryServer implements Runnable { if (lib.isCached(meta.getLuid())) { // ◉ = ◉ - builder.append( - ""); + builder.append(""); } else { // ○ = ○ - builder.append( - ""); + builder.append(""); } builder.append(""); builder.append(meta.getLuid()); @@ -672,8 +673,7 @@ public class WebLibraryServer implements Runnable { // 1-based (0 = desc) int chapter = 0; if (chapterStr != null && !"cover".equals(chapterStr) - && !"metadata".equals(chapterStr) - && !"json".equals(chapterStr)) { + && !"metadata".equals(chapterStr) && !"json".equals(chapterStr)) { try { chapter = Integer.parseInt(chapterStr); if (chapter < 0) { @@ -729,8 +729,8 @@ public class WebLibraryServer implements Runnable { builder.append(p.getContent()); } - in = new ByteArrayInputStream( - builder.toString().getBytes("utf-8")); + in = new ByteArrayInputStream(builder.toString() + .getBytes("utf-8")); } else { Paragraph para = story.getChapters().get(chapter - 1) .getParagraphs().get(paragraph - 1); @@ -740,8 +740,8 @@ public class WebLibraryServer implements Runnable { mimeType = "image/png"; in = img.newInputStream(); } else { - in = new ByteArrayInputStream( - para.getContent().getBytes("utf-8")); + in = new ByteArrayInputStream(para.getContent() + .getBytes("utf-8")); } } } @@ -860,8 +860,7 @@ public class WebLibraryServer implements Runnable { desc.append("\t\t\n"); desc.append("\t
\n"); desc.append("\t\n"); - desc.append( - "\t\t\n"); + desc.append("\t\t\n"); desc.append("\t\t\n"); desc.append("\t\t\n"); desc.append("\t
HEAD 1HEAD 2
HEAD 1HEAD 2
KEY 1VAL 1
KEY 2VAL 2
\n"); @@ -871,8 +870,7 @@ public class WebLibraryServer implements Runnable { content.append("
\n"); content.append(desc); - content.append( - new TextOutput(false).convert(chap, chapter > 0)); + content.append(new TextOutput(false).convert(chap, chapter > 0)); content.append("
\n"); if (chapter <= 1) @@ -897,8 +895,8 @@ public class WebLibraryServer implements Runnable { para = chap.getParagraphs().get(paragraph - 1); } catch (IndexOutOfBoundsException e) { return NanoHTTPD.newFixedLengthResponse(Status.NOT_FOUND, - NanoHTTPD.MIME_PLAINTEXT, - "Paragraph " + paragraph + " not found"); + NanoHTTPD.MIME_PLAINTEXT, "Paragraph " + paragraph + + " not found"); } if (para.getType() == ParagraphType.IMAGE) { @@ -943,7 +941,7 @@ public class WebLibraryServer implements Runnable { disabledLeft, previous, // disabledRight, next, // disabledRight, last // - )); + )); builder.append(content); @@ -957,18 +955,19 @@ public class WebLibraryServer implements Runnable { builder.append(" BACK\n"); if (paragraph > 0) { - builder.append(String.format("" // - + "\tREAL\n"// - + "\tWIDTH\n"// - + "\tHEIGHT\n"// - + "\n", // - disabledZoomReal, - uri + "?optionName=zoom&optionValue=real", // - disabledZoomWidth, - uri + "?optionName=zoom&optionValue=width", // - disabledZoomHeight, - uri + "?optionName=zoom&optionValue=height" // - )); + builder.append(String + .format("" // + + "\tREAL\n"// + + "\tWIDTH\n"// + + "\tHEIGHT\n"// + + "\n", // + disabledZoomReal, uri + + "?optionName=zoom&optionValue=real", // + disabledZoomWidth, uri + + "?optionName=zoom&optionValue=width", // + disabledZoomHeight, uri + + "?optionName=zoom&optionValue=height" // + )); } appendPostHtml(builder); @@ -984,21 +983,23 @@ public class WebLibraryServer implements Runnable { private Response newInputStreamResponse(String mimeType, InputStream in) { if (in == null) { - return NanoHTTPD.newFixedLengthResponse(Status.NO_CONTENT, "", - null); + return NanoHTTPD + .newFixedLengthResponse(Status.NO_CONTENT, "", null); } return NanoHTTPD.newChunkedResponse(Status.OK, mimeType, in); } private String getContentOf(String file) { - InputStream in = IOUtils.openResource(WebLibraryServerIndex.class, - file); + InputStream in = IOUtils + .openResource(WebLibraryServerIndex.class, file); if (in != null) { try { return IOUtils.readSmallStream(in); } catch (IOException e) { - Instance.getInstance().getTraceHandler().error( - new IOException("Cannot get file: index.pre.html", e)); + Instance.getInstance() + .getTraceHandler() + .error(new IOException( + "Cannot get file: index.pre.html", e)); } } @@ -1048,8 +1049,7 @@ public class WebLibraryServer implements Runnable { } // NULL if not whitelist OK or if not found - private Story story(String luid, List whitelist) - throws IOException { + private Story story(String luid, List whitelist) throws IOException { synchronized (storyCache) { if (storyCache.containsKey(luid)) { Story story = storyCache.get(luid); @@ -1111,8 +1111,8 @@ public class WebLibraryServer implements Runnable { favicon = "icon_" + icon.replace("-", "_") + ".png"; } - builder.append( - getContentOf("index.pre.html").replace("favicon.ico", favicon)); + builder.append(getContentOf("index.pre.html").replace("favicon.ico", + favicon)); if (banner) { builder.append("