Class AbstractFilePacker

  • Direct Known Subclasses:
    CssPacker, JsPacker

    public abstract class AbstractFilePacker
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractFilePacker​(java.lang.String extension)
      Builds a new file packer using specified options.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getFilePack​(java.lang.String[] relativeFilePaths)
      Packs specified files into one and single string.
      protected static java.util.Set<java.lang.String> getFilesInPack​(java.lang.String urlPrefix, java.lang.String paramName, java.util.Collection<java.lang.String> files, java.lang.String browserName)
      Workaround the browser limitation by distributing many js/css accross several pack.
      protected abstract org.apache.log4j.Logger getLogger()
      Returns the logger to be used for log messages.
      java.io.File getMinifiedFile​(java.io.File cssOrJsFile, java.lang.String relativeFilePath)
      Retrieve the minified File associated to the specified CSS or JS file.
      protected boolean isExcludedFromMinification​(java.lang.String relativeFilePath)
      Checks if given file should be excluded from minification due to exclusion regexps.
      boolean minifyFile​(java.io.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 boolean perFileMinificationEnabled()
      Check if minification should be performed on each file as opposed to the whole pack.
      protected abstract java.lang.String processFileContent​(java.lang.String relativeFilePath, java.io.File file, java.lang.String fileContent)
      Process file content before adding it to the pack
      protected abstract java.lang.String processPackContent​(java.lang.String packContent)
      Process the pack content before returning it the pack
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • channel

        protected static final Channel channel
      • CHANNEL_PACKER_MINIFY_EXCLUSION_REGEX

        protected static final java.lang.String CHANNEL_PACKER_MINIFY_EXCLUSION_REGEX
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractFilePacker

        protected AbstractFilePacker​(java.lang.String extension)
                              throws java.io.IOException
        Builds a new file packer using specified options.
        Parameters:
        extension - file extension required to pack file
        Throws:
        java.io.IOException - if an exception occurs
    • Method Detail

      • getFilePack

        public java.lang.String getFilePack​(java.lang.String[] relativeFilePaths)
        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

        public java.io.File getMinifiedFile​(java.io.File cssOrJsFile,
                                            java.lang.String relativeFilePath)
        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 return new 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 file
        relativeFilePath - the path of the CSS or JS file relative to the webapp root
        Returns:
        a new File instance
      • minifyFile

        public boolean minifyFile​(java.io.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.

        For example, if new File("/test/foobar.min.css"); is specified as parameter, this checks if new File("/test/foobar.min.css"); (as returned by getMinifiedFile(File, String)) exists and is up to date, if it is not it will create it.

        Parameters:
        cssOrJsFile - the CSS File to compress
        force - 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

        protected boolean isExcludedFromMinification​(java.lang.String relativeFilePath)
        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 java.util.Set<java.lang.String> getFilesInPack​(java.lang.String urlPrefix,
                                                                        java.lang.String paramName,
                                                                        java.util.Collection<java.lang.String> files,
                                                                        java.lang.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 pack
        browserName - name of the browser used to find the properties 'channel.packer.xxx' defining the limit values. If null, use 'IE' because it's the most constraining.
        Returns:
        a set of packed URL distributed with the maximum limits
      • processFileContent

        protected abstract java.lang.String processFileContent​(java.lang.String relativeFilePath,
                                                               java.io.File file,
                                                               java.lang.String fileContent)
        Process file content before adding it to the pack
        Parameters:
        relativeFilePath - the relative path of the file being processed
        file - the file being processed
        fileContent - the fileContent as read by the AbstractFilePacker
        Returns:
        the processed file content, must not return null.
      • processPackContent

        protected abstract java.lang.String processPackContent​(java.lang.String packContent)
        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.
      • 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:
        Logger of this packer, must not return null.