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