22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/beans/PropertyValue.hpp>
24#include <com/sun/star/configuration/theDefaultProvider.hpp>
25#include <com/sun/star/container/XNameAccess.hpp>
26#include <com/sun/star/container/XNameContainer.hpp>
27#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
28#include <com/sun/star/lang/XSingleServiceFactory.hpp>
29#include <com/sun/star/util/XChangesBatch.hpp>
36 const OUString& sPackage,
39 css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider(
40 css::configuration::theDefaultProvider::get( rxContext ) );
42 std::vector< css::uno::Any > lParams;
43 css::beans::PropertyValue aParam ;
46 aParam.Name =
"nodepath";
47 aParam.Value <<= sPackage;
48 lParams.emplace_back(aParam);
53 aParam.Name =
"locale";
54 aParam.Value <<= OUString(
"*");
55 lParams.emplace_back(aParam);
59 css::uno::Reference< css::uno::XInterface > xCFG;
63 xCFG = xConfigProvider->createInstanceWithArguments(
64 "com.sun.star.configuration.ConfigurationAccess",
67 xCFG = xConfigProvider->createInstanceWithArguments(
68 "com.sun.star.configuration.ConfigurationUpdateAccess",
76 const OUString& sRelPath,
77 const OUString& sKey )
79 css::uno::Reference< css::container::XHierarchicalNameAccess > xAccess(xCFG, css::uno::UNO_QUERY_THROW);
81 css::uno::Reference< css::beans::XPropertySet > xProps;
82 xAccess->getByHierarchicalName(sRelPath) >>= xProps;
85 throw css::container::NoSuchElementException(
86 "The requested path \"" + sRelPath +
"\" does not exist.");
88 return xProps->getPropertyValue(sKey);
93 const OUString& sRelPath,
94 const OUString& sKey ,
95 const css::uno::Any& aValue )
97 css::uno::Reference< css::container::XHierarchicalNameAccess > xAccess(xCFG, css::uno::UNO_QUERY_THROW);
99 css::uno::Reference< css::beans::XPropertySet > xProps;
100 xAccess->getByHierarchicalName(sRelPath) >>= xProps;
103 throw css::container::NoSuchElementException(
104 "The requested path \"" + sRelPath +
"\" does not exist.");
106 xProps->setPropertyValue(sKey, aValue);
111 const OUString& sRelPathToSet,
112 const OUString& sSetNode )
114 css::uno::Reference< css::container::XHierarchicalNameAccess > xAccess(xCFG, css::uno::UNO_QUERY_THROW);
115 css::uno::Reference< css::container::XNameAccess > xSet;
116 xAccess->getByHierarchicalName(sRelPathToSet) >>= xSet;
119 throw css::container::NoSuchElementException(
120 "The requested path \"" + sRelPathToSet +
"\" does not exist." );
123 css::uno::Reference< css::uno::XInterface > xNode;
124 if (xSet->hasByName(sSetNode))
125 xSet->getByName(sSetNode) >>= xNode;
128 css::uno::Reference< css::lang::XSingleServiceFactory > xNodeFactory(xSet, css::uno::UNO_QUERY_THROW);
129 xNode = xNodeFactory->createInstance();
130 css::uno::Reference< css::container::XNameContainer > xSetReplace(xSet, css::uno::UNO_QUERY_THROW);
131 xSetReplace->insertByName(sSetNode, css::uno::Any(xNode));
139 const OUString& sPackage,
140 const OUString& sRelPath,
141 const OUString& sKey ,
150 const OUString& sPackage,
151 const OUString& sRelPath,
152 const OUString& sKey ,
153 const css::uno::Any& aValue ,
164 css::uno::Reference< css::util::XChangesBatch > xBatch(xCFG, css::uno::UNO_QUERY_THROW);
165 xBatch->commitChanges();
static void writeDirectKey(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &sPackage, const OUString &sRelPath, const OUString &sKey, const css::uno::Any &aValue, EConfigurationModes eMode)
does the same then openConfig() / writeRelativeKey() & flush() together.
static css::uno::Reference< css::uno::XInterface > makeSureSetNodeExists(const css::uno::Reference< css::uno::XInterface > &xCFG, const OUString &sRelPathToSet, const OUString &sSetNode)
it checks if the specified set node exists ... or create an empty one otherwise.
static css::uno::Any readDirectKey(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &sPackage, const OUString &sRelPath, const OUString &sKey, EConfigurationModes eMode)
does the same then openConfig() & readRelativeKey() together.
static css::uno::Any readRelativeKey(const css::uno::Reference< css::uno::XInterface > &xCFG, const OUString &sRelPath, const OUString &sKey)
reads the value of an existing(!) configuration key, which is searched relative to the specified conf...
static css::uno::Reference< css::uno::XInterface > openConfig(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &sPackage, EConfigurationModes eMode)
returns access to the specified configuration package.
static void flush(const css::uno::Reference< css::uno::XInterface > &xCFG)
commit all changes made on the specified configuration access.
static void writeRelativeKey(const css::uno::Reference< css::uno::XInterface > &xCFG, const OUString &sRelPath, const OUString &sKey, const css::uno::Any &aValue)
writes a new value for an existing(!) configuration key, which is searched relative to the specified ...
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Copy from a container into a Sequence.
EConfigurationModes
specify all possible modes, which can be used to open a configuration access.
@ ReadOnly
configuration will be opened readonly
@ AllLocales
all localized nodes will be interpreted as XInterface instead of interpreting it as atomic value node...