Difference between revisions of "OpenOffice Simple UNO Client Application Project Type"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Bundled UNO Bootstrap Glue Code)
Line 79: Line 79:
 
</blockquote>
 
</blockquote>
 
The ''unowinreg.dll'' is to be platform independent and necessary to find the default office installation on Windows.
 
The ''unowinreg.dll'' is to be platform independent and necessary to find the default office installation on Windows.
 +
 +
= See also =
 +
* [[JavaEclipseTuto|Java Eclipse Tutorial]]

Revision as of 18:44, 5 August 2006

Overview

The StarOffice/OpenOffice.org Client Application wizard creates a new J2SE project with office API support, means the office library is added to the project to provide code completion and context sensitive help for the office API. The generated main function contains some code to bootstrap an UNO environment and returns the remote office context object of the default office installation on the system. This works only if a default installation of the office was made and the soffice binary in the <office>/program directory is in the path (at least reachable over a symbolic links). 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 office SDK + special manifest entries to support the simply UNO bootstrap feature which enables the application jar to run without any further prepared environment but having full access to the office API to control, automate the office process.

Project Wizard

The project wizard should be simply to use, you simply choose

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

and follow the wizard.

  • Step 1: Selecting the project type

Simple Client1.png

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

Simple Client2.png

Generated Code

The generated code looks like [java] /*

* 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();
       }
       catch (java.lang.Exception e){
           e.printStackTrace();
       }
       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 office 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 form 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 to be platform independent and necessary to find the default office installation on Windows.

See also

Personal tools