Java Code Examples for org.osgi.framework.Bundle#getEntry()

The following examples show how to use org.osgi.framework.Bundle#getEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractDocumentationHover.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads the hover style sheet.
 */
protected static String loadStyleSheet(String cssPath)
{
	Bundle bundle = Platform.getBundle(UIEplPlugin.PLUGIN_ID);
	if (bundle == null)
	{
		return StringUtil.EMPTY;
	}
	URL styleSheetURL = bundle.getEntry(cssPath);
	if (styleSheetURL != null)
	{
		try
		{
			return IOUtil.read(styleSheetURL.openStream());
		}
		catch (IOException ex)
		{
			IdeLog.logError(UIEplPlugin.getDefault(), "Documentation hover - Error loading the style-sheet", ex); //$NON-NLS-1$
			return StringUtil.EMPTY;
		}
	}
	return StringUtil.EMPTY;
}
 
Example 2
Source File: OSGIServiceLoader.java    From incubator-tamaya with Apache License 2.0 6 votes vote down vote up
private void checkAndLoadBundle(Bundle bundle) {
    if (bundle.getEntry(META_INF_SERVICES) == null) {
        return;
    }
    synchronized (resourceBundles) {
        resourceBundles.add(bundle);
        LOG.info("Registered ServiceLoader bundle: " + bundle.getSymbolicName());
    }
    Enumeration<String> entryPaths = bundle.getEntryPaths(META_INF_SERVICES);
    while (entryPaths.hasMoreElements()) {
        String entryPath = entryPaths.nextElement();
        if (!entryPath.endsWith("/")) {
            processEntryPath(bundle, entryPath);
        }
    }
}
 
Example 3
Source File: DBConfig.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public DBConfig(URL dbconfig, MetaData metaData){
	this.metaData = metaData;
	try {
		SAXReader reader = new SAXReader();
		Document doc = reader.read(dbconfig);
		root = doc.getRootElement();
		
		Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
		URL defaultUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
		SAXReader defaultReader = new SAXReader();
		Document defaultDoc = defaultReader.read(defaultUrl);
		defaultRoot = defaultDoc.getRootElement();
	} catch (DocumentException e) {
		logger.warn("", e);
	}
}
 
Example 4
Source File: FontMappingManagerFactory.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected URL getConfigURL( String configName )
{
	// try to load the format specific configuration
	String fileName = configName + ".xml";
	Bundle bundle = Platform
			.getBundle( "org.eclipse.birt.report.engine.fonts" ); //$NON-NLS-1$
	if ( bundle != null )
	{
		return bundle.getEntry( fileName );
	}
	return getClass( ).getClassLoader( ).getResource( fileName );
}
 
Example 5
Source File: BundleInformation.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public BundleInformation ( final Bundle bundle )
{
    this.bundle = bundle;
    this.bundleRevision = bundle.adapt ( BundleRevision.class );

    this.aboutHtml = bundle.getEntry ( "about.html" );
    this.licenseTxt = bundle.getEntry ( "META-INF/LICENSE.txt" );
    this.noticeTxt = bundle.getEntry ( "META-INF/NOTICE.txt" );

    this.licenses = LicenseInformation.parse ( bundle.getHeaders ().get ( Constants.BUNDLE_LICENSE ) );
}
 
Example 6
Source File: OperateSystemDBImpl.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public OperateSystemDBImpl() {
	metaData = new MetaDataImpl();
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
	metaData.setDbType(dbConfig.getDefaultType());
}
 
