01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.vfs.provider.http;
18:
19: import org.apache.commons.httpclient.HttpClient;
20: import org.apache.commons.httpclient.HttpConnectionManager;
21: import org.apache.commons.vfs.FileName;
22: import org.apache.commons.vfs.FileObject;
23: import org.apache.commons.vfs.FileSystem;
24: import org.apache.commons.vfs.FileSystemOptions;
25: import org.apache.commons.vfs.provider.AbstractFileSystem;
26: import org.apache.commons.vfs.provider.GenericFileName;
27:
28: import java.util.Collection;
29:
30: /**
31: * An HTTP file system.
32: *
33: * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
34: * @version $Revision: 548717 $ $Date: 2007-06-19 06:07:40 -0700 (Tue, 19 Jun 2007) $
35: */
36: public class HttpFileSystem extends AbstractFileSystem implements
37: FileSystem {
38: private final HttpClient client;
39:
40: protected HttpFileSystem(final GenericFileName rootName,
41: final HttpClient client,
42: final FileSystemOptions fileSystemOptions) {
43: super (rootName, null, fileSystemOptions);
44: this .client = client;
45: }
46:
47: /**
48: * Adds the capabilities of this file system.
49: */
50: protected void addCapabilities(final Collection caps) {
51: caps.addAll(HttpFileProvider.capabilities);
52: }
53:
54: protected HttpClient getClient() {
55: return client;
56: }
57:
58: public void closeCommunicationLink() {
59: if (getClient() != null) {
60: HttpConnectionManager mgr = getClient()
61: .getHttpConnectionManager();
62: if (mgr instanceof ThreadLocalHttpConnectionManager) {
63: ((ThreadLocalHttpConnectionManager) mgr)
64: .releaseLocalConnection();
65: }
66: }
67: }
68:
69: /**
70: * Creates a file object. This method is called only if the requested
71: * file is not cached.
72: */
73: protected FileObject createFile(final FileName name)
74: throws Exception {
75: return new HttpFileObject(name, this);
76: }
77: }
|