//# 0 errors, 163 messages
//#
/*
    //#I18nMessages.java:1:1: class: org.apache.roller.weblogger.util.I18nMessages
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */

package org.apache.roller.weblogger.util;

import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * A utility class for handling i18n messaging.
 */
public final class I18nMessages {
    
    private static final Log log = LogFactory.getLog(I18nMessages.class);
    //#I18nMessages.java:37: method: org.apache.roller.weblogger.util.I18nMessages.org.apache.roller.weblogger.util.I18nMessages__static_init
    //#I18nMessages.java:37: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.util.I18nMessages
    //#    method: org.apache.roller.weblogger.util.I18nMessages__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(org.apache.roller.weblogger.util.I18nMessages__static_init): __Descendant_Table[org/apache/roller/weblogger/util/I18nMessages]
    //#output(org.apache.roller.weblogger.util.I18nMessages__static_init): __Dispatch_Table.getLocale()Ljava/util/Locale;
    //#output(org.apache.roller.weblogger.util.I18nMessages__static_init): __Dispatch_Table.getString(Ljava/lang/String;)Ljava/lang/String;
    //#output(org.apache.roller.weblogger.util.I18nMessages__static_init): __Dispatch_Table.getString(Ljava/lang/String;Ljava/util/List;)Ljava/lang/String;
    //#output(org.apache.roller.weblogger.util.I18nMessages__static_init): __Dispatch_Table.getString(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    //#output(org.apache.roller.weblogger.util.I18nMessages__static_init): log
    //#output(org.apache.roller.weblogger.util.I18nMessages__static_init): messagesMap
    //#post(org.apache.roller.weblogger.util.I18nMessages__static_init): __Descendant_Table[org/apache/roller/weblogger/util/I18nMessages] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.util.I18nMessages__static_init): __Dispatch_Table.getLocale()Ljava/util/Locale; == &getLocale
    //#post(org.apache.roller.weblogger.util.I18nMessages__static_init): __Dispatch_Table.getString(Ljava/lang/String;)Ljava/lang/String; == &getString
    //#post(org.apache.roller.weblogger.util.I18nMessages__static_init): __Dispatch_Table.getString(Ljava/lang/String;Ljava/util/List;)Ljava/lang/String; == &getString
    //#post(org.apache.roller.weblogger.util.I18nMessages__static_init): __Dispatch_Table.getString(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; == &getString
    //#post(org.apache.roller.weblogger.util.I18nMessages__static_init): init'ed(log)
    //#post(org.apache.roller.weblogger.util.I18nMessages__static_init): init'ed(messagesMap)
    
    // locale and bundle we are using for messaging
    private final Locale locale;
    private final ResourceBundle bundle;
    
    // a map of cached messages instances, keyed by locale
    private static Map<Locale, I18nMessages> messagesMap = 
    //#I18nMessages.java:44: end of method: org.apache.roller.weblogger.util.I18nMessages.org.apache.roller.weblogger.util.I18nMessages__static_init
            Collections.synchronizedMap(new HashMap());
    
    
    private I18nMessages(String locale) {
    //#I18nMessages.java:48: method: void org.apache.roller.weblogger.util.I18nMessages.org.apache.roller.weblogger.util.I18nMessages(String)
    //#input(void org.apache.roller.weblogger.util.I18nMessages(String)): locale
    //#input(void org.apache.roller.weblogger.util.I18nMessages(String)): this
    //#output(void org.apache.roller.weblogger.util.I18nMessages(String)): new Locale(toLocale#1) num objects
    //#output(void org.apache.roller.weblogger.util.I18nMessages(String)): new Locale(toLocale#2) num objects
    //#output(void org.apache.roller.weblogger.util.I18nMessages(String)): new Locale(toLocale#3) num objects
    //#output(void org.apache.roller.weblogger.util.I18nMessages(String)): this.bundle
    //#output(void org.apache.roller.weblogger.util.I18nMessages(String)): this.locale
    //#new obj(void org.apache.roller.weblogger.util.I18nMessages(String)): new Locale(toLocale#1)
    //#new obj(void org.apache.roller.weblogger.util.I18nMessages(String)): new Locale(toLocale#2)
    //#new obj(void org.apache.roller.weblogger.util.I18nMessages(String)): new Locale(toLocale#3)
    //#post(void org.apache.roller.weblogger.util.I18nMessages(String)): init'ed(this.bundle)
    //#post(void org.apache.roller.weblogger.util.I18nMessages(String)): init'ed(this.locale)
    //#post(void org.apache.roller.weblogger.util.I18nMessages(String)): new Locale(toLocale#1) num objects <= 1
    //#post(void org.apache.roller.weblogger.util.I18nMessages(String)): new Locale(toLocale#2) num objects <= 1
    //#post(void org.apache.roller.weblogger.util.I18nMessages(String)): new Locale(toLocale#3) num objects <= 1
    //#unanalyzed(void org.apache.roller.weblogger.util.I18nMessages(String)): Effects-of-calling:org.apache.commons.lang.StringUtils:split
    //#unanalyzed(void org.apache.roller.weblogger.util.I18nMessages(String)): Effects-of-calling:java.util.Locale
    //#unanalyzed(void org.apache.roller.weblogger.util.I18nMessages(String)): Effects-of-calling:java.util.Locale:getDefault
        Locale loc = I18nUtils.toLocale(locale);
        this.locale = loc;
        this.bundle = ResourceBundle.getBundle("ApplicationResources", loc);
    }
    //#I18nMessages.java:52: end of method: void org.apache.roller.weblogger.util.I18nMessages.org.apache.roller.weblogger.util.I18nMessages(String)
    
    private I18nMessages(Locale locale) {
    //#I18nMessages.java:54: method: void org.apache.roller.weblogger.util.I18nMessages.org.apache.roller.weblogger.util.I18nMessages(Locale)
    //#input(void org.apache.roller.weblogger.util.I18nMessages(Locale)): locale
    //#input(void org.apache.roller.weblogger.util.I18nMessages(Locale)): this
    //#output(void org.apache.roller.weblogger.util.I18nMessages(Locale)): this.bundle
    //#output(void org.apache.roller.weblogger.util.I18nMessages(Locale)): this.locale
    //#post(void org.apache.roller.weblogger.util.I18nMessages(Locale)): init'ed(this.bundle)
    //#post(void org.apache.roller.weblogger.util.I18nMessages(Locale)): this.locale == locale
    //#post(void org.apache.roller.weblogger.util.I18nMessages(Locale)): init'ed(this.locale)
        this.locale = locale;
        this.bundle = ResourceBundle.getBundle("ApplicationResources", locale);
    }
    //#I18nMessages.java:57: end of method: void org.apache.roller.weblogger.util.I18nMessages.org.apache.roller.weblogger.util.I18nMessages(Locale)
    
    
    /**
     * Get an instance for a given locale.
     */
    public static I18nMessages getMessages(String locale) {
        
        log.debug("request for messages in locale = "+locale);
    //#I18nMessages.java:65: method: I18nMessages org.apache.roller.weblogger.util.I18nMessages.getMessages(String)
    //#I18nMessages.java:65: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.util.I18nMessages
    //#    method: I18nMessages getMessages(String)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
    //#input(I18nMessages getMessages(String)): "request for messages in locale = "._tainted
    //#input(I18nMessages getMessages(String)): __Descendant_Table[org/apache/roller/weblogger/util/I18nMessages]
    //#input(I18nMessages getMessages(String)): __Descendant_Table[others]
    //#input(I18nMessages getMessages(String)): locale
    //#input(I18nMessages getMessages(String)): locale._tainted
    //#input(I18nMessages getMessages(String)): log
    //#input(I18nMessages getMessages(String)): messagesMap
    //#output(I18nMessages getMessages(String)): new I18nMessages(getMessages#2) num objects
    //#output(I18nMessages getMessages(String)): new I18nMessages(getMessages#2).__Tag
    //#output(I18nMessages getMessages(String)): new I18nMessages(getMessages#2).bundle
    //#output(I18nMessages getMessages(String)): new I18nMessages(getMessages#2).locale
    //#output(I18nMessages getMessages(String)): new Locale(toLocale#1) num objects
    //#output(I18nMessages getMessages(String)): new Locale(toLocale#2) num objects
    //#output(I18nMessages getMessages(String)): new Locale(toLocale#3) num objects
    //#output(I18nMessages getMessages(String)): return_value
    //#new obj(I18nMessages getMessages(String)): new I18nMessages(getMessages#2)
    //#new obj(I18nMessages getMessages(String)): new Locale(toLocale#1)
    //#new obj(I18nMessages getMessages(String)): new Locale(toLocale#2)
    //#new obj(I18nMessages getMessages(String)): new Locale(toLocale#3)
    //#pre[3] (I18nMessages getMessages(String)): messagesMap != null
    //#presumption(I18nMessages getMessages(String)): java.util.Map:get(...).__Tag@68 == org/apache/roller/weblogger/util/I18nMessages
    //#presumption(I18nMessages getMessages(String)): org.apache.commons.logging.LogFactory:getLog(...)@37 != null
    //#post(I18nMessages getMessages(String)): return_value != null
    //#post(I18nMessages getMessages(String)): new I18nMessages(getMessages#2) num objects <= 1
    //#post(I18nMessages getMessages(String)): new I18nMessages(getMessages#2).__Tag == org/apache/roller/weblogger/util/I18nMessages
    //#post(I18nMessages getMessages(String)): init'ed(new I18nMessages(getMessages#2).bundle)
    //#post(I18nMessages getMessages(String)): init'ed(new I18nMessages(getMessages#2).locale)
    //#post(I18nMessages getMessages(String)): new Locale(toLocale#1) num objects <= 1
    //#post(I18nMessages getMessages(String)): new Locale(toLocale#2) num objects <= 1
    //#post(I18nMessages getMessages(String)): new Locale(toLocale#3) num objects <= 1
    //#unanalyzed(I18nMessages getMessages(String)): Effects-of-calling:org.apache.commons.lang.StringUtils:split
    //#unanalyzed(I18nMessages getMessages(String)): Effects-of-calling:java.util.Locale
    //#unanalyzed(I18nMessages getMessages(String)): Effects-of-calling:java.util.Locale:getDefault
    //#unanalyzed(I18nMessages getMessages(String)): Effects-of-calling:java.util.ResourceBundle:getBundle
    //#test_vector(I18nMessages getMessages(String)): java.util.Map:get(...)@68: Inverse{null}, Addr_Set{null}
        
        // check if we already have a message utils created for that locale
        I18nMessages messages = messagesMap.get(locale);
        
        // if no utils for that language yet then construct
        if(messages == null) {
            messages = new I18nMessages(locale);
            
            // keep a reference to it
            messagesMap.put(messages.getLocale(), messages);
        }
        
        return messages;
    //#I18nMessages.java:78: end of method: I18nMessages org.apache.roller.weblogger.util.I18nMessages.getMessages(String)
    }
    
    
    /**
     * Get an instance for a given locale.
     */
    public static I18nMessages getMessages(Locale locale) {
        
        log.debug("request for messages in locale = "+locale.toString());
    //#I18nMessages.java:87: method: I18nMessages org.apache.roller.weblogger.util.I18nMessages.getMessages(Locale)
    //#I18nMessages.java:87: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.util.I18nMessages
    //#    method: I18nMessages getMessages(Locale)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
    //#input(I18nMessages getMessages(Locale)): "request for messages in locale = "._tainted
    //#input(I18nMessages getMessages(Locale)): __Descendant_Table[org/apache/roller/weblogger/util/I18nMessages]
    //#input(I18nMessages getMessages(Locale)): __Descendant_Table[others]
    //#input(I18nMessages getMessages(Locale)): locale
    //#input(I18nMessages getMessages(Locale)): locale._tainted
    //#input(I18nMessages getMessages(Locale)): log
    //#input(I18nMessages getMessages(Locale)): messagesMap
    //#output(I18nMessages getMessages(Locale)): new I18nMessages(getMessages#2) num objects
    //#output(I18nMessages getMessages(Locale)): new I18nMessages(getMessages#2).__Tag
    //#output(I18nMessages getMessages(Locale)): new I18nMessages(getMessages#2).bundle
    //#output(I18nMessages getMessages(Locale)): new I18nMessages(getMessages#2).locale
    //#output(I18nMessages getMessages(Locale)): return_value
    //#new obj(I18nMessages getMessages(Locale)): new I18nMessages(getMessages#2)
    //#pre[1] (I18nMessages getMessages(Locale)): locale != null
    //#pre[3] (I18nMessages getMessages(Locale)): messagesMap != null
    //#presumption(I18nMessages getMessages(Locale)): java.util.Map:get(...).__Tag@90 == org/apache/roller/weblogger/util/I18nMessages
    //#presumption(I18nMessages getMessages(Locale)): org.apache.commons.logging.LogFactory:getLog(...)@37 != null
    //#post(I18nMessages getMessages(Locale)): return_value != null
    //#post(I18nMessages getMessages(Locale)): new I18nMessages(getMessages#2) num objects <= 1
    //#post(I18nMessages getMessages(Locale)): new I18nMessages(getMessages#2).__Tag == org/apache/roller/weblogger/util/I18nMessages
    //#post(I18nMessages getMessages(Locale)): init'ed(new I18nMessages(getMessages#2).bundle)
    //#post(I18nMessages getMessages(Locale)): new I18nMessages(getMessages#2).locale == locale
    //#post(I18nMessages getMessages(Locale)): new I18nMessages(getMessages#2).locale != null
    //#unanalyzed(I18nMessages getMessages(Locale)): Effects-of-calling:java.util.ResourceBundle:getBundle
    //#test_vector(I18nMessages getMessages(Locale)): java.util.Map:get(...)@90: Inverse{null}, Addr_Set{null}
        
        // check if we already have a message utils created for that locale
        I18nMessages messages = messagesMap.get(locale);
        
        // if no utils for that language yet then construct
        if(messages == null) {
            messages = new I18nMessages(locale);
            
            // keep a reference to it
            messagesMap.put(messages.getLocale(), messages);
        }
        
        return messages;
    //#I18nMessages.java:100: end of method: I18nMessages org.apache.roller.weblogger.util.I18nMessages.getMessages(Locale)
    }
    
    
    /**
     * The locale representing this message utils.
     */
    public final Locale getLocale() {
        return this.locale;
    //#I18nMessages.java:108: method: Locale org.apache.roller.weblogger.util.I18nMessages.getLocale()
    //#input(Locale getLocale()): this
    //#input(Locale getLocale()): this.locale
    //#output(Locale getLocale()): return_value
    //#post(Locale getLocale()): return_value == this.locale
    //#post(Locale getLocale()): init'ed(return_value)
    //#I18nMessages.java:108: end of method: Locale org.apache.roller.weblogger.util.I18nMessages.getLocale()
    }
    
    
    /**
     * Get a message from the bundle.
     */
    public final String getString(String key) {
        
        try {
            return bundle.getString(key);
    //#I18nMessages.java:118: method: String org.apache.roller.weblogger.util.I18nMessages.getString(String)
    //#input(String getString(String)): "Error getting key "._tainted
    //#input(String getString(String)): key
    //#input(String getString(String)): key._tainted
    //#input(String getString(String)): log
    //#input(String getString(String)): this
    //#input(String getString(String)): this.bundle
    //#output(String getString(String)): return_value
    //#pre[4] (String getString(String)): (soft) this.bundle != null
    //#presumption(String getString(String)): org.apache.commons.logging.LogFactory:getLog(...)@37 != null
    //#post(String getString(String)): init'ed(return_value)
        } catch (Exception e) {
            // send a warning in the logs
            log.warn("Error getting key "+key);
    //#I18nMessages.java:121: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:warn(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.util.I18nMessages
    //#    method: String getString(String)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:warn(Object)
            return key;
    //#I18nMessages.java:122: end of method: String org.apache.roller.weblogger.util.I18nMessages.getString(String)
        }
    }
    
    
    /**
     * Get a message from the bundle and substitute the given args into
     * the message contents.
     */
    public final String getString(String key, List args) {
        
        try {
            String msg = bundle.getString(key);
    //#I18nMessages.java:134: method: String org.apache.roller.weblogger.util.I18nMessages.getString(String, List)
    //#input(String getString(String, List)): "Error getting key "._tainted
    //#input(String getString(String, List)): args
    //#input(String getString(String, List)): key
    //#input(String getString(String, List)): key._tainted
    //#input(String getString(String, List)): log
    //#input(String getString(String, List)): this
    //#input(String getString(String, List)): this.bundle
    //#output(String getString(String, List)): return_value
    //#pre[1] (String getString(String, List)): (soft) args != null
    //#pre[5] (String getString(String, List)): (soft) this.bundle != null
    //#presumption(String getString(String, List)): org.apache.commons.logging.LogFactory:getLog(...)@37 != null
    //#post(String getString(String, List)): init'ed(return_value)
            return MessageFormat.format(msg, args.toArray());
        } catch (Exception e) {
            // send a warning in the logs
            log.warn("Error getting key "+key, e);
    //#I18nMessages.java:138: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:warn(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.util.I18nMessages
    //#    method: String getString(String, List)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:warn(Object, Throwable)
            return key;
    //#I18nMessages.java:139: end of method: String org.apache.roller.weblogger.util.I18nMessages.getString(String, List)
        }
    }
    
    
    /**
     * Get a message from the bundle and substitute the given args into
     * the message contents.
     */
    public final String getString(String key, Object[] args) {
        
        try {
            String msg = bundle.getString(key);
    //#I18nMessages.java:151: method: String org.apache.roller.weblogger.util.I18nMessages.getString(String, Object[])
    //#input(String getString(String, Object[])): "Error getting key "._tainted
    //#input(String getString(String, Object[])): args
    //#input(String getString(String, Object[])): key
    //#input(String getString(String, Object[])): key._tainted
    //#input(String getString(String, Object[])): log
    //#input(String getString(String, Object[])): this
    //#input(String getString(String, Object[])): this.bundle
    //#output(String getString(String, Object[])): return_value
    //#pre[5] (String getString(String, Object[])): (soft) this.bundle != null
    //#presumption(String getString(String, Object[])): org.apache.commons.logging.LogFactory:getLog(...)@37 != null
    //#post(String getString(String, Object[])): init'ed(return_value)
            return MessageFormat.format(msg, args);
        } catch (Exception e) {
            // send a warning in the logs
            log.warn("Error getting key "+key, e);
    //#I18nMessages.java:155: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:warn(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.util.I18nMessages
    //#    method: String getString(String, Object[])
    //#    unanalyzed callee: void org.apache.commons.logging.Log:warn(Object, Throwable)
            return key;
    //#I18nMessages.java:156: end of method: String org.apache.roller.weblogger.util.I18nMessages.getString(String, Object[])
        }
    }
    
}
    //#I18nMessages.java:: end of class: org.apache.roller.weblogger.util.I18nMessages
