SnTT: putting text from Notes to an OpenOffice document on Mac and Linux via LotusScript (is anything impossible with Notes?)
Julian Buss, November 5th, 2008 20:20:51
Tags:  Development 
As you may have read here, I'm researching how to automate OpenOffice from Notes via LotusScript on Mac and Linux. On Windows that's no problem because you can use OLE from LotusScript to access OpenOffice features. But on the Mac and Linux, there is no OLE.

But: there is Java to the rescue!

Accessing OpenOffice via the native UNO API from Java is like making holiday in hell, just a little bit worse. But, as I wrote, there is the NOA (Nice Office Access) toolkit which wrapps the OpenOffice API and makes it usable.

And now, with the NOA and some research, I have a working way how to access OpenOffice via LotusScript on Linux and Mac. With that you can for instance set text from Notes to an OpenOffice text document, or you can use OpenOffice to convert documents to PDF, or your can use it to draw charts or whatever.

Here is the basic way:

1.) Download NOA from http://ubion.ion.ag/solutions/004niceofficeaccess?set_language=en (use the Linux version on the Mac, too).

2.) Start your Eclipse, start a new project, include all the JARs from the NOA/lib directory and play with NOA. Try to do some basic stuff like creating a document, saving it, getting bookmarks and setting text to it. This is just to get used to NOA.

3.) In Domino Designer, create a new Java script library (no, not a JavaScript library but a script library containing Java stuff). There, hit the "edit" button and add all the JARs from the NOA package. You don't need the DLL or SO files.

4.) In the same Java script library, write your Java code to do stuff with OpenOffice (for example, set text to a bookmark in a document). For instance, I'm using something like this:
---
import ag.ion.bion.officelayer.application.IOfficeApplication;
import ag.ion.bion.officelayer.application.OfficeApplicationRuntime;
import ag.ion.bion.officelayer.document.IDocument;
import ag.ion.bion.officelayer.document.IDocumentService;
import ag.ion.bion.officelayer.text.ITextDocument;
import java.util.HashMap;

public class YNOOoHelper {
      private static IOfficeApplication officeAplication = null;
      private static IDocumentService documentService null;
      private ITextDocument currentTextDocument = null;


      public YNOOoHelper() {
      }
     
      public void init(String OOoPath) {
              try {
                      HashMap configuration = new HashMap();
                      configuration.put(IOfficeApplication.APPLICATION_HOME_KEY, OOoPath);
                      configuration.put(IOfficeApplication.APPLICATION_TYPE_KEY, IOfficeApplication.LOCAL_APPLICATION);
                      officeAplication = OfficeApplicationRuntime.getApplication(configuration);        
                      officeAplication.setConfiguration(configuration);
                      officeAplication.activate();        
                      documentService = officeAplication.getDocumentService();

              } catch (Exception e) {
                      e.printStackTrace();
              }
      }
     
      public void setDocument(String filePath) {
              try {
                      String s;
                      currentTextDocument = null;
                      IDocument docs[] = documentService.getCurrentDocuments();
                      for (int i = 0; i < docs.length; i++) {
              //                s = docs[i].getPersistenceService().getLocation().toString();
                              s = docs[i].getLocationURL().toString();
                              //System.out.println("found doc "+s);
                              if (s.toLowerCase().contains(filePath.toLowerCase())) {
                                      //System.out.println("!!! found our doc: "+filePath);
                                      currentTextDocument = (ITextDocument)docs[i];
                              }
                      }                        
              } catch (Exception e) {
                      e.printStackTrace();
              }
      }
     
      public void setTextToBookmark(String bookmark, String text) {
              try {
                      if (currentTextDocument == null) {
                              System.out.println("no current text document set.");
                              return;
                      }
                      if (currentTextDocument.getTextService().getBookmarkService().getBookmark(bookmark) != null) {
                              currentTextDocument.getTextService().getBookmarkService().getBookmark(bookmark).setText(text);
                      } else {
                              System.out.println("No bookmark found: "+bookmark);
                      }

              } catch (Exception e) {
                      e.printStackTrace();
              }
      }
}
---

5.) Now you are ready to access that java code from LotusScript. For example, create an agent with some code like this:
----
Uselsx "*javacon"
Use "your java script library"

Dim session As New notesSession
Dim jSession As JavaSession
Dim jClass As JavaClass
Dim jObject As JavaObject
Dim jError As JavaError        
     
Set jSession = New  JAVASESSION
Set jClass = jSession.GetClass("YNOOoHelper")
Set jObject = jClass.CreateObject                
Call jObject.init("/Applications/OpenOffice.org.app/Contents")
Call jObject.setDocument("/Users/julian/Documents/test-Zwei.odt")
Call jObject.setTextToBookmark("test", "mac "+Cstr(Now))
----


So, basically you write your own Java class to provide some simple methods doing some stuff in OpenOffice. Then, via the LS2Java bridge, you use this class. Because the class resides in the same Java script library as the NOA JAR packages, it can use them and access OpenOffice.

This might work with Symphony, too. I did not test that yet.

To be honest, I did not believed that there is a way to automate OpenOffice via Notes on the Mac. On Linux, yes, perhaps, but on the Mac - no way. And yet again I see that "impossible" is an unknown phrase in Notes development :-)
Über diese Seite
Das YouAtNotes Blog ist ein Webtagebuch der Mitarbeiter von YouAtNotes. Hier möchten wir ihnen direkt aus dem Alltag eines Softwarehauses berichten.
Wir freuen uns über Ihre Kommentare und wünschen Ihnen anregende und unterhaltsame Lektüre.

Impressum

Blog of Julian Buss

Suche
RSS-Feeds
rssfeed.pngContent Feed
rssfeed.pngComment Feed
Aktuelle Einträge
Aktuelle Kommentare
Links zu YouAtNotes
Links zu YouAtNotes (in englisch)
Archiv