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 * http://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 024 * file. 025 * </p> 026 * <p> 027 * {@link FileHandler} uses {@link FileLocator} objects for referencing files. 028 * These objects are not guaranteed to identify a file in a unique way. For 029 * instance, if only a file name is defined, this could mean a relative file 030 * name in the current directory, the name of a resource to be loaded from the 031 * class path, or something else. Before the file described by a 032 * {@code FileLocator} can be actually accessed, an unambiguous URL pointing to 033 * this file has to be obtained. This is the job of a 034 * {@code FileLocationStrategy}. 035 * </p> 036 * <p> 037 * This interface defines a method for locating a file provided as a 038 * {@code FileLocator} object. If location is successful, a URL is returned. A 039 * concrete implementation can perform arbitrary actions to search for the file 040 * in question at various places. There will also be an implementation allowing 041 * the combination of multiple {@code FileLocationStrategy} implementations; so 042 * a file can be searched using multiple strategies until one of them is 043 * successful. 044 * </p> 045 * 046 * @since 2.0 047 */ 048public interface FileLocationStrategy 049{ 050 /** 051 * Tries to locate the specified file. The method also expects the 052 * {@code FileSystem} to be used. Note that the {@code FileLocator} object 053 * may also contain a {@code FileSystem}, but this is optional. The passed 054 * in {@code FileSystem} should be used, and callers must not pass a 055 * <b>null</b> reference for this argument. A concrete implementation has to 056 * evaluate the properties stored in the {@code FileLocator} object and try 057 * to match them to an existing file. If this can be done, a corresponding 058 * URL is returned. Otherwise, result is <b>null</b>. Implementations should 059 * not throw an exception (unless parameters are <b>null</b>) as there might 060 * be alternative strategies which can find the file in question. 061 * 062 * @param fileSystem the {@code FileSystem} to be used for this operation 063 * @param locator the object describing the file to be located 064 * @return a URL pointing to the referenced file if location was successful; 065 * <b>null</b> if the file could not be resolved 066 */ 067 URL locate(FileSystem fileSystem, FileLocator locator); 068}