org.omnifaces.facesviews
Class FacesViews

java.lang.Object
  extended by org.omnifaces.facesviews.FacesViews

public final class FacesViews
extends java.lang.Object

This class contains the core methods that implement the Faces Views feature. TODO: break up in logic and config?

Author:
Arjan Tijms

Field Summary
static java.lang.String FACES_VIEWS_DISPATCH_METHOD_PARAM_NAME
          The name of the init parameter (in web.xml) that determines the method used by FacesViews to invoke the FacesServlet.
static java.lang.String FACES_VIEWS_ENABLED_PARAM_NAME
          Web context parameter to switch auto-scanning completely off for Servlet 3.0 containers.
static java.lang.String FACES_VIEWS_EXTENSION_ACTION_PARAM_NAME
          The name of the init parameter (in web.xml) that determines the action that is performed whenever a resource is requested WITH extension that's also available without an extension.
static java.lang.String FACES_VIEWS_FILTER_AFTER_DECLARED_FILTERS_PARAM_NAME
          The name of the boolean init parameter (in web.xml) via which the user can set whether the FacesViewsForwardingFilter should match before declared filters (false) or after declared filters (true);
static java.lang.String FACES_VIEWS_ORIGINAL_SERVLET_PATH
           
static java.lang.String FACES_VIEWS_PATH_ACTION_PARAM_NAME
          The name of the init parameter (in web.xml) that determines the action that is performed whenever a resource is requested in a public path that has been used for scanning views by faces views.
static java.lang.String FACES_VIEWS_RESOURCES
           
static java.lang.String FACES_VIEWS_RESOURCES_EXTENSIONS
           
static java.lang.String FACES_VIEWS_REVERSE_RESOURCES
           
static java.lang.String FACES_VIEWS_SCAN_PATHS_PARAM_NAME
          The name of the init parameter (in web.xml) where the value holds a comma separated list of paths that are to be scanned by faces views.
static java.lang.String FACES_VIEWS_SCANNED_VIEWS_EXTENSIONLESS_PARAM_NAME
          The name of the init parameter (in web.xml) via which the user can set scanned views to be always rendered extensionless.
static java.lang.String PUBLIC_SCAN_PATHS
          The name of the application scope context parameter under which a Set version of the public paths that are to be scanned by faces views are kept.
static java.lang.String SCAN_PATHS
          The name of the application scope context parameter under which a Set version of the paths that are to be scanned by faces views are kept.
static java.lang.String SCANNED_VIEWS_EXTENSIONLESS
          The name of the application scope context parameter under which a Boolean version of the scanned views always exensionless init parameter is kept.
static java.lang.String WEB_INF_VIEWS
          A special dedicated "well-known" directory where facelets implementing views can be placed.
 
Method Summary
static boolean canScanDirectory(java.lang.String rootPath, java.lang.String directory)
           
static boolean canScanResource(java.lang.String resource, java.lang.String extensionToScan)
           
static ExtensionAction getExtensionAction(javax.servlet.ServletContext servletContext)
           
static java.lang.String getExtensionlessURLWithQuery(javax.servlet.http.HttpServletRequest request)
          Obtains the full request URL from the given request complete with the query string, but with the extension (if any) cut out.
static java.lang.String getExtensionlessURLWithQuery(javax.servlet.http.HttpServletRequest request, java.lang.String resource)
          Obtains the full request URL from the given request and the given resource complete with the query string, but with the extension (if any) cut out.
static FacesServletDispatchMethod getFacesServletDispatchMethod(javax.servlet.ServletContext servletContext)
           
static java.lang.String getMappedPath(java.lang.String path)
           
static PathAction getPathAction(javax.servlet.ServletContext servletContext)
           
static java.util.Set<java.lang.String> getPublicRootPaths(javax.servlet.ServletContext servletContext)
           
static java.util.Set<java.lang.String> getRootPaths(javax.servlet.ServletContext servletContext)
           
static boolean isFilterAfterDeclaredFilters(javax.servlet.ServletContext servletContext)
           
static boolean isResourceInPublicPath(javax.servlet.ServletContext servletContext, java.lang.String resource)
           
static java.lang.Boolean isScannedViewsAlwaysExtensionless(javax.faces.context.FacesContext context)
           
static void mapFacesServlet(javax.servlet.ServletContext servletContext, java.util.Set<java.lang.String> extensions)
          Map the Facelets Servlet to the given extensions
static java.lang.String normalizeRootPath(java.lang.String rootPath)
           
static java.util.Map<java.lang.String,java.lang.String> scanAndStoreViews(javax.servlet.ServletContext context)
          Scans for faces-views resources and stores the result at the designated location "org.omnifaces.facesviews" in the ServletContext.
static java.util.Map<java.lang.String,java.lang.String> scanViews(javax.servlet.ServletContext servletContext)
          Scans resources (views) recursively starting with the given resource paths and returns a flat map containing all resources encountered.
static void scanViews(javax.servlet.ServletContext servletContext, java.lang.String rootPath, java.util.Set<java.lang.String> resourcePaths, java.util.Map<java.lang.String,java.lang.String> collectedViews, java.lang.String extensionToScan, java.util.Set<java.lang.String> collectedExtensions)
          Scans resources (views) recursively starting with the given resource paths for a specific root path, and collects those and all unique extensions encountered in a flat map respectively set.
static void scanViewsFromRootPaths(javax.servlet.ServletContext servletContext, java.util.Map<java.lang.String,java.lang.String> collectedViews, java.util.Set<java.lang.String> collectedExtensions)
           
static java.lang.String stripFacesViewsPrefix(java.lang.String resource)
          Strips the special 'faces-views' prefix path from the resource if any.
static void tryScanAndStoreViews(javax.servlet.ServletContext context)
          Checks if resources haven't been scanned yet, and if not does scanning and stores the result at the designated location "org.omnifaces.facesviews" in the ServletContext.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEB_INF_VIEWS

public static final java.lang.String WEB_INF_VIEWS
A special dedicated "well-known" directory where facelets implementing views can be placed. This directory is scanned by convention so that no explicit configuration is needed.

See Also:
Constant Field Values

FACES_VIEWS_ENABLED_PARAM_NAME

public static final java.lang.String FACES_VIEWS_ENABLED_PARAM_NAME
Web context parameter to switch auto-scanning completely off for Servlet 3.0 containers.

See Also:
Constant Field Values

FACES_VIEWS_SCAN_PATHS_PARAM_NAME

public static final java.lang.String FACES_VIEWS_SCAN_PATHS_PARAM_NAME
The name of the init parameter (in web.xml) where the value holds a comma separated list of paths that are to be scanned by faces views.

See Also:
Constant Field Values

FACES_VIEWS_SCANNED_VIEWS_EXTENSIONLESS_PARAM_NAME

public static final java.lang.String FACES_VIEWS_SCANNED_VIEWS_EXTENSIONLESS_PARAM_NAME
The name of the init parameter (in web.xml) via which the user can set scanned views to be always rendered extensionless. Without this setting (or it being set to false), it depends on whether the request URI uses an extension or not. If it doesn't, links are also rendered without one, otherwise are rendered with an extension.

See Also:
Constant Field Values

FACES_VIEWS_EXTENSION_ACTION_PARAM_NAME

public static final java.lang.String FACES_VIEWS_EXTENSION_ACTION_PARAM_NAME
The name of the init parameter (in web.xml) that determines the action that is performed whenever a resource is requested WITH extension that's also available without an extension. See ExtensionAction

See Also:
Constant Field Values

FACES_VIEWS_PATH_ACTION_PARAM_NAME

