blob: 8e2ebc423d0c9461ce5be6fdc0f9816aafafafce [file] [log] [blame]
package org.eclipse.wst.xsl.jaxp.launching.internal;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
public class Utils
{
public static String getFileLocation(String bundleId, String path) throws CoreException
{
String location = null;
try
{
URL url = FileLocator.find(Platform.getBundle(bundleId), new Path(path), null);
if (url != null)
{
URL fileUrl = FileLocator.toFileURL(url);
File file = new File(fileUrl.getFile());
location = file.getAbsolutePath();
}
}
catch (IOException e)
{
throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, Messages.getString("Utils.0") + path + Messages.getString("Utils.1") + bundleId, e)); //$NON-NLS-1$ //$NON-NLS-2$
}
return location;
}
public static String getPluginLocation(String bundleId) throws CoreException
{
String location = null;
try
{
URL url = new URL("platform:/plugin/"+bundleId);
if (url != null)
{
URL fileUrl = FileLocator.toFileURL(url);
File file = new File(fileUrl.getFile());
location = file.getAbsolutePath();
}
}
catch (IOException e)
{
throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, Messages.getString("Utils.0") + bundleId + Messages.getString("Utils.1") + bundleId, e)); //$NON-NLS-1$ //$NON-NLS-2$
}
return location;
}
}