commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dflo...@apache.org
Subject svn commit: r154554 - in jakarta/commons/sandbox/i18n/trunk/src: examples/org/apache/i18n/examples/ java/org/apache/commons/i18n/ java/org/apache/commons/i18n/bundles/
Date Sun, 20 Feb 2005 18:14:50 GMT
Author: dflorey
Date: Sun Feb 20 10:14:48 2005
New Revision: 154554

URL: http://svn.apache.org/viewcvs?view=rev&rev=154554
Log:
Javadocs added

Added:
    jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/LocalizedExceptionExample.java
      - copied, changed from r154315, jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/ResourceBundleExample.java
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java
Removed:
    jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/ResourceBundleExample.java
Modified:
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java

Copied: jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/LocalizedExceptionExample.java
(from r154315, jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/ResourceBundleExample.java)
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/LocalizedExceptionExample.java?view=diff&rev=154554&p1=jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/ResourceBundleExample.java&r1=154315&p2=jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/LocalizedExceptionExample.java&r2=154554
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/ResourceBundleExample.java
(original)
+++ jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/LocalizedExceptionExample.java
Sun Feb 20 10:14:48 2005
@@ -20,19 +20,52 @@
 package org.apache.i18n.examples;
 
 import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
+import org.apache.commons.i18n.LocalizedException;
 import org.apache.commons.i18n.XMLMessageProvider;
-import org.apache.commons.i18n.bundles.MessageBundle;
+import org.apache.commons.i18n.bundles.ErrorBundle;
 
 /**
  * @author Daniel Florey
  *
  */
-public class ResourceBundleExample {
+public class LocalizedExceptionExample {
+    private static final Logger logger = Logger.getLogger(LocalizedExceptionExample.class.getName());
+
     public static void main(String[] args) {
         XMLMessageProvider.install("org.apache.commons-i18n.test", Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
-        MessageBundle xmlMessage = new MessageBundle("helloWorld");
-        System.out.println(xmlMessage.getTitle(Locale.GERMAN));
-        System.out.println(xmlMessage.getText(Locale.GERMAN));
+
+        Locale currentUsersLocale = Locale.GERMAN;
+        
+        // Dealing with localized exceptions
+        try {
+            someMethodThrowingAnException();
+        } catch ( LocalizedException exception ) {
+            ErrorBundle errorMessage = exception.getErrorMessage();
+            // Print the summary of this error to the log with level SEVERE
+            // using the VM default locale:
+            logger.log(Level.SEVERE, errorMessage.getSummary(Locale.getDefault()));
+            // Print the details of this error to the log with level FINE
+            // using the VM default locale:
+            logger.log(Level.FINE, errorMessage.getDetails(Locale.getDefault()));
+            // Provide the title of this error to the user in a highly visible way
+            // using the current users locale:
+            System.out.println("#### "+errorMessage.getTitle(currentUsersLocale)+" ####");
+            // Provide the text of this error to the user
+            // using the current users locale:
+            System.out.println(errorMessage.getText(currentUsersLocale));
+        }
+    }
+
+    /**
+     * @throws LocalizedException is thrown just to show the capabilities of LocalizedExceptions
+     */
+    private static void someMethodThrowingAnException() throws LocalizedException {
+        String userCausingTheException = "Daniel";
+        throw new LocalizedException(
+                new ErrorBundle("theCauseOfThisException",
+                new String[] { userCausingTheException } ));
     }
 }

Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java?view=diff&r1=154553&r2=154554
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java
(original)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java
Sun Feb 20 10:14:48 2005
@@ -49,8 +49,6 @@
  * exists and to deal with the {@link MessageNotFound} exception that will 
  * be thrown if you try to access a not existing entry.</p>
  * 
- * @author Daniel Florey
- * 
  */
 public class MessageManager {
     static final String INTERNAL_MESSAGE_NOT_FOUND = "Internal I18n error: Message not found";

Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java?view=diff&r1=154553&r2=154554
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java
(original)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java
Sun Feb 20 10:14:48 2005
@@ -33,7 +33,6 @@
 import java.util.logging.Logger;
 
 /**
- * @author Daniel Florey
  *
  */
 public class ResourceBundleMessageProvider implements MessageProvider {

Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java?view=diff&r1=154553&r2=154554
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java
(original)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java
Sun Feb 20 10:14:48 2005
@@ -33,8 +33,7 @@
  * exceptions.</p>
  *
  */
-public class ErrorBundle extends TextBundle {
-    public final static String TITLE = "title";
+public class ErrorBundle extends MessageBundle {
     public final static String SUMMARY = "summary";
     public final static String DETAILS = "details";
 
@@ -53,26 +52,6 @@
     public ErrorBundle(String messageId, Object[] arguments) {
         super(messageId, arguments);
     }
-
-
-    /**
-     * @param locale The locale that is used to find the appropriate localized text 
-     * @return returns the localized message entry with the key <code>title</code>
-     * @throws MessageNotFoundException is thrown if no entry with key <code>title</code>
could be found in the message bundle identified by the given message identifier
-     */
-    public String getTitle(Locale locale) throws MessageNotFoundException {
-        return getEntry(TITLE, locale);
-    }
-
-    /**
-     * @param locale The locale that is used to find the appropriate localized text 
-     * @param defaultText The default text will be returned, if no entry with key <code>title</code>
could be found in the message bundle identified by the given message identifier
-     * @return returns the localized message entry with the key <code>title</code>
-     */
-    public String getTitle(Locale locale, String defaultSummary) {
-        return getEntry(TITLE, defaultSummary, locale);
-    }
-
 
     /**
      * @param locale The locale that is used to find the appropriate localized text 

Added: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java?view=auto&rev=154554
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java
(added)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java
Sun Feb 20 10:14:48 2005
@@ -0,0 +1,71 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons-sandbox//i18n/src/java/org/apache/commons/i18n/LocalizedError.java,v
1.1 2004/10/04 13:41:09 dflorey Exp $
+ * $Revision: 1.1 $
+ * $Date: 2005-02-14 20:03:07 +0100 (Mo, 14 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * Copyright 2004 The Apache Software Foundation 
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.commons.i18n.bundles;
+
+import java.util.Locale;
+
+import org.apache.commons.i18n.MessageNotFoundException;
+
+
+/**
+ * <p>The <code>MessageBundle</code> groups together title and text.</p>
+ *
+ */
+public class MessageBundle extends TextBundle {
+    public final static String TITLE = "title";
+
+    /**
+     * @param messageId Unique message id that identifies the message 
+     */
+    public MessageBundle(String messageId) {
+        super(messageId);
+    }
+
+    /**
+     * @param messageId Unique message id that identifies the message 
+     * @param arguments An array of objects conaining the values that should be
+     * inserted into the localized message.  
+     */
+    public MessageBundle(String messageId, Object[] arguments) {
+        super(messageId, arguments);
+    }
+
+
+    /**
+     * @param locale The locale that is used to find the appropriate localized text 
+     * @return returns the localized message entry with the key <code>title</code>
+     * @throws MessageNotFoundException is thrown if no entry with key <code>title</code>
could be found in the message bundle identified by the given message identifier
+     */
+    public String getTitle(Locale locale) throws MessageNotFoundException {
+        return getEntry(TITLE, locale);
+    }
+
+    /**
+     * @param locale The locale that is used to find the appropriate localized text 
+     * @param defaultText The default text will be returned, if no entry with key <code>title</code>
could be found in the message bundle identified by the given message identifier
+     * @return returns the localized message entry with the key <code>title</code>
+     */
+    public String getTitle(Locale locale, String defaultSummary) {
+        return getEntry(TITLE, defaultSummary, locale);
+    }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message