KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > config > source > HTTPConfigSource


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.config.source;
18
19 import java.io.BufferedInputStream JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.net.URL JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 /**
29  * ConfigSource implementation that gets its data via HTTP.
30  *
31  * @author gavinc
32  */

33 public class HTTPConfigSource extends BaseConfigSource
34 {
35     private static Log logger = LogFactory.getLog(HTTPConfigSource.class);
36    
37     /**
38      * Constructs an HTTP configuration source that uses a single URL
39      *
40      * @param url the url of the file from which to get config
41      *
42      * @see HTTPConfigSource#HTTPConfigSource(List<String>)
43      */

44     public HTTPConfigSource(String JavaDoc url)
45     {
46         this(Collections.singletonList(url));
47     }
48     
49    /**
50     * Constructs an HTTPConfigSource using the list of URLs
51     *
52     * @param source List of URLs to get config from
53     */

54    public HTTPConfigSource(List JavaDoc<String JavaDoc> sourceStrings)
55    {
56       super(sourceStrings);
57    }
58
59    /**
60     * Retrieves an input stream over HTTP for the given URL
61     *
62     * @param sourceString URL to retrieve config data from
63     * @return The input stream
64     */

65    public InputStream JavaDoc getInputStream(String JavaDoc sourceString)
66    {
67       InputStream JavaDoc is = null;
68       
69       try
70       {
71          URL JavaDoc url = new URL JavaDoc(sourceString);
72          is = new BufferedInputStream JavaDoc(url.openStream());
73       }
74       catch (Throwable JavaDoc e)
75       {
76           if (logger.isDebugEnabled())
77           {
78               logger.debug("Failed to obtain input stream to URL: " + sourceString, e);
79           }
80       }
81       
82       return is;
83    }
84 }
85
Popular Tags