bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / helper / ConfigurationRead.java
bloba3af03c81ee3e43e1abc7b5d53fac4b731a28fa7
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package helper;
20 import com.sun.star.lang.XMultiServiceFactory;
21 import com.sun.star.container.XHierarchicalNameAccess;
22 import com.sun.star.container.XNameAccess;
23 import com.sun.star.container.NoSuchElementException;
24 import com.sun.star.beans.PropertyValue;
25 import com.sun.star.beans.PropertyState;
26 import com.sun.star.uno.UnoRuntime;
28 /**
29 * Read configuration settings.
31 public class ConfigurationRead {
33 XHierarchicalNameAccess root = null;
35 /**
36 * Creates new ConfigurationRead
37 * @param xMSF An instance of service
38 * "com.sun.star.configuration.ConfigurationProvider"
39 * @param rootnode The root of the configuration nodes.
41 public ConfigurationRead(XMultiServiceFactory xMSF, String rootnode) {
43 PropertyValue [] nodeArgs = new PropertyValue [1];
44 PropertyValue nodepath = new PropertyValue();
45 nodepath.Name = "nodepath";
46 nodepath.Value = rootnode;
47 nodepath.Handle = -1;
48 nodepath.State = PropertyState.DEFAULT_VALUE;
49 nodeArgs[0]=nodepath;
51 try {
52 Object rootObject = xMSF.createInstanceWithArguments(
53 "com.sun.star.configuration.ConfigurationAccess",
54 nodeArgs);
56 root = UnoRuntime.queryInterface(
57 XHierarchicalNameAccess.class, rootObject);
59 catch(com.sun.star.uno.Exception e) {
60 e.printStackTrace();
64 /**
65 * Creates new ConfigurationRead. This uses "org.openoffice.Setup"
66 * as default root name.
67 * @param xMSF An instance of service
68 * "com.sun.star.configuration.ConfigurationProvider"
70 public ConfigurationRead(XMultiServiceFactory xMSF) {
71 this(xMSF, "org.openoffice.Setup");
74 /**
75 * Does the node with this hierarchical name exist?
76 * @param name The hierarchical name of a subnode.
77 * @return True, if the node exists.
79 public boolean hasByHieracrhicalName(String name) throws NoSuchElementException,
80 com.sun.star.lang.WrappedTargetException {
82 return root.hasByHierarchicalName(name);
87 /**
88 * Get the elements of the root node.
89 * @return All elements of the root node.
91 public String[] getRootNodeNames() {
93 XNameAccess xName = UnoRuntime.queryInterface(XNameAccess.class, root);
94 String[]names = xName.getElementNames();
95 return names;
98 /**
99 * Get all elements of this node
100 * @param name The name of the node
101 * @return All elements of this node (as hierarchical names).
103 public String[] getSubNodeNames(String name) {
104 String[]names = null;
105 try {
107 Object next = root.getByHierarchicalName(name);
108 XNameAccess x = UnoRuntime.queryInterface(
109 XNameAccess.class, next);
110 names = x.getElementNames();
111 for (int i=0; i< names.length; i++) {
112 names[i] = name + "/" + names[i];
115 catch(Exception e) {
116 //just return null, if there are no further nodes
118 return names;
122 * Get contents of a node by its hierarchical name.
123 * @param name The hierarchical name of the node.
124 * @return The contents as an object
126 public Object getByHierarchicalName(String name) throws NoSuchElementException {
127 return root.getByHierarchicalName(name);