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; 14 import java.net.URL; 15 import java.net.URLConnection; 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 convertToFileURL(URL url) throws IOException { 28 //TODO should close connection at all times 29 URLConnection connection = url.openConnection(); 30 if (connection instanceof BundleURLConnection) { 31 return ((BundleURLConnection) connection).getFileURL(); 32 } else { 33 return url; 34 } 35 } 36 37 public URL convertToLocalURL(URL url) throws IOException { 38 //TODO should close connection at all times 39 URLConnection connection = url.openConnection(); 40 if (connection instanceof BundleURLConnection) { 41 return ((BundleURLConnection) connection).getLocalURL(); 42 } else { 43 return url; 44 } 45 } 46 }