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