2016-09-02 8 views
-2

私はC#の開発者ですが、実際にはOpenOffice-PlugInのJava 1.6でいくつかの機能を開発しなければなりません。 これらの関数の1つは、実行中のOpenOfficeのバージョンのような環境のメタ情報を取得することです。 Googleで何か見つからなかった。私は、レジストリエントリが存在することを知っています。しかし、それは単なる価値のないサブキーです。 Java 1.6で実行中のOpenOfficeのバージョン番号をどのように取得できますか?Java(1.6)でOpenOfficeのバージョンを読む方法

編集:

私は解決策を得ました。同じ問題がある場合、私は他の開発者を助ける。方法ではカプセル化されていなければなりません。

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; 

答えて

1

ConfigurationProviderインタフェースを使用する方法のthis example codeを参照してください。どのように動作するかを理解するのにも役立つthis python exampleがあります。

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; 
} 
+0

ありがとうございました。私はしかし、私のアドイン内から実行中のOOバージョンのバージョンを照会する方法を探していて、ライブラリを使用する必要がないことを望んでいましたが、OOはバージョンを照会するアドインの可能性を提供します。これが可能なら誰でも知っていますか? – Andy

関連する問題