craigmcc    02/01/19 21:34:08

  Modified:    conf/share struts-config_1_1.dtd
               src/share/org/apache/struts/action ActionServlet.java
               src/share/org/apache/struts/config ApplicationConfig.java
                        MessageResourcesConfig.java
  Log:
  Follow Martin's suggestion and allow more than one <message-resources>
  element in the struts-config.xml file.  The default (as you might expect :-)
  is backwards compatible.
  
  Also, refine the storing of data sources and message resources into servlet
  context attributes.  The actual attribute used is the specified key plus the
  sub-application prefix (which, for the default sub-app, is again backwards
  compatible).  The net effect of this is that data source and message
  resources keys do *not* have to be globally unique.
  
  Revision  Changes    Path
  1.11      +16 -2     jakarta-struts/conf/share/struts-config_1_1.dtd
  
  Index: struts-config_1_1.dtd
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/conf/share/struts-config_1_1.dtd,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- struts-config_1_1.dtd     17 Jan 2002 00:15:05 -0000      1.10
  +++ struts-config_1_1.dtd     20 Jan 2002 05:34:08 -0000      1.11
  @@ -11,7 +11,7 @@
          "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd";>
   
  -     $Id: struts-config_1_1.dtd,v 1.10 2002/01/17 00:15:05 craigmcc Exp $
  +     $Id: struts-config_1_1.dtd,v 1.11 2002/01/20 05:34:08 craigmcc Exp $
   -->
   
   
  @@ -85,7 +85,7 @@
        hierarchy, and contains nested elements for all of the other
        configuration settings.
   -->
  -<!ELEMENT struts-config (data-sources?, form-beans?, global-exceptions?, 
global-forwards?, action-mappings?, controller?, message-resources?)>
  +<!ELEMENT struts-config (data-sources?, form-beans?, global-exceptions?, 
global-forwards?, action-mappings?, controller?, message-resources*)>
   <!ATTLIST struts-config  id             ID              #IMPLIED>
   
   
  @@ -112,6 +112,10 @@
                        source will be stored.  Default is the value specified
                        by string constant Action.DATA_SOURCE_KEY.
   
  +                     NOTE:  The attribute under which this data source is
  +                     actually stored will be the key value suffixed by
  +                     the application prefix for this sub-application
  +
        type            Fully qualified Java class name of the data source
                        implementation class.  This class must implement
                        "javax.sql.DataSource" and be configurable totally
  @@ -467,6 +471,15 @@
                        By default, this is set to
                        org.apache.struts.util.PropertyMessageResourcesFactory.
   
  +     key             Servlet context attribute key under which this
  +                     message resources bundle will be stored.  Default is the
  +                     value specified by the string constant
  +                     Action.MESSAGES_KEY.
  +
  +                     NOTE:  The attribute under which this message resources is
  +                     actually stored will be the key value suffixed by
  +                     the application prefix for this sub-application
  +
        null            Set to true if you want our message resources to return
                        a null string for unknown message keys, or false to
                        return a message with the bad key value.  [true]
  @@ -478,6 +491,7 @@
   <!ATTLIST message-resources id          ID              #IMPLIED>
   <!ATTLIST message-resources className   %ClassName;     #IMPLIED>
   <!ATTLIST message-resources factory     %ClassName;     #IMPLIED>
  +<!ATTLIST message-resources key         %AttributeName; #IMPLIED>
   <!ATTLIST message-resources null        %Boolean;       #IMPLIED>
   <!ATTLIST message-resources parameter   CDATA           #REQUIRED>
   
  
  
  
  1.88      +41 -30    
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.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- ActionServlet.java        17 Jan 2002 00:15:05 -0000      1.87
  +++ ActionServlet.java        20 Jan 2002 05:34:08 -0000      1.88
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.87 
2002/01/17 00:15:05 craigmcc Exp $
  - * $Revision: 1.87 $
  - * $Date: 2002/01/17 00:15:05 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.88 
