public class DependencyAggregator extends Object implements org.springframework.context.ApplicationContextAware, CacheReporter
| Modifier and Type | Class and Description |
|---|---|
static class |
DependencyAggregator.CompressionType |
| Modifier and Type | Field and Description |
|---|---|
int |
cacheSize
Set the size of the file cache for MD5 checksums
|
String |
charset |
static String |
CLIENT_COLLATION_DEBUG |
static String |
CLIENT_DEBUG |
boolean |
disableOptimizations |
static char |
DOUBLE_QUOTE |
static String |
FLAGS |
static String |
INLINE_AGGREGATION_MARKER |
int |
linebreak |
boolean |
munge |
static Pattern |
p |
boolean |
preserveAllSemiColons |
static char |
SINGLE_QUOTE |
boolean |
verbose |
| Constructor and Description |
|---|
DependencyAggregator() |
| Modifier and Type | Method and Description |
|---|---|
void |
adjustImageURLs(String cssPath,
StringBuilder cssContents)
This method is used to ensure all image URL are correct when CSS files are aggregated together.
|
protected void |
cacheChecksumForFileSet(Set<String> fileSet,
String checksum)
Caches a generated aggregated resource checksum against the fileset that it was
generated against.
|
protected void |
cacheCompressedCssResource(String path,
String content)
Caches the supplied CSS resource using a combination of the current Theme ID with
the CSS source path.
|
protected void |
cacheCompressedJSResource(String path,
String content) |
protected void |
cacheDependencyResource(String checksum,
DependencyResource content) |
void |
clearCaches() |
String |
compressCSSFile(InputStream in)
Compresses the CSS file provided by the supplied
InputStream using the YUI CssCompressor. |
String |
compressJavaScript(Reader reader)
Compresses the JavaScript file provided by the supplied
InputStream using the YUI JavaScriptCompressor. |
boolean |
excludeFileFromCompression(String path)
Checks to see whether or not the path meets any of the compression exclusion criteria.
|
String |
generateCSSDependencies(LinkedHashSet<String> paths)
Generates a single compressed CSS resource from the supplied list of paths and
returns an MD5 checksum value that should be passed to the browser to when requesting
the dependencies from the server.
|
String |
generateJavaScriptDependencies(LinkedHashSet<String> paths)
Generates a single compressed JavaScript resource from the supplied list of paths and
returns an MD5 checksum value that should be passed to the browser to when requesting
the dependencies from the server.
|
String |
getCachedChecksumForFileSet(Set<String> fileSet)
This checks the cache to see if the requested set of files has previously been used to generate
an aggregated resource.
|
String |
getCachedCompressedCssResource(String path)
Attempts to retrieve a previously cached CSS resource.
|
String |
getCachedCompressedJSResource(String path) |
DependencyResource |
getCachedDependencyResource(String checksum)
Attempts to retrieve a previously stored aggregated resource that has been
mapped to a specific checksum.
|
DependencyHandler |
getDependencyHandler() |
protected Map<Set<String>,String> |
getFileSetChecksumCache()
Construct the File Set MD5 Checksum Cache
Currently this cache is based on a ConcurrentLinkedHashMap impl - to maintain a maximum size and insert order
allowing old items to be ejected in a deterministic pattern.
|
List<String> |
getMissingFileWarningSuppressionList()
Gets the paths to suppress missing file warnings for.
|
javax.servlet.ServletContext |
getServletContext() |
boolean |
isCollationDebugMode()
Indicates whether the client should operate in collation debug mode.
|
boolean |
isDebugMode()
Indicates whether the client should operate in debug mode.
|
protected String |
processCssImport(String importContents,
String cssPath,
String importPath,
Set<String> processedPaths)
Processes a single CSS import request.
|
StringBuffer |
processCssImports(String cssPath,
String fileContents,
Set<String> processedPaths)
When aggregating CSS files together its important to process any import statements that are included.
|
List<CacheReport> |
report() |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setCacheSize(int cacheSize) |
void |
setCharset(String charset) |
void |
setCompressionExclusions(List<String> compressionExclusions) |
void |
setCssImageDataHandler(CssImageDataHandler cssImageDataHandler) |
void |
setCssThemeHandler(CssThemeHandler cssThemeHandler) |
void |
setDependencyHandler(DependencyHandler dependencyHandler) |
void |
setDisableOptimizations(boolean disableOptimizations) |
void |
setLinebreak(int linebreak) |
void |
setMissingFileWarningSuppressionList(List<String> missingFileWarningSuppressionList)
Setter provided for Spring to set the missing file warning suppression list from the configuration.
|
void |
setMunge(boolean munge) |
void |
setPreserveAllSemiColons(boolean preserveAllSemiColons) |
void |
setScriptConfigModel(org.springframework.extensions.webscripts.ScriptConfigModel scriptConfigModel) |
void |
setVerbose(boolean verbose) |
public String charset
public int linebreak
public boolean munge
public boolean verbose
public boolean preserveAllSemiColons
public boolean disableOptimizations
public static final String FLAGS
public static final String CLIENT_DEBUG
public static final String CLIENT_COLLATION_DEBUG
public static final String INLINE_AGGREGATION_MARKER
public int cacheSize
public static char SINGLE_QUOTE
public static char DOUBLE_QUOTE
public static final Pattern p
public void setCacheSize(int cacheSize)
public void setCssImageDataHandler(CssImageDataHandler cssImageDataHandler)
public void setCssThemeHandler(CssThemeHandler cssThemeHandler)
public DependencyHandler getDependencyHandler()
public void setDependencyHandler(DependencyHandler dependencyHandler)
public boolean isDebugMode()
Indicates whether the client should operate in debug mode. This means that all dependency resources should not be compressed or collated.
public boolean isCollationDebugMode()
Indicates whether the client should operate in collation debug mode. This means that collated dependency resources should include the names of the files that have been collated.
public javax.servlet.ServletContext getServletContext()
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic void setScriptConfigModel(org.springframework.extensions.webscripts.ScriptConfigModel scriptConfigModel)
public List<String> getMissingFileWarningSuppressionList()
public void setMissingFileWarningSuppressionList(List<String> missingFileWarningSuppressionList)
missingFileWarningSuppressionList - The list of paths to suppress warnings for.public String generateJavaScriptDependencies(LinkedHashSet<String> paths)
Generates a single compressed JavaScript resource from the supplied list of paths and returns an MD5 checksum value that should be passed to the browser to when requesting the dependencies from the server. The combined compressed source is cached using the MD5 checksum as a key.
paths - A list of paths to compress and combine into a single resource.public String generateCSSDependencies(LinkedHashSet<String> paths)
Generates a single compressed CSS resource from the supplied list of paths and returns an MD5 checksum value that should be passed to the browser to when requesting the dependencies from the server. The combined compressed source is cached using the MD5 checksum as a key.
paths - A list of paths to compress and combine into a single resource.public String getCachedChecksumForFileSet(Set<String> fileSet)
fileSet - Setprotected void cacheChecksumForFileSet(Set<String> fileSet, String checksum)
fileSet - Setchecksum - Stringprotected Map<Set<String>,String> getFileSetChecksumCache()
public String getCachedCompressedCssResource(String path)
path - Stringprotected void cacheCompressedCssResource(String path, String content)
path - Stringcontent - Stringpublic DependencyResource getCachedDependencyResource(String checksum)
checksum - The checksum to look in the cache forDependencyResource or null if not cached.protected void cacheDependencyResource(String checksum, DependencyResource content)
public void clearCaches()
clearCaches in interface CacheReporterpublic List<CacheReport> report()
report in interface CacheReporterpublic void adjustImageURLs(String cssPath, StringBuilder cssContents) throws IOException
This method is used to ensure all image URL are correct when CSS files are aggregated together. It does this by converting relative paths to absolute paths to avoid issues where a relative path becomes invalid following aggregation of the CSS file.
cssPath - The path of the CSS file being aggregated.cssContents - The contents of the CSS file being aggregated.IOExceptionpublic StringBuffer processCssImports(String cssPath, String fileContents, Set<String> processedPaths)
cssPath - StringfileContents - StringprocessedPaths - Setprotected String processCssImport(String importContents, String cssPath, String importPath, Set<String> processedPaths) throws IOException
Processes a single CSS import request. This method ensures that infinite loops do not occur. The functionality has been abstracted to a separate method so that it can be called when either in debug or production modes.
importContents - The current contents of the CSS file being processed.cssPath - The current path of the CSS file being processed.importPath - The path requested to be imported within the current CSS file being processed.processedPaths - A Set of the paths already processed.IOExceptionpublic String compressJavaScript(Reader reader) throws IOException
Compresses the JavaScript file provided by the supplied InputStream using the YUI JavaScriptCompressor.
reader - ReaderIOExceptionpublic String compressCSSFile(InputStream in) throws IOException
Compresses the CSS file provided by the supplied InputStream using the YUI CssCompressor.
in - InputStreamIOExceptionpublic boolean excludeFileFromCompression(String path)
path - The path to check against the filterstrue if the path should be excluded and false otherwise.public void setCharset(String charset)
public void setLinebreak(int linebreak)
public void setMunge(boolean munge)
public void setVerbose(boolean verbose)
public void setPreserveAllSemiColons(boolean preserveAllSemiColons)
public void setDisableOptimizations(boolean disableOptimizations)
Copyright © 2005–2016 Alfresco Software. All rights reserved.