 | OO-Snippets: Get the Application Name of a documentCommons| Keywords | application name, XComponent, com.sun.star.text.TextDocument |
|---|
| Language | Java |
|---|
| Application | Office |
|---|
| Authors | Tobias Krais (www.design-to-use.de) (initial)
|
|---|
| Supported Versions | 2.0.x 1.1.x |
|---|
| Supported OS | All |
|---|
| Question | How to get the Application Name of a document?
|
|---|
| Answer | |
|---|
import com.sun.star.frame.XModuleManager;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public class Snippets {
Component context to be passed to a component via
com.sun.star.lang.XSingleComponentFactory .
private static XComponentContext xComponentContext;
Factory interface for creating component instances giving a context from
which to retrieve deployment values.
private static XMultiComponentFactory xMCF;
Get the application name of a document.
@param myXComponent
@return
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{
sOOoApp = xMM.identify(myXComponent);
}
catch(com.sun.star.uno.Exception e)
{
return null;
}
return sOOoApp;
}
}
|
Changelog| Date | User | Modification |
|---|
| 2006-12-11 | tobiaskrais | Initial version |
|