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 29*cdf0e10cSrcweir #ifndef EXTENSIONS_OOOIMPROVEMENT_CONFIGURATIONHELPER_HXX 30*cdf0e10cSrcweir #define EXTENSIONS_OOOIMPROVEMENT_CONFIGURATIONHELPER_HXX 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <com/sun/star/uno/XInterface.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp> 37*cdf0e10cSrcweir #include <rtl/ustring.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir namespace oooimprovement 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir #ifdef css 43*cdf0e10cSrcweir #error css defined globally 44*cdf0e10cSrcweir #endif 45*cdf0e10cSrcweir #define css ::com::sun::star 46*cdf0e10cSrcweir // Copy from comphelper module, we cant use that directly from an extension 47*cdf0e10cSrcweir class MyConfigurationHelper 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir public: 50*cdf0e10cSrcweir //----------------------------------------------- 51*cdf0e10cSrcweir /** specify all possible modes, which can be used to open a configuration access. 52*cdf0e10cSrcweir * 53*cdf0e10cSrcweir * @see openConfig() 54*cdf0e10cSrcweir * @see readDirectKey() 55*cdf0e10cSrcweir * @see writeDirectKey() 56*cdf0e10cSrcweir */ 57*cdf0e10cSrcweir enum EConfigurationModes 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir /// opens configuration in read/write mode (without LAZY writing!) 60*cdf0e10cSrcweir E_STANDARD = 0, 61*cdf0e10cSrcweir /// configuration will be opened readonly 62*cdf0e10cSrcweir E_READONLY = 1, 63*cdf0e10cSrcweir /// all localized nodes will be interpreted as css::uno::XInterface instead of interpreting it as atomic value nodes 64*cdf0e10cSrcweir E_ALL_LOCALES = 2, 65*cdf0e10cSrcweir /// enable lazy writing 66*cdf0e10cSrcweir E_LAZY_WRITE = 4 67*cdf0e10cSrcweir }; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir //----------------------------------------------- 70*cdf0e10cSrcweir /** returns access to the specified configuration package. 71*cdf0e10cSrcweir * 72*cdf0e10cSrcweir * This method should be used, if e.g. more then one request to the same 73*cdf0e10cSrcweir * configuration package is needed. The configuration access can be cached 74*cdf0e10cSrcweir * outside and used inbetween. 75*cdf0e10cSrcweir * 76*cdf0e10cSrcweir * @param xSMGR 77*cdf0e10cSrcweir * the uno service manager, which should be used to create the 78*cdf0e10cSrcweir * configuration access. 79*cdf0e10cSrcweir * 80*cdf0e10cSrcweir * @param sPackage 81*cdf0e10cSrcweir * the name of the configuration package. 82*cdf0e10cSrcweir * e.g. <ul> 83*cdf0e10cSrcweir * <li>org.openoffice.Office.Common</li> 84*cdf0e10cSrcweir * <li>org.openoffice.Office.Common/Menu</li> 85*cdf0e10cSrcweir * </ul> 86*cdf0e10cSrcweir * 87*cdf0e10cSrcweir * @param eMode 88*cdf0e10cSrcweir * specify the open mode for the returned configuration access. 89*cdf0e10cSrcweir * It's interpreted as a flag field and can be any usefull combination 90*cdf0e10cSrcweir * of values of EConfigurationModes. 91*cdf0e10cSrcweir * 92*cdf0e10cSrcweir * @throw css::uno::Any exceptions the underlying configuration can throw. 93*cdf0e10cSrcweir * E.g. css::uno::Exception if the configuration could not be opened. 94*cdf0e10cSrcweir */ 95*cdf0e10cSrcweir static css::uno::Reference< css::uno::XInterface> openConfig( 96*cdf0e10cSrcweir const css::uno::Reference< css::lang::XMultiServiceFactory> xSMGR, 97*cdf0e10cSrcweir const ::rtl::OUString& sPackage, 98*cdf0e10cSrcweir sal_Int32 eMode); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir //----------------------------------------------- 101*cdf0e10cSrcweir /** reads the value of an existing(!) configuration key, 102*cdf0e10cSrcweir * which is searched relative to the specified configuration access. 103*cdf0e10cSrcweir * 104*cdf0e10cSrcweir * This method must be used in combination with openConfig(). 105*cdf0e10cSrcweir * The cached configuration access must be provided here ... and 106*cdf0e10cSrcweir * all operations are made relativ to this access point. 107*cdf0e10cSrcweir * 108*cdf0e10cSrcweir * @param xCFG 109*cdf0e10cSrcweir * the configuration root, where sRelPath should be interpreted. 110*cdf0e10cSrcweir * as relativ path 111*cdf0e10cSrcweir * 112*cdf0e10cSrcweir * @param sRelPath 113*cdf0e10cSrcweir * path relative to xCFG parameter. 114*cdf0e10cSrcweir * 115*cdf0e10cSrcweir * @param sKey 116*cdf0e10cSrcweir * the configuration node, where we should read the value. 117*cdf0e10cSrcweir * 118*cdf0e10cSrcweir * @return [css.uno.css::uno::Any] 119*cdf0e10cSrcweir * the value of sKey. 120*cdf0e10cSrcweir * 121*cdf0e10cSrcweir * @throw css::uno::Any exceptions the underlying configuration can throw. 122*cdf0e10cSrcweir * E.g. css::container::NoSuchElementException if the specified 123*cdf0e10cSrcweir * key does not exists. 124*cdf0e10cSrcweir */ 125*cdf0e10cSrcweir static css::uno::Any readRelativeKey( 126*cdf0e10cSrcweir const css::uno::Reference< css::uno::XInterface> xCFG, 127*cdf0e10cSrcweir const ::rtl::OUString& sRelPath, 128*cdf0e10cSrcweir const ::rtl::OUString& sKey); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir //----------------------------------------------- 131*cdf0e10cSrcweir /** writes a new value for an existing(!) configuration key, 132*cdf0e10cSrcweir * which is searched relative to the specified configuration access. 133*cdf0e10cSrcweir * 134*cdf0e10cSrcweir * This method must be used in combination with openConfig(). 135*cdf0e10cSrcweir * The cached configuration access must be provided here ... and 136*cdf0e10cSrcweir * all operations are made relativ to this access point. 137*cdf0e10cSrcweir * 138*cdf0e10cSrcweir * @param xCFG 139*cdf0e10cSrcweir * the configuration root, where sRelPath should be interpreted. 140*cdf0e10cSrcweir * as relativ path 141*cdf0e10cSrcweir * 142*cdf0e10cSrcweir * @param sRelPath 143*cdf0e10cSrcweir * path relative to xCFG parameter. 144*cdf0e10cSrcweir * 145*cdf0e10cSrcweir * @param sKey 146*cdf0e10cSrcweir * the configuration node, where we should write the new value. 147*cdf0e10cSrcweir * 148*cdf0e10cSrcweir * @param aValue 149*cdf0e10cSrcweir * the new value for sKey. 150*cdf0e10cSrcweir * 151*cdf0e10cSrcweir * @throw css::uno::Any exceptions the underlying configuration can throw. 152*cdf0e10cSrcweir * E.g. css::container::NoSuchElementException if the specified 153*cdf0e10cSrcweir * key does not exists or css::uno::Exception if the provided configuration 154*cdf0e10cSrcweir * access does not allow writing for this key. 155*cdf0e10cSrcweir */ 156*cdf0e10cSrcweir static void writeRelativeKey( 157*cdf0e10cSrcweir const css::uno::Reference< css::uno::XInterface> xCFG, 158*cdf0e10cSrcweir const ::rtl::OUString& sRelPath, 159*cdf0e10cSrcweir const ::rtl::OUString& sKey, 160*cdf0e10cSrcweir const css::uno::Any& aValue); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir //----------------------------------------------- 163*cdf0e10cSrcweir /** commit all changes made on the specified configuration access. 164*cdf0e10cSrcweir * 165*cdf0e10cSrcweir * This method must be used in combination with openConfig(). 166*cdf0e10cSrcweir * The cached configuration access must be provided here. 167*cdf0e10cSrcweir * 168*cdf0e10cSrcweir * @param xCFG 169*cdf0e10cSrcweir * the configuration root, where changes should be commited. 170*cdf0e10cSrcweir * 171*cdf0e10cSrcweir * @throw css::uno::Any exceptions the underlying configuration can throw. 172*cdf0e10cSrcweir * E.g. uno::Exception if the provided configuration 173*cdf0e10cSrcweir * access does not allow writing for this set. 174*cdf0e10cSrcweir */ 175*cdf0e10cSrcweir static void flush(const css::uno::Reference< css::uno::XInterface>& xCFG); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir //----------------------------------------------- 178*cdf0e10cSrcweir /** does the same then openConfig() & readRelativeKey() together. 179*cdf0e10cSrcweir * 180*cdf0e10cSrcweir * This method should be used for reading one key at one code place only. 181*cdf0e10cSrcweir * Because it opens the specified configuration package, reads the key and 182*cdf0e10cSrcweir * closes the configuration again. 183*cdf0e10cSrcweir * 184*cdf0e10cSrcweir * So its not very usefull to use this method for reading multiple keys at the same time. 185*cdf0e10cSrcweir * (Excepting these keys exists inside different configuration packages ...)) 186*cdf0e10cSrcweir */ 187*cdf0e10cSrcweir static css::uno::Any readDirectKey( 188*cdf0e10cSrcweir const css::uno::Reference< css::lang::XMultiServiceFactory> xSMGR, 189*cdf0e10cSrcweir const ::rtl::OUString& sPackage, 190*cdf0e10cSrcweir const ::rtl::OUString& sRelPath, 191*cdf0e10cSrcweir const ::rtl::OUString& sKey, 192*cdf0e10cSrcweir sal_Int32 eMode); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir //----------------------------------------------- 195*cdf0e10cSrcweir /** does the same then openConfig() / writeRelativeKey() & flush() together. 196*cdf0e10cSrcweir * 197*cdf0e10cSrcweir * This method should be used for writing one key at one code place only. 198*cdf0e10cSrcweir * Because it opens the specified configuration package, writes the key, flush 199*cdf0e10cSrcweir * all changes and closes the configuration again. 200*cdf0e10cSrcweir * 201*cdf0e10cSrcweir * So its not very usefull to use this method for writing multiple keys at the same time. 202*cdf0e10cSrcweir * (Excepting these keys exists inside different configuration packages ...)) 203*cdf0e10cSrcweir */ 204*cdf0e10cSrcweir static void writeDirectKey( 205*cdf0e10cSrcweir const css::uno::Reference< css::lang::XMultiServiceFactory> xSMGR, 206*cdf0e10cSrcweir const ::rtl::OUString& sPackage, 207*cdf0e10cSrcweir const ::rtl::OUString& sRelPath, 208*cdf0e10cSrcweir const ::rtl::OUString& sKey, 209*cdf0e10cSrcweir const css::uno::Any& aValue, 210*cdf0e10cSrcweir sal_Int32 eMode); 211*cdf0e10cSrcweir }; 212*cdf0e10cSrcweir #undef css 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir #endif 215