diff --git a/pom.xml b/pom.xml index c609d13..00e952a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.openautonomousconnection WebServer - 1.0.1-BETA.0.4 + 1.0.1-BETA.0.5 Open Autonomous Connection https://open-autonomous-connection.org/ diff --git a/src/main/java/org/openautonomousconnection/webserver/api/WebPage.java b/src/main/java/org/openautonomousconnection/webserver/api/WebPage.java index 1345555..e44994b 100644 --- a/src/main/java/org/openautonomousconnection/webserver/api/WebPage.java +++ b/src/main/java/org/openautonomousconnection/webserver/api/WebPage.java @@ -1,13 +1,50 @@ package org.openautonomousconnection.webserver.api; import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.html.HTMLBodyElement; +import org.w3c.dom.html.HTMLDocument; +import org.w3c.dom.html.HTMLHeadElement; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; /** * Server-side Java page (v1.0.1-BETA). * - *

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