Branch data Line data Source code
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 : : #ifndef SD_TOOLS_CONFIGURATION_ACCESS_HXX
21 : : #define SD_TOOLS_CONFIGURATION_ACCESS_HXX
22 : :
23 : : #include <rtl/ustring.hxx>
24 : : #include <com/sun/star/container/XNameAccess.hpp>
25 : : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
26 : : #include <com/sun/star/uno/XComponentContext.hpp>
27 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 : : #include <vector>
29 : : #include <boost/function.hpp>
30 : :
31 : : namespace css = ::com::sun::star;
32 : :
33 : : namespace sd { namespace tools {
34 : :
35 : : /** This class gives access to the configuration. Create an object of this
36 : : class for one node of the configuration. This will be the root node.
37 : : Its children are then accessible through the new ConfigurationAccess
38 : : object.
39 : : */
40 : 260 : class ConfigurationAccess
41 : : {
42 : : public:
43 : : enum WriteMode { READ_WRITE, READ_ONLY };
44 : :
45 : : /** Create a new object to access the configuration entries below the
46 : : given root.
47 : : @param rsRootName
48 : : Name of the root.
49 : : @param eMode
50 : : This flag specifies whether to give read-write or read-only
51 : : access.
52 : : */
53 : : ConfigurationAccess(
54 : : const ::rtl::OUString& rsRootName,
55 : : const WriteMode eMode);
56 : :
57 : : ConfigurationAccess(
58 : : const css::uno::Reference<css::uno::XComponentContext>& rxContext,
59 : : const ::rtl::OUString& rsRootName,
60 : : const WriteMode eMode);
61 : :
62 : : /** Return a configuration node below the root of the called object.
63 : : @param rsPathToNode
64 : : The relative path from the root (as given the constructor) to
65 : : the node.
66 : : @return
67 : : The type of the returned node varies with the requested node.
68 : : It is empty when the node was not found.
69 : : */
70 : : css::uno::Any GetConfigurationNode (
71 : : const ::rtl::OUString& rsPathToNode);
72 : :
73 : : /** Return a configuration node below the given node.
74 : : @param rxNode
75 : : The node that acts as root to the given relative path.
76 : : @param rsPathToNode
77 : : The relative path from the given node to the requested node.
78 : : @return
79 : : The type of the returned node varies with the requested node.
80 : : It is empty when the node was not found.
81 : : */
82 : : static css::uno::Any GetConfigurationNode (
83 : : const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
84 : : const ::rtl::OUString& rsPathToNode);
85 : :
86 : : /** Write any changes that have been made back to the configuration.
87 : : This call is ignored when the called ConfigurationAccess object was
88 : : not create with read-write mode.
89 : : */
90 : : void CommitChanges (void);
91 : :
92 : : /** This functor is typically called for every item in a set. Its two
93 : : parameters are the name of key item (often of no further interest)
94 : : and the value of the item.
95 : : */
96 : : typedef ::boost::function<void(
97 : : const ::rtl::OUString&,
98 : : const std::vector<css::uno::Any>&) > Functor;
99 : :
100 : : /** Execute a functor for all elements of the given container.
101 : : @param rxContainer
102 : : The container is a XNameAccess to a list of the configuration.
103 : : This can be a node returned by GetConfigurationNode().
104 : : @param rArguments
105 : : The functor is called with arguments that are children of each
106 : : element of the container. The set of children is specified this
107 : : list.
108 : : @param rFunctor
109 : : The functor to be executed for some or all of the elements in
110 : : the given container.
111 : : */
112 : : static void ForAll (
113 : : const css::uno::Reference<css::container::XNameAccess>& rxContainer,
114 : : const ::std::vector<rtl::OUString>& rArguments,
115 : : const Functor& rFunctor);
116 : :
117 : : /** Fill a list with the string contents of all sub-elements in the given container.
118 : : @param rxContainer
119 : : The container is a XNameAccess to a list of the configuration.
120 : : This can be a node returned by GetConfigurationNode().
121 : : @param rsArgument
122 : : This specifies which string children of the elements in the
123 : : container are to be inserted into the list. The specified child
124 : : has to be of type string.
125 : : @param rList
126 : : The list to be filled.
127 : : */
128 : : static void FillList(
129 : : const css::uno::Reference<css::container::XNameAccess>& rxContainer,
130 : : const ::rtl::OUString& rsArgument,
131 : : ::std::vector<rtl::OUString>& rList);
132 : :
133 : : private:
134 : : css::uno::Reference<css::uno::XInterface> mxRoot;
135 : :
136 : : void Initialize (
137 : : const css::uno::Reference<css::lang::XMultiServiceFactory>& rxProvider,
138 : : const ::rtl::OUString& rsRootName,
139 : : const WriteMode eMode);
140 : : };
141 : :
142 : : } } // end of namespace sd::tools
143 : :
144 : : #endif
145 : :
146 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|