Package org.apache.camel.spi
Interface PropertiesComponent
- All Superinterfaces:
AutoCloseable
,Service
,StaticService
Component for property placeholders and loading properties from sources (such as .properties file from classpath or
file system)
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.extractProperties
(String optionPrefix, boolean nested) Loads the properties from the default locations and extract properties by the given prefix.Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.Gets the configured properties locations.getPropertiesFunction
(String name) Gets thePropertiesFunction
by the given namegetPropertiesSource
(String name) Gets the customPropertiesSource
by the nameGets thePropertiesSourceFactory
.Gets the properties sourcesboolean
hasPropertiesFunction
(String name) Is there aPropertiesFunction
with the given name?void
keepOnlyChangeProperties
(Properties properties) Filters the given list of properties, by removing properties that are already loaded and have same key and value.Loads the properties from the default locations and sources.loadProperties
(Predicate<String> filter) Loads the properties from the default locations and sources filtering them out according to a predicate.Loads the properties from the default locations and sources filtering them out according to a predicate, and maps the key using the key mapper.Loads the properties from the default locations and sources.loadPropertiesAsMap
(Predicate<String> filter) Loads the properties from the default locations and sources filtering them out according to a predicate.Parses the input text and resolve all property placeholders from within the text.Parses the input text and resolve all property placeholders from within the text.boolean
reloadProperties
(String pattern) Reload properties from the given location patterns.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
setIgnoreMissingProperty
(boolean ignoreMissingProperty) Whether to silently ignore if a property cannot be resolved (i.e. all properties is marked as optional), and return the value as-is.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 Details
-
FACTORY
Service factory key.- See Also:
-
PREFIX_TOKEN
The prefix token.- See Also:
-
SUFFIX_TOKEN
The suffix token.- See Also:
-
OPTIONAL_TOKEN
The token for marking a placeholder as optional- See Also:
-
PREFIX_OPTIONAL_TOKEN
The prefix and optional tokens- See Also:
-
-
Method Details
-
parseUri
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
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
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
Loads the properties from the default locations and sources.- Returns:
- a
Map
representing the properties loaded.
-
loadProperties
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.
-
extractProperties
Loads the properties from the default locations and extract properties by the given prefix.- Parameters:
optionPrefix
- prefix to filternested
- whether to include nested properties- Returns:
- the properties loaded with option prefix removed.
-
loadProperties
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
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
Gets the configured properties locations. This may be empty if the properties component has only been configured withPropertiesSource
. -
setLocation
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
Adds the list of locations to the current locations, where to load properties. You can use comma to separate multiple locations. -
getPropertiesSourceFactory
PropertiesSourceFactory getPropertiesSourceFactory()Gets thePropertiesSourceFactory
. -
addPropertiesSource
Adds a customPropertiesSource
to use as source for loading and/or looking up property values. -
getPropertiesSource
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
Registers thePropertiesFunction
as a function to this component. -
getPropertiesFunction
Gets thePropertiesFunction
by the given name- Parameters:
name
- the function name- Returns:
- the function or null if no function exists
-
hasPropertiesFunction
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. -
setIgnoreMissingProperty
void setIgnoreMissingProperty(boolean ignoreMissingProperty) Whether to silently ignore if a property cannot be resolved (i.e. all properties is marked as optional), and return the value as-is. -
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
Sets initial properties which will be added before any property locations are loaded. -
addInitialProperty
Adds an initial property which will be added before any property locations are loaded.- Parameters:
key
- the keyvalue
- the value
-
setOverrideProperties
Sets a special list of override properties that take precedence and will use first, if a property exist. -
addOverrideProperty
Adds a special override property that take precedence and will use first, if a property exist.- Parameters:
key
- the keyvalue
- the value
-
setLocalProperties
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
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
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
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
-
keepOnlyChangeProperties
Filters the given list of properties, by removing properties that are already loaded and have same key and value. If all properties are not changed then the properties will become empty.- Parameters:
properties
- the given properties to filter.
-
addPropertiesLookupListener
Adds thePropertiesLookupListener
.
-