Package jodd.props
Class Props
java.lang.Object
jodd.props.Props
- All Implemented Interfaces:
Cloneable
Super properties: fast, configurable, supports (ini) sections, profiles.
Basic parsing rules:
- By default, props files are UTF8 encoded.
- Leading and trailing spaces will be trimmed from section names and property names.
- Leading and/or trailing spaces may be trimmed from property values.
- You can use either equal sign (=) or colon (:) to assign property values
- Comments begin with either a semicolon (;), or a sharp sign (#) and extend to the end of line. It doesn't have to be the first character.
- A backslash (\) escapes the next character (e.g., \# is a literal #, \\ is a literal \).
- If the last character of a line is backslash (\), the value is continued on the next line with new line character included.
- \\uXXXX is encoded as character
- \t, \r and \f are encoded as characters
Sections rules:
- Section names are enclosed between [ and ].
- Properties following a section header belong to that section. Section name is added as a prefix to section properties.
- Section ends with empty section definition [] or with new section start
Profiles rules:
- Profile names are enclosed between < and > in property key.
- Each property key may contain zero, one or more profile definitions.
Macro rules:
- Profile values may contain references to other properties using ${ and }
- Inner references are supported
- References are resolved first in the profile context and then in the base props context.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String[]protected Stringprotected final PropsDataprivate static final Stringprotected booleanprotected final PropsParser -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInnerMap(String prefix, Map<?, ?> map) Adds child map to the props on given prefix.voidaddInnerMap(String prefix, Map<?, ?> map, String profile) Adds child map to the props on given prefix.protected Propsclone()Clones props by creating new instance and copying current configuration.intCounts the total number of properties, including all profiles.static Propscreate()Statis ctor.entries()voidextractProps(Map target) Extracts props belonging to active profiles.voidextractProps(Map target, String... profiles) Extract props of given profiles.voidextractSubProps(Map target, String... wildcardPatterns) Extracts subset of properties that matches given wildcards.voidextractSubProps(Map target, String[] profiles, String[] wildcardPatterns) Extracts subset of properties that matches given wildcards.String[]Returns active profiles ornullif none defined.String[]Returns all profiles names.getBaseValue(String key) Returnsstringvalue of base property.getBooleanValue(String key) Returns boolean value of given property ornullif property not found.getBooleanValue(String key, Boolean defaultValue) Returns boolean value or default one if property not defined.getBooleanValue(String key, Boolean defaultValue, String... profiles) getBooleanValue(String key, String... profiles) getDoubleValue(String key) Returns double value of given property ornullif property not found.getDoubleValue(String key, Double defaultValue) Returns double value or default one if property not defined.getDoubleValue(String key, Double defaultValue, String... profiles) getDoubleValue(String key, String... profiles) getIntegerValue(String key) Returns integer value of given property ornullif property not found.getIntegerValue(String key, Integer defaultValue) Returns integer value or default one if property not defined.getIntegerValue(String key, Integer defaultValue, String... profiles) getIntegerValue(String key, String... profiles) getLongValue(String key) Returns long value of given property ornullif property not found.getLongValue(String key, Long defaultValue) Returns long value or default one if property not defined.getLongValue(String key, Long defaultValue, String... profiles) getLongValue(String key, String... profiles) String[]getProfilesFor(String propKeyNameWildcard) Returns all the profiles that define certain prop's key name.Returns value of property, using active profiles, ornullif property not found.Returnsstringvalue of given profiles.getValueOrDefault(String key, String defaultValue) Returns value of property, using active profiles or default value if not found.protected voidInitializes props.Returns inner map from the props with given prefix.iterator()Returns iterator for active profiles.Loads props from the file.Loads properties from the file in provided encoding.load(InputStream in) Loads properties from input stream.load(InputStream in, String encoding) Loads properties from input stream and provided encoding.Loads props from the string.Loads base properties from the provided java properties.Loads base properties from java Map using provided prefix.loadEnvironment(String prefix) Loads environment properties with given prefix.loadSystemProperties(String prefix) Loads system properties with given prefix.protected voidParses input string and loads provided properties map.protected voidResolves active profiles from special property.setActiveProfiles(String... activeProfiles) Sets new active profiles and overrides existing ones.setAppendDuplicateProps(boolean appendDuplicateProps) Appends duplicate props.setEscapeNewLineValue(String escapeNewLineValue) Specifies the new line string when EOL is escaped.setIgnoreMissingMacros(boolean ignoreMissingMacros) Ignore missing macros by replacing them with an empty string.setIgnorePrefixWhitespacesOnNewLine(boolean ignorePrefixWhitespacesOnNewLine) Defines if the prefix whitespaces should be ignored when value is split into the lines.setMultilineValues(boolean multilineValues) Enables multiline values.setSkipEmptyProps(boolean skipEmptyProps) Skips empty properties as they don't exist.voidSets default value.voidSets value on some profile.setValueTrimLeft(boolean valueTrimLeft) Specifies should the values be trimmed from the left.setValueTrimRight(boolean valueTrimRight) Specifies should the values be trimmed from the right.
-
Field Details
-
DEFAULT_PROFILES_PROP
- See Also:
-
parser
-
data
-
activeProfilesProp
-
activeProfiles
-
initialized
protected volatile boolean initialized
-
-
Constructor Details
-
Props
public Props()Creates new props. -
Props
-
-
Method Details
-
create
Statis ctor. -
clone
Clones props by creating new instance and copying current configuration. -
getActiveProfiles
Returns active profiles ornullif none defined. -
setActiveProfiles
Sets new active profiles and overrides existing ones. By settingnull, no active profile will be set.Note that if some props are loaded after this method call, they might override active profiles by using special property for active profiles (
@profiles). -
setEscapeNewLineValue
Specifies the new line string when EOL is escaped. Default value is an empty string. -
setValueTrimLeft
Specifies should the values be trimmed from the left. Default istrue. -
setValueTrimRight
Specifies should the values be trimmed from the right. Default istrue. -
setIgnorePrefixWhitespacesOnNewLine
Defines if the prefix whitespaces should be ignored when value is split into the lines. -
setSkipEmptyProps
Skips empty properties as they don't exist. -
setAppendDuplicateProps
Appends duplicate props. -
setIgnoreMissingMacros
Ignore missing macros by replacing them with an empty string. -
setMultilineValues
Enables multiline values. -
parse
Parses input string and loads provided properties map. -
load
Loads props from the string. -
load
Loads props from the file. Assumes UTF8 encoding unless the file ends with '.properties', than it uses ISO 8859-1.- Throws:
IOException
-
load
Loads properties from the file in provided encoding.- Throws:
IOException
-
load
Loads properties from input stream. Stream is not closed at the end.- Throws:
IOException
-
load
Loads properties from input stream and provided encoding. Stream is not closed at the end.- Throws:
IOException
-
load
Loads base properties from the provided java properties. Null values are ignored. -
load
Loads base properties from java Map using provided prefix. Null values are ignored. -
loadSystemProperties
Loads system properties with given prefix. If prefix isnullit will not be ignored. -
loadEnvironment
Loads environment properties with given prefix. If prefix isnullit will not be used. -
countTotalProperties
public int countTotalProperties()Counts the total number of properties, including all profiles. This operation performs calculation each time and it might be more time consuming then expected. -
getBaseValue
Returnsstringvalue of base property. Returnsnullif property doesn't exist. -
getValue
Returns value of property, using active profiles, ornullif property not found. -
getValueOrDefault
Returns value of property, using active profiles or default value if not found. -
getIntegerValue
Returns integer value of given property ornullif property not found. -
getIntegerValue
Returns integer value or default one if property not defined. -
getLongValue
Returns long value of given property ornullif property not found. -
getLongValue
Returns long value or default one if property not defined. -
getDoubleValue
Returns double value of given property ornullif property not found. -
getDoubleValue
Returns double value or default one if property not defined. -
getBooleanValue
Returns boolean value of given property ornullif property not found. -
getBooleanValue
Returns boolean value or default one if property not defined. -
getValue
Returnsstringvalue of given profiles. If key is not found under listed profiles, base properties will be searched. Returnsnullif property doesn't exist. -
getIntegerValue
-
getIntegerValue
-
getLongValue
-
getLongValue
-
getDoubleValue
-
getDoubleValue
-
getBooleanValue
-
getBooleanValue
-
setValue
Sets default value. -
setValue
Sets value on some profile. -
extractProps
Extracts props belonging to active profiles. -
extractProps
Extract props of given profiles. -
extractSubProps
Extracts subset of properties that matches given wildcards. -
extractSubProps
Extracts subset of properties that matches given wildcards. -
innerMap
Returns inner map from the props with given prefix. Keys in returned map will not have the prefix. -
addInnerMap
Adds child map to the props on given prefix. -
addInnerMap
Adds child map to the props on given prefix. -
initialize
protected void initialize()Initializes props. By default it only resolves active profiles. -
resolveActiveProfiles
protected void resolveActiveProfiles()Resolves active profiles from special property. This property can be only a base property! If default active property is not defined, nothing happens. Otherwise, it will replace currently active profiles. -
getAllProfiles
Returns all profiles names. -
getProfilesFor
Returns all the profiles that define certain prop's key name. Key name is given as a wildcard, or it can be matched fully. -
entries
-
iterator
Returns iterator for active profiles.
-