/* * Copyright (c) 2006 Borland Software Corporation * * 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: * Dmitry Stadnik (Borland) - initial API and implementation */ package org.eclipse.gmf.internal.common; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.util.URI; /** * @author dstadnik */ public class URIUtil { private URIUtil() { } public static IFile getFile(URI uri) { String fileName = uri.toFileString(); if (fileName != null) { return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileName)); } if (uri.toString().startsWith("platform:/resource")) { //$NON-NLS-1$ String path = uri.toString().substring("platform:/resource".length()); //$NON-NLS-1$ IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path)); if (workspaceResource instanceof IFile) { return (IFile) workspaceResource; } } return null; } }