dion        02/05/29 16:22:05

  Modified:    src/java/org/apache/maven/struts Struts10WarValidator.java
  Log:
  - Added validation of <forward> tags being either a file in the war, or
  an action defined in the struts config
  
  Revision  Changes    Path
  1.10      +26 -8     
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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Struts10WarValidator.java 29 May 2002 06:42:00 -0000      1.9
  +++ Struts10WarValidator.java 29 May 2002 23:22:05 -0000      1.10
  @@ -87,10 +87,12 @@
    *   <li>&lt;global-forwards&gt; <code>type</code> must be a class in the war</li>
    *   <li>&lt;forward&gt; <code>redirect</code> must be <code>true</code> or
    *      <code>false</code></li>
  + *   <li>&lt;forward&gt; <code>path</code> must refer to either a file in the
  + *      war (e.g. a jsp), or an action defined in the struts configuration</li>
    * </ol>
    *
    * @author  dion
  - * @version $Id: Struts10WarValidator.java,v 1.9 2002/05/29 06:42:00 dion Exp $
  + * @version $Id: Struts10WarValidator.java,v 1.10 2002/05/29 23:22:05 dion Exp $
    */
   public class Struts10WarValidator extends WarValidator
   {
  @@ -296,7 +298,8 @@
           for (int index = 0; index < forwards.size(); index++)
           {
               forward = (Forward) forwards.get(index);
  -            info("validating forward '" + forward.getName() + "'");
  +            info("validating forward '" + forward.getName() + "', path: '" + 
  +                forward.getPath() + "'");
               if (CollectionUtils.cardinality(forward, forwards) > 1)
               {
                   error("forward is a duplicate (by name)");
  @@ -337,18 +340,33 @@
                   // could be an action - check to see if it matches the pattern for
                   // action servlet, if it does, extract the action path, and make
                   // sure it's in the list of actions
  -                RE regexp = new RE(war.getActionServletPattern());
  +                String pattern = war.getActionServletPattern();
  +                // escape '.', as it has special meaning to regular exprs
  +                pattern = Strings.replace(pattern, ".", "\\.");
  +                // change * to (*) to group matching characters for access
  +                pattern = Strings.replace(pattern, "*", "(.*)");
  +                RE regexp = new RE(pattern);
                   if (regexp.match(path))
                   {
  -                    String matchingExpression = Strings.replace(path, "*", 
  -                        "(*)");
  -                    RE matching = new RE(matchingExpression);
  -                    String actionPath = matching.getParen(1);
  +                    String actionPath = regexp.getParen(1);
  +                    Action dummyAction = new Action();
  +                    dummyAction.setPath(actionPath);
  +                    if (!war.getActions().contains(dummyAction))
  +                    {
  +                        error("action path for forward (" + actionPath + ")" +
  +                            " not found");
  +                    }
  +                }
  +                else
  +                {
  +                    error("No action or web resource found for '" + path + "'");
                   }
               }
               catch (RESyntaxException e)
               {
  -                // ignore temporarily
  +                throw new IllegalStateException("bad regular expression created"
  +                    + " from action servlet url-pattern in web.xml " +
  +                    e.getMessage());
               }
           }
           // check redirect
  
  
  

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

Reply via email to