2

I'm having difficulties finding the proper approach to provide css and csjs resources in my custom xpages Library. I was not able to find any good info on how to package such resources with my osgi plugin.

I took a look at the extlib implementation, but couldn't really make much of what is happening in the ResourceHandler parts (and if those are even related to what I need, actually). So what steps are necessary if one wanted to deploy, say, a dojo dijit within the library?

  • 3
    How about the Bootstrap4XPages implementation (https://github.com/markleusink/Bootstrap4XPages-1)? Maybe you can figure that one out: it's a lot smaller than the ExtLib and one of its purposes is to provide css/ csjs. This blogpost (http://www.gregorbyte.com/2014/07/bootswatches-from-osgi-fragment.html) has some good info too. – Mark Leusink Jul 10 '14 at 11:55
  • Hi Mark, thanks for nudging me twards the bootstrap4xpages project. I already took a look at it before, but obviously not close enough. I more or less -copied- extracted the approach from there and with some fiddling around it finally worked! I added the answer below and hope I didn't forget anything. – Gernot Hummer Jul 11 '14 at 05:35

1 Answers1

1

What did it for me: Create an OSGi Plugin Activator; in the constructor, load a custom ExtLibLoaderExtension that basically sits on top of the Extlib resource handling. To use that, the resources need to go into a subfolder of "/resources/web/extlib" with a name that is specified by this very ExtLibLoaderExtension.

The Activator:

public class MyCustomActivator extends Plugin {

    public static MyCustomActivator instance;

    public MyCustomActivator() {
        instance = this;

        ExtLibLoaderExtension.getExtensions().add(new MyCustomLoader());
    }
}

The ExtLibLoaderExtension:

public class MyCustomLoader extends ExtLibLoaderExtension {

    public MyCustomLoader(){

    }

    @Override
    public Bundle getOSGiBundle() {
        return MyCustomActivator.instance.getBundle();
    }

    @Override
    public URL getResourceURL(HttpServletRequest request, String name) {
        if(name.startsWith("[put subfolder name here]")) {
            String path = ExtlibResourceProvider.BUNDLE_RES_PATH_EXTLIB+name;
            return ExtLibUtil.getResourceURL(
                MyCustomActivator.instance.getBundle(), path);
         }
        return null;
    }

}

Make sure your resources folder is included in the Build section of your plugin.xml. On the Overview Tab, provide the Activator class in the section General Information on the top left. After all this, you can access your resources from a Webbrowser by using the /xsp/.ibmxspres/.extlib/[put subfolder name here]/ junction once you've deployed the updateSite and restarted the http task.