struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-struts/src/share/org/apache/struts/util RequestUtils.java
Date Thu, 03 Jul 2003 01:47:06 GMT
dgraham     2003/07/02 18:47:06

  Modified:    src/share/org/apache/struts Globals.java
               src/share/org/apache/struts/action ActionServlet.java
               src/share/org/apache/struts/util RequestUtils.java
  Log:
  Moved initialization of module prefix list to the new 
  ActionServlet.initModulePrefixes() method from RequestUtils.getModulePrefixes()
  because of a potential race condition documented in PR# 21091.  This also 
  required a move of the RequestUtils.PREFIXES constant to 
  Globals.MODULE_PREFIXES_KEY.
  
  Revision  Changes    Path
  1.6       +15 -16    jakarta-struts/src/share/org/apache/struts/Globals.java
  
  Index: Globals.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/Globals.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Globals.java	16 Feb 2003 02:51:32 -0000	1.5
  +++ Globals.java	3 Jul 2003 01:47:05 -0000	1.6
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,26 +59,17 @@
    *
    */
   
  -
   package org.apache.struts;
   
  -
   import java.io.Serializable;
   
  -
   /**
  - * <p>Global manifest constants for the entire Struts Framework.</p>
  - *
  - * <p>Many of these constants were initially defined in <code>Action</code>,
  - * but were moved here so that they could be referenced without referencing
  - * the <code>Action</code> class itself.  For backwards compatibility,
  - * constant references there point at this class, and the constant values
  - * themselves have not changed.</p>
  + * Global manifest constants for the entire Struts Framework.
    *
    * @author Craig R. McClanahan
  + * @author David Graham
    * @version $Revision$ $Date$
    */
  -
   public class Globals implements Serializable {
   
   
  @@ -138,6 +129,14 @@
        */
       public static final String MODULE_KEY =
           "org.apache.struts.action.MODULE";
  +        
  +    /**
  +     * The ServletContext attribute under which we store the module prefixes 
  +     * String[].
  +     * @since Struts 1.2
  +     */
  +    public static final String MODULE_PREFIXES_KEY =
  +        "org.apache.struts.globals.MODULE_PREFIXES";
   
   
       /**
  
  
  
  1.154     +39 -7     jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
  
  Index: ActionServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
  retrieving revision 1.153
  retrieving revision 1.154
  diff -u -r1.153 -r1.154
  --- ActionServlet.java	2 Jul 2003 04:02:40 -0000	1.153
  +++ ActionServlet.java	3 Jul 2003 01:47:05 -0000	1.154
  @@ -72,6 +72,7 @@
   import java.util.Iterator;
   import java.util.MissingResourceException;
   
  +import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   import javax.servlet.UnavailableException;
   import javax.servlet.http.HttpServlet;
  @@ -445,13 +446,15 @@
           initOther();
           initServlet();
   
  -        // Initialize modules as needed
           getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
  +        
  +        // Initialize modules as needed
           ModuleConfig moduleConfig = initModuleConfig("", config);
           initModuleMessageResources(moduleConfig);
           initModuleDataSources(moduleConfig);
           initModulePlugIns(moduleConfig);
           moduleConfig.freeze();
  +        
           Enumeration names = getServletConfig().getInitParameterNames();
           while (names.hasMoreElements()) {
               String name = (String) names.nextElement();
  @@ -466,8 +469,37 @@
               initModulePlugIns(moduleConfig);
               moduleConfig.freeze();
           }
  -        destroyConfigDigester();
  -
  +        
  +        this.initModulePrefixes(this.getServletContext());
  +        
  +        this.destroyConfigDigester();
  +    }
  +    
  +    /**
  +     * Saves a String[] of module prefixes in the ServletContext under 
  +     * Globals.MODULE_PREFIXES_KEY.  <strong>NOTE</strong> -
  +     * the "" prefix for the default module is not included in this list.
  +     * 
  +     * @since Struts 1.2
  +     */
  +    protected void initModulePrefixes(ServletContext context) {
  +        ArrayList prefixList = new ArrayList();
  +        
  +        Enumeration names = context.getAttributeNames();
  +        while (names.hasMoreElements()) {
  +            String name = (String) names.nextElement();
  +            if (!name.startsWith(Globals.MODULE_KEY)) {
  +                continue;
  +            }
  +            
  +            String prefix = name.substring(Globals.MODULE_KEY.length());
  +            if (prefix.length() > 0) {
  +                prefixList.add(prefix);
  +            }
  +        }
  +        
  +        String[] prefixes = (String[]) prefixList.toArray(new String[prefixList.size()]);
  +        context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes);
       }
   
   
  
  
  
  1.107     +9 -37     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.106
  retrieving revision 1.107
  diff -u -r1.106 -r1.107
  --- RequestUtils.java	2 Jul 2003 03:09:47 -0000	1.106
  +++ RequestUtils.java	3 Jul 2003 01:47:05 -0000	1.107
  @@ -133,11 +133,6 @@
        */
       private static MessageResources messages =
           MessageResources.getMessageResources("org.apache.struts.util.LocalStrings");
  -
  -    /**
  -     * The context attribute under which we store our prefixes list.
  -     */
  -    private static final String PREFIXES_KEY = "org.apache.struts.util.PREFIXES";
       
       /**
        * Java 1.4 encode method to use instead of deprecated 1.3 version.
  @@ -1844,38 +1839,15 @@
   
       /**
        * Return the list of module prefixes that are defined for
  -     * this web application, creating it if necessary.  <strong>NOTE</strong>
-
  +     * this web application.  <strong>NOTE</strong> -
        * the "" prefix for the default module is not included in this list.
        *
  -     * @param context The ServletContext for this web application
  -     * @return an array of module prefixes
  +     * @param context The ServletContext for this web application.
  +     * @return An array of module prefixes.
        * @since Struts 1.1
        */
  -    public synchronized static String[] getModulePrefixes(ServletContext context) {
  -        // TODO Move prefix list initialization to ActionServlet.init() and unsynchronize
  -        // this method in Struts 1.2 
  -        
  -        String prefixes[] = (String[]) context.getAttribute(PREFIXES_KEY);
  -        if (prefixes != null) {
  -            return (prefixes);
  -        }
  -
  -        ArrayList list = new ArrayList();
  -        Enumeration names = context.getAttributeNames();
  -        while (names.hasMoreElements()) {
  -            String name = (String) names.nextElement();
  -            if (!name.startsWith(Globals.MODULE_KEY)) {
  -                continue;
  -            }
  -            String prefix = name.substring(Globals.MODULE_KEY.length());
  -            if (prefix.length() > 0) {
  -                list.add(prefix);
  -            }
  -        }
  -        prefixes = (String[]) list.toArray(new String[list.size()]);
  -        context.setAttribute(PREFIXES_KEY, prefixes);
  -        return (prefixes);
  -
  +    public static String[] getModulePrefixes(ServletContext context) {
  +        return (String[]) context.getAttribute(Globals.MODULE_PREFIXES_KEY);
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Mime
View raw message