X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibraryServerHtml.java;h=1ec3b1fbb8eed3a84ba9c4e291156e69a4f5bae1;hp=6489fdf75880e6d3488803d88fa4722091811ecc;hb=9a705a5aa74f35f9dfece944f3d8d965270b21f2;hpb=6673ec5924d57a37c4f995f9c81c50a187b51c63 diff --git a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java index 6489fdf..1ec3b1f 100644 --- a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java +++ b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java @@ -47,15 +47,36 @@ abstract class WebLibraryServerHtml implements Runnable { abstract protected Response getStoryPart(String uri, WLoginResult login); + abstract protected Response setStoryPart(String uri, String value, + WLoginResult login) throws IOException; + abstract protected Response getCover(String uri, WLoginResult login) throws IOException; + abstract protected Response setCover(String uri, String luid, + WLoginResult login) throws IOException; + abstract protected List metas(WLoginResult login) throws IOException; abstract protected Story story(String luid, WLoginResult login) throws IOException; + protected abstract Response imprt(String uri, String url, + WLoginResult login) throws IOException; + + protected abstract Response imprtProgress(String uri, WLoginResult login); + + protected abstract Response delete(String uri, WLoginResult login) + throws IOException; + + /** + * Wait until all operations are done and stop the server. + *

+ * All the new R/W operations will be refused after a call to stop. + */ + protected abstract Response stop(WLoginResult login); + public WebLibraryServerHtml(boolean secure) throws IOException { Integer port = Instance.getInstance().getConfig() .getInteger(Config.SERVER_PORT); @@ -152,13 +173,14 @@ abstract class WebLibraryServerHtml implements Runnable { } Response rep = null; - if (!login.isSuccess() && WebLibraryUrls.isSupportedUrl(uri)) { + if (!login.isSuccess() + && WebLibraryUrls.isSupportedUrl(uri, true)) { rep = loginPage(login, uri); } if (rep == null) { try { - if (WebLibraryUrls.isSupportedUrl(uri)) { + if (WebLibraryUrls.isSupportedUrl(uri, false)) { if (WebLibraryUrls.INDEX_URL.equals(uri)) { rep = root(session, cookies, login); } else if (WebLibraryUrls.VERSION_URL.equals(uri)) { @@ -166,17 +188,38 @@ abstract class WebLibraryServerHtml implements Runnable { MIME_PLAINTEXT, Version.getCurrentVersion().toString()); } else if (WebLibraryUrls.isCoverUrl(uri)) { - rep = getCover(uri, login); + String luid = params.get("luid"); + if (luid != null) { + rep = setCover(uri, luid, login); + } else { + rep = getCover(uri, login); + } } else if (WebLibraryUrls.isListUrl(uri)) { rep = getList(uri, login); } else if (WebLibraryUrls.isStoryUrl(uri)) { - rep = getStoryPart(uri, login); + String value = params.get("value"); + if (value != null) { + rep = setStoryPart(uri, value, login); + } else { + rep = getStoryPart(uri, login); + } } else if (WebLibraryUrls.isViewUrl(uri)) { rep = getViewer(cookies, uri, login); } else if (WebLibraryUrls.LOGOUT_URL.equals(uri)) { session.getCookies().delete("cookie"); cookies.remove("cookie"); rep = loginPage(login(false, false), uri); + } else if (WebLibraryUrls.isImprtUrl(uri)) { + String url = params.get("url"); + if (url != null) { + rep = imprt(uri, url, login); + } else { + rep = imprtProgress(uri, login); + } + } else if (WebLibraryUrls.isDeleteUrl(uri)) { + rep = delete(uri, login); + } else if (WebLibraryUrls.EXIT_URL.equals(uri)) { + rep = WebLibraryServerHtml.this.stop(login); } else { getTraceHandler().error( "Supported URL was not processed: " @@ -223,9 +266,7 @@ abstract class WebLibraryServerHtml implements Runnable { } }; - if (ssf != null) - - { + if (ssf != null) { getTraceHandler().trace("Install SSL on the web server..."); server.makeSecure(ssf, null); getTraceHandler().trace("Done."); @@ -241,6 +282,10 @@ abstract class WebLibraryServerHtml implements Runnable { } } + protected void doStop() { + server.stop(); + } + /** * The traces handler for this {@link WebLibraryServerHtml}. * @@ -270,23 +315,25 @@ abstract class WebLibraryServerHtml implements Runnable { appendPreHtml(builder, true); if (login.isBadLogin()) { - builder.append("

Bad login or password
"); + builder.append( + "\t\t
Bad login or password
"); } else if (login.isBadCookie()) { - builder.append("
Your session timed out
"); + builder.append( + "\t\t
Your session timed out
"); } if (WebLibraryUrls.LOGOUT_URL.equals(uri)) { uri = WebLibraryUrls.INDEX_URL; } + builder.append("\t\t
\n"); 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"); - builder.append("
\n"); + "\t\t\t

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

"); + builder.append("\t\t\t\n"); + builder.append("\t\t\t\n"); + builder.append("\t\t\t\n"); + builder.append("\t\t\n"); appendPostHtml(builder); @@ -324,42 +371,42 @@ abstract class WebLibraryServerHtml implements Runnable { // TODO: javascript in realtime, using visible=false + hide [submit] - builder.append("
\n"); - builder.append("\n"); // TODO: javascript in realtime, using visible=false + hide [submit] - builder.append("
\n"); - builder.append("\tFilter: \n"); + builder.append("\t\t\t
\n"); + builder.append("\t\t\t\tFilter: \n"); builder.append( - "\t\n"); - builder.append("\t\n"); + builder.append("\t\t\t\t\n"); - builder.append("\t"); builder.append( - "\t\n"); - builder.append("
\n"); - builder.append("\n"); + "\t\t\t\t\n"); + builder.append( + "\t\t\t\t\n"); + builder.append("\t\t\t
\n"); + builder.append("\t\t\n"); - builder.append("\t
"); + builder.append("\t\t
\n"); for (MetaData meta : result.getMetas()) { if (!filter.isEmpty() && !meta.getTitle().toLowerCase() .contains(filter.toLowerCase())) { @@ -433,7 +481,7 @@ abstract class WebLibraryServerHtml implements Runnable { continue; } - builder.append("
"); + builder.append("\t\t\t
"); builder.append(""); - desc.append(story.getMeta().getTitle()); - desc.append("\n"); - desc.append("
\n"); - desc.append("\t\n"); - desc.append("\t\t\n"); - desc.append("\t\n"); - desc.append("\t\n"); + desc.append("\t\t\t

") + .append(story.getMeta().getTitle()) + .append("

\n"); + desc.append("\t\t\t
\n"); + desc.append( + "\t\t\t\t\n"); + desc.append("\t\t\t\t\t\n"); + desc.append("\t\t\t\t\n"); + desc.append("\t\t\t\t
\n"); Map details = BasicLibrary .getMetaDesc(story.getMeta()); for (String key : details.keySet()) { - appendTableRow(desc, 2, key, details.get(key)); + appendTableRow(desc, 5, key, details.get(key)); } - desc.append("\t
\n"); - desc.append("
\n"); - desc.append("

Description

\n"); + desc.append("\t\t\t\t\n"); + desc.append("\t\t\t
\n"); + desc.append("\t\t\t

Description

\n"); } - content.append("
\n"); + content.append("\t\t
\n"); content.append(desc); - String description = new TextOutput(false).convert(chap, - chapter > 0); - content.append(chap.getParagraphs().size() <= 0 - ? "No content provided." - : description); - content.append("
\n"); + if (chap.getParagraphs().size() <= 0) { + content.append("\t\t\tNo content provided.\n"); + } else { + content.append( + "\t\t\t\n"); // + content.append("\t\t\t").append( + new TextOutput(false).convert(chap, chapter > 0)) + .append("\n"); + } + content.append("\t\t
\n"); if (chapter <= 0) disabledLeft = " disabled='disbaled'"; @@ -646,9 +700,9 @@ abstract class WebLibraryServerHtml implements Runnable { String javascript = "document.getElementById(\"previous\").click(); return false;"; content.append(String.format("" // - + "" - + "" - + "", // + + "\t\t\n" + + "\t\t\t\n" + + "\t\t\n", // javascript, // next, // zoomStyle, // @@ -656,18 +710,20 @@ abstract class WebLibraryServerHtml implements Runnable { paragraph))); } else { content.append(String.format("" // - + "
%s
", // + + "\t\t
" // + + "\t\t\t%s\n" // + + "\t\t
\n", // para.getContent())); } } builder.append(String.format("" // - + "\n", // disabledRight, next, // disabledRight, last // )); builder.append(content); - builder.append("
0) { - builder.append("s4"); + builder.append(" s4"); } else { - builder.append("s1"); + builder.append(" s1"); } builder.append("'>\n"); - builder.append(" BACK\n"); + builder.append("\t\t\tBACK\n"); if (paragraph > 0) { builder.append(String.format("" // - + "\tREAL\n"// - + "\tWIDTH\n"// - + "\tHEIGHT\n"// - + "
\n", // + + "\t\t\tREAL\n"// + + "\t\t\tWIDTH\n"// + + "\t\t\tHEIGHT\n", // disabledZoomReal, uri + "?optionName=zoom&optionValue=real", // disabledZoomWidth, @@ -735,6 +790,8 @@ abstract class WebLibraryServerHtml implements Runnable { )); } + builder.append("\t\t
\n"); + appendPostHtml(builder); return NanoHTTPD.newFixedLengthResponse(Status.OK, NanoHTTPD.MIME_HTML, builder.toString()); @@ -781,15 +838,15 @@ abstract class WebLibraryServerHtml implements Runnable { getContentOf("index.pre.html").replace("favicon.ico", favicon)); if (banner) { - builder.append("\n"); + builder.append("\t\t
\n"); } }