1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::uno
;
36 ConfigurationAccess::ConfigurationAccess (
37 const OUString
& rsRootName
,
38 const WriteMode eMode
)
40 Reference
<lang::XMultiServiceFactory
> xProvider
=
41 configuration::theDefaultProvider::get( ::comphelper::getProcessComponentContext() );
42 Initialize(xProvider
, rsRootName
, eMode
);
45 void ConfigurationAccess::Initialize (
46 const Reference
<lang::XMultiServiceFactory
>& rxProvider
,
47 const OUString
& rsRootName
,
48 const WriteMode eMode
)
52 Sequence
<Any
> aCreationArguments(comphelper::InitAnyPropertySequence(
54 {"nodepath", Any(rsRootName
)},
55 {"depth", Any(sal_Int32(-1))}
58 OUString sAccessService
;
59 if (eMode
== READ_ONLY
)
60 sAccessService
= "com.sun.star.configuration.ConfigurationAccess";
62 sAccessService
= "com.sun.star.configuration.ConfigurationUpdateAccess";
64 mxRoot
= rxProvider
->createInstanceWithArguments(
70 DBG_UNHANDLED_EXCEPTION("sd.tools");
74 Any
ConfigurationAccess::GetConfigurationNode (
75 const OUString
& sPathToNode
)
77 return GetConfigurationNode(
78 Reference
<container::XHierarchicalNameAccess
>(mxRoot
, UNO_QUERY
),
82 Any
ConfigurationAccess::GetConfigurationNode (
83 const css::uno::Reference
<css::container::XHierarchicalNameAccess
>& rxNode
,
84 const OUString
& sPathToNode
)
86 if (sPathToNode
.isEmpty())
93 return rxNode
->getByHierarchicalName(sPathToNode
);
96 catch (const Exception
&)
98 TOOLS_WARN_EXCEPTION("sd", "caught exception while getting configuration node" << sPathToNode
);
104 void ConfigurationAccess::CommitChanges()
106 Reference
<util::XChangesBatch
> xConfiguration (mxRoot
, UNO_QUERY
);
107 if (xConfiguration
.is())
108 xConfiguration
->commitChanges();
111 } // end of namespace sd::tools
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */