01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.util.url;
19:
20: import org.apache.ivy.util.Message;
21:
22: /**
23: *
24: */
25: public final class URLHandlerRegistry {
26: private URLHandlerRegistry() {
27: }
28:
29: private static URLHandler defaultHandler = new BasicURLHandler();
30:
31: public static URLHandler getDefault() {
32: return defaultHandler;
33: }
34:
35: public static void setDefault(URLHandler def) {
36: defaultHandler = def;
37: }
38:
39: /**
40: * This method is used to get appropriate http downloader dependening on Jakarta Commons
41: * HttpClient availability in classpath, or simply use jdk url handling in other cases.
42: *
43: * @return most accurate http downloader
44: */
45: public static URLHandler getHttp() {
46: try {
47: Class.forName("org.apache.commons.httpclient.HttpClient");
48: Class handler = Class
49: .forName("org.apache.ivy.util.url.HttpClientHandler");
50: Message
51: .verbose("jakarta commons httpclient detected: using it for http downloading");
52: return (URLHandler) handler.newInstance();
53: } catch (ClassNotFoundException e) {
54: Message
55: .verbose("jakarta commons httpclient not found: using jdk url handling");
56: return new BasicURLHandler();
57: } catch (NoClassDefFoundError e) {
58: Message
59: .verbose("error occurred while loading jakarta commons httpclient: "
60: + e.getMessage());
61: Message.verbose("Using jdk url handling instead.");
62: return new BasicURLHandler();
63: } catch (InstantiationException e) {
64: Message
65: .verbose("couldn't instantiate HttpClientHandler: using jdk url handling");
66: return new BasicURLHandler();
67: } catch (IllegalAccessException e) {
68: Message
69: .verbose("couldn't instantiate HttpClientHandler: using jdk url handling");
70: return new BasicURLHandler();
71: }
72: }
73:
74: }
|