public class ContextUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ContextUtils.FacesContextDetails
Stores information about FacesContext that can
be used to switch back to a previous FacesContext
|
Modifier and Type | Field and Description |
---|---|
protected static String |
ATTR_APP_VERSION |
static String |
DEFAULT_CURRENCY_FORMAT_EXPRESSION |
static String |
DEFAULT_DATE_FORMAT_EXPRESSION |
static String |
DEFAULT_NUMBER_FORMAT_EXPRESSION |
static String |
DEFAULT_TIME_FORMAT_EXPRESSION |
static String |
DEFAULT_TIME_ZONE_EXPRESSION |
static String |
FACES_RESOURCES |
protected static String |
ICONTEXT_KEY |
protected static DateFormat |
LAST_MODIFIED_VERSION_FORMAT |
protected static Pattern |
RE_BUILD_TIMESTAMP |
protected static Pattern |
RE_BUILD_VERSION |
protected static Pattern |
RE_DATE_TIME_ORDER_ELEMENT |
protected static Pattern |
RE_FORMATTED_MESSAGE_ELEMENT |
Constructor and Description |
---|
ContextUtils() |
Modifier and Type | Method and Description |
---|---|
protected static String |
_applyUserPrefsToMessagePattern(FacesContext ctx,
String message,
Object[] args)
Applies user preferences for date/time/number formatting to message pattern.
|
static ContextUtils.FacesContextDetails |
clearFacesContextDetails()
Clears out the current faces context and other related objects
|
static void |
error(FacesMessage.Severity severity,
String message,
String details) |
static void |
error(String message) |
static void |
error(String message,
String details) |
static void |
error(String message,
Throwable throwable) |
static void |
error(Throwable throwable) |
static ResourceBundle |
findBundle(FacesContext ctx,
String name)
Finds a resource bundle by name using the current response locale
|
static String |
formatMessage(FacesContext ctx,
String message,
Object[] args)
Formats specified message with the specified arguments using
MessageFormat . |
static String |
getAppVersion(FacesContext context)
Calculate the application version of the current context.
|
static FacesContext |
getFacesContext()
Retrieve the current FacesContext
|
static InputStream |
getResourceInputStream(String relPath)
Returns an InputStream for a resource at the given path
|
static com.softwareag.g11n.util.iContext |
getResponseIContext(FacesContext ctx)
Calculates the locale to use for the response.
|
static Locale |
getResponseLocale(FacesContext ctx)
Calculates the locale to use for the response.
|
static ServletContext |
getServletContext(String webAppName)
Deprecated.
use
RuntimeUtilOsgi.getServletContext(String webAppName) instead. |
static ClassLoader |
getWebAppClassLoader(ServletContext servletContext)
Gets the classloader for the supplied servlet context
|
static void |
initializeResponseWriter(FacesContext context)
Initialize the ResponseWriter for the servlet context if it has not already been created.
|
static boolean |
isCafView(FacesContext ctx)
Helper to check if the faces context is for a CAF view
|
static boolean |
isCafView(FacesContext ctx,
String viewId)
Helper to check if the faces context is for a CAF view
|
static String |
localizeMessage(Class<?> bundleClass,
String key)
Returns the message from the specified resource bundle with the specified key.
|
static String |
localizeMessage(FacesContext ctx,
Class<?> bundleClass,
String key)
Returns the message from the specified resource bundle with the specified key.
|
static String |
localizeMessage(FacesContext ctx,
Class<?> bundleClass,
String key,
Object[] args)
Returns the message from the specified resource bundle with the specified key,
formatted with the specified
MessageFormat arguments. |
static String |
localizeMessage(FacesContext ctx,
Class<?> bundleClass,
String key,
Object[] args,
boolean prependKey)
Returns the message from the specified resource bundle with the specified key,
formatted with the specified
MessageFormat arguments. |
static String |
localizeMessage(FacesContext ctx,
String bundleName,
String key,
Object[] args)
Returns the message from the specified resource bundle with the specified key,
formatted with the specified
MessageFormat arguments. |
static String |
localizeMessage(FacesContext ctx,
String bundleName,
String key,
Object[] args,
boolean prependKey)
Returns the message from the specified resource bundle with the specified key,
formatted with the specified
MessageFormat arguments. |
static String |
localizeMessage(FacesContext ctx,
String bundleName,
String key,
Object[] args,
boolean prependKey,
boolean catchMissingResourceException)
Returns the message from the specified resource bundle with the specified key,
formatted with the specified
MessageFormat arguments. |
static String |
localizeMessage(String key)
Returns the message from the default faces resource bundle with the specified key.
|
static String |
localizeMessage(String key,
Object[] args)
Returns the formatted message from the default faces resource bundle with the specified key
|
static String |
localizeMessage(String key,
Object[] args,
boolean prependKey)
Returns the message from the default faces resource bundle with the specified key.
|
static void |
restoreFacesContextDetails(ContextUtils.FacesContextDetails details)
Restores the current faces context and other related objects
|
static void |
setCurrentFacesContext(FacesContext facesContext)
Set the current faces context for this thread.
|
public static final String FACES_RESOURCES
public static final String DEFAULT_CURRENCY_FORMAT_EXPRESSION
public static final String DEFAULT_NUMBER_FORMAT_EXPRESSION
public static final String DEFAULT_DATE_FORMAT_EXPRESSION
public static final String DEFAULT_TIME_FORMAT_EXPRESSION
public static final String DEFAULT_TIME_ZONE_EXPRESSION
protected static final String ICONTEXT_KEY
protected static final Pattern RE_FORMATTED_MESSAGE_ELEMENT
protected static final Pattern RE_DATE_TIME_ORDER_ELEMENT
protected static final String ATTR_APP_VERSION
protected static final Pattern RE_BUILD_TIMESTAMP
protected static final Pattern RE_BUILD_VERSION
protected static final DateFormat LAST_MODIFIED_VERSION_FORMAT
public static String localizeMessage(String key)
key
- the resource bundle key.public static String localizeMessage(String key, Object[] args)
key
- Resource bundle key as Stringargs
- MessageFormat
formatted string arguments as an Object[], or null.public static String localizeMessage(String key, Object[] args, boolean prependKey)
key
- Resource bundle key as Stringargs
- MessageFormat
formatted string arguments as an Object[], or null.prependKey
- True to prepend the key to formatted message (for an error message).public static String localizeMessage(Class<?> bundleClass, String key)
bundleClass
- Resource bundle class, or null for default faces resource bundle class.key
- Resource bundle key as Stringpublic static String localizeMessage(FacesContext ctx, Class<?> bundleClass, String key)
ctx
- Current context, or null for current tls instance.bundleClass
- Resource bundle class, or null for default faces resource bundle class.key
- Resource bundle key as Stringpublic static String localizeMessage(FacesContext ctx, Class<?> bundleClass, String key, Object[] args)
MessageFormat
arguments.ctx
- Current context, or null for current tls instance.bundleClass
- Resource bundle class, or null for default faces resource bundle class.key
- Resource bundle key as Stringargs
- MessageFormat
formatted string arguments as an Object[], or null.public static String localizeMessage(FacesContext ctx, Class<?> bundleClass, String key, Object[] args, boolean prependKey)
MessageFormat
arguments.ctx
- Current context, or null for current tls instance.bundleClass
- Resource bundle class, or null for default faces resource bundle class.key
- Resource bundle key as Stringargs
- MessageFormat
formatted string arguments as an Object[], or null.prependKey
- True to prepend key to formatted message (for an error message).public static String localizeMessage(FacesContext ctx, String bundleName, String key, Object[] args)
MessageFormat
arguments.ctx
- Current context, or null for current tls instance.bundleName
- Resource bundle name, or null for default faces resource bundle class.key
- Resource bundle key as Stringargs
- MessageFormat
formatted string arguments as an Object[], or null.public static String localizeMessage(FacesContext ctx, String bundleName, String key, Object[] args, boolean prependKey) throws MissingResourceException
MessageFormat
arguments.ctx
- Current context, or null for current tls instance.bundleName
- Resource bundle name, or null for default faces resource bundle class.key
- Resource bundle key as Stringargs
- MessageFormat
formatted string arguments as an Object[], or null.prependKey
- True to prepend key to formatted message (for an error message).MissingResourceException
- if bundle could not be found OR if resource could not be found in the bundle.public static String localizeMessage(FacesContext ctx, String bundleName, String key, Object[] args, boolean prependKey, boolean catchMissingResourceException)
MessageFormat
arguments.ctx
- Current context, or null for current tls instance.bundleName
- Resource bundle name, or null for default faces resource bundle class.key
- Resource bundle key as Stringargs
- MessageFormat
formatted string arguments as an Object[], or null.prependKey
- True to prepend key to formatted message (for an error message).catchMissingResourceException
- true to catch any MissingResourceExceptionspublic static String formatMessage(FacesContext ctx, String message, Object[] args)
MessageFormat
.
Uses current user's locale, plus user's preferred default date/time/number patterns.ctx
- Current faces context.message
- Message to format (ie "Distance is {0,number} km.").args
- Arguments with which to format message.protected static String _applyUserPrefsToMessagePattern(FacesContext ctx, String message, Object[] args)
ctx
- Current faces context.message
- Message to format (ie "Distance is {0,number} km.").args
- (optional) Arguments with which to format message.public static Locale getResponseLocale(FacesContext ctx)
ctx
- Current context, or null for current thread instance.public static com.softwareag.g11n.util.iContext getResponseIContext(FacesContext ctx)
ctx
- Current context, or null for current thread instance.public static ResourceBundle findBundle(FacesContext ctx, String name) throws MissingResourceException
ctx
- Current context, or null for current thread instance.name
- Name of the resource bundle as StringMissingResourceException
- if bundle could not be found.public static InputStream getResourceInputStream(String relPath)
relPath
- Relative path to the resource as Stringpublic static void error(FacesMessage.Severity severity, String message, String details)
public static void error(String message)
public static void error(Throwable throwable)
public static FacesContext getFacesContext()
public static String getAppVersion(FacesContext context)
context
- Current faces context.public static void initializeResponseWriter(FacesContext context) throws IOException
context
- the context to initialize.IOException
public static boolean isCafView(FacesContext ctx)
public static boolean isCafView(FacesContext ctx, String viewId)
@Deprecated public static ServletContext getServletContext(String webAppName) throws Exception
RuntimeUtilOsgi.getServletContext(String webAppName)
instead.webAppName
- the servlet context path to matchException
public static ClassLoader getWebAppClassLoader(ServletContext servletContext)
servletContext
- public static ContextUtils.FacesContextDetails clearFacesContextDetails()
public static void restoreFacesContextDetails(ContextUtils.FacesContextDetails details)
details
- details of the previous faces contextpublic static void setCurrentFacesContext(FacesContext facesContext)
clearFacesContextDetails()
+
restoreFacesContextDetails(FacesContextDetails)
instead.facesContext
- the faces context for this thread