Fixed startup page
This commit is contained in:
parent
bc35492cee
commit
342368bd77
1 changed files with 15 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package se.hal.page;
|
package se.hal.page;
|
||||||
|
|
||||||
import se.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
|
import zutil.MimeTypeUtil;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.net.http.HttpHeader;
|
import zutil.net.http.HttpHeader;
|
||||||
import zutil.net.http.HttpPage;
|
import zutil.net.http.HttpPage;
|
||||||
|
|
@ -8,19 +9,26 @@ import zutil.net.http.HttpPrintStream;
|
||||||
import zutil.parser.Templator;
|
import zutil.parser.Templator;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class StartupWebPage implements HttpPage {
|
public class StartupWebPage implements HttpPage {
|
||||||
private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/startup.tmpl";
|
private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/startup.tmpl";
|
||||||
|
private static final List<String> ACCEPTED_FILE_LIST = Arrays.asList(
|
||||||
|
"/css/bootstrap.min.css",
|
||||||
|
"/css/hal.css",
|
||||||
|
"/fonts/glyphicons-halflings-regular.ttf",
|
||||||
|
"/fonts/glyphicons-halflings-regular.woff",
|
||||||
|
"/fonts/glyphicons-halflings-regular.woff2"
|
||||||
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void respond(HttpPrintStream out, HttpHeader headers, Map<String, Object> session, Map<String, String> cookie, Map<String, String> request) throws IOException {
|
public void respond(HttpPrintStream out, HttpHeader headers, Map<String, Object> session, Map<String, String> cookie, Map<String, String> request) throws IOException {
|
||||||
if (headers.getRequestURL().endsWith("bootstrap.min.css")) {
|
if (ACCEPTED_FILE_LIST.contains(headers.getRequestURL())) {
|
||||||
printFileContents(HalContext.RESOURCE_WEB_ROOT + "/css/bootstrap.min.css", out);
|
printFileContents(headers.getRequestURL(), out);
|
||||||
} else if (headers.getRequestURL().endsWith("hal.css")) {
|
|
||||||
printFileContents(HalContext.RESOURCE_WEB_ROOT + "/css/hal.css", out);
|
|
||||||
} else {
|
} else {
|
||||||
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
||||||
out.print(tmpl.compile());
|
out.print(tmpl.compile());
|
||||||
|
|
@ -28,7 +36,7 @@ public class StartupWebPage implements HttpPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printFileContents(String path, HttpPrintStream out) throws IOException {
|
private void printFileContents(String path, HttpPrintStream out) throws IOException {
|
||||||
out.setHeader(HttpHeader.HEADER_CONTENT_TYPE, "text/css");
|
out.setHeader(HttpHeader.HEADER_CONTENT_TYPE, MimeTypeUtil.getMimeByExtension(FileUtil.getFileExtension(path)).toString());
|
||||||
out.print(FileUtil.getContent(HalContext.RESOURCE_WEB_ROOT + path));
|
out.write(FileUtil.getByteContent(FileUtil.find(HalContext.RESOURCE_WEB_ROOT + path)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue