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.vfs2.provider.http; 018 019import java.util.Collection; 020 021import org.apache.commons.httpclient.HttpClient; 022import org.apache.commons.httpclient.HttpConnectionManager; 023import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; 024import org.apache.commons.vfs2.Capability; 025import org.apache.commons.vfs2.FileObject; 026import org.apache.commons.vfs2.FileSystemOptions; 027import org.apache.commons.vfs2.provider.AbstractFileName; 028import org.apache.commons.vfs2.provider.AbstractFileSystem; 029import org.apache.commons.vfs2.provider.GenericFileName; 030 031/** 032 * An HTTP file system. 033 */ 034public class HttpFileSystem extends AbstractFileSystem { 035 private final HttpClient client; 036 037 protected HttpFileSystem(final GenericFileName rootName, final HttpClient client, 038 final FileSystemOptions fileSystemOptions) { 039 super(rootName, null, fileSystemOptions); 040 this.client = client; 041 } 042 043 /** 044 * Adds the capabilities of this file system. 045 */ 046 @Override 047 protected void addCapabilities(final Collection<Capability> caps) { 048 caps.addAll(HttpFileProvider.capabilities); 049 } 050 051 protected HttpClient getClient() { 052 return client; 053 } 054 055 /** @since 2.0 */ 056 @Override 057 public void closeCommunicationLink() { 058 if (getClient() != null) { 059 final HttpConnectionManager mgr = getClient().getHttpConnectionManager(); 060 if (mgr instanceof MultiThreadedHttpConnectionManager) { 061 ((MultiThreadedHttpConnectionManager) mgr).shutdown(); 062 } 063 } 064 } 065 066 /** 067 * Creates a file object. This method is called only if the requested file is not cached. 068 */ 069 @Override 070 protected FileObject createFile(final AbstractFileName name) throws Exception { 071 return new HttpFileObject(name, this); 072 } 073}