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

java.lang.Object
  extended by org.kuali.rice.krad.theme.postprocessor.ThemeFilesProcessor
      extended by org.kuali.rice.krad.theme.postprocessor.ThemeCssFilesProcessor

public class ThemeCssFilesProcessor
extends ThemeFilesProcessor

Theme files processor for CSS files

Merge contents are processed to rewrite any URLs (to images) for the changed path. CSS includes are not rewritten and will not work correctly in the merged file. For minification, the YUI compressor is used: YUI Compressor

Author:
Kuali Rice Team (rice.collab@kuali.org)
See Also:
ThemeFilesProcessor, CssCompressor

Field Summary
protected  int linebreak
           
 
Fields inherited from class org.kuali.rice.krad.theme.postprocessor.ThemeFilesProcessor
PLUGIN_FILES_KEY, projectVersion, SUBDIR_FILES_KEY, themeDirectory, themeName, themePluginDirsMap, themeProperties, workingDir
 
Constructor Summary
ThemeCssFilesProcessor(String themeName, File themeDirectory, Properties themeProperties, Map<String,File> themePluginDirsMap, File workingDir, String projectVersion)
           
 
Method Summary
protected  void addAdditionalFiles(List<File> themeFiles)
          Invoked during the collection of files to allow additional files to be added to the theme's list
protected  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 getFileListingConfigKey()
          Key for the property that will be written to the theme derived properties to list the included files for the file type
protected  String getFileTypeDirectoryName()
          Name of the directory relative to the theme directory which contains files for the type
protected  String getFileTypeExtension()
          Extension (ex.
protected  void minify(File mergedFile, File minifiedFile)
          Minifies the CSS contents from the given merged file into the minified file
protected  String processMergeFileContents(String fileContents, File fileToMerge, File mergedFile)
          Processes the merge contents to rewrite any URLs necessary for the directory change
protected  String rewriteCssUrls(String css, File mergeFile, File mergedFile)
          Performs URL rewriting within the given CSS contents
protected  List<File> sortThemeFiles(List<File> pluginFiles, List<File> subDirFiles)
          Sorts the list of CSS files from the plugin and sub directories
 
Methods inherited from class org.kuali.rice.krad.theme.postprocessor.ThemeFilesProcessor
addMissingPluginDirs, collectThemeFiles, createMergedFile, getFileExcludes, getFileIncludes, getFileTypeSubDirectory, getPropertyValueAsPluginDirs, getThemePropertyValue, mergeFiles, process
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

linebreak

protected int linebreak
Constructor Detail

ThemeCssFilesProcessor

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

getFileTypeExtension

protected String getFileTypeExtension()
Description copied from class: ThemeFilesProcessor
Extension (ex. 'css') for the file type being processed

Specified by:
getFileTypeExtension in class ThemeFilesProcessor
Returns:
file type extension
See Also:
ThemeFilesProcessor.getFileTypeExtension()

getExcludesConfigKey

protected String getExcludesConfigKey()
Description copied from class: ThemeFilesProcessor
Key for the property within the theme's properties file that can be configured to exlcude files of the type being processed

Specified by:
getExcludesConfigKey in class ThemeFilesProcessor
Returns:
property key for file type excludes
See Also:
ThemeFilesProcessor.getExcludesConfigKey()

getFileTypeDirectoryName

protected String getFileTypeDirectoryName()
Description copied from class: ThemeFilesProcessor
Name of the directory relative to the theme directory which contains files for the type

Specified by:
getFileTypeDirectoryName in class ThemeFilesProcessor
Returns:
directory name
See Also:
ThemeFilesProcessor.getFileTypeDirectoryName()

getFileListingConfigKey

protected String getFileListingConfigKey()
Description copied from class: ThemeFilesProcessor
Key for the property that will be written to the theme derived properties to list the included files for the file type

Specified by:
getFileListingConfigKey in class ThemeFilesProcessor
Returns:
property key for file type listing
See Also:
ThemeFilesProcessor.getFileListingConfigKey()

addAdditionalFiles

protected void addAdditionalFiles(List<File> themeFiles)
Description copied from class: ThemeFilesProcessor
Invoked during the collection of files to allow additional files to be added to the theme's list

Specified by:
addAdditionalFiles in class ThemeFilesProcessor
Parameters:
themeFiles - list of additional files to included for the theme
See Also:
ThemeFilesProcessor#addAdditionalFiles(java.util.List)

sortThemeFiles

protected List<File> sortThemeFiles(List<File> pluginFiles,
                                    List<File> subDirFiles)
Sorts the list of CSS files from the plugin and sub directories

The sorting algorithm is as follows:

  1. Any files which match patterns configured by the property cssLoadFirst
  2. CSS files from plugin directories, first ordered by any files that match patterns configured with pluginCssLoadOrder, followed by all remaining plugin files
  3. CSS files from the theme subdirectory, first ordered by any files that match patterns configured with themeCssLoadOrder, then any remaining theme files
  4. Files that match patterns configured by the property cssLoadLast. Note any files that match here will be excluded from any of the previous steps

Specified by:
sortThemeFiles in class ThemeFilesProcessor
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
See Also:
ThemeFilesProcessor#sortThemeFiles(java.util.List, java.util.List)

processMergeFileContents

protected String processMergeFileContents(String fileContents,
                                          File fileToMerge,
                                          File mergedFile)
                                   throws IOException
Processes the merge contents to rewrite any URLs necessary for the directory change

Specified by:
processMergeFileContents in class ThemeFilesProcessor
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
See Also:
ThemeFilesProcessor.processMergeFileContents(java.lang.String, java.io.File, java.io.File)

rewriteCssUrls

protected String rewriteCssUrls(String css,
                                File mergeFile,
                                File mergedFile)
                         throws IOException
Performs URL rewriting within the given CSS contents

The given merge file (where the merge contents come from) and the merged file (where they are going to) is used to determine the path difference. Once that path difference is found, the contents are then matched to find any URLs. For each relative URL (absolute URLs are not modified), the path is adjusted and replaced into the contents. ex. suppose the merged file is /plugins/foo/plugin.css, and the merged file is /themes/mytheme/stylesheets/merged.css, the path difference will then be '../../../plugins/foo/'. So a URL in the CSS contents of 'images/image.png' will get rewritten to '../../../plugins/foo/images/image.png'

Parameters:
css - contents to adjust URLs for
mergeFile - file that provided the merge contents
mergedFile - file the contents will be going to
Returns:
css contents, with possible adjusted URLs
Throws:
IOException

minify

protected void minify(File mergedFile,
                      File minifiedFile)
               throws IOException
Minifies the CSS contents from the given merged file into the minified file

Minification is performed using the YUI Compressor compiler with no line break

Specified by:
minify in class ThemeFilesProcessor
Parameters:
mergedFile - file containing the merged contents
minifiedFile - file created to receive the minified contents
Throws:
IOException
See Also:
ThemeFilesProcessor.minify(java.io.File, java.io.File), CssCompressor


Copyright © 2005–2014 The Kuali Foundation. All rights reserved.