X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FWebLibraryServerHtml.java;h=e530d3f0a3a9b4c90cf6a31ecef6ae73e09b1020;hb=c43615157b52a51f9d4a8a9f8a0a32490dbbb30d;hp=ac0631dd60ba32abc8f34b7297510bbc78039c95;hpb=14c0debd37e7de3fa8b5acb81c234f96452ec2a2;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java
index ac0631d..e530d3f 100644
--- a/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java
+++ b/src/be/nikiroo/fanfix/library/WebLibraryServerHtml.java
@@ -70,6 +70,13 @@ abstract class WebLibraryServerHtml implements Runnable {
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);
@@ -166,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)) {
@@ -210,6 +218,8 @@ abstract class WebLibraryServerHtml implements Runnable {
}
} 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: "
@@ -272,6 +282,10 @@ abstract class WebLibraryServerHtml implements Runnable {
}
}
+ protected void doStop() {
+ server.stop();
+ }
+
/**
* The traces handler for this {@link WebLibraryServerHtml}.
*
@@ -301,23 +315,25 @@ abstract class WebLibraryServerHtml implements Runnable {
appendPreHtml(builder, true);
if (login.isBadLogin()) {
- builder.append("
Bad login or password
");
+ builder.append(
+ "\t\tBad login or password
");
} else if (login.isBadCookie()) {
- builder.append("Your session timed out
");
+ builder.append(
+ "\t\tYour session timed out
");
}
if (WebLibraryUrls.LOGOUT_URL.equals(uri)) {
uri = WebLibraryUrls.INDEX_URL;
}
+ builder.append("\t\t\n");
+ "\t\t\tYou 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);
@@ -355,45 +371,53 @@ abstract class WebLibraryServerHtml implements Runnable {
// TODO: javascript in realtime, using visible=false + hide [submit]
- builder.append("\n");
-
- builder.append("\t");
+ builder.append("\t\t
\n");
for (MetaData meta : result.getMetas()) {
if (!filter.isEmpty() && !meta.getTitle().toLowerCase()
.contains(filter.toLowerCase())) {
@@ -464,36 +481,30 @@ abstract class WebLibraryServerHtml implements Runnable {
continue;
}
- builder.append("
\n");
+
+ builder.append(getTemplate("bookline") //
+ .replace("${href}",
+ WebLibraryUrls.getViewUrl(meta.getLuid(), null,
+ null)) //
+ .replace("${luid}", meta.getLuid()) //
+ .replace("${title}", meta.getTitle()) //
+ .replace("${author}", author) //
+ .replace("${cachedClass}", cachedClass) //
+ .replace("${cached}", cached) //
+ );
}
- builder.append("
");
+ builder.append("\t\t
\n");
appendPostHtml(builder);
return NanoHTTPD.newFixedLengthResponse(builder.toString());
@@ -593,32 +604,38 @@ abstract class WebLibraryServerHtml implements Runnable {
StringBuilder desc = new StringBuilder();
if (chapter <= 0) {
- desc.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\tDescription
\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'";
@@ -677,9 +694,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, //
@@ -687,18 +704,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" //
- + "\t
<<\n"//
- + "\t
<\n" //
- + "\t
\n" //
- + "\t\t
%d
\n" //
- + "\t\t
\n", //
+ + "\t\t
\n" //
+ + "\t\t\t
<<\n"//
+ + "\t\t\t
<\n" //
+ + "\t\t\t
\n" //
+ + "\t\t\t\t
%d
\n" //
+ + "\t\t\t\t
\n", //
disabledLeft, first, //
disabledLeft, previous, //
paragraph > 0 ? paragraph : chapter //
@@ -706,11 +725,11 @@ abstract class WebLibraryServerHtml implements Runnable {
// List of chap/para links
- appendItemA(builder, 3, WebLibraryUrls.getViewUrl(luid, 0, null),
+ appendItemA(builder, 5, WebLibraryUrls.getViewUrl(luid, 0, null),
"Description", paragraph == 0 && chapter == 0);
if (paragraph > 0) {
for (int i = 1; i <= chap.getParagraphs().size(); i++) {
- appendItemA(builder, 3,
+ appendItemA(builder, 5,
WebLibraryUrls.getViewUrl(luid, chapter, i),
"Image " + i, paragraph == i);
}
@@ -722,7 +741,7 @@ abstract class WebLibraryServerHtml implements Runnable {
chapName += ": " + c.getName();
}
- appendItemA(builder, 3,
+ appendItemA(builder, 5,
WebLibraryUrls.getViewUrl(luid, i, null), chapName,
chapter == i);
@@ -731,32 +750,31 @@ abstract class WebLibraryServerHtml implements Runnable {
}
builder.append(String.format("" //
- + "\t\t
\n" //
- + "\t
\n" //
- + "\t
>\n" //
- + "\t
>>\n"//
- + "
\n", //
+ + "\t\t\t\t
\n" //
+ + "\t\t\t
\n" //
+ + "\t\t\t
>\n" //
+ + "\t\t\t
>>\n"//
+ + "\t\t
\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\t
BACK\n");
if (paragraph > 0) {
builder.append(String.format("" //
- + "\t
REAL\n"//
- + "\t
WIDTH\n"//
- + "\t
HEIGHT\n"//
- + "
\n", //
+ + "\t\t\tREAL\n"//
+ + "\t\t\tWIDTH\n"//
+ + "\t\t\tHEIGHT\n", //
disabledZoomReal,
uri + "?optionName=zoom&optionValue=real", //
disabledZoomWidth,
@@ -766,6 +784,8 @@ abstract class WebLibraryServerHtml implements Runnable {
));
}
+ builder.append("\t\t\n");
+
appendPostHtml(builder);
return NanoHTTPD.newFixedLengthResponse(Status.OK,
NanoHTTPD.MIME_HTML, builder.toString());
@@ -812,15 +832,15 @@ abstract class WebLibraryServerHtml implements Runnable {
getContentOf("index.pre.html").replace("favicon.ico", favicon));
if (banner) {
- builder.append("\n");
- builder.append("\t
\n");
+ builder.append("\t\t\t
\n");
- builder.append("\t
Fanfix
\n");
- builder.append("\t
") //
+ builder.append("\t\t\tFanfix
\n");
+ builder.append("\t\t\t") //
.append(Version.getCurrentVersion()) //
.append("
\n");
- builder.append("
\n");
+ builder.append("\t\t\n");
}
}
@@ -874,4 +894,14 @@ abstract class WebLibraryServerHtml implements Runnable {
builder.append(name);
builder.append("\n");
}
+
+ private String getTemplate(String template) throws IOException {
+ InputStream in = IOUtils.openResource(WebLibraryServerIndex.class,
+ template + ".html");
+ try {
+ return IOUtils.readSmallStream(in);
+ } finally {
+ in.close();
+ }
+ }
}