update dev300-m58
[ooovba.git] / qadevOOo / runner / helper / ConfigurationRead.java
blob1a202298eb1e8c79df144c1847141e9f7771b8a6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ConfigurationRead.java,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package helper;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.container.XHierarchicalNameAccess;
34 import com.sun.star.container.XNameAccess;
35 import com.sun.star.container.NoSuchElementException;
36 import com.sun.star.beans.PropertyValue;
37 import com.sun.star.beans.PropertyState;
38 import com.sun.star.uno.UnoRuntime;
40 /**
41 * Read configuration settings.
43 public class ConfigurationRead {
45 XHierarchicalNameAccess root = null;
47 /**
48 * Creates new ConfigurationRead
49 * @param xMSF An instance of service
50 * "com.sun.star.configuration.ConfigurationProvider"
51 * @param rootnode The root of the configuration nodes.
53 public ConfigurationRead(XMultiServiceFactory xMSF, String rootnode) {
55 PropertyValue [] nodeArgs = new PropertyValue [1];
56 PropertyValue nodepath = new PropertyValue();
57 nodepath.Name = "nodepath";
58 nodepath.Value = rootnode;
59 nodepath.Handle = -1;
60 nodepath.State = PropertyState.DEFAULT_VALUE;
61 nodeArgs[0]=nodepath;
63 try {
64 Object rootObject = xMSF.createInstanceWithArguments(
65 "com.sun.star.configuration.ConfigurationAccess",
66 nodeArgs);
68 root = (XHierarchicalNameAccess)
69 UnoRuntime.queryInterface(
70 XHierarchicalNameAccess.class, rootObject);
72 catch(com.sun.star.uno.Exception e) {
73 e.printStackTrace();
77 /**
78 * Creates new ConfigurationRead. This uses "org.openoffice.Setup"
79 * as default root name.
80 * @param xMSF An instance of service
81 * "com.sun.star.configuration.ConfigurationProvider"
83 public ConfigurationRead(XMultiServiceFactory xMSF) {
84 this(xMSF, "org.openoffice.Setup");
87 /**
88 * Does the node with this hierarchical name exist?
89 * @param name The hierarchical name of a subnode.
90 * @return True, if the node exists.
92 public boolean hasByHieracrhicalName(String name) throws NoSuchElementException,
93 com.sun.star.lang.WrappedTargetException {
95 return root.hasByHierarchicalName(name);
101 * Get the elements of the root node.
102 * @return All elements of the root node.
104 public String[] getRootNodeNames() {
106 XNameAccess xName = (XNameAccess)
107 UnoRuntime.queryInterface(XNameAccess.class, root);
108 String[]names = xName.getElementNames();
109 return names;
113 * Get all elements of this node
114 * @param name The name of the node
115 * @return All elements of this node (as hierarchical names).
117 public String[] getSubNodeNames(String name) {
118 String[]names = null;
119 try {
121 Object next = root.getByHierarchicalName(name);
122 XNameAccess x = (XNameAccess)UnoRuntime.queryInterface(
123 XNameAccess.class, next);
124 names = x.getElementNames();
125 for (int i=0; i< names.length; i++) {
126 names[i] = name + "/" + names[i];
129 catch(Exception e) {
130 //just return null, if there are no further nodes
132 return names;
136 * Get contents of a node by its hierarchical name.
137 * @param The hierarchical name of the node.
138 * @return The contents as an object
140 public Object getByHierarchicalName(String name) throws NoSuchElementException {
141 return root.getByHierarchicalName(name);