KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > http > HttpFileProvider


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.provider.http;
17
18 import org.apache.commons.httpclient.HttpClient;
19 import org.apache.commons.vfs.Capability;
20 import org.apache.commons.vfs.FileName;
21 import org.apache.commons.vfs.FileSystem;
22 import org.apache.commons.vfs.FileSystemConfigBuilder;
23 import org.apache.commons.vfs.FileSystemException;
24 import org.apache.commons.vfs.FileSystemOptions;
25 import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider;
26 import org.apache.commons.vfs.provider.GenericFileName;
27
28 import java.util.Arrays JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.Collections JavaDoc;
31
32
33 /**
34  * An HTTP provider that uses commons-httpclient.
35  *
36  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
37  */

38 public class HttpFileProvider
39     extends AbstractOriginatingFileProvider
40 {
41     final static Collection JavaDoc capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[]
42     {
43         Capability.GET_TYPE,
44         Capability.READ_CONTENT,
45         Capability.URI,
46         Capability.GET_LAST_MODIFIED,
47         Capability.ATTRIBUTES,
48         Capability.RANDOM_ACCESS_READ
49     }));
50
51     public HttpFileProvider()
52     {
53         super();
54         setFileNameParser(HttpFileNameParser.getInstance());
55     }
56
57     /**
58      * Creates a {@link FileSystem}.
59      */

60     protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
61         throws FileSystemException
62     {
63         // Create the file system
64
final GenericFileName rootName = (GenericFileName) name;
65
66         HttpClient httpClient = HttpClientFactory.createConnection(rootName.getHostName(),
67             rootName.getPort(),
68             rootName.getUserName(),
69             rootName.getPassword(),
70             fileSystemOptions);
71
72         return new HttpFileSystem(rootName, httpClient, fileSystemOptions);
73     }
74
75     public FileSystemConfigBuilder getConfigBuilder()
76     {
77         return HttpFileSystemConfigBuilder.getInstance();
78     }
79
80     public Collection JavaDoc getCapabilities()
81     {
82         return capabilities;
83     }
84 }
85
Popular Tags