Class TextResourceFilter

  extended by org.apache.myfaces.custom.stylesheet.TextResourceFilter
All Implemented Interfaces:

public class TextResourceFilter
extends Object
implements Serializable

Loads, filters and then caches any resource available to the webapp.

The resource can then be retrieved from the cache when desired. In particular, it can be retrieved via a URL that invokes the Tomahawk ExtensionsFilter and TextResourceFilterProvider classes.

The "filtering" process looks for any strings of form #{...} in the resource, and executes it as an EL expression. The original expression is then replaced with the return value of the expression.

Note that evaluation of EL expressions happens only once, when the resource is loaded into the cache for the first time. And the EL expressions are evaluated using the context of whatever faces request happens to be active at the time. EL expressions in filtered resources should therefore not reference any request-scoped or session-scoped values as the cached result would be unpredictable.

This class is a per-webapp singleton, accessed via the getInstance method.

See Also:
Serialized Form

Nested Class Summary
static class TextResourceFilter.ResourceInfo
Constructor Summary
protected TextResourceFilter()
Method Summary
protected static TextResourceFilter create()
 TextResourceFilter.ResourceInfo getFilteredResource(String path)
          Return the cached content for the specified resource.
static TextResourceFilter getInstance(javax.faces.context.FacesContext context)
          Return the application-singleton instance of this class.
static TextResourceFilter getInstance(javax.servlet.ServletContext context)
          Return the application-singleton instance of this class.
 TextResourceFilter.ResourceInfo getOrCreateFilteredResource(javax.faces.context.FacesContext context, String path)
          Load, filter and cache the specified resource (if it isn't already cached).
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


protected TextResourceFilter()
Method Detail


protected static TextResourceFilter create()


public static TextResourceFilter getInstance(javax.servlet.ServletContext context)
Return the application-singleton instance of this class.


public static TextResourceFilter getInstance(javax.faces.context.FacesContext context)
Return the application-singleton instance of this class.


public TextResourceFilter.ResourceInfo getFilteredResource(String path)
Return the cached content for the specified resource.

If the resource is not already in the cache (due to an earlier call to getOrCreateFilteredResource) then null is returned.

The path param is a simple key that must match the value passed to an earlier call to getOrCreateFilteredResource.


public TextResourceFilter.ResourceInfo getOrCreateFilteredResource(javax.faces.context.FacesContext context,
                                                                   String path)
                                                            throws IOException
Load, filter and cache the specified resource (if it isn't already cached).

Note: This method is not synchronized for performance reasons (the map is). The worst case is that we filter a resource twice the first time which is not a problem.

The path param must start with a slash, and is interpreted as a path relative to the webapp root (not the current page).


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.