Package org.apache.camel.spi
Interface PropertiesComponent
-
- All Superinterfaces:
AutoCloseable
,Service
,StaticService
public interface PropertiesComponent extends StaticService
Component for property placeholders and loading properties from sources (such as .properties file from classpath or file system)
-
-
Field Summary
Fields Modifier and Type Field Description static String
FACTORY
Service factory key.static String
OPTIONAL_TOKEN
The token for marking a placeholder as optionalstatic String
PREFIX_OPTIONAL_TOKEN
The prefix and optional tokensstatic String
PREFIX_TOKEN
The prefix token.static String
SUFFIX_TOKEN
The suffix token.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
addInitialProperty(String key, String value)
Adds an initial property which will be added before any property locations are loaded.void
addLocation(String location)
Adds the list of locations to the current locations, where to load properties.void
addOverrideProperty(String key, String value)
Adds a special override property that take precedence and will use first, if a property exist.void
addPropertiesFunction(PropertiesFunction function)
Registers thePropertiesFunction
as a function to this component.void
addPropertiesLookupListener(PropertiesLookupListener propertiesLookupListener)
Adds thePropertiesLookupListener
.void
addPropertiesSource(PropertiesSource propertiesSource)
Adds a customPropertiesSource
to use as source for loading and/or looking up property values.Properties
getLocalProperties()
Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.default Map<String,Object>
getLocalPropertiesAsMap()
Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.List<String>
getLocations()
Gets the configured properties locations.PropertiesFunction
getPropertiesFunction(String name)
Gets thePropertiesFunction
by the given namePropertiesSource
getPropertiesSource(String name)
Gets the customPropertiesSource
by the nameList<PropertiesSource>
getPropertiesSources()
Gets the properties sourcesboolean
hasPropertiesFunction(String name)
Is there aPropertiesFunction
with the given name?Properties
loadProperties()
Loads the properties from the default locations and sources.Properties
loadProperties(Predicate<String> filter)
Loads the properties from the default locations and sources filtering them out according to a predicate.Properties
loadProperties(Predicate<String> filter, Function<String,String> keyMapper)
Loads the properties from the default locations and sources filtering them out according to a predicate, and maps the key using the key mapper.default Map<String,Object>
loadPropertiesAsMap()
Loads the properties from the default locations and sources.default Map<String,Object>
loadPropertiesAsMap(Predicate<String> filter)
Loads the properties from the default locations and sources filtering them out according to a predicate.String
parseUri(String uri)
Parses the input text and resolve all property placeholders from within the text.String
parseUri(String uri, boolean keepUnresolvedOptional)
Parses the input text and resolve all property placeholders from within the text.boolean
reloadProperties(String pattern)
Reload properties from the given location patterns.Optional<String>
resolveProperty(String key)
Looks up the property with the given keyvoid
setEncoding(String encoding)
Encoding to use when loading properties file from the file system or classpath.void
setIgnoreMissingLocation(boolean ignoreMissingLocation)
Whether to silently ignore if a location cannot be located, such as a properties file not found.void
setInitialProperties(Properties initialProperties)
Sets initial properties which will be added before any property locations are loaded.void
setLocalProperties(Properties localProperties)
Sets a special list of local properties (ie thread local) that take precedence and will use first, if a property exist.void
setLocation(String location)
A list of locations to load properties.void
setNestedPlaceholder(boolean nestedPlaceholder)
Whether to support nested property placeholders.void
setOverrideProperties(Properties overrideProperties)
Sets a special list of override properties that take precedence and will use first, if a property exist.
-
-
-
Field Detail
-
FACTORY
static final String FACTORY
Service factory key.- See Also:
- Constant Field Values
-
PREFIX_TOKEN
static final String PREFIX_TOKEN
The prefix token.- See Also:
- Constant Field Values
-
SUFFIX_TOKEN
static final String SUFFIX_TOKEN
The suffix token.- See Also:
- Constant Field Values
-
OPTIONAL_TOKEN
static final String OPTIONAL_TOKEN
The token for marking a placeholder as optional- See Also:
- Constant Field Values
-
PREFIX_OPTIONAL_TOKEN
static final String PREFIX_OPTIONAL_TOKEN
The prefix and optional tokens- See Also:
- Constant Field Values
-
-
Method Detail
-
parseUri
String parseUri(String uri)
Parses the input text and resolve all property placeholders from within the text.- Parameters:
uri
- input text- Returns:
- text with resolved property placeholders
- Throws:
IllegalArgumentException
- is thrown if error during parsing
-
parseUri
String parseUri(String uri, boolean keepUnresolvedOptional)
Parses the input text and resolve all property placeholders from within the text.- Parameters:
uri
- input textkeepUnresolvedOptional
- whether to keep placeholders that are optional and was unresolved- Returns:
- text with resolved property placeholders
- Throws:
IllegalArgumentException
- is thrown if error during parsing
-
resolveProperty
Optional<String> resolveProperty(String key)
Looks up the property with the given key- Parameters:
key
- the name of the property- Returns:
- the property value if present
-
loadProperties
Properties loadProperties()
Loads the properties from the default locations and sources.- Returns:
- the properties loaded.
-
loadPropertiesAsMap
default Map<String,Object> loadPropertiesAsMap()
Loads the properties from the default locations and sources.- Returns:
- a
Map
representing the properties loaded.
-
loadProperties
Properties loadProperties(Predicate<String> filter)
Loads the properties from the default locations and sources filtering them out according to a predicate.PropertiesComponent pc = getPropertiesComponent(); Properties props = pc.loadProperties(key -> key.startsWith("camel.component.seda"));
- Parameters:
filter
- the predicate used to filter out properties based on the key.- Returns:
- the properties loaded.
-
loadProperties
Properties loadProperties(Predicate<String> filter, Function<String,String> keyMapper)
Loads the properties from the default locations and sources filtering them out according to a predicate, and maps the key using the key mapper.PropertiesComponent pc = getPropertiesComponent(); Properties props = pc.loadProperties(key -> key.startsWith("camel.component.seda"), StringHelper::dashToCamelCase);
- Parameters:
filter
- the predicate used to filter out properties based on the key.keyMapper
- to map keys- Returns:
- the properties loaded.
-
loadPropertiesAsMap
default Map<String,Object> loadPropertiesAsMap(Predicate<String> filter)
Loads the properties from the default locations and sources filtering them out according to a predicate.PropertiesComponent pc = getPropertiesComponent(); Map props = pc.loadPropertiesAsMap(key -> key.startsWith("camel.component.seda"));
- Parameters:
filter
- the predicate used to filter out properties based on the key.- Returns:
- a
Map
representing the properties loaded.
-
getLocations
List<String> getLocations()
Gets the configured properties locations. This may be empty if the properties component has only been configured withPropertiesSource
.
-
setLocation
void setLocation(String location)
A list of locations to load properties. You can use comma to separate multiple locations. This option will override any default locations and only use the locations from this option.
-
addLocation
void addLocation(String location)
Adds the list of locations to the current locations, where to load properties. You can use comma to separate multiple locations.
-
addPropertiesSource
void addPropertiesSource(PropertiesSource propertiesSource)
Adds a customPropertiesSource
to use as source for loading and/or looking up property values.
-
getPropertiesSource
PropertiesSource getPropertiesSource(String name)
Gets the customPropertiesSource
by the name- Parameters:
name
- the name of the source- Returns:
- the source, or null if no source exists
-
getPropertiesSources
List<PropertiesSource> getPropertiesSources()
Gets the properties sources
-
addPropertiesFunction
void addPropertiesFunction(PropertiesFunction function)
Registers thePropertiesFunction
as a function to this component.
-
getPropertiesFunction
PropertiesFunction getPropertiesFunction(String name)
Gets thePropertiesFunction
by the given name- Parameters:
name
- the function name- Returns:
- the function or null if no function exists
-
hasPropertiesFunction
boolean hasPropertiesFunction(String name)
Is there aPropertiesFunction
with the given name?
-
setIgnoreMissingLocation
void setIgnoreMissingLocation(boolean ignoreMissingLocation)
Whether to silently ignore if a location cannot be located, such as a properties file not found.
-
setNestedPlaceholder
void setNestedPlaceholder(boolean nestedPlaceholder)
Whether to support nested property placeholders. A nested placeholder, means that a placeholder, has also a placeholder, that should be resolved (recursively).
-
setInitialProperties
void setInitialProperties(Properties initialProperties)
Sets initial properties which will be added before any property locations are loaded.
-
addInitialProperty
void addInitialProperty(String key, String value)
Adds an initial property which will be added before any property locations are loaded.- Parameters:
key
- the keyvalue
- the value
-
setOverrideProperties
void setOverrideProperties(Properties overrideProperties)
Sets a special list of override properties that take precedence and will use first, if a property exist.
-
addOverrideProperty
void addOverrideProperty(String key, String value)
Adds a special override property that take precedence and will use first, if a property exist.- Parameters:
key
- the keyvalue
- the value
-
setLocalProperties
void setLocalProperties(Properties localProperties)
Sets a special list of local properties (ie thread local) that take precedence and will use first, if a property exist.
-
getLocalProperties
Properties getLocalProperties()
Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.
-
getLocalPropertiesAsMap
default Map<String,Object> getLocalPropertiesAsMap()
Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.- Returns:
- a
Map
representing the local properties, or null if not currently in use.
-
setEncoding
void setEncoding(String encoding)
Encoding to use when loading properties file from the file system or classpath. If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) as documented byProperties.load(java.io.InputStream)
Important you must set encoding before setting locations.
-
reloadProperties
boolean reloadProperties(String pattern)
Reload properties from the given location patterns.- Parameters:
pattern
- patterns, or null to reload from all known locations- Returns:
- true if some properties was reloaded
-
addPropertiesLookupListener
void addPropertiesLookupListener(PropertiesLookupListener propertiesLookupListener)
Adds thePropertiesLookupListener
.
-
-