Tom
Further to my previous email, attached is a snippet created using
the Snippet-Creator, it focuses on
how to open a connection to openoffice that is disposable (i.e no need
to call System.exit(0) )
Thanks
David D
Tom Schindl wrote:
> David Dankwerth schrieb:
> | Stephan
> |
> | Many thanks for your help, your direction has helped me produce
> | a sample that uses GUI to convert to pdf Office documents using UNO and
> | openoffice.
> |
> | I am attaching the sample and hope it would be useful for other people.
> |
> | All the best
> | David Dankwerth
> | ri3k
> |
>
> Hi David,
>
> maybe this could get part of
> http://api.openoffice.org/SDK/example_collection.html which I'm afraid
> does not exists yet. The whole thing is too big for our snippet page
> (http://codesnippets.services.openoffice.org/) but maybe we should
> create a designated part on the snippet-page where we offer
> larger-scale examples/complete applications like yours.
>
> We also discussed this earlier when think about an extension manager but
> because nobody really head time we are stuck at the moment.
>
> Maybe we could also pull out the really interesting parts of your
> DocConverter class and create small codesnippets out of them.
>
> Until then we could maybe integrate the whole into
> http://api.openoffice.org/servlets/ProjectDocumentList
>
> One more hint if you would provide your classes compiled as a jar it
> would maybe very easy to integrate in an Java-App.
>
> Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
________________________________________________________________________
This e-mail and its attachments are confidential. If you are not the intended
recipient of this e-mail message, please telephone or e-mail us immediately,
delete this message from your system and do not read, copy, distribute,
disclose or otherwise use this e-mail message and any attachments.
Although ri3k believes this e-mail and any attachments to be free of any virus
or other defect which may affect your computer, it is the responsibility of the
recipient to ensure that it is virus free and ri3k does not accept any
responsibility for any loss or damage in any way from its use.
<?xml version="1.0"?>
<!--
$RCSfile: $
last change: $Revision: $ $Author: $ $Date: $
(c)2003 by the copyright holders listed with the author-tags.
If no explicit copyright holder is mentioned with a certain author,
the author him-/herself is the copyright holder. All rights reserved.
Public Documentation License Notice:
The contents of this Documentation are subject to the
Public Documentation License Version 1.0 (the "License");
you may only use this Documentation if you comply with
the terms of this License. A copy of the License is
available at http://www.openoffice.org/licenses/PDL.html
The Original Documentation can be found in the CVS archives
of openoffice.org at the place specified by RCSfile: in this header.
The Initial Writer(s) of the Original Documentation are listed
with the author-tags below.
The Contributor(s) are listed with the author-tags below
without the marker for being an initial author.
All Rights Reserved.
-->
<snippet language="Java" application="Office">
<keywords>
</keywords>
<authors>
<author id="" initial="false" email="[EMAIL PROTECTED]">David Dankwerth</author>
<author id="" initial="false" email="[EMAIL PROTECTED]">Guy Schohet</author>
</authors>
<question heading="Open connection to xBridge ">How to open connection to xBride that i can dispose
<p>I open connection to openoffice using the UNO api, but dont want to run</p>
<p>System.exit(0) to exit the program ( because it runs in a servlet for example)</p>
</question>
<answer>
<p>In order for the program to exit, the connection must be disposed,</p>
<p>in order to dispose the connection you must have a direct reference</p>
<p>to the Bridge.</p>
<p>using :</p>
<p>XComponentContext xComponentContext =</p>
<p> com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );</p>
<p>as most the examples do, does not give you direct reference to the bridge instance</p>
<p></p>
<listing> /**
* open connection to openoffice
*/
public void useConnection() throws java.lang.Exception {
try {
XComponentContext _ctx =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
xRemoteContext = _ctx ;
Object x = xRemoteContext.getServiceManager().createInstanceWithContext(
"com.sun.star.connection.Connector", xRemoteContext );
XConnector xConnector = (XConnector )
UnoRuntime.queryInterface(XConnector.class, x);
XConnection connection = xConnector.connect( con);
if (connection == null)
System.out.println("Connection is null");
x = xRemoteContext.getServiceManager().createInstanceWithContext(
"com.sun.star.bridge.BridgeFactory", xRemoteContext);
XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(
XBridgeFactory.class , x );
if (xBridgeFactory== null)
System.out.println("bridge factoriy is null");
// this is the bridge that you will dispose
bridge = xBridgeFactory.createBridge( "" , "urp", connection , null );
XComponent xComponent = (XComponent) UnoRuntime.queryInterface(
XComponent.class, bridge );
// get the remote instance
x = bridge.getInstance( "StarOffice.ServiceManager");
// Query the initial object for its main factory interface
xRemoteServiceManager = ( XMultiComponentFactory )
UnoRuntime.queryInterface( XMultiComponentFactory.class, x );
// retrieve the component context (it's not yet exported from the office)
// Query for the XPropertySet interface.
XPropertySet xProperySet = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class, xRemoteServiceManager );
// Get the default context from the office server.
Object oDefaultContext =
xProperySet.getPropertyValue( "DefaultContext" );
// Query for the interface XComponentContext.
XComponentContext xOfficeComponentContext =
( XComponentContext ) UnoRuntime.queryInterface(
XComponentContext.class, oDefaultContext );
// now create the desktop service
// NOTE: use the office component context here !
Object oDesktop = xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", xOfficeComponentContext );
officeComponentLoader = ( XComponentLoader )
UnoRuntime.queryInterface( XComponentLoader.class, oDesktop );
String available = (null !=officeComponentLoader ? "available" : "not available");
System.out.println( "remote ServiceManager is " + available );
}
catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1
xRemoteContext = null;
throw e;
}
}
/**
* when all the work is done, call release to dispose of the bridge
* and your program can exit normaly, without forcing a System.exit
*/
public void release()
throws Exception
{
XComponent xcomponent =
( XComponent ) UnoRuntime.queryInterface( XComponent.class,
bridge );
// Closing the bridge
xcomponent.dispose();
}
</listing>
</answer>
<versions>
<version number="1.1.x" status="tested"/>
</versions>
<operating-systems>
<operating-system name="All"/>
</operating-systems>
<changelog>
</changelog>
</snippet>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]