2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.httpd;
|
2013-08-27 01:48:04 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;
|
2013-08-27 01:48:04 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public class HTTPDPageBuilder
|
2013-08-27 01:48:04 +00:00
|
|
|
{
|
2015-02-16 16:00:38 +00:00
|
|
|
private static final String TEMPLATE = "<!DOCTYPE html>\r\n"
|
2013-08-27 17:49:45 +00:00
|
|
|
+ "<html>\r\n"
|
|
|
|
+ "<head>\r\n"
|
|
|
|
+ "<title>{$TITLE}</title>\r\n"
|
|
|
|
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n"
|
2013-09-03 20:35:11 +00:00
|
|
|
+ "{$STYLE}"
|
|
|
|
+ "{$SCRIPT}"
|
2013-08-27 17:49:45 +00:00
|
|
|
+ "</head>\r\n"
|
2013-09-03 20:35:11 +00:00
|
|
|
+ "<body>\r\n{$BODY}</body>\r\n"
|
2013-08-27 17:49:45 +00:00
|
|
|
+ "</html>\r\n";
|
2013-09-03 20:35:11 +00:00
|
|
|
private static final String STYLE = "<style type=\"text/css\">{$STYLE}</style>\r\n";
|
2015-02-16 16:00:38 +00:00
|
|
|
private static final String SCRIPT = "<script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js\"></script>\r\n"
|
2013-09-03 20:35:11 +00:00
|
|
|
+ "<script src=\"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js\"></script>\r\n"
|
|
|
|
+ "<script>\r\n{$SCRIPT}\r\n</script>\r\n";
|
2013-08-27 01:48:04 +00:00
|
|
|
//
|
2013-09-03 20:35:11 +00:00
|
|
|
private String body = null;
|
|
|
|
private String title = null;
|
|
|
|
private String style = null;
|
|
|
|
private String script = null;
|
2013-08-27 01:48:04 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public HTTPDPageBuilder()
|
2013-08-27 01:48:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public HTTPDPageBuilder(String body, String title, String style, String script)
|
2013-08-27 01:48:04 +00:00
|
|
|
{
|
|
|
|
this.body = body;
|
|
|
|
this.title = title;
|
2013-08-27 17:49:45 +00:00
|
|
|
this.style = style;
|
2013-09-03 20:35:11 +00:00
|
|
|
this.script = script;
|
2013-08-27 01:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setBody(String body)
|
|
|
|
{
|
|
|
|
this.body = body;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTitle(String title)
|
|
|
|
{
|
|
|
|
this.title = title;
|
|
|
|
}
|
|
|
|
|
2013-08-27 17:49:45 +00:00
|
|
|
public void setStyle(String style)
|
|
|
|
{
|
|
|
|
this.style = style;
|
|
|
|
}
|
|
|
|
|
2013-09-03 20:35:11 +00:00
|
|
|
public void setScript(String script)
|
|
|
|
{
|
|
|
|
this.script = script;
|
|
|
|
}
|
|
|
|
|
2013-08-27 01:48:04 +00:00
|
|
|
public Response getResponse()
|
|
|
|
{
|
2013-08-27 17:49:45 +00:00
|
|
|
return new Response(this.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString()
|
|
|
|
{
|
2013-09-03 20:35:11 +00:00
|
|
|
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));
|
2013-08-27 01:48:04 +00:00
|
|
|
}
|
|
|
|
}
|