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.core;
19:
20: import java.io.File;
21: import java.net.MalformedURLException;
22: import java.net.URL;
23:
24: /**
25: * Resolve an file or url relatively to its context.
26: */
27: public abstract class RelativeUrlResolver {
28:
29: /**
30: * Resolve the url in the context of context.
31: * @param context The URL of the ressource containing the reference url
32: * @param url a relative or absolution url string
33: * @throws MalformedURLException
34: */
35: public abstract URL getURL(URL context, String url)
36: throws MalformedURLException;
37:
38: /**
39: * Relsovle file or url path relatively to a context. file is considered first.
40: * If file is not defined, url will be considered.
41: * @param context The URL of the ressource containing the reference file or url
42: * @param file a relative or absolute path
43: * @param url a relative or absolution url string
44: * @return the resulting url or null if faile and url are null.
45: * @throws MalformedURLException
46: */
47: public URL getURL(URL context, String file, String url)
48: throws MalformedURLException {
49: if (file != null) {
50: File f = new File(file);
51: if (f.isAbsolute()) {
52: return f.toURL();
53: } else {
54: return getURL(context, file);
55: }
56: } else if (url != null) {
57: return getURL(context, url);
58: } else {
59: return null;
60: }
61: }
62: }
|