Package net.sf.jasperreports.engine
Class JRPropertiesUtil
- java.lang.Object
-
- net.sf.jasperreports.engine.JRPropertiesUtil
-
public final class JRPropertiesUtil extends 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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JRPropertiesUtil.PropertySuffix
Class used bygetProperties(String)
.
-
Field Summary
Fields Modifier and Type Field Description static String
EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FAILURE
static String
EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FILE_FAILURE
static String
PROPERTY_PREFIX
The prefix used by all properties.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
asBoolean(String value)
Converts aString
value into aboolean
.static boolean
asBoolean(String value, boolean defaultValue)
static Character
asCharacter(String value)
Converts aString
into aCharacter
value.static double
asDouble(String value)
Converts aString
value into adouble
.static float
asFloat(String value)
Converts aString
value into afloat
.static int
asInteger(String value)
Converts aString
value into aint
.static long
asLong(String value)
Converts aString
value into along
.List<JRPropertiesUtil.PropertySuffix>
getAllProperties(JRPropertiesHolder propertiesHolder, String prefix)
Returns the list of all properties for a key prefix, including global properties.List<JRPropertiesUtil.PropertySuffix>
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.Boolean
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.Boolean
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.Character
getCharacterProperty(String key)
Returns a property as aCharacter
value.Character
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.Character
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.Double
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.Float
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.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.Integer
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.String
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)
List<JRPropertiesUtil.PropertySuffix>
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.String
getProperty(String key)
Returns the value of the property.String
getProperty(String key, String defaultValue)
Returns the value of the property.String
getProperty(String key, JRPropertiesHolder... propertiesHolders)
Returns the value of a property, looking for it in several properties holders and then in the system properties.String
getProperty(JRPropertiesHolder propertiesHolder, String key)
Returns the value of a property, looking first in the supplied properties holder and then in the system properties.String
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.String
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 Detail
-
PROPERTY_PREFIX
public static final String PROPERTY_PREFIX
The prefix used by all properties.- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FILE_FAILURE
public static final String EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FILE_FAILURE
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FAILURE
public static final String EXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FAILURE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static JRPropertiesUtil getInstance(JasperReportsContext jasperReportsContext)
-
loadProperties
public static Properties loadProperties(String name, Properties defaults) throws JRException
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
public String getProperty(String key)
Returns the value of the property.- Parameters:
key
- the key- Returns:
- the property value
-
getProperty
public String getProperty(String key, String defaultValue)
Returns the value of the property.- Parameters:
key
- the keydefaultValue
- the value to return when the property is not set- Returns:
- the property value
-
removeProperty
public void removeProperty(String key)
-
getBooleanProperty
public boolean getBooleanProperty(String key)
Returns a property as a boolean value.- Parameters:
key
- the key- Returns:
- the property value as a boolean
-
getBooleanProperty
public boolean getBooleanProperty(String key, boolean defaultValue)
Returns a property as a boolean value.- Parameters:
key
- the keydefaultValue
- the default value- Returns:
- the property value as a boolean
-
getIntegerProperty
public int getIntegerProperty(String key)
Returns a property as an integer value.- Parameters:
key
- the key- Returns:
- the property value as an integer
-
getFloatProperty
public float getFloatProperty(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(String value)
Converts aString
value into aboolean
.- Parameters:
value
- the value- Returns:
- the value as a
boolean
-
asBoolean
public static boolean asBoolean(String value, boolean defaultValue)
-
asInteger
public static int asInteger(String value)
Converts aString
value into aint
.- Parameters:
value
- the value- Returns:
- the value as a
int
-
asFloat
public static float asFloat(String value)
Converts aString
value into afloat
.- Parameters:
value
- the value- Returns:
- the value as a
float
-
asDouble
public static double asDouble(String value)
Converts aString
value into adouble
.- Parameters:
value
- the value- Returns:
- the value as a
double
-
getProperties
public List<JRPropertiesUtil.PropertySuffix> getProperties(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 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(JRPropertiesHolder, String)
-
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(JRPropertiesHolder, String)
-
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(JRPropertiesMap, String)
-
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:
getProperties(JRPropertiesMap, String)
-
getProperty
public String getProperty(JRPropertiesHolder propertiesHolder, 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 holderkey
- the key- Returns:
- the property value
-
getProperty
public String 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.- Parameters:
propertiesHolder
- the properties holderkey
- the keydefaultValue
- the value to return if no property is found- Returns:
- the property value
-
getProperty
public String getProperty(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 keypropertiesHolders
- the properties holders- Returns:
- the property value
-
getProperty
public String getProperty(JRPropertiesMap propertiesMap, 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 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
public 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.- Parameters:
propertiesMap
- the properties mapkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getBooleanProperty
public Boolean 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.- Parameters:
propertiesMap
- the properties mapkey
- the key- Returns:
- the property value
-
getBooleanProperty
public Boolean 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.- Parameters:
propertiesHolder
- the properties holderkey
- the key- Returns:
- the property value
-
getIntegerProperty
public Integer 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.- Parameters:
propertiesMap
- the properties mapkey
- the key- Returns:
- the property value
-
getIntegerProperty
public 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.- Parameters:
propertiesHolder
- the properties holderkey
- the key- Returns:
- the property value
-
getIntegerProperty
public 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.- Parameters:
propertiesHolder
- the properties holderkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getIntegerProperty
public 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.- Parameters:
propertiesMap
- the properties mapkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getIntegerProperty
public int getIntegerProperty(String key, int defaultValue)
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
public Float 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.- Parameters:
propertiesHolder
- the properties holderkey
- the key- Returns:
- the property value
-
getFloatProperty
public 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.- 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
public 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.- Parameters:
propertiesMap
- the properties mapkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getFloatProperty
public float getFloatProperty(String key, float defaultValue)
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
public static long asLong(String value)
Converts aString
value into along
.- Parameters:
value
- the value- Returns:
- the value as a
long
-
getLongProperty
public long getLongProperty(String key)
Returns a property as a long value.- Parameters:
key
- the key- Returns:
- the property value as a long
-
getLongProperty
public long getLongProperty(String key, long defaultValue)
Returns a property as a long value.- Parameters:
key
- the keydefaultValue
- the default value- Returns:
- the property value as a long
-
getLongProperty
public 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.- Parameters:
propertiesMap
- the properties mapkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getLongProperty
public 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.- Parameters:
propertiesHolder
- the properties holderkey
- the keydefaultValue
- the default value used if the property is not found- Returns:
- the property value
-
getDoubleProperty
public Double 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.- Parameters:
propertiesHolder
- the properties holderkey
- the key- Returns:
- the property value
-
getOwnProperties
protected static JRPropertiesMap getOwnProperties(JRPropertiesHolder propertiesHolder)
-
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(JRPropertiesHolder, JRPropertiesHolder, String)
-
transferProperties
public void transferProperties(JRPropertiesMap source, JRPropertiesHolder destination, List<String> propertyNames)
-
transfer
protected void transfer(JRPropertiesMap source, JRPropertiesHolder destination, String tranferPropertiesPrefix)
-
getCharacterProperty
public Character getCharacterProperty(String key)
Returns a property as aCharacter
value.- Parameters:
key
- the key- Returns:
- the property value as a
Character
- See Also:
asCharacter(String)
-
getCharacterProperty
public Character 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.- Parameters:
propertiesHolder
- the properties holderkey
- the key- Returns:
- the property value as a
Character
-
getCharacterProperty
public Character 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.- Parameters:
propertiesMap
- the properties mapkey
- the key- Returns:
- the property value as a
Character
-
asCharacter
public static Character asCharacter(String value)
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
public static String getOwnProperty(JRPropertiesHolder propertiesHolder, String key)
-
-