com.sun.faces.application.resource
public class ResourceManager extends java.lang.Object
ResourceInfo
instances
and cache any that are successfully looked up to reduce the
computational overhead with the scanning/version checking.Modifier and Type | Field and Description |
---|---|
private ResourceCache |
cache
Cache for storing
ResourceInfo instances to reduce the cost
of the resource lookups. |
private ClasspathResourceHelper |
classpathHelper
ResourceHelper used for looking up classpath-based resources. |
private java.util.List<java.util.regex.Pattern> |
compressableTypes
Patterns used to find
ResourceInfo instances that may have their
content compressed. |
private static java.util.regex.Pattern |
CONFIG_MIMETYPE_PATTERN
Pattern for valid mime types to configure compression. |
private java.util.concurrent.locks.ReentrantLock |
lock
This lock is used to ensure the lookup of compressable
ResourceInfo
instances are atomic to prevent theading issues when writing the compressed
content during a lookup. |
private static java.util.logging.Logger |
LOGGER |
private ResourceHelper |
webappHelper
ResourceHelper used for looking up webapp-based resources. |
Constructor and Description |
---|
ResourceManager(java.util.Map<java.lang.String,java.lang.Object> appMap,
ResourceCache cache)
Constructs a new
ResourceManager . |
ResourceManager(ResourceCache cache) |
Modifier and Type | Method and Description |
---|---|
private void |
addToCache(ResourceInfo info)
Adds the the specified
ResourceInfo to the cache. |
private ResourceInfo |
doLookup(java.lang.String libraryName,
java.lang.String resourceName,
java.lang.String localePrefix,
boolean compressable,
javax.faces.context.FacesContext ctx)
Attempt to look up the Resource based on the provided details.
|
(package private) LibraryInfo |
findLibrary(java.lang.String libraryName,
java.lang.String localePrefix,
javax.faces.context.FacesContext ctx)
Attempt to lookup and return a
LibraryInfo based on the
specified arguments . |
(package private) LibraryInfo |
findLibraryOnClasspathWithZipDirectoryEntryScan(java.lang.String libraryName,
java.lang.String localePrefix,
javax.faces.context.FacesContext ctx,
boolean forceScan) |
private ResourceInfo |
findResource(LibraryInfo library,
java.lang.String resourceName,
java.lang.String localePrefix,
boolean compressable,
javax.faces.context.FacesContext ctx)
Attempt to lookup and return a
ResourceInfo based on the
specified arguments . |
ResourceInfo |
findResource(java.lang.String libraryName,
java.lang.String resourceName,
java.lang.String contentType,
javax.faces.context.FacesContext ctx)
Attempt to lookup a
ResourceInfo based on the specified
libraryName |
private ResourceInfo |
getFromCache(java.lang.String name,
java.lang.String library,
java.lang.String localePrefix) |
private java.lang.String |
getLocalePrefix(javax.faces.context.FacesContext context)
Obtains the application configured message resources for the current
request locale.
|
private void |
initCompressableTypes(java.util.Map<java.lang.String,java.lang.Object> appMap)
Init
compressableTypes from the configuration. |
private boolean |
isCompressable(java.lang.String contentType,
javax.faces.context.FacesContext ctx) |
private boolean |
isPatternValid(java.lang.String input) |
private static boolean |
nameContainsForbiddenSequence(java.lang.String name) |
private java.lang.String |
trimLeadingSlash(java.lang.String s) |
private static final java.util.logging.Logger LOGGER
private static final java.util.regex.Pattern CONFIG_MIMETYPE_PATTERN
Pattern
for valid mime types to configure compression.private ResourceHelper webappHelper
ResourceHelper
used for looking up webapp-based resources.private ClasspathResourceHelper classpathHelper
ResourceHelper
used for looking up classpath-based resources.private ResourceCache cache
ResourceInfo
instances to reduce the cost
of the resource lookups.private java.util.List<java.util.regex.Pattern> compressableTypes
ResourceInfo
instances that may have their
content compressed.private java.util.concurrent.locks.ReentrantLock lock
ResourceInfo
instances are atomic to prevent theading issues when writing the compressed
content during a lookup.public ResourceManager(ResourceCache cache)
public ResourceManager(java.util.Map<java.lang.String,java.lang.Object> appMap, ResourceCache cache)
ResourceManager
. Note: if the current
ProjectStage
is ProjectStage.Development
caching or
ResourceInfo
instances will not occur.public ResourceInfo findResource(java.lang.String libraryName, java.lang.String resourceName, java.lang.String contentType, javax.faces.context.FacesContext ctx)
Attempt to lookup a ResourceInfo
based on the specified
libraryName
and
resourceName
Implementation Note: Synchronization is necessary when looking up compressed resources. This ensures the atomicity of the content being compressed. As such, the cost of doing this is low as once the resource is in the cache, the lookup won't be performed again until the cache is cleared. That said, it's not a good idea to have caching disabled in a production environment if leveraging compression. If the resource isn't compressable, then we don't worry about creating a few extra copies of ResourceInfo until the cache is populated.
libraryName
- the name of the library (if any)resourceName
- the name of the resourcecontentType
- the content type of the resource. This will be
used to determine if the resource is compressablectx
- the FacesContext
for the current
requestResourceInfo
if a resource if found matching the
provided arguments, otherwise, return null
private ResourceInfo doLookup(java.lang.String libraryName, java.lang.String resourceName, java.lang.String localePrefix, boolean compressable, javax.faces.context.FacesContext ctx)
libraryName
- the name of the library (if any)resourceName
- the name of the resourcelocalePrefix
- the locale prefix for this resource (if any)compressable
- if this resource can be compressedctx
- the FacesContext
for the current
requestResourceInfo
if a resource if found matching the
provided arguments, otherwise, return null
private static boolean nameContainsForbiddenSequence(java.lang.String name)
private ResourceInfo getFromCache(java.lang.String name, java.lang.String library, java.lang.String localePrefix)
name
- the resource namelibrary
- the library namelocalePrefix
- the Locale prefixResourceInfo
from the cache or null
if no cached entry is foundprivate void addToCache(ResourceInfo info)
ResourceInfo
to the cache.info
- the @{link ResourceInfo} to add.LibraryInfo findLibrary(java.lang.String libraryName, java.lang.String localePrefix, javax.faces.context.FacesContext ctx)
Attempt to lookup and return a LibraryInfo
based on the
specified arguments
.
The lookup process will first search the file system of the web application. If the library is not found, then it processed to searching the classpath.
If a library is found, this method will return a LibraryInfo
instance that contains the name, version, and ResourceHelper
.
libraryName
- the library to findlocalePrefix
- the prefix for the desired localectx
- the FacesContext
for the current requestLibraryInfo findLibraryOnClasspathWithZipDirectoryEntryScan(java.lang.String libraryName, java.lang.String localePrefix, javax.faces.context.FacesContext ctx, boolean forceScan)
private ResourceInfo findResource(LibraryInfo library, java.lang.String resourceName, java.lang.String localePrefix, boolean compressable, javax.faces.context.FacesContext ctx)
Attempt to lookup and return a ResourceInfo
based on the
specified arguments
.
The lookup process will first search the file system of the web application. If the library is not found, then it processed to searching the classpath.
If a library is found, this method will return a LibraryInfo
instance that contains the name, version, and ResourceHelper
.
library
- the library the resource should be found inresourceName
- the name of the resourcelocalePrefix
- the prefix for the desired localecompressable
- true
if the resource can be compressedctx
- the FacesContext
for the current requestprivate java.lang.String getLocalePrefix(javax.faces.context.FacesContext context)
Obtains the application configured message resources for the current
request locale. If a ResourceBundle is found and contains the key
javax.faces.resource.localePrefix
, use the value associated
with that key as the prefix for locale specific resources.
For example, say the request locale is en_US, and
javax.faces.resourceLocalePrefix
is found with a value of
en
, a resource path within a web application might look like
/resources/en/corp/images/greetings.jpg
context
- the FacesContext
for the current requestnull
if no prefix can be determinedprivate java.lang.String trimLeadingSlash(java.lang.String s)
s
- input Stringprivate boolean isCompressable(java.lang.String contentType, javax.faces.context.FacesContext ctx)
contentType
- content-type in questionctx
- the @{link FacesContext} for the current requesttrue
if this resource can be compressed, otherwise
false
private void initCompressableTypes(java.util.Map<java.lang.String,java.lang.Object> appMap)
compressableTypes
from the configuration.private boolean isPatternValid(java.lang.String input)
input
- input mime-type pattern from the configurationtrue
if the input matches the expected pattern,
otherwise false
Copyright © 2002-2010 Oracle America, Inc. All Rights Reserved.