X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Futil%2FBundleResourceLoader.java;h=c8fb8a40cdb5c1db652b2c04b9bc0e52ea365d5d;hb=c811008ac91053f068c26f48427617de9bb7b79c;hp=cda00efcdeac88f239ca33f2b933e038fe1efef9;hpb=e299bf6123fb27d14176d2a164a85971be40fa2a;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/util/BundleResourceLoader.java b/org.argeo.cms.ui/src/org/argeo/cms/util/BundleResourceLoader.java index cda00efcd..c8fb8a40c 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/util/BundleResourceLoader.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/util/BundleResourceLoader.java @@ -7,40 +7,20 @@ import java.net.URL; import org.argeo.cms.CmsException; import org.eclipse.rap.rwt.service.ResourceLoader; import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; /** {@link ResourceLoader} implementation wrapping an {@link Bundle}. */ -public class BundleResourceLoader implements ResourceLoader { - private final BundleContext bundleContext; +class BundleResourceLoader implements ResourceLoader { + private final Bundle bundle; - public BundleResourceLoader(BundleContext bundleContext) { - this.bundleContext = bundleContext; + public BundleResourceLoader(Bundle bundle) { + this.bundle = bundle; } @Override - public InputStream getResourceAsStream(String resourceName) - throws IOException { - // TODO deal with other bundles - Bundle bundle = bundleContext.getBundle(); - // String location = - // bundle.getLocation().substring("initial@reference:".length()); - // if (location.startsWith("file:")) { - // Path path = null; - // try { - // path = Paths.get(new URI(location)); - // } catch (URISyntaxException e) { - // e.printStackTrace(); - // } - // if (path != null) { - // Path resourcePath = path.resolve(resourceName); - // if (Files.exists(resourcePath)) - // return Files.newInputStream(resourcePath); - // } - // } + public InputStream getResourceAsStream(String resourceName) throws IOException { URL res = bundle.getResource(resourceName); if (res == null) - throw new CmsException("Resource " + resourceName - + " not found in bundle " + bundle.getSymbolicName()); + throw new CmsException("Resource " + resourceName + " not found in bundle " + bundle.getSymbolicName()); return res.openStream(); }