DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22519>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22519

Allow multiple MessageResources files to be loaded under one key

           Summary: Allow multiple MessageResources files to be loaded under
                    one key
           Product: Struts
           Version: 1.1 Final
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Utilities
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


If the files are specified as a comma delimited list under the parameter of the
message-resources element in the struts config. The only code change that needs
to be made is the following in the loadLocal() method of PropertyMessageResources:

        /**
         * @see org.apache.struts.util.PropertyMessageResources#loadLocale(String)
         * Same as PropertyMessageResources but allows comma separated lists of
properties files.
         * 
         * NOTE: If a property is specified in more than one file, only the first
instance of it 
         * will be loaded.
         */
        protected synchronized void loadLocale(String localeKey) {

        if (log.isTraceEnabled()) {
            log.trace("loadLocale(" + localeKey + ")");
        }
        
        // Have we already attempted to load messages for this locale?
        if (locales.get(localeKey) != null) {
            return;
        }
        locales.put(localeKey, localeKey);

        // Set up to load the property resource for this locale key, if we can
        String nameList = config.replace('.', '/');
        StringTokenizer nameListTokenizer = new StringTokenizer(nameList,",");
        
        while (nameListTokenizer.hasMoreTokens()) {
                        String name = nameListTokenizer.nextToken();
                if (localeKey.length() > 0) {
                    name += "_" + localeKey;
                }
                name += ".properties";
                InputStream is = null;
                Properties props = new Properties();
        
                // Load the specified property resource
                if (log.isTraceEnabled()) {
                    log.trace("  Loading resource '" + name + "'");
                }
                
                ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
                if (classLoader == null) {
                    classLoader = this.getClass().getClassLoader();
                }
                
                is = classLoader.getResourceAsStream(name);
                if (is != null) {
                    try {
                        props.load(is);
                        
                    } catch (IOException e) {
                        log.error("loadLocale()", e);
                    } finally {
                        try {
                            is.close();
                        } catch (IOException e) {
                            log.error("loadLocale()", e);
                        }
                    }
                }
                
                if (log.isTraceEnabled()) {
                    log.trace("  Loading resource completed");
                }
        
                // Copy the corresponding values into our cache
                if (props.size() < 1) {
                    return;
                }
                
                synchronized (messages) {
                    Iterator names = props.keySet().iterator();
                    while (names.hasNext()) {
                        String key = (String) names.next();
                        if (log.isTraceEnabled()) {
                            log.trace("  Saving message key '" + messageKey(localeKey,
key));
                        }
                        if (messages.get(messageKey(localeKey, key))== null) {
                                messages.put(messageKey(localeKey, key), 
props.getProperty(key));
                        }
                        else {
                                log.info(messageKey(localeKey, key) + ": was already 
loaded
and will be ignored.");
                        }
                    }
                }
        }

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

Reply via email to