From 13bc2f6ae2379dd9f81edb4848971c8b4e91aabd Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 08:08:57 +0200 Subject: [PATCH] Turn the HTTP method into an enumeration. --- .../java/net/pterodactylus/sone/web/page/Page.java | 37 ++++++++++++++++++++-- .../pterodactylus/sone/web/page/PageToadlet.java | 5 +-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/page/Page.java b/src/main/java/net/pterodactylus/sone/web/page/Page.java index a1125cc..8f2a4d7 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/Page.java +++ b/src/main/java/net/pterodactylus/sone/web/page/Page.java @@ -58,11 +58,42 @@ public interface Page { */ public class Request { + /** + * Enumeration for all possible HTTP request methods. + * + * @author David ‘Bombe’ + * Roden + */ + public enum Method { + + /** GET. */ + GET, + + /** POST. */ + POST, + + /** PUT. */ + PUT, + + /** DELETE. */ + DELETE, + + /** HEAD. */ + HEAD, + + /** OPTIONS. */ + OPTIONS, + + /** TRACE. */ + TRACE, + + } + /** The URI that was accessed. */ private final URI uri; /** The HTTP method that was used. */ - private final String method; + private final Method method; /** The HTTP request. */ private final HTTPRequest httpRequest; @@ -82,7 +113,7 @@ public interface Page { * @param toadletContext * The toadlet context of the request */ - public Request(URI uri, String method, HTTPRequest httpRequest, ToadletContext toadletContext) { + public Request(URI uri, Method method, HTTPRequest httpRequest, ToadletContext toadletContext) { this.uri = uri; this.method = method; this.httpRequest = httpRequest; @@ -103,7 +134,7 @@ public interface Page { * * @return The HTTP method */ - public String getMethod() { + public Method getMethod() { return method; } diff --git a/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java b/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java index af826f1..57a3439 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java +++ b/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.net.URI; import java.util.Map.Entry; +import net.pterodactylus.sone.web.page.Page.Request.Method; import freenet.client.HighLevelSimpleClient; import freenet.clients.http.LinkEnabledCallback; import freenet.clients.http.Toadlet; @@ -99,7 +100,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback { * if the toadlet context is closed */ public void handleMethodGET(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException { - handleRequest(new Page.Request(uri, "GET", httpRequest, toadletContext)); + handleRequest(new Page.Request(uri, Method.GET, httpRequest, toadletContext)); } /** @@ -117,7 +118,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback { * if the toadlet context is closed */ public void handleMethodPOST(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException { - handleRequest(new Page.Request(uri, "POST", httpRequest, toadletContext)); + handleRequest(new Page.Request(uri, Method.POST, httpRequest, toadletContext)); } /** -- 2.7.4