Class JRPropertiesUtil


  • public final class JRPropertiesUtil
    extends java.lang.Object
    Class that provides static methods for loading, getting and setting properties.

    The following actions are performed:

    • The default (hardcoded) properties are set.
    • If the system property "net.sf.jasperreports.properties" has been set then the specified proprties file is loaded.
    • Otherwise "jasperreports.properties" is loaded if found in the classpath.
    • For backward compatibility, system properties like "jasper.reports.compile.xml.validation" are checked and their values are used. This way of specifying properties is deprecated.

    Author:
    Lucian Chirita (lucianc@users.sourceforge.net)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean asBoolean​(java.lang.String value)
      Converts a String value into a boolean.
      static boolean asBoolean​(java.lang.String value, boolean defaultValue)  
      static java.lang.Character asCharacter​(java.lang.String value)
      Converts a String into a Character value.
      static double asDouble​(java.lang.String value)
      Converts a String value into a double.
      static float asFloat​(java.lang.String value)
      Converts a String value into a float.
      static int asInteger​(java.lang.String value)
      Converts a String value into a int.
      static long asLong​(java.lang.String value)
      Converts a String value into a long.
      java.util.List<JRPropertiesUtil.PropertySuffix> getAllProperties​(JRPropertiesHolder propertiesHolder, java.lang.String prefix)
      Returns the list of all properties for a key prefix, including global properties.
      java.util.List<JRPropertiesUtil.PropertySuffix> getAllProperties​(JRPropertiesMap propertiesMap, java.lang.String prefix)
      Returns the list of all properties for a key prefix, including global properties.
      boolean getBooleanProperty​(java.lang.String key)
      Returns a property as a boolean value.
      boolean getBooleanProperty​(java.lang.String key, boolean defaultValue)
      Returns a property as a boolean value.
      boolean getBooleanProperty​(java.lang.String key, boolean defaultValue, JRPropertiesHolder... propertiesHolders)
      Returns the value of a property as a boolean, looking first in several properties holders and then in the system properties.
      java.lang.Boolean getBooleanProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key)
      Returns the value of a property as a Boolean, looking first in the supplied properties holder and then in the system properties.
      boolean getBooleanProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key, boolean defaultValue)
      Returns the value of a property as a boolean, looking first in the supplied properties holder and then in the system properties.
      java.lang.Boolean getBooleanProperty​(JRPropertiesMap propertiesMap, java.lang.String key)
      Returns the value of a property as a boolean, looking first in the supplied properties map and then in the system properties.
      boolean getBooleanProperty​(JRPropertiesMap propertiesMap, java.lang.String key, boolean defaultValue)
      Returns the value of a property as a boolean, looking first in the supplied properties map and then in the system properties.
      java.lang.Character getCharacterProperty​(java.lang.String key)
      Returns a property as a Character value.
      java.lang.Character getCharacterProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key)
      Returns the value of a property as a Character value, looking first in the supplied properties holder and then in the system properties.
      java.lang.Character getCharacterProperty​(JRPropertiesMap propertiesMap, java.lang.String key)
      Returns the value of a property as a Character value, looking first in the supplied properties map and then in the system properties.
      java.lang.Double getDoubleProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key)
      Returns the value of a property as a Double, looking first in the supplied properties holder and then in the system properties.
      float getFloatProperty​(java.lang.String key)
      Returns a property as a float value.
      float getFloatProperty​(java.lang.String key, float defaultValue)
      Returns the value of a property as a float.
      float getFloatProperty​(java.lang.String key, float defaultValue, JRPropertiesHolder... propertiesHolders)
      Returns the value of a property as a float, looking first in several properties holders and then in the system properties.
      java.lang.Float getFloatProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key)
      Returns the value of a property as a Float, looking first in the supplied properties holder and then in the system properties.
      float getFloatProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key, float defaultValue)
      Returns the value of a property as a float, looking first in the supplied properties holder and then in the system properties.
      float getFloatProperty​(JRPropertiesMap propertiesMap, java.lang.String key, float defaultValue)
      Returns the value of a property as a float, looking first in the supplied properties map and then in the system properties.
      static JRPropertiesUtil getInstance​(JasperReportsContext jasperReportsContext)  
      int getIntegerProperty​(java.lang.String key)
      Returns a property as an integer value.
      int getIntegerProperty​(java.lang.String key, int defaultValue)
      Returns the value of a property as an integer.
      java.lang.Integer getIntegerProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key)
      Returns the value of a property as an Integer, looking first in the supplied properties holder and then in the system properties.
      int getIntegerProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key, int defaultValue)
      Returns the value of a property as an integer, looking first in the supplied properties holder and then in the system properties.
      java.lang.Integer getIntegerProperty​(JRPropertiesMap propertiesMap, java.lang.String key)
      Returns the value of a property as an Integer, looking first in the supplied properties map and then in the system properties.
      int getIntegerProperty​(JRPropertiesMap propertiesMap, java.lang.String key, int defaultValue)
      Returns the value of a property as an integer, looking first in the supplied properties map and then in the system properties.
      java.lang.String getLocalizedProperty​(java.lang.String property, java.util.Locale locale)  
      long getLongProperty​(java.lang.String key)
      Returns a property as a long value.
      long getLongProperty​(java.lang.String key, long defaultValue)
      Returns a property as a long value.
      long getLongProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key, long defaultValue)
      Returns the value of a property as a long, looking first in the supplied properties holder and then in the system properties.
      long getLongProperty​(JRPropertiesMap propertiesMap, java.lang.String key, long defaultValue)
      Returns the value of a property as a long, looking first in the supplied properties map and then in the system properties.
      protected static JRPropertiesMap getOwnProperties​(JRPropertiesHolder propertiesHolder)  
      static java.lang.String getOwnProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key)  
      java.util.List<JRPropertiesUtil.PropertySuffix> getProperties​(java.lang.String prefix)
      Returns the list of all properties for a key prefix.
      static java.util.List<JRPropertiesUtil.PropertySuffix> getProperties​(JRPropertiesHolder propertiesHolder, java.lang.String prefix)
      Returns the list of all properties for a key prefix.
      static java.util.List<JRPropertiesUtil.PropertySuffix> getProperties​(JRPropertiesMap propertiesMap, java.lang.String prefix)
      Returns the list of all properties for a key prefix.
      java.lang.String getProperty​(java.lang.String key)
      Returns the value of the property.
      java.lang.String getProperty​(java.lang.String key, JRPropertiesHolder... propertiesHolders)
      Returns the value of a property, looking for it in several properties holders and then in the system properties.
      java.lang.String getProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key)
      Returns the value of a property, looking first in the supplied properties holder and then in the system properties.
      java.lang.String getProperty​(JRPropertiesHolder propertiesHolder, java.lang.String key, java.lang.String defaultValue)
      Returns the value of a property, looking first in the supplied properties holder and then in the system properties, using a default value if the property is not found.
      java.lang.String getProperty​(JRPropertiesMap propertiesMap, java.lang.String key)
      Returns the value of a property, looking first in the supplied properties map and then in the system properties.
      static java.util.Properties loadProperties​(java.lang.String name, java.util.Properties defaults)
      Loads a properties file from the classpath.
      void removeProperty​(java.lang.String key)  
      void setProperty​(java.lang.String key, java.lang.String value)  
      protected void transfer​(JRPropertiesMap source, JRPropertiesHolder destination, java.lang.String tranferPropertiesPrefix)  
      void transferProperties​(JRPropertiesHolder source, JRPropertiesHolder destination, java.lang.String tranferPropertiesPrefix)
      Copies properties from one object to another.
      void transferProperties​(JRPropertiesMap source, JRPropertiesHolder destination, java.lang.String tranferPropertiesPrefix)
      Copies properties from one object to another.
      void transferProperties​(JRPropertiesMap source, JRPropertiesHolder destination, java.util.List<java.lang.String> propertyNames)  
      • Methods inherited from class java.lang.Object

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

      • PROPERTY_PREFIX

        public static final java.lang.String PROPERTY_PREFIX
        The prefix used by all properties.
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FILE_FAILURE

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FILE_FAILURE
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FAILURE

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FAILURE
        See Also:
        Constant Field Values
    • Method Detail

      • loadProperties

        public static java.util.Properties loadProperties​(java.lang.String name,
                                                          java.util.Properties defaults)
                                                   throws JRException
        Loads a properties file from the classpath.
        Parameters:
        name - the resource name
        defaults - the default properties
        Returns:
        the loaded properties if the resource is found, null otherwise
        Throws:
        JRException
      • getProperty

        public java.lang.String getProperty​(java.lang.String key)
        Returns the value of the property.
        Parameters:
        key - the key
        Returns:
        the property value
      • setProperty

        public void setProperty​(java.lang.String key,
                                java.lang.String value)
      • removeProperty

        public void removeProperty​(java.lang.String key)
      • getBooleanProperty

        public boolean getBooleanProperty​(java.lang.String key)
        Returns a property as a boolean value.
        Parameters:
        key - the key
        Returns:
        the property value as a boolean
      • getBooleanProperty

        public boolean getBooleanProperty​(java.lang.String key,
                                          boolean defaultValue)
        Returns a property as a boolean value.
        Parameters:
        key - the key
        defaultValue - the default value
        Returns:
        the property value as a boolean
      • getIntegerProperty

        public int getIntegerProperty​(java.lang.String key)
        Returns a property as an integer value.
        Parameters:
        key - the key
        Returns:
        the property value as an integer
      • getFloatProperty

        public float getFloatProperty​(java.lang.String key)
        Returns a property as a float value.
        Parameters:
        key - the key
        Returns:
        the property value as a float
      • asBoolean

        public static boolean asBoolean​(java.lang.String value)
        Converts a String value into a boolean.
        Parameters:
        value - the value
        Returns:
        the value as a boolean
      • asBoolean

        public static boolean asBoolean​(java.lang.String value,
                                        boolean defaultValue)
      • asInteger

        public static int asInteger​(java.lang.String value)
        Converts a String value into a int.
        Parameters:
        value - the value
        Returns:
        the value as a int
      • asFloat

        public static float asFloat​(java.lang.String value)
        Converts a String value into a float.
        Parameters:
        value - the value
        Returns:
        the value as a float
      • asDouble

        public static double asDouble​(java.lang.String value)
        Converts a String value into a double.
        Parameters:
        value - the value
        Returns:
        the value as a double
      • getProperties

        public java.util.List<JRPropertiesUtil.PropertySuffix> getProperties​(java.lang.String prefix)
        Returns the list of all properties for a key prefix.
        Parameters:
        prefix - the key prefix
        Returns:
        a list of PropertySuffix objects containing the suffix of the key and the value
      • getProperty

        public java.lang.String getProperty​(JRPropertiesHolder propertiesHolder,
                                            java.lang.String key)
        Returns the value of a property, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        Returns:
        the property value
      • getProperty

        public java.lang.String getProperty​(JRPropertiesHolder propertiesHolder,
                                            java.lang.String key,
                                            java.lang.String defaultValue)
        Returns the value of a property, looking first in the supplied properties holder and then in the system properties, using a default value if the property is not found.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        defaultValue - the value to return if no property is found
        Returns:
        the property value
      • getProperty

        public java.lang.String getProperty​(java.lang.String key,
                                            JRPropertiesHolder... propertiesHolders)
        Returns the value of a property, looking for it in several properties holders and then in the system properties.
        Parameters:
        key - the key
        propertiesHolders - the properties holders
        Returns:
        the property value
      • getProperty

        public java.lang.String getProperty​(JRPropertiesMap propertiesMap,
                                            java.lang.String key)
        Returns the value of a property, looking first in the supplied properties map and then in the system properties.
        Parameters:
        propertiesMap - the properties map
        key - the key
        Returns:
        the property value
      • getBooleanProperty

        public boolean getBooleanProperty​(JRPropertiesHolder propertiesHolder,
                                          java.lang.String key,
                                          boolean defaultValue)
        Returns the value of a property as a boolean, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • getBooleanProperty

        public boolean getBooleanProperty​(java.lang.String key,
                                          boolean defaultValue,
                                          JRPropertiesHolder... propertiesHolders)
        Returns the value of a property as a boolean, looking first in several properties holders and then in the system properties.
        Parameters:
        key - the key
        defaultValue - the default value used if the property is not found
        propertiesHolders - the properties holders
        Returns:
        the property value
      • getBooleanProperty

        public boolean getBooleanProperty​(JRPropertiesMap propertiesMap,
                                          java.lang.String key,
                                          boolean defaultValue)
        Returns the value of a property as a boolean, looking first in the supplied properties map and then in the system properties.
        Parameters:
        propertiesMap - the properties map
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • getBooleanProperty

        public java.lang.Boolean getBooleanProperty​(JRPropertiesMap propertiesMap,
                                                    java.lang.String key)
        Returns the value of a property as a boolean, looking first in the supplied properties map and then in the system properties.
        Parameters:
        propertiesMap - the properties map
        key - the key
        Returns:
        the property value
      • getBooleanProperty

        public java.lang.Boolean getBooleanProperty​(JRPropertiesHolder propertiesHolder,
                                                    java.lang.String key)
        Returns the value of a property as a Boolean, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        Returns:
        the property value
      • getIntegerProperty

        public java.lang.Integer getIntegerProperty​(JRPropertiesMap propertiesMap,
                                                    java.lang.String key)
        Returns the value of a property as an Integer, looking first in the supplied properties map and then in the system properties.
        Parameters:
        propertiesMap - the properties map
        key - the key
        Returns:
        the property value
      • getIntegerProperty

        public java.lang.Integer getIntegerProperty​(JRPropertiesHolder propertiesHolder,
                                                    java.lang.String key)
        Returns the value of a property as an Integer, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        Returns:
        the property value
      • getIntegerProperty

        public int getIntegerProperty​(JRPropertiesHolder propertiesHolder,
                                      java.lang.String key,
                                      int defaultValue)
        Returns the value of a property as an integer, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • getIntegerProperty

        public int getIntegerProperty​(JRPropertiesMap propertiesMap,
                                      java.lang.String key,
                                      int defaultValue)
        Returns the value of a property as an integer, looking first in the supplied properties map and then in the system properties.
        Parameters:
        propertiesMap - the properties map
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • getIntegerProperty

        public int getIntegerProperty​(java.lang.String key,
                                      int defaultValue)
        Returns the value of a property as an integer.
        Parameters:
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • getFloatProperty

        public java.lang.Float getFloatProperty​(JRPropertiesHolder propertiesHolder,
                                                java.lang.String key)
        Returns the value of a property as a Float, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        Returns:
        the property value
      • getFloatProperty

        public float getFloatProperty​(JRPropertiesHolder propertiesHolder,
                                      java.lang.String key,
                                      float defaultValue)
        Returns the value of a property as a float, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • getFloatProperty

        public float getFloatProperty​(java.lang.String key,
                                      float defaultValue,
                                      JRPropertiesHolder... propertiesHolders)
        Returns the value of a property as a float, looking first in several properties holders and then in the system properties.
        Parameters:
        key - the key
        defaultValue - the default value used if the property is not found
        propertiesHolders - the properties holders
        Returns:
        the property value
      • getFloatProperty

        public float getFloatProperty​(JRPropertiesMap propertiesMap,
                                      java.lang.String key,
                                      float defaultValue)
        Returns the value of a property as a float, looking first in the supplied properties map and then in the system properties.
        Parameters:
        propertiesMap - the properties map
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • getFloatProperty

        public float getFloatProperty​(java.lang.String key,
                                      float defaultValue)
        Returns the value of a property as a float.
        Parameters:
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • asLong

        public static long asLong​(java.lang.String value)
        Converts a String value into a long.
        Parameters:
        value - the value
        Returns:
        the value as a long
      • getLongProperty

        public long getLongProperty​(java.lang.String key)
        Returns a property as a long value.
        Parameters:
        key - the key
        Returns:
        the property value as a long
      • getLongProperty

        public long getLongProperty​(java.lang.String key,
                                    long defaultValue)
        Returns a property as a long value.
        Parameters:
        key - the key
        defaultValue - the default value
        Returns:
        the property value as a long
      • getLongProperty

        public long getLongProperty​(JRPropertiesMap propertiesMap,
                                    java.lang.String key,
                                    long defaultValue)
        Returns the value of a property as a long, looking first in the supplied properties map and then in the system properties.
        Parameters:
        propertiesMap - the properties map
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • getLongProperty

        public long getLongProperty​(JRPropertiesHolder propertiesHolder,
                                    java.lang.String key,
                                    long defaultValue)
        Returns the value of a property as a long, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        defaultValue - the default value used if the property is not found
        Returns:
        the property value
      • getDoubleProperty

        public java.lang.Double getDoubleProperty​(JRPropertiesHolder propertiesHolder,
                                                  java.lang.String key)
        Returns the value of a property as a Double, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        Returns:
        the property value
      • transferProperties

        public void transferProperties​(JRPropertiesHolder source,
                                       JRPropertiesHolder destination,
                                       java.lang.String tranferPropertiesPrefix)
        Copies properties from one object to another.

        The properties to be copied are determined by one or more JasperReports properties having a specified prefix. The values of these properties are interpreted as prefixes of properties to copy.

        Parameters:
        source - the source properties holder
        destination - the destination properties holder
        tranferPropertiesPrefix - the prefix of the JasperReports properties that specify the object properties to copy
      • getCharacterProperty

        public java.lang.Character getCharacterProperty​(java.lang.String key)
        Returns a property as a Character value.
        Parameters:
        key - the key
        Returns:
        the property value as a Character
        See Also:
        asCharacter(String)
      • getCharacterProperty

        public java.lang.Character getCharacterProperty​(JRPropertiesHolder propertiesHolder,
                                                        java.lang.String key)
        Returns the value of a property as a Character value, looking first in the supplied properties holder and then in the system properties.
        Parameters:
        propertiesHolder - the properties holder
        key - the key
        Returns:
        the property value as a Character
      • getCharacterProperty

        public java.lang.Character getCharacterProperty​(JRPropertiesMap propertiesMap,
                                                        java.lang.String key)
        Returns the value of a property as a Character value, looking first in the supplied properties map and then in the system properties.
        Parameters:
        propertiesMap - the properties map
        key - the key
        Returns:
        the property value as a Character
      • asCharacter

        public static java.lang.Character asCharacter​(java.lang.String value)
        Converts a String into a Character value.

        If the String value is null or the empty string, null is returned. Otherwise, the method returns the first character in the string.

        Parameters:
        value - the String value
        Returns:
        the value converted to Character
      • getOwnProperty

        public static java.lang.String getOwnProperty​(JRPropertiesHolder propertiesHolder,
                                                      java.lang.String key)
      • getLocalizedProperty

        public java.lang.String getLocalizedProperty​(java.lang.String property,
                                                     java.util.Locale locale)