net.sf.jasperreports.engine
Class JRPropertiesUtil

java.lang.Object
  extended by net.sf.jasperreports.engine.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:

Version:
$Id: JRPropertiesUtil.java 5396 2012-05-21 01:06:15Z teodord $
Author:
Lucian Chirita (lucianc@users.sourceforge.net)

Nested Class Summary
static class JRPropertiesUtil.PropertySuffix
          Class used by getProperties(String).
 
Field Summary
static java.lang.String PROPERTY_PREFIX
          The prefix used by all properties.
 
Method Summary
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 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(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.
 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.
 boolean getBooleanProperty(java.lang.String key)
          Returns a property as a boolean value.
 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 holder and then in the system properties.
 java.lang.Character getCharacterProperty(java.lang.String key)
          Returns a property as a Character value.
 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.
 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.
static JRPropertiesUtil getInstance(JasperReportsContext jasperReportsContext)
           
 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.
 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.
 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.
 long getLongProperty(JRPropertiesHolder propertiesHolder, java.lang.String key, int 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, int defaultValue)
          Returns the value of a property as a long, looking first in the supplied properties map and then in the system properties.
 long getLongProperty(java.lang.String key)
          Returns a property as a long value.
protected static JRPropertiesMap getOwnProperties(JRPropertiesHolder propertiesHolder)
           
static java.lang.String getOwnProperty(JRPropertiesHolder propertiesHolder, java.lang.String key)
           
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.util.List<JRPropertiesUtil.PropertySuffix> getProperties(java.lang.String prefix)
          Returns the list of all properties for a key prefix.
 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(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.
 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.
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.
 
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
Method Detail

getInstance

public static JRPropertiesUtil getInstance(JasperReportsContext jasperReportsContext)

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

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

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

getProperties

public static java.util.List<JRPropertiesUtil.PropertySuffix> getProperties(JRPropertiesHolder propertiesHolder,
                                                                            java.lang.String prefix)
Returns the list of all properties for a key prefix. Only this holder's own properties are considered, and not global properties.

Parameters:
propertiesHolder - the properties holder
prefix - the key prefix
Returns:
a list of PropertySuffix objects containing the suffix of the key and the value
See Also:
getAllProperties(JRPropertiesHolder, String)

getAllProperties

public 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.

Parameters:
propertiesHolder - the properties holder
prefix - the key prefix
Returns:
a list of PropertySuffix objects containing the suffix of the key and the value
See Also:
getProperties(JRPropertiesHolder, String)

getProperties

public static java.util.List<JRPropertiesUtil.PropertySuffix> getProperties(JRPropertiesMap propertiesMap,
                                                                            java.lang.String prefix)
Returns the list of all properties for a key prefix. Only properties from propertiesMap are considered, and not global properties.

Parameters:
propertiesMap - the properties map
prefix - the key prefix
Returns:
a list of PropertySuffix objects containing the suffix of the key and the value
See Also:
getAllProperties(JRPropertiesMap, String)

getAllProperties

public 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.

Parameters:
propertiesMap - the properties map
prefix - the key prefix
Returns:
a list of PropertySuffix objects containing the suffix of the key and the value
See Also:
getProperties(JRPropertiesMap, String)

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(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(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

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 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(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(JRPropertiesMap propertiesMap,
                            java.lang.String key,
                            int 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,
                            int 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

getOwnProperties

protected static JRPropertiesMap getOwnProperties(JRPropertiesHolder propertiesHolder)

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

transferProperties

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

Parameters:
source - the source properties
destination - the destination properties holder
tranferPropertiesPrefix - the prefix of the JasperReports properties that specify the object properties to copy
See Also:
transferProperties(JRPropertiesHolder, JRPropertiesHolder, String)

transfer

protected void transfer(JRPropertiesMap source,
                        JRPropertiesHolder destination,
                        java.lang.String tranferPropertiesPrefix)

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(JRPropertiesMap propertiesMap,
                                                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:
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)


© 2001-2010 Jaspersoft Corporation www.jaspersoft.com