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 .
20 import com
.sun
.star
.lang
.XMultiServiceFactory
;
21 import com
.sun
.star
.container
.XHierarchicalNameAccess
;
22 import com
.sun
.star
.container
.NoSuchElementException
;
23 import com
.sun
.star
.beans
.PropertyValue
;
24 import com
.sun
.star
.beans
.PropertyState
;
25 import com
.sun
.star
.uno
.UnoRuntime
;
28 * Read configuration settings.
30 public class ConfigurationRead
{
32 private XHierarchicalNameAccess root
= null;
35 * Creates new ConfigurationRead
36 * @param xMSF An instance of service
37 * "com.sun.star.configuration.ConfigurationProvider"
38 * @param rootnode The root of the configuration nodes.
40 private ConfigurationRead(XMultiServiceFactory xMSF
, String rootnode
) {
42 PropertyValue
[] nodeArgs
= new PropertyValue
[1];
43 PropertyValue nodepath
= new PropertyValue();
44 nodepath
.Name
= "nodepath";
45 nodepath
.Value
= rootnode
;
47 nodepath
.State
= PropertyState
.DEFAULT_VALUE
;
51 Object rootObject
= xMSF
.createInstanceWithArguments(
52 "com.sun.star.configuration.ConfigurationAccess",
55 root
= UnoRuntime
.queryInterface(
56 XHierarchicalNameAccess
.class, rootObject
);
58 catch(com
.sun
.star
.uno
.Exception e
) {
64 * Creates new ConfigurationRead. This uses "org.openoffice.Setup"
65 * as default root name.
66 * @param xMSF An instance of service
67 * "com.sun.star.configuration.ConfigurationProvider"
69 public ConfigurationRead(XMultiServiceFactory xMSF
) {
70 this(xMSF
, "org.openoffice.Setup");
74 * Get contents of a node by its hierarchical name.
75 * @param name The hierarchical name of the node.
76 * @return The contents as an object
78 public Object
getByHierarchicalName(String name
) throws NoSuchElementException
{
79 return root
.getByHierarchicalName(name
);