(short demos at the end)
You can call Sun people slow when it comes to creating an ecosystem of plugins. NetBeans had a platform years ago, but it’s only been a year since it became brain-dead easy to develop on top of it. As the saying goes: better late than never…
Starting with version OpenOffice 2.0.4 (freshly released) which was just released, packaging has evolved (new .oxt extension) and tools (Java for the time being) are now available to help you write code to extend the features of the suite or to interact with a silent instance. If you want to find out more about it, read this.
Also, the last OpenOffice Conference in Lyon had a presentation by Jürgen
Schmidt on “OpenOffice.org Extensions Infrastructure”. Note that all this applies to StarOffice 8 (Update 4) also.
A couple of weeks back, I needed to write a prototype client to illustrate to end-users the use of a web services protocol (more on that in a later entry). TCP tunnels and technical Swing clients are not what you everyday tool and OpenOffice felt like a better choice. The only problem was the rather bad experience I had a couple of years back trying to get my head around UNO, the IDL language behind (inside) OpenOffice. I briefly tried the Eclipse plugin, but it required too much hand-coding and UNO investment.
I was lucky to test-drive an early version of the NetBeans OpenOffice integration plugin (thank you Steffen and Jürgen!). Here’s how it went:
What I simply wanted to do is provide a UI to the user to be able to send to current document using an optimized, reliable, and secure web services protocol (implemented in my case using GlassFish‘s WSIT). If this document was
in Open Document format, I would show the document metadata (properties) and send them over in the payload together with the document.
I decided on using Java 6 because of all the great desktop improvements (most important to me were look-and-feel fidelity and no more gray rectangle) it provides and because obviously Java now has Web Services in the JDK. So here are the ingredients:
– Java 6 SDK (I used build 96)
– OpenOffice 2.0.4 (build 680)
– OpenOffice SDK (same version)
– NetBeans 6 Milestone 3
Java needs to be enabled (this is the default), and OpenOffice should be set to use the proper JRE (this is also where debugging options for the JVM are set) :
Once the OpenOffice NetBeans plugin is installed (get it here),
and the OpenOffice and SDK configured (Tools -> Options
NetBeans now has several new project types: client application,
Calc Add-in, UNO component:
You can now develop using Java and Swing (Matisse is yet again a life saver) and build the archive (an
.oxt file containing the JAR and XML metadata) or even deploy directly (using a call to the
binary) to the OpenOffice instance (you’ll need to restart it to test).
setting up UNO environment ...
build UNO idl files
Building jar: D:\\dev\\PRESTOopenoffice\\dist\\PRESTOopenoffice.jar
creating UNO extension package ...
Building zip: D:\\dev\\PRESTOopenoffice\\dist\\PRESTOopenoffice.oxt
Copying 1 file to D:\\dev\\PRESTOopenoffice\\dist
extension package ...
T:/OpenOffice.org2.0\\program\\unopkg add -f D:\\dev\\PRESTOopenoffice\\dist\\PRESTOopenoffice.oxt
BUILD SUCCESSFUL (total time: 3 seconds)
Installing the extension can also be done manually using the Package Manager from the Tools menu (which is how your users would use it). Note that you can deploy this extension into previous versions of OpenOffice (2.0.x) or StarOffice 8 by changing the extension from
A Calc Add-In project looks like this:
I will not go into all the details of these files. All I can say is that I happy I don't have to know most of what they do and why they exist.
CalcAddins.xcu file is key to registering your extension in the OpenOffice UI : a menu item, a toolbar, etc... All this can be conditional and internationalized. The
uno-extension-manifest.xml file is very similar to the JAR manifest and points to all the resources needed by the extension (including to file described above and all the Java code).
Once set up, you'll have code completion for
It really felt strange the first time I crashed OpenOffice. I started looking for a stacktrace but couldn't find one. So I ended up setting NetBeans de remote debug the JVM running inside OpenOffice executing my code. To enable debugging, add this line to the Parameters in the above Java options window:
and use Run -> Attach Debugger in NetBeans (the connector is
SocketListen and port is
localhost). You can't step into OpenOffice code at this point, but this proved to
be very useful.
- I'm no UNO/OpenOffice expert, so I relied on OO-Snippets (to get the current document path in my case).
- If you really want to mess with
.xcu files, make sure NetBeans recognizes them as XML: Tools ->Options ->Advanced ->IDE Configuration ->System ->Object Types ->XML Objects.
- Make sure the
.oxt file contains all the Java code you need including libraries (hack the
uno-package ANT target if necessary and make sure the manifest has an appropriate entry to reference the library jars relatively using
Class-Path:). If you're really in hacking mode, drop library jars in the
- If you're crashing OpenOffice all too often, try disabling the auto recovery.
- Looking for standard output: simply start OpenOffice from the command line.
And finally, the small demos :
Using the module in NetBeans.
Installing and using the extension in OpenOffice.
Hopefully this will give you ideas of what can be achieved with OpenOffice and a little bit of Java coding.
I have a few ideas myself, let's see if can find the time to implement.