Class ThemeFilesProcessor

java.lang.Object
org.kuali.rice.krad.theme.postprocessor.ThemeFilesProcessor
Direct Known Subclasses:
ThemeCssFilesProcessor, ThemeJsFilesProcessor

public abstract class ThemeFilesProcessor extends Object
Base class for the JS and CSS theme file processors (or post-processors) that act on a given theme

The post processing of JS and CSS files is orchestrated in this base class with the specific configuration for each provided through abstract methods. This process() method performs the major calls of the process

Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Field Details

    • PLUGIN_FILES_KEY

      protected static final String PLUGIN_FILES_KEY
      See Also:
    • SUBDIR_FILES_KEY

      protected static final String SUBDIR_FILES_KEY
      See Also:
    • themeName

      protected String themeName
    • themeDirectory

      protected File themeDirectory
    • themeProperties

      protected Properties themeProperties
    • themePluginDirsMap

      protected Map<String,File> themePluginDirsMap
    • workingDir

      protected File workingDir
    • projectVersion

      protected String projectVersion
  • Constructor Details

  • Method Details

    • process

      public void process()
      Carries out the theme files post process

      Processing of each file type includes the following:

      • Collect the theme files for each type
      • Perform a sorting process on the files to form the correct order of sourcing or merging
      • Merge all the files for the type into a single file. Here subclasses can perform alterations on the merged contents
      • Minifiy the merged file using a compressor that is appropriate for the file type
      • Write out the listing of files for the type to the theme's properties file

      Any IOException that occur are caught and thrown as runtime exceptions

    • collectThemeFiles

      protected Map<String,List<File>> collectThemeFiles()
      Collects the file names to include for the theme, separated by whether they come from a plugin directory or the theme directory

      First all plugin directories that are included for the theme are listed based on the include for that file type getFileIncludes(). Individual plugin files can be excluded with the property pluginFileExcludes, or the global excludes for the file type getFileExcludes() Next the subdirectory of the theme that holds the file type, given by getFileTypeSubDirectory(), is listed to pick up include files. Again the global file includes and excludes for the type is used Finally, subclasses can add additional files by implementing addAdditionalFiles(java.util.List)

      Returns:
      map containing an entry for plugin file names, and theme file names. Keys are given by PLUGIN_FILES_KEY and SUBDIR_FILES_KEY
      See Also:
    • getFileIncludes

      protected String[] getFileIncludes()
      Builds array of patterns used to find files to include for the type, by default picks up all files that have the extension for the type being processed
      Returns:
      array of string patterns to include
      See Also:
    • getFileExcludes

      protected String[] getFileExcludes()
      Builds array of patterns used to exclude files to include for the type

      Each file type has a configuration property where exclude patterns can be listed. This property key is retrieved by getExcludesConfigKey(), and then split by the comma to get the array of patterns

      Returns:
      array of string patterns to exclude
    • getFileTypeSubDirectory

      protected File getFileTypeSubDirectory()
      Returns the File object that points to the theme subdirectory that contains files for the file type

      Sub directory is formed by finding the directory with name getFileTypeDirectoryName() within the theme directory

      Returns:
      sub directory for the file type
      See Also:
    • createMergedFile

      protected File createMergedFile(boolean minified)
      Creates a new file that will hold the merged or minified contents

      The merged file name is constructed by taking the theme name, concatenated with "." and the project version. To form the minified file name, the min suffix ".min" is appended to the merged file name

      Parameters:
      minified - indicates whether to add the minified suffix
      Returns:
      file object pointing to the merged or minified file
    • mergeFiles

      protected void mergeFiles(List<File> filesToMerge, File mergedFile) throws IOException
      Merges the content from the list of files into the given merge file

      Contents are read for each file in the order they appear in the files list. Before adding the contents to the merged file, the method processMergeFileContents(java.lang.String, java.io.File, java.io.File) is invoked to allow subclasses to alter the contents

      Parameters:
      filesToMerge - list of files whose content should be merged
      mergedFile - file that should receive the merged content
      Throws:
      IOException
    • getFileTypeExtension

      protected abstract String getFileTypeExtension()
      Extension (ex. 'css') for the file type being processed
      Returns:
      file type extension
    • getFileTypeDirectoryName

      protected abstract String getFileTypeDirectoryName()
      Name of the directory relative to the theme directory which contains files for the type
      Returns:
      directory name
    • getExcludesConfigKey

      protected abstract String getExcludesConfigKey()
      Key for the property within the theme's properties file that can be configured to exlcude files of the type being processed
      Returns:
      property key for file type excludes
    • getFileListingConfigKey

      protected abstract String getFileListingConfigKey()
      Key for the property that will be written to the theme derived properties to list the included files for the file type
      Returns:
      property key for file type listing
    • addAdditionalFiles

      protected abstract void addAdditionalFiles(List<File> themeFiles)
      Invoked during the collection of files to allow additional files to be added to the theme's list
      Parameters:
      themeFiles - list of additional files to included for the theme
    • sortThemeFiles

      protected abstract List<File> sortThemeFiles(List<File> pluginFiles, List<File> subDirFiles)
      Invoked to build the final sorted list of files for the type, files from plugins and from the theme's sub directory are passed separately so special treatment can be given to those for sorting
      Parameters:
      pluginFiles - list of files that will be included and come from a plugin directory
      subDirFiles - list of files that will be included and come from the theme subdirectory
      Returns:
      list of all files to include for the theme in the correct source order
    • processMergeFileContents

      protected abstract String processMergeFileContents(String fileContents, File fileToMerge, File mergedFile) throws IOException
      Invoked during the merge process to alter the given file contents before they are appended to the merge file
      Parameters:
      fileContents - contents of the file that will be added
      fileToMerge - file the contents were pulled from
      mergedFile - file receiving the merged contents
      Returns:
      file contents to merge (possibly altered)
      Throws:
      IOException
    • minify

      protected abstract void minify(File mergedFile, File minifiedFile) throws IOException
      Invoked after the merged file has been created to create the minified version
      Parameters:
      mergedFile - file containing the merged contents
      minifiedFile - file created to receive the minified contents
      Throws:
      IOException
    • getThemePropertyValue

      protected List<String> getThemePropertyValue(String propertyKey)
      Helper method that retrieves the value for the given property from the theme's properties as a list of strings
      Parameters:
      propertyKey - key for the property to retrieve the value for
      Returns:
      list of string values parsed from the property value