Author: mrdon
Date: Tue Dec 13 11:45:48 2005
New Revision: 356591

URL: http://svn.apache.org/viewcvs?rev=356591&view=rev
Log:
Adding new interceptors to call reset() and validate() on the ActionForm, 
adding a new
StrutsFactory to provide conversion functions between Struts Action 1.x and Ti, 
added
class-level Javadocs, added rife as build dependency (temporary until XWork 
fixed)


Added:
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormResetInterceptor.java
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormValidationInterceptor.java
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java
Modified:
    struts/sandbox/trunk/ti/phase1/jars/legacy/project.properties
    struts/sandbox/trunk/ti/phase1/jars/legacy/project.xml
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/DynaBeanPropertyAccessor.java
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDriven.java
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDrivenInterceptor.java
    
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestScopedModelDrivenInterceptor.java

Modified: struts/sandbox/trunk/ti/phase1/jars/legacy/project.properties
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/project.properties?rev=356591&r1=356590&r2=356591&view=diff
==============================================================================
--- struts/sandbox/trunk/ti/phase1/jars/legacy/project.properties (original)
+++ struts/sandbox/trunk/ti/phase1/jars/legacy/project.properties Tue Dec 13 
11:45:48 2005
@@ -1,2 +1,5 @@
 maven.compile.source=1.4
 maven.compile.target=1.4
+
+
+maven.repo.remote=http://www.ibiblio.org/maven/,http://cvs.apache.org/repository/,http://www.twdata.org/repository/

Modified: struts/sandbox/trunk/ti/phase1/jars/legacy/project.xml
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/project.xml?rev=356591&r1=356590&r2=356591&view=diff
==============================================================================
--- struts/sandbox/trunk/ti/phase1/jars/legacy/project.xml (original)
+++ struts/sandbox/trunk/ti/phase1/jars/legacy/project.xml Tue Dec 13 11:45:48 
2005
@@ -25,4 +25,22 @@
   <artifactId>struts-ti-core</artifactId>
   <name>Struts Ti Core</name>
 
+  <dependencies>
+
+       <!-- Standard dependencies -->  
+    <dependency>
+      <groupId>struts</groupId>
+      <artifactId>struts</artifactId>
+      <version>1.2.8</version>
+      <url>http://struts.apache.org/</url>
+    </dependency>
+ 
+    <dependency>
+      <groupId>rife</groupId>
+      <artifactId>rife-continuations</artifactId>
+      <version>1.2</version>
+      <url>http://rifers.org/</url>
+    </dependency>
+  </dependencies>
+
 </project>

Added: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormResetInterceptor.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormResetInterceptor.java?rev=356591&view=auto
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormResetInterceptor.java
 (added)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormResetInterceptor.java
 Tue Dec 13 11:45:48 2005
@@ -0,0 +1,51 @@
+/*
+ * $Id: Action.java 240373 2005-08-27 01:58:39Z jmitchell $
+ *
+ * Copyright 2000-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.legacy;
+
+import com.opensymphony.xwork.interceptor.ModelDrivenInterceptor;
+import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.interceptor.AroundInterceptor;
+import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.webwork.ServletActionContext;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMapping;
+
+/**
+ *  Calls the reset() method on the ActionForm, if it exists.
+ */
+public class ActionFormResetInterceptor extends AroundInterceptor {
+
+    protected void after(ActionInvocation dispatcher, String result) throws 
Exception {
+    }
+
+    protected void before(ActionInvocation invocation) throws Exception {
+        Object action = invocation.getAction();
+
+        if (action instanceof ScopedModelDriven) {
+            ScopedModelDriven modelDriven = (ScopedModelDriven) action;
+            Object model = modelDriven.getModel();
+            if (model != null) {
+                ActionMapping mapping = 
StrutsFactory.getStrutsFactory().createActionMapping(invocation.getProxy().getConfig());
+                HttpServletRequest req = ServletActionContext.getRequest();
+                ((ActionForm)model).reset(mapping, req);
+            }
+        }
+    }
+}

Added: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormValidationInterceptor.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormValidationInterceptor.java?rev=356591&view=auto
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormValidationInterceptor.java
 (added)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ActionFormValidationInterceptor.java
 Tue Dec 13 11:45:48 2005
