Skip to main content



      Home
Home » Eclipse Projects » Equinox » Resource Access in Bundles
Resource Access in Bundles [message #76003] Wed, 01 November 2006 10:57 Go to next message
Eclipse UserFriend
Originally posted by: user.domain.invalid

Hi,

I have a bundle which includes several resources files, e.g. *.csv files.
How can I access these files from within my bundle?

I tried:

Url u = myBundle.getEntry("name.csv");

But the given url has the form:
bundleentry://32/name.csv

32 is the bundle id.
But how can I access to the file with such an url?

Best regards,
Sabine
Re: Resource Access in Bundles [message #76051 is a reply to message #76003] Wed, 01 November 2006 11:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: boon296.yahoo.de

Hi,

Bundle bundle = Platform.getBundle(ID);
URL url = bundle.getEntry(path);
URL realUrl = Platform.resolve(url);

This should transform your URL.

But I've got a question, too.
If I access Platform.getBundle(ID) nothing happens.
The program stops (don't terminate), but there is no exception and noch
continue.

Does anyone know what I can do?

Thanks.
Re: Resource Access in Bundles [message #76081 is a reply to message #76003] Wed, 01 November 2006 12:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jeff_mcaffer.REMOVE.ca.ibm.com

Classloader.getResource() works as always.

as for the pattern you tried, you get back a URL. use URL.openStream()
to get the contents.

If you realy must have a file URL then you can try
URLConverter.toFileURL(). This surfaces either as an OSGi service or as
a static method on FileLocator. resolving the URL will work some of
the time but really depends on the nature of the original underlying URL
being resolved.

Jeff

Sabine Wagner wrote:
> Hi,
>
> I have a bundle which includes several resources files, e.g. *.csv files.
> How can I access these files from within my bundle?
>
> I tried:
>
> Url u = myBundle.getEntry("name.csv");
>
> But the given url has the form:
> bundleentry://32/name.csv
>
> 32 is the bundle id.
> But how can I access to the file with such an url?
>
> Best regards,
> Sabine
>
Re: Resource Access in Bundles [message #76096 is a reply to message #76051] Wed, 01 November 2006 12:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: user.domain.invalid

Hi Ronny,

I can`t use "Platform" because the bundle is running in equinox.
Platform just work for Eclipse plugins not for equinox bundles.

That's why I can't use
Platform.resolve(url);
:(

Does anybody knows an equivalent for equinox?

Best regards,
Sabine





Ronny F schrieb:

> Hi,
>
> Bundle bundle = Platform.getBundle(ID);
> URL url = bundle.getEntry(path);
> URL realUrl = Platform.resolve(url);
>
> This should transform your URL.
>
> But I've got a question, too.
> If I access Platform.getBundle(ID) nothing happens.
> The program stops (don't terminate), but there is no exception and noch
> continue.
>
> Does anyone know what I can do?
>
> Thanks.
>
>
Re: Resource Access in Bundles [message #76186 is a reply to message #76051] Wed, 01 November 2006 15:24 Go to previous messageGo to next message
Eclipse UserFriend
Is the method hung in Platform.getBundle(ID)? If that is the case then
it sounds like a deadlock of some kind. If you can reproduce then
please open a bug report against Platform->Runtime. It would be useful
to attach a Thread dump and attach a testcase we can use to reproduce.

That said, I do not see any reason that method should hang.

Tom

Ronny F wrote:
> If I access Platform.getBundle(ID) nothing happens.
> The program stops (don't terminate), but there is no exception and noch
> continue.
>
> Does anyone know what I can do?
>
> Thanks.
>
>
Re: Resource Access in Bundles [message #76202 is a reply to message #76096] Thu, 02 November 2006 02:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: boon296.yahoo.de

Hi,

how do you get your bundle for myBundle.getEntry("name.csv"); without
platform?

Thank you.
Ronny

"Sabine Wagner" <user@domain.invalid> schrieb im Newsbeitrag
news:eiak7u$n5r$1@utils.eclipse.org...
> Hi Ronny,
>
> I can`t use "Platform" because the bundle is running in equinox.
> Platform just work for Eclipse plugins not for equinox bundles.
>
> That's why I can't use
> Platform.resolve(url);
> :(
>
> Does anybody knows an equivalent for equinox?
>
> Best regards,
> Sabine
>
>
>
>
>
> Ronny F schrieb:
>
>> Hi,
>>
>> Bundle bundle = Platform.getBundle(ID);
>> URL url = bundle.getEntry(path);
>> URL realUrl = Platform.resolve(url);
>>
>> This should transform your URL.
>>
>> But I've got a question, too.
>> If I access Platform.getBundle(ID) nothing happens.
>> The program stops (don't terminate), but there is no exception and noch
>> continue.
>>
>> Does anyone know what I can do?
>>
>> Thanks.
>
Re: Resource Access in Bundles [message #76218 is a reply to message #76186] Thu, 02 November 2006 02:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: boon296.yahoo.de

Hi,

yes, I may reproduce it any time. But how do I open a bug report?
I noticed, that this problem occurs on any method of the platform class.
My plugin is working fine, I only inserted these line to test the platform:
Platform.getInstallLocation();
If I debug the program at this line, the debugger holds there. Then I click
"step into" an nothing happens. All debugging buttons went gray and the
program hangs.

best regards,
Ronny

"Tom Watson" <tjwatson@us.ibm.com> schrieb im Newsbeitrag
news:eiavqa$5m4$1@utils.eclipse.org...
> Is the method hung in Platform.getBundle(ID)? If that is the case then it
> sounds like a deadlock of some kind. If you can reproduce then please
> open a bug report against Platform->Runtime. It would be useful to attach
> a Thread dump and attach a testcase we can use to reproduce.
>
> That said, I do not see any reason that method should hang.
>
> Tom
>
> Ronny F wrote:
>> If I access Platform.getBundle(ID) nothing happens.
>> The program stops (don't terminate), but there is no exception and noch
>> continue.
>>
>> Does anyone know what I can do?
>>
>> Thanks.
Re: Resource Access in Bundles [message #76346 is a reply to message #76202] Fri, 03 November 2006 16:01 Go to previous messageGo to next message
Eclipse UserFriend
Ronny F wrote:
> Hi,
>
> how do you get your bundle for myBundle.getEntry("name.csv"); without
> platform?
>
> Thank you.
> Ronny
>

The BundleContext has getBundle methods that allow you to get a Bundle
object.

But I'm still confused by the original question in this thread.

Url u = myBundle.getEntry("name.csv");

gives url has the form:
bundleentry://32/name.csv

Sabine, can you explain why this URL does not work for you. Do you
really need it to be a file: URL? If so the you will need to look for a
URLConverter service that has a protocol=bundleentry service property.
Then you can call the URLConverter.toFileURL method.

Tom
Re: Resource Access in Bundles [message #78486 is a reply to message #76346] Tue, 05 December 2006 10:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: caomin2005.gmail.com

Hi, Tom,

If url bundleentry:://32/name.csv is not converted, can it be used to open
that file directly ?

Thanks,
Michael Cao

"Tom Watson" <tjwatson@us.ibm.com> wrote in message
news:eigao0$uac$1@utils.eclipse.org...
> Ronny F wrote:
>> Hi,
>>
>> how do you get your bundle for myBundle.getEntry("name.csv"); without
>> platform?
>>
>> Thank you.
>> Ronny
>>
>
> The BundleContext has getBundle methods that allow you to get a Bundle
> object.
>
> But I'm still confused by the original question in this thread.
>
> Url u = myBundle.getEntry("name.csv");
>
> gives url has the form:
> bundleentry://32/name.csv
>
> Sabine, can you explain why this URL does not work for you. Do you really
> need it to be a file: URL? If so the you will need to look for a
> URLConverter service that has a protocol=bundleentry service property.
> Then you can call the URLConverter.toFileURL method.
>
> Tom
Re: Resource Access in Bundles [message #78501 is a reply to message #78486] Tue, 05 December 2006 12:42 Go to previous messageGo to next message
Eclipse UserFriend
Michael, I when through this once myself. The bundle apparatus wants to
prevent you from getting the files, I suppose because the designers
viewed "files" as concrete bits on a disk drive. So you can only get
stuff thru a different abstraction, a combination of Java streams, Web
URIs, and Eclipse Paths. This code may help you find more info, esp on
FileLocator and getEntryPaths; it serves content or directories
depending on the in coming url:

public Response openPluginStream(String uri) throws IOException {
Bundle bundle = FireclipsePlugin.getInstance().getBundle();
IPath inPlugin = new Path(uri);
if (!inPlugin.hasTrailingSeparator() && !uri.equals("/")) {
try {
return new Response(HTTP_OK, getMIME(uri), FileLocator
.openStream(bundle, inPlugin, false));
} catch (IOException e) {
// IOException if the given path cannot be found in this plug-in
// Fall through and try as dir
uri = uri + "/";
}
} // else ends in "/"
Enumeration e = bundle.getEntryPaths(uri);
if (e == null)
throw new IOException("Bundle from plugin "
+ FireclipsePlugin.PLUGIN_ID
+ " has no entry paths for uri=" + uri);
String title = "Contents of " + FireclipsePlugin.PLUGIN_ID;
StringBuffer buf = new StringBuffer("<html><head><title>" + title
+ "</title><BASE href=\"" + this.getPluginURL()
+ "\"></head><body><h1>" + title + "</h1>\n");
while (e.hasMoreElements()) {
String path = e.nextElement().toString();
buf.append("<a href=\"" + path.substring(1) + "\">"
+ path.substring(1) + "</a><br>\n");
}
buf.append("</body></html>\n");
return new Response(HTTP_OK, "text/html", new StringBufferInputStream(
buf.toString()));
}




michael cao wrote:
> Hi, Tom,
>
> If url bundleentry:://32/name.csv is not converted, can it be used to open
> that file directly ?
>
> Thanks,
> Michael Cao
>
> "Tom Watson" <tjwatson@us.ibm.com> wrote in message
> news:eigao0$uac$1@utils.eclipse.org...
>
>>Ronny F wrote:
>>
>>>Hi,
>>>
>>>how do you get your bundle for myBundle.getEntry("name.csv"); without
>>>platform?
>>>
>>>Thank you.
>>>Ronny
>>>
>>
>>The BundleContext has getBundle methods that allow you to get a Bundle
>>object.
>>
>>But I'm still confused by the original question in this thread.
>>
>>Url u = myBundle.getEntry("name.csv");
>>
>>gives url has the form:
>>bundleentry://32/name.csv
>>
>>Sabine, can you explain why this URL does not work for you. Do you really
>>need it to be a file: URL? If so the you will need to look for a
>>URLConverter service that has a protocol=bundleentry service property.
>>Then you can call the URLConverter.toFileURL method.
>>
>>Tom
>
>
>
Re: Resource Access in Bundles [message #78610 is a reply to message #78486] Wed, 06 December 2006 22:46 Go to previous message
Eclipse UserFriend
Originally posted by: jeff_mcaffer.REMOVE.ca.ibm.com

I think there is still some confusion here. can someone post a code
pattern that is not working for them? You can indeed call
getEntry("name.csv").openStream() and read the contents. So what is the
case for which this does not work?

Jeff

michael cao wrote:
> Hi, Tom,
>
> If url bundleentry:://32/name.csv is not converted, can it be used to open
> that file directly ?
>
> Thanks,
> Michael Cao
>
> "Tom Watson" <tjwatson@us.ibm.com> wrote in message
> news:eigao0$uac$1@utils.eclipse.org...
>> Ronny F wrote:
>>> Hi,
>>>
>>> how do you get your bundle for myBundle.getEntry("name.csv"); without
>>> platform?
>>>
>>> Thank you.
>>> Ronny
>>>
>> The BundleContext has getBundle methods that allow you to get a Bundle
>> object.
>>
>> But I'm still confused by the original question in this thread.
>>
>> Url u = myBundle.getEntry("name.csv");
>>
>> gives url has the form:
>> bundleentry://32/name.csv
>>
>> Sabine, can you explain why this URL does not work for you. Do you really
>> need it to be a file: URL? If so the you will need to look for a
>> URLConverter service that has a protocol=bundleentry service property.
>> Then you can call the URLConverter.toFileURL method.
>>
>> Tom
>
>
Previous Topic:bundle autoloading 2nd try
Next Topic:help with access restriction on org.eclipse.osgi
Goto Forum:
  


Current Time: Fri May 09 19:28:09 EDT 2025

Powered by FUDForum. Page generated in 0.04679 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top