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 classJRPropertiesUtil.PropertySuffixClass used bygetProperties(String).
-
Field Summary
Fields Modifier and Type Field Description static StringEXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FAILUREstatic StringEXCEPTION_MESSAGE_KEY_LOAD_PROPERTIES_FILE_FAILUREstatic StringPROPERTY_PREFIXThe prefix used by all properties.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleanasBoolean(String value)Converts aStringvalue into aboolean.static booleanasBoolean(String value, boolean defaultValue)static CharacterasCharacter(String value)Converts aStringinto aCharactervalue.static doubleasDouble(String value)Converts aStringvalue into adouble.static floatasFloat(String value)Converts aStringvalue into afloat.static intasInteger(String value)Converts aStringvalue into aint.static longasLong(String value)Converts aStringvalue 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.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.BooleangetBooleanProperty(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.BooleangetBooleanProperty(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.CharactergetCharacterProperty(String key)Returns a property as aCharactervalue.CharactergetCharacterProperty(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.CharactergetCharacterProperty(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.DoublegetDoubleProperty(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.FloatgetFloatProperty(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.IntegergetIntegerProperty(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.IntegergetIntegerProperty(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.StringgetLocalizedProperty(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)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.StringgetProperty(String key)Returns the value of the property.StringgetProperty(String key, JRPropertiesHolder... propertiesHolders)Returns the value of a property, looking for it in several properties holders and then in the system properties.StringgetProperty(JRPropertiesHolder propertiesHolder, String key)Returns the value of a property, looking first in the supplied properties holder and then in the system properties.StringgetProperty(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.StringgetProperty(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 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,
nullotherwise - Throws:
JRException
-
getProperty
public String getProperty(String key)
Returns the value of the property.- Parameters:
key- the key- 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 aStringvalue 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 aStringvalue into aint.- Parameters:
value- the value- Returns:
- the value as a
int
-
asFloat
public static float asFloat(String value)
Converts aStringvalue into afloat.- Parameters:
value- the value- Returns:
- the value as a
float
-
asDouble
public static double asDouble(String value)
Converts aStringvalue 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
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(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
PropertySuffixobjects 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 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(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
PropertySuffixobjects 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 aStringvalue 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 aCharactervalue.- 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 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
public Character 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.- Parameters:
propertiesMap- the properties mapkey- the key- Returns:
- the property value as a
Character
-
asCharacter
public static Character asCharacter(String value)
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
public static String getOwnProperty(JRPropertiesHolder propertiesHolder, String key)
-
-