Java Code Examples for com.sun.star.lang.XMultiServiceFactory#createInstanceWithArguments()

The following examples show how to use com.sun.star.lang.XMultiServiceFactory#createInstanceWithArguments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationInfo.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method can be used to get any info from the application that is available.
 * (Possible paths and keys can be retrieved with the dumpInfo method).
 * Returns the object described by the path and key, or <code>null</code> if not available.
 * 
 * @param path the path to the key information
 * @param key the key to get the value for
 * 
 * @return the object described by the path and key, or <code>null</code> if not available
 * 
 * @throws Exception if retreiving the value fails
 * 
 * @author Markus Krüger
 * @date 18.11.2008
 */
public Object getInfo(String path, String key) 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(key);
}
 
Example 2
Source File: ApplicationInfo.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method dumps info from the application described by the path.
 * 
 * @param path the path to be dumped, or null to dump from root
 * 
 * @throws Exception if dumping info fails
 * 
 * @author Markus Krüger
 * @date 18.11.2008
 */
public void dumpInfo(String path) throws Exception {
  if (path == null || path.length() == 0)
    path = NODE_ROOT;
  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)) {
      dumpInfo(path + "/"
          + names[i]);
    }
  }
}