@@ -0,0 +1,55 @@
+/*
+ * $Id: Action.java 240373 2005-08-27 01:58:39Z jmitchell $
+ *
+ * Copyright 2000-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.legacy;
+
+import com.opensymphony.xwork.interceptor.ModelDrivenInterceptor;
+import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.interceptor.AroundInterceptor;
+import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.webwork.ServletActionContext;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionError;
+
+/**
+ *  Calls the validate() method on the ActionForm, if it exists.  The errors 
are handled
+ *  like regular XWork validation errors.
+ */
+public class ActionFormValidationInterceptor extends AroundInterceptor {
+
+    protected void after(ActionInvocation dispatcher, String result) throws 
Exception {
+    }
+
+    protected void before(ActionInvocation invocation) throws Exception {
+        Object action = invocation.getAction();
+
+        if (action instanceof ScopedModelDriven) {
+            ScopedModelDriven modelDriven = (ScopedModelDriven) action;
+            Object model = modelDriven.getModel();
+            if (model != null) {
+                ActionMapping mapping = 
StrutsFactory.getStrutsFactory().createActionMapping(invocation.getProxy().getConfig());
+                HttpServletRequest req = ServletActionContext.getRequest();
+                ActionErrors errors = ((ActionForm)model).validate(mapping, 
req);
+                StrutsFactory.getStrutsFactory().convertErrors(errors, 
action);                
+            }
+        }
+    }
+}

Modified: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/DynaBeanPropertyAccessor.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/DynaBeanPropertyAccessor.java?rev=356591&r1=356590&r2=356591&view=diff
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/DynaBeanPropertyAccessor.java
 (original)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/DynaBeanPropertyAccessor.java
 Tue Dec 13 11:45:48 2005
@@ -15,6 +15,7 @@
  * limitations under the License.
  *
  */
+
 package org.apache.ti.legacy;
 
 import java.io.Serializable;
@@ -25,8 +26,7 @@
 import java.util.Map;
 
 /**
- * 
- * @todo Finish documenting me!
+ * Provides access to DynaBean properties in OGNL
  */
 public class DynaBeanPropertyAccessor implements PropertyAccessor {
 

Modified: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDriven.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDriven.java?rev=356591&r1=356590&r2=356591&view=diff
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDriven.java
 (original)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDriven.java
 Tue Dec 13 11:45:48 2005
@@ -1,22 +1,32 @@
 /*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
+ * $Id$
+ * Copyright 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.legacy;
 
 import com.opensymphony.xwork.ModelDriven;
 
 /**
- * ModelDriven Actions provide a model object to be pushed onto the ValueStack
- * in addition to the Action itself, allowing a FormBean type approach like 
Struts.
- *
- * @author Jason Carreira
- *         Created Apr 8, 2003 6:22:42 PM
+ * Adds the ability to set a model, probably retrieved from a given state.
  */
 public interface ScopedModelDriven extends ModelDriven {
 
     /**
-     * @return the model to be pushed onto the ValueStack instead of the 
Action itself
+     * Sets the model
      */
     void setModel(Object model);
 }

Modified: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDrivenInterceptor.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDrivenInterceptor.java?rev=356591&r1=356590&r2=356591&view=diff
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDrivenInterceptor.java
 (original)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/ScopedModelDrivenInterceptor.java
 Tue Dec 13 11:45:48 2005
@@ -1,7 +1,21 @@
 /*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
+ * $Id$
+ * Copyright 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.legacy;
 
 import com.opensymphony.xwork.interceptor.ModelDrivenInterceptor;
@@ -13,6 +27,10 @@
 
 import java.util.Map;
 
+/**
+ *  Retrieves the model class from the configured scope, then provides it 
+ *  to the Action.
+ */
 public class ScopedModelDrivenInterceptor extends ModelDrivenInterceptor {
 
     protected void after(ActionInvocation dispatcher, String result) throws 
Exception {

Added: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java?rev=356591&view=auto
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java
 (added)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java
 Tue Dec 13 11:45:48 2005
@@ -0,0 +1,94 @@
+/*
+ * $Id$
+ * Copyright 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.legacy;
+
+import com.opensymphony.xwork.*;
+import com.opensymphony.xwork.config.entities.ActionConfig;
+import org.apache.struts.action.*;
+import org.apache.struts.config.*;
+import java.util.*;
+
+
+/**
+ *  Provides conversion methods between the Struts Action 1.x and XWork
+ *  classes.
+ */
+public class StrutsFactory {
+    private static StrutsFactory FACTORY = new StrutsFactory();
+
+    protected StrutsFactory() {
+    }
+
+    public static void setStrutsFactory(StrutsFactory factory) {
+        FACTORY = factory;
+    }
+
+    public static StrutsFactory getStrutsFactory() {
+        return FACTORY;
+    }
+
+    public ModuleConfig createModuleConfig() {
+        return null;
+    }
+
+    public ActionMapping createActionMapping(ActionConfig cfg) {
+        return null;
+    }
+
+    public void convertErrors(ActionErrors errors, Object action) {
+        ValidationAware vaction = null;
+        TextProvider text = null;
+        
+        if (action instanceof ValidationAware) {
+            vaction = (ValidationAware)action;
+        }
+        if (action instanceof TextProvider) {
+            text = (TextProvider)action;
+        }
+
+        ActionMessage error = null;
+        String field = null;
+        String msg = null;
+        Object[] values = null;
+        for (Iterator i = errors.properties(); i.hasNext(); ) {
+            field = (String) i.next();
+            for (Iterator it = errors.get(field); it.hasNext(); ) {
+                error = (ActionMessage) it.next();
+                msg = error.getKey();
+                if (error.isResource() && text != null) {
+                    values = error.getValues();
+                    if (values != null) {
+                        msg = text.getText(error.getKey(), 
Arrays.asList(values));
+                    } else {
+                        msg = text.getText(error.getKey());
+                    }    
+                } 
+                if (vaction != null) {
+                    if (field == errors.GLOBAL_MESSAGE) {
+                        vaction.addActionError(msg);
+                    } else {
+                        vaction.addFieldError(field, msg);
+                    }
+                } else {
+                    // should do something here
+                }
+            }
+        }
+    }    
+}

Modified: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestScopedModelDrivenInterceptor.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestScopedModelDrivenInterceptor.java?rev=356591&r1=356590&r2=356591&view=diff
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestScopedModelDrivenInterceptor.java
 (original)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestScopedModelDrivenInterceptor.java
 Tue Dec 13 11:45:48 2005
@@ -39,12 +39,12 @@
         assertTrue(obj instanceof String);
 
         HashMap session = new HashMap();
-        obj = inter.resolveModel(factory, session, "java.lang.String", 
"request", "foo");
+        obj = inter.resolveModel(factory, session, "java.lang.String", 
"session", "foo");
         assertNotNull(obj);
         assertTrue(obj instanceof String);
         assertTrue(obj == session.get("foo"));
 
-        obj = inter.resolveModel(factory, session, "java.lang.String", 
"request", "foo");
+        obj = inter.resolveModel(factory, session, "java.lang.String", 
"session", "foo");
         assertNotNull(obj);
         assertTrue(obj instanceof String);
         assertTrue(obj == session.get("foo"));

Added: 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java?rev=356591&view=auto
==============================================================================
--- 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java
 (added)
+++ 
struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java
 Tue Dec 13 11:45:48 2005
@@ -0,0 +1,52 @@
+package org.apache.ti.legacy;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+import org.apache.commons.beanutils.*;
+import com.opensymphony.xwork.ActionSupport;
+import ognl.*;
+import org.apache.struts.action.*;
+import org.apache.struts.config.*;
+
+/**  Description of the Class */
+public class TestStrutsFactory extends TestCase {
+
+    protected StrutsFactory factory = null;
+    
+    public TestStrutsFactory(String name) throws Exception {
+        super(name);
+    }
+
+
+    public static void main(String args[]) {
+        junit.textui.TestRunner.run(TestStrutsFactory.class);
+    }
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    public void setUp() throws Exception {
+    
+        factory = new StrutsFactory();
+    }
+
+
+
+
+    public void testConvertErrors() throws Exception {
+
+        ActionMessage err1 = new ActionMessage("error1");
+        ActionMessage err2 = new ActionMessage("error2", new Integer(1));
+        ActionErrors errors = new ActionErrors();
+        errors.add(errors.GLOBAL_MESSAGE, err1);
+        errors.add("foo", err2);
+
+        ActionSupport action = new ActionSupport();
+        factory.convertErrors(errors, action);
+
+        assertTrue(1 == action.getActionErrors().size());
+        assertTrue(1 == action.getFieldErrors().size());
+    }
+}
+



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

Reply via email to