Hi Tom, here a new Snippet.
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> <keyword>application name</keyword> <keyword>XComponent</keyword> <keyword>com.sun.star.text.TextDocument</keyword> </keywords> <authors> <author id="tobiaskrais" initial="true" email="[EMAIL PROTECTED]" copyright="GPL">Tobias Krais (www.design-to-use.de)</author> </authors> <question heading="Get the Application Name of a document">How to get the Application Name of a document? </question> <answer> <listing>import {%see com.sun.star.frame.XModuleManager}; import {%see com.sun.star.lang.XComponent}; import {%see com.sun.star.lang.XMultiComponentFactory}; import {%see com.sun.star.uno.UnoRuntime}; import {%see com.sun.star.uno.XComponentContext}; public class Snippets { /** * Component context to be passed to a component via * com.sun.star.lang.XSingleComponentFactory . Arbitrary values * (e.g. deployment values) can be retrieved from the context. * * How to get this Object, see {%internal ../Office/Office.BootstrapOpenOffice.snip} * or {%internal ../Office/Office.ConnectToListeningOpenOffice.snip} */ private static XComponentContext xComponentContext; /** * Factory interface for creating component instances giving a context from * which to retrieve deployment values. * * How to get this Object, see {%internal ../Office/Office.BootstrapOpenOffice.snip} * or {%internal ../Office/Office.ConnectToListeningOpenOffice.snip} */ private static XMultiComponentFactory xMCF; /** * Get the application name of a document. E.g. for a writer document * "com.sun.star.text.TextDocument" * * @param myXComponent UNO Representativ of the opened document. * @return The OpenOffice application name. It looks like * "com.sun.star.text.TextDocument". */ public static String getApplicationName(XComponent myXComponent) { XModuleManager xMM = null; try { xMM = (XModuleManager)UnoRuntime.queryInterface( XModuleManager.class, xMCF.createInstanceWithContext( "com.sun.star.frame.ModuleManager", xComponentContext)); } catch (com.sun.star.uno.Exception e) { return null; } String sOOoApp = null; try{ // Getting the application name of the document, // e.g. "com.sun.star.text.TextDocument" for writer sOOoApp = xMM.identify(myXComponent); } catch(com.sun.star.uno.Exception e) { return null; } return sOOoApp; } }</listing> </answer> <versions> <version number="2.0.x" status="tested"/> <version number="1.1.x" status="untested"/> </versions> <operating-systems> <operating-system name="All"/> </operating-systems> <changelog> <change author-id="tobiaskrais" date="2006-12-11">Initial version</change> </changelog> </snippet>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]