summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2024-05-20 17:58:16 -0400
committerBenjamin Culkin <scorpress@gmail.com>2024-05-20 17:58:16 -0400
commit40a9d99496e098562f090fb7ffce9e749011b131 (patch)
tree437df24d65470582e943e494a52db8ed65a881ae /projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java
parentff072dfe782f6f22123cd4ba050828d35c0d0fbd (diff)
Formatting pass
Diffstat (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java')
-rw-r--r--projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java235
1 files changed, 104 insertions, 131 deletions
diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java
index d9fbade..6362a03 100644
--- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java
+++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java
@@ -25,160 +25,133 @@ import java.util.TimeZone;
import net.wotonomy.foundation.NSArray;
/**
-* A pure java implementation of WOResponse.
-*
-* @author michael@mpowers.net
-* @author $Author: cgruber $
-* @version $Revision: 905 $
-*/
-public class WOResponse extends WOMessage
- implements WOActionResults
-{
+ * A pure java implementation of WOResponse.
+ *
+ * @author michael@mpowers.net
+ * @author $Author: cgruber $
+ * @version $Revision: 905 $
+ */
+public class WOResponse extends WOMessage implements WOActionResults {
protected static String defaultEncoding;
- private static SimpleDateFormat htmlDateFormat;
- static
- {
- defaultEncoding = "ISO8859_1";
- htmlDateFormat = new SimpleDateFormat(
- "EEE, dd MMM yyyy HH:mm:ss z" );
- htmlDateFormat.setTimeZone(
- TimeZone.getTimeZone( "GMT" ) );
- }
+ private static SimpleDateFormat htmlDateFormat;
+ static {
+ defaultEncoding = "ISO8859_1";
+ htmlDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
+ htmlDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ }
private int status;
/**
- * Parameterless constructor which should not be called.
- */
- public WOResponse ()
- {
+ * Parameterless constructor which should not be called.
+ */
+ public WOResponse() {
status = -1; // -1 indicates not yet set
- }
+ }
+
+ /**
+ * Sets the status code of the response. You should use the constants defined in
+ * HttpServletResponse.
+ */
+ public void setStatus(int code) {
+ status = code;
+ }
/**
- * Sets the status code of the response.
- * You should use the constants defined in HttpServletResponse.
- */
- public void setStatus (int code)
- {
- status = code;
- }
+ * Gets the current status code for the response.
+ */
+ public int status() {
+ return status;
+ }
/**
- * Gets the current status code for the response.
- */
- public int status ()
- {
- return status;
- }
+ * Sets a header in the response to disable client caching. (Whether this works
+ * depends on the client implementation.)
+ */
+ public void disableClientCaching() {
+ String dateString = htmlDateFormat.format(new Date());
+ setHeader(dateString, "Date");
+ setHeader(dateString, "Expires");
+ setHeader("no-cache", "Pragma");
+ setHeaders(new NSArray(new Object[] { "private", "no-cache", "max-age = 0" }), "Cache-Control");
+ // System.out.println( "disableClientCaching: " + dateString );
+ }
/**
- * Sets a header in the response to disable client caching.
- * (Whether this works depends on the client implementation.)
- */
- public void disableClientCaching ()
- {
- String dateString = htmlDateFormat.format( new Date() );
- setHeader( dateString, "Date" );
- setHeader( dateString, "Expires" );
- setHeader( "no-cache", "Pragma" );
- setHeaders( new NSArray( new Object[] {
- "private", "no-cache", "max-age = 0" } ), "Cache-Control" );
- //System.out.println( "disableClientCaching: " + dateString );
- }
-
- /**
- * Returns this object. (Implements the WOActionResults interface.)
- */
- public WOResponse generateResponse()
- {
- return this;
- }
+ * Returns this object. (Implements the WOActionResults interface.)
+ */
+ public WOResponse generateResponse() {
+ return this;
+ }
/**
- * Generates the response using the specified servlet response,
- * but does not flush the buffer. The caller is responsible
- * for sending the response to the client. <br><br>
- * Note that this method is currently responsible for setting
- * the content type to "text/html". As far as I can tell, WORequests
- * have no way to set the content type and therefore must always
- * be of type "text/html".
- */
- void generateServletResponse
- (javax.servlet.http.HttpServletResponse response)
- {
- if ( WOApplication.application().isPageRefreshOnBacktrackEnabled() )
- {
- disableClientCaching();
- }
-
- String key;
- java.util.Enumeration e, f;
-
- // set content type: might be overwritten by headers below
- response.setContentType( "text/html" );
-
- // set status
- if ( status != -1 )
- {
- response.setStatus( status );
+ * Generates the response using the specified servlet response, but does not
+ * flush the buffer. The caller is responsible for sending the response to the
+ * client. <br>
+ * <br>
+ * Note that this method is currently responsible for setting the content type
+ * to "text/html". As far as I can tell, WORequests have no way to set the
+ * content type and therefore must always be of type "text/html".
+ */
+ void generateServletResponse(javax.servlet.http.HttpServletResponse response) {
+ if (WOApplication.application().isPageRefreshOnBacktrackEnabled()) {
+ disableClientCaching();
+ }
+
+ String key;
+ java.util.Enumeration e, f;
+
+ // set content type: might be overwritten by headers below
+ response.setContentType("text/html");
+
+ // set status
+ if (status != -1) {
+ response.setStatus(status);
}
- // set headers
- f = _headers.allKeys().objectEnumerator();
- while ( f.hasMoreElements() )
- {
- key = f.nextElement().toString();
- e = ((NSArray)_headers.objectForKey( key )).objectEnumerator();
- if ( e.hasMoreElements() )
- {
- // overwrite existing header
- response.setHeader( key, e.nextElement().toString() );
- }
- while ( e.hasMoreElements() )
- {
- response.addHeader( key, e.nextElement().toString() );
- }
+ // set headers
+ f = _headers.allKeys().objectEnumerator();
+ while (f.hasMoreElements()) {
+ key = f.nextElement().toString();
+ e = ((NSArray) _headers.objectForKey(key)).objectEnumerator();
+ if (e.hasMoreElements()) {
+ // overwrite existing header
+ response.setHeader(key, e.nextElement().toString());
+ }
+ while (e.hasMoreElements()) {
+ response.addHeader(key, e.nextElement().toString());
+ }
}
- // set cookies
- e = _cookies.allValues().objectEnumerator();
- while ( e.hasMoreElements() )
- {
- response.addCookie( (WOCookie) e.nextElement() );
- }
-
- try
- {
- // write content
- response.getOutputStream().write(_contentData.bytes() );
- if ( status > 299 )
- {
- response.sendError( status );
- }
- }
- catch ( Exception exc )
- {
- throw new RuntimeException(
- "Error writing response: " + exc );
+ // set cookies
+ e = _cookies.allValues().objectEnumerator();
+ while (e.hasMoreElements()) {
+ response.addCookie((WOCookie) e.nextElement());
}
- }
+ try {
+ // write content
+ response.getOutputStream().write(_contentData.bytes());
+ if (status > 299) {
+ response.sendError(status);
+ }
+ } catch (Exception exc) {
+ throw new RuntimeException("Error writing response: " + exc);
+ }
+ }
/**
- * Returns the current default encoding seting.
- */
- public static String defaultEncoding ()
- {
- return defaultEncoding;
- }
+ * Returns the current default encoding seting.
+ */
+ public static String defaultEncoding() {
+ return defaultEncoding;
+ }
/**
- * Sets the default encoding setting.
- */
- public static void setDefaultEncoding (String encoding)
- {
- defaultEncoding = encoding;
- }
+ * Sets the default encoding setting.
+ */
+ public static void setDefaultEncoding(String encoding) {
+ defaultEncoding = encoding;
+ }
}