public class LanguageUtils
extends java.lang.Object
getAllPortletMessages(PortletRequest)
or instance method
getAllPortletMessages()
and pull messages from the resulting map as necessary, relying on
replaceMessageTokens(String, Object[])
for token substitution on demand.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
REQUEST_ATTRIBUTE_PORTLET_CONFIG
Name of request attribute that holds the
PortletConfig class. |
Constructor and Description |
---|
LanguageUtils(javax.portlet.PortletRequest request)
Constructor for using an instance of LanguageUtils without passing the request to each static method call.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.String> |
getAllPortletMessages()
|
static java.util.Map<java.lang.String,java.lang.String> |
getAllPortletMessages(javax.portlet.PortletRequest request)
Retrieves all messages available in a resource bundle for the invoking portlet. messages are returned in a map, keyed by message name.
|
static java.lang.String |
getMessage(javax.portlet.PortletRequest request,
java.lang.String messageName)
Retrieves a message with no parameter subtitution.
|
static java.lang.String |
getMessage(javax.portlet.PortletRequest request,
java.lang.String messageName,
java.lang.Object[] params)
Retrieves a message from a resource bundle, substituting the specified parameters for tokens in the message string.
|
java.lang.String |
getMessage(java.lang.String messageName)
Convenience instance-specific wrapper of
getMessage(PortletRequest, String) . |
java.lang.String |
getMessage(java.lang.String messageName,
java.lang.Object[] params)
Convenience instance-specific wrapper of
getMessage(PortletRequest, String, Object[]) . |
static java.lang.String |
replaceMessageTokens(java.lang.String message,
java.lang.Object[] params)
Substitutes parameters for tokens in the message string.
|
public static final java.lang.String REQUEST_ATTRIBUTE_PORTLET_CONFIG
PortletConfig
class. JSR 286 spec requires the portlet container to make
the portlet config available in the PortletRequest under this attribute name.public LanguageUtils(javax.portlet.PortletRequest request)
request
- PortletRequest for the portlet whose resource bundle will be accessed.public java.lang.String getMessage(java.lang.String messageName)
getMessage(PortletRequest, String)
. Uses the instance's PortletRequest as the first
argument.messageName
- Name of message to retrieve from resource bundle.public java.lang.String getMessage(java.lang.String messageName, java.lang.Object[] params)
getMessage(PortletRequest, String, Object[])
. Uses the instance's PortletRequest as
the first argument.messageName
- Name of message to retrieve from resource bundle.params
- Array of parameters to substitute for tokens in the message string.public java.util.Map<java.lang.String,java.lang.String> getAllPortletMessages()
getAllPortletMessages(PortletRequest)
. Uses the instance's PortletRequest as the first argument.public static java.lang.String getMessage(javax.portlet.PortletRequest request, java.lang.String messageName)
getMessage(PortletRequest, String, Object[])
with a null params
argument.request
- PortletRequest for the portlet whose resource bundle will be accessed.messageName
- Name of message to retrieve from resource bundle.public static java.lang.String getMessage(javax.portlet.PortletRequest request, java.lang.String messageName, java.lang.Object[] params)
MessageFormat
class for details about parameter substitution.request
- PortletRequest for the portlet whose resource bundle will be accessed.messageName
- Name of message to retrieve from resource bundle.params
- Parameters to substitute for tokens in the message.MessageFormat.format(String, Object...)
public static java.util.Map<java.lang.String,java.lang.String> getAllPortletMessages(javax.portlet.PortletRequest request)
replaceMessageTokens(String, Object[])
.
This method may be used to load (and potentially cache) messages for a portlet and avoid repeated calls to load the same strings from
the resource bundle.request
- PortletRequest for portlet whose resource bundle will be loaded.public static java.lang.String replaceMessageTokens(java.lang.String message, java.lang.Object[] params)
MessageFormat
class for details about parameter substitution.message
- Message with tokens to replace.params
- Parameters to substitute for tokens in the message.MessageFormat.format(String, Object...)
Copyright 2003, 2014, Oracle and/or its affiliates. All rights reserved.