1 package org
.argeo
.cms
.util
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
7 import org
.argeo
.cms
.CmsException
;
8 import org
.eclipse
.rap
.rwt
.service
.ResourceLoader
;
9 import org
.osgi
.framework
.Bundle
;
10 import org
.osgi
.framework
.BundleContext
;
12 /** {@link ResourceLoader} implementation wrapping an {@link Bundle}. */
13 public class BundleResourceLoader
implements ResourceLoader
{
14 private final BundleContext bundleContext
;
16 public BundleResourceLoader(BundleContext bundleContext
) {
17 this.bundleContext
= bundleContext
;
21 public InputStream
getResourceAsStream(String resourceName
)
23 // TODO deal with other bundles
24 Bundle bundle
= bundleContext
.getBundle();
26 // bundle.getLocation().substring("initial@reference:".length());
27 // if (location.startsWith("file:")) {
30 // path = Paths.get(new URI(location));
31 // } catch (URISyntaxException e) {
32 // e.printStackTrace();
34 // if (path != null) {
35 // Path resourcePath = path.resolve(resourceName);
36 // if (Files.exists(resourcePath))
37 // return Files.newInputStream(resourcePath);
40 URL res
= bundle
.getResource(resourceName
);
42 throw new CmsException("Resource " + resourceName
43 + " not found in bundle " + bundle
.getSymbolicName());
44 return res
.openStream();