KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > internal > adaptor > URLConverterImpl


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.runtime.internal.adaptor;
12
13 import java.io.IOException JavaDoc;
14 import java.net.URL JavaDoc;
15 import java.net.URLConnection JavaDoc;
16 import org.eclipse.osgi.framework.internal.core.BundleURLConnection;
17 import org.eclipse.osgi.service.urlconversion.URLConverter;
18
19 /**
20  * The service implementation that allows bundleresource or bundleentry
21  * URLs to be converted to native file URLs on the local file system.
22  *
23  * <p>Internal class.</p>
24  */

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

30     public URL JavaDoc toFileURL(URL JavaDoc url) throws IOException JavaDoc {
31         URLConnection JavaDoc connection = url.openConnection();
32         if (connection instanceof BundleURLConnection)
33             return ((BundleURLConnection) connection).getFileURL();
34         return url;
35     }
36
37     /* (non-Javadoc)
38      * @see org.eclipse.osgi.service.urlconversion.URLConverter#resolve(java.net.URL)
39      */

40     public URL JavaDoc resolve(URL JavaDoc url) throws IOException JavaDoc {
41         URLConnection JavaDoc connection = url.openConnection();
42         if (connection instanceof BundleURLConnection)
43             return ((BundleURLConnection) connection).getLocalURL();
44         return url;
45     }
46 }
47
Popular Tags