Class AbstractFileLocationStrategy
- All Implemented Interfaces:
FileLocationStrategy
- Direct Known Subclasses:
AbsoluteNameLocationStrategy,BasePathLocationStrategy,ClasspathLocationStrategy,CombinedLocationStrategy,FileSystemLocationStrategy,HomeDirectoryLocationStrategy,ProvidedURLLocationStrategy
Note that some FileLocationStrategy implementation use URLs internally to encode file locations.
As of version 2.15.0, by default, the only URL schemes allowed are file and jar. To override this default, you can either use the system
property org.apache.commons.configuration2.io.FileLocationStrategy.schemes or build a subclass of AbstractFileLocationStrategy.
The system property org.apache.commons.configuration2.io.FileLocationStrategy.schemes String value must be a comma-separated list of schemes,
where the default is "file,jar", and the complete list is "file,http,https,jar".
The root builder for AbstractFileLocationStrategy is AbstractFileLocationStrategy.AbstractBuilder where you define allowed schemes and hosts through its setter
methods.
For example, to programatically enable the shemes "file", "http", "https", and "jar" for all strategies, you write:
final PropertiesConfiguration pc = new PropertiesConfiguration();
pc.setIncludeListener(PropertiesConfiguration.NOOP_INCLUDE_LISTENER);
final FileHandler handler = new FileHandler(pc);
final CombinedLocationStrategy.Builder builder = new CombinedLocationStrategy.Builder()
.setSchemes(new TreeSet<>(Arrays.asList("file", "http", "https", "jar")));
// @formatter:off
handler.setLocationStrategy(builder.setSubStrategies(Arrays.asList(
new ProvidedURLLocationStrategy(builder),
new FileSystemLocationStrategy(builder),
new AbsoluteNameLocationStrategy(builder),
new BasePathLocationStrategy(builder),
new HomeDirectoryLocationStrategy.Builder().setEvaluateBasePath(true).getUnchecked(),
new HomeDirectoryLocationStrategy.Builder().setEvaluateBasePath(false).getUnchecked(),
new ClasspathLocationStrategy(builder)))
.get());
// @formatter:on
handler.setBasePath(TEST_BASE_PATH);
handler.setFileName("include-load-url-host-unknown-exception.properties");
handler.load();
- Since:
- 2.15.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstractFileLocationStrategy.AbstractBuilder<T extends FileLocationStrategy,B extends AbstractFileLocationStrategy.AbstractBuilder<T, B>> Builds new instances for subclasses.static classBuilds new instances of T. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringDefault schemes.Enabled URL-based hosts, empty means all are enabled.private static final StringThe system property keyorg.apache.commons.configuration2.io.FileLocationStrategy.schemes.Enabled URL-based schemes, empty means all are enabled. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance where the enabled URL schemes are read the system property"org.apache.commons.configuration2.io.FileLocationStrategy.schemes".AbstractFileLocationStrategy(Set<String> schemes) -
Method Summary
Modifier and TypeMethodDescription(package private) URLprivate static voidprivate static voidcheckScheme(String value, Set<String> validSet) Checks if the scheme is allowed.(package private) static voidValidatesurlagainst the scheme and host allow-lists.getHosts()Gets the enabled hosts.Gets the enabled schemes.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.configuration2.io.FileLocationStrategy
locate
-
Field Details
-
DEFAULT_SCHEMES
Default schemes.- See Also:
-
KEY_SCHEMES
The system property keyorg.apache.commons.configuration2.io.FileLocationStrategy.schemes.If absent, defaults to
"file,jar".For complete functionality, use
"file,http,https,jar".- See Also:
-
hosts
Enabled URL-based hosts, empty means all are enabled. Host are case-insensitive. -
schemes
Enabled URL-based schemes, empty means all are enabled. Schemes are case-insensitive.
-
-
Constructor Details
-
AbstractFileLocationStrategy
AbstractFileLocationStrategy()Constructs a new instance where the enabled URL schemes are read the system property"org.apache.commons.configuration2.io.FileLocationStrategy.schemes".If absent, defaults to
"file,jar".For complete functionality, use
"file,http,https,jar". -
AbstractFileLocationStrategy
AbstractFileLocationStrategy(AbstractFileLocationStrategy.AbstractBuilder<?, ?> builder) -
AbstractFileLocationStrategy
-
-
Method Details
-
checkHost
-
checkScheme
Checks if the scheme is allowed.- Parameters:
value- A URL scheme, never empty ornull.validSet- the scheme valid-set.
-
checkUrl
Validatesurlagainst the scheme and host allow-lists.- Parameters:
url- the URL to check.validSchemes- the scheme valid-set.validHosts- the host valid-set.- Throws:
ConfigurationDeniedException- if the URL or any embedded URL fails the check, or ajar:URL is malformed.
-
getSchemesProperty
-
check
-
getHosts
Gets the enabled hosts.- Returns:
- the enabled hosts.
-
getSchemes
Gets the enabled schemes.- Returns:
- the enabled schemes.
-
toString
-