Every .java page must implement this interface.
+ *Every .java page must extend this class.
*/ -public interface WebPage { +public abstract class WebPage { + + private static final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + private static final DocumentBuilder documentBuilder; + + static { + try { + documentBuilder = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } + } + + protected Document document; + + protected HTMLBodyElement body; + + protected HTMLHeadElement head; + /** + * Default constructor that creates a new Document instance + */ + public WebPage() { + this.document = documentBuilder.newDocument(); + + this.head = (HTMLHeadElement) this.document.createElement("head"); + + this.body = (HTMLBodyElement) this.document.createElement("body"); + } /** * Handles a web request. @@ -16,5 +53,5 @@ public interface WebPage { * @return resource response packet * @throws Exception on unexpected failures */ - WebResourceResponsePacket handle(WebPageContext ctx) throws Exception; + public abstract WebResourceResponsePacket handle(WebPageContext ctx) throws Exception; } \ No newline at end of file