KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.core.runtime.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.adaptor.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     public URL JavaDoc convertToFileURL(URL JavaDoc url) throws IOException JavaDoc {
28         //TODO should close connection at all times
29
URLConnection JavaDoc connection = url.openConnection();
30         if (connection instanceof BundleURLConnection) {
31             return ((BundleURLConnection) connection).getFileURL();
32         } else {
33             return url;
34         }
35     }
36
37     public URL JavaDoc convertToLocalURL(URL JavaDoc url) throws IOException JavaDoc {
38         //TODO should close connection at all times
39
URLConnection JavaDoc connection = url.openConnection();
40         if (connection instanceof BundleURLConnection) {
41             return ((BundleURLConnection) connection).getLocalURL();
42         } else {
43             return url;
44         }
45     }
46 }
Popular Tags