Ticket #692 (closed Enhancement: fixed)

Opened 10 years ago

Last modified 10 years ago

Plugin framework: easify access to plugin's own resources

Reported by: jri Owned by: jri
Priority: Minor Milestone: Release 4.4
Component: DeepaMehta Standard Distribution Version: 4.3
Keywords: Cc: dgf, Malte, carolina
Complexity: 2 Area: Application Framework / API
Module: deepamehta-core

Description

A plugin who wants access its own resources should not required to call

dms.getPlugin(itsOwnPluginUri).getResourceAsStream(...)

but should simply call

getResourceAsStream(...)

Change History

comment:1 Changed 10 years ago by jri

  • Status changed from new to accepted

comment:2 Changed 10 years ago by Jörg Richter

Core API change: access static resources (#692).

BREAKING CHANGE

The Core's Plugin interface has changed.

1 renamed Method:

getResourceAsStream() -> getStaticResource()

The method's semantics has also changed in 2 aspects:

  • when no such resource was found an exception is thrown (instead of returning null). This makes errors more obviuos, in particular when streaming a resource to the client. A bad resource name is reported through an exception instead of letting the browser fail silently.
  • the thrown exception is a runtime exception (instead of an IOException), so you're not strictly required to catch it.

1 new Method:

boolean hasStaticResource(String name)

Use this to check if the plugin provides a static resource with the given name. If this method returns true you can be sure that getStaticResource() will not throw an exception.

In preparation of "Plugin framework: easify access to plugin's own resources".

See #692.

comment:3 Changed 10 years ago by Jörg Richter

Core: easify static resource access (#692).

PluginActivator has a new method:

InputStream getStaticResource(String name)

Use this to access a static resource of your plugin.
The argument is the resource name: a "/"-separated path name, relative to the plugin bundle's root directory. It may or may not begin with "/" (it makes no difference).

So, you don't need to call dms.getPlugin(yourPluginUri) anymore.
And you don't need to catch any exception.

See #692.

comment:4 Changed 10 years ago by jri

  • Status changed from accepted to closed
  • Resolution set to fixed

comment:5 Changed 10 years ago by Jörg Richter

Core API change: access static resources (#692).

BREAKING CHANGE

The Core's Plugin interface has changed.

1 renamed Method:

getResourceAsStream() -> getStaticResource()

The method's semantics has also changed in 2 aspects:

  • when no such resource was found an exception is thrown (instead of returning null). This makes errors more obviuos, in particular when streaming a resource to the client. A bad resource name is reported through an exception instead of letting the browser fail silently.
  • the thrown exception is a runtime exception (instead of an IOException), so you're not strictly required to catch it.

1 new Method:

boolean hasStaticResource(String name)

Use this to check if the plugin provides a static resource with the given name. If this method returns true you can be sure that getStaticResource() will not throw an exception.

In preparation of "Plugin framework: easify access to plugin's own resources".

See #692.

comment:6 Changed 10 years ago by Jörg Richter

Core: easify static resource access (#692).

PluginActivator has a new method:

InputStream getStaticResource(String name)

Use this to access a static resource of your plugin.
The argument is the resource name: a "/"-separated path name, relative to the plugin bundle's root directory. It may or may not begin with "/" (it makes no difference).

So, you don't need to call dms.getPlugin(yourPluginUri) anymore.
And you don't need to catch any exception.

See #692.

Note: See TracTickets for help on using tickets.