public static final java.lang.String FACES_VIEWS_PATH_ACTION_PARAM_NAME
The name of the init parameter (in web.xml) that determines the action that is performed whenever a resource is requested in a public path that has been used for scanning views by faces views. See PathAction

See Also:
Constant Field Values

FACES_VIEWS_DISPATCH_METHOD_PARAM_NAME

public static final java.lang.String FACES_VIEWS_DISPATCH_METHOD_PARAM_NAME
The name of the init parameter (in web.xml) that determines the method used by FacesViews to invoke the FacesServlet. See FacesServletDispatchMethod.

See Also:
Constant Field Values

FACES_VIEWS_FILTER_AFTER_DECLARED_FILTERS_PARAM_NAME

public static final java.lang.String FACES_VIEWS_FILTER_AFTER_DECLARED_FILTERS_PARAM_NAME
The name of the boolean init parameter (in web.xml) via which the user can set whether the FacesViewsForwardingFilter should match before declared filters (false) or after declared filters (true);

See Also:
Constant Field Values

SCAN_PATHS

public static final java.lang.String SCAN_PATHS
The name of the application scope context parameter under which a Set version of the paths that are to be scanned by faces views are kept.

See Also:
Constant Field Values

PUBLIC_SCAN_PATHS

public static final java.lang.String PUBLIC_SCAN_PATHS
The name of the application scope context parameter under which a Set version of the public paths that are to be scanned by faces views are kept. A public path is a path that is also directly accessible, e.g. is world readable. This excludes the special path /, which is by definition world readable but not included in this set.

See Also:
Constant Field Values

SCANNED_VIEWS_EXTENSIONLESS

public static final java.lang.String SCANNED_VIEWS_EXTENSIONLESS
The name of the application scope context parameter under which a Boolean version of the scanned views always exensionless init parameter is kept.

See Also:
Constant Field Values

FACES_VIEWS_RESOURCES

public static final java.lang.String FACES_VIEWS_RESOURCES
See Also:
Constant Field Values

FACES_VIEWS_REVERSE_RESOURCES

public static final java.lang.String FACES_VIEWS_REVERSE_RESOURCES
See Also:
Constant Field Values

FACES_VIEWS_RESOURCES_EXTENSIONS

public static final java.lang.String FACES_VIEWS_RESOURCES_EXTENSIONS
See Also:
Constant Field Values

FACES_VIEWS_ORIGINAL_SERVLET_PATH

public static final java.lang.String FACES_VIEWS_ORIGINAL_SERVLET_PATH
See Also:
Constant Field Values
Method Detail

scanViewsFromRootPaths

public static void scanViewsFromRootPaths(javax.servlet.ServletContext servletContext,
                                          java.util.Map<java.lang.String,java.lang.String> collectedViews,
                                          java.util.Set<java.lang.String> collectedExtensions)

getRootPaths

public static java.util.Set<java.lang.String> getRootPaths(javax.servlet.ServletContext servletContext)

getPublicRootPaths

public static java.util.Set<java.lang.String> getPublicRootPaths(javax.servlet.ServletContext servletContext)

normalizeRootPath

public static java.lang.String normalizeRootPath(java.lang.String rootPath)

isResourceInPublicPath

public static boolean isResourceInPublicPath(javax.servlet.ServletContext servletContext,
                                             java.lang.String resource)

getExtensionAction

public static ExtensionAction getExtensionAction(javax.servlet.ServletContext servletContext)

getPathAction

public static PathAction getPathAction(javax.servlet.ServletContext servletContext)

getFacesServletDispatchMethod

public static FacesServletDispatchMethod getFacesServletDispatchMethod(javax.servlet.ServletContext servletContext)

isFilterAfterDeclaredFilters

public static boolean isFilterAfterDeclaredFilters(javax.servlet.ServletContext servletContext)

isScannedViewsAlwaysExtensionless

public static java.lang.Boolean isScannedViewsAlwaysExtensionless(javax.faces.context.FacesContext context)

scanViews

public static void scanViews(javax.servlet.ServletContext servletContext,
                             java.lang.String rootPath,
                             java.util.Set<java.lang.String> resourcePaths,
                             java.util.Map<java.lang.String,java.lang.String> collectedViews,
                             java.lang.String extensionToScan,
                             java.util.Set<java.lang.String> collectedExtensions)
Scans resources (views) recursively starting with the given resource paths for a specific root path, and collects those and all unique extensions encountered in a flat map respectively set.

Parameters:
servletContext -
rootPath - one of the paths from which views are scanned. By default this is typically /WEB-INF/faces-view/
resourcePaths - collection of paths to be considered for scanning, can be either files or directories.
collectedViews - a mapping of all views encountered during scanning. Mapping will be from the simplified form to the actual location relatively to the web root. E.g key "foo", value "/WEB-INF/faces-view/foo.xhtml"
extensionToScan - a specific extension to scan for. Should start with a ., e.g. ".xhtml". If this is given, only resources with that extension will be scanned. If null, all resources will be scanned.
collectedExtensions - set in which all unique extensions will be collected. May be null, in which case no extensions will be collected

canScanDirectory

public static boolean canScanDirectory(java.lang.String rootPath,
                                       java.lang.String directory)

canScanResource

public static boolean canScanResource(java.lang.String resource,
                                      java.lang.String extensionToScan)

scanViews

public static java.util.Map<java.lang.String,java.lang.String> scanViews(javax.servlet.ServletContext servletContext)
Scans resources (views) recursively starting with the given resource paths and returns a flat map containing all resources encountered.

Parameters:
servletContext -
Returns:
views

tryScanAndStoreViews

public static void tryScanAndStoreViews(javax.servlet.ServletContext context)
Checks if resources haven't been scanned yet, and if not does scanning and stores the result at the designated location "org.omnifaces.facesviews" in the ServletContext.

Parameters:
context -

scanAndStoreViews

public static java.util.Map<java.lang.String,java.lang.String> scanAndStoreViews(javax.servlet.ServletContext context)
Scans for faces-views resources and stores the result at the designated location "org.omnifaces.facesviews" in the ServletContext.

Parameters:
context -
Returns:
the view found during scanning, or the empty map if no views encountered

stripFacesViewsPrefix

public static java.lang.String stripFacesViewsPrefix(java.lang.String resource)
Strips the special 'faces-views' prefix path from the resource if any.

Parameters:
resource -
Returns:
the resource without the special prefix path, or as-is if it didn't start with this prefix.

getMappedPath

public static java.lang.String getMappedPath(java.lang.String path)

mapFacesServlet

public static void mapFacesServlet(javax.servlet.ServletContext servletContext,
                                   java.util.Set<java.lang.String> extensions)
Map the Facelets Servlet to the given extensions

Parameters:
extensions - collections of extensions (typically those as encountered during scanning)

getExtensionlessURLWithQuery

public static java.lang.String getExtensionlessURLWithQuery(javax.servlet.http.HttpServletRequest request)
Obtains the full request URL from the given request complete with the query string, but with the extension (if any) cut out.

E.g. http://localhost/foo/bar.xhtml?kaz=1 becomes http://localhost/foo/bar?kaz=1

Parameters:
request - the request from the URL is obtained.
Returns:
request URL with query parameters but without file extension

getExtensionlessURLWithQuery

public static java.lang.String getExtensionlessURLWithQuery(javax.servlet.http.HttpServletRequest request,
                                                            java.lang.String resource)
Obtains the full request URL from the given request and the given resource complete with the query string, but with the extension (if any) cut out.

E.g. http://localhost/foo/bar.xhtml?kaz=1 becomes http://localhost/foo/bar?kaz=1

Parameters:
request - the request from which the base URL is obtained.
resource - the resource relative to the base URL
Returns:
request URL with query parameters but without file extension