application name
XComponent
com.sun.star.text.TextDocument
Tobias Krais (www.design-to-use.de)
How to get the Application Name of a document?
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;
}
}
Initial version