KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > source > impl > WebDAVSourceFactory


1 /*
2  * Copyright 1999-2004 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.cocoon.components.source.impl;
17
18 import java.io.IOException JavaDoc;
19 import java.net.MalformedURLException JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.avalon.framework.configuration.Configurable;
23 import org.apache.avalon.framework.configuration.Configuration;
24 import org.apache.avalon.framework.configuration.ConfigurationException;
25 import org.apache.avalon.framework.logger.AbstractLogEnabled;
26 import org.apache.avalon.framework.parameters.Parameters;
27 import org.apache.avalon.framework.thread.ThreadSafe;
28 import org.apache.commons.httpclient.HttpURL;
29 import org.apache.commons.httpclient.HttpsURL;
30 import org.apache.excalibur.source.Source;
31 import org.apache.excalibur.source.SourceException;
32 import org.apache.excalibur.source.SourceFactory;
33
34 /**
35  * A factory for WebDAV sources
36  *
37  * @version $Id: WebDAVSourceFactory.java 30932 2004-07-29 17:35:38Z vgritsenko $
38 */

39 public class WebDAVSourceFactory extends AbstractLogEnabled
40 implements SourceFactory, Configurable, ThreadSafe {
41
42     private String JavaDoc protocol;
43     private boolean secure;
44     
45     /**
46      * Read the scheme name.
47      */

48     public void configure(Configuration configuration) throws ConfigurationException {
49         this.protocol = configuration.getAttribute("name");
50         
51         // parse parameters
52
Parameters parameters = Parameters.fromConfiguration(configuration);
53         this.secure = parameters.getParameterAsBoolean("secure", false);
54     }
55     
56     /**
57      * Get a <code>Source</code> object.
58      * @param parameters This is optional.
59      */

60     public Source getSource(String JavaDoc location, Map JavaDoc parameters)
61         throws MalformedURLException JavaDoc, IOException JavaDoc, SourceException {
62         
63         if (this.getLogger().isDebugEnabled()) {
64             this.getLogger().debug("Creating source object for " + location);
65         }
66         
67         int index = location.indexOf(':');
68         if (index != -1) {
69             location = location.substring(index+3);
70         }
71         
72         HttpURL url;
73         if (this.secure) {
74             url = new HttpsURL("https://" + location);
75         } else {
76             url = new HttpURL("http://" + location);
77         }
78         
79         return WebDAVSource.newWebDAVSource(url, this.protocol, getLogger());
80     }
81
82     public void release(Source source) {
83         // do nothing
84
}
85 }
86
Popular Tags