OpenOffice Simple UNO Client Application Project Type

From Apache OpenOffice Wiki
Jump to: navigation, search

Back to OpenOffice.org NetBeans Integration

Overview

The OpenOffice.org Client Application wizard creates a new J2SE project with OpenOffice.org API support. This means the OpenOffice.org library is added to the project to provide code completion and context sensitive help for the OpenOffice.org API. The generated main function contains some code to bootstrap an UNO environment and returns the remote OpenOffice.org context object of the default OpenOffice.org installation on the system. This works only if a default installation of OpenOffice.org was made and the soffice binary in the <office>/program directory is in the path (at least reachable over a symbolic link). There are some fallback strategies possible which are not further discussed here.
The project builds a customized jar file containing special UNO bootstrap classes from the OpenOffice.org SDK and special manifest entries to support the simple UNO bootstrap feature. The UNO bootstrap feature enables the application jar to run without any further environment preparation and has full access to the OpenOffice.org API to control and automate the OpenOffice.org process.

Project Wizard

The project wizard is quite simple to use. Choose

  • File -> New Project -> OpenOffice.org -> OpenOffice.org Client Application

and follow the wizard.

  • Step 1: Select the project type

Simple Client1.png

  • Step 2: Define the project, class name, an optional package and the project location

Simple Client2.png

Generated Code

The generated code looks like

/*
 * TestClient.java
 *
 * Created on 10.06.2006 - 17:45:42
 *
 */
 
package org.test;
 
import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;
 
/**
 *
 * @author XXXXX
 */
public class TestClient {
 
    /** Creates a new instance of TestClient */
    public TestClient() {
    }
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();
            if (xContext == null) {
                System.err.println("ERROR: Could not bootstrap default Office.");
            }
        }
        catch (java.lang.Exception e){
            e.printStackTrace();
        }
        finally {
            System.exit( 0 );
        }
    }
 
}

Line 29 contains the UNO bootstrap call which returns the remote office context object. The remote context is main entry point to work with the OpenOffice.org API. The code is quite simple and should only show the first step. The generated project is buildable, runnable and can be started or debugged directly from within NetBeans as a normal J2SE application.

Manifest Entries for the UNO Bootstrap Mechanism

The manifest needs some special entries to support the simple UNO bootstrap feature:

Main-Class: com.sun.star.lib.loader.Loader

Name: com/sun/star/lib/loader/Loader.class
Application-Class: org.test.TestClient

where org.test.TestClient is the original main class.

Bundled UNO Bootstrap Glue Code

The following precompiled class files and the dll from the SDK are bundled with the client application jar.

com/sun/star/lib/loader/Loader$CustomURLClassLoader.class
com/sun/star/lib/loader/Loader.class
com/sun/star/lib/loader/InstallationFinder$StreamGobbler.class
com/sun/star/lib/loader/InstallationFinder.class
com/sun/star/lib/loader/WinRegKey.class
com/sun/star/lib/loader/WinRegKeyException.class
win/unowinreg.dll

The unowinreg.dll is included so that the client application can be platform independent. It is used to find the default OpenOffice.org installation on Windows.

See also

Personal tools