incubator-kalumet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1359368 - /incubator/kalumet/trunk/kalumet-modules/console/src/main/java/org/apache/kalumet/console/app/Messages.java
Date Mon, 09 Jul 2012 19:48:33 GMT
Author: olamy
Date: Mon Jul  9 19:48:33 2012
New Revision: 1359368

URL: http://svn.apache.org/viewvc?rev=1359368&view=rev
Log:
prevent NPE

Modified:
    incubator/kalumet/trunk/kalumet-modules/console/src/main/java/org/apache/kalumet/console/app/Messages.java

Modified: incubator/kalumet/trunk/kalumet-modules/console/src/main/java/org/apache/kalumet/console/app/Messages.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/kalumet-modules/console/src/main/java/org/apache/kalumet/console/app/Messages.java?rev=1359368&r1=1359367&r2=1359368&view=diff
==============================================================================
--- incubator/kalumet/trunk/kalumet-modules/console/src/main/java/org/apache/kalumet/console/app/Messages.java
(original)
+++ incubator/kalumet/trunk/kalumet-modules/console/src/main/java/org/apache/kalumet/console/app/Messages.java
Mon Jul  9 19:48:33 2012
@@ -35,70 +35,76 @@ import java.util.ResourceBundle;
 public class Messages
 {
 
-  private static final String BUNDLE_NAME = "org.apache.kalumet.console.app.locales.Messages";
+    private static final String BUNDLE_NAME = "org.apache.kalumet.console.app.locales.Messages";
 
-  // a map which contains DateFormat objects for various locales.
-  private static final Map DATE_FORMAT_MEDIUM_MAP = new HashMap();
+    // a map which contains DateFormat objects for various locales.
+    private static final Map DATE_FORMAT_MEDIUM_MAP = new HashMap();
 
-  /**
-   * Formats a date with the specified locale.
-   *
-   * @param date the date to be formatted.
-   * @return a localized String representation of the date.
-   */
-  public static final String formatDateTimeMedium( Date date )
-  {
-    Locale locale = ApplicationInstance.getActive().getLocale();
-    DateFormat df = (DateFormat) DATE_FORMAT_MEDIUM_MAP.get( locale );
-    if ( df == null )
+    /**
+     * Formats a date with the specified locale.
+     *
+     * @param date the date to be formatted.
+     * @return a localized String representation of the date.
+     */
+    public static final String formatDateTimeMedium( Date date )
     {
-      df = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM, locale );
-      DATE_FORMAT_MEDIUM_MAP.put( locale, df );
+        Locale locale = getLocale();
+        DateFormat df = (DateFormat) DATE_FORMAT_MEDIUM_MAP.get( locale );
+        if ( df == null )
+        {
+            df = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM, locale
);
+            DATE_FORMAT_MEDIUM_MAP.put( locale, df );
+        }
+        return date == null ? null : df.format( date );
     }
-    return date == null ? null : df.format( date );
-  }
 
-  /**
-   * Returns a localized formatted message. This method conveniently wraps a
-   * call to a MessageFormat object.
-   *
-   * @param key       the key of the message to be returned.
-   * @param arguments an array of arguments to be inserted into the message.
-   */
-  public static String getFormattedString( String key, Object[] arguments )
-  {
-    Locale locale = ApplicationInstance.getActive().getLocale();
-    String template = getString( key );
-    MessageFormat messageFormat = new MessageFormat( template );
-    messageFormat.setLocale( locale );
-    return messageFormat.format( arguments, new StringBuffer(), null ).toString();
-  }
-
-  /**
-   * Returns localized text.
-   *
-   * @param key the key of the text to be returned.
-   * @return the appropriate localized text (if the key is not defined, the string "!key!"
is returned).
-   */
-  public static String getString( String key )
-  {
-    try
+    /**
+     * Returns a localized formatted message. This method conveniently wraps a
+     * call to a MessageFormat object.
+     *
+     * @param key       the key of the message to be returned.
+     * @param arguments an array of arguments to be inserted into the message.
+     */
+    public static String getFormattedString( String key, Object[] arguments )
     {
-      Locale locale = ApplicationInstance.getActive().getLocale();
-      ResourceBundle resource = ResourceBundle.getBundle( BUNDLE_NAME, locale );
-      return resource.getString( key );
+        Locale locale = getLocale();
+        String template = getString( key );
+        MessageFormat messageFormat = new MessageFormat( template );
+        messageFormat.setLocale( locale );
+        return messageFormat.format( arguments, new StringBuffer(), null ).toString();
     }
-    catch ( MissingResourceException e )
+
+    /**
+     * Returns localized text.
+     *
+     * @param key the key of the text to be returned.
+     * @return the appropriate localized text (if the key is not defined, the string "!key!"
is returned).
+     */
+    public static String getString( String key )
+    {
+        try
+        {
+            Locale locale = getLocale();
+
+            ResourceBundle resource = ResourceBundle.getBundle( BUNDLE_NAME, locale );
+            return resource.getString( key );
+        }
+        catch ( MissingResourceException e )
+        {
+            return '!' + key + '!';
+        }
+    }
+
+    private static Locale getLocale()
     {
-      return '!' + key + '!';
+        return ApplicationInstance.getActive() == null ? Locale.ENGLISH : ApplicationInstance.getActive().getLocale();
     }
-  }
 
-  /**
-   * Non-instantiable class.
-   */
-  private Messages()
-  {
-  }
+    /**
+     * Non-instantiable class.
+     */
+    private Messages()
+    {
+    }
 
 }



Mime
View raw message