View Javadoc

1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons-sandbox//i18n/src/java/org/apache/commons/i18n/LocalizedBundle.java,v 1.3 2004/12/29 17:03:55 dflorey Exp $
3    * $Revision: 1.3 $
4    * $Date: 2004-12-29 18:03:55 +0100 (Mi, 29 Dez 2004) $
5    *
6    * ====================================================================
7    *
8    * Copyright 2004 The Apache Software Foundation 
9    *
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   *
14   *     http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   *
22   */
23  
24  package org.apache.commons.i18n;
25  
26  import java.io.Serializable;
27  import java.util.Locale;
28  
29  /***
30   * @author Daniel Florey
31   * 
32   * The <code>LocalizedBundle</code> class represents a bundle of localized messages that
33   * belong together.
34   * The <code>LocalizedBundle</code> class itself contains the message id and the arguments
35   * that might be used to include dynamic values into the message text and knows nothing
36   * 
37   */
38  public class LocalizedBundle implements Serializable {
39      public final static String ID = "id";
40      public final static String ARGUMENTS = "arguments";
41  
42      protected String id;
43      protected Object[] arguments;
44  
45      /***
46       * @param messageId The messageId refers the corresponding bundle in the file containing
47       * the localized messages. The format of the message file depends on the implementation of the 
48       * MessageManager.
49       */
50      public LocalizedBundle(String messageId) {
51          this.id = messageId;
52          this.arguments = new Object[0];
53      }
54  
55      /***
56       * @param messageId The messageId refers the corresponding bundle in the file containing
57       * the localized messages. The format of the message file depends on the implementation of the 
58       * MessageManager.
59       * @param arguments An array of objects containing argument for the messages. These arguments
60       * are used to insert dynamic values into the localized messages.
61       */
62      public LocalizedBundle(String messageId, Object[] arguments) {
63          this.id = messageId;
64          this.arguments = arguments;
65      }
66  
67      /***
68       * @return returns the id of this bundle
69       */
70      public String getId() {
71          return id;
72      }
73  
74      /***
75       * @return returns the arguments associated with this message bundle
76       */
77      public Object[] getArguments() {
78      	return arguments;
79      }
80      
81      /***
82       * @param key the key of the specific message entry in the message bundle
83       * @param locale the locale for that this message should be rendered
84       * @return returns the localized text  
85       * @throws MessageNotFoundException if an entry with the given key can not be found
86       * in this bundle
87       */
88      public String getText(String key, Locale locale) throws MessageNotFoundException {
89          return MessageManager.getText(id, key, arguments, locale);
90      }
91  
92      /***
93       * @param key the key of the specific message entry in the message bundle
94       * @param locale the locale for that this message should be rendered
95       * @param defaultText the text to be returned if no entry was found for the given key
96       * @return returns the localized text  
97       */
98      public String getText(String key, String defaultText, Locale locale) {
99          return MessageManager.getText(id, key, arguments, locale, defaultText);
100     }
101 }