/src/libreoffice/sd/source/ui/tools/ConfigurationAccess.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <tools/ConfigurationAccess.hxx> |
21 | | #include <com/sun/star/lang/XMultiServiceFactory.hpp> |
22 | | #include <com/sun/star/container/XHierarchicalNameAccess.hpp> |
23 | | #include <com/sun/star/configuration/theDefaultProvider.hpp> |
24 | | #include <com/sun/star/container/XNameAccess.hpp> |
25 | | #include <com/sun/star/util/XChangesBatch.hpp> |
26 | | #include <comphelper/processfactory.hxx> |
27 | | #include <comphelper/propertysequence.hxx> |
28 | | #include <comphelper/diagnose_ex.hxx> |
29 | | #include <sal/log.hxx> |
30 | | |
31 | | using namespace ::com::sun::star; |
32 | | using namespace ::com::sun::star::uno; |
33 | | |
34 | | namespace sdtools { |
35 | | |
36 | | ConfigurationAccess::ConfigurationAccess ( |
37 | | const OUString& rsRootName, |
38 | | const WriteMode eMode) |
39 | 0 | { |
40 | 0 | Reference<lang::XMultiServiceFactory> xProvider = |
41 | 0 | configuration::theDefaultProvider::get( ::comphelper::getProcessComponentContext() ); |
42 | 0 | Initialize(xProvider, rsRootName, eMode); |
43 | 0 | } |
44 | | |
45 | | void ConfigurationAccess::Initialize ( |
46 | | const Reference<lang::XMultiServiceFactory>& rxProvider, |
47 | | const OUString& rsRootName, |
48 | | const WriteMode eMode) |
49 | 0 | { |
50 | 0 | try |
51 | 0 | { |
52 | 0 | Sequence<Any> aCreationArguments(comphelper::InitAnyPropertySequence( |
53 | 0 | { |
54 | 0 | {"nodepath", Any(rsRootName)}, |
55 | 0 | {"depth", Any(sal_Int32(-1))} |
56 | 0 | })); |
57 | |
|
58 | 0 | OUString sAccessService; |
59 | 0 | if (eMode == READ_ONLY) |
60 | 0 | sAccessService = "com.sun.star.configuration.ConfigurationAccess"; |
61 | 0 | else |
62 | 0 | sAccessService = "com.sun.star.configuration.ConfigurationUpdateAccess"; |
63 | |
|
64 | 0 | mxRoot = rxProvider->createInstanceWithArguments( |
65 | 0 | sAccessService, |
66 | 0 | aCreationArguments); |
67 | 0 | } |
68 | 0 | catch (Exception&) |
69 | 0 | { |
70 | 0 | DBG_UNHANDLED_EXCEPTION("sd.tools"); |
71 | 0 | } |
72 | 0 | } |
73 | | |
74 | | Any ConfigurationAccess::GetConfigurationNode ( |
75 | | const OUString& sPathToNode) |
76 | 0 | { |
77 | 0 | return GetConfigurationNode( |
78 | 0 | Reference<container::XHierarchicalNameAccess>(mxRoot, UNO_QUERY), |
79 | 0 | sPathToNode); |
80 | 0 | } |
81 | | |
82 | | Any ConfigurationAccess::GetConfigurationNode ( |
83 | | const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode, |
84 | | const OUString& sPathToNode) |
85 | 0 | { |
86 | 0 | if (sPathToNode.isEmpty()) |
87 | 0 | return Any(rxNode); |
88 | | |
89 | 0 | try |
90 | 0 | { |
91 | 0 | if (rxNode.is()) |
92 | 0 | { |
93 | 0 | return rxNode->getByHierarchicalName(sPathToNode); |
94 | 0 | } |
95 | 0 | } |
96 | 0 | catch (const Exception&) |
97 | 0 | { |
98 | 0 | TOOLS_WARN_EXCEPTION("sd", "caught exception while getting configuration node" << sPathToNode); |
99 | 0 | } |
100 | | |
101 | 0 | return Any(); |
102 | 0 | } |
103 | | |
104 | | void ConfigurationAccess::CommitChanges() |
105 | 0 | { |
106 | 0 | Reference<util::XChangesBatch> xConfiguration (mxRoot, UNO_QUERY); |
107 | 0 | if (xConfiguration.is()) |
108 | 0 | xConfiguration->commitChanges(); |
109 | 0 | } |
110 | | |
111 | | } // end of namespace sdtools |
112 | | |
113 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |