Groovy Documentation

org.grails.plugin.resource
[Groovy] Class ResourceProcessor

java.lang.Object
  org.grails.plugin.resource.ResourceProcessor
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, org.springframework.web.context.ServletContextAware

@groovy.util.logging.Commons
class ResourceProcessor

Primary service facade to actions on resources. This class loads resource declarations (see reload()) and receives requests from the servlet filter to serve resources. It will process the resource if necessary the first time, and then return the file.

Authors:
Marc Palmer (marc@grailsrocks.com)
Luke Daley (ld@ldaley.com)


Nested Class Summary
private static class ResourceProcessor.UriUrlCacheEntry

 
Field Summary
private java.io.File workDir

 
Property Summary
static java.lang.Object ADHOC_MODULE

static java.lang.Object DEFAULT_ADHOC_EXCLUDES

static java.lang.Object DEFAULT_ADHOC_INCLUDES

static java.lang.Object DEFAULT_MODULE_SETTINGS

', '*

static java.lang.Object PATH_MATCHER

static java.lang.Object SYNTHETIC_MODULE

java.util.List adHocExcludesLowerCase

java.util.List adHocIncludes

java.lang.Object allResourcesByOriginalSourceURI

java.lang.Object grailsApplication

java.lang.Object grailsLinkGenerator

java.lang.Object grailsResourceLocator

java.lang.Object modulesByName

java.lang.Object modulesInDependencyOrder

java.util.List optionalDispositions

boolean processingEnabled

boolean reloading

java.util.concurrent.ConcurrentMap resourceAllowedCache

java.lang.Object resourceInfo

boolean resourceLocatorEnabled

java.lang.Object resourceMappers

java.util.concurrent.ConcurrentMap servingAllowedCache

javax.servlet.ServletContext servletContext

java.lang.Object staticUrlPrefix

StatsManager statsManager

static java.lang.Object transactional

java.util.concurrent.ConcurrentMap uriToUrlCache

long uriToUrlCacheTimeout

 
Constructor Summary
ResourceProcessor()

 
Method Summary
void addModuleDispositionsToRequest(java.lang.Object request, java.lang.String moduleName)

Add dispositions for a module to a Request.

void afterPropertiesSet()

Initialize bean after properties have been set.

void applyMappers(ResourceMeta r)

java.lang.String buildLinkToOriginalResource(java.util.Map args)

Take g.resource style args and create a link to that original resource in the app, relative to the app context path

boolean canProcessLegacyResource(java.lang.Object uri)

private java.lang.Object collectResourcesThatNeedProcessing(java.lang.Object module, java.lang.Object batch)

protected com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap createDefaultAuthorizationCache()

protected com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap createDefaultUriToUrlCache()

java.lang.Object defineModule(java.lang.String name)

java.lang.Object defineModuleFromBuilder(java.lang.Object builderInfo, ResourceProcessorBatch resBatch)

boolean doCanProcessLegacyResource(java.lang.Object uri)

boolean doIsServingURLAllowed(java.lang.String uri, java.net.URL url)

java.lang.Object dumpResources(java.lang.Object toLog = true)

java.lang.Object extractURI(java.lang.Object request, java.lang.Object adhoc)

ResourceMeta findResourceForURI(java.lang.String uri)

See if we have a ResourceMeta for this URI.

ResourceMeta findSyntheticResourceById(java.lang.Object bundleId)

void forgetModules()

void forgetResources()

java.lang.Object getAllModuleNamesRequired(java.lang.Object moduleNameList)

Return a list of all the names of all modules required (included the input modules) to satisfy the dependencies of the input list of module names.

java.lang.Object getAllModuleNamesRequired(java.util.Map moduleNamesAndMandatory)

Return a list of all the names of all modules required (included the input modules) to satisfy the dependencies of the input list of module names.

groovy.util.ConfigObject getConfig()

Returns the config object under 'grails.resources'

java.lang.Object getConfigParamOrDefault(java.lang.String key, java.lang.Object defaultValue)

Used to retrieve a resources config param, or return the supplied default value if no explicit value was set in config

java.lang.Object getDefaultSettingsForURI(java.lang.Object uri, java.lang.Object typeOverride = null)

ResourceMeta getExistingResourceMeta(java.lang.Object uri)

java.lang.String getMimeType(java.lang.Object uri)

Resolve mime type for a URI by file extension

java.lang.Object getModule(java.lang.Object name)

Retrieve a module by name.

java.lang.Object getModulesInDependencyOrder(java.lang.Object moduleNameList)

Return a the module names sorted in first to last dependency order, based on the required name list

ResourceModule getOrCreateSyntheticOrImplicitModule(boolean synthetic)

java.net.URL getOriginalResourceURLForURI(java.lang.Object uri)

Returns the actual URL for loading the resource specified by the uri By default this is a file in the app's WAR, but this could support other schemes

java.lang.Object getPluginManager()

ResourceMeta getResourceMetaForURI(java.lang.Object uri, java.lang.Boolean createAdHocResourceIfNeeded = true, java.lang.String declaringResource = null, groovy.lang.Closure postProcessor = null)

Get the existing or create a new ad-hoc ResourceMeta for the URI.

java.io.File getWorkDir()

boolean isDebugMode(javax.servlet.ServletRequest request)

private boolean isExplicitDebugRequest(javax.servlet.http.HttpServletRequest request)

boolean isInternalModule(java.lang.Object moduleOrName)

private boolean isMapperEnabledInGlobalConfig(ResourceMapper m)

Test if mapper is enabled in global configuration.

boolean isServingURLAllowed(java.lang.String uri, java.net.URL url)

private void loadMappers()

private java.lang.Object loadModules(ResourceProcessorBatch batch)

private java.lang.Object loadResources(ResourceProcessorBatch resBatch)

java.io.File makeFileForURI(java.lang.String uri)

java.lang.String makeFileSystemPathFromURI(java.lang.Object uri)

Workaround for replaceAll problems with \ in Java

ResourceMeta newSyntheticResource(java.lang.String uri, java.lang.Class type)

ResourceMeta prepareResource(ResourceMeta r, boolean adHocResource)

Execute the processing chain for the resource, returning list of URIs to add to uri -> resource mappings for this resource

void prepareResourceBatch(ResourceProcessorBatch batch)

void prepareSingleDeclaredResource(ResourceMeta r, groovy.lang.Closure postPrepare = null)

boolean processLegacyResource(java.lang.Object request, java.lang.Object response)

Process a legacy URI that points to a normal resource, not produced with our own tags, and likely not referencing a declared resource.

void processModernResource(java.lang.Object request, java.lang.Object response)

Process a URI where the input URI matches a cached and declared resource URI, without any redirects.

void redirectToActualUrl(ResourceMeta res, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

Redirect the client to the actual processed Url, used for when an ad-hoc resource is accessed

void reloadAll()

java.lang.Object reloadChangedFiles()

java.lang.Object reloadMappers()

Reload just the mappers and just the resources - keep the existing module definitiosn

java.lang.Object reloadModules()

static java.lang.Object removeQueryParams(java.lang.Object uri)

void resolveSyntheticResourceDependencies()

private java.net.URL resolveUriToURL(java.lang.Object uri)

private java.lang.Object resourcesChanged(ResourceProcessorBatch batch)

void storeModule(ResourceModule m, ResourceProcessorBatch batch)

void updateDependencyOrder()

Topographic Sort ordering for a Directed Acyclic Graph of dependencies.

static java.lang.String urlToNormalizedFormat(java.net.URL url)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

workDir

private java.io.File workDir


 
Property Detail

ADHOC_MODULE

static java.lang.Object ADHOC_MODULE


DEFAULT_ADHOC_EXCLUDES

static java.lang.Object DEFAULT_ADHOC_EXCLUDES


DEFAULT_ADHOC_INCLUDES

static java.lang.Object DEFAULT_ADHOC_INCLUDES


DEFAULT_MODULE_SETTINGS

static java.lang.Object DEFAULT_MODULE_SETTINGS
', '*


PATH_MATCHER

static final java.lang.Object PATH_MATCHER


SYNTHETIC_MODULE

static java.lang.Object SYNTHETIC_MODULE


adHocExcludesLowerCase

java.util.List adHocExcludesLowerCase


adHocIncludes

java.util.List adHocIncludes


allResourcesByOriginalSourceURI

java.lang.Object allResourcesByOriginalSourceURI


grailsApplication

java.lang.Object grailsApplication


grailsLinkGenerator

java.lang.Object grailsLinkGenerator


grailsResourceLocator

java.lang.Object grailsResourceLocator


modulesByName

java.lang.Object modulesByName


modulesInDependencyOrder

java.lang.Object modulesInDependencyOrder


optionalDispositions

java.util.List optionalDispositions


processingEnabled

boolean processingEnabled


reloading

boolean reloading


resourceAllowedCache

java.util.concurrent.ConcurrentMap resourceAllowedCache


resourceInfo

java.lang.Object resourceInfo


resourceLocatorEnabled

boolean resourceLocatorEnabled


resourceMappers

java.lang.Object resourceMappers


servingAllowedCache

java.util.concurrent.ConcurrentMap servingAllowedCache


servletContext

javax.servlet.ServletContext servletContext


staticUrlPrefix

java.lang.Object staticUrlPrefix


statsManager

StatsManager statsManager


transactional

static java.lang.Object transactional


uriToUrlCache

java.util.concurrent.ConcurrentMap uriToUrlCache


uriToUrlCacheTimeout

long uriToUrlCacheTimeout


 
Constructor Detail

ResourceProcessor

ResourceProcessor()


 
Method Detail

addModuleDispositionsToRequest

void addModuleDispositionsToRequest(java.lang.Object request, java.lang.String moduleName)
Add dispositions for a module to a Request.
Parameters:
request - to add dispositions to
moduleName


afterPropertiesSet

void afterPropertiesSet()
Initialize bean after properties have been set.


applyMappers

void applyMappers(ResourceMeta r)


buildLinkToOriginalResource

java.lang.String buildLinkToOriginalResource(java.util.Map args)
Take g.resource style args and create a link to that original resource in the app, relative to the app context path


canProcessLegacyResource

boolean canProcessLegacyResource(java.lang.Object uri)


collectResourcesThatNeedProcessing

private java.lang.Object collectResourcesThatNeedProcessing(java.lang.Object module, java.lang.Object batch)


createDefaultAuthorizationCache

protected com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap createDefaultAuthorizationCache()


createDefaultUriToUrlCache

protected com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap createDefaultUriToUrlCache()


defineModule

java.lang.Object defineModule(java.lang.String name)


defineModuleFromBuilder

java.lang.Object defineModuleFromBuilder(java.lang.Object builderInfo, ResourceProcessorBatch resBatch)


doCanProcessLegacyResource

boolean doCanProcessLegacyResource(java.lang.Object uri)


doIsServingURLAllowed

boolean doIsServingURLAllowed(java.lang.String uri, java.net.URL url)


dumpResources

java.lang.Object dumpResources(java.lang.Object toLog = true)


extractURI

java.lang.Object extractURI(java.lang.Object request, java.lang.Object adhoc)


findResourceForURI

ResourceMeta findResourceForURI(java.lang.String uri)
See if we have a ResourceMeta for this URI.
Returns:
null if not processed/created yet, the instance if it exists


findSyntheticResourceById

ResourceMeta findSyntheticResourceById(java.lang.Object bundleId)


forgetModules

void forgetModules()


forgetResources

void forgetResources()


getAllModuleNamesRequired

java.lang.Object getAllModuleNamesRequired(java.lang.Object moduleNameList)
Return a list of all the names of all modules required (included the input modules) to satisfy the dependencies of the input list of module names.


getAllModuleNamesRequired

java.lang.Object getAllModuleNamesRequired(java.util.Map moduleNamesAndMandatory)
Return a list of all the names of all modules required (included the input modules) to satisfy the dependencies of the input list of module names.


getConfig

groovy.util.ConfigObject getConfig()
Returns the config object under 'grails.resources'


getConfigParamOrDefault

java.lang.Object getConfigParamOrDefault(java.lang.String key, java.lang.Object defaultValue)
Used to retrieve a resources config param, or return the supplied default value if no explicit value was set in config


getDefaultSettingsForURI

java.lang.Object getDefaultSettingsForURI(java.lang.Object uri, java.lang.Object typeOverride = null)


getExistingResourceMeta

ResourceMeta getExistingResourceMeta(java.lang.Object uri)


getMimeType

java.lang.String getMimeType(java.lang.Object uri)
Resolve mime type for a URI by file extension


getModule

java.lang.Object getModule(java.lang.Object name)
Retrieve a module by name.
Parameters:
name
Returns:
ResourceModule or null if none by that name


getModulesInDependencyOrder

java.lang.Object getModulesInDependencyOrder(java.lang.Object moduleNameList)
Return a the module names sorted in first to last dependency order, based on the required name list


getOrCreateSyntheticOrImplicitModule

ResourceModule getOrCreateSyntheticOrImplicitModule(boolean synthetic)


getOriginalResourceURLForURI

java.net.URL getOriginalResourceURLForURI(java.lang.Object uri)
Returns the actual URL for loading the resource specified by the uri By default this is a file in the app's WAR, but this could support other schemes


getPluginManager

java.lang.Object getPluginManager()


getResourceMetaForURI

ResourceMeta getResourceMetaForURI(java.lang.Object uri, java.lang.Boolean createAdHocResourceIfNeeded = true, java.lang.String declaringResource = null, groovy.lang.Closure postProcessor = null)
Get the existing or create a new ad-hoc ResourceMeta for the URI.
returns:
The resource instance - which may have a null processedFile if the resource cannot be found


getWorkDir

java.io.File getWorkDir()


isDebugMode

boolean isDebugMode(javax.servlet.ServletRequest request)


isExplicitDebugRequest

private boolean isExplicitDebugRequest(javax.servlet.http.HttpServletRequest request)


isInternalModule

boolean isInternalModule(java.lang.Object moduleOrName)


isMapperEnabledInGlobalConfig

private boolean isMapperEnabledInGlobalConfig(ResourceMapper m)
Test if mapper is enabled in global configuration.
Parameters:
mapper - to check
Returns:
true if enabled, false otherwise


isServingURLAllowed

boolean isServingURLAllowed(java.lang.String uri, java.net.URL url)


loadMappers

private void loadMappers()


loadModules

private java.lang.Object loadModules(ResourceProcessorBatch batch)


loadResources

private java.lang.Object loadResources(ResourceProcessorBatch resBatch)


makeFileForURI

java.io.File makeFileForURI(java.lang.String uri)


makeFileSystemPathFromURI

java.lang.String makeFileSystemPathFromURI(java.lang.Object uri)
Workaround for replaceAll problems with \ in Java


newSyntheticResource

ResourceMeta newSyntheticResource(java.lang.String uri, java.lang.Class type)


prepareResource

ResourceMeta prepareResource(ResourceMeta r, boolean adHocResource)
Execute the processing chain for the resource, returning list of URIs to add to uri -> resource mappings for this resource


prepareResourceBatch

void prepareResourceBatch(ResourceProcessorBatch batch)


prepareSingleDeclaredResource

void prepareSingleDeclaredResource(ResourceMeta r, groovy.lang.Closure postPrepare = null)


processLegacyResource

boolean processLegacyResource(java.lang.Object request, java.lang.Object response)
Process a legacy URI that points to a normal resource, not produced with our own tags, and likely not referencing a declared resource. Therefore the URI may not be build-unique and cannot reliably be cached so we have to redirect "Moved Temporarily" to it in case another plugin causes eternal caching etc. To do this, we simply search the cache based on sourceUrl instead of actualUrl This is not recommended, its just a quick out of the box fix for legacy (or pre-"resources plugin" plugin) code. So a request for /css/main.css comes in. This needs to redirect to e.g. /static/css/342342353345343534.css This involves looking it up by source uri. Therefore the same resource may have multiple mappings in the resourceInfo map but they should not be conflicting.


processModernResource

void processModernResource(java.lang.Object request, java.lang.Object response)
Process a URI where the input URI matches a cached and declared resource URI, without any redirects. This is the real deal


redirectToActualUrl

void redirectToActualUrl(ResourceMeta res, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Redirect the client to the actual processed Url, used for when an ad-hoc resource is accessed


reloadAll

void reloadAll()


reloadChangedFiles

java.lang.Object reloadChangedFiles()


reloadMappers

java.lang.Object reloadMappers()
Reload just the mappers and just the resources - keep the existing module definitiosn


reloadModules

java.lang.Object reloadModules()


removeQueryParams

static java.lang.Object removeQueryParams(java.lang.Object uri)


resolveSyntheticResourceDependencies

void resolveSyntheticResourceDependencies()


resolveUriToURL

private java.net.URL resolveUriToURL(java.lang.Object uri)


resourcesChanged

private java.lang.Object resourcesChanged(ResourceProcessorBatch batch)


storeModule

void storeModule(ResourceModule m, ResourceProcessorBatch batch)


updateDependencyOrder

void updateDependencyOrder()
Topographic Sort ordering for a Directed Acyclic Graph of dependencies. Less scary than it seemed, but still a bit hard to read. Think about vectors and edges. Visit wikipedia.


urlToNormalizedFormat

static java.lang.String urlToNormalizedFormat(java.net.URL url)


 

Groovy Documentation