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 booleanConverts aStringvalue into aboolean.static booleanstatic CharacterasCharacter(String value) Converts aStringinto aCharactervalue.static doubleConverts aStringvalue into adouble.static floatConverts aStringvalue into afloat.static intConverts aStringvalue into aint.static longConverts aStringvalue 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.booleangetBooleanProperty(String key) Returns a property as a boolean value.booleangetBooleanProperty(String key, boolean defaultValue) Returns a property as a boolean value.booleangetBooleanProperty(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.booleangetBooleanProperty(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.booleangetBooleanProperty(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 aCharactervalue.getCharacterProperty(JRPropertiesHolder propertiesHolder, String key) Returns the value of a property as aCharactervalue, 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 aCharactervalue, 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.floatgetFloatProperty(String key) Returns a property as a float value.floatgetFloatProperty(String key, float defaultValue) Returns the value of a property as a float.floatgetFloatProperty(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.floatgetFloatProperty(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.floatgetFloatProperty(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 JRPropertiesUtilgetInstance(JasperReportsContext jasperReportsContext) intgetIntegerProperty(String key) Returns a property as an integer value.intgetIntegerProperty(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.intgetIntegerProperty(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.intgetIntegerProperty(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) longgetLongProperty(String key) Returns a property as a long value.longgetLongProperty(String key, long defaultValue) Returns a property as a long value.longgetLongProperty(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.longgetLongProperty(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 JRPropertiesMapgetOwnProperties(JRPropertiesHolder propertiesHolder) static StringgetOwnProperty(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 PropertiesloadProperties(String name, Properties defaults) Loads a properties file from the classpath.voidremoveProperty(String key) voidsetProperty(String key, String value) protected voidtransfer(JRPropertiesMap source, JRPropertiesHolder destination, String tranferPropertiesPrefix) voidtransferProperties(JRPropertiesHolder source, JRPropertiesHolder destination, String tranferPropertiesPrefix) Copies properties from one object to another.voidtransferProperties(JRPropertiesMap source, JRPropertiesHolder destination, String tranferPropertiesPrefix) Copies properties from one object to another.voidtransferProperties(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,
nullotherwise - 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 aStringvalue into aboolean.- Parameters:
value- the value- Returns:
- the value as a
boolean
-
asBoolean
-
asInteger
Converts aStringvalue into aint.- Parameters:
value- the value- Returns:
- the value as a
int
-
asFloat
Converts aStringvalue into afloat.- Parameters:
value- the value- Returns:
- the value as a
float
-
asDouble
Converts aStringvalue 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
PropertySuffixobjects 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
PropertySuffixobjects 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
PropertySuffixobjects 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 frompropertiesMapare considered, and not global properties.- Parameters:
propertiesMap- the properties mapprefix- the key prefix- Returns:
- a list of
PropertySuffixobjects 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
PropertySuffixobjects 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 aStringvalue 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 aCharactervalue.- Parameters:
key- the key- Returns:
- the property value as a
Character - See Also:
-
getCharacterProperty
Returns the value of a property as aCharactervalue, 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 aCharactervalue, 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 aStringinto aCharactervalue.If the
Stringvalue is null or the empty string,nullis returned. Otherwise, the method returns the first character in the string.- Parameters:
value- theStringvalue- Returns:
- the value converted to
Character
-
getOwnProperty
-
getLocalizedProperty
-