Example 7
Source File: TestFileCopier.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void copyFolderFromBundleToFolder(Bundle bundle, String sourcePath, String targetPath) {
	try {
		URL folder = bundle.getEntry(sourcePath);
		File file = new File(FileLocator.resolve(folder).toURI());
		if (file.exists() && file.isDirectory()) {
			for (File f : file.listFiles()) {
				copyFileFromBundleToFolder(bundle, new Path(sourcePath).append(f.getName()), new Path(targetPath));
			}
		}
	} catch (URISyntaxException | IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 8
Source File: PluginUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 根据相对路径获取绝对路径
 * @param relativePath
 * @return ;
 */
public static String getAbsolutePath(String relativePath) {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL defaultUrl = buddle.getEntry(relativePath);
	String imagePath = relativePath;
	try {
		imagePath = new File(FileLocator.toFileURL(defaultUrl).getPath()).getAbsolutePath();
	} catch (IOException e) {
		LOGGER.error(Messages.getString("util.PluginUtil.logger1"), e);
		e.printStackTrace();
	}
	return imagePath;
}
 
Example 9
Source File: EclipsePlatform.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * setup logger used for tracing.
 * 
 * It reads ".options" in the plugin folder to get all the tracing items,
 * call the .getDebugOptions() to get the option values and setup the logger
 * use the values.
 * 
 * @param pluginId
 *            plugin id
 */
public void initializeTracing( String pluginId )
{

	Bundle bundle = org.eclipse.core.runtime.Platform.getBundle( pluginId );
	String debugFlag = pluginId + "/debug";
	if ( bundle != null )
	{

		try
		{
			URL optionUrl = bundle.getEntry( ".options" );
			InputStream in = optionUrl.openStream( );
			if ( in != null )
			{
				Properties options = new Properties( );
				options.load( in );
				Iterator entryIter = options.entrySet( ).iterator( );
				while ( entryIter.hasNext( ) )
				{
					Map.Entry entry = (Map.Entry) entryIter.next( );
					String option = (String) entry.getKey( );
					if ( !debugFlag.equals( option ) )
					{
						String value = org.eclipse.core.runtime.Platform
								.getDebugOption( option );
						setupLogger( option, value );
					}
				}
			}
		}
		catch ( Exception ex )
		{
			logger.log( Level.WARNING, ex.getMessage( ), ex );
		}
	}
}
 
Example 10
Source File: OperateDBImpl.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public OperateDBImpl() {
	metaData = new MetaDataImpl();
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
	metaData.setServerName(dbConfig.getDefaultServer());
	metaData.setPort(dbConfig.getDefaultPort());
	metaData.setDbType(dbConfig.getDefaultType());
}
 
Example 11
Source File: OperateSystemDBImpl.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public OperateSystemDBImpl(){
	metaData = new MetaDataImpl();
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
	metaData.setServerName(dbConfig.getDefaultServer());
	metaData.setPort(dbConfig.getDefaultPort());
	metaData.setDbType(dbConfig.getDefaultType());
}
 
Example 12
Source File: OperateDBImpl.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public OperateDBImpl() {
	metaData = new MetaDataImpl();
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
	metaData.setServerName(dbConfig.getDefaultServer());
	metaData.setPort(dbConfig.getDefaultPort());
	metaData.setDbType(dbConfig.getDefaultType());
}
 
Example 13
Source File: TMDatabaseImpl.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 构造函数
 */
public TMDatabaseImpl() {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
}
 
Example 14
Source File: BundleResourceProvider.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public URL getResource ( final String name )
{
    if ( !name.startsWith ( "/bundle/" ) )
    {
        return null;
    }

    final String toks[] = name.split ( "/", 4 );

    if ( toks.length != 4 )
    {
        logger.debug ( "Invalid format: {}", new Object[] { toks } );
        return null;
    }

    if ( !toks[1].equals ( "bundle" ) )
    {
        return null;
    }

    final long bundleId;
    try
    {
        bundleId = Long.parseLong ( toks[2] );
    }
    catch ( final NumberFormatException e )
    {
        logger.debug ( "Failed to parse bundle id", e );
        return null;
    }

    final Bundle bundle = findBundle ( bundleId );
    logger.trace ( "Target bundle: {}", bundle );
    if ( bundle == null )
    {
        return null;
    }

    final URL result = bundle.getEntry ( toks[3] );
    logger.trace ( "Resource entry ({}): {}", toks[3], result );
    if ( result == null )
    {
        return null;
    }

    logger.debug ( "Requesting resource: {}", result );

    return result;
}
 
Example 15
Source File: AuthHttpContext.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public URL getResource(String name) {
    final String normalizedName = normalizeResourcePath(rootPath + (name.startsWith("/") ? "" : "/") + name).trim();

    log.debug(String.format("Searching bundle " + bundle + " for resource [%s], normalized to [%s]",
            name, normalizedName));

    URL url = resourceCache.get(normalizedName);

    if (url == null && !normalizedName.isEmpty()) {
        url = bundle.getEntry(normalizedName);
        if (url == null) {
            log.debug("getEntry failed, trying with /META-INF/resources/ in bundle class space");
            // Search attached bundles for web-fragments
            Set<Bundle> bundlesInClassSpace = getBundlesInClassSpace(bundle, new HashSet<>());
            for (Bundle bundleInClassSpace : bundlesInClassSpace) {
                url = bundleInClassSpace.getEntry("/META-INF/resources/" + normalizedName);
                if (url != null) {
                    break;
                }
            }
        }
        // obviously still not found might be available from a attached bundle resource
        if (url == null) {
            log.debug("getEntry failed, fallback to getResource");
            url = bundle.getResource(normalizedName);
        }
        if (url == null) {
            log.debug("getResource failed, fallback to system bundle getResource");
            url = bundle.getClass().getClassLoader().getResource(normalizedName);
        }
        if (url == null) {
            url = NO_URL;
        }
        resourceCache.putIfAbsent(normalizedName, url);
    }

    if (url != null && url != NO_URL) {
        log.debug(String.format("Resource found as url [%s]", url));
    } else {
        log.debug("Resource not found");
        url = null;
    }
    return url;
}
 
Example 16
Source File: OSGIServiceLoader.java    From incubator-tamaya with Apache License 2.0 4 votes vote down vote up
private void processEntryPath(Bundle bundle, String entryPath) {
    try {
        String serviceName = entryPath.substring(META_INF_SERVICES.length());
        if (!serviceName.startsWith("org.apache.tamaya")) {
            // Ignore non Tamaya entries...
            return;
        }
        Class<?> serviceClass = bundle.loadClass(serviceName);
        URL child = bundle.getEntry(entryPath);
        InputStream inStream = child.openStream();
        LOG.info("Loading Services " + serviceClass.getName() + " from bundle...: " + bundle.getSymbolicName());
        try (BufferedReader br = new BufferedReader(new InputStreamReader(inStream, StandardCharsets.UTF_8))) {
            String line = br.readLine();
            while (line != null) {
                String implClassName = getImplClassName(line);
                if (implClassName.length() > 0) {
                    try {
                        // Load the service class
                        LOG.fine("Loading Class " + implClassName + " from bundle...: " + bundle.getSymbolicName());
                        Class<?> implClass = bundle.loadClass(implClassName);
                        if (!serviceClass.isAssignableFrom(implClass)) {
                            LOG.warning("Configured service: " + implClassName + " is not assignable to "
                                    + serviceClass.getName());
                            continue;
                        }
                        LOG.info("Loaded Service Factory (" + serviceName + "): " + implClassName);
                        // Provide service properties
                        Hashtable<String, String> props = new Hashtable<>();
                        props.put(Constants.VERSION_ATTRIBUTE, bundle.getVersion().toString());
                        String vendor = bundle.getHeaders().get(Constants.BUNDLE_VENDOR);
                        props.put(Constants.SERVICE_VENDOR, (vendor != null ? vendor : "anonymous"));
                        // Translate annotated @Priority into a service ranking
                        props.put(Constants.SERVICE_RANKING,
                                String.valueOf(PriorityServiceComparator.getPriority(implClass)));

                        // Register the service factory on behalf of the intercepted bundle
                        JDKUtilServiceFactory factory = new JDKUtilServiceFactory(implClass);
                        BundleContext bundleContext = bundle.getBundleContext();
                        bundleContext.registerService(serviceName, factory, props);
                        LOG.info("Registered Tamaya service class: " + implClassName + "(" + serviceName + ")");
                    } catch (NoClassDefFoundError | Exception err) {
                        LOG.log(Level.SEVERE, "Failed to load service: " + implClassName, err);
                    }
                }
                line = br.readLine();
            }
        }
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Failed to read services from: " + entryPath, e);
    }
}
 
Example 17
Source File: Netigso.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected Enumeration<URL> findResources(Module m, String resName) {
    Bundle b = findBundle(m.getCodeNameBase());
    URL u = b.getEntry(resName);
    return u == null ? Enumerations.<URL>empty() : Enumerations.singleton(u);
}
 
Example 18
Source File: TMDatabaseImpl.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public TMDatabaseImpl() {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
}
 
Example 19
Source File: TMDatabaseImpl.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 构造函数
 */
public TMDatabaseImpl() {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
}
 
Example 20
Source File: TMDatabaseImpl.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 构造函数
 */
public TMDatabaseImpl() {
	Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
	URL fileUrl = buddle.getEntry(Constants.DBCONFIG_PATH);
	dbConfig = new DBConfig(fileUrl);
}