Class ThemeBuilderUtils

java.lang.Object
org.kuali.rice.krad.theme.util.ThemeBuilderUtils

public class ThemeBuilderUtils extends Object
Utility methods for the view builder module
Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addExtensionToPatterns(String[] patterns, String extension)
    Iterates through the given list of patterns and checks whether the pattern ends with the given extension or a wildcard, if not the extension is appended to the pattern
    static String[]
    addToArray(String[] array, String stringToAdd)
    Adds the string to the end of the array of strings, or creates a new array containing the string if the array parameter is null
    static String[]
    addToArray(String[] array, String[] arrayToAdd)
    Adds the second array of strings to the end of the first array of strings, or creates a new array containing the second array elements if the first does not exist
    static String
    calculatePathToFile(File fromFile, File toFile)
    Calculates the path from the first file to the second
    static void
    copyDirectory(String sourceDirectoryPath, String targetDirectoryPath)
    Copies all the contents from the directory given by the source path to the directory given by the target path
    static void
    copyMissingContent(File sourceDirectory, File targetDirectory, List<String> sourceExcludes)
    Copies all content (files and directories) from the source directory to the target directory, except content that already exists in the target directory (same name and path), in other words it does not override any existing content
    static void
    copyProperty(String propertyKey, Properties sourceProperties, Properties targetProperties)
    Copies the property key/value from the source properties to the target properties if a property with the same key does not exist in the target properties
    protected static boolean
    Indicates whether the given file is withing the given path (file's path starts with the given path), note this does not check whether the file exists
    static List<String>
    getDirectoryContents(File baseDirectory, String[] includes, String[] excludes)
    Retrieves a list of files and directories that are in the given directory, possibly filtered by the list of include patterns or exclude patterns
    static List<String>
    getDirectoryFileNames(File baseDirectory, String[] includes, String[] excludes)
    Retrieves a list of file names that are in the given directory, possibly filtered by the list of include patterns or exclude patterns
    static List<File>
    getDirectoryFiles(File baseDirectory, String[] includes, String[] excludes)
    Retrieves a list of files that are in the given directory, possibly filtered by the list of include patterns or exclude patterns
    static String[]
    Retrieves the value for the property with the given key from the properties object, as an array of strings (by splitting the value on commas)
    static List<String>
    Retrieves the value for the property with the given key from the properties object, as a list of strings (by splitting the value on commas)
    static String
    getRelativePath(File parentDirectory, File file)
    Returns the path of the given file relative to the parent directory
    static List<String>
    getRelativePaths(File parentDirectory, List<File> files)
    Builds a list of strings that hold the path from each given file relative to the parent directory
    static List<File>
    getSubDirectories(File baseDirectory, List<String> subDirectoryNames)
    Get the sub directories of the given directory that have the given names
    static boolean
    inExcludeList(String name, String[] excludes)
    Determines if one of the given patterns matches the given name, or if the exclude list is null or empty the file will not be excluded
    static boolean
    inIncludeList(String name, String[] includes)
    Determines if one of the given patterns matches the given name, or if the include list is null or empty the file will be included
    static boolean
    isMatch(File file, String pattern)
    Indicates whether the base name for the given file (name without path and the extension) matches the given pattern
    static List<File>
    matchFiles(List<File> filesToMatch, String pattern)
    Iterates through the list of files and returns those files whose names matches the given pattern
    static List<File>
    orderFiles(List<File> pluginFiles, List<File> subDirFiles, List<String> loadFirstPatterns, List<String> loadLastPatterns, List<String> pluginLoadOrder, List<String> subDirLoadOrder)
    Orders the list of plugin files and sub directory files according to the given patterns
    static Properties
    Retrieve the Properties object loaded from the theme.properties file found in the given theme directory
    static void
    storeThemeProperties(String themeDirectory, Properties themeProperties)
    Stores the given properties object in a file named theme-derived.properties within the given theme directory
    static void
    validateFileExistence(List<File> filesToValidate, String exceptionMessage)
    Iterates through each file in the given list and verifies the file exists, if not a runtime exception is thrown with the provided message

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ThemeBuilderUtils

      public ThemeBuilderUtils()
  • Method Details

    • retrieveThemeProperties

      public static Properties retrieveThemeProperties(String themeDirectory) throws IOException
      Retrieve the Properties object loaded from the theme.properties file found in the given theme directory
      Parameters:
      themeDirectory - directory for the theme to pull properties file from
      Returns:
      Properties object loaded with the theme configuration, or null if the properties file does not exist
      Throws:
      IOException
    • storeThemeProperties

      public static void storeThemeProperties(String themeDirectory, Properties themeProperties) throws IOException
      Stores the given properties object in a file named theme-derived.properties within the given theme directory
      Parameters:
      themeDirectory - directory the properties file should be created in
      themeProperties - properties that should be written to the properties file
      Throws:
      IOException
    • getPropertyValueAsList

      public static List<String> getPropertyValueAsList(String key, Properties properties)
      Retrieves the value for the property with the given key from the properties object, as a list of strings (by splitting the value on commas)
      Parameters:
      key - key for the property to retrieve
      properties - properties object to pull property from
      Returns:
      list of strings parsed from the property value
    • getPropertyValueAsArray

      public static String[] getPropertyValueAsArray(String key, Properties properties)
      Retrieves the value for the property with the given key from the properties object, as an array of strings (by splitting the value on commas)
      Parameters:
      key - key for the property to retrieve
      properties - properties object to pull property from
      Returns:
      array of strings parsed from the property value
    • copyProperty

      public static void copyProperty(String propertyKey, Properties sourceProperties, Properties targetProperties)
      Copies the property key/value from the source properties to the target properties if a property with the same key does not exist in the target properties
      Parameters:
      propertyKey - key of the property to copy
      sourceProperties - properties to pull the property from
      targetProperties - properties to copy the property to
    • validateFileExistence

      public static void validateFileExistence(List<File> filesToValidate, String exceptionMessage)
      Iterates through each file in the given list and verifies the file exists, if not a runtime exception is thrown with the provided message
      Parameters:
      filesToValidate - list of files to check existence for
      exceptionMessage - message for runtime exception if a file is found that does not exist
    • getDirectoryFiles

      public static List<File> getDirectoryFiles(File baseDirectory, String[] includes, String[] excludes)
      Retrieves a list of files that are in the given directory, possibly filtered by the list of include patterns or exclude patterns
      Parameters:
      baseDirectory - directory to retrieve files from
      includes - list of patterns to match against for files to include, can include Ant patterns
      excludes - list of patterns to match for excluded files, can include Ant patterns
      Returns:
      list of files within the directory that match all given patterns
    • getDirectoryFileNames

      public static List<String> getDirectoryFileNames(File baseDirectory, String[] includes, String[] excludes)
      Retrieves a list of file names that are in the given directory, possibly filtered by the list of include patterns or exclude patterns
      Parameters:
      baseDirectory - directory to retrieve file names from
      includes - list of patterns to match against for file names to include, can include Ant patterns
      excludes - list of patterns to match for excluded file names, can include Ant patterns
      Returns:
      list of file names within the directory that match all given patterns
    • getSubDirectories

      public static List<File> getSubDirectories(File baseDirectory, List<String> subDirectoryNames)
      Get the sub directories of the given directory that have the given names
      Parameters:
      baseDirectory - directory containing the sub directories
      subDirectoryNames - list of sub directory names to return
      Returns:
      list of Files pointing to the sub directories
    • getDirectoryContents

      public static List<String> getDirectoryContents(File baseDirectory, String[] includes, String[] excludes)
      Retrieves a list of files and directories that are in the given directory, possibly filtered by the list of include patterns or exclude patterns
      Parameters:
      baseDirectory - directory to retrieve files and directories from
      includes - list of patterns to match against for files to include, can include Ant patterns
      excludes - list of patterns to match for excluded files, can include Ant patterns
      Returns:
      list of files within the directory that match all given patterns
    • copyDirectory

      public static void copyDirectory(String sourceDirectoryPath, String targetDirectoryPath) throws IOException
      Copies all the contents from the directory given by the source path to the directory given by the target path

      If source directory does not exist nothing is performed. The target directory will be created if it does not exist. Any hidden directories (directory names that start with ".") will be deleted from the target directory

      Parameters:
      sourceDirectoryPath - absolute path to the source directory
      targetDirectoryPath - absolute path to the target directory
      Throws:
      IOException
    • copyMissingContent

      public static void copyMissingContent(File sourceDirectory, File targetDirectory, List<String> sourceExcludes) throws IOException
      Copies all content (files and directories) from the source directory to the target directory, except content that already exists in the target directory (same name and path), in other words it does not override any existing content

      Files from the source directory can be excluded from the copying by setting one or more patterns in the source excludes list

      Parameters:
      sourceDirectory - directory to copy content from
      targetDirectory - directory to copy content to
      sourceExcludes - list of patterns to match on for source exclusions
      Throws:
      IOException
    • inIncludeList

      public static boolean inIncludeList(String name, String[] includes)
      Determines if one of the given patterns matches the given name, or if the include list is null or empty the file will be included
      Parameters:
      name - string to match
      includes - list of string patterns to match on
      Returns:
      true if the name is a match, false if not
    • inExcludeList

      public static boolean inExcludeList(String name, String[] excludes)
      Determines if one of the given patterns matches the given name, or if the exclude list is null or empty the file will not be excluded
      Parameters:
      name - string to match
      excludes - list of string patterns to match on
      Returns:
      true if the name is a match, false if not
    • addExtensionToPatterns

      public static void addExtensionToPatterns(String[] patterns, String extension)
      Iterates through the given list of patterns and checks whether the pattern ends with the given extension or a wildcard, if not the extension is appended to the pattern
      Parameters:
      patterns - array of patterns to check and append to if necessary
      extension - string extension to check for and append if necessary
    • getRelativePaths

      public static List<String> getRelativePaths(File parentDirectory, List<File> files)
      Builds a list of strings that hold the path from each given file relative to the parent directory
      Parameters:
      parentDirectory - directory to build path from
      files - list of files to build relative paths for
      Returns:
      list of strings containing the relative paths
    • getRelativePath

      public static String getRelativePath(File parentDirectory, File file)
      Returns the path of the given file relative to the parent directory
      Parameters:
      parentDirectory - directory to build path from
      file - file to build relative paths for
      Returns:
      string containing the relative path
    • calculatePathToFile

      public static String calculatePathToFile(File fromFile, File toFile)
      Calculates the path from the first file to the second

      Assumes there is a common base directory somewhere in the path of both files. Once it finds that base directory, builds the path starting at the from file to it, then adds the path from the base directory to the target file

      Parameters:
      fromFile - file whose path is the starting point
      toFile - file whose path is the ending point
      Returns:
      string containing the path
    • fileMatchesPath

      protected static boolean fileMatchesPath(String path, File file)
      Indicates whether the given file is withing the given path (file's path starts with the given path), note this does not check whether the file exists
      Parameters:
      path - path to check for
      file - file whose path should be checked
      Returns:
      true if the file is contained in the path, false if not
    • orderFiles

      public static List<File> orderFiles(List<File> pluginFiles, List<File> subDirFiles, List<String> loadFirstPatterns, List<String> loadLastPatterns, List<String> pluginLoadOrder, List<String> subDirLoadOrder)
      Orders the list of plugin files and sub directory files according to the given patterns
      Parameters:
      pluginFiles - list of plugin files to order
      subDirFiles - list of sub directory files to order
      loadFirstPatterns - list of patterns for files that should be ordered first
      loadLastPatterns - list of patterns for files that should be ordered last
      pluginLoadOrder - list of patterns for ordering the plugin files
      subDirLoadOrder - list of patterns for ordering the sub directory files
      Returns:
      list containing all of the given plugin and sub directory files ordered by the given patterns
    • matchFiles

      public static List<File> matchFiles(List<File> filesToMatch, String pattern)
      Iterates through the list of files and returns those files whose names matches the given pattern
      Parameters:
      filesToMatch - list of files to match
      pattern - pattern to match on
      Returns:
      list of files whose name that match the pattern
    • isMatch

      public static boolean isMatch(File file, String pattern)
      Indicates whether the base name for the given file (name without path and the extension) matches the given pattern
      Parameters:
      file - file to match
      pattern - pattern to match on
      Returns:
      true if the file name matches the pattern, false if not
    • addToArray

      public static String[] addToArray(String[] array, String stringToAdd)
      Adds the string to the end of the array of strings, or creates a new array containing the string if the array parameter is null
      Parameters:
      array - string array to add to
      stringToAdd - string to add
      Returns:
      array containing all the original array elements plus the string
    • addToArray

      public static String[] addToArray(String[] array, String[] arrayToAdd)
      Adds the second array of strings to the end of the first array of strings, or creates a new array containing the second array elements if the first does not exist

      Note: Can't use org.apache.commons.lang.ArrayUtils#addAll(java.lang.Object[], java.lang.Object[]) because it doesn't allow String arrays to be passed in. Latest version of ArrayUtils uses generics and does

      Parameters:
      array - array to add to
      arrayToAdd - array to add
      Returns:
      array containing all the strings from both arrays