*/
protected String determinePrincipalName () {
// Get principal
- Principal userPrincipal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
+ final Principal userPrincipal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
// Init with null
String principalName = null;
*/
protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException {
// Get context parameter
- Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey));
+ final Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey));
+
// Return it
return contextValue;
}
+ /**
+ * Returns a message based on given i18nKey or puts it into three question
+ * marks each side when not found.
+ * <p>
+ * @param i18nKey I18n key
+ * <p>
+ * @return Localized message
+ */
+ protected String getMessageFromBundle (final String i18nKey) {
+ // Validate parameter
+ if (null == i18nKey) {
+ // Throw NPE
+ throw new NullPointerException("i18nKey is null"); //NOI18N
+ } else if (i18nKey.isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("i18nKey is null"); //NOI18N
+ }
+
+ // Get current locale
+ final Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
+
+ // Get bundle bundle
+ final ResourceBundle bundle = this.loadResourceBundle(locale);
+
+ // Default is i18nKey
+ String message = MessageFormat.format("???{0}???", i18nKey); //NOI18N
+
+ // Try it
+ try {
+ // Get message
+ message = bundle.getString(i18nKey);
+ } catch (final MissingResourceException ex) {
+ // Did not find it, ignored
+ }
+
+ // Return it
+ return message;
+ }
+
/**
* Returns given property key or throws an exception if not found.
* <p>
*/
protected String getStringContextParameter (final String parameterKey) throws NullPointerException {
// Get context parameter
- String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey);
+ final String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey);
+
// Is it null?
if (null == contextValue) {
// Throw NPE
throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N
}
+
// Return it
return contextValue;
}
// Is empty
throw new IllegalArgumentException("controllerName is empty"); //NOI18N
}
+
// Try to get context parameter
- String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N
+ final String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N
+
// Is it set and true?
- boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE;
+ final boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE;
+
// Return it
return isEnabled;
}
// Is empty
throw new IllegalArgumentException("i18nKey is null"); //NOI18N
}
- // Get current locale
- Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
- // Get bundle bundle
- ResourceBundle bundle = this.loadResourceBundle(locale);
- // Default is i18nKey
- String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N
- // Try it
- try {
- // Get message
- message = bundle.getString(i18nKey);
- } catch (final MissingResourceException ex) {
- // Did not find it, ignored
- }
+
+ // Get message from bundle
+ final String message = this.getMessageFromBundle(i18nKey);
+
// Get context and add message
FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message));
}