Package org.openhab.core.i18n
Class AbstractI18nException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.openhab.core.i18n.AbstractI18nException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
CommunicationException
,ConfigurationException
Provides an exception class for openHAB that incorporates support for internationalization
- Author:
- Laurent Garnier - Initial contribution
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractI18nException
(String message, @Nullable Object @Nullable ... msgParams) protected
AbstractI18nException
(String message, @Nullable Throwable cause, @Nullable Object @Nullable ... msgParams) protected
AbstractI18nException
(Throwable cause) -
Method Summary
Modifier and TypeMethodDescription@Nullable String
getLocalizedMessage
(@Nullable org.osgi.framework.Bundle bundle, @Nullable TranslationProvider i18nProvider, @Nullable Locale locale) Returns a localized description of this exception.@Nullable String
getMessage
(@Nullable org.osgi.framework.Bundle bundle, @Nullable TranslationProvider i18nProvider) Returns the detail message string of this exception.@Nullable String
Provides the raw message If the message does not start with "@text/", it returns the same as the getMessage() method.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
AbstractI18nException
- Parameters:
message
- the exception message; use "@text/key" to reference "key" entry in the properties filemsgParams
- the optional arguments of the message defined in the properties file
-
AbstractI18nException
protected AbstractI18nException(String message, @Nullable Throwable cause, @Nullable Object @Nullable ... msgParams) - Parameters:
message
- the exception message; use "@text/key" to reference "key" entry in the properties filecause
- the cause (which is saved for later retrieval by the getCause() method). A null value is permitted, and indicates that the cause is nonexistent or unknown.msgParams
- the optional arguments of the message defined in the properties file
-
AbstractI18nException
- Parameters:
cause
- the cause (which is saved for later retrieval by the getCause() method).
-
-
Method Details
-
getMessage
public @Nullable String getMessage(@Nullable org.osgi.framework.Bundle bundle, @Nullable TranslationProvider i18nProvider) Returns the detail message string of this exception. In case the message starts with "@text/" and the parameters bundle and i18nProvider are not null, the translation provider is used to look for the message key in the English properties file of the provided bundle.- Parameters:
bundle
- the bundle containing the i18n propertiesi18nProvider
- the translation provider- Returns:
- the detail message string of this exception instance (which may be null)
-
getLocalizedMessage
public @Nullable String getLocalizedMessage(@Nullable org.osgi.framework.Bundle bundle, @Nullable TranslationProvider i18nProvider, @Nullable Locale locale) Returns a localized description of this exception. In case the message starts with "@text/" and the parameters bundle and i18nProvider are not null, the translation provider is used to look for the message key in the properties file of the provided bundle containing strings for the requested language. English language is considered if no language is provided.- Parameters:
bundle
- the bundle containing the i18n propertiesi18nProvider
- the translation providerlocale
- the language to use for localizing the message- Returns:
- the localized description of this exception instance (which may be null)
-
getRawMessage
Provides the raw message If the message does not start with "@text/", it returns the same as the getMessage() method. If the message starts with "@text/" and no optional arguments are set, it returns a string of this kind: @text/key If the message starts with "@text/" and optional arguments are set, it returns a string of this kind: @text/key [ "param1", "param2" ]- Returns:
- the raw message or null if the message is undefined
-