1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ConfigurationAccess.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_TOOLS_CONFIGURATION_ACCESS_HXX
32 #define SD_TOOLS_CONFIGURATION_ACCESS_HXX
34 #include <rtl/ustring.hxx>
35 #include <com/sun/star/container/XNameAccess.hpp>
36 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <boost/function.hpp>
42 namespace css
= ::com::sun::star
;
44 namespace sd
{ namespace tools
{
46 /** This class gives access to the configuration. Create an object of this
47 class for one node of the configuration. This will be the root node.
48 Its children are then accessible through the new ConfigurationAccess
51 class ConfigurationAccess
54 enum WriteMode
{ READ_WRITE
, READ_ONLY
};
56 /** Create a new object to access the configuration entries below the
61 This flag specifies whether to give read-write or read-only
65 const ::rtl::OUString
& rsRootName
,
66 const WriteMode eMode
);
69 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
70 const ::rtl::OUString
& rsRootName
,
71 const WriteMode eMode
);
73 /** Return a configuration node below the root of the called object.
75 The relative path from the root (as given the constructor) to
78 The type of the returned node varies with the requested node.
79 It is empty when the node was not found.
81 css::uno::Any
GetConfigurationNode (
82 const ::rtl::OUString
& rsPathToNode
);
84 /** Return a configuration node below the given node.
86 The node that acts as root to the given relative path.
88 The relative path from the given node to the requested node.
90 The type of the returned node varies with the requested node.
91 It is empty when the node was not found.
93 static css::uno::Any
GetConfigurationNode (
94 const css::uno::Reference
<css::container::XHierarchicalNameAccess
>& rxNode
,
95 const ::rtl::OUString
& rsPathToNode
);
97 /** Write any changes that have been made back to the configuration.
98 This call is ignored when the called ConfigurationAccess object was
99 not create with read-write mode.
101 void CommitChanges (void);
103 /** This functor is typically called for every item in a set. Its two
104 parameters are the name of key item (often of no further interest)
105 and the value of the item.
107 typedef ::boost::function
<void(
108 const ::rtl::OUString
&,
109 const std::vector
<css::uno::Any
>&) > Functor
;
111 /** Execute a functor for all elements of the given container.
113 The container is a XNameAccess to a list of the configuration.
114 This can be a node returned by GetConfigurationNode().
116 The functor is called with arguments that are children of each
117 element of the container. The set of children is specified this
120 The functor to be executed for some or all of the elements in
124 const css::uno::Reference
<css::container::XNameAccess
>& rxContainer
,
125 const ::std::vector
<rtl::OUString
>& rArguments
,
126 const Functor
& rFunctor
);
128 /** Fill a list with the string contents of all sub-elements in the given container.
130 The container is a XNameAccess to a list of the configuration.
131 This can be a node returned by GetConfigurationNode().
133 This specifies which string children of the elements in the
134 container are to be inserted into the list. The specified child
135 has to be of type string.
137 The list to be filled.
139 static void FillList(
140 const css::uno::Reference
<css::container::XNameAccess
>& rxContainer
,
141 const ::rtl::OUString
& rsArgument
,
142 ::std::vector
<rtl::OUString
>& rList
);
145 css::uno::Reference
<css::uno::XInterface
> mxRoot
;
148 const css::uno::Reference
<css::lang::XMultiServiceFactory
>& rxProvider
,
149 const ::rtl::OUString
& rsRootName
,
150 const WriteMode eMode
);
153 } } // end of namespace sd::tools