dion        02/05/22 03:06:49

  Modified:    src/java/org/apache/maven/struts Struts10WarValidator.java
  Log:
  - added validation of actions
  
  Revision  Changes    Path
  1.4       +84 -5     
jakarta-turbine-maven/src/java/org/apache/maven/struts/Struts10WarValidator.java
  
  Index: Struts10WarValidator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/struts/Struts10WarValidator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Struts10WarValidator.java 22 May 2002 06:55:28 -0000      1.3
  +++ Struts10WarValidator.java 22 May 2002 10:06:49 -0000      1.4
  @@ -55,8 +55,11 @@
    */
   
   import java.io.IOException;
  -import java.util.List;
  +import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.List;
  +import java.util.Map;
  +
   
   import org.apache.maven.j2ee.ValidationEvent;
   import org.apache.maven.j2ee.WarValidator;
  @@ -71,7 +74,7 @@
    * </ol>
    *
    * @author  dion
  - * @version $Id: Struts10WarValidator.java,v 1.3 2002/05/22 06:55:28 dion Exp $
  + * @version $Id: Struts10WarValidator.java,v 1.4 2002/05/22 10:06:49 dion Exp $
    */
   public class Struts10WarValidator extends WarValidator
   {
  @@ -97,6 +100,7 @@
               strutsWar.setConfig(getConfig());
               validateStrutsConfig(strutsWar);
               validateFormBeans(strutsWar);
  +            validateActions(strutsWar);
           }
           catch (IOException ioe)
           {
  @@ -137,6 +141,7 @@
       
       /** validations for the form beans in the config
        * @param strutsWar - the struts web app being validated
  +     * @throws IOException when there are problems reading the war
        */
       private void validateFormBeans(Struts10WarFile strutsWar) throws IOException
       {
  @@ -145,9 +150,9 @@
           FormBean bean = null;
           ClassLoader loader = new WarClassLoader(strutsWar, 
               getClass().getClassLoader());
  -        for (Iterator beans = formBeans.iterator(); beans.hasNext();)
  +        for (int index = 0; index < formBeans.size(); index++)
           {
  -            bean = (FormBean) beans.next();
  +            bean = (FormBean) formBeans.get(index);
               info("validating form bean: '" + bean.getName() + "', class: '" +
                   bean.getType() + "'");
               validateClass(bean.getType(), loader);
  @@ -157,4 +162,78 @@
               }
           }
       }
  -}
  +    
  +    /** validations for the actions in the config
  +     * @param strutsWar - the struts web app being validated
  +     * @throws IOException when there are problems reading the war
  +     */
  +    private void validateActions(Struts10WarFile war) throws IOException
  +    {
  +        info("validating Struts Actions");
  +        List actions = war.getActions();
  +        Action action = null;
  +        ClassLoader loader = new WarClassLoader(war, 
  +            getClass().getClassLoader());
  +        List formBeans = war.getFormBeans();
  +        Map formBeansByName = new HashMap();
  +        // put form beans into a map to find them easier
  +        FormBean formBean = null;
  +        for (int index = 0; index < formBeans.size(); index++)
  +        {
  +            formBean = (FormBean) formBeans.get(index);
  +            formBeansByName.put(formBean.getName(), formBean);
  +        }
  +        // check actions
  +        for (int index = 0; index < actions.size(); index++) 
  +        {
  +            action = (Action) actions.get(index);
  +            info("validating action for path: '" + action.getPath() + "'");
  +            if (action.getClassName() != null)
  +            {
  +                validateClass(action.getClassName(), loader);
  +            }
  +            if (action.getName() != null)
  +            {
  +                if (formBeansByName.get(action.getName()) == null)
  +                {
  +                    error("action refers to a non-existent form bean: '" +
  +                        action.getName() + "'");
  +                }
  +            }
  +            if (!action.getPath().startsWith("/"))
  +            {
  +                error("action path doesn't start with a '/'");
  +            }
  +            if (action.getScope() != null)
  +            {
  +                // valid values are "request" or "session" according to the dtd
  +                String scope = action.getScope();
  +                if (!(scope.equals("request") || scope.equals("session")))
  +                {
  +                    error("scope is not 'request' or 'session': '" + scope + 
  +                        "'");
  +                }
  +            }
  +            if (action.getType() != null)
  +            {
  +                validateClass(action.getType(), loader);
  +            }
  +            if (action.getUnknown() != null) // true or false only
  +            {
  +                String unknown = action.getUnknown();
  +                if (!(unknown.equals("true") || unknown.equals("false")))
  +                {
  +                    error("unknown attribute is not 'true' or 'false'");
  +                }
  +            }
  +            if (action.getValidate() != null) // true or false only
  +            {
  +                String validate = action.getValidate();
  +                if (!(validate.equals("true") || validate.equals("false")))
  +                {
  +                    error("validate attribute is not 'true' or 'false'");
  +                }
  +            }
  +        } // end for all actions
  +    } // end method
  +} // end class
  
  
  

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

Reply via email to