diff --git a/src/main/java/org/openautonomousconnection/webserver/api/WebPage.java b/src/main/java/org/openautonomousconnection/webserver/api/WebPage.java index 361589a..b0df9d2 100644 --- a/src/main/java/org/openautonomousconnection/webserver/api/WebPage.java +++ b/src/main/java/org/openautonomousconnection/webserver/api/WebPage.java @@ -1,25 +1,59 @@ -# Open Autonomous Connection WebServer +package org.openautonomousconnection.webserver.api; -This is the WebServer for our Open Autonomous Connection project.
-Feel free to join our Discord. -
+import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket; +import org.openautonomousconnection.webserver.Main; +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; -## License Notice +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; -This project (OAC) is licensed under -the [Open Autonomous Public License (OAPL)](https://open-autonomous-connection.org/license.html). +/** + * Server-side Java page (v1.0.1-BETA). + * + *

Every .java page must extend this class.

+ */ +public abstract class WebPage { -**Third-party components:** -
-Download all license here: https://open-autonomous-connection.org/assets/licenses.zip -- *UnlegitLibrary* is authored by the same copyright holder and is used here under a special agreement: - While [UnlegitLibrary](https://repo.unlegitdqrk.dev/UnlegitDqrk/unlegitlibrary/) is generally distributed under - the [GNU GPLv3](https://repo.unlegitdqrk.dev/UnlegitDqrk/unlegitlibrary/src/branch/master/LICENSE), - it is additionally licensed under OAPL **exclusively for the OAC project**. - Therefore, within OAC, the OAPL terms apply to UnlegitLibrary as well. + private static final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); -# Bugs/Problems + private static final DocumentBuilder documentBuilder; -# In progress + static { + DocumentBuilder temp = null; + try { + temp = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + Main.getValues().logger.exception("Failed to create document builder", e); + temp = null; + } -# TODO \ No newline at end of file + documentBuilder = temp; + } + + protected final Document document; + protected final HTMLHeadElement head; + protected final HTMLBodyElement body; + + /** + * 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. + * + * @param ctx context (client, request, session) + * @return resource response packet + * @throws Exception on unexpected failures + */ + public abstract WebResourceResponsePacket handle(WebPageContext ctx) throws Exception; +} \ No newline at end of file