Source code
Description: source: package: org.apache.commons.configuration2.io, interface: FileLocationStrategy

    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *     https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.configuration2.io;
    018
    019import java.net.URL;
    020
    021/**
    022 * <p>
    023 * An interface allowing applications to customize the process of locating a file.
    024 * </p>
    025 * <p>
    026 * {@link FileHandler} uses {@link FileLocator} objects for referencing files. These objects are not guaranteed to
    027 * identify a file in a unique way. For instance, if only a file name is defined, this could mean a relative file name
    028 * in the current directory, the name of a resource to be loaded from the class path, or something else. Before the file
    029 * described by a {@code FileLocator} can be actually accessed, an unambiguous URL pointing to this file has to be
    030 * obtained. This is the job of a {@code FileLocationStrategy}.
    031 * </p>
    032 * <p>
    033 * This interface defines a method for locating a file provided as a {@code FileLocator} object. If location is
    034 * successful, a URL is returned. A concrete implementation can perform arbitrary actions to search for the file in
    035 * question at various places. There will also be an implementation allowing the combination of multiple
    036 * {@code FileLocationStrategy} implementations; so a file can be searched using multiple strategies until one of them
    037 * is successful.
    038 * </p>
    039 * <p>
    040 * See {@link AbstractFileLocationStrategy} learn how to grant an deny URL schemes and hosts.
    041 * </p>
    042 *
    043 * @see AbstractFileLocationStrategy
    044 * @since 2.0
    045 */
    046public interface FileLocationStrategy {
    047
    048    /**
    049     * Tries to locate the specified file. The method also expects the {@code FileSystem} to be used. Note that the
    050     * {@code FileLocator} object may also contain a {@code FileSystem}, but this is optional. The passed in
    051     * {@code FileSystem} should be used, and callers must not pass a <strong>null</strong> reference for this argument. A concrete
    052     * implementation has to evaluate the properties stored in the {@code FileLocator} object and try to match them to an
    053     * existing file. If this can be done, a corresponding URL is returned. Otherwise, result is <strong>null</strong>.
    054     * Implementations should not throw an exception (unless parameters are <strong>null</strong>) as there might be alternative
    055     * strategies which can find the file in question.
    056     *
    057     * @param fileSystem the {@code FileSystem} to be used for this operation
    058     * @param locator the object describing the file to be located
    059     * @return a URL pointing to the referenced file if location was successful; <strong>null</strong> if the file could not be
    060     *         resolved
    061     */
    062    URL locate(FileSystem fileSystem, FileLocator locator);
    063}