Class PropertiesFileExtensions


  • public final class PropertiesFileExtensions
    extends java.lang.Object
    The class PropertiesFileExtensions provides methods for load properties file
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Properties getLocalPropertiesFromClass​(java.lang.Class<?> componentClass, java.lang.Class<?> defaultClass, java.util.Locale locale)
      Gets the properties.
      static java.lang.String getProjectName()
      Gets the project name from the 'project.properties'.
      static java.util.Map<java.io.File,​java.util.Map<java.lang.String,​java.util.List<java.lang.String>>> getRedundantKeys​(java.io.File dirToSearch)
      Gets the redundant keys in properties files from the given directory.
      static java.util.Properties loadProperties​(java.io.File propertiesFile)
      Load a Properties-object from the given File-object.
      static java.util.Properties loadProperties​(java.lang.Class<?> clazz, java.lang.String name)
      Load properties.
      static java.util.Properties loadProperties​(java.lang.Class<?> clazz, java.lang.String packagePath, java.lang.String fileName)
      Load properties.
      static java.util.Properties loadProperties​(java.lang.String packagePath)
      Gives a Properties-object from the given packagepath.
      static java.util.Properties loadProperties​(java.lang.String packagePath, java.lang.String fileName)
      Load properties.
      static <T> java.util.Properties loadProperties​(T object, java.lang.String propertiesFilename)
      Load Properties object from the given arguments.
      static java.util.Properties loadPropertiesFromClassObject​(java.lang.Class<?> clazz, java.util.Locale locale)
      Load the properties file from the given class object.
      static java.io.File newBackupOf​(java.io.File file)
      Creates a backup file from the given properties file.
      static java.util.List<java.lang.String> removeComments​(java.io.File propertiesFile)
      Removes the comments from the given properties file.
      static java.util.Set<java.lang.String> resolveAvailableLanguages​(java.lang.String bundlepackage, java.lang.String bundlename)
      Resolves all the available languages for the given resource bundle name in the given bundle package.
      • Methods inherited from class java.lang.Object

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

      • PropertiesFileExtensions

        public PropertiesFileExtensions()
    • Method Detail

      • getLocalPropertiesFromClass

        public static java.util.Properties getLocalPropertiesFromClass​(java.lang.Class<?> componentClass,
                                                                       java.lang.Class<?> defaultClass,
                                                                       java.util.Locale locale)
                                                                throws java.io.IOException
        Gets the properties.
        Parameters:
        componentClass - the component class
        defaultClass - the default class
        locale - the locale
        Returns:
        the properties
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • getProjectName

        public static java.lang.String getProjectName()
                                               throws java.io.IOException
        Gets the project name from the 'project.properties'. In this properties file is only a reference of the artifactId from the pom.
        Returns:
        the project name
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • getRedundantKeys

        public static java.util.Map<java.io.File,​java.util.Map<java.lang.String,​java.util.List<java.lang.String>>> getRedundantKeys​(java.io.File dirToSearch)
                                                                                                                                         throws java.io.IOException
        Gets the redundant keys in properties files from the given directory. The search is recursive and finds all properties files. The result is a map with key the properties file and the found redundant keys as a map.
        Parameters:
        dirToSearch - the dir to search
        Returns:
        the redundant keys
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • loadProperties

        public static java.util.Properties loadProperties​(java.lang.Class<?> clazz,
                                                          java.lang.String name)
                                                   throws java.io.IOException
        Load properties.
        Parameters:
        clazz - the clazz
        name - the package path with the file name
        Returns:
        the properties
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • loadProperties

        public static java.util.Properties loadProperties​(java.lang.Class<?> clazz,
                                                          java.lang.String packagePath,
                                                          java.lang.String fileName)
                                                   throws java.io.IOException
        Load properties.
        Parameters:
        clazz - the clazz
        packagePath - the package path without the file name
        fileName - the file name
        Returns:
        the properties
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • loadProperties

        public static java.util.Properties loadProperties​(java.io.File propertiesFile)
                                                   throws java.io.IOException
        Load a Properties-object from the given File-object.
        Parameters:
        propertiesFile - the properties file
        Returns:
        the properties or null if the file is not found.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • loadProperties

        public static java.util.Properties loadProperties​(java.lang.String packagePath)
                                                   throws java.io.IOException
        Gives a Properties-object from the given packagepath.
        Parameters:
        packagePath - The package-path and the name from the resource as a String.
        Returns:
        The Properties-object from the given packagepath.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • loadProperties

        public static java.util.Properties loadProperties​(java.lang.String packagePath,
                                                          java.lang.String fileName)
                                                   throws java.io.IOException
        Load properties.
        Parameters:
        packagePath - the package path without the file name
        fileName - the file name
        Returns:
        the properties
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • loadProperties

        public static <T> java.util.Properties loadProperties​(T object,
                                                              java.lang.String propertiesFilename)
                                                       throws java.io.IOException
        Load Properties object from the given arguments.
        Type Parameters:
        T - the generic type of the object
        Parameters:
        object - the object for get the package path
        propertiesFilename - the properties filename
        Returns:
        the loaded Properties or null if the loading process failed.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • loadPropertiesFromClassObject

        public static java.util.Properties loadPropertiesFromClassObject​(java.lang.Class<?> clazz,
                                                                         java.util.Locale locale)
                                                                  throws java.io.IOException
        Load the properties file from the given class object. The filename from the properties file is the same as the simple name from the class object and it looks at the same path as the given class object. If locale is not null than the language will be added to the filename from the properties file.
        Parameters:
        clazz - the clazz
        locale - the locale
        Returns:
        the properties
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newBackupOf

        public static java.io.File newBackupOf​(java.io.File file)
                                        throws java.io.IOException
        Creates a backup file from the given properties file.
        Parameters:
        file - the file
        Returns:
        the backup file
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • removeComments

        public static java.util.List<java.lang.String> removeComments​(java.io.File propertiesFile)
                                                               throws java.io.IOException
        Removes the comments from the given properties file.
        Parameters:
        propertiesFile - the properties file
        Returns:
        the list
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • resolveAvailableLanguages

        public static java.util.Set<java.lang.String> resolveAvailableLanguages​(java.lang.String bundlepackage,
                                                                                java.lang.String bundlename)
        Resolves all the available languages for the given resource bundle name in the given bundle package. Note the default resource bundle is excluded.
        Parameters:
        bundlepackage - The package that contains the properties files.
        bundlename - The name of the resource bundle.
        Returns:
        a Set of String objects with the available languages excluding the default.