Class AbstractFileLocationStrategy
- java.lang.Object
-
- org.apache.commons.configuration2.io.AbstractFileLocationStrategy
-
- All Implemented Interfaces:
FileLocationStrategy
- Direct Known Subclasses:
AbsoluteNameLocationStrategy,BasePathLocationStrategy,ClasspathLocationStrategy,CombinedLocationStrategy,FileSystemLocationStrategy,HomeDirectoryLocationStrategy,ProvidedURLLocationStrategy
public abstract class AbstractFileLocationStrategy extends java.lang.Object implements FileLocationStrategy
Abstracts services for FileLocationStrategy implementations.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
Using System Propertiesfileandjar. To override this default, you can either use the system propertyorg.apache.commons.configuration2.io.FileLocationStrategy.schemesor build a subclass ofAbstractFileLocationStrategy.The system property
Using a Builderorg.apache.commons.configuration2.io.FileLocationStrategy.schemesString 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
AbstractFileLocationStrategyisAbstractFileLocationStrategy.AbstractBuilderwhere 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:
FileLocationStrategy
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractFileLocationStrategy.AbstractBuilder<T extends FileLocationStrategy,B extends AbstractFileLocationStrategy.AbstractBuilder<T,B>>Builds new instances for subclasses.static classAbstractFileLocationStrategy.StrategyBuilder<T extends FileLocationStrategy>Builds new instances of T.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.configuration2.io.FileLocationStrategy
locate
-
-