public class DojoDependencyHandler extends Object implements CacheReporter
This bean provides a way of ensuring that Dojo requested dependency file contents are modified to reference MD5 checksum codes
| Modifier and Type | Field and Description |
|---|---|
static String |
REQUEST_PACKAGES |
static String |
WIDGET_CONFIG |
static String |
WIDGET_NAME |
static String |
WIDGETS_LIST |
| Constructor and Description |
|---|
DojoDependencyHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearCaches()
Clears the caches stored in the
cachedDeps and generatedResourceCache maps. |
protected static String |
getBuildKeyForDependencies(Map<String,DojoDependencies> dependencies)
Construct the hash lookup key for a Map of Dojo dependencies.
|
String |
getCachedResource(String path)
Attempts to retrieve a generated JavaScript resource that has been previously cached.
|
String |
getChecksumForDependencies(Map<String,DojoDependencies> dependencies,
String pagePath,
DojoDependencies pageDeps)
Return the checksum for a set of dependencies.
|
String |
getChecksumPathForDependencies(String source)
This method is used to both generate the checksum for the supplied JavaScript source code and also to cache that generated
source code against the checksum generated.
|
DojoDependencies |
getDependencies(String path)
Gets the
DojoDependencies for the supplied path. |
String |
getPath(String sourcePath,
String dependencyPath)
Calculates the path of the dependency relative to the path of the supplied source path.
|
Map<String,String> |
getRequestDojoPackages()
This returns the Dojo packages for the current request (that will include all dynamic configuration extensions)
if available, otherwise returns the spring injected value (the static configuration).
|
StringBuilder |
outputAggregateResource(Map<String,DojoDependencies> depsToOutput,
String baseUrl)
This method builds the equivalent of a Dojo build layer from the
Map of supplied DojoDependencies. |
StringBuilder |
outputDependency(String name,
String path,
DojoDependencies deps)
This method is used to generate the output for a single dependency in a way that replicates what would be generated
from building a Dojo layer.
|
void |
processControllerWidgets(List widgets,
Map<String,DojoDependencies> dependenciesForCurrentRequest)
Recursively processes lists of widgets that are defined in the WebScript model.
|
void |
processCssDependencies(Map<String,DojoDependencies> dependenciesForCurrentRequest,
OutputCSSContentModelElement outputCss,
String prefix,
String group)
This method iterates through the dependencies provided in reverse.
|
void |
processNonAmdDependencies(Map<String,DojoDependencies> dependenciesForCurrentRequest,
OutputJavaScriptContentModelElement outputJs,
String prefix,
String group)
This method iterates through the dependencies provided in reverse.
|
void |
processString(String contents,
DojoDependencies dependencies,
Map<String,DojoDependencies> dependenciesForCurrentRequest)
Performs analysis on the supplied String and updates the supplied
DojoDependencies object. |
void |
recursivelyProcessDependencies(DojoDependencies deps,
Map<String,DojoDependencies> allDeps)
Recursively processes all the JavaScript dependencies in the supplied
DojoDependencies object. |
List<CacheReport> |
report() |
protected String |
reverseAlias(String path)
Calculates the configured Dojo package from the supplied path.
|
void |
setDependencyAggregator(DependencyAggregator dependencyAggregator)
Setter provided to allow the Spring application context to set a
DependencyAggregator. |
void |
setDependencyHandler(DependencyHandler dependencyHandler)
Setter provided to allow the Spring application context to set a
DependencyHandler. |
void |
setDependencyRules(List<DojoDependencyRule> dependencyRules)
Setter provided to allow the Spring application context to set the
DojoDependencyRule list. |
void |
setWebFrameworkConfigElement(WebFrameworkConfigElement webFrameworkConfigElement)
Setter provided to allow the Spring application context to set a
WebFrameworkConfigElement. |
public static final String WIDGET_NAME
public static final String WIDGET_CONFIG
public static final String WIDGETS_LIST
public static final String REQUEST_PACKAGES
public void setDependencyHandler(DependencyHandler dependencyHandler)
DependencyHandler.dependencyHandler - DependencyHandlerpublic void setDependencyAggregator(DependencyAggregator dependencyAggregator)
DependencyAggregator.dependencyAggregator - DependencyAggregatorpublic void setWebFrameworkConfigElement(WebFrameworkConfigElement webFrameworkConfigElement)
WebFrameworkConfigElement.webFrameworkConfigElement - WebFrameworkConfigElementpublic void setDependencyRules(List<DojoDependencyRule> dependencyRules)
DojoDependencyRule list.dependencyRules - Listpublic void clearCaches()
cachedDeps and generatedResourceCache maps.
This method has been provided to allow a WebScript to clear the caches of running systems.clearCaches in interface CacheReporterpublic List<CacheReport> report()
report in interface CacheReporterpublic void processString(String contents, DojoDependencies dependencies, Map<String,DojoDependencies> dependenciesForCurrentRequest)
Performs analysis on the supplied String and updates the supplied DojoDependencies object.
contents - Stringdependencies - DojoDependenciesdependenciesForCurrentRequest - Mappublic DojoDependencies getDependencies(String path)
Gets the DojoDependencies for the supplied path. The cache is checked first to make sure that the
processing hasn't already been done before but if it hasn't been processed the path will be processed. All the
JavaScript dependencies found for the supplied path should be processed by the calling code.
DojoDependencies for the supplied pathpublic void recursivelyProcessDependencies(DojoDependencies deps, Map<String,DojoDependencies> allDeps)
Recursively processes all the JavaScript dependencies in the supplied DojoDependencies object. All dependency
paths found are added to the supplied Map so that all the dependencies for the current request can be tracked and
used to prevent infinite loops.
deps - The DojoDependencies to process.allDeps - A Map of all the dependencies processed so far.public String getCachedResource(String path)
ProcessJsonModelDirective instance to the getChecksumPathForDependencies
method.path - The path to look up in the cache.null if it couldn't be found.public String getChecksumPathForDependencies(String source)
ResourceController looks for the resource
it can be retrieved. The path returned is mapped to the "surf" Dojo package. This package should always exist as it is defined
in the core Surf configuration.source - The JavaScript source to generate the checksum for and to be cached.public String getChecksumForDependencies(Map<String,DojoDependencies> dependencies, String pagePath, DojoDependencies pageDeps)
dependencies - Map of dependencies for a page - the keys are used as the overall hashkeyprotected static String getBuildKeyForDependencies(Map<String,DojoDependencies> dependencies)
The key must be based on the keys for each of the dependencies in the list - but not the values e.g. not based on the common HashMap Entry algorithm getKey.hashCode() ^ getValue().hashCode() as we cannot guarantee that the value objects will return the same hash each time.
dependencies - Map of DojoDependenciesprotected String reverseAlias(String path)
path - The path to find the Dojo package for.public StringBuilder outputAggregateResource(Map<String,DojoDependencies> depsToOutput, String baseUrl)
This method builds the equivalent of a Dojo build layer from the Map of supplied DojoDependencies.
public StringBuilder outputDependency(String name, String path, DojoDependencies deps) throws IOException
This method is used to generate the output for a single dependency in a way that replicates what would be generated from building a Dojo layer. Effectively the supplied file is added to a cache object that prevents Dojo from needing to explicitly load the file when it is required by another file.
name - The (short) name of the dependency (relative to the Dojo AMD package configuration).path - The full path of the filedeps - A list of the dependencies known to the current dependency. This is primarily used for processing
text dependencies.IOExceptionpublic Map<String,String> getRequestDojoPackages()
public String getPath(String sourcePath, String dependencyPath)
Calculates the path of the dependency relative to the path of the supplied source path. If dependency path is mapped to a Dojo package alias then that package is used to calculate the path.
sourcePath - The path of the file from which the dependency is referenced.dependencyPath - The path of the dependency as referenced in the source file.public void processControllerWidgets(List widgets, Map<String,DojoDependencies> dependenciesForCurrentRequest)
Recursively processes lists of widgets that are defined in the WebScript model. This works on the assumption that nested widgets will be configured as follows:
name: <widget-name>
config: {
widgets: [
{
name: <widget-name>
<etc...>
}
]
}
widgets - The List of widgets currently being processed.dependenciesForCurrentRequest - The dependencies processed on the current request.public void processCssDependencies(Map<String,DojoDependencies> dependenciesForCurrentRequest, OutputCSSContentModelElement outputCss, String prefix, String group)
dependenciesForCurrentRequest - MapoutputCss - OutputCSSContentModelElementprefix - Stringgroup - Stringpublic void processNonAmdDependencies(Map<String,DojoDependencies> dependenciesForCurrentRequest, OutputJavaScriptContentModelElement outputJs, String prefix, String group)
dependenciesForCurrentRequest - MapoutputJs - OutputJavaScriptContentModelElementprefix - Stringgroup - StringCopyright © 2005–2016 Alfresco Software. All rights reserved.