Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 27b6c293096fc102d55149d0c26623df6d53472a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*******************************************************************************
 * Copyright (c) 2006, 2015 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.internal.runtime;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import org.eclipse.core.internal.boot.PlatformURLConnection;
import org.eclipse.core.internal.boot.PlatformURLHandler;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.osgi.service.urlconversion.URLConverter;

/**
 * Class which implements the URLConverter service. Manages conversion of a 
 * platform: URL to one with a more well known protocol.
 * 
 * @since 3.2
 */
public class PlatformURLConverter implements URLConverter {

	@Override
	public URL toFileURL(URL url) throws IOException {
		URLConnection connection = url.openConnection();
		if (!(connection instanceof PlatformURLConnection))
			return url;
		URL result = ((PlatformURLConnection) connection).getURLAsLocal();
		// if we have a bundle*: URL we should try to convert it
		if (!result.getProtocol().startsWith(PlatformURLHandler.BUNDLE))
			return result;
		return FileLocator.toFileURL(result);
	}

	@Override
	public URL resolve(URL url) throws IOException {
		URLConnection connection = url.openConnection();
		if (!(connection instanceof PlatformURLConnection))
			return url;
		URL result = ((PlatformURLConnection) connection).getResolvedURL();
		// if we have a bundle*: URL we should try to convert it
		if (!result.getProtocol().startsWith(PlatformURLHandler.BUNDLE))
			return result;
		return FileLocator.resolve(result);
	}
}

Back to the top