Skip to content

PluginDevelopment_2.0

kohlhaas edited this page Oct 9, 2015 · 4 revisions

Some hints to get started in 2.0

Dependency Injection

Rapla 2.0 supports the jsr 330 dependency injection way

https://jcp.org/en/jsr/detail?id=330

You can use @inject to specify which services a class needs

    @Inject
    public MyClass(ClientFacade facade)
        this.facade = facade;
    }

injects the ClientFacade into your object.

If you want to use interfaces in injections you can use the org.rapla.inject.DefaultImplementation annotation to provide an implementation.

@DefaultImplementation(of = ClientFacade.class, context = InjectionContext.all)
public class FacadeImpl implements ClientFacade,StorageUpdateListener {
}

Extension Points

look for the extension points in

  • org.rapla.client.extensionpoints
  • org.rapla.server.extensionpoints

you don't need a plugin class anymore to implement an extension. Just add the extension annotiation to your extension class that implements the extension interface.

Exmaple:

in org.rapla.server.servletpages.RaplaStatusPageGenerator

@Extension(provides = RaplaPageExtension.class,id="server")
public class RaplaStatusPageGenerator implements RaplaPageExtension {
    RaplaResources m_i18n;
    @Inject
    public RaplaStatusPageGenerator(RaplaResources i18n) throws RaplaContextException {
        m_i18n = i18n;
    }

    public void generatePage( ServletContext context, HttpServletRequest request, HttpServletResponse response ) throws IOException {
       ... Page generation code here
    }
}

adds a page that is available under http://localhost:8051/rapla?page=server

in org.rapla.server.internal.RaplaStatusEntry

@Extension(provides = HtmlMainMenu.class,id="status")
public class RaplaStatusEntry extends DefaultHTMLMenuEntry implements HtmlMainMenu
{
    @Inject
    public RaplaStatusEntry(RaplaResources i18n)
    {
        super(i18n.getString("server_status"), "rapla?page=server");
    }
}

adds a link on the main page

Internationalization

2.0 doesn't use resources xml's anymore.

Its just the properties files

For the main Resource Bundle the files are located under

src\main\resources\org\rapla\

  • RaplaResources.properties
  • RaplaResources_fr.properties
  • RaplaResources_de.properties ...

to access the properties implement a class providing the I18nBundle Extension

@Extension(provides = I18nBundle.class, id = RaplaResources.ID)
@Singleton
public class RaplaResources extends AbstractBundle {
    public static final String ID = "org.rapla";
    public static final String BUNDLENAME = ID + ".RaplaResources";

    @Inject
    public RaplaResources(BundleManager bundleManager)
    {
      super(BUNDLENAME, bundleManager);
    }
    public String getString(@PropertyKey(resourceBundle = BUNDLENAME) String key)
    {
        return super.getString(key);
    }

    public String getString(@PropertyKey(resourceBundle = BUNDLENAME) String key,Locale locale)
    {
        return super.getString(key, locale);
    }

    public String format(@PropertyKey(resourceBundle = BUNDLENAME) String key, Object... obj)
    {
        return super.format(key, obj);
    }

    // add custom format methods here

    // custom format for the calendarweek
    public String calendarweek(Date startDate) {
        String format = getString("calendarweek.abbreviation");
        int week = DateTools.getWeekInYear(startDate, getLocale());
        String result = format.replace("{0}", "" + week);
        // old format also works
        result = result.replace("{0,date,w}", "" + week);
        return result;
    }

You can use the bundle by just adding RaplaResources in an injected constructor

    @Inject
    public RaplaStatusEntry(RaplaResources i18n)
    {

Clone this wiki locally