org.apache.commons.configuration2.io

## Interface FileLocationStrategy

- All Known Implementing Classes:
    AbsoluteNameLocationStrategy, BasePathLocationStrategy, ClasspathLocationStrategy, CombinedLocationStrategy, FileSystemLocationStrategy, HomeDirectoryLocationStrategy, ProvidedURLLocationStrategy

      public interface FileLocationStrategy

  An interface allowing applications to customize the process of locating a file.

  `FileHandler` uses `FileLocator` objects for referencing files. These objects are not guaranteed to identify a file in a unique way. For instance, if only a file name is defined, this could mean a relative file name in the current directory, the name of a resource to be loaded from the class path, or something else. Before the file described by a `FileLocator` can be actually accessed, an unambiguous URL pointing to this file has to be obtained. This is the job of a `FileLocationStrategy`.

  This interface defines a method for locating a file provided as a `FileLocator` object. If location is successful, a URL is returned. A concrete implementation can perform arbitrary actions to search for the file in question at various places. There will also be an implementation allowing the combination of multiple `FileLocationStrategy` implementations; so a file can be searched using multiple strategies until one of them is successful.

  Since:
    2.0

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `URL` | `locate(FileSystem fileSystem, FileLocator locator)` Tries to locate the specified file.

- - ### Method Detail

    - #### locate

          URL locate(FileSystem fileSystem,
                     FileLocator locator)

      Tries to locate the specified file. The method also expects the `FileSystem` to be used. Note that the `FileLocator` object may also contain a `FileSystem`, but this is optional. The passed in `FileSystem` should be used, and callers must not pass a null reference for this argument. A concrete implementation has to evaluate the properties stored in the `FileLocator` object and try to match them to an existing file. If this can be done, a corresponding URL is returned. Otherwise, result is null. Implementations should not throw an exception (unless parameters are null) as there might be alternative strategies which can find the file in question.
      Parameters:
        `fileSystem` - the `FileSystem` to be used for this operation
        `locator` - the object describing the file to be located
      Returns:
        a URL pointing to the referenced file if location was successful; null if the file could not be resolved

Copyright © 2001–2020 The Apache Software Foundation. All rights reserved.