sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1401244 - in /sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis: measure/Angle.java util/logging/Logging.java util/resources/IndexedResourceBundle.java util/resources/Loader.java
Date Tue, 23 Oct 2012 11:07:47 GMT
Author: desruisseaux
Date: Tue Oct 23 11:07:46 2012
New Revision: 1401244

URL: http://svn.apache.org/viewvc?rev=1401244&view=rev
Log:
Use Exception.getMessage() or getLocalizedMessage() depending if the message is targeted to
system administrator or end user.

Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Loader.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java?rev=1401244&r1=1401243&r2=1401244&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java Tue Oct
23 11:07:46 2012
@@ -90,7 +90,13 @@ public class Angle implements Comparable
                 angle = getAngleFormat().parseObject(string);
             }
         } catch (ParseException exception) {
-            NumberFormatException e = new NumberFormatException(exception.getLocalizedMessage());
+            /*
+             * Use Exception.getMessage() instead than getLocalizedMessage() because the
later
+             * is formatted in the AngleFormat locale, which is hard-coded to Locale.CANADA
in
+             * our 'getAngleFormat()' implementation. The getMessage() method uses the system
+             * locale, which is what we actually want.
+             */
+            NumberFormatException e = new NumberFormatException(exception.getMessage());
             e.initCause(exception);
             throw e;
         }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1401244&r1=1401243&r2=1401244&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java Tue
Oct 23 11:07:46 2012
@@ -543,9 +543,13 @@ public final class Logging extends Stati
          * Now prepare the log message. If we have been unable to figure out a source class
and
          * method name, we will fallback on JDK logging default mechanism, which may returns
a
          * less relevant name than our attempt to use the logger name as the package name.
+         *
+         * The message is fetched using Exception.getMessage() instead than getLocalizedMessage()
+         * because in a client-server architecture, we want the locale on the server-side
instead
+         * than the locale on the client side.
          */
         final StringBuilder buffer = new StringBuilder(Classes.getShortClassName(error));
-        String message = error.getLocalizedMessage();
+        String message = error.getMessage(); // Targeted to system administrators.
         if (message != null) {
             buffer.append(": ").append(message);
         }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java?rev=1401244&r1=1401243&r2=1401244&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
Tue Oct 23 11:07:46 2012
@@ -38,6 +38,7 @@ import org.opengis.util.InternationalStr
 
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.Classes;
+import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.logging.Logging;
 
@@ -389,11 +390,12 @@ public class IndexedResourceBundle exten
             return values;
         } catch (IOException exception) {
             record.setLevel  (Level.WARNING);
-            record.setMessage(exception.getLocalizedMessage());
+            record.setMessage(exception.getMessage()); // For administrator, use system locale.
             record.setThrown (exception);
             Logging.log(IndexedResourceBundle.class, methodName, record);
             final MissingResourceException error = new MissingResourceException(
-                    exception.getLocalizedMessage(), getClass().getCanonicalName(), key);
+                    Exceptions.getMessage(exception, getLocale()), // For users, use requested
locale.
+                    getClass().getCanonicalName(), key);
             error.initCause(exception);
             throw error;
         }
@@ -463,7 +465,7 @@ public class IndexedResourceBundle exten
                 }
                 replacement = CharSequences.shortSentence(text, MAX_STRING_LENGTH);
             } else if (element instanceof Throwable) {
-                String message = ((Throwable) element).getLocalizedMessage();
+                String message = Exceptions.getMessage((Throwable) element, getFormatLocale());
                 if (message == null) {
                     message = Classes.getShortClassName(element);
                 }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Loader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Loader.java?rev=1401244&r1=1401243&r2=1401244&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Loader.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Loader.java
Tue Oct 23 11:07:46 2012
@@ -23,6 +23,7 @@ import java.util.ResourceBundle;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.io.IOException;
+import org.apache.sis.util.Exceptions;
 
 
 /**
@@ -119,29 +120,16 @@ final class Loader extends ResourceBundl
         /*
          * If the file exists, instantiate now the resource bundle. Note that the constructor
          * will not loads the data immediately, which is why we don't pass it the above URL.
+         *
+         * Note: Do not call Constructor.setAccessible(true) - this is not allowed in Applet.
          */
         final Constructor<?> c;
         try {
-            c = classe.getDeclaredConstructor(String.class);
-        } catch (NoSuchMethodException e) {
-            throw instantiationFailure(e);
+            return (ResourceBundle) classe.getDeclaredConstructor(String.class).newInstance(filename);
+        } catch (NoSuchMethodException | InvocationTargetException e) {
+            InstantiationException exception = new InstantiationException(Exceptions.getMessage(e,
locale));
+            exception.initCause(e);
+            throw exception;
         }
-        final ResourceBundle bundle;
-        // Do not call c.setAccessible(true) - this is not allowed in Applet.
-        try {
-            bundle = (ResourceBundle) c.newInstance(filename);
-        } catch (InvocationTargetException e) {
-            throw instantiationFailure(e);
-        }
-        return bundle;
-    }
-
-    /**
-     * Creates an exception for a resource bundle that can not be created.
-     */
-    private static InstantiationException instantiationFailure(final Exception cause) {
-        InstantiationException exception = new InstantiationException(cause.getLocalizedMessage());
-        exception.initCause(cause);
-        return exception;
     }
 }



Mime
View raw message