Package net.sf.jasperreports.engine
Class JRPropertiesUtil
java.lang.Object
net.sf.jasperreports.engine.JRPropertiesUtil
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)
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Converts aString
value into aboolean
.static boolean
static Character
asCharacter
(String value) Converts aString
into aCharacter
value.static double
Converts aString
value into adouble
.static float
Converts aString
value into afloat
.static int
Converts aString
value into aint
.static long
Converts aString
value into along
.getAllProperties
(JRPropertiesHolder propertiesHolder, String prefix) Returns the list of all properties for a key prefix, including global properties.getAllProperties
(JRPropertiesMap propertiesMap, String prefix) Returns the list of all properties for a key prefix, including global properties.boolean
getBooleanProperty
(String key) Returns a property as a boolean value.boolean
getBooleanProperty
(String key, boolean defaultValue) Returns a property as a boolean value.boolean
getBooleanProperty
(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.getBooleanProperty
(JRPropertiesHolder propertiesHolder, 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, 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.getBooleanProperty
(JRPropertiesMap propertiesMap, 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, 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.Returns a property as aCharacter
value.getCharacterProperty
(JRPropertiesHolder propertiesHolder, String key) Returns the value of a property as aCharacter
value, looking first in the supplied properties holder and then in the system properties.getCharacterProperty
(JRPropertiesMap propertiesMap, String key) Returns the value of a property as aCharacter
value, looking first in the supplied properties map and then in the system properties.getDoubleProperty
(JRPropertiesHolder propertiesHolder, 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
(String key) Returns a property as a float value.float
getFloatProperty
(String key, float defaultValue) Returns the value of a property as a float.float
getFloatProperty
(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.getFloatProperty
(JRPropertiesHolder propertiesHolder, 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, 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, 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
(String key) Returns a property as an integer value.int
getIntegerProperty
(String key, int defaultValue) Returns the value of a property as an integer.getIntegerProperty
(JRPropertiesHolder propertiesHolder, 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, 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.getIntegerProperty
(JRPropertiesMap propertiesMap, 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, 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.getLocalizedProperty
(String property, Locale locale) long
getLongProperty
(String key) Returns a property as a long value.long
getLongProperty
(String key, long defaultValue) Returns a property as a long value.long
getLongProperty
(JRPropertiesHolder propertiesHolder, 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, 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 String
getOwnProperty
(JRPropertiesHolder propertiesHolder, String key) getProperties
(String prefix) Returns the list of all properties for a key prefix.static List
<JRPropertiesUtil.PropertySuffix> getProperties
(JRPropertiesHolder propertiesHolder, String prefix) Returns the list of all properties for a key prefix.static List
<JRPropertiesUtil.PropertySuffix> getProperties
(JRPropertiesMap propertiesMap, String prefix) Returns the list of all properties for a key prefix.getProperty
(String key) Returns the value of the property.getProperty
(String key, String defaultValue) Returns the value of the property.getProperty
(String key, JRPropertiesHolder... propertiesHolders) Returns the value of a property, looking for it in several properties holders and then in the system properties.getProperty
(JRPropertiesHolder propertiesHolder, String key) Returns the value of a property, looking first in the supplied properties holder and then in the system properties.getProperty
(JRPropertiesHolder propertiesHolder, String key, 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.getProperty
(JRPropertiesMap propertiesMap, String key) Returns the value of a property, looking first in the supplied properties map and then in the system properties.static Properties
loadProperties
(String name, Properties defaults) Loads a properties file from the classpath.void
removeProperty
(String key) void
setProperty
(String key, String value) protected void
transfer
(JRPropertiesMap source, JRPropertiesHolder destination, String tranferPropertiesPrefix) void
transferProperties
(JRPropertiesHolder source, JRPropertiesHolder destination, String tranferPropertiesPrefix) Copies properties from one object to another.void
transferProperties
(JRPropertiesMap source, JRPropertiesHolder destination, String tranferPropertiesPrefix) Copies properties from one object to another.void
transferProperties
(JRPropertiesMap source, JRPropertiesHolder destination, List<String> propertyNames)
-
Field Details
-
PROPERTY_PREFIX
The prefix used by all properties.- See Also:
-
EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FILE_FAILURE
- See Also:
-
EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FAILURE
- See Also:
-
-
Method Details
-
getInstance
-
loadProperties
Loads a properties file from the classpath.- Parameters:
name
- the resource namedefaults
- the default properties- Returns:
- the loaded properties if the resource is found,
null
otherwise - Throws:
JRException
-
getProperty
Returns the value of the property.- Parameters:
key
- the key- Returns:
- the property value
-
getProperty
Returns the value of the property.- Parameters:
key
- the keydefaultValue
- the value to return when the property is not set- Returns:
- the property value
-
setProperty
-
removeProperty
-
getBooleanProperty
Returns a property as a boolean value.- Parameters:
key
- the key- Returns:
- the property value as a boolean
-
getBooleanProperty
Returns a property as a boolean value.- Parameters:
key
- the keydefaultValue
- the default value- Returns:
- the property value as a boolean
-
getIntegerProperty
Returns a property as an integer value.- Parameters:
key
- the key- Returns:
- the property value as an integer
-
getFloatProperty
Returns a property as a float value.- Parameters:
key
- the key- Returns:
- the property value as a float
-
asBoolean
Converts aString
value into aboolean
.- Parameters:
value
- the value- Returns:
- the value as a
boolean
-
asBoolean
-
asInteger
Converts aString
value into aint
.- Parameters:
value
- the value- Returns:
- the value as a
int
-
asFloat
Converts aString
value into afloat
.- Parameters:
value
- the value- Returns:
- the value as a
float
-
asDouble
Converts aString
value into adouble
.- Parameters:
value
- the value- Returns:
- the value as a
double
-
getProperties
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 List<JRPropertiesUtil.PropertySuffix> getProperties(JRPropertiesHolder propertiesHolder, 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 holderprefix
- the key prefix- Returns:
- a list of
PropertySuffix
objects containing the suffix of the key and the value - See Also:
-
getAllProperties
public List<JRPropertiesUtil.PropertySuffix> getAllProperties(JRPropertiesHolder propertiesHolder, String prefix) Returns the list of all properties for a key prefix, including global properties.- Parameters:
propertiesHolder
- the properties holderprefix
- the key prefix- Returns:
- a list of
PropertySuffix
objects containing the suffix of the key and the value - See Also:
-
getProperties
public static List<JRPropertiesUtil.PropertySuffix> getProperties(JRPropertiesMap propertiesMap, String prefix) Returns the list of all properties for a key prefix. Only properties frompropertiesMap
are considered, and not global properties.- Parameters:
propertiesMap
- the properties mapprefix
- the key prefix- Returns:
- a list of
PropertySuffix
objects containing the suffix of the key and the value - See Also:
-
getAllProperties
public List<JRPropertiesUtil.PropertySuffix> getAllProperties(JRPropertiesMap propertiesMap, String prefix) Returns the list of all properties for a key prefix, including global properties.- Parameters:
propertiesMap
- the properties mapprefix
- the key prefix- Returns:
- a list of
PropertySuffix
objects containing the suffix of the key and the value - See Also:
-
getProperty
Returns the value of a property, looking first in the supplied properties holder and then in the system properties.- Parameters:
propertiesHolder
- the properties holderkey
- the key- Returns:
- the property value
-
getProperty
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 holderkey
- the keydefaultValue
- the value to return if no property is found- Returns:
- the property value
-
getProperty
Returns the value of a property, looking for it in several properties holders and then in the system properties.- Parameters:
key
- the keypropertiesHolders
- the properties holders- Returns:
- the property value
-
getProperty
Returns the value of a property, looking first in the supplied properties map and then in the system properties.- Parameters:
propertiesMap
- the properties mapkey
- the key- Returns:
- the property value
-
getBooleanProperty
public boolean getBooleanProperty(JRPropertiesHolder propertiesHolder, 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 holderkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getBooleanProperty
public boolean getBooleanProperty(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 keydefaultValue
- the default value used if the property is not foundpropertiesHolders
- the properties holders- Returns:
- the property value
-
getBooleanProperty
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 mapkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getBooleanProperty
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 mapkey
- the key- Returns:
- the property value
-
getBooleanProperty
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 holderkey
- the key- Returns:
- the property value
-
getIntegerProperty
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 mapkey
- the key- Returns:
- the property value
-
getIntegerProperty
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 holderkey
- the key- Returns:
- the property value
-
getIntegerProperty
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 holderkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getIntegerProperty
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 mapkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getIntegerProperty
Returns the value of a property as an integer.- Parameters:
key
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getFloatProperty
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 holderkey
- the key- Returns:
- the property value
-
getFloatProperty
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 holderkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getFloatProperty
public float getFloatProperty(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 keydefaultValue
- the default value used if the property is not foundpropertiesHolders
- the properties holders- Returns:
- the property value
-
getFloatProperty
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 mapkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getFloatProperty
Returns the value of a property as a float.- Parameters:
key
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
asLong
Converts aString
value into along
.- Parameters:
value
- the value- Returns:
- the value as a
long
-
getLongProperty
Returns a property as a long value.- Parameters:
key
- the key- Returns:
- the property value as a long
-
getLongProperty
Returns a property as a long value.- Parameters:
key
- the keydefaultValue
- the default value- Returns:
- the property value as a long
-
getLongProperty
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 mapkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getLongProperty
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 holderkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getDoubleProperty
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 holderkey
- the key- Returns:
- the property value
-
getOwnProperties
-
transferProperties
public void transferProperties(JRPropertiesHolder source, JRPropertiesHolder destination, 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 holderdestination
- the destination properties holdertranferPropertiesPrefix
- the prefix of the JasperReports properties that specify the object properties to copy
-
transferProperties
public void transferProperties(JRPropertiesMap source, JRPropertiesHolder destination, String tranferPropertiesPrefix) Copies properties from one object to another.- Parameters:
source
- the source propertiesdestination
- the destination properties holdertranferPropertiesPrefix
- the prefix of the JasperReports properties that specify the object properties to copy- See Also:
-
transferProperties
public void transferProperties(JRPropertiesMap source, JRPropertiesHolder destination, List<String> propertyNames) -
transfer
protected void transfer(JRPropertiesMap source, JRPropertiesHolder destination, String tranferPropertiesPrefix) -
getCharacterProperty
Returns a property as aCharacter
value.- Parameters:
key
- the key- Returns:
- the property value as a
Character
- See Also:
-
getCharacterProperty
Returns the value of a property as aCharacter
value, looking first in the supplied properties holder and then in the system properties.- Parameters:
propertiesHolder
- the properties holderkey
- the key- Returns:
- the property value as a
Character
-
getCharacterProperty
Returns the value of a property as aCharacter
value, looking first in the supplied properties map and then in the system properties.- Parameters:
propertiesMap
- the properties mapkey
- the key- Returns:
- the property value as a
Character
-
asCharacter
Converts aString
into aCharacter
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
- theString
value- Returns:
- the value converted to
Character
-
getOwnProperty
-
getLocalizedProperty
-