[api-dev] One more Snippet

2006-12-11 Thread Tobias Krais
Hi Tom,

don't wonder, why I produce so many snippets today. I quit working at my
company and change to an other one. But before I leave, I give back the
comunity, what it gave to me.

More Snippets will follow.

Should I send other snippets coming soon as PM?

Greetings, Tobias
?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
	keywordbootstrap/keyword
	keywordconnect/keyword
/keywords

authors
	author id=tobiaskrais initial=true email=[EMAIL PROTECTED] copyright=GPLTobias Krais (www.design-to-use.de)/author
/authors

question heading=Connect to Listening OpenOfficeHow to connect to a already listening OpenOffice?

pYou can start a OpenOffice in listening mode with e.g. this command:/p
pooffice -accept=quot;socket,host=localhost,port=9000;urp;StarOffice.ServiceManagerquot;/p
pThis commandline starts OpenOffice listening on port 9000/p
/question

answer
pThis method connect to a listening OpenOffice./p
listingimport {%see com.sun.star.beans.XPropertySet};
import {%see com.sun.star.bridge.UnoUrlResolver};
import {%see com.sun.star.bridge.XUnoUrlResolver};
import {%see com.sun.star.comp.helper.Bootstrap};
import {%see com.sun.star.lang.XMultiComponentFactory};
import {%see com.sun.star.uno.UnoRuntime};
import {%see com.sun.star.uno.XComponentContext};

/**
 * This method connects to a running OpenOffice. This OpenOffice is
 * listening on a specific port. It connects to this port.
 * 
 * @param ooport
 * @return
 */
public void connectListeningOpenOffice(String ooport)
{
	try{
		// Create an OO Component Context
		XComponentContext xCC = 
Bootstrap.createInitialComponentContext(null);

		// create a connector, so that it can contact the office
		XUnoUrlResolver urlResolver = UnoUrlResolver.create(xCC);

		Object initialObject = urlResolver.resolve(
quot;uno:socket,host=localhost,port=quot; + ooport
+ quot;;urp;StarOffice.ServiceManagerquot;);

		XMultiComponentFactory xMCF = (XMultiComponentFactory)
UnoRuntime.queryInterface(XMultiComponentFactory.class,
			initialObject);

		// retrieve the component context as property (it is not yet
		// exported from the office). Query for the XPropertySet interface.
		XPropertySet xProperySet = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, xMCF);

		// Get the default context from the office server.
		Object oDefaultContext = xProperySet.getPropertyValue(quot;DefaultContextquot;);

		// Query for the interface XComponentContext.
		xCC = (XComponentContext)
		UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext);

		// now create the desktop service
		// NOTE: use the office component context here!
		Object desktop = xMCF.createInstanceWithContext(
quot;com.sun.star.frame.Desktopquot;, xCC);
	}
	catch(Exception e){
	}
}/listing
/answer

versions
	version number=2.0.x status=tested/
	version number=1.1.x status=tested/
/versions

operating-systems
operating-system name=All/
/operating-systems

changelog
	change author-id=tobiaskrais date=2006-12-11Linking imports/change
	change author-id=tobiaskrais date=2006-03-20Initial version/change
/changelog

/snippet

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Re: [api-dev] One more Snippet

2006-12-11 Thread Tom Schindl
Tobias Krais schrieb:
 Hi Tom,
 
 don't wonder, why I produce so many snippets today. I quit working at my
 company and change to an other one. But before I leave, I give back the
 comunity, what it gave to me.
 
 More Snippets will follow.
 
 Should I send other snippets coming soon as PM?

I prefer having them on the mailing list so that I don't miss one.

Tom



signature.asc
Description: OpenPGP digital signature


Re: [api-dev] One more Snippet

2006-12-11 Thread Tom Schindl
Tobias Krais schrieb:
 Hi Tom,
 
 don't wonder, why I produce so many snippets today. I quit working at my
 company and change to an other one. But before I leave, I give back the
 comunity, what it gave to me.
 
 More Snippets will follow.
 
 Should I send other snippets coming soon as PM?
 
 Greetings, Tobias
 

Done.



signature.asc
Description: OpenPGP digital signature