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