\n");
+ selects.add(templates.browserSelect("browser3", browser3, options));
+ }
- builder.append("\t\t cookies, String uri,
@@ -566,9 +540,6 @@ abstract class WebLibraryServerHtml implements Runnable {
NanoHTTPD.MIME_PLAINTEXT, "Story not found");
}
- StringBuilder builder = new StringBuilder();
- appendPreHtml(builder, false);
-
// For images documents, always go to the images if not chap 0 desc
if (story.getMeta().isImageDocument()) {
if (chapter > 0 && paragraph <= 0)
@@ -589,7 +560,7 @@ abstract class WebLibraryServerHtml implements Runnable {
String first, previous, next, last;
- StringBuilder content = new StringBuilder();
+ String viewer = "";
String disabledLeft = "";
String disabledRight = "";
@@ -607,41 +578,37 @@ abstract class WebLibraryServerHtml implements Runnable {
last = WebLibraryUrls.getViewUrl(luid,
story.getChapters().size(), null);
- StringBuilder desc = new StringBuilder();
-
+ String desc = "";
if (chapter <= 0) {
- 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");
+ StringBuilder desclines = new StringBuilder();
Map details = BasicLibrary
.getMetaDesc(story.getMeta());
for (String key : details.keySet()) {
- appendTableRow(desc, 5, key, details.get(key));
+ desclines.append(getTemplate("viewer.descline") //
+ .replace("${key}", key) //
+ .replace("${value}", details.get(key)) //
+ );
}
- desc.append("\t\t\t\t
\n");
- desc.append("\t\t\t
\n");
- desc.append("\t\t\tDescription
\n");
+
+ desc = getTemplate("viewer.desc") //
+ .replace("${title}", story.getMeta().getTitle()) //
+ .replace("${href}", next) //
+ .replace("${cover}",
+ WebLibraryUrls.getStoryUrlCover(luid)) //
+ .replace("${details}", desclines.toString()) //
+ ;
}
- content.append("\t\t\n");
- content.append(desc);
+ viewer = getTemplate("viewer.text") //
+ .replace("${desc}", desc) //
+ ;
if (chap.getParagraphs().size() <= 0) {
- content.append("\t\t\tNo content provided.\n");
+ viewer = viewer.replace("${content}",
+ "No content provided.");
} else {
- content.append(
- "\t\t\t\n"); //
- content.append("\t\t\t").append(
- new TextOutput(false).convert(chap, chapter > 0))
- .append("\n");
+ viewer = viewer.replace("${content}",
+ new TextOutput(false).convert(chap, chapter > 0));
}
- content.append("\t\t
\n");
if (chapter <= 0)
disabledLeft = " disabled='disbaled'";
@@ -698,46 +665,39 @@ 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, //
- WebLibraryUrls.getStoryUrl(luid, chapter,
- paragraph)));
+ viewer = getTemplate("viewer.image") //
+ .replace("${href}", next) //
+ .replace("${zoomStyle}", zoomStyle) //
+ .replace("${src}", WebLibraryUrls.getStoryUrl(luid,
+ chapter, paragraph)) //
+ ;
} else {
- content.append(String.format("" //
- + "\t\t" //
- + "\t\t\t%s\n" //
- + "\t\t
\n", //
- para.getContent()));
+ viewer = getTemplate("viewer.text") //
+ .replace("${desc}", "") //
+ .replace("${content}",
+ new TextOutput(false).convert(para)) //
+ ;
}
}
- builder.append(String.format("" //
- + "\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 //
- ));
-
// List of chap/para links
-
- appendItemA(builder, 5, WebLibraryUrls.getViewUrl(luid, 0, null),
- "Description", paragraph == 0 && chapter == 0);
+ StringBuilder links = new StringBuilder();
+ links.append(getTemplate("viewer.link") //
+ .replace("${link}",
+ WebLibraryUrls.getViewUrl(luid, 0, null)) //
+ .replace("${class}",
+ paragraph == 0 && chapter == 0 ? "selected" : "") //
+ .replace("${name}", "Description") //
+ );
if (paragraph > 0) {
for (int i = 1; i <= chap.getParagraphs().size(); i++) {
- appendItemA(builder, 5,
- WebLibraryUrls.getViewUrl(luid, chapter, i),
- "Image " + i, paragraph == i);
+ links.append(getTemplate("viewer.link") //
+ .replace("${link}",
+ WebLibraryUrls.getViewUrl(luid, chapter, i)) //
+ .replace("${class}",
+ paragraph == i ? "selected" : "") //
+ .replace("${name}", "Image " + i) //
+ );
}
} else {
int i = 1;
@@ -747,52 +707,79 @@ abstract class WebLibraryServerHtml implements Runnable {
chapName += ": " + c.getName();
}
- appendItemA(builder, 5,
- WebLibraryUrls.getViewUrl(luid, i, null), chapName,
- chapter == i);
+ links.append(getTemplate("viewer.link") //
+ .replace("${link}",
+ WebLibraryUrls.getViewUrl(luid, i, null)) //
+ .replace("${class}", chapter == i ? "selected" : "") //
+ .replace("${name}", chapName) //
+ );
i++;
}
}
- builder.append(String.format("" //
- + "\t\t\t\t
\n" //
- + "\t\t\t
\n" //
- + "\t\t\t
>\n" //
- + "\t\t\t
>>\n"//
- + "\t\t
\n", //
- disabledRight, next, //
- disabledRight, last //
- ));
+ // Buttons on the optionbar
- builder.append(content);
-
- builder.append("\t\t\n");
+ builder.append(getTemplateIndexPreBanner(false));
+
+ builder.append(getTemplate("viewer.navbar") //
+ .replace("${disabledFirst}", disabledLeft) //
+ .replace("${disabledPrevious}", disabledLeft) //
+ .replace("${disabledNext}", disabledRight) //
+ .replace("${disabledLast}", disabledRight) //
+ .replace("${hrefFirst}", first) //
+ .replace("${hrefPrevious}", previous) //
+ .replace("${hrefNext}", next) //
+ .replace("${hrefLast}", last) //
+ .replace("${current}",
+ "" + (paragraph > 0 ? paragraph : chapter)) //
+ .replace("${links}", links.toString()) //
+ );
+
+ builder.append(viewer);
+
+ builder.append(getTemplate("viewer.optionbar") //
+ .replace("${classSize}", (paragraph > 0 ? "s4" : "s1")) //
+ .replace("${buttons}", buttons.toString()) //
+ );
+
+ builder.append(getTemplate("index.post"));
- appendPostHtml(builder);
return NanoHTTPD.newFixedLengthResponse(Status.OK,
NanoHTTPD.MIME_HTML, builder.toString());
} catch (IOException e) {
@@ -811,22 +798,8 @@ abstract class WebLibraryServerHtml implements Runnable {
return NanoHTTPD.newChunkedResponse(Status.OK, mimeType, in);
}
- private String getContentOf(String 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));
- }
- }
-
- return "";
- }
-
- private void appendPreHtml(StringBuilder builder, boolean banner) {
+ private String getTemplateIndexPreBanner(boolean banner)
+ throws IOException {
String favicon = "favicon.ico";
String icon = Instance.getInstance().getUiConfig()
.getString(UiConfig.PROGRAM_ICON);
@@ -834,70 +807,30 @@ abstract class WebLibraryServerHtml implements Runnable {
favicon = "icon_" + icon.replace("-", "_") + ".png";
}
- builder.append(
- getContentOf("index.pre.html").replace("favicon.ico", favicon));
+ String html = getTemplate("index.pre") //
+ .replace("${title}", "Fanfix") //
+ .replace("${favicon}", favicon) //
+ ;
if (banner) {
- builder.append("\t\t\n");
- builder.append("\t\t\t
\n");
- builder.append("\t\t\t
Fanfix
\n");
- builder.append("\t\t\t
") //
- .append(Version.getCurrentVersion()) //
- .append("
\n");
- builder.append("\t\t
\n");
- }
- }
-
- private void appendPostHtml(StringBuilder builder) {
- builder.append(getContentOf("index.post.html"));
- }
-
- private void appendOption(StringBuilder builder, int depth, String name,
- String value, String selected) {
- for (int i = 0; i < depth; i++) {
- builder.append("\t");
- }
- builder.append("\n");
- }
-
- private void appendTableRow(StringBuilder builder, int depth,
- String... tds) {
- for (int i = 0; i < depth; i++) {
- builder.append("\t");
+ html += getTemplate("index.banner") //
+ .replace("${favicon}", favicon) //
+ .replace("${version}",
+ Version.getCurrentVersion().toString()) //
+ ;
}
- int col = 1;
- builder.append("");
- for (String td : tds) {
- builder.append("");
- builder.append(td);
- builder.append(" | ");
- }
- builder.append("
\n");
+ return html;
}
- private void appendItemA(StringBuilder builder, int depth, String link,
- String name, boolean selected) {
- for (int i = 0; i < depth; i++) {
- builder.append("\t");
- }
-
- builder.append("");
- builder.append(name);
- builder.append("\n");
}
}