package me.totalfreedom.totalfreedommod.httpd; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; public class HTTPDPageBuilder { private static final String TEMPLATE = "\r\n" + "\r\n" + "\r\n" + "{$TITLE}\r\n" + "\r\n" + "{$STYLE}" + "{$SCRIPT}" + "\r\n" + "\r\n{$BODY}\r\n" + "\r\n"; private static final String STYLE = "\r\n"; private static final String SCRIPT = "\r\n" + "\r\n" + "\r\n"; // private String body = null; private String title = null; private String style = null; private String script = null; public HTTPDPageBuilder() { } public HTTPDPageBuilder(String body, String title, String style, String script) { this.body = body; this.title = title; this.style = style; this.script = script; } public void setBody(String body) { this.body = body; } public void setTitle(String title) { this.title = title; } public void setStyle(String style) { this.style = style; } public void setScript(String script) { this.script = script; } public Response getResponse() { return new Response(this.toString()); } @Override public String toString() { return TEMPLATE .replace("{$BODY}", this.body == null ? "" : this.body) .replace("{$TITLE}", this.title == null ? "" : this.title) .replace("{$STYLE}", this.style == null ? "" : STYLE.replace("{$STYLE}", this.style)) .replace("{$SCRIPT}", this.script == null ? "" : SCRIPT.replace("{$SCRIPT}", this.script)); } }