Java Path to URL getUrl(String pluginId, String relativePath)

Here you can find the source of getUrl(String pluginId, String relativePath)

Description

Return an URL for the file located within the installation directory of the plug-in that has the given identifier that has the given relative path.

License

Open Source License

Parameter

Parameter Description
pluginId the identifier for the plug-in
relativePath the relative path of the file within the installation directory

Return

the URL for the specified file

Declaration

public static URL getUrl(String pluginId, String relativePath) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 Google, Inc.//from ww  w  .j  a  va2 s  .c  om
 * 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:
 *    Google, Inc. - initial API and implementation
 *******************************************************************************/

import java.net.URL;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.Bundle;

public class Main {
    /**
     * Return an URL for the file located within the installation directory of the plug-in that has
     * the given identifier that has the given relative path.
     * 
     * @param pluginId
     *          the identifier for the plug-in
     * @param relativePath
     *          the relative path of the file within the installation directory
     * 
     * @return the URL for the specified file
     */
    public static URL getUrl(String pluginId, String relativePath) {
        Bundle bundle;
        if (pluginId == null || relativePath == null) {
            return null;
        }
        bundle = Platform.getBundle(pluginId);
        if (bundle != null) {
            return bundle.getEntry(relativePath);
        }
        return null;
    }

    /**
     * Return an URL for the file located within the installation directory of the given plug-in that
     * has the given relative path.
     * 
     * @param pluginId
     *          the identifier for the plug-in
     * @param relativePath
     *          the relative path of the file within the installation directory
     * 
     * @return the URL for the specified file
     */
    public static URL getUrl(Plugin plugin, String relativePath) {
        if (plugin == null || relativePath == null) {
            return null;
        }
        return plugin.getBundle().getEntry(relativePath);
    }
}

Related

  1. getUrl(String inPath)
  2. getUrl(String ip, String port, String servicePath, String serviceName, String... args)
  3. getURL(String path)
  4. getURL(String path)
  5. getURL(String path, URL context)
  6. getURL(String schema, String host, String path)
  7. getUrl(URL base, String path)
  8. getUrlForLocalPath(String path)
  9. getURLFromClassPath(String source)