Author: mrdon
Date: Sat Aug 13 20:38:09 2005
New Revision: 232573

URL: http://svn.apache.org/viewcvs?rev=232573&view=rev
Log:
 * Adding a chain that manipulates or even creates new context's to use for the 
main request 
   processing chain, create-context
 * Adding the validator context to the ognl stack
 * Adding a command that wraps the servlet request with one that, if an object 
isn't found in 
   the request attribute, looks it up in the stack


Added:
    
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/MakeContextStackAware.java
    
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/StackAwareRequest.java
Modified:
    
struts/sandbox/trunk/ti/src/java/org/apache/ti/interceptor/ControllerValidationInterceptor.java
    
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java
    
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml

Modified: 
struts/sandbox/trunk/ti/src/java/org/apache/ti/interceptor/ControllerValidationInterceptor.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/interceptor/ControllerValidationInterceptor.java?rev=232573&r1=232572&r2=232573&view=diff
==============================================================================
--- 
struts/sandbox/trunk/ti/src/java/org/apache/ti/interceptor/ControllerValidationInterceptor.java
 (original)
+++ 
struts/sandbox/trunk/ti/src/java/org/apache/ti/interceptor/ControllerValidationInterceptor.java
 Sat Aug 13 20:38:09 2005
@@ -4,6 +4,7 @@
  */
 package org.apache.ti.interceptor;
 
+import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.interceptor.AroundInterceptor;
 import com.opensymphony.xwork.validator.*;
@@ -44,6 +45,10 @@
         Object action = inv.getAction();
         
         ValidatorContext val = 
ControllerContext.getContext().getValidatorContext();
+        
+        // Add to the value stack
+        ActionContext.getContext().getValueStack().push(val);
+
         String context = invocation.getProxy().getActionName();
         if (log.isDebugEnabled()) {
             log.debug("Validating "

Modified: 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java?rev=232573&r1=232572&r2=232573&view=diff
==============================================================================
--- 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java
 (original)
+++ 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java
 Sat Aug 13 20:38:09 2005
@@ -42,6 +42,8 @@
  */
 public class ChainRequestProcessor implements RequestProcessor {
 
+    public static final String WEB_CONTEXT = "webContext";
+
     /**
      * <p>Comma-separated list of context or classloader-relative path(s) that
      * contain the configuration for the default commons-chain catalog(s).</p>
@@ -72,8 +74,11 @@
      */
     protected Command startCmd = null;
 
+    protected Command ctxCmd = null;
+
     protected String catalogName = "struts-ti";
     protected String startCmdName = "start";
+    protected String ctxCmdName = "create-context";
     protected String initCmdName = "init";
 
     protected SourceResolver resolver = null;
@@ -90,6 +95,10 @@
         this.startCmdName = name;
     }
 
+    public void setCreateContextCommandName(String name) {
+        this.ctxCmdName = name;
+    }    
+
     public void setInitCommandName(String name) {
         this.initCmdName = name;
     }
@@ -135,6 +144,12 @@
                         + startCmdName + "'");
             }
 
+            ctxCmd = catalog.getCommand(ctxCmdName);
+            if (ctxCmd == null) {
+                log.debug("Cannot find '" + ctxCmdName + "', skipping "
+                        + "context creation step");
+            }
+
         } catch (Throwable t) {
 
             // The follow error message is not retrieved from internal message
@@ -158,6 +173,15 @@
 
             // Add initialization parameters directly to context.
             ctx.putAll(initParameters);
+
+            // Allow the chain to replace the context if needed
+            if (ctxCmd != null) {
+                log.debug("Executing create context chain");
+                ctx.put(WEB_CONTEXT, ctx);
+                ctxCmd.execute(ctx);
+                ctx = (WebContext)ctx.get(WEB_CONTEXT);
+            }    
+            
             startCmd.execute(ctx);
         } catch (Exception e) {
             // Execute the exception processing chain??

Modified: 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml?rev=232573&r1=232572&r2=232573&view=diff
==============================================================================
--- 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml
 (original)
+++ 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml
 Sat Aug 13 20:38:09 2005
@@ -54,6 +54,10 @@
       <command name="initXWork" />
       <command name="initWebWork" />
     </chain>
+ 
+    <chain     name="create-context" >
+      <command name="makeContextStackAware" 
className="org.apache.ti.processor.chain.servlet.MakeContextStackAware" />
+    </chain>
     
     <chain     name="process-action" 
className="org.apache.ti.processor.chain.ProcessActionChain">
       

Added: 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/MakeContextStackAware.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/MakeContextStackAware.java?rev=232573&view=auto
==============================================================================
--- 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/MakeContextStackAware.java
 (added)
+++ 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/MakeContextStackAware.java
 Sat Aug 13 20:38:09 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ti.processor.chain.servlet;
+
+
+import org.apache.ti.processor.chain.ChainRequestProcessor;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.web.WebContext;
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+
+import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+import javax.servlet.http.*;
+import javax.servlet.*;
+
+
+/**
+ * <p>Select the <code>Locale</code> to be used for this request.</p>
+ *
+ * @version $Rev: 169091 $ $Date: 2005-05-07 09:11:38 -0700 (Sat, 07 May 2005) 
$
+ */
+
+public class MakeContextStackAware implements Command {
+
+
+    private static final Log log = 
LogFactory.getLog(MakeContextStackAware.class);
+
+
+    public boolean execute(Context oldCtx) {
+        log.debug("Wrapping context with stack aware wrapper");
+        ServletWebContext ctx = (ServletWebContext) 
oldCtx.get(ChainRequestProcessor.WEB_CONTEXT);        
+        
+        HttpServletRequest req = new StackAwareRequest(ctx.getRequest());
+        ctx.initialize(ctx.getContext(), req, ctx.getResponse());
+        oldCtx.put(ChainRequestProcessor.WEB_CONTEXT, ctx);
+        
+        
+        return false;
+    }
+}
+

Added: 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/StackAwareRequest.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/StackAwareRequest.java?rev=232573&view=auto
==============================================================================
--- 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/StackAwareRequest.java
 (added)
+++ 
struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/servlet/StackAwareRequest.java
 Sat Aug 13 20:38:09 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ti.processor.chain.servlet;
+
+
+import org.apache.ti.processor.chain.ChainRequestProcessor;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.web.WebContext;
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+
+import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+import javax.servlet.http.*;
+import javax.servlet.*;
+
+
+/**
+ * <p>Select the <code>Locale</code> to be used for this request.</p>
+ *
+ * @version $Rev: 169091 $ $Date: 2005-05-07 09:11:38 -0700 (Sat, 07 May 2005) 
$
+ */
+
+public class StackAwareRequest extends HttpServletRequestWrapper {
+
+
+    private static final Log log = LogFactory.getLog(StackAwareRequest.class);
+
+    private ServletRequest wrappedRequest;
+
+    public StackAwareRequest(HttpServletRequest request) {
+        super(request);
+        wrappedRequest = request;
+    }
+
+    public Object getAttribute(String s) {
+        Object attribute = super.getAttribute(s);
+        if (attribute == null) {
+            // If not found, then try the ValueStack
+            OgnlValueStack stack = ActionContext.getContext().getValueStack();
+            if (stack != null) {
+                attribute = stack.findValue(s);
+            }
+        }
+        return attribute;
+    }
+}
+



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to