summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.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/WOComponentRequestHandler.java
parentff072dfe782f6f22123cd4ba050828d35c0d0fbd (diff)
Formatting pass
Diffstat (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java')
-rw-r--r--projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java340
1 files changed, 148 insertions, 192 deletions
diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java
index 9f79987..9d35ab4 100644
--- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java
+++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java
@@ -18,212 +18,168 @@ License along with this library; if not, see http://www.gnu.org
package net.wotonomy.web;
-
/**
-* An implementation of WORequestHandler that dispatches Component actions.
-*
-* @author michael@mpowers.net
-* @author $Author: cgruber $
-* @version $Revision: 905 $
-*/
-public class WOComponentRequestHandler
- extends WORequestHandler
-{
- public WOResponse handleRequest( WORequest aRequest )
- {
- WOApplication application = aRequest.application();
- WOContext context = WOContext.contextWithRequest( aRequest );
- WOResponse response = null;
-
- // no concurrent access is allowed to a user's session:
- // a user/browser/machine with multiple requests will have to wait
- synchronized ( aRequest.request.getSession() )
- {
- try
- {
- application.awake();
-
- WOSession session = null;
- /*
- // the NeXT way
- String sessionID = aRequest.sessionID();
- if ( sessionID != null )
- {
- session = application.restoreSessionWithID( sessionID, context );
- if ( session == null )
- {
- response = application.handleSessionRestorationErrorInContext( context );
- }
- }
- else
- {
- session = application.createSessionForRequest( aRequest );
- if ( session == null )
- {
- response = application.handleSessionCreationErrorInContext( context );
- }
- else
- {
- session.setContext( context );
- }
- }
- */
- // the servlet way
- String sessionID = aRequest.sessionID();
- if ( sessionID != null )
- {
- session = application.restoreSessionWithID( sessionID, context );
- }
-
- if ( session == null )
- {
- session = application.createSessionForRequest( aRequest );
- if ( session == null )
- {
- response = application.handleSessionCreationErrorInContext( context );
- }
- else
- {
- session.setContext( context );
- }
- }
-
- context.setSession( session );
-
- session.awake();
-
- if ( response == null )
- {
-
- WOComponent page;
- String contextID = aRequest.contextID();
-
- if ( contextID != null )
- {
- page = session.restorePageForContextID( contextID );
- }
- else
- {
- page = application.pageWithName( aRequest.pageName(), context );
- }
-
- if ( page == null )
- {
- //FIXME: should we call this a restoration error, or do we
- // allow a bookmark with an expired context id to resume gracefully?
- page = application.pageWithName( aRequest.pageName(), context );
- //!response = application.handlePageRestorationErrorInContext( context );
- }
- //!else
- {
- context.pushElement( page ); //? needed?
- page.ensureAwakeInContext( context ); //? shouldn't this be in WOApplication?
-
- // only take values from request if there are values in the request
- System.out.println("should I takeValuesFromRequest ? " + ( aRequest.formValueKeys().count() > 0 ));
- if ( aRequest.formValueKeys().count() > 0 )
- {
- application.takeValuesFromRequest( aRequest, context );
- }
-
- // only invoke action if there is a sender id to invoke
- WOActionResults result;
- System.out.println("senderID: " + aRequest.senderID());
- if ( aRequest.senderID() != null )
- {
- result = application.invokeAction( aRequest, context );
- }
- else
- {
- result = null;
- }
-
- if ( result == null || result == page ) // same page is returned
- {
- result = page;
-
- // generate response
- response = new WOResponse();
- application.appendToResponse( response, context );
- page.sleep();
- }
- else // different page is returned
- if ( result instanceof WOComponent )
- {
- page.sleep();
- page = (WOComponent) result;
- page.ensureAwakeInContext( context );
- context.popElement(); // removes page
- context.pushElement( page );
-
- // generate response
- response = new WOResponse();
- application.appendToResponse( response, context );
- page.sleep();
- }
- else // WOResponse was returnd
- {
- response = (WOResponse) result;
- }
-
- context.popElement();
- session.sleep();
- session.savePage( page );
- session.setContext( null );
- application.saveSessionForContext( context );
- }
- }
- }
- catch ( Throwable t )
- {
- response = application.handleException( t, context );
- }
-
- application.sleep();
- }
- return response;
- }
+ * An implementation of WORequestHandler that dispatches Component actions.
+ *
+ * @author michael@mpowers.net
+ * @author $Author: cgruber $
+ * @version $Revision: 905 $
+ */
+public class WOComponentRequestHandler extends WORequestHandler {
+ public WOResponse handleRequest(WORequest aRequest) {
+ WOApplication application = aRequest.application();
+ WOContext context = WOContext.contextWithRequest(aRequest);
+ WOResponse response = null;
+
+ // no concurrent access is allowed to a user's session:
+ // a user/browser/machine with multiple requests will have to wait
+ synchronized (aRequest.request.getSession()) {
+ try {
+ application.awake();
+
+ WOSession session = null;
+ /*
+ * // the NeXT way String sessionID = aRequest.sessionID(); if ( sessionID !=
+ * null ) { session = application.restoreSessionWithID( sessionID, context ); if
+ * ( session == null ) { response =
+ * application.handleSessionRestorationErrorInContext( context ); } } else {
+ * session = application.createSessionForRequest( aRequest ); if ( session ==
+ * null ) { response = application.handleSessionCreationErrorInContext( context
+ * ); } else { session.setContext( context ); } }
+ */
+ // the servlet way
+ String sessionID = aRequest.sessionID();
+ if (sessionID != null) {
+ session = application.restoreSessionWithID(sessionID, context);
+ }
+
+ if (session == null) {
+ session = application.createSessionForRequest(aRequest);
+ if (session == null) {
+ response = application.handleSessionCreationErrorInContext(context);
+ } else {
+ session.setContext(context);
+ }
+ }
+
+ context.setSession(session);
+
+ session.awake();
+
+ if (response == null) {
+
+ WOComponent page;
+ String contextID = aRequest.contextID();
+
+ if (contextID != null) {
+ page = session.restorePageForContextID(contextID);
+ } else {
+ page = application.pageWithName(aRequest.pageName(), context);
+ }
+
+ if (page == null) {
+ // FIXME: should we call this a restoration error, or do we
+ // allow a bookmark with an expired context id to resume gracefully?
+ page = application.pageWithName(aRequest.pageName(), context);
+ // !response = application.handlePageRestorationErrorInContext( context );
+ }
+ // !else
+ {
+ context.pushElement(page); // ? needed?
+ page.ensureAwakeInContext(context); // ? shouldn't this be in WOApplication?
+
+ // only take values from request if there are values in the request
+ System.out
+ .println("should I takeValuesFromRequest ? " + (aRequest.formValueKeys().count() > 0));
+ if (aRequest.formValueKeys().count() > 0) {
+ application.takeValuesFromRequest(aRequest, context);
+ }
+
+ // only invoke action if there is a sender id to invoke
+ WOActionResults result;
+ System.out.println("senderID: " + aRequest.senderID());
+ if (aRequest.senderID() != null) {
+ result = application.invokeAction(aRequest, context);
+ } else {
+ result = null;
+ }
+
+ if (result == null || result == page) // same page is returned
+ {
+ result = page;
+
+ // generate response
+ response = new WOResponse();
+ application.appendToResponse(response, context);
+ page.sleep();
+ } else // different page is returned
+ if (result instanceof WOComponent) {
+ page.sleep();
+ page = (WOComponent) result;
+ page.ensureAwakeInContext(context);
+ context.popElement(); // removes page
+ context.pushElement(page);
+
+ // generate response
+ response = new WOResponse();
+ application.appendToResponse(response, context);
+ page.sleep();
+ } else // WOResponse was returnd
+ {
+ response = (WOResponse) result;
+ }
+
+ context.popElement();
+ session.sleep();
+ session.savePage(page);
+ session.setContext(null);
+ application.saveSessionForContext(context);
+ }
+ }
+ } catch (Throwable t) {
+ response = application.handleException(t, context);
+ }
+
+ application.sleep();
+ }
+ return response;
+ }
}
/*
- * $Log$
- * Revision 1.2 2006/02/19 01:44:02 cgruber
- * Add xmlrpc files
- * Remove jclark and replace with dom4j and javax.xml.sax stuff
- * Re-work dependencies and imports so it all compiles.
+ * $Log$ Revision 1.2 2006/02/19 01:44:02 cgruber Add xmlrpc files Remove jclark
+ * and replace with dom4j and javax.xml.sax stuff Re-work dependencies and
+ * imports so it all compiles.
*
- * Revision 1.1 2006/02/16 13:22:22 cgruber
- * Check in all sources in eclipse-friendly maven-enabled packages.
+ * Revision 1.1 2006/02/16 13:22:22 cgruber Check in all sources in
+ * eclipse-friendly maven-enabled packages.
*
- * Revision 1.8 2003/08/07 00:15:15 chochos
- * general cleanup (mostly removing unused imports)
+ * Revision 1.8 2003/08/07 00:15:15 chochos general cleanup (mostly removing
+ * unused imports)
*
- * Revision 1.7 2003/01/17 20:34:57 mpowers
- * Better handling for components and parents in the context's element stack.
+ * Revision 1.7 2003/01/17 20:34:57 mpowers Better handling for components and
+ * parents in the context's element stack.
*
- * Revision 1.6 2003/01/15 19:50:49 mpowers
- * Fixed issues with WOSession and Serializable.
- * Can now persist sessions between classloaders (hot swap of class impls).
+ * Revision 1.6 2003/01/15 19:50:49 mpowers Fixed issues with WOSession and
+ * Serializable. Can now persist sessions between classloaders (hot swap of
+ * class impls).
*
- * Revision 1.4 2003/01/14 15:51:09 mpowers
- * No longer calling takeValues or invokeAction if there are no request params
+ * Revision 1.4 2003/01/14 15:51:09 mpowers No longer calling takeValues or
+ * invokeAction if there are no request params
*
- * Revision 1.3 2003/01/13 22:24:34 mpowers
- * Request-response cycle is working with session and page persistence.
+ * Revision 1.3 2003/01/13 22:24:34 mpowers Request-response cycle is working
+ * with session and page persistence.
*
- * Revision 1.1 2003/01/09 16:13:59 mpowers
- * Implemented WOComponentRequestHandler:
- * Bringing the request-response cycle more into conformance.
+ * Revision 1.1 2003/01/09 16:13:59 mpowers Implemented
+ * WOComponentRequestHandler: Bringing the request-response cycle more into
+ * conformance.
*
- * Revision 1.2 2002/12/17 14:57:44 mpowers
- * Minor corrections to WORequests's parsing, and updated javadocs.
+ * Revision 1.2 2002/12/17 14:57:44 mpowers Minor corrections to WORequests's
+ * parsing, and updated javadocs.
*
- * Revision 1.1.1.1 2000/12/21 15:53:19 mpowers
- * Contributing wotonomy.
+ * Revision 1.1.1.1 2000/12/21 15:53:19 mpowers Contributing wotonomy.
*
- * Revision 1.2 2000/12/20 16:25:50 michael
- * Added log to all files.
+ * Revision 1.2 2000/12/20 16:25:50 michael Added log to all files.
*
*
*/
-