2002/01/20 05:34:08 craigmcc Exp $
  + * $Revision: 1.88 $
  + * $Date: 2002/01/20 05:34:08 $
    *
    * ====================================================================
    *
  @@ -266,7 +266,7 @@
    *
    * @author Craig R. McClanahan
    * @author Ted Husted
  - * @version $Revision: 1.87 $ $Date: 2002/01/17 00:15:05 $
  + * @version $Revision: 1.88 $ $Date: 2002/01/20 05:34:08 $
    */
   
   public class ActionServlet
  @@ -759,7 +759,12 @@
           }
   
           // Special handling for the default app's MessageResourcesConfig
  -        MessageResourcesConfig mrc = config.getMessageResourcesConfig();
  +        MessageResourcesConfig mrc =
  +            config.findMessageResourcesConfig(Action.MESSAGES_KEY);
  +        if (mrc == null) {
  +            mrc = new MessageResourcesConfig();
  +            config.addMessageResourcesConfig(mrc);
  +        }
           value = getServletConfig().getInitParameter("application");
           if (value != null) {
               mrc.setParameter(value);
  @@ -827,7 +832,8 @@
                   throw new UnavailableException
                       (internal.getMessage("dataSource.init", dscs[i].getKey()));
               }
  -            getServletContext().setAttribute(dscs[i].getKey(), ds);
  +            getServletContext().setAttribute
  +                (dscs[i].getKey() + config.getPrefix(), ds);
               dataSources.put(dscs[i].getKey(), ds);
           }
           dataSources.setFast(true);
  @@ -851,31 +857,36 @@
       protected void initApplicationMessageResources
           (ApplicationConfig config) throws ServletException {
   
  -        MessageResourcesConfig mrc = config.getMessageResourcesConfig();
  -        if ((mrc.getFactory() == null) || (mrc.getParameter() == null)) {
  -            return;
  -        }
  -        if (debug >= 1) {
  -            log("Initializing application path '" + config.getPrefix() +
  -                "' message resources from '" + mrc.getParameter() + "'");
  -        }
  +        MessageResourcesConfig mrcs[] =
  +            config.findMessageResourcesConfigs();
  +        for (int i = 0; i < mrcs.length; i++) {
  +            if ((mrcs[i].getFactory() == null) ||
  +                (mrcs[i].getParameter() == null)) {
  +                continue;
  +            }
  +            if (debug >= 1) {
  +                log("Initializing application path '" + config.getPrefix() +
  +                    "' message resources from '" +
  +                    mrcs[i].getParameter() + "'");
  +            }
   
  -        try {
  -            String factory = mrc.getFactory();
  -            MessageResourcesFactory.setFactoryClass(factory);
  -            MessageResourcesFactory factoryObject =
  -                MessageResourcesFactory.createFactory();
  -            MessageResources resources =
  -                factoryObject.createResources(mrc.getParameter());
  -            resources.setReturnNull(mrc.getNull());
  -            getServletContext().setAttribute
  -                (Action.MESSAGES_KEY + config.getPrefix(), resources);
  -        } catch (Throwable t) {
  -            log(internal.getMessage
  -                ("applicationResources", mrc.getParameter()), t);
  -            throw new UnavailableException
  -                (internal.getMessage
  -                 ("applicationResources", mrc.getParameter()));
  +            try {
  +                String factory = mrcs[i].getFactory();
  +                MessageResourcesFactory.setFactoryClass(factory);
  +                MessageResourcesFactory factoryObject =
  +                    MessageResourcesFactory.createFactory();
  +                MessageResources resources =
  +                    factoryObject.createResources(mrcs[i].getParameter());
  +                resources.setReturnNull(mrcs[i].getNull());
  +                getServletContext().setAttribute
  +                    (mrcs[i].getKey() + config.getPrefix(), resources);
  +            } catch (Throwable t) {
  +                log(internal.getMessage
  +                    ("applicationResources", mrcs[i].getParameter()), t);
  +                throw new UnavailableException
  +                    (internal.getMessage
  +                     ("applicationResources", mrcs[i].getParameter()));
  +            }
           }
   
       }
  
  
  
  1.8       +74 -22    
jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java
  
  Index: ApplicationConfig.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ApplicationConfig.java    15 Jan 2002 18:39:36 -0000      1.7
  +++ ApplicationConfig.java    20 Jan 2002 05:34:08 -0000      1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v 
1.7 2002/01/15 18:39:36 craigmcc Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/01/15 18:39:36 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v 
1.8 2002/01/20 05:34:08 craigmcc Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/01/20 05:34:08 $
    *
    * ====================================================================
    *
  @@ -82,7 +82,7 @@
    * previous Struts behavior that only supported one application.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.7 $ $Date: 2002/01/15 18:39:36 $
  + * @version $Revision: 1.8 $ $Date: 2002/01/20 05:34:08 $
    * @since Struts 1.1
    */
   
  @@ -146,6 +146,13 @@
       protected FastHashMap forwards = new FastHashMap();
   
   
  +    /**
  +     * The set of message resources configurations for this
  +     * application, if any, keyed by the <code>key</code> property.
  +     */
  +    protected FastHashMap messageResources = new FastHashMap();
  +
  +
       // ------------------------------------------------------------- Properties
   
   
  @@ -180,24 +187,6 @@
   
   
       /**
  -     * The message resources configuration object for this application.
  -     */
  -    protected MessageResourcesConfig messageResourcesConfig = null;
  -
  -    public MessageResourcesConfig getMessageResourcesConfig() {
  -        if (this.messageResourcesConfig == null)
  -            this.messageResourcesConfig = new MessageResourcesConfig();
  -        return (this.messageResourcesConfig);
  -    }
  -
  -    public void setMessageResourcesConfig(MessageResourcesConfig mrc) {
  -        if (configured)
  -            throw new IllegalStateException("Configuration is frozen");
  -        this.messageResourcesConfig = mrc;
  -    }
  -
  -
  -    /**
        * The prefix of the context-relative portion of the request URI, used to
        * select this configuration versus others supported by the controller
        * servlet.  A configuration with a prefix of a zero-length String is the
  @@ -342,6 +331,24 @@
   
   
       /**
  +     * Add a new <code>MessageResourcesConfig</code> instance to the set
  +     * associated with this application.
  +     *
  +     * @param config The new configuration instance to be added
  +     *
  +     * @exception IllegalStateException if this application configuration
  +     *  has been frozen
  +     */
  +    public void addMessageResourcesConfig(MessageResourcesConfig config) {
  +
  +        if (configured)
  +            throw new IllegalStateException("Configuration is frozen");
  +        messageResources.put(config.getKey(), config);
  +
  +    }
  +
  +
  +    /**
        * Return the action configuration for the specified path, if any;
        * otherwise return <code>null</code>.
        *
  @@ -467,6 +474,33 @@
   
   
       /**
  +     * Return the message resources configuration for the specified key,
  +     * if any; otherwise return <code>null</code>.
  +     *
  +     * @param key Key of the data source configuration to return
  +     */
  +    public MessageResourcesConfig findMessageResourcesConfig(String key) {
  +
  +        return ((MessageResourcesConfig) messageResources.get(key));
  +
  +    }
  +
  +
  +    /**
  +     * Return the message resources configurations for this application.
  +     * If there are none, a zero-length array is returned.
  +     */
  +    public MessageResourcesConfig[] findMessageResourcesConfigs() {
  +
  +        MessageResourcesConfig results[] =
  +            new MessageResourcesConfig[messageResources.size()];
  +        return ((MessageResourcesConfig[])
  +                messageResources.values().toArray(results));
  +
  +    }
  +
  +
  +    /**
        * Freeze the configuration of this application.  After this method
        * returns, any attempt to modify the configuration will return
        * an IllegalStateException.
  @@ -479,6 +513,7 @@
           exceptions.setFast(true);
           formBeans.setFast(true);
           forwards.setFast(true);
  +        messageResources.setFast(true);
           ActionConfig[] configs = findActionConfigs();
           for (int i = 0; i < configs.length; i++) {
               configs[i].freeze();
  @@ -569,6 +604,23 @@
           if (configured)
               throw new IllegalStateException("Configuration is frozen");
           forwards.remove(config.getName());
  +
  +    }
  +
  +
  +    /**
  +     * Remove the specified message resources configuration instance.
  +     *
  +     * @param config MessageResourcesConfig instance to be removed
  +     *
  +     * @exception IllegalStateException if this application configuration
  +     *  has been frozen
  +     */
  +    public void removeMessageResourcesConfig(MessageResourcesConfig config) {
  +
  +        if (configured)
  +            throw new IllegalStateException("Configuration is frozen");
  +        messageResources.remove(config.getKey());
   
       }
   
  
  
  
  1.3       +20 -4     
jakarta-struts/src/share/org/apache/struts/config/MessageResourcesConfig.java
  
  Index: MessageResourcesConfig.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/MessageResourcesConfig.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MessageResourcesConfig.java       13 Jan 2002 00:25:36 -0000      1.2
  +++ MessageResourcesConfig.java       20 Jan 2002 05:34:08 -0000      1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/MessageResourcesConfig.java,v
 1.2 2002/01/13 00:25:36 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/13 00:25:36 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/MessageResourcesConfig.java,v
 1.3 2002/01/20 05:34:08 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/01/20 05:34:08 $
    *
    * ====================================================================
    *
  @@ -64,6 +64,7 @@
   
   
   import java.io.Serializable;
  +import org.apache.struts.action.Action;
   
   
   /**
  @@ -72,7 +73,7 @@
    * configuration file.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/13 00:25:36 $
  + * @version $Revision: 1.3 $ $Date: 2002/01/20 05:34:08 $
    * @since Struts 1.1
    */
   
  @@ -95,6 +96,21 @@
   
       public void setFactory(String factory) {
           this.factory = factory;
  +    }
  +
  +
  +    /**
  +     * The servlet context attributes key under which this MessageResources
  +     * instance is stored.
  +     */
  +    protected String key = Action.MESSAGES_KEY;
  +
  +    public String getKey() {
  +        return (this.key);
  +    }
  +
  +    public void setKey(String key) {
  +        this.key = key;
       }
   
   
  
  
  

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

Reply via email to