1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski #ifndef __FRAMEWORK_PATTERN_CONFIGURATION_HXX_ 25*b1cdbd2cSJim Jagielski #define __FRAMEWORK_PATTERN_CONFIGURATION_HXX_ 26*b1cdbd2cSJim Jagielski 27*b1cdbd2cSJim Jagielski //_______________________________________________ 28*b1cdbd2cSJim Jagielski // own includes 29*b1cdbd2cSJim Jagielski 30*b1cdbd2cSJim Jagielski #include <services.h> 31*b1cdbd2cSJim Jagielski #include <general.h> 32*b1cdbd2cSJim Jagielski 33*b1cdbd2cSJim Jagielski //_______________________________________________ 34*b1cdbd2cSJim Jagielski // interface includes 35*b1cdbd2cSJim Jagielski #include <com/sun/star/uno/Sequence.hxx> 36*b1cdbd2cSJim Jagielski #include <com/sun/star/uno/Any.hxx> 37*b1cdbd2cSJim Jagielski 38*b1cdbd2cSJim Jagielski #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HXX_ 39*b1cdbd2cSJim Jagielski #include <com/sun/star/beans/PropertyValue.hpp> 40*b1cdbd2cSJim Jagielski #endif 41*b1cdbd2cSJim Jagielski #include <com/sun/star/uno/XInterface.hpp> 42*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XMultiServiceFactory.hpp> 43*b1cdbd2cSJim Jagielski 44*b1cdbd2cSJim Jagielski //_______________________________________________ 45*b1cdbd2cSJim Jagielski // other includes 46*b1cdbd2cSJim Jagielski #include <rtl/ustrbuf.hxx> 47*b1cdbd2cSJim Jagielski 48*b1cdbd2cSJim Jagielski //_______________________________________________ 49*b1cdbd2cSJim Jagielski // namespaces 50*b1cdbd2cSJim Jagielski 51*b1cdbd2cSJim Jagielski #ifndef css 52*b1cdbd2cSJim Jagielski namespace css = ::com::sun::star; 53*b1cdbd2cSJim Jagielski #endif 54*b1cdbd2cSJim Jagielski 55*b1cdbd2cSJim Jagielski namespace framework{ 56*b1cdbd2cSJim Jagielski namespace pattern{ 57*b1cdbd2cSJim Jagielski namespace configuration{ 58*b1cdbd2cSJim Jagielski 59*b1cdbd2cSJim Jagielski //_______________________________________________ 60*b1cdbd2cSJim Jagielski // definitions 61*b1cdbd2cSJim Jagielski 62*b1cdbd2cSJim Jagielski //----------------------------------------------- 63*b1cdbd2cSJim Jagielski class ConfigurationHelper 64*b1cdbd2cSJim Jagielski { 65*b1cdbd2cSJim Jagielski //------------------------------------------- 66*b1cdbd2cSJim Jagielski // const 67*b1cdbd2cSJim Jagielski public: 68*b1cdbd2cSJim Jagielski 69*b1cdbd2cSJim Jagielski //--------------------------------------- 70*b1cdbd2cSJim Jagielski /** @short allow opening of a configuration access 71*b1cdbd2cSJim Jagielski in different working modes. 72*b1cdbd2cSJim Jagielski 73*b1cdbd2cSJim Jagielski @descr All enum values must be useable as flags 74*b1cdbd2cSJim Jagielski mapped into a int32 value! 75*b1cdbd2cSJim Jagielski */ 76*b1cdbd2cSJim Jagielski enum EOpenMode 77*b1cdbd2cSJim Jagielski { 78*b1cdbd2cSJim Jagielski /// open it readonly (default=readwrite!) 79*b1cdbd2cSJim Jagielski E_READONLY = 1, 80*b1cdbd2cSJim Jagielski /// disable fallback handling for localized cfg nodes 81*b1cdbd2cSJim Jagielski E_ALL_LOCALES = 2 82*b1cdbd2cSJim Jagielski }; 83*b1cdbd2cSJim Jagielski 84*b1cdbd2cSJim Jagielski //------------------------------------------- 85*b1cdbd2cSJim Jagielski // interface 86*b1cdbd2cSJim Jagielski public: 87*b1cdbd2cSJim Jagielski 88*b1cdbd2cSJim Jagielski //--------------------------------------- 89*b1cdbd2cSJim Jagielski /** 90*b1cdbd2cSJim Jagielski @short opens a configuration access. 91*b1cdbd2cSJim Jagielski 92*b1cdbd2cSJim Jagielski @descr TODO 93*b1cdbd2cSJim Jagielski 94*b1cdbd2cSJim Jagielski @param xSMGR 95*b1cdbd2cSJim Jagielski this method need an uno service manager for internal work. 96*b1cdbd2cSJim Jagielski 97*b1cdbd2cSJim Jagielski @param sPackage 98*b1cdbd2cSJim Jagielski name the configuration file. 99*b1cdbd2cSJim Jagielski e.g. "/.org.openoffice.Setup" 100*b1cdbd2cSJim Jagielski Note: It must start with "/" but end without(!) "/"! 101*b1cdbd2cSJim Jagielski 102*b1cdbd2cSJim Jagielski @param sRelPath 103*b1cdbd2cSJim Jagielski describe the relativ path of the requested key inside 104*b1cdbd2cSJim Jagielski the specified package. 105*b1cdbd2cSJim Jagielski e.g. "Office/Factories" 106*b1cdbd2cSJim Jagielski Note: Its not allowed to start or end with a "/"! 107*b1cdbd2cSJim Jagielski Further you must use encoded path elements if 108*b1cdbd2cSJim Jagielski e.g. set nodes are involved. 109*b1cdbd2cSJim Jagielski 110*b1cdbd2cSJim Jagielski @param nOpenFlags 111*b1cdbd2cSJim Jagielski force opening of the configuration access in special mode. 112*b1cdbd2cSJim Jagielski see enum EOpenMode for further informations. 113*b1cdbd2cSJim Jagielski */ openConfig(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR,const::rtl::OUString & sPackage,const::rtl::OUString & sRelPath,sal_Int32 nOpenFlags)114*b1cdbd2cSJim Jagielski static css::uno::Reference< css::uno::XInterface > openConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , 115*b1cdbd2cSJim Jagielski const ::rtl::OUString& sPackage , 116*b1cdbd2cSJim Jagielski const ::rtl::OUString& sRelPath , 117*b1cdbd2cSJim Jagielski sal_Int32 nOpenFlags) 118*b1cdbd2cSJim Jagielski { 119*b1cdbd2cSJim Jagielski static ::rtl::OUString PATH_SEPERATOR = ::rtl::OUString::createFromAscii("/"); 120*b1cdbd2cSJim Jagielski 121*b1cdbd2cSJim Jagielski css::uno::Reference< css::uno::XInterface > xCFG; 122*b1cdbd2cSJim Jagielski 123*b1cdbd2cSJim Jagielski try 124*b1cdbd2cSJim Jagielski { 125*b1cdbd2cSJim Jagielski css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider( 126*b1cdbd2cSJim Jagielski xSMGR->createInstance(SERVICENAME_CFGPROVIDER), css::uno::UNO_QUERY_THROW); 127*b1cdbd2cSJim Jagielski 128*b1cdbd2cSJim Jagielski ::rtl::OUStringBuffer sPath(1024); 129*b1cdbd2cSJim Jagielski sPath.append(sPackage ); 130*b1cdbd2cSJim Jagielski sPath.append(PATH_SEPERATOR); 131*b1cdbd2cSJim Jagielski sPath.append(sRelPath ); 132*b1cdbd2cSJim Jagielski 133*b1cdbd2cSJim Jagielski sal_Bool bReadOnly = ((nOpenFlags & ConfigurationHelper::E_READONLY ) == ConfigurationHelper::E_READONLY ); 134*b1cdbd2cSJim Jagielski sal_Bool bAllLocales = ((nOpenFlags & ConfigurationHelper::E_ALL_LOCALES) == ConfigurationHelper::E_ALL_LOCALES); 135*b1cdbd2cSJim Jagielski 136*b1cdbd2cSJim Jagielski sal_Int32 c = 1; 137*b1cdbd2cSJim Jagielski if (bAllLocales) 138*b1cdbd2cSJim Jagielski c = 2; 139*b1cdbd2cSJim Jagielski 140*b1cdbd2cSJim Jagielski css::uno::Sequence< css::uno::Any > lParams(c); 141*b1cdbd2cSJim Jagielski css::beans::PropertyValue aParam; 142*b1cdbd2cSJim Jagielski 143*b1cdbd2cSJim Jagielski aParam.Name = ::rtl::OUString::createFromAscii("nodepath"); 144*b1cdbd2cSJim Jagielski aParam.Value <<= sPath.makeStringAndClear(); 145*b1cdbd2cSJim Jagielski lParams[0] <<= aParam; 146*b1cdbd2cSJim Jagielski 147*b1cdbd2cSJim Jagielski if (bAllLocales) 148*b1cdbd2cSJim Jagielski { 149*b1cdbd2cSJim Jagielski aParam.Name = ::rtl::OUString::createFromAscii("*"); 150*b1cdbd2cSJim Jagielski aParam.Value <<= sal_True; 151*b1cdbd2cSJim Jagielski lParams[1] <<= aParam; 152*b1cdbd2cSJim Jagielski } 153*b1cdbd2cSJim Jagielski 154*b1cdbd2cSJim Jagielski if (bReadOnly) 155*b1cdbd2cSJim Jagielski xCFG = xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS, lParams); 156*b1cdbd2cSJim Jagielski else 157*b1cdbd2cSJim Jagielski xCFG = xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGUPDATEACCESS, lParams); 158*b1cdbd2cSJim Jagielski } 159*b1cdbd2cSJim Jagielski catch(const css::uno::RuntimeException& exRun) 160*b1cdbd2cSJim Jagielski { throw exRun; } 161*b1cdbd2cSJim Jagielski catch(const css::uno::Exception&) 162*b1cdbd2cSJim Jagielski { xCFG.clear(); } 163*b1cdbd2cSJim Jagielski 164*b1cdbd2cSJim Jagielski return xCFG; 165*b1cdbd2cSJim Jagielski } 166*b1cdbd2cSJim Jagielski }; 167*b1cdbd2cSJim Jagielski 168*b1cdbd2cSJim Jagielski } // namespace configuration 169*b1cdbd2cSJim Jagielski } // namespace pattern 170*b1cdbd2cSJim Jagielski } // namespace framework 171*b1cdbd2cSJim Jagielski 172*b1cdbd2cSJim Jagielski #endif // __FRAMEWORK_PATTERN_CONFIGURATION_HXX_ 173