Extend OpenOffice.org

It's easier than you might think to create your own OpenOffice.org extensions.

If you have a nifty macro or a nice Writer template you want to share with other OpenOffice.org users, publishing them on the Web along with detailed installation instructions is probably not the best way to go. Fortunately, OpenOffice.org supports extensions—small installable packages that provide added functionality. You easily can turn your templates, autotext entries, gallery art and macros into extensions that can be installed with a couple of clicks. Better yet, OpenOffice.org's extensions have an easy-to-understand and well-defined architecture, and you can start building your own extensions in no time.

Extending OpenOffice.org's functionality using extensions is nothing new. From the very beginning, users could add new features to the office suite by installing so-called UNO packages. Usually, these packages contained OOo Basic code, and they offered a more straightforward way of integrating macros into OpenOffice.org applications. With the release of OpenOffice.org 2.0.4, the idea of adding new features via installable packages has been rethought thoroughly and aligned with a concept that is more familiar to end users—namely the extension architecture of the Mozilla Firefox browser.

The technical implementation of the extension system in OpenOffice.org also has been reworked. Most notably, the new version of OpenOffice.org can handle so-called non-code extensions that can contain document templates, gallery items, autotext snippets and so on. The new version of OpenOffice.org also introduces the new .oxt file extension that allows users to identify installable extension packages easily.

How Extensions Work

An OpenOffice.org extension is essentially a zip file that includes both the installable contents and additional metadata required to install and register the extension properly. OpenOffice.org provides a simple-to-use tool called Package Manager that lets users install new extensions and manage existing ones. To install an extension, simply choose Tools→Package Manager, select My Packages, and press the Add button. Once the extension is installed, restart OpenOffice.org, and you are good to go. Unlike Firefox, some types of extensions don't require you to restart OpenOffice.org. For example, if you install non-code extensions, you can use them right away.

Figure 1. The Contents of a Non-Code OpenOffice.org Extension

To better understand the anatomy of OpenOffice.org extensions, let's dissect an empty sample extension from the OpenOffice.org Wiki (wiki.services.openoffice.org/wiki/Non-code_extensions). In order to peek inside the package, you have to change its extension from oxt to zip. This allows you to treat the package as a regular zip archive. The package consists of three elements: the META-INF and template folders, as well as the Paths.xcu configuration file. The META-INF folder contains the manifest.xml file that, among other things, “points” to the Paths.xcu configuration file. The Paths.xcu file contains information that the Package Manager uses to add the templates to the appropriate location. This location is defined as %origin%/template, and the Package Manager replaces the %origin% variable with the full path to the internal template container. The fuse parameter adds the templates to the specified container or creates a new one if it doesn't exist. To create a new template extension, you don't need to tweak anything; the configuration file and the overall structure of the extension remain the same. All you have to do is copy your custom templates into the template folder. Change the file extension of the resulting package back to oxt, and install it via Tools→Package Manager. To check whether the extension has been installed properly, choose File→Templates→Organize; you should see your templates in the My Templates folder.

Creating a Programmatic Extension from Scratch

Although creating non-code extensions is rather trivial, building packages containing code (let's call them programmatic extensions) is a different matter. The programmatic extension includes not only the code itself, but also a more complex configuration file containing information about menus, submenus, commands and macros assigned to them, icons and so forth. Creating a configuration file manually, even for the most simple programmatic extension, requires some technical knowledge, and it can be rather time consuming. Fortunately, there is a tool that can automate the entire process of creating an extension. Although the Add-on Tool (documentation.openoffice.org/HOW_TO/various_topics/Addons1_1en.sxw) hasn't been updated since 2003, it still does a great job of generating extensions that can be used with the latest version of OpenOffice.org. To get to grips with the Add-on Tool and better understand the process of creating a programmatic extension, let's build a simple dummy text-generator extension from scratch. Once installed, the extension adds the Lorem ipsum command to the Tools→Add-Ons menu. This command runs an OpenOffice.org Basic macro that inserts a specified number of paragraphs with the Lorem ipsum dummy text. The following description assumes that you have a general knowledge of how to create and manage macros, modules and libraries in OpenOffice.org. The Add-on Tool uses the older term “add-on”, which you can consider a synonym of “extension”.

Start with creating a macro that generates the dummy text. To keep things tidy, create a separate library called LoremipsumLib, containing the LoremipsumModule. In this module, add the macro shown in Listing 1. (Replace the “Lorem ipsum dolor sit amet...” string with a paragraph of dummy text.)

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

openoffice

tom pitts's picture

with some organizations resisting the MS Office 2007 file formats, maybe the openoffice file formats gain have some traction.

a lot of people complain they couldn't get by with just openoffice, but i used it throughout college and still do at home.

Its the extensions that will make it great

Charley Uchea's picture

Being able to extend the functionality of an office suit will, in its maturity, allow openoffice to become the ms office killer it should be

Hallo

Anonymous's picture

Hallo

Open Office

Klettergriffe's picture

Thnaks for these very interesting posting. I will try it out now.

Open Office

AdiX's picture

It thanks for article. Open Office is essential in work me!

Something wrong with the date?

Michael's picture

Either you live in the future or something is wrong with the post date. It is the same with the next post. The following posts are okay.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix