KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > runtime > PlatformURLConverter


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.runtime;
12
13 import java.io.IOException JavaDoc;
14 import java.net.URL JavaDoc;
15 import java.net.URLConnection JavaDoc;
16 import org.eclipse.core.internal.boot.PlatformURLConnection;
17 import org.eclipse.core.internal.boot.PlatformURLHandler;
18 import org.eclipse.core.runtime.FileLocator;
19 import org.eclipse.osgi.service.urlconversion.URLConverter;
20
21 /**
22  * Class which implements the URLConverter service. Manages conversion of a
23  * platform: URL to one with a more well known protocol.
24  *
25  * @since 3.2
26  */

27 public class PlatformURLConverter implements URLConverter {
28
29     /* (non-Javadoc)
30      * @see org.eclipse.osgi.service.urlconversion.URLConverter#toFileURL(java.net.URL)
31      */

32     public URL JavaDoc toFileURL(URL JavaDoc url) throws IOException JavaDoc {
33         URLConnection JavaDoc connection = url.openConnection();
34         if (!(connection instanceof PlatformURLConnection))
35             return url;
36         URL JavaDoc result = ((PlatformURLConnection) connection).getURLAsLocal();
37         // if we have a bundle*: URL we should try to convert it
38
if (!result.getProtocol().startsWith(PlatformURLHandler.BUNDLE))
39             return result;
40         return FileLocator.toFileURL(result);
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.osgi.service.urlconversion.URLConverter#resolve(java.net.URL)
45      */

46     public URL JavaDoc resolve(URL JavaDoc url) throws IOException JavaDoc {
47         URLConnection JavaDoc connection = url.openConnection();
48         if (!(connection instanceof PlatformURLConnection))
49             return url;
50         URL JavaDoc result = ((PlatformURLConnection) connection).getResolvedURL();
51         // if we have a bundle*: URL we should try to convert it
52
if (!result.getProtocol().startsWith(PlatformURLHandler.BUNDLE))
53             return result;
54         return FileLocator.resolve(result);
55     }
56 }
57
Popular Tags