org.kuali.rice.krad.theme.postprocessor
Class ThemeFilesProcessor

java.lang.Object
  extended by 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

Base class also provides some helper methods such as getPropertyValueAsPluginDirs(java.lang.String) and #addMissingPluginDirs(java.util.List)

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

Field Summary
protected static String PLUGIN_FILES_KEY
           
protected  String projectVersion
           
protected static String SUBDIR_FILES_KEY
           
protected  File themeDirectory
           
protected  String themeName
           
protected  Map<String,File> themePluginDirsMap
           
protected  Properties themeProperties
           
protected  File workingDir
           
 
Constructor Summary
ThemeFilesProcessor(String themeName, File themeDirectory, Properties themeProperties, Map<String,File> themePluginDirsMap, File workingDir, String projectVersion)
           
 
Method Summary
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
protected  List<File> addMissingPluginDirs(List<File> pluginList)
          Helper method to add any plugin directories for the theme being processed to the given list if they are not already contained in the list
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
protected  File createMergedFile(boolean minified)
          Creates a new file that will hold the merged or minified contents
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
protected  String[] getFileExcludes()
          Builds array of patterns used to exclude files to include for the type
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
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
protected abstract  String getFileTypeDirectoryName()
          Name of the directory relative to the theme directory which contains files for the type
protected abstract  String getFileTypeExtension()
          Extension (ex.
protected  File getFileTypeSubDirectory()
          Returns the File object that points to the theme subdirectory that contains files for the file type
protected  List<File> getPropertyValueAsPluginDirs(String propertyKey)
          Helper method that retrieves the value for the given property from the theme's properties as a list of file objects that point to plugin directories
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
protected  void mergeFiles(List<File> filesToMerge, File mergedFile)
          Merges the content from the list of files into the given merge file
protected abstract  void minify(File mergedFile, File minifiedFile)
          Invoked after the merged file has been created to create the minified version
 void process()
          Carries out the theme files post process
protected abstract  String processMergeFileContents(String fileContents, File fileToMerge, File mergedFile)
          Invoked during the merge process to alter the given file contents before they are appended to the merge file
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLUGIN_FILES_KEY

protected static final String PLUGIN_FILES_KEY
See Also:
Constant Field Values

SUBDIR_FILES_KEY

protected static final String SUBDIR_FILES_KEY
See Also:
Constant Field Values

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 Detail

ThemeFilesProcessor

public ThemeFilesProcessor(String themeName,
                           File themeDirectory,
                           Properties themeProperties,
                           Map<String,File> themePluginDirsMap,
                           File workingDir,
                           String projectVersion)
Method Detail

process

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

Processing of each file type includes the following:

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(), getFileExcludes(), getFileTypeSubDirectory(), addAdditionalFiles(java.util.List)

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:
getFileTypeExtension()

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
See Also:
getExcludesConfigKey();

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:
getFileTypeDirectoryName()

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

getPropertyValueAsPluginDirs

protected List<File> getPropertyValueAsPluginDirs(String propertyKey)
Helper method that retrieves the value for the given property from the theme's properties as a list of file objects that point to plugin directories

Parameters:
propertyKey - key for the property to retrieve the value for
Returns:
list of files (plugin directories) parsed from the property value

addMissingPluginDirs

protected List<File> addMissingPluginDirs(List<File> pluginList)
Helper method to add any plugin directories for the theme being processed to the given list if they are not already contained in the list

Parameters:
pluginList - list of plugin directories to complete
Returns:
list of plugin directories that includes all plugins for the theme


Copyright © 2005-2014 The Kuali Foundation. All Rights Reserved.