public class Util extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Util.JavaeeNamespaceContext |
Modifier and Type | Method and Description |
---|---|
static String |
addExactMappedMarker(String mapping) |
static void |
canSetAppArtifact(ApplicationAssociate applicationAssociate,
String artifactName) |
static void |
checkIdUniqueness(FacesContext context,
UIComponent component,
Set<String> componentIds)
Utility method to validate ID uniqueness for the tree represented
by
component . |
static boolean |
classHasAnnotations(Class<?> clazz) |
static <T> T |
coalesce(T... objects)
Returns the first non-
null object of the argument list, or null if there is no such element. |
static boolean |
componentIsDisabled(UIComponent component) |
static boolean |
componentIsDisabledOrReadonly(UIComponent component) |
static DocumentBuilderFactory |
createDocumentBuilderFactory() |
static SAXParserFactory |
createSAXParserFactory() |
static SchemaFactory |
createSchemaFactory(String uri) |
static TransformerFactory |
createTransformerFactory() |
static String |
generateCreatedBy(FacesContext facesContext) |
static javax.enterprise.inject.spi.BeanManager |
getCdiBeanManager(FacesContext facesContext)
Get the CDI bean manager.
|
static String |
getClientWindowId(FacesContext context) |
static String |
getContentTypeFromResponse(Object response)
PRECONDITION: argument
response is non-null and
has a method called getContentType that takes no
arguments and returns a String, with no side-effects. |
static ClassLoader |
getContextClassLoader2()
Identify and return the class loader that is associated with the calling web application.
|
static Converter |
getConverterForClass(Class converterClass,
FacesContext context) |
static Converter |
getConverterForIdentifer(String converterId,
FacesContext context) |
static ClassLoader |
getCurrentLoader(Object fallbackClass) |
static String |
getDOCTYPEFromFacesContextAttributes(FacesContext context) |
static String |
getFacesConfigXmlVersion(FacesContext facesContext)
Get the faces-config.xml version (if any).
|
static String |
getFacesMapping(FacesContext context)
Returns the URL pattern of the
FacesServlet that
is executing the current request. |
static FeatureDescriptor |
getFeatureDescriptor(String name,
String displayName,
String desc,
boolean expert,
boolean hidden,
boolean preferred,
Object type,
Boolean designTime) |
static String |
getFirstWildCardMappingToFacesServlet(ExternalContext externalContext) |
static long |
getLastModified(URL url) |
static Object |
getListenerInstance(javax.el.ValueExpression type,
javax.el.ValueExpression binding)
Factory method for creating the varius JSF listener
instances that may be referenced by
type
or binding . |
static Locale |
getLocaleFromContextOrSystem(FacesContext context) |
static Locale |
getLocaleFromString(String localeStr) |
static String |
getNamingContainerPrefix(FacesContext context)
If view root is instance of naming container, return its container client id, suffixed with separator character.
|
static String |
getStackTraceString(Throwable e)
Leverage the Throwable.getStackTrace() method to produce a String
version of the stack trace, with a "\n" before each line.
|
static StateManager |
getStateManager(FacesContext context) |
static Class |
getTypeFromString(String type) |
static javax.el.ValueExpression |
getValueExpressionNullSafe(UIComponent component,
String name) |
static ViewHandler |
getViewHandler(FacesContext context) |
static String |
getViewStateId(FacesContext context) |
static String |
getWebXmlVersion(FacesContext facesContext)
Get the web.xml version (if any).
|
static String |
getXMLDECLFromFacesContextAttributes(FacesContext context) |
static int |
indexOfSet(String str,
char[] set,
int fromIndex) |
static boolean |
isAllEmpty(Object... values)
Returns true if all values are empty, false if at least one value is not empty.
|
static boolean |
isAllNull(Object... values) |
static boolean |
isAnyEmpty(Object... values)
Returns
true if at least one value is empty. |
static boolean |
isAnyNull(Object... values) |
static boolean |
isCdiAvailable(FacesContext facesContext)
Is CDI available.
|
static boolean |
isCdiAvailable(javax.servlet.ServletContext servletContext)
Is CDI available (ServletContext variant)
|
static boolean |
isCdiOneOneOrLater(FacesContext facesContext)
Is CDI 1.1 or later
|
static boolean |
isEmpty(Collection<?> collection)
Returns
true if the given collection is null or is empty. |
static boolean |
isEmpty(Object value)
Returns
true if the given value is null or is empty. |
static boolean |
isEmpty(Object[] array)
Returns
true if the given array is null or is empty. |
static boolean |
isEmpty(String string)
Returns true if the given string is null or is empty.
|
static boolean |
isExactMapped(String mapping)
Returns true if the provided
url-mapping is
an exact mapping (starts with EXACT_MARKER ). |
static <T> boolean |
isOneOf(T object,
T... objects)
Returns
true if the given object equals one of the given objects. |
static boolean |
isPortletRequest(FacesContext context)
Convenience method for determining if the request associated
with the specified
FacesContext is a PortletRequest
submitted by the JSR-301 bridge. |
static boolean |
isPrefixMapped(String mapping)
Returns true if the provided
url-mapping is
a prefix path mapping (starts with / ). |
static boolean |
isResourceExactMappedToFacesServlet(ExternalContext externalContext,
String resource)
Checks if the FacesServlet is exact mapped to the given resource.
|
static boolean |
isSpecialAttributeName(String name) |
static boolean |
isUnitTestModeEnabled() |
static boolean |
isViewIdExactMappedToFacesServlet(String viewId)
Checks if the FacesServlet is exact mapped to the given resource.
|
static boolean |
isViewPopulated(FacesContext ctx,
UIViewRoot viewToRender) |
static Class |
loadClass(String name,
Object fallbackClass) |
static Class<?> |
loadClass2(String name,
Object fallbackClass) |
static <T> T |
newInstance(Class<?> clazz) |
static void |
notNegative(String varname,
long number) |
static void |
notNull(String varname,
Object var) |
static void |
notNullAttribute(String attributeName,
Object attribute) |
static void |
notNullNamedObject(Object object,
String objectId,
String logMsg) |
static void |
notNullViewId(String viewId) |
static String |
removeAllButLastSlashPathSegment(String input) |
static String |
removeAllButNextToLastSlashPathSegment(String input) |
static String |
removeExactMappedMarker(String mapping) |
static String |
removeLastPathSegment(String input) |
static <T> List<T> |
reverse(List<T> list) |
static void |
saveDOCTYPEToFacesContextAttributes(String DOCTYPE) |
static void |
saveXMLDECLToFacesContextAttributes(String XMLDECL) |
static void |
setUnitTestModeEnabled(boolean enabled) |
static void |
setViewPopulated(FacesContext ctx,
UIViewRoot viewToRender)
Flag the specified
UIViewRoot as populated. |
static String[] |
split(Map<String,Object> appMap,
String toSplit,
String regex)
A slightly more efficient version of
String.split() which caches
the Pattern s in an LRUMap instead of
creating a new Pattern on each
invocation. |
static String[] |
split(javax.servlet.ServletContext sc,
String toSplit,
String regex) |
static boolean |
startsWithOneOf(String string,
String... prefixes)
Returns
true if the given string starts with one of the given prefixes. |
public static boolean isPortletRequest(FacesContext context)
Convenience method for determining if the request associated
with the specified FacesContext
is a PortletRequest
submitted by the JSR-301 bridge.
context
- the FacesContext
associated with
the request.public static String generateCreatedBy(FacesContext facesContext)
public static Object getListenerInstance(javax.el.ValueExpression type, javax.el.ValueExpression binding)
Factory method for creating the varius JSF listener
instances that may be referenced by type
or binding
.
If binding
is not null
and the evaluation result is not null
return
that instance. Otherwise try to instantiate an instances
based on type
.
type
- the Listener
typebinding
- a ValueExpression
which resolves
to a Listener
instanceListener
instance based off the provided
type
and public static void setUnitTestModeEnabled(boolean enabled)
public static boolean isUnitTestModeEnabled()
public static TransformerFactory createTransformerFactory()
public static SAXParserFactory createSAXParserFactory()
public static DocumentBuilderFactory createDocumentBuilderFactory()
public static SchemaFactory createSchemaFactory(String uri)
public static Class loadClass(String name, Object fallbackClass) throws ClassNotFoundException
ClassNotFoundException
public static <T> T newInstance(Class<?> clazz)
public static ClassLoader getCurrentLoader(Object fallbackClass)
public static ClassLoader getContextClassLoader2() throws FacesException
Identify and return the class loader that is associated with the calling web application.
FacesException
- if the web application class loader cannot be identifiedpublic static String removeAllButLastSlashPathSegment(String input)
public static String removeAllButNextToLastSlashPathSegment(String input)
public static void notNegative(String varname, long number)
public static void notNullViewId(String viewId)
public static void notNullNamedObject(Object object, String objectId, String logMsg)
public static void canSetAppArtifact(ApplicationAssociate applicationAssociate, String artifactName)
public static javax.el.ValueExpression getValueExpressionNullSafe(UIComponent component, String name)
public static boolean isEmpty(String string)
string
- The string to be checked on emptiness.public static boolean isEmpty(Object[] array)
true
if the given array is null or is empty.array
- The array to be checked on emptiness.true
if the given array is null or is empty.public static boolean isEmpty(Collection<?> collection)
true
if the given collection is null or is empty.collection
- The collection to be checked on emptiness.true
if the given collection is null or is empty.public static boolean isEmpty(Object value)
true
if the given value is null or is empty. Types of String, Collection, Map, Optional and Array are
recognized. If none is recognized, then examine the emptiness of the toString() representation instead.value
- The value to be checked on emptiness.true
if the given value is null or is empty.public static boolean isAllEmpty(Object... values)
values
- the values to be checked on emptinesspublic static boolean isAnyEmpty(Object... values)
true
if at least one value is empty.values
- the values to be checked on emptinesstrue
if any value is empty and false
if no values are emptypublic static boolean isAllNull(Object... values)
public static boolean isAnyNull(Object... values)
@SafeVarargs public static <T> boolean isOneOf(T object, T... objects)
true
if the given object equals one of the given objects.T
- The generic object type.object
- The object to be checked if it equals one of the given objects.objects
- The argument list of objects to be tested for equality.true
if the given object equals one of the given objects.@SafeVarargs public static <T> T coalesce(T... objects)
null
object of the argument list, or null
if there is no such element.T
- The generic object type.objects
- The argument list of objects to be tested for non-null
.null
object of the argument list, or null
if there is no such element.public static boolean startsWithOneOf(String string, String... prefixes)
true
if the given string starts with one of the given prefixes.string
- The object to be checked if it starts with one of the given prefixes.prefixes
- The argument list of prefixes to be checkedtrue
if the given string starts with one of the given prefixes.public static Locale getLocaleFromContextOrSystem(FacesContext context)
context
- the FacesContext
for the current requestpublic static Converter getConverterForClass(Class converterClass, FacesContext context)
public static Converter getConverterForIdentifer(String converterId, FacesContext context)
public static StateManager getStateManager(FacesContext context) throws FacesException
FacesException
public static Class getTypeFromString(String type) throws ClassNotFoundException
ClassNotFoundException
public static ViewHandler getViewHandler(FacesContext context) throws FacesException
FacesException
public static boolean componentIsDisabled(UIComponent component)
public static boolean componentIsDisabledOrReadonly(UIComponent component)
public static Locale getLocaleFromString(String localeStr) throws IllegalArgumentException
IllegalArgumentException
public static int indexOfSet(String str, char[] set, int fromIndex)
str
- local stringset
- the substringfromIndex
- starting indexfromIndex
, the index of the
first occurrence of any substring from set
in
toSearch
, or -1 if no such match is foundpublic static String getStackTraceString(Throwable e)
Leverage the Throwable.getStackTrace() method to produce a String version of the stack trace, with a "\n" before each line.
e
- the Throwable to obtain the stacktrace frompublic static String getContentTypeFromResponse(Object response)
PRECONDITION: argument response
is non-null and
has a method called getContentType
that takes no
arguments and returns a String, with no side-effects.
This method allows us to get the contentType in both the servlet and portlet cases, without introducing a compile-time dependency on the portlet api.
response
- the current responsepublic static FeatureDescriptor getFeatureDescriptor(String name, String displayName, String desc, boolean expert, boolean hidden, boolean preferred, Object type, Boolean designTime)
public static String[] split(Map<String,Object> appMap, String toSplit, String regex)
A slightly more efficient version of
String.split()
which caches
the Pattern
s in an LRUMap instead of
creating a new Pattern
on each
invocation.
appMap
- the Application MaptoSplit
- the string to splitregex
- the regex used for splittingPattern.spit(String, int)
public static String getFacesMapping(FacesContext context)
Returns the URL pattern of the
FacesServlet
that
is executing the current request. If there are multiple
URL patterns, the value returned by
HttpServletRequest.getServletPath()
and
HttpServletRequest.getPathInfo()
is
used to determine which mapping to return.
FacesServlet
.
NOTE: This method was supposed to be replaced with the "mapping API" from Servlet 4, but this has not been implemented in time for JSF 2.3 to depend on.
context
- the FacesContext
of the current requestFacesServlet
or null
if no mapping can be determinedNullPointerException
- if context
is nullpublic static boolean isViewIdExactMappedToFacesServlet(String viewId)
Not to be confused with isExactMapped(String)
, which checks
if a string representing a mapping, not a resource, is an exact mapping.
This should be replaced by the Servlet 4 mapping API when/if that becomes available and JSF/Mojarra can depend on it.
viewId
- the view id to testpublic static boolean isResourceExactMappedToFacesServlet(ExternalContext externalContext, String resource)
Not to be confused with isExactMapped(String)
, which checks
if a string representing a mapping, not a resource, is an exact mapping.
This should be replaced by the Servlet 4 mapping API when/if that becomes available and JSF/Mojarra can depend on it.
externalContext
- the external context for this requestresource
- the resource to testpublic static String getFirstWildCardMappingToFacesServlet(ExternalContext externalContext)
public static boolean isExactMapped(String mapping)
Returns true if the provided url-mapping
is
an exact mapping (starts with EXACT_MARKER
).
mapping
- a url-pattern
/
public static boolean isPrefixMapped(String mapping)
Returns true if the provided url-mapping
is
a prefix path mapping (starts with /
).
mapping
- a url-pattern
/
public static boolean isSpecialAttributeName(String name)
public static boolean isViewPopulated(FacesContext ctx, UIViewRoot viewToRender)
ctx
- the FacesContext
for the current requestviewToRender
- the UIViewRoot
to checktrue
if the FacesContext
attributes map
contains a reference to the UIViewRoot
's view IDpublic static void setViewPopulated(FacesContext ctx, UIViewRoot viewToRender)
Flag the specified UIViewRoot
as populated.
ctx
- the FacesContext
for the current requestviewToRender
- the UIViewRoot
to mark as populatedpublic static void checkIdUniqueness(FacesContext context, UIComponent component, Set<String> componentIds)
component
.public static boolean classHasAnnotations(Class<?> clazz)
public static String getNamingContainerPrefix(FacesContext context)
context
- Involved faces context.public static String getViewStateId(FacesContext context)
public static String getClientWindowId(FacesContext context)
public static void saveDOCTYPEToFacesContextAttributes(String DOCTYPE)
public static String getDOCTYPEFromFacesContextAttributes(FacesContext context)
public static void saveXMLDECLToFacesContextAttributes(String XMLDECL)
public static String getXMLDECLFromFacesContextAttributes(FacesContext context)
public static long getLastModified(URL url)
public static String getFacesConfigXmlVersion(FacesContext facesContext)
facesContext
- the Faces context.public static String getWebXmlVersion(FacesContext facesContext)
facesContext
- the Faces context.public static javax.enterprise.inject.spi.BeanManager getCdiBeanManager(FacesContext facesContext)
facesContext
- the Faces context to consultpublic static boolean isCdiAvailable(FacesContext facesContext)
facesContext
- the Faces context to consult.public static boolean isCdiAvailable(javax.servlet.ServletContext servletContext)
servletContext
- the servlet context.public static boolean isCdiOneOneOrLater(FacesContext facesContext)
facesContext
- the Faces context.Comments to: faces-dev@eclipse.org.
Copyright © 2019 Eclipse Foundation. All rights reserved.
Use is subject to license terms.