|
|
Transparent Use of Office UNO ComponentsIntroductionThis document is about making the use of office UNO components transparent to the user. If some client code wants to use office UNO components, then the typical use case is, that the client code is first looking for an existing office installation. If an installation is found, it is checked if the office process is already running. If no office process is running, an office process is started. After that the client code connects to the running office using remote UNO mechanisms in order to get the remote component context of that office. After this, the client code can use the remote component context to access arbitrary office UNO components. From the perspective of the client code there is no difference between local and remote components. The idea is, that the component context is provided in a more transparent way. Especially the location of an existing office installation and the detection of a running office process should be hidden from the user. Transparent Use from JavaThe UNO component context is the root object for all UNO client applications. It must be passed to a component during its instantiation and therefore basically provides an environment for components. The component context also provides the service manager, which is used to create components. The idea is, that a bootstrap method is provided, which bootstraps the component context from a UNO installation. A simple client application may then look like:
One of the requirements for a Java client application is, that Java finds the
Customized Class LoaderThe concept is based on the requirement that every class that uses UNO types or other classes that come with a office installation gets loaded by a customized class loader. This customized class loader knows the location of a UNO installation and loads every class from a jar or class file that belongs to the office installation. That means, the customized class loader must be instantiated and initialized before the first class that uses UNO is loaded. For convenience we will provide some tooling in the SDK, which allows to build a client jar file, which can be invoked by
A client application created by using the SDK tooling will automatically load
the class
The customized loader needs a special entry in the manifest file that specifies the name of the class that contains the client application code: Name: com/sun/star/lib/loader/Loader.class Application-Class: MyApplication The implementation of Finding a UNO installationThe location of a UNO installation can be specified by the Java system
property
In addition, it is possible to specify a UNO installation by setting the
environment variable
Note, that this is not working with Java 1.3.1 and Java 1.4, because environment variables are not supported in those Java versions. If no UNO installation is specified by the user, the default UNO installation on the system is searched for. The search algorithm is platform dependent. On the Windows platform, the UNO installation is found by reading the default
value of the key "Software\OpenOffice.org\UNO\InstallPath" from the
root key HKEY_CURRENT_USER in the Windows Registry. If this key is missing,
the key is read from the root key HKEY_LOCAL_MACHINE. One of those keys is
always written during the installation of an office. In a single user
installation the key is written to HKEY_CURRENT_USER, in a multi-user
installation of an administrator to HKEY_LOCAL_MACHINE. Note, that the default
installation is the last installed office, but with the restriction, that
HKEY_CURRENT_USER has a higher priority than HKEY_LOCAL_MACHINE. The reading
from the Windows Registry requires, that the native library unowinreg.dll is
part of the application jar file or can be found in the
On the Unix/Linux platforms, the UNO installation is found from the
The bootstrap methodThe Note, that the office process can only be started, if the
Transparent Use from C++Also for C++ a bootstrap function is provided, which bootstraps the component context from a UNO installation. An example for a simple client application shows the following code snipplet: // get the remote office component context Reference< XComponentContext > xContext( ::cppu::bootstrap() ); // get the remote office service manager Reference< XMultiComponentFactory > xServiceManager( xContext->getServiceManager() ); // get an instance of the remote office desktop UNO service // and query the XComponentLoader interface Reference < XComponentLoader > xComponentLoader( xServiceManager->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), xContext ), UNO_QUERY ); // open a spreadsheet document Reference< XComponent > xComponent( xComponentLoader->loadComponentFromURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/scalc" ) ), OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0, Sequence < ::com::sun::star::beans::PropertyValue >() ) ); A C++ client application which uses UNO is linked to the C++ UNO libraries,
which can be found in the program directory of a UNO installation. When running
the client application, the C++ UNO libraries are found only, if the UNO
program directory is included in the Application LoaderAs this requires the knowledge of the location of a UNO installation, we
will provide an application loader ( For convenience we will provide some tooling in the SDK, which allows to
build a client executable file (e.g.
In this case, the On the Unix/Linux platforms the application loader writes error messages to
the Note, that the C++ application loader is only available with OOo 2.0. Finding a UNO installationA UNO installation can be specified by the user by setting the
If no UNO installation is specified by the user, the default installation on the system is taken. On the Windows platform, the default installation is read from the default value of the key "Software\OpenOffice.org\UNO\InstallPath" from the root key HKEY_CURRENT_USER in the Windows Registry. If this key is missing, the key is read from the root key HKEY_LOCAL_MACHINE. On the Unix/Linux platforms, the default installation is found from the
The bootstrap functionThe Author: Thomas Benisch. Last changed: $Date: 2004/12/05 13:42:29 $. |


