org.omnifaces.util
Class Hacks

java.lang.Object
  extended by org.omnifaces.util.Hacks

public final class Hacks
extends java.lang.Object

Collection of JSF implementation and/or JSF component library specific hacks.

Since:
1.3
Author:
Bauke Scholtz, Arjan Tijms

Method Summary
static javax.faces.context.PartialViewContext getRichFacesPartialViewContext()
          RichFaces PartialViewContext implementation does not extend from PartialViewContextWrapper.
static java.util.Collection<java.lang.String> getRichFacesRenderIds()
          RichFaces PartialViewContext implementation does not have the getRenderIds() method properly implemented.
static java.util.Set<ResourceIdentifier> getRichFacesResourceLibraryResources(ResourceIdentifier id)
          Returns an ordered set of all JSF resource identifiers for the given RichFaces resource library resources.
static javax.faces.context.PartialViewContext getRichFacesWrappedPartialViewContext()
          RichFaces PartialViewContext implementation does not have any getWrapped() method to return the wrapped PartialViewContext.
static boolean isJUELSupportingMethodExpression()
           
static boolean isJUELUsed()
           
static boolean isJUELUsed(javax.el.ExpressionFactory factory)
           
static boolean isRichFacesInstalled()
          Returns true if RichFaces is installed.
static boolean isRichFacesResourceLibraryRenderer(java.lang.String rendererType)
          Returns true if the given renderer type is recognizeable as RichFaces resource library renderer.
static boolean isRichFacesResourceOptimizationEnabled()
          RichFaces "resource optimization" do not support Resource.getURL() and Resource.getInputStream().
static boolean isSameOrHigherVersion(java.lang.String version1, java.lang.String version2)
          Checks if the given version1 is the same or a higher version than version2.
static java.lang.reflect.Method methodExpressionToStaticMethod(javax.el.ELContext context, javax.el.MethodExpression methodExpression)
          This method wraps a MethodExpression in a Method which can be statically invoked.
static void removeResourceDependencyState(javax.faces.context.FacesContext context)
          Remove the resource dependency processing related attributes from the given faces context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isRichFacesInstalled

public static boolean isRichFacesInstalled()
Returns true if RichFaces is installed. That is, when the RichFaces specific ExtendedPartialViewContextImpl is present in the runtime classpath -which is present in RF 4.x. As this is usually auto-registered, we may safely assume that RichFaces is installed.

Returns:
Whether RichFaces is installed.

getRichFacesPartialViewContext

public static javax.faces.context.PartialViewContext getRichFacesPartialViewContext()
RichFaces PartialViewContext implementation does not extend from PartialViewContextWrapper. So a hack wherin the exact fully qualified class name needs to be known has to be used to properly extract it from the FacesContext.getPartialViewContext().

Returns:
The RichFaces PartialViewContext implementation.

getRichFacesRenderIds

public static java.util.Collection<java.lang.String> getRichFacesRenderIds()
RichFaces PartialViewContext implementation does not have the getRenderIds() method properly implemented. So a hack wherin the exact name of the private field needs to be known has to be used to properly extract it from the RichFaces PartialViewContext implementation.

Returns:
The render IDs from the RichFaces PartialViewContext implementation.

getRichFacesWrappedPartialViewContext

public static javax.faces.context.PartialViewContext getRichFacesWrappedPartialViewContext()
RichFaces PartialViewContext implementation does not have any getWrapped() method to return the wrapped PartialViewContext. So a reflection hack is necessary to return it from the private field.

Returns:
The wrapped PartialViewContext from the RichFaces PartialViewContext implementation.

isRichFacesResourceOptimizationEnabled

public static boolean isRichFacesResourceOptimizationEnabled()
RichFaces "resource optimization" do not support Resource.getURL() and Resource.getInputStream(). The combined resource handler has to manually create the URL based on Resource.getRequestPath() and the current request domain URL whenever RichFaces "resource optimization" is enabled.

Returns:
Whether RichFaces resource optimization is enabled.

isRichFacesResourceLibraryRenderer

public static boolean isRichFacesResourceLibraryRenderer(java.lang.String rendererType)
Returns true if the given renderer type is recognizeable as RichFaces resource library renderer.

Parameters:
rendererType - The renderer type to be checked.
Returns:
Whether the given renderer type is recognizeable as RichFaces resource library renderer.

getRichFacesResourceLibraryResources

public static java.util.Set<ResourceIdentifier> getRichFacesResourceLibraryResources(ResourceIdentifier id)
Returns an ordered set of all JSF resource identifiers for the given RichFaces resource library resources.

Parameters:
id - The resource identifier of the RichFaces resource library (e.g. org.richfaces:ajax.reslib).
Returns:
An ordered set of all JSF resource identifiers for the given RichFaces resource library resources.

isJUELUsed

public static boolean isJUELUsed()

isJUELUsed

public static boolean isJUELUsed(javax.el.ExpressionFactory factory)

isJUELSupportingMethodExpression

public static boolean isJUELSupportingMethodExpression()

isSameOrHigherVersion

public static boolean isSameOrHigherVersion(java.lang.String version1,
                                            java.lang.String version2)
Checks if the given version1 is the same or a higher version than version2.

Parameters:
version1 - the first version in the comparison
version2 - the second version in the comparison
Returns:
true if version1 is the same or a higher version than version2, false otherwise

methodExpressionToStaticMethod

public static java.lang.reflect.Method methodExpressionToStaticMethod(javax.el.ELContext context,
                                                                      javax.el.MethodExpression methodExpression)
This method wraps a MethodExpression in a Method which can be statically invoked.

Since Method is a final class with only a non-public constructor, various reflective tricks have been used to create an instance of this class and make sure it calls the given method expression. It has been tested on the Sun/Oracle JDK versions 6 and 7, and it should work on OpenJDK 6 and 7 as well. Other JDKs might not work.

Parameters:
context - the context used for evaluation of the method expression when it's invoked later. NOTE, this reference is retained by the returned method.
methodExpression - the method expression to be wrapped
Returns:
a Method instance that when invoked causes the wrapped method expression to be invoked.

removeResourceDependencyState

public static void removeResourceDependencyState(javax.faces.context.FacesContext context)
Remove the resource dependency processing related attributes from the given faces context.

Parameters:
context - The involved faces context.