| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||
| TrailsMessageSource |
|
| 1.0;1 |
| 1 | /* |
|
| 2 | * Created on 25/11/2005 by Eduardo Piva - eduardo@gwe.com.br |
|
| 3 | * |
|
| 4 | */ |
|
| 5 | package org.trails.i18n; |
|
| 6 | ||
| 7 | import java.util.Locale; |
|
| 8 | ||
| 9 | import org.trails.descriptor.IClassDescriptor; |
|
| 10 | import org.trails.descriptor.IDescriptor; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * Interface used to imlement i18n in Trails pages and components. |
|
| 14 | */ |
|
| 15 | public interface TrailsMessageSource |
|
| 16 | { |
|
| 17 | ||
| 18 | Object[] EMPTY_ARGUMENTS = new Object[]{}; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Return a internationalized message. |
|
| 22 | * |
|
| 23 | * @param key Key used to locate the message. |
|
| 24 | * @return Localized message. Return null if message not found. |
|
| 25 | */ |
|
| 26 | public String getMessage(String key); |
|
| 27 | ||
| 28 | /** |
|
| 29 | * Return a internationalized message specifing arguments to format this message. |
|
| 30 | * |
|
| 31 | * @param key Key used to locate the message. |
|
| 32 | * @param args Arguments to format the message. |
|
| 33 | * @return Localized message. Return null of message not found. |
|
| 34 | */ |
|
| 35 | public String getMessage(String key, Object[] args); |
|
| 36 | ||
| 37 | /** |
|
| 38 | * Same as getMessage(String key), but it will return a default value instead of null if message not found. |
|
| 39 | * |
|
| 40 | * @param defaultMessage Default message to return if message not found. |
|
| 41 | */ |
|
| 42 | public String getMessageWithDefaultValue(String key, String defaultMessage); |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Same as getMessage(String key, Object[] args), but will return a default value instead of null if message not |
|
| 46 | * found. |
|
| 47 | * |
|
| 48 | * @param defaultMessage Default message to return if message not found. |
|
| 49 | */ |
|
| 50 | public String getMessageWithDefaultValue(String key, Object[] args, String defaultMessage); |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Given a IDescriptor, this method select an i18n message for the descriptor. If no i18n message is found, a |
|
| 54 | * defaultMessage is used instead. |
|
| 55 | * |
|
| 56 | * @param clazz Class description. |
|
| 57 | * @param defaultDisplayName default displayName to return if no i18n message is found. |
|
| 58 | * @return |
|
| 59 | */ |
|
| 60 | public String getDisplayName(IDescriptor clazz, String defaultDisplayName); |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Given a IClassDescriptor and a Locale, this method select an i18n message for the class in the plural name |
|
| 64 | * |
|
| 65 | * @param clazz Class description |
|
| 66 | * @param defaultDisplayName default displayName to return if no i18n message is found. |
|
| 67 | * @return |
|
| 68 | */ |
|
| 69 | public String getPluralDislayName(IClassDescriptor clazz, String defaultDisplayName); |
|
| 70 | ||
| 71 | ||
| 72 | /** |
|
| 73 | * Return a internationalized message. |
|
| 74 | * <p/> |
|
| 75 | * Sometimes it makes sense to force a Locale, but don't overuse this method. |
|
| 76 | * |
|
| 77 | * @param key Key used to locate the message. |
|
| 78 | * @param locale Locale used to locate message. |
|
| 79 | * @return Localized message. Return null if message not found. |
|
| 80 | */ |
|
| 81 | public String getMessage(String key, Locale locale); |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Return a internationalized message specifing arguments to format this message. |
|
| 85 | * <p/> |
|
| 86 | * Sometimes it makes sense to force a Locale, but don't overuse this method. |
|
| 87 | * |
|
| 88 | * @param key Key used to locate the message. |
|
| 89 | * @param args Arguments to format the message. |
|
| 90 | * @param locale Locale used to locate message. |
|
| 91 | * @return Localized message. Return null of message not found. |
|
| 92 | */ |
|
| 93 | public String getMessage(String key, Object[] args, Locale locale); |
|
| 94 | ||
| 95 | public String getMessageWithDefaultValue(String key, Locale locale, String defaultMessage); |
|
| 96 | public String getMessageWithDefaultValue(String key, Object[] args, Locale locale, String defaultMessage); |
|
| 97 | } |