Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 39590 invoked from network); 20 Feb 2005 18:14:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 20 Feb 2005 18:14:54 -0000 Received: (qmail 3742 invoked by uid 500); 20 Feb 2005 18:14:53 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 3334 invoked by uid 500); 20 Feb 2005 18:14:52 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 3321 invoked by uid 500); 20 Feb 2005 18:14:51 -0000 Received: (qmail 3318 invoked by uid 99); 20 Feb 2005 18:14:51 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 20 Feb 2005 10:14:51 -0800 Received: (qmail 39484 invoked by uid 65534); 20 Feb 2005 18:14:50 -0000 Message-ID: <20050220181450.39483.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Sun, 20 Feb 2005 18:14:50 -0000 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/ To: commons-cvs@jakarta.apache.org From: dflorey@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: dflorey Date: Sun Feb 20 10:14:48 2005 New Revision: 154554 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D154554 Log: Javadocs added Added: jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/example= s/LocalizedExceptionExample.java - copied, changed from r154315, jakarta/commons/sandbox/i18n/trunk/sr= c/examples/org/apache/i18n/examples/ResourceBundleExample.java jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bun= dles/MessageBundle.java Removed: jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/example= s/ResourceBundleExample.java Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/Mes= sageManager.java jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/Res= ourceBundleMessageProvider.java jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bun= dles/ErrorBundle.java Copied: jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/exa= mples/LocalizedExceptionExample.java (from r154315, jakarta/commons/sandbox= /i18n/trunk/src/examples/org/apache/i18n/examples/ResourceBundleExample.jav= a) URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/e= xamples/org/apache/i18n/examples/LocalizedExceptionExample.java?view=3Ddiff= &rev=3D154554&p1=3Djakarta/commons/sandbox/i18n/trunk/src/examples/org/apac= he/i18n/examples/ResourceBundleExample.java&r1=3D154315&p2=3Djakarta/common= s/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/LocalizedExcepti= onExample.java&r2=3D154554 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/example= s/ResourceBundleExample.java (original) +++ jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/example= s/LocalizedExceptionExample.java Sun Feb 20 10:14:48 2005 @@ -20,19 +20,52 @@ package org.apache.i18n.examples; =20 import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; =20 +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; =20 /** * @author Daniel Florey * */ -public class ResourceBundleExample { +public class LocalizedExceptionExample { + private static final Logger logger =3D Logger.getLogger(LocalizedExcep= tionExample.class.getName()); + public static void main(String[] args) { XMLMessageProvider.install("org.apache.commons-i18n.test", Thread.= currentThread().getContextClassLoader().getResourceAsStream("testMessages.x= ml")); - MessageBundle xmlMessage =3D new MessageBundle("helloWorld"); - System.out.println(xmlMessage.getTitle(Locale.GERMAN)); - System.out.println(xmlMessage.getText(Locale.GERMAN)); + + Locale currentUsersLocale =3D Locale.GERMAN; + =20 + // Dealing with localized exceptions + try { + someMethodThrowingAnException(); + } catch ( LocalizedException exception ) { + ErrorBundle errorMessage =3D 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.getDef= ault())); + // Print the details of this error to the log with level FINE + // using the VM default locale: + logger.log(Level.FINE, errorMessage.getDetails(Locale.getDefau= lt())); + // Provide the title of this error to the user in a highly vis= ible way + // using the current users locale: + System.out.println("#### "+errorMessage.getTitle(currentUsersL= ocale)+" ####"); + // 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 LocalizedEx= ception { + String userCausingTheException =3D "Daniel"; + throw new LocalizedException( + new ErrorBundle("theCauseOfThisException", + new String[] { userCausingTheException } )); } } Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i1= 8n/MessageManager.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/j= ava/org/apache/commons/i18n/MessageManager.java?view=3Ddiff&r1=3D154553&r2= =3D154554 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/Mes= sageManager.java (original) +++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/Mes= sageManager.java Sun Feb 20 10:14:48 2005 @@ -49,8 +49,6 @@ * exists and to deal with the {@link MessageNotFound} exception that will=20 * be thrown if you try to access a not existing entry.

*=20 - * @author Daniel Florey - *=20 */ public class MessageManager { static final String INTERNAL_MESSAGE_NOT_FOUND =3D "Internal I18n erro= r: Message not found"; Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i1= 8n/ResourceBundleMessageProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/j= ava/org/apache/commons/i18n/ResourceBundleMessageProvider.java?view=3Ddiff&= r1=3D154553&r2=3D154554 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/Res= ourceBundleMessageProvider.java (original) +++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/Res= ourceBundleMessageProvider.java Sun Feb 20 10:14:48 2005 @@ -33,7 +33,6 @@ import java.util.logging.Logger; =20 /** - * @author Daniel Florey * */ public class ResourceBundleMessageProvider implements MessageProvider { Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i1= 8n/bundles/ErrorBundle.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/j= ava/org/apache/commons/i18n/bundles/ErrorBundle.java?view=3Ddiff&r1=3D15455= 3&r2=3D154554 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bun= dles/ErrorBundle.java (original) +++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bun= dles/ErrorBundle.java Sun Feb 20 10:14:48 2005 @@ -33,8 +33,7 @@ * exceptions.

* */ -public class ErrorBundle extends TextBundle { - public final static String TITLE =3D "title"; +public class ErrorBundle extends MessageBundle { public final static String SUMMARY =3D "summary"; public final static String DETAILS =3D "details"; =20 @@ -53,26 +52,6 @@ public ErrorBundle(String messageId, Object[] arguments) { super(messageId, arguments); } - - - /** - * @param locale The locale that is used to find the appropriate local= ized text=20 - * @return returns the localized message entry with the key titl= e - * @throws MessageNotFoundException is thrown if no entry with key title could be found in the message bundle identified by the give= n message identifier - */ - public String getTitle(Locale locale) throws MessageNotFoundException = { - return getEntry(TITLE, locale); - } - - /** - * @param locale The locale that is used to find the appropriate local= ized text=20 - * @param defaultText The default text will be returned, if no entry w= ith key title could be found in the message bundle identified = by the given message identifier - * @return returns the localized message entry with the key titl= e - */ - public String getTitle(Locale locale, String defaultSummary) { - return getEntry(TITLE, defaultSummary, locale); - } - =20 /** * @param locale The locale that is used to find the appropriate local= ized text=20 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/j= ava/org/apache/commons/i18n/bundles/MessageBundle.java?view=3Dauto&rev=3D15= 4554 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bun= dles/MessageBundle.java (added) +++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bun= dles/MessageBundle.java Sun Feb 20 10:14:48 2005 @@ -0,0 +1,71 @@ +/* + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jak= arta-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) $ + * + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * Copyright 2004 The Apache Software Foundation=20 + * + * 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; + + +/** + *

The MessageBundle groups together title and text.

+ * + */ +public class MessageBundle extends TextBundle { + public final static String TITLE =3D "title"; + + /** + * @param messageId Unique message id that identifies the message=20 + */ + public MessageBundle(String messageId) { + super(messageId); + } + + /** + * @param messageId Unique message id that identifies the message=20 + * @param arguments An array of objects conaining the values that shou= ld be + * inserted into the localized message. =20 + */ + public MessageBundle(String messageId, Object[] arguments) { + super(messageId, arguments); + } + + + /** + * @param locale The locale that is used to find the appropriate local= ized text=20 + * @return returns the localized message entry with the key titl= e + * @throws MessageNotFoundException is thrown if no entry with key title could be found in the message bundle identified by the give= n message identifier + */ + public String getTitle(Locale locale) throws MessageNotFoundException = { + return getEntry(TITLE, locale); + } + + /** + * @param locale The locale that is used to find the appropriate local= ized text=20 + * @param defaultText The default text will be returned, if no entry w= ith key title could be found in the message bundle identified = by the given message identifier + * @return returns the localized message entry with the key titl= e + */ + 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