org.kuali.rice.krad.uif.view
Class ViewTheme

java.lang.Object
  extended by org.kuali.rice.krad.datadictionary.DictionaryBeanBase
      extended by org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase
          extended by org.kuali.rice.krad.uif.view.ViewTheme
All Implemented Interfaces:
Serializable, DictionaryBean, UifDictionaryBean

public class ViewTheme
extends UifDictionaryBeanBase
implements Serializable

Holds a configuration of CSS and JS assets that provides the base for one or more views

The list of CSS and JS files that are sourced in for a view come from its theme, along with any additional files configured for the specific view. Generally an application will have one theme for the entire application. The theme has logic for 'dev' mode versus 'test/prod' mode. This is controlled through the rice.krad.dev.mode configuration variable. In development mode it will source in all the CSS and JS files individually (to allow for easier debugging). In non-development mode it will source in a minified file. The path for the minified files can be specified by setting getMinCssFile() and getMinScriptFile(). If not set, it will be formed by using the getName(), getMinVersionSuffix(), and min suffix (this is the file name generated by the theme builder). To indicate the min file should not be sourced in regardless of the environment, set the property isIncludeMinFiles() to false The path to the minified file is determined by getDirectory(). It this is not set, it is defaulted to be '/themes' plus the name of the theme (eg '/themes/kboot')

There are two ways the theme can be configured, manual or by convention. If you want to manually configured the view theme, set isUsesThemeBuilder() to false. For dev mode, you must then set the getMinCssSourceFiles() and getMinScriptSourceFiles() lists to the theme files. For configuration by convention, only the theme getName() is required. The directory will be assumed to be '/themes/{name}'. Furthermore the list of min CSS and JS files will be retrieved from the theme.properties file created by the theme builder

Author:
Kuali Rice Team (rice.collab@kuali.org)
See Also:
Serialized Form

Constructor Summary
ViewTheme()
           
 
Method Summary
 void configureThemeDefaults()
          Invoked by View#performApplyModel method to setup defaults for the theme
<T> T
copy()
          Returns a clone of the View Theme.
protected
<T> void
copyProperties(T viewTheme)
          Copies the properties over for the copy method.
 ConfigurationService getConfigurationService()
          Helper method to retrieve an instance of ConfigurationService
 List<String> getCssFiles()
          List of file paths (relative to the web root) or URLs that will be sourced into the view as CSS files
 String getDirectory()
          Path to the directory (relative to the web root) that holds the assets for the theme
 String getImageDirectory()
          Path to the directory (relative to the web root) that contains images for the theme
 String getMinCssFile()
          File path for the minified CSS file
 List<String> getMinCssSourceFiles()
          List of file paths (relative to web root) or URLs that make up the minified CSS file
 String getMinScriptFile()
          File path for the minified JS file
 List<String> getMinScriptSourceFiles()
          List of file paths (relative to web root) or URLs that make up the minified JS file
 String getMinVersionSuffix()
          When the min file paths are not set, the min file names will be generated using the theme name, version, and the min suffix.
 String getName()
          A name that identifies the view theme, when using the theme builder this should be the same as the directory (for example, if directory is '/themes/kboot', the theme name will be 'kboot')
protected  String[] getPropertyValue(Properties properties, String key)
          Helper method to retrieve the value of a property from the given Properties object as a string array (string is parsed using comma delimiter)
 List<String> getScriptFiles()
          List of file paths (relative to the web root) or URLs that will be sourced into the view as JS files
 String getThemeDirectory()
          Retrieves the directory associated with the theme
protected  Properties getThemeProperties()
          Retrieves the theme properties associated with the theme
protected  boolean inDevMode()
          Indicates whether operation is in development mode by checking the KRAD configuration parameter
 boolean isIncludeMinFiles()
          Indicates the min files should be sourced into the CSS and JS lists when not in development mode (this is regardless of whether theme builder is being used or not)
 boolean isUsesThemeBuilder()
          Indicates whether the theme has been built (or will be built) using the theme builder and therefore the theme configuration can be defaulted according to the conventions used by the builder
 void setCssFiles(List<String> cssFiles)
          Setter for the list of CSS files that should be sourced in along with the minified files
 void setDirectory(String directory)
          Setter for the theme directory path
 void setImageDirectory(String imageDirectory)
          Setter for the directory that contains images for the theme
 void setIncludeMinFiles(boolean includeMinFiles)
          Setter for including min files in the CSS and JS lists
 void setMinCssFile(String minCssFile)
          Setter for the min CSS file path
 void setMinCssSourceFiles(List<String> minCssSourceFiles)
          Setter for the min file CSS list
protected  void setMinFileLists()
          Sets the getMinScriptSourceFiles() and getMinCssSourceFiles() lists from the corresponding properties in the theme properties file
 void setMinScriptFile(String minScriptFile)
          Setter for the min JS file path
 void setMinScriptSourceFiles(List<String> minScriptSourceFiles)
          Setter for the min file JS list
 void setMinVersionSuffix(String minVersionSuffix)
          Setter for the min file version string
 void setName(String name)
          Setter for the theme name
 void setScriptFiles(List<String> scriptFiles)
          Setter for the list of JS files that should be sourced in along with the minified files
 void setUsesThemeBuilder(boolean usesThemeBuilder)
          Setter the indicates whether the theme uses the theme builder
 
Methods inherited from class org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase
getExpressionGraph, getPropertyExpression, getPropertyExpressions, getRefreshExpressionGraph, setExpressionGraph, setPropertyExpressions, setRefreshExpressionGraph
 
Methods inherited from class org.kuali.rice.krad.datadictionary.DictionaryBeanBase
getComponentCode, getNamespaceCode, setComponentCode, setNamespaceCode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.kuali.rice.krad.datadictionary.DictionaryBean
getComponentCode, getNamespaceCode
 

Constructor Detail

ViewTheme

public ViewTheme()
Method Detail

configureThemeDefaults

public void configureThemeDefaults()
Invoked by View#performApplyModel method to setup defaults for the theme

Checks whether we are in dev mode, if so it adds all the CSS and JS files as resources. If isUsesThemeBuilder() is true, retrieve the theme-derived.properties file in the theme directory to get the listing of CSS and JS files for theme When not in dev mode, builds the min file name and path for CSS and JS, which is added to the list that is sourced in


getThemeDirectory

public String getThemeDirectory()
Retrieves the directory associated with the theme

If getDirectory() is not configured, the theme directory is assumed to be located in the 'themes' folder of the web root. The directory name is assumed to be the name of the theme

Returns:
String path to theme directory relative to the web root

setMinFileLists

protected void setMinFileLists()
Sets the getMinScriptSourceFiles() and getMinCssSourceFiles() lists from the corresponding properties in the theme properties file


getThemeProperties

protected Properties getThemeProperties()
                                 throws IOException
Retrieves the theme properties associated with the theme

The theme builder creates a file named UifConstants.THEME_DERIVED_PROPERTY_FILE located in the theme directory. Here the path is formed and loaded into a properties object

Returns:
Properties object containing theme properties, or null if the properties file was not found
Throws:
IOException

getPropertyValue

protected String[] getPropertyValue(Properties properties,
                                    String key)
Helper method to retrieve the value of a property from the given Properties object as a string array (string is parsed using comma delimiter)

Parameters:
properties - properties object to pull property value from
key - key for the property to retrieve
Returns:
string array parsed from the property value, or null if property was not found or empty

inDevMode

protected boolean inDevMode()
Indicates whether operation is in development mode by checking the KRAD configuration parameter

Returns:
true if in dev mode, false if not

getName

public String getName()
A name that identifies the view theme, when using the theme builder this should be the same as the directory (for example, if directory is '/themes/kboot', the theme name will be 'kboot')

When using the theme builder (config by convention), the name is required configuration

Returns:
name for the theme

setName

public void setName(String name)
Setter for the theme name

Parameters:
name -

getDirectory

public String getDirectory()
Path to the directory (relative to the web root) that holds the assets for the theme

When using the theme builder the directory is not required and will default to '/themes/{name}'

Returns:
path to theme directory

setDirectory

public void setDirectory(String directory)
Setter for the theme directory path

Parameters:
directory -

getImageDirectory

public String getImageDirectory()
Path to the directory (relative to the web root) that contains images for the theme

Configured directory will populate the UifConstants.ContextVariableNames.THEME_IMAGES context variable which can be referenced with an expression for an image source

When using the theme builder the image directory is not required and will default to a sub directory of the theme directory with name 'images'

Returns:
theme image directory

setImageDirectory

public void setImageDirectory(String imageDirectory)
Setter for the directory that contains images for the theme

Parameters:
imageDirectory -

getMinVersionSuffix

public String getMinVersionSuffix()
When the min file paths are not set, the min file names will be generated using the theme name, version, and the min suffix. This property is set to indicate the version number to use

For application themes this can be set to the config parameter ${app.version}

Returns:
version string for the min file name

setMinVersionSuffix

public void setMinVersionSuffix(String minVersionSuffix)
Setter for the min file version string

Parameters:
minVersionSuffix -

isIncludeMinFiles

public boolean isIncludeMinFiles()
Indicates the min files should be sourced into the CSS and JS lists when not in development mode (this is regardless of whether theme builder is being used or not)

Default is true for including min files

Returns:
true if min files should be sourced in, false if not

setIncludeMinFiles

public void setIncludeMinFiles(boolean includeMinFiles)
Setter for including min files in the CSS and JS lists

Parameters:
includeMinFiles -

getMinCssFile

public String getMinCssFile()
File path for the minified CSS file

When min file is not set it will be generated by using the theme directory, name, version, and min prefix. This corresponds to the min file names generated by the theme builder For example, with name 'kboot' and version '2.3.0' the min file name will be '/themes/kboot/stylesheets/kboot.2.3.0.min.css'

Returns:
path of min css file

setMinCssFile

public void setMinCssFile(String minCssFile)
Setter for the min CSS file path

Parameters:
minCssFile -

getMinScriptFile

public String getMinScriptFile()
File path for the minified JS file

When min file is not set it will be generated by using the theme directory, name, version, and min prefix. This corresponds to the min file names generated by the theme builder For example, with name 'kboot' and version '2.3.0' the min file name will be '/themes/kboot/scripts/kboot.2.3.0.min.js'

Returns:
path of min css file

setMinScriptFile

public void setMinScriptFile(String minScriptFile)
Setter for the min JS file path

Parameters:
minScriptFile -

getMinCssSourceFiles

public List<String> getMinCssSourceFiles()
List of file paths (relative to web root) or URLs that make up the minified CSS file

In development mode, instead of sourcing in the min CSS file, the list of files specified here will be included. This is to facilitate easier debugging. When using the theme builder this list is automatically retrieved and populated from the theme properties

Returns:
list of min CSS file paths or URLs

setMinCssSourceFiles

public void setMinCssSourceFiles(List<String> minCssSourceFiles)
Setter for the min file CSS list

Parameters:
minCssSourceFiles -

getMinScriptSourceFiles

public List<String> getMinScriptSourceFiles()
List of file paths (relative to web root) or URLs that make up the minified JS file

In development mode, instead of sourcing in the min JS file, the list of files specified here will be included. This is to facilitate easier debugging. When using the theme builder this list is automatically retrieved and populated from the theme properties

Returns:
list of min JS file paths or URLs

setMinScriptSourceFiles

public void setMinScriptSourceFiles(List<String> minScriptSourceFiles)
Setter for the min file JS list

Parameters:
minScriptSourceFiles -

getCssFiles

public List<String> getCssFiles()
List of file paths (relative to the web root) or URLs that will be sourced into the view as CSS files

Generally this list should be left empty, and the min file lists configured instead (or none with theme builder). However if there are resources that are not part of the minified CSS file that should be included with the theme they can be added here The minified file path (or list of individual files that make up the minification) will be added to the beginning of this list. Therefore any entries explicitly added through configuration will be sourced in last

Returns:
list of file paths or URLs for CSS

setCssFiles

public void setCssFiles(List<String> cssFiles)
Setter for the list of CSS files that should be sourced in along with the minified files

Parameters:
cssFiles -

getScriptFiles

public List<String> getScriptFiles()
List of file paths (relative to the web root) or URLs that will be sourced into the view as JS files

Generally this list should be left empty, and the min file lists configured instead (or none with theme builder). However if there are resources that are not part of the minified JS file that should be included with the theme they can be added here The minified file path (or list of individual files that make up the minification) will be added to the beginning of this list. Therefore any entries explicitly added through configuration will be sourced in last

Returns:
list of file paths or URLs for JS

setScriptFiles

public void setScriptFiles(List<String> scriptFiles)
Setter for the list of JS files that should be sourced in along with the minified files

Parameters:
scriptFiles -

isUsesThemeBuilder

public boolean isUsesThemeBuilder()
Indicates whether the theme has been built (or will be built) using the theme builder and therefore the theme configuration can be defaulted according to the conventions used by the builder

When set to true, only the getName() property is required to be configured for the theme. All other configuration will be determined based on convention. When manually configuring the theme, this flag should be turned off (by default this flag is on)

Returns:
true if the theme uses the theme builder, false if not

setUsesThemeBuilder

public void setUsesThemeBuilder(boolean usesThemeBuilder)
Setter the indicates whether the theme uses the theme builder

Parameters:
usesThemeBuilder -

getConfigurationService

public ConfigurationService getConfigurationService()
Helper method to retrieve an instance of ConfigurationService

Returns:
instance of ConfigurationService

copy

public <T> T copy()
Returns a clone of the View Theme.

Overrides:
copy in class DictionaryBeanBase
Returns:
ViewTheme instance

copyProperties

protected <T> void copyProperties(T viewTheme)
Copies the properties over for the copy method.

Overrides:
copyProperties in class UifDictionaryBeanBase
Parameters:
viewTheme - ViewTheme instance to copy properties to


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