@Slf4j @CompileStatic class ViewResourceLocator extends Object
Extended because the handy methods we want in DefaultGroovyPageLocator are protected. Used to locate View resources whether in development or WAR deployed mode from static resources, custom resource loaders and binary plugins. Loads from a local grails-app folder for dev and from WEB-INF in development mode. GroovyPageResourceLoader bean exists in dev/test mode and deals with plugin paths, inplace etc... will not be here in deplyed war
Modifiers | Name | Description |
---|---|---|
static class |
ViewResourceLocator.FileSystemContextResource |
FileSystemResource that explicitly expresses a context-relative path through implementing the ContextResource interface. |
static class |
ViewResourceLocator.PluginViewPathInfo |
|
class |
ViewResourceLocator.ViewContextResource |
a simple resource that build from a URI and adds the base path the resource used to find it |
Type | Name and description |
---|---|
static String |
GRAILS_APP_VIEWS_PATH |
static String |
PLUGINS_PATH |
ApplicationContext |
ctx |
ResourceLoader |
devResourceLoader |
Collection<ResourceLoader> |
grailsResourceLoaders |
List<String> |
grailsViewPaths |
GrailsPluginManager |
pluginManager |
Boolean |
scanAllPluginsWhenNotFound This is the nuclear approach |
Boolean |
searchBinaryPlugins |
List<ResourceLoader> |
searchLoaders collection of resourceLoaders to use right after searchPaths is scanned |
List<String> |
searchPaths the search locations to try first. |
String |
webInfPrefix |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
addResourceLoader(ResourceLoader resourceLoader) |
|
void |
addSearchPath(String path) |
|
static String |
concatPaths(String... pieces) |
|
Resource |
findInClassPath(String uri) search on the base classpath |
|
Resource |
findInGrailsViewPaths(String uri) Looks in grails-app/views with WEB-INF for production and without it for prod |
|
Resource |
findInSearchLoaders(String uri) |
|
Resource |
findInSearchLocations(String uri) |
|
Resource |
findResource(String uri) |
|
Resource |
findResource(List<String> paths) searches the list of paths |
|
Resource |
findResource(ResourceLoader rloader, List<String> searchPaths) searches the list of paths for a specific loader |
|
Resource |
findResourceInBinaryPlugin(BinaryGrailsPlugin plugin, String uri) this will not work in Grails2. |
|
Resource |
findResourceInPlugin(GrailsPlugin plugin, String uri) find the uri in the plugin |
|
Resource |
findResourceWithPluginPath(String uri) if uri starts with "/plugin/" then this attempts to resolve it @return |
|
Resource |
findWithPluginController(String uri) Attempts to resolve a uri relative to a plugin controller. |
|
ClassLoader |
getClassLoader() |
|
static ViewResourceLocator.PluginViewPathInfo |
getPluginViewPathInfo(String uri) |
|
Resource |
getResource(String uri) |
|
void |
init() |
|
Resource |
locate(String uri) Find a view resource for a path. |
|
Resource |
scanPluginsForResource(String uri) The nuclear approach that scans every plugin to find the view |
|
void |
setApplicationContext(ApplicationContext applicationContext) |
|
void |
setPluginManager(GrailsPluginManager pluginManager) |
|
void |
setResourceLoader(ResourceLoader resourceLoader) adds a resourceLoader to the GrailResourceLoader |
This is the nuclear approach
collection of resourceLoaders to use right after searchPaths is scanned
the search locations to try first. Will be classpaths and external directories usually
Looks in grails-app/views with WEB-INF for production and without it for prod
searches the list of paths
searches the list of paths for a specific loader
this will not work in Grails2. checks the
find the uri in the plugin
if uri starts with "/plugin/" then this attempts to resolve it
Attempts to resolve a uri relative to a plugin controller. Finds the right url if its in a plugin Example: if the controller is Demo in the plugin CoolPlugin looks for a view index.xyz then its going to try for "/plugins/foobar-0.1/grails-app/views/demo/index.xyz"
uri
- The nameFind a view resource for a path. For example /foo/bar.xyz will search for /WEB-INF/grails-app/views/foo/bar.xyz in production and grails-app/views/foo/bar.xyz at development time
uri
- The uri to searchThe nuclear approach that scans every plugin to find the view
adds a resourceLoader to the GrailResourceLoader