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: */
017: package org.apache.commons.vfs;
018:
019: import org.apache.commons.logging.Log;
020:
021: import java.io.File;
022: import java.net.URLStreamHandlerFactory;
023: import java.util.Collection;
024: import java.lang.reflect.Constructor;
025:
026: import org.apache.commons.vfs.operations.FileOperationProvider;
027:
028: /**
029: * A FileSystemManager manages a set of file systems. This interface is
030: * used to locate a {@link FileObject} by name from one of those file systems.
031: * <p/>
032: * <p>To locate a {@link FileObject}, use one of the <code>resolveFile()</code>
033: * methods.</p>
034: * <p/>
035: * <h4><a name="naming">File Naming</a></h4>
036: * <p/>
037: * <p>A file system manager can recognise several types of file names:
038: * <p/>
039: * <ul>
040: * <p/>
041: * <li><p>Absolute URI. These must start with a scheme, such as
042: * <code>file:</code> or <code>ftp:</code>, followed by a scheme dependent
043: * file name. Some examples:</p>
044: * <pre>
045: * file:/c:/somefile
046: * ftp://somewhere.org/somefile
047: * </pre>
048: * <p/>
049: * <li><p>Absolute local file name. For example,
050: * <code>/home/someuser/a-file</code> or <code>c:\dir\somefile.html</code>.
051: * Elements in the name can be separated using any of the following
052: * characters: <code>/</code>, <code>\</code>, or the native file separator
053: * character. For example, the following file names are the same:</p>
054: * <pre>
055: * c:\somedir\somefile.xml
056: * c:/somedir/somefile.xml
057: * </pre>
058: * <p/>
059: * <li><p>Relative path. For example: <code>../somefile</code> or
060: * <code>somedir/file.txt</code>. The file system manager resolves relative
061: * paths against its <i>base file</i>. Elements in the relative path can be
062: * separated using <code>/</code>, <code>\</code>, or file system specific
063: * separator characters. Relative paths may also contain <code>..</code> and
064: * <code>.</code> elements. See {@link FileObject#resolveFile} for more
065: * details.</p>
066: * <p/>
067: * </ul>
068: *
069: * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
070: * @version $Revision: 484648 $ $Date: 2006-12-08 08:18:36 -0800 (Fri, 08 Dec 2006) $
071: */
072: public interface FileSystemManager {
073: /**
074: * Returns the base file used to resolve relative paths.
075: */
076: public FileObject getBaseFile() throws FileSystemException;
077:
078: /**
079: * Locates a file by name. Equivalent to calling
080: * <code>resolveFile(uri, getBaseName())</code>.
081: *
082: * @param name The name of the file.
083: * @return The file. Never returns null.
084: * @throws FileSystemException On error parsing the file name.
085: */
086: public FileObject resolveFile(String name)
087: throws FileSystemException;
088:
089: /**
090: * Locates a file by name. Equivalent to calling
091: * <code>resolveFile(uri, getBaseName())</code>.
092: *
093: * @param name The name of the file.
094: * @param fileSystemOptions The FileSystemOptions used for FileSystem creation
095: * @return The file. Never returns null.
096: * @throws FileSystemException On error parsing the file name.
097: */
098: public FileObject resolveFile(String name,
099: FileSystemOptions fileSystemOptions)
100: throws FileSystemException;
101:
102: /**
103: * Locates a file by name. The name is resolved as described
104: * <a href="#naming">above</a>. That is, the name can be either
105: * an absolute URI, an absolute file name, or a relative path to
106: * be resolved against <code>baseFile</code>.
107: * <p/>
108: * <p>Note that the file does not have to exist when this method is called.
109: *
110: * @param name The name of the file.
111: * @param baseFile The base file to use to resolve relative paths.
112: * May be null.
113: * @return The file. Never returns null.
114: * @throws FileSystemException On error parsing the file name.
115: */
116: public FileObject resolveFile(FileObject baseFile, String name)
117: throws FileSystemException;
118:
119: /**
120: * Locates a file by name. See {@link #resolveFile(FileObject, String)}
121: * for details.
122: *
123: * @param baseFile The base file to use to resolve relative paths.
124: * May be null.
125: * @param name The name of the file.
126: * @return The file. Never returns null.
127: * @throws FileSystemException On error parsing the file name.
128: */
129: public FileObject resolveFile(File baseFile, String name)
130: throws FileSystemException;
131:
132: /**
133: * Resolves a name, relative to this file name. Equivalent to calling
134: * <code>resolveName( path, NameScope.FILE_SYSTEM )</code>.
135: *
136: * @param root the base filename
137: * @param name The name to resolve.
138: * @return A {@link FileName} object representing the resolved file name.
139: * @throws FileSystemException If the name is invalid.
140: */
141: public FileName resolveName(final FileName root, final String name)
142: throws FileSystemException;
143:
144: /**
145: * Resolves a name, relative to the "root" file name. Refer to {@link NameScope}
146: * for a description of how names are resolved.
147: *
148: * @param root the base filename
149: * @param name The name to resolve.
150: * @param scope The {@link NameScope} to use when resolving the name.
151: * @return A {@link FileName} object representing the resolved file name.
152: * @throws FileSystemException If the name is invalid.
153: */
154: public FileName resolveName(final FileName root, String name,
155: NameScope scope) throws FileSystemException;
156:
157: /**
158: * Converts a local file into a {@link FileObject}.
159: *
160: * @param file The file to convert.
161: * @return The {@link FileObject} that represents the local file. Never
162: * returns null.
163: * @throws FileSystemException On error converting the file.
164: */
165: public FileObject toFileObject(File file)
166: throws FileSystemException;
167:
168: /**
169: * Creates a layered file system. A layered file system is a file system
170: * that is created from the contents of a file, such as a zip or tar file.
171: *
172: * @param provider The name of the file system provider to use. This name
173: * is the same as the scheme used in URI to identify the provider.
174: * @param file The file to use to create the file system.
175: * @return The root file of the new file system.
176: * @throws FileSystemException On error creating the file system.
177: */
178: public FileObject createFileSystem(String provider, FileObject file)
179: throws FileSystemException;
180:
181: /**
182: * Closes the given filesystem.<br />
183: * If you use VFS as singleton it is VERY dangerous to call this method.
184: */
185: public void closeFileSystem(FileSystem filesystem);
186:
187: /**
188: * Creates a layered file system. A layered file system is a file system
189: * that is created from the contents of a file, such as a zip or tar file.
190: *
191: * @param file The file to use to create the file system.
192: * @return The root file of the new file system.
193: * @throws FileSystemException On error creating the file system.
194: */
195: public FileObject createFileSystem(FileObject file)
196: throws FileSystemException;
197:
198: /**
199: * Creates an empty virtual file system. Can be populated by adding
200: * junctions to it.
201: *
202: * @param rootUri The root URI to use for the new file system. Can be null.
203: * @return The root file of the new file system.
204: */
205: public FileObject createVirtualFileSystem(String rootUri)
206: throws FileSystemException;
207:
208: /**
209: * Creates a virtual file system. The file system will contain a junction
210: * at the fs root to the supplied root file.
211: *
212: * @param rootFile The root file to backs the file system.
213: * @return The root of the new file system.
214: */
215: public FileObject createVirtualFileSystem(FileObject rootFile)
216: throws FileSystemException;
217:
218: /**
219: * Returns a streamhandler factory to enable URL lookup using this
220: * FileSystemManager.
221: */
222: public URLStreamHandlerFactory getURLStreamHandlerFactory();
223:
224: /**
225: * Determines if a layered file system can be created for a given file.
226: *
227: * @param file The file to check for.
228: */
229: public boolean canCreateFileSystem(FileObject file)
230: throws FileSystemException;
231:
232: /**
233: * Get the cache used to cache fileobjects.
234: */
235: public FilesCache getFilesCache();
236:
237: /**
238: * Get the cache strategy used
239: */
240: public CacheStrategy getCacheStrategy();
241:
242: /**
243: * Get the file object decorator used
244: */
245: public Class getFileObjectDecorator();
246:
247: /**
248: * The constructor associated to the fileObjectDecorator.
249: * We cache it here for performance reasons.
250: */
251: public Constructor getFileObjectDecoratorConst();
252:
253: /**
254: * The class to use to determine the content-type (mime-type)
255: */
256: public FileContentInfoFactory getFileContentInfoFactory();
257:
258: /**
259: * Get the schemes currently available.
260: */
261: public String[] getSchemes();
262:
263: /**
264: * Get the capabilities for a given scheme.
265: *
266: * @throws FileSystemException if the given scheme is not konwn
267: */
268: public Collection getProviderCapabilities(final String scheme)
269: throws FileSystemException;
270:
271: /**
272: * Sets the logger to use.
273: */
274: public void setLogger(final Log log);
275:
276: /**
277: * Get the configuration builder for the given scheme
278: *
279: * @throws FileSystemException if the given scheme is not konwn
280: */
281: public FileSystemConfigBuilder getFileSystemConfigBuilder(
282: final String scheme) throws FileSystemException;
283:
284: /**
285: * Resolve the uri to a filename
286: *
287: * @throws FileSystemException if this is not possible
288: */
289: public FileName resolveURI(String uri) throws FileSystemException;
290:
291: // -- OPERATIONS --
292: /**
293: * Adds the specified FileOperationProvider for the specified scheme.
294: * Several FileOperationProvider's might be registered for the same scheme.
295: * For example, for "file" scheme we can register SvnWsOperationProvider and
296: * CvsOperationProvider.
297: *
298: * @param scheme
299: * @param operationProvider
300: * @throws FileSystemException
301: */
302: public void addOperationProvider(final String scheme,
303: final FileOperationProvider operationProvider)
304: throws FileSystemException;
305:
306: /**
307: * @see FileSystemManager#addOperationProvider(String, org.apache.commons.vfs.operations.FileOperationProvider)
308: *
309: * @param schemes
310: * @param operationProvider
311: * @throws FileSystemException
312: */
313: public void addOperationProvider(final String[] schemes,
314: final FileOperationProvider operationProvider)
315: throws FileSystemException;
316:
317: /**
318: * @param scheme the scheme for wich we want to get the list af registered providers.
319: *
320: * @return the registered FileOperationProviders for the specified scheme.
321: * If there were no providers registered for the scheme, it returns null.
322: *
323: * @throws FileSystemException
324: */
325: public FileOperationProvider[] getOperationProviders(
326: final String scheme) throws FileSystemException;
327: }
|