From 02bc52037e9ccccca672d6156d9c325c74fe28b3 Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Mon, 1 Jul 2024 17:27:48 -0400 Subject: Update a whole bunch of things Yeah... not a great commit message. t.b.h, I could maybe've split the commit into more parts; but that would be quite a lot off effort and would have a pretty decent chance of at least one of the commits leaving the repository in a non-working state. For the future, will want to try and commit more often so there aren't these mega-commits where it's just "a whole bunch of stuff changed" --- .../src/main/java/net/wotonomy/web/WORequest.java | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WORequest.java') diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WORequest.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WORequest.java index 5664e59..3991b34 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WORequest.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WORequest.java @@ -20,6 +20,7 @@ package net.wotonomy.web; import java.io.InputStream; import java.util.Enumeration; +import java.util.Locale; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; @@ -43,7 +44,7 @@ import net.wotonomy.foundation.NSMutableDictionary; public class WORequest extends WOResponse { HttpServletRequest request; private WOApplication application; - private NSArray languages; + private NSArray languages; private String requestHandlerKey; private String requestHandlerPath; private String pageName; @@ -61,11 +62,11 @@ public class WORequest extends WOResponse { /** * Standard constructor. Method and URL are required. HeaderMap is a map of * header names to arrays containing one or more values. Data is the content of - * the request. UserInfo contains application-defined paramters that get passed + * the request. UserInfo contains application-defined parameters that get passed * to all objects involved in dispatching the request. */ - public WORequest(String aMethod, String aURL, String aProtocolName, NSDictionary headerMap, NSData aData, - NSDictionary userInfo) { + public WORequest(String aMethod, String aURL, String aProtocolName, NSDictionary> headerMap, NSData aData, + NSDictionary userInfo) { throw new RuntimeException("This constructor is not yet supported."); } @@ -97,7 +98,7 @@ public class WORequest extends WOResponse { requestHandlerPath = requestHandlerPath.substring(i); } - Enumeration e = requestHandlerPathArray().objectEnumerator(); + Enumeration e = requestHandlerPathArray().objectEnumerator(); // skipping session ID for now if (e.hasMoreElements()) { pageName = e.nextElement().toString(); @@ -131,6 +132,7 @@ public class WORequest extends WOResponse { * Returns the name of the protocol (presumably HTTP) and the version used by * the client as sent in the request headers. */ + @Override public String httpVersion() { return request.getProtocol(); } @@ -138,7 +140,8 @@ public class WORequest extends WOResponse { /** * Returns an array of the header names in this request in no particular order. */ - public NSArray headerKeys() { + @Override + public NSArray headerKeys() { return arrayFromEnumeration(request.getHeaderNames()); } @@ -146,7 +149,8 @@ public class WORequest extends WOResponse { * Returns an array of the header values for the specified key in no particular * order. */ - public NSArray headersForKey(String aString) { + @Override + public NSArray headersForKey(String aString) { return arrayFromEnumeration(request.getHeaders(aString)); } @@ -154,6 +158,7 @@ public class WORequest extends WOResponse { * Returns one value for the specified header key. Provided as a convenience * since most headers have only one value. Returns null if not found. */ + @Override public String headerForKey(String aKey) { return request.getHeader(aKey); } @@ -163,6 +168,7 @@ public class WORequest extends WOResponse { * content is determined by the "content-type" header. On error, null is * returned. */ + @Override public NSData content() { // TODO: This is broken! NSMutableData data = new NSMutableData(); @@ -186,11 +192,12 @@ public class WORequest extends WOResponse { * Returns the application-specific userInfo dictionary. This implementation * returns the servlet attribute map. */ + @Override public NSDictionary userInfo() { // TODO: Test this logic. Object key, value; - NSMutableDictionary info = new NSMutableDictionary(); - java.util.Enumeration e = request.getAttributeNames(); + NSMutableDictionary info = new NSMutableDictionary<>(); + java.util.Enumeration e = request.getAttributeNames(); while (e.hasMoreElements()) { key = e.nextElement(); value = request.getAttribute(e.nextElement().toString()); @@ -205,7 +212,7 @@ public class WORequest extends WOResponse { * Returns the items in the request handler path parsed by the "/" delimiter and * put into an array. */ - public NSArray requestHandlerPathArray() { + public NSArray requestHandlerPathArray() { return NSArray.componentsSeparatedByString(requestHandlerPath(), "/"); } @@ -214,7 +221,7 @@ public class WORequest extends WOResponse { * The strings are returned in java Locale format, meaning dashes (-) are * converted to underbars (_): see java.util.Locale.toString(). */ - public NSArray browserLanguages() { + public NSArray browserLanguages() { if (languages == null) { languages = arrayFromEnumeration(request.getLocales()); } @@ -284,15 +291,15 @@ public class WORequest extends WOResponse { /** * Returns an array containing all the form keys in the request. */ - public NSArray formValueKeys() { + public NSArray formValueKeys() { return arrayFromEnumeration(request.getParameterNames()); } /** * Returns an array of the values for the specified key in no particular order. */ - public NSArray formValuesForKey(String aKey) { - NSMutableArray result = new NSMutableArray(); + public NSArray formValuesForKey(String aKey) { + NSMutableArray result = new NSMutableArray<>(); String[] values = request.getParameterValues(aKey); if (values != null) { for (int i = 0; i < values.length; i++) { @@ -500,8 +507,8 @@ public class WORequest extends WOResponse { /** * Convenience method to populate an NSArray from an Enumeration. */ - private static NSArray arrayFromEnumeration(java.util.Enumeration e) { - NSMutableArray result = new NSMutableArray(); + private static NSArray arrayFromEnumeration(java.util.Enumeration e) { + NSMutableArray result = new NSMutableArray<>(); while (e.hasMoreElements()) { result.addObject(e.nextElement()); } -- cgit v1.2.3