How to extend Notes 8: dynamic extensions using Java

I get so many question on how to extend Notes 8 that I finally decided to create a series of blog posts on how to do it. All the posts in the series may be found under the extending_notes8 tag. In all of the examples I assume a working knowledge of Eclipse and Java programming and how to work with extension points.

As I briefly mentioned in my last post (“How to extend Notes 8: capture group LiveText recognizers with a Java action“) it’s possible to create new extensions to Lotus Notes using Java and hence inject functionality into the client dynamically. It’s very cool functionality and it allows you to inject anything from content types and recognizers to sidebar panels. I’ve used this a lot previously and also demoed it in my “How dynamic are your Notes sidebar plugins?” demo. Watch the Flash video and see how you can make sidebar panels come and go on demand.

Now on to the code…

The trick to dynamic extensions is to inject extensions into the Extension Registry at runtime. The Extension Registry is where Eclipse reads the plugin contributions from plugin.xml files into at startup. If we inject an extension, and the receiving plugins are set up to handle dynamically adding extensions you are golden. Let me show you have to use the Extension Registry.

final String extensionXml = ...;
final IExtensionRegistry reg = Platform.getExtensionRegistry();
InputStream ins = new ByteArrayInputStream(extensionXml.getBytes());
Bundle bundle = Activator.getDefault().getBundle();
IContributor contr = ContributorFactoryOSGi.createContributor(bundle);
reg.addContribution(ins, contr, false, null, null, null);

The code does the following:

  1. Defines the extension XML to add (more on this later).
  2. Gets the extension registry from the platform.
  3. Reads the extension XML into an input stream.
  4. Retrieves the bundle.
  5. Creates a new contributor that is the object that makes the contribution to the extension registry.
  6. Adds the contribution to the registry.

So what is the extension XML mentioned above?

The extension XML is the XML that defines the extension you’re adding. It’s actually any piece of XML you would stick in your plugin.xml file either manually or using the UI editor. An example could be a custom recognizer and content type as shown below as a snippet from Java.

final String extensionXml = "<?xml version="1.0" encoding="utf-8" ?>" +
"<?eclipse version="3.2"?>" +
"<plugin>" +
"<extension id="DCR.ExampleRecognizer.%s"
   point="com.ibm.rcp.annotation.regex.regexTypes">" +
"<regexTypes contentTypeId="DCCT.ExampleContentType.%s"
   id="DCR.ExampleRecognizer.%s" match="([A-Z]{4})-(\d{4})"
   name="Example Recognizer">" +
"<group contentTypePropertyId="pn" number="2"/>" +
"<group contentTypePropertyId="pf" number="1"/>" +
"<group contentTypePropertyId="contents" number="0"/>" +
"</regexTypes>" +
"</extension>" +
"<extension id="DCCT.ExampleContentType.%s"
   point="com.ibm.rcp.content.contentTypes">" +
"<contentSet>" +
"<type category="Recognized Content"
   id="DCCT.ExampleContentType.%s"
   name="Example Content Type">" +
"<property description="Entire Contents" id="contents"/>" +
"<property description="Product Family" id="pf"/>" +
"<property description="Part Number" id="pn"/>" +
"</type>" +
"</contentSet>" +
"</extension>" +
"</plugin>";

That’s how you do it. Tomorrow I’ll show how to combine it with our custom recognizer and content type to inject it dynamically into the LiveText system in Lotus Notes. Stay tuned…

9 thoughts on “How to extend Notes 8: dynamic extensions using Java”

  1. Hi Mikkel,

    Fantastic series of article on live text and widgets. If you could provide a demo nsf, it will be very helpful for people like me who are new to Notes 8.5.1.

    Thanks a lot  for your kind contribution.

    Regards,

    Bernd

     

     

    Like

  2. Hi Mikkel,

    I have been following your series on LiveText and recognizers, and I have implemented a recognizer that looks for phone numbers in mails. It works great for "internal" mails. All phone numbers are found. But for internet mails I receive, the recognizer finds nothing. Is this just how it works or is there something wrong?

    Regards,

    Torben

    Like

  3. Hi Torben,

    LiveText currently only works on NotesRichText. External eMails arrive as MIME and are most likely displayed using the embedded browser (that’s a default setting). You have to disable that in the preferences, so Notes converts them to RichText. The price you pay: Notes “infamous” rendering engine.

    Like

  4. Hi Stephan. <span class=”unauthenticated” id=”comment1288094023578.author”>Thank you, that did the trick 🙂 Do you know if there is any plans to make it work also when rendering through the browser?

    Regards,

    Torben

    </span>

    Like

  5. It is on the list of potential future enhancements (I’ve seen code in the lab) which also means LiveText comes to Sametime and others. However it is not confirmed when (and could be postponed indefinitely)

    Like

  6. The regular expression you inject could be thought of as a way of writing your recognizer in Java. There’s no way currently – that I know of – to write a class that is called to perform recognition at runtime.

    Like

Comments are closed.