Class AbstractFilePacker

java.lang.Object
com.jalios.jcms.tools.AbstractFilePacker
Direct Known Subclasses:
CssPacker, JsPacker

public abstract class AbstractFilePacker extends Object
  • Field Details

    • channel

      protected static final Channel channel
    • CHANNEL_PACKER_MINIFY_EXCLUSION_REGEX

      protected static final String CHANNEL_PACKER_MINIFY_EXCLUSION_REGEX
      See Also:
  • Constructor Details

    • AbstractFilePacker

      protected AbstractFilePacker(String extension) throws IOException
      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

      public String getFilePack(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 File getMinifiedFile(File cssOrJsFile, 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(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(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 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 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 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 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 String processPackContent(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.
    • postProcessPackContent

      protected String postProcessPackContent(String packContent)
      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:
      Logger of this packer, must not return null.