KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > webdav > WebdavClientFactory


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.webdav;
17
18 import org.apache.commons.httpclient.HttpClient;
19 import org.apache.commons.httpclient.HttpURL;
20 import org.apache.commons.vfs.FileSystemException;
21 import org.apache.commons.vfs.FileSystemOptions;
22 import org.apache.webdav.lib.WebdavResource;
23
24 import java.io.IOException JavaDoc;
25
26 /**
27  * Create a HttpClient instance
28  *
29  * @author <a HREF="mailto:imario@apache.org">Mario Ivankovits</a>
30  */

31 public class WebdavClientFactory
32 {
33     private WebdavClientFactory()
34     {
35     }
36
37     /**
38      * Creates a new connection to the server.
39      */

40     public static HttpClient createConnection(String JavaDoc hostname, int port, String JavaDoc username, String JavaDoc password, FileSystemOptions fileSystemOptions) throws FileSystemException
41     {
42         // Create an Http client
43
HttpClient client;
44         try
45         {
46             final HttpURL url = new HttpURL(username,
47                 password,
48                 hostname,
49                 port,
50                 "/");
51
52             // WebdavResource resource = null;
53
WebdavResource resource = new WebdavResource()
54             {
55             };
56
57             if (fileSystemOptions != null)
58             {
59                 String JavaDoc proxyHost = WebdavFileSystemConfigBuilder.getInstance().getProxyHost(fileSystemOptions);
60                 int proxyPort = WebdavFileSystemConfigBuilder.getInstance().getProxyPort(fileSystemOptions);
61
62                 if (proxyHost != null && proxyPort > 0)
63                 {
64                     // resource = new WebdavResource(url, proxyHost, proxyPort);
65
resource.setProxy(proxyHost, proxyPort);
66                 }
67             }
68
69             /*
70             if (resource == null)
71             {
72                 resource = new WebdavResource(url);
73             }
74             resource.setProperties(WebdavResource.NOACTION, 1);
75             */

76             resource.setHttpURL(url, WebdavResource.NOACTION, 1);
77
78             client = resource.retrieveSessionInstance();
79             client.setHttpConnectionManager(new WebdavConnectionManager());
80         }
81         catch (final IOException JavaDoc e)
82         {
83             throw new FileSystemException("vfs.provider.webdav/connect.error", hostname, e);
84         }
85
86         return client;
87     }
88 }
Popular Tags