dgraham     2003/07/26 11:44:54

  Modified:    src/share/org/apache/struts/taglib/html FormTag.java
               src/share/org/apache/struts/util RequestUtils.java
               src/share/org/apache/struts/taglib TagUtils.java
  Log:
  Moved RequestUtils.getActionMappingURL() and .getActionMappingName()
  to TagUtils.
  
  Revision  Changes    Path
  1.52      +8 -6      
jakarta-struts/src/share/org/apache/struts/taglib/html/FormTag.java
  
  Index: FormTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/FormTag.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- FormTag.java      26 Jul 2003 01:22:30 -0000      1.51
  +++ FormTag.java      26 Jul 2003 18:44:53 -0000      1.52
  @@ -593,7 +593,9 @@
           results.append("\" action=\"");
           results.append(
               response.encodeURL(
  -                RequestUtils.getActionMappingURL(this.action, this.pageContext)));
  +                TagUtils.getInstance().getActionMappingURL(
  +                    this.action,
  +                    this.pageContext)));
                   
           results.append("\"");
           
  @@ -812,7 +814,7 @@
                   Globals.ACTION_SERVLET_KEY);
   
           // Look up the action mapping we will be submitting to
  -        String mappingName = RequestUtils.getActionMappingName(action);
  +        String mappingName = TagUtils.getInstance().getActionMappingName(action);
           mapping = (ActionMapping) moduleConfig.findActionConfig(mappingName);
           if (mapping == null) {
               JspException e = new 
JspException(messages.getMessage("formTag.mapping", mappingName));
  
  
  
  1.122     +15 -65    
jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
  
  Index: RequestUtils.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
  retrieving revision 1.121
  retrieving revision 1.122
  diff -u -r1.121 -r1.122
  --- RequestUtils.java 26 Jul 2003 17:39:33 -0000      1.121
  +++ RequestUtils.java 26 Jul 2003 18:44:54 -0000      1.122
  @@ -558,74 +558,24 @@
        * <li>If the resulting value does not start with a slash, then a
        *     slash is prepended.</li>
        * </ul>
  +     * @deprecated Use TagUtils.getActionMappingName() instead.  This will be 
  +     * removed after Struts 1.2.
        */
       public static String getActionMappingName(String action) {
  -
  -        String value = action;
  -        int question = action.indexOf("?");
  -        if (question >= 0) {
  -            value = value.substring(0, question);
  -        }
  -        int slash = value.lastIndexOf("/");
  -        int period = value.lastIndexOf(".");
  -        if ((period >= 0) && (period > slash)) {
  -            value = value.substring(0, period);
  -        }
  -        if (value.startsWith("/")) {
  -            return (value);
  -        } else {
  -            return ("/" + value);
  -        }
  +        return TagUtils.getInstance().getActionMappingName(action);
       }
   
       /**
        * Return the form action converted into a server-relative URL.
  +     * @deprecated Use TagUtils.getActionMappingURL() instead.  This will be 
  +     * removed after Struts 1.2.
        */
  -    public static String getActionMappingURL(String action, PageContext 
pageContext) {
  -
  -        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
  -        StringBuffer value = new StringBuffer(request.getContextPath());
  -        ModuleConfig config = getRequestModuleConfig(request);
  -        if (config != null) {
  -            value.append(config.getPrefix());
  -        }
  -
  -        // Use our servlet mapping, if one is specified
  -        String servletMapping =
  -            (String) pageContext.getAttribute(Globals.SERVLET_KEY, 
PageContext.APPLICATION_SCOPE);
  -        if (servletMapping != null) {
  -            String queryString = null;
  -            int question = action.indexOf("?");
  -            if (question >= 0) {
  -                queryString = action.substring(question);
  -            }
  -            String actionMapping = getActionMappingName(action);
  -            if (servletMapping.startsWith("*.")) {
  -                value.append(actionMapping);
  -                value.append(servletMapping.substring(1));
  -            } else if (servletMapping.endsWith("/*")) {
  -                value.append(servletMapping.substring(0, servletMapping.length() - 
2));
  -                value.append(actionMapping);
  -            } else if (servletMapping.equals("/")) {
  -                value.append(actionMapping);
  -            }
  -            if (queryString != null) {
  -                value.append(queryString);
  -            }
  -        }
  -
  -        // Otherwise, assume extension mapping is in use and extension is
  -        // already included in the action property
  -        else {
  -            if (!action.startsWith("/")) {
  -                value.append("/");
  -            }
  -            value.append(action);
  -        }
  -
  -        // Return the completed value
  -        return (value.toString());
  -     }
  +    public static String getActionMappingURL(
  +        String action,
  +        PageContext pageContext) {
  +            
  +        return TagUtils.getInstance().getActionMappingURL(action, pageContext);
  +    }
   
        /**
        * Create (if necessary) and return an ActionForm instance appropriate
  
  
  
  1.9       +117 -12   jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java
  
  Index: TagUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TagUtils.java     26 Jul 2003 18:28:03 -0000      1.8
  +++ TagUtils.java     26 Jul 2003 18:44:54 -0000      1.9
  @@ -151,7 +151,7 @@
        * identified, return <code>null</code>.
        *
        * @param pageContext PageContext we are operating in
  -
  +    
        * @param paramId Single-value request parameter name (if any)
        * @param paramName Bean containing single-value parameter value
        * @param paramProperty Property (of bean named by <code>paramName</code>
  @@ -192,11 +192,17 @@
           Map map = null;
           try {
               if (name != null) {
  -                map = (Map) TagUtils.getInstance().lookup(pageContext, name, 
property, scope);
  +                map =
  +                    (Map) TagUtils.getInstance().lookup(
  +                        pageContext,
  +                        name,
  +                        property,
  +                        scope);
               }
           } catch (ClassCastException e) {
               saveException(pageContext, e);
  -            throw new JspException(messages.getMessage("parameters.multi", name, 
property, scope));
  +            throw new JspException(
  +                messages.getMessage("parameters.multi", name, property, scope));
           } catch (JspException e) {
               saveException(pageContext, e);
               throw e;
  @@ -215,7 +221,12 @@
   
               Object paramValue = null;
               try {
  -                paramValue = TagUtils.getInstance().lookup(pageContext, paramName, 
paramProperty, paramScope);
  +                paramValue =
  +                    TagUtils.getInstance().lookup(
  +                        pageContext,
  +                        paramName,
  +                        paramProperty,
  +                        paramScope);
               } catch (JspException e) {
                   saveException(pageContext, e);
                   throw e;
  @@ -316,6 +327,95 @@
   
           return errors;
       }
  +    
  +    /**
  +     * Return the form action converted into an action mapping path.  The
  +     * value of the <code>action</code> property is manipulated as follows in
  +     * computing the name of the requested mapping:
  +     * <ul>
  +     * <li>Any filename extension is removed (on the theory that extension
  +     *     mapping is being used to select the controller servlet).</li>
  +     * <li>If the resulting value does not start with a slash, then a
  +     *     slash is prepended.</li>
  +     * </ul>
  +     */
  +    public String getActionMappingName(String action) {
  +
  +        String value = action;
  +        int question = action.indexOf("?");
  +        if (question >= 0) {
  +            value = value.substring(0, question);
  +        }
  +        
  +        int slash = value.lastIndexOf("/");
  +        int period = value.lastIndexOf(".");
  +        if ((period >= 0) && (period > slash)) {
  +            value = value.substring(0, period);
  +        }
  +        
  +        if (value.startsWith("/")) {
  +            return (value);
  +        } else {
  +            return ("/" + value);
  +        }
  +    }
  +
  +    /**
  +     * Return the form action converted into a server-relative URL.
  +     */
  +    public String getActionMappingURL(String action, PageContext pageContext) {
  +
  +        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
  +        StringBuffer value = new StringBuffer(request.getContextPath());
  +        ModuleConfig config = RequestUtils.getRequestModuleConfig(request);
  +        
  +        if (config != null) {
  +            value.append(config.getPrefix());
  +        }
  +
  +        // Use our servlet mapping, if one is specified
  +        String servletMapping =
  +            (String) pageContext.getAttribute(
  +                Globals.SERVLET_KEY,
  +                PageContext.APPLICATION_SCOPE);
  +
  +        if (servletMapping != null) {
  +            
  +            String queryString = null;
  +            int question = action.indexOf("?");
  +            if (question >= 0) {
  +                queryString = action.substring(question);
  +            }
  +
  +            String actionMapping = getActionMappingName(action);
  +            if (servletMapping.startsWith("*.")) {
  +                value.append(actionMapping);
  +                value.append(servletMapping.substring(1));
  +
  +            } else if (servletMapping.endsWith("/*")) {
  +                value.append(
  +                    servletMapping.substring(0, servletMapping.length() - 2));
  +                value.append(actionMapping);
  +
  +            } else if (servletMapping.equals("/")) {
  +                value.append(actionMapping);
  +            }
  +            if (queryString != null) {
  +                value.append(queryString);
  +            }
  +        }
  +
  +        // Otherwise, assume extension mapping is in use and extension is
  +        // already included in the action property
  +        else {
  +            if (!action.startsWith("/")) {
  +                value.append("/");
  +            }
  +            value.append(action);
  +        }
  +
  +        return value.toString();
  +    }
   
       /**
        * Return the ModuleConfig object if it exists, null if otherwise.
  @@ -424,7 +524,9 @@
               if (scope == null) {
                   e = new JspException(messages.getMessage("lookup.bean.any", name));
               } else {
  -                e = new JspException(messages.getMessage("lookup.bean", name, 
scope));
  +                e =
  +                    new JspException(
  +                        messages.getMessage("lookup.bean", name, scope));
               }
               saveException(pageContext, e);
               throw e;
  @@ -440,7 +542,8 @@
   
           } catch (IllegalAccessException e) {
               saveException(pageContext, e);
  -            throw new JspException(messages.getMessage("lookup.access", property, 
name));
  +            throw new JspException(
  +                messages.getMessage("lookup.access", property, name));
   
           } catch (InvocationTargetException e) {
               Throwable t = e.getTargetException();
  @@ -448,11 +551,13 @@
                   t = e;
               }
               saveException(pageContext, t);
  -            throw new JspException(messages.getMessage("lookup.target", property, 
name));
  +            throw new JspException(
  +                messages.getMessage("lookup.target", property, name));
   
           } catch (NoSuchMethodException e) {
               saveException(pageContext, e);
  -            throw new JspException(messages.getMessage("lookup.method", property, 
name));
  +            throw new JspException(
  +                messages.getMessage("lookup.method", property, name));
           }
   
       }
  
  
  

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

Reply via email to