这是indexloc提供的服务,不要输入任何密码
Skip to content
Jochen Staerk edited this page Dec 21, 2015 · 1 revision

Source: Markus Krüger (NOA developer)

The code will be implemented in next NOA version 2.2.1 (release date not yet set). The IOfficeApplication will then return IApplicationInfo that provides these information.

If you need to get some information about the OpenOffice.org application setup, such as its version or locale, then you can use following example method:

  public static String getSetupInfo(IServiceProvider serviceProvider, String path, String element)
      throws Exception {
    Object configProviderObject = serviceProvider.createService("com.sun.star.comp.configuration.ConfigurationProvider");
    XMultiServiceFactory xConfigServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
        configProviderObject);
    String readConfAccess = "com.sun.star.configuration.ConfigurationAccess";
    PropertyValue[] properties = new PropertyValue[1];
    properties[0] = new PropertyValue();
    properties[0].Name = "nodepath";
    properties[0].Value = path;
    Object configReadAccessObject = xConfigServiceFactory.createInstanceWithArguments(readConfAccess,
        properties);
    XNameAccess xConfigNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
        configReadAccessObject);
    return xConfigNameAccess.getByName(element).toString();
  }

These are some examples:

Get version:

....
getSetupInfo(officeAplication.getServiceProvider(),"/org.openoffice.Setup/Product","ooSetupVersionAboutBox");

or

....
getSetupInfo(officeAplication.getServiceProvider(),"/org.openoffice.Setup/Product","ooSetupVersion");

Get locale:

....
getSetupInfo(officeAplication.getServiceProvider(),"/org.openoffice.Setup/L10N","ooLocale");

The following method will dump all available information to system out if you use "/org.openoffice.Setup" as path:

  public static void dumpSetupInfos(IServiceProvider serviceProvider, String path)
      throws Exception {
    Object configProviderObject = serviceProvider.createService("com.sun.star.comp.configuration.ConfigurationProvider");
    XMultiServiceFactory xConfigServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
        configProviderObject);
    String readConfAccess = "com.sun.star.configuration.ConfigurationAccess";
    PropertyValue[] properties = new PropertyValue[1];
    properties[0] = new PropertyValue();
    properties[0].Name = "nodepath";
    properties[0].Value = path;
    Object configReadAccessObject = xConfigServiceFactory.createInstanceWithArguments(readConfAccess,
        properties);
    XNameAccess xConfigNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
        configReadAccessObject);
    String[] names = xConfigNameAccess.getElementNames();
    System.out.println(path);
    System.out.println("=======================================");
    for (int i = 0; i < names.length; i++) {
      Object element = xConfigNameAccess.getByName(names[i]);
      if (element instanceof String || element instanceof Boolean
          || element instanceof Number
          || element instanceof Character
          || element instanceof CharSequence) {
        System.out.println(names[i] + ": "
            + element);
      }
      else if (element instanceof String[]) {
        System.out.println(names[i] + ": "
            + Arrays.asList((String[]) element).toString());
      }
      else if (!(element instanceof Any)) {
        dumpSetupInfos(serviceProvider, path + "/"
            + names[i]);
      }
    }
  }
Clone this wiki locally