mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
introduce docsify; refactor the daemon
This commit is contained in:
parent
7dc62012a6
commit
91e4d79953
12 changed files with 1038 additions and 26 deletions
52
src/main/java/de/kosit/validationtool/daemon/GuiHandler.java
Normal file
52
src/main/java/de/kosit/validationtool/daemon/GuiHandler.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package de.kosit.validationtool.daemon;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GuiHandler extends BaseHandler {
|
||||
|
||||
private static final URL INDEX_HTML = GuiHandler.class.getClassLoader().getResource("gui/index.html");
|
||||
|
||||
public GuiHandler() {
|
||||
if (INDEX_HTML == null) {
|
||||
throw new IllegalStateException("No html found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException {
|
||||
assert INDEX_HTML != null;
|
||||
final String path = exchange.getRequestURI().toASCIIString();
|
||||
if (path.equals("/")) {
|
||||
write(exchange, IOUtils.toString(INDEX_HTML, Charset.defaultCharset()).getBytes(), "text/html");
|
||||
} else{
|
||||
final URL resource = GuiHandler.class.getClassLoader().getResource("gui" + path);
|
||||
if (resource != null) {
|
||||
write(exchange,IOUtils.toString(resource, Charset.defaultCharset()).getBytes(), Mediatype.resolveBySuffix(resource.getPath()).getMimeType());;
|
||||
}else {
|
||||
error(exchange,404,"not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
protected enum Mediatype {
|
||||
JS("application/javascript"),
|
||||
MD("text/markdown"),
|
||||
CSS("text/css");
|
||||
private final String mimeType;
|
||||
|
||||
static Mediatype resolveBySuffix(String path){
|
||||
return Arrays.stream(values()).filter(e->path.toUpperCase().endsWith("."+e.name())).findFirst().orElse(Mediatype.MD);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue