001 /*
002 * Copyright 2010-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package griffon.core.i18n;
018
019 import java.util.List;
020 import java.util.Locale;
021 import java.util.Map;
022
023 /**
024 * Interface for resolving messages, with support for the parameterization and internationalization of such messages.
025 *
026 * @author Andres Almiray
027 * @author Alexander Klein
028 * @since 1.1.0
029 */
030 public interface MessageSource {
031 /**
032 * Try to resolve the message.
033 *
034 * @param key Key to lookup, such as 'log4j.appenders.console'
035 * @return The resolved message at the given key for the default locale
036 * @throws NoSuchMessageException if no message is found
037 */
038 String getMessage(String key) throws NoSuchMessageException;
039
040 /**
041 * Try to resolve the message.
042 *
043 * @param key Key to lookup, such as 'log4j.appenders.console'
044 * @param locale Locale in which to lookup
045 * @return The resolved message at the given key for the given locale
046 * @throws NoSuchMessageException if no message is found
047 */
048 String getMessage(String key, Locale locale) throws NoSuchMessageException;
049
050 /**
051 * Try to resolve the message.
052 *
053 * @param key Key to lookup, such as 'log4j.appenders.console'
054 * @param args Arguments that will be filled in for params within the message (params look like "{0}" within a
055 * message, but this might differ between implementations), or null if none.
056 * @return The resolved message at the given key for the default locale
057 * @throws NoSuchMessageException if no message is found
058 */
059 String getMessage(String key, Object[] args) throws NoSuchMessageException;
060
061 /**
062 * Try to resolve the message.
063 *
064 * @param key Key to lookup, such as 'log4j.appenders.console'
065 * @param args Arguments that will be filled in for params within the message (params look like "{0}" within a
066 * message, but this might differ between implementations), or null if none.
067 * @param locale Locale in which to lookup
068 * @return The resolved message at the given key for the given locale
069 * @throws NoSuchMessageException if no message is found
070 */
071 String getMessage(String key, Object[] args, Locale locale) throws NoSuchMessageException;
072
073 /**
074 * Try to resolve the message.
075 *
076 * @param key Key to lookup, such as 'log4j.appenders.console'
077 * @param args Arguments that will be filled in for params within the message (params look like "{0}" within a
078 * message, but this might differ between implementations), or null if none.
079 * @return The resolved message at the given key for the default locale
080 * @throws NoSuchMessageException if no message is found
081 */
082 String getMessage(String key, List args) throws NoSuchMessageException;
083
084 /**
085 * Try to resolve the message.
086 *
087 * @param key Key to lookup, such as 'log4j.appenders.console'
088 * @param args Arguments that will be filled in for params within the message (params look like "{0}" within a
089 * message, but this might differ between implementations), or null if none.
090 * @param locale Locale in which to lookup
091 * @return The resolved message at the given key for the given locale
092 * @throws NoSuchMessageException if no message is found
093 */
094 String getMessage(String key, List args, Locale locale) throws NoSuchMessageException;
095
096 /**
097 * Try to resolve the message. Return default message if no message was found.
098 *
099 * @param key Key to lookup, such as 'log4j.appenders.console'
100 * @param defaultMessage Message to return if the lookup fails
101 * @return The resolved message at the given key for the default locale
102 */
103 String getMessage(String key, String defaultMessage);
104
105 /**
106 * Try to resolve the message. Return default message if no message was found.
107 *
108 * @param key Key to lookup, such as 'log4j.appenders.console'
109 * @param defaultMessage Message to return if the lookup fails
110 * @param locale Locale in which to lookup
111 * @return The resolved message at the given key for the given locale
112 */
113 String getMessage(String key, String defaultMessage, Locale locale);
114
115 /**
116 * Try to resolve the message. Return default message if no message was found.
117 *
118 * @param key Key to lookup, such as 'log4j.appenders.console'
119 * @param args Arguments that will be filled in for params within the message (params look like "{0}"
120 * within a message, but this might differ between implementations), or null if none.
121 * @param defaultMessage Message to return if the lookup fails
122 * @return The resolved message at the given key for the default locale
123 */
124 String getMessage(String key, Object[] args, String defaultMessage);
125
126 /**
127 * Try to resolve the message. Return default message if no message was found.
128 *
129 * @param key Key to lookup, such as 'log4j.appenders.console'
130 * @param args Arguments that will be filled in for params within the message (params look like "{0}"
131 * within a message, but this might differ between implementations), or null if none.
132 * @param defaultMessage Message to return if the lookup fails
133 * @param locale Locale in which to lookup
134 * @return The resolved message at the given key for the given locale
135 */
136 String getMessage(String key, Object[] args, String defaultMessage, Locale locale);
137
138 /**
139 * Try to resolve the message. Return default message if no message was found.
140 *
141 * @param key Key to lookup, such as 'log4j.appenders.console'
142 * @param args Arguments that will be filled in for params within the message (params look like "{0}"
143 * within a message, but this might differ between implementations), or null if none.
144 * @param defaultMessage Message to return if the lookup fails
145 * @return The resolved message at the given key for the default locale
146 */
147 String getMessage(String key, List args, String defaultMessage);
148
149 /**
150 * Try to resolve the message. Return default message if no message was found.
151 *
152 * @param key Key to lookup, such as 'log4j.appenders.console'
153 * @param args Arguments that will be filled in for params within the message (params look like "{0}"
154 * within a message, but this might differ between implementations), or null if none.
155 * @param defaultMessage Message to return if the lookup fails
156 * @param locale Locale in which to lookup
157 * @return The resolved message at the given key for the given locale
158 */
159 String getMessage(String key, List args, String defaultMessage, Locale locale);
160
161 /**
162 * Try to resolve the message.
163 *
164 * @param key Key to lookup, such as 'log4j.appenders.console'
165 * @param args Arguments that will be filled in for params within the message (params look like "{:key}"
166 * within a message, but this might differ between implementations), or null if none.
167 * @return The resolved message at the given key for the default locale
168 * @throws NoSuchMessageException if no message is found
169 */
170 String getMessage(String key, Map<String, Object> args) throws NoSuchMessageException;
171
172 /**
173 * Try to resolve the message.
174 *
175 * @param key Key to lookup, such as 'log4j.appenders.console'
176 * @param args Arguments that will be filled in for params within the message (params look like "{:key}"
177 * within a message, but this might differ between implementations), or null if none.
178 * @param locale Locale in which to lookup
179 * @return The resolved message at the given key for the given locale
180 * @throws NoSuchMessageException if no message is found
181 */
182 String getMessage(String key, Map<String, Object> args, Locale locale) throws NoSuchMessageException;
183
184 /**
185 * Try to resolve the message. Return default message if no message was found.
186 *
187 * @param key Key to lookup, such as 'log4j.appenders.console'
188 * @param args Arguments that will be filled in for params within the message (params look like "{:key}"
189 * within a message, but this might differ between implementations), or null if none.
190 * @param defaultMessage Message to return if the lookup fails
191 * @return The resolved message at the given key for the default locale
192 */
193 String getMessage(String key, Map<String, Object> args, String defaultMessage);
194
195 /**
196 * Try to resolve the message. Return default message if no message was found.
197 *
198 * @param key Key to lookup, such as 'log4j.appenders.console'
199 * @param args Arguments that will be filled in for params within the message (params look like "{:key}"
200 * within a message, but this might differ between implementations), or null if none.
201 * @param defaultMessage Message to return if the lookup fails
202 * @param locale Locale in which to lookup
203 * @return The resolved message at the given key for the given locale
204 */
205 String getMessage(String key, Map<String, Object> args, String defaultMessage, Locale locale);
206 }
|