Package com.jalios.jcms.tools
Class AbstractFilePacker
java.lang.Object
com.jalios.jcms.tools.AbstractFilePacker
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractFilePacker(String extension) Builds a new file packer using specified options. -
Method Summary
Modifier and TypeMethodDescriptiongetFilePack(String... relativeFilePaths) Packs specified files into one and single string.getFilesInPack(String urlPrefix, String paramName, Collection<String> files, String browserName) Workaround the browser limitation by distributing many js/css accross several pack.protected abstract org.apache.log4j.LoggerReturns the logger to be used for log messages.getMinifiedFile(File cssOrJsFile, String relativeFilePath) Retrieve the minified File associated to the specified CSS or JS file.protected booleanisExcludedFromMinification(String relativeFilePath) Checks if given file should be excluded from minification due to exclusion regexps.booleanminifyFile(File cssOrJsFile, boolean force) Minify the specified CSS file into a compress version if it does not already exists in an up to date version.protected abstract booleanCheck if minification should be performed on each file as opposed to the whole pack.protected StringpostProcessPackContent(String packContent) Process the final pack content after optional minification.protected abstract StringprocessFileContent(String relativeFilePath, File file, String fileContent) Process file content before adding it to the packprotected abstract StringprocessPackContent(String packContent) Process the pack content before returning it the pack
-
Field Details
-
channel
-
CHANNEL_PACKER_MINIFY_EXCLUSION_REGEX
- See Also:
-
-
Constructor Details
-
AbstractFilePacker
Builds a new file packer using specified options.- Parameters:
extension- file extension required to pack file- Throws:
IOException- if an exception occurs
-
-
Method Details
-
getFilePack
Packs specified files into one and single string.- Parameters:
relativeFilePaths- an array of path relative to the webapp directory- Returns:
- a String containing path of all files to pack.
-
getMinifiedFile
Retrieve the minified File associated to the specified CSS or JS file.Example : If
new File("/test/foobar.css");is specified as parameter, this method will returnnew File("/WEB-INF/jcmswork/min.css/test/foobar.css");This method does not create the file, it simply retrieve the File instance.
- Parameters:
cssOrJsFile- a valid CSS or JS filerelativeFilePath- the path of the CSS or JS file relative to the webapp root- Returns:
- a new File instance
-
minifyFile
Minify the specified CSS file into a compress version if it does not already exists in an up to date version.For example, if
new File("/test/foobar.min.css");is specified as parameter, this checks ifnew File("/test/foobar.min.css");(as returned bygetMinifiedFile(File, String)) exists and is up to date, if it is not it will create it.- Parameters:
cssOrJsFile- the CSS File to compressforce- set to true to force generation of minified file even if an up to date apparently exists- Returns:
- true if File was minified, false otherwise
-
isExcludedFromMinification
Checks if given file should be excluded from minification due to exclusion regexps.Exclusion regexp can be declared using property "channel.packer.minify-exclusion-regex", or sub properties starting by "channel.packer.minify-exclusion-regex".
- Parameters:
relativeFilePath- the file to check if it must be minified or not- Returns:
- true if file must be minified, false otherwise
- Since:
- jcms-10.0.1
-
getFilesInPack
protected static Set<String> getFilesInPack(String urlPrefix, String paramName, Collection<String> files, String browserName) Workaround the browser limitation by distributing many js/css accross several pack.- 2000 characters maximum for URL length : limit length of pack
- 288Kb per js/css file/pack on IE : limit size of pack
- Parameters:
urlPrefix- the JS/CSS Packer URL previx, eg "css/csspacker.jsp?version=1234", "js/jspacker.jsp?"paramName- the param name to use eg : "css" or "js"files- the list of files to packbrowserName- name of the browser used to find the properties 'channel.packer.xxx' defining the limit values. Ifnull, use 'IE' because it's the most constraining.- Returns:
- a set of packed URL distributed with the maximum limits
-
processFileContent
protected abstract String processFileContent(String relativeFilePath, File file, String fileContent) Process file content before adding it to the pack- Parameters:
relativeFilePath- the relative path of the file being processedfile- the file being processedfileContent- the fileContent as read by the AbstractFilePacker- Returns:
- the processed file content, must not return null.
-
processPackContent
Process the pack content before returning it the pack- Parameters:
packContent- the whole pack content as computed by the AbstractFilePacker- Returns:
- the processed pack content, must not return null.
-
postProcessPackContent
Process the final pack content after optional minification.- Parameters:
packContent- the whole pack content as computed by the AbstractFilePacker- Returns:
- the post processed pack content, must not return null.
-
perFileMinificationEnabled
protected abstract boolean perFileMinificationEnabled()Check if minification should be performed on each file as opposed to the whole pack.- Returns:
- true to use minified version of individual file, false if minification is disabled or enabled on whole pack
-
getLogger
protected abstract org.apache.log4j.Logger getLogger()Returns the logger to be used for log messages. This methods must be implemented by the file packer.- Returns:
Loggerof this packer, must not return null.
-