/** * Calls {@link #findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)} * with aTextName as the default message. * * @see #findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args) */ public static String findText(Class aClass, String aTextName, Locale locale) { return findText(aClass, aTextName, locale, aTextName, new Object[0]); }
/** * Finds a localized text message for the given key, aTextName, in the specified resource bundle * with aTextName as the default message. * <p/> * If a message is found, it will also be interpolated. Anything within <code>${...}</code> * will be treated as an OGNL expression and evaluated as such. * * @see #findText(java.util.ResourceBundle, String, java.util.Locale, String, Object[]) */ public static String findText(ResourceBundle bundle, String aTextName, Locale locale) { return findText(bundle, aTextName, locale, aTextName, new Object[0]); }
/** * Checks if a key is available in the resource bundles associated with this action. * The resource bundles are searched, starting with the one associated * with this particular action, and testing all its superclasses' bundles. * It will stop once a bundle is found that contains the given text. This gives * a cascading style that allow global texts to be defined for an application base * class. */ public boolean hasKey(String key) { String message; if (clazz != null) { message = LocalizedTextUtil.findText(clazz, key, getLocale(), null, new Object[0] ); } else { message = LocalizedTextUtil.findText(bundle, key, getLocale(), null, new Object[0]); } return message != null; }
/** * Get a text from the resource bundles associated with this action. * The resource bundles are searched, starting with the one associated * with this particular action, and testing all its superclasses' bundles. * It will stop once a bundle is found that contains the given text. This gives * a cascading style that allow global texts to be defined for an application base * class. If no text is found for this text name, the default value is returned. * * @param key name of text to be found * @param defaultValue the default value which will be returned if no text is found * @param args an array of args to be used in a MessageFormat message * @return value of named text or the provided defaultValue if no value is found */ public String getText(String key, String defaultValue, String[] args) { if (clazz != null) { return LocalizedTextUtil.findText(clazz, key, getLocale(), defaultValue, args); } else { return LocalizedTextUtil.findText(bundle, key, getLocale(), defaultValue, args); } }
/** * Get a text from the resource bundles associated with this action. * The resource bundles are searched, starting with the one associated * with this particular action, and testing all its superclasses' bundles. * It will stop once a bundle is found that contains the given text. This gives * a cascading style that allow global texts to be defined for an application base * class. If no text is found for this text name, the default value is returned. * * @param key name of text to be found * @param defaultValue the default value which will be returned if no text is found * @param args a List of args to be used in a MessageFormat message * @return value of named text or the provided defaultValue if no value is found */ public String getText(String key, String defaultValue, List<?> args) { Object[] argsArray = ((args != null && !args.equals(Collections.emptyList())) ? args.toArray() : null); if (clazz != null) { return LocalizedTextUtil.findText(clazz, key, getLocale(), defaultValue, argsArray); } else { return LocalizedTextUtil.findText(bundle, key, getLocale(), defaultValue, argsArray); } }
/** * Gets a message based on a key using the supplied args, as defined in * {@link java.text.MessageFormat}, or, if the message is not found, a supplied * default value is returned. Instead of using the value stack in the ActionContext * this version of the getText() method uses the provided value stack. * * @param key the resource bundle key that is to be searched for * @param defaultValue the default value which will be returned if no message is found * @param args a list args to be used in a {@link java.text.MessageFormat} message * @param stack the value stack to use for finding the text * @return the message as found in the resource bundle, or defaultValue if none is found */ public String getText(String key, String defaultValue, List<?> args, ValueStack stack) { Object[] argsArray = ((args != null) ? args.toArray() : null); Locale locale; if (stack == null){ locale = getLocale(); }else{ locale = (Locale) stack.getContext().get(ActionContext.LOCALE); } if (locale == null) { locale = getLocale(); } if (clazz != null) { return LocalizedTextUtil.findText(clazz, key, locale, defaultValue, argsArray, stack); } else { return LocalizedTextUtil.findText(bundle, key, locale, defaultValue, argsArray, stack); } }
public char execute(ActionContext context, AgiOperations opts) throws IOException, AgiException { Locale locale = context.getLocale(); ValueStack valueStack = context.getValueStack(); String text = LocalizedTextUtil.findText( AbstractAgiTemplate.this.getClass(), _message, locale, _message, _args, valueStack); return _textToSpeechFactory.getAudio(opts, text, ALL_DIGITS); } }
/** * Gets a message based on a key using the supplied args, as defined in * {@link java.text.MessageFormat}, or, if the message is not found, a supplied * default value is returned. Instead of using the value stack in the ActionContext * this version of the getText() method uses the provided value stack. * * @param key the resource bundle key that is to be searched for * @param defaultValue the default value which will be returned if no message is found * @param args an array args to be used in a {@link java.text.MessageFormat} message * @param stack the value stack to use for finding the text * @return the message as found in the resource bundle, or defaultValue if none is found */ public String getText(String key, String defaultValue, String[] args, ValueStack stack) { Locale locale; if (stack == null){ locale = getLocale(); }else{ locale = (Locale) stack.getContext().get(ActionContext.LOCALE); } if (locale == null) { locale = getLocale(); } if (clazz != null) { return LocalizedTextUtil.findText(clazz, key, locale, defaultValue, args, stack); } else { return LocalizedTextUtil.findText(bundle, key, locale, defaultValue, args, stack); } }
/** * Finds a localized text message for the given key, aTextName, in the specified resource * bundle. * <p/> * If a message is found, it will also be interpolated. Anything within <code>${...}</code> * will be treated as an OGNL expression and evaluated as such. * <p/> * If a message is <b>not</b> found a WARN log will be logged. * * @param bundle the bundle * @param aTextName the key * @param locale the locale * @param defaultMessage the default message to use if no message was found in the bundle * @param args arguments for the message formatter. */ public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args) { ValueStack valueStack = ActionContext.getContext().getValueStack(); return findText(bundle, aTextName, locale, defaultMessage, args, valueStack); }
protected void notifyDeveloperParameterException(Object action, String property, String message) { String developerNotification = LocalizedTextUtil.findText(ParametersInterceptor.class, "devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification:\n{0}", new Object[]{ "Unexpected Exception caught setting '" + property + "' on '" + action.getClass() + ": " + message } ); LOG.error(developerNotification); // see https://issues.apache.org/jira/browse/WW-4066 if (action instanceof ValidationAware) { Collection<String> messages = ((ValidationAware) action).getActionMessages(); messages.add(message); ((ValidationAware) action).setActionMessages(messages); } }
/** * Handles logging and UI messages for ConversationExceptions * * @param invocation * @param ce * @return */ protected String handleUnexpectedException(ActionInvocation invocation, ConversationException ce) { LOG.error("An unexpected exception occurred in Conversation Processing, returning result of " + CONVERSATION_EXCEPTION_KEY); Locale locale = invocation.getInvocationContext().getLocale(); String errorMessage = LocalizedTextUtil.findText(this.getClass(), CONVERSATION_EXCEPTION_KEY, locale, "An unexpected error occurred while processing you request. Please try again.", new Object[0]); if (LOG.isDebugEnabled()) { LOG.debug("Placing Conversation Error Message on stack (key={" + CONVERSATION_EXCEPTION_KEY + "}): " + errorMessage); } //Placing message on stack instead of in actionErrors for retrieval in UI invocation.getStack().getContext().put(CONVERSATION_EXCEPTION_KEY, errorMessage); this.handleConversationErrorAware(invocation.getProxy(), errorMessage); return CONVERSATION_EXCEPTION_KEY; }
String errorMessage = LocalizedTextUtil.findText(this.getClass(), conversationSpecificMessageKey, locale); errorMessage = LocalizedTextUtil.findText(this.getClass(), CONVERSATION_ID_EXCEPTION_KEY, locale, "The workflow that you are attempting to continue has ended or expired. Your requested action was not processed.", new Object[0]);
return findText(aClass, aTextName, locale, defaultMessage, args, valueStack);
if (obj != null) valueStack.push(obj); msg = findText(clazz, newKey, locale, null, args); if (obj != null) valueStack.pop();
} catch (RuntimeException e) { if (devMode) { String developerNotification = LocalizedTextUtil.findText(ParametersInterceptor.class, "devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification:\n{0}", new Object[]{ "Unexpected Exception caught setting '" + entry.getKey() + "' on '" + action.getClass() + ": " + e.getMessage() });
} catch (RuntimeException e) { if (devMode) { String developerNotification = LocalizedTextUtil.findText(ParametersInterceptor.class, "devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification:\n{0}", new Object[]{ "Unexpected Exception caught setting '" + entry.getKey() + "' on '" + action.getClass() + ": " + e.getMessage() });