Reputation: 11
I'm a C# developer and actually i have to develop some functions in Java 1.6 for an OpenOffice-PlugIn. One of these functions is to get some meta informations of environment like the version of the executing OpenOffice. On Google i didn't find something. I know that a registry entry exists. But that is just a subkey without a value. Does anybody know, how i can get the Version Number of the executing OpenOffice with Java 1.6?
Edit:
Now i have the solution. I will help other developer, if they have the same issue. It must be only capsuled in a method.
XComponentContext componentContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
XMultiComponentFactory xRemoteServiceManager = componentContext.getServiceManager();
Object configProvider = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.configuration.ConfigurationProvider", componentContext);
XMultiServiceFactory xConfigProvider = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, configProvider);
PropertyValue[] lParams = new PropertyValue[1];
lParams[0] = new PropertyValue();
lParams[0].Name = "nodepath";
lParams[0].Value = "/org.openoffice.Setup/Product";
Object xAccess = xConfigProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess" , lParams);
XNameAccess xNameAccess = (com.sun.star.container.XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xAccess);
String OOVersion = (String)xNameAccess.getByName("ooSetupVersion");
return OOVersion;
Upvotes: -2
Views: 131
Reputation: 10400
See this example code of how to use ConfigurationProvider interface. You may find this python example helpful also to understand how things work.
NODE_PRODUCT = "org.openoffice.Setup/Product";
public String getOpenOfficeVersion() {
try {
// OOo >= 2.2 returns major.minor.micro
return getOpenOfficeProperty(NODE_PRODUCT, "ooSetupVersionAboutBox");
} catch (OpenOfficeException noSuchElementException) {
// OOo < 2.2 only returns major.minor
return getOpenOfficeProperty(NODE_PRODUCT, "ooSetupVersion");
}
}
public String getOpenOfficeProperty(String nodePath, String node) {
if (!nodePath.startsWith("/")) {
nodePath = "/" + nodePath;
}
String property = "";
// create the provider and remember it as a XMultiServiceFactory
try {
final String sProviderService = "com.sun.star.configuration.ConfigurationProvider";
Object configProvider = connection.getRemoteServiceManager().createInstanceWithContext(
sProviderService, connection.getComponentContext());
XMultiServiceFactory xConfigProvider = UnoRuntime.queryInterface(
com.sun.star.lang.XMultiServiceFactory.class, configProvider);
// The service name: Need only read access:
final String sReadOnlyView = "com.sun.star.configuration.ConfigurationAccess";
// creation arguments: nodepath
PropertyValue aPathArgument = new PropertyValue();
aPathArgument.Name = "nodepath";
aPathArgument.Value = nodePath;
Object[] aArguments = new Object[1];
aArguments[0] = aPathArgument;
// create the view
XInterface xElement = (XInterface) xConfigProvider.createInstanceWithArguments(sReadOnlyView, aArguments);
XNameAccess xChildAccess = UnoRuntime.queryInterface(XNameAccess.class, xElement);
// get the value
property = (String) xChildAccess.getByName(node);
} catch (Exception exception) {
throw new OpenOfficeException("Could not retrieve property", exception);
}
return property;
}
Upvotes: 1