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 // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_framework.hxx" 30*cdf0e10cSrcweir #include <accelerators/presethandler.hxx> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir //_______________________________________________ 33*cdf0e10cSrcweir // own includes 34*cdf0e10cSrcweir #include <classes/fwkresid.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include "classes/resource.hrc" 37*cdf0e10cSrcweir #include <threadhelp/readguard.hxx> 38*cdf0e10cSrcweir #include <threadhelp/writeguard.hxx> 39*cdf0e10cSrcweir #include <services.h> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //_______________________________________________ 42*cdf0e10cSrcweir // interface includes 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #ifndef __COM_SUN_STAR_CONFIGURATION_CORRUPTEDUICONFIGURATIONEXCEPTION_HPP_ 45*cdf0e10cSrcweir #include <com/sun/star/configuration/CorruptedUIConfigurationException.hpp> 46*cdf0e10cSrcweir #endif 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #ifndef __COM_SUN_STAR_CONTAINER_NOSUCHELEMENTEXCEPTION_HPP_ 49*cdf0e10cSrcweir #include <com/sun/star/container/NoSuchElementException.hpp> 50*cdf0e10cSrcweir #endif 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #ifndef __COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ 53*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 54*cdf0e10cSrcweir #endif 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #ifndef __COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ 57*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #ifndef __COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_ 61*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 62*cdf0e10cSrcweir #endif 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir #ifndef __COM_SUN_STAR_EMBED_XTRANSACTEDOBJECT_HPP_ 65*cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp> 66*cdf0e10cSrcweir #endif 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #ifndef __COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ 69*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 70*cdf0e10cSrcweir #endif 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir //_______________________________________________ 73*cdf0e10cSrcweir // other includes 74*cdf0e10cSrcweir #include <vcl/svapp.hxx> 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir #ifndef _RTL_USTRBUF_HXX 77*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 78*cdf0e10cSrcweir #endif 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir //_______________________________________________ 81*cdf0e10cSrcweir // const 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir #define SUBSTORAGE_GLOBAL DECLARE_ASCII("global" ) 84*cdf0e10cSrcweir #define SUBSTORAGE_MODULES DECLARE_ASCII("modules") 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir #define BASEPATH_SHARE_LAYER DECLARE_ASCII("UIConfig" ) 87*cdf0e10cSrcweir #define BASEPATH_USER_LAYER DECLARE_ASCII("UserConfig") 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir #define RELPATH_SHARE_LAYER DECLARE_ASCII("soffice.cfg") 90*cdf0e10cSrcweir #define RELPATH_USER_LAYER DECLARE_ASCII("soffice.cfg") 91*cdf0e10cSrcweir // #define RELPATH_SHARE_LAYER DECLARE_ASCII("soffice.cfg/uiconfig.zip") 92*cdf0e10cSrcweir // #define RELPATH_USER_LAYER DECLARE_ASCII("soffice.cfg/uiconfig.zip") 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir #define FILE_EXTENSION DECLARE_ASCII(".xml") 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir #define PATH_SEPERATOR DECLARE_ASCII("/") 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir static const ::sal_Int32 ID_CORRUPT_UICONFIG_SHARE = 1; 99*cdf0e10cSrcweir static const ::sal_Int32 ID_CORRUPT_UICONFIG_USER = 2; 100*cdf0e10cSrcweir static const ::sal_Int32 ID_CORRUPT_UICONFIG_GENERAL = 3; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir //_______________________________________________ 103*cdf0e10cSrcweir // namespace 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir namespace framework 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir //----------------------------------------------- 109*cdf0e10cSrcweir ::rtl::OUString PresetHandler::PRESET_DEFAULT() 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir static ::rtl::OUString RSTYPE = DECLARE_ASCII("default"); 112*cdf0e10cSrcweir return RSTYPE; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir //----------------------------------------------- 116*cdf0e10cSrcweir ::rtl::OUString PresetHandler::TARGET_CURRENT() 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir static ::rtl::OUString RSTYPE = DECLARE_ASCII("current"); 119*cdf0e10cSrcweir return RSTYPE; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //----------------------------------------------- 123*cdf0e10cSrcweir ::rtl::OUString PresetHandler::RESOURCETYPE_MENUBAR() 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir static ::rtl::OUString RSTYPE = DECLARE_ASCII("menubar"); 126*cdf0e10cSrcweir return RSTYPE; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir //----------------------------------------------- 130*cdf0e10cSrcweir ::rtl::OUString PresetHandler::RESOURCETYPE_TOOLBAR() 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir static ::rtl::OUString RSTYPE = DECLARE_ASCII("toolbar"); 133*cdf0e10cSrcweir return RSTYPE; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //----------------------------------------------- 137*cdf0e10cSrcweir ::rtl::OUString PresetHandler::RESOURCETYPE_ACCELERATOR() 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir static ::rtl::OUString RSTYPE = DECLARE_ASCII("accelerator"); 140*cdf0e10cSrcweir return RSTYPE; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir //----------------------------------------------- 144*cdf0e10cSrcweir ::rtl::OUString PresetHandler::RESOURCETYPE_STATUSBAR() 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir static ::rtl::OUString RSTYPE = DECLARE_ASCII("statusbar"); 147*cdf0e10cSrcweir return RSTYPE; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir //----------------------------------------------- 151*cdf0e10cSrcweir PresetHandler::PresetHandler(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR) 152*cdf0e10cSrcweir : ThreadHelpBase (&Application::GetSolarMutex() ) 153*cdf0e10cSrcweir , m_xSMGR (xSMGR ) 154*cdf0e10cSrcweir , m_aSharedStorages ( ) 155*cdf0e10cSrcweir , m_lDocumentStorages(xSMGR ) 156*cdf0e10cSrcweir , m_aLocale (::comphelper::Locale::X_NOTRANSLATE()) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //----------------------------------------------- 161*cdf0e10cSrcweir PresetHandler::PresetHandler(const PresetHandler& rCopy) 162*cdf0e10cSrcweir : ThreadHelpBase (&Application::GetSolarMutex() ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir m_xSMGR = rCopy.m_xSMGR; 165*cdf0e10cSrcweir m_eConfigType = rCopy.m_eConfigType; 166*cdf0e10cSrcweir m_sResourceType = rCopy.m_sResourceType; 167*cdf0e10cSrcweir m_sModule = rCopy.m_sModule; 168*cdf0e10cSrcweir m_aSharedStorages = rCopy.m_aSharedStorages; 169*cdf0e10cSrcweir m_xWorkingStorageShare = rCopy.m_xWorkingStorageShare; 170*cdf0e10cSrcweir m_xWorkingStorageNoLang = rCopy.m_xWorkingStorageNoLang; 171*cdf0e10cSrcweir m_xWorkingStorageUser = rCopy.m_xWorkingStorageUser; 172*cdf0e10cSrcweir m_lPresets = rCopy.m_lPresets; 173*cdf0e10cSrcweir m_lTargets = rCopy.m_lTargets; 174*cdf0e10cSrcweir m_aLocale = rCopy.m_aLocale; 175*cdf0e10cSrcweir m_lDocumentStorages = rCopy.m_lDocumentStorages; 176*cdf0e10cSrcweir m_sRelPathShare = rCopy.m_sRelPathShare; 177*cdf0e10cSrcweir m_sRelPathNoLang = rCopy.m_sRelPathNoLang; 178*cdf0e10cSrcweir m_sRelPathUser = rCopy.m_sRelPathUser; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir //----------------------------------------------- 182*cdf0e10cSrcweir PresetHandler::~PresetHandler() 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir m_xWorkingStorageShare.clear(); 185*cdf0e10cSrcweir m_xWorkingStorageNoLang.clear(); 186*cdf0e10cSrcweir m_xWorkingStorageUser.clear(); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir /* #i46497# 189*cdf0e10cSrcweir Dont call forgetCachedStorages() here for shared storages. 190*cdf0e10cSrcweir Because we opened different sub storages by using openPath(). 191*cdf0e10cSrcweir And every already open path was reused and referenced (means it's 192*cdf0e10cSrcweir ref count was increased!) 193*cdf0e10cSrcweir So now we have to release our ref counts to these shared storages 194*cdf0e10cSrcweir only ... and not to free all used storages. 195*cdf0e10cSrcweir Otherwise we will disconnect all other open configuration access 196*cdf0e10cSrcweir objects which base on these storages. 197*cdf0e10cSrcweir */ 198*cdf0e10cSrcweir m_aSharedStorages->m_lStoragesShare.closePath(m_sRelPathShare); 199*cdf0e10cSrcweir m_aSharedStorages->m_lStoragesUser.closePath (m_sRelPathUser ); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir /* On the other side closePath() is not needed for our special handled 202*cdf0e10cSrcweir document storage. Because it's not shared with others ... so we can 203*cdf0e10cSrcweir free it. 204*cdf0e10cSrcweir */ 205*cdf0e10cSrcweir m_lDocumentStorages.forgetCachedStorages(); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir //----------------------------------------------- 209*cdf0e10cSrcweir void PresetHandler::forgetCachedStorages() 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir // SAFE -> ---------------------------------- 212*cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir if (m_eConfigType == E_DOCUMENT) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir m_xWorkingStorageShare.clear(); 217*cdf0e10cSrcweir m_xWorkingStorageNoLang.clear(); 218*cdf0e10cSrcweir m_xWorkingStorageUser.clear(); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir m_lDocumentStorages.forgetCachedStorages(); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir aWriteLock.unlock(); 224*cdf0e10cSrcweir // <- SAFE ---------------------------------- 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir //----------------------------------------------- 228*cdf0e10cSrcweir ::rtl::OUString lcl_getLocalizedMessage(::sal_Int32 nID) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir ::rtl::OUString sMessage = ::rtl::OUString::createFromAscii("Unknown error."); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir switch(nID) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir case ID_CORRUPT_UICONFIG_SHARE : 235*cdf0e10cSrcweir sMessage = ::rtl::OUString( String( FwkResId( STR_CORRUPT_UICFG_SHARE ))); 236*cdf0e10cSrcweir break; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir case ID_CORRUPT_UICONFIG_USER : 239*cdf0e10cSrcweir sMessage = ::rtl::OUString( String( FwkResId( STR_CORRUPT_UICFG_USER ))); 240*cdf0e10cSrcweir break; 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir case ID_CORRUPT_UICONFIG_GENERAL : 243*cdf0e10cSrcweir sMessage = ::rtl::OUString( String( FwkResId( STR_CORRUPT_UICFG_GENERAL ))); 244*cdf0e10cSrcweir break; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir return sMessage; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir //----------------------------------------------- 251*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > PresetHandler::getOrCreateRootStorageShare() 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xRoot = m_aSharedStorages->m_lStoragesShare.getRootStorage(); 254*cdf0e10cSrcweir if (xRoot.is()) 255*cdf0e10cSrcweir return xRoot; 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir // SAFE -> ---------------------------------- 258*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 259*cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 260*cdf0e10cSrcweir aReadLock.unlock(); 261*cdf0e10cSrcweir // <- SAFE ---------------------------------- 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xPathSettings( 264*cdf0e10cSrcweir xSMGR->createInstance(SERVICENAME_PATHSETTINGS), 265*cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir ::rtl::OUString sShareLayer; 268*cdf0e10cSrcweir xPathSettings->getPropertyValue(BASEPATH_SHARE_LAYER) >>= sShareLayer; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir // "UIConfig" is a "multi path" ... use first part only here! 271*cdf0e10cSrcweir sal_Int32 nPos = sShareLayer.indexOf(';'); 272*cdf0e10cSrcweir if (nPos > 0) 273*cdf0e10cSrcweir sShareLayer = sShareLayer.copy(0, nPos); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // Note: May be an user uses URLs without a final slash! Check it ... 276*cdf0e10cSrcweir nPos = sShareLayer.lastIndexOf('/'); 277*cdf0e10cSrcweir if (nPos != sShareLayer.getLength()-1) 278*cdf0e10cSrcweir sShareLayer += ::rtl::OUString::createFromAscii("/"); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir sShareLayer += RELPATH_SHARE_LAYER; // folder 281*cdf0e10cSrcweir /* 282*cdf0e10cSrcweir // TODO remove me! 283*cdf0e10cSrcweir // Attention: This is temp. workaround ... We create a temp. storage file 284*cdf0e10cSrcweir // based of a sytem directory. This must be used so, till the storage implementation 285*cdf0e10cSrcweir // can work on directories too. 286*cdf0e10cSrcweir */ 287*cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lArgs(2); 288*cdf0e10cSrcweir lArgs[0] <<= sShareLayer; 289*cdf0e10cSrcweir lArgs[1] <<= css::embed::ElementModes::READ | css::embed::ElementModes::NOCREATE; 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > xStorageFactory(xSMGR->createInstance(SERVICENAME_FILESYSTEMSTORAGEFACTORY) , css::uno::UNO_QUERY_THROW); 292*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xStorage; 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir try 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir xStorage = css::uno::Reference< css::embed::XStorage >(xStorageFactory->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir throw css::configuration::CorruptedUIConfigurationException( 301*cdf0e10cSrcweir lcl_getLocalizedMessage(ID_CORRUPT_UICONFIG_SHARE), 302*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >(), 303*cdf0e10cSrcweir ex.Message); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir m_aSharedStorages->m_lStoragesShare.setRootStorage(xStorage); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir return xStorage; 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir //----------------------------------------------- 312*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > PresetHandler::getOrCreateRootStorageUser() 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xRoot = m_aSharedStorages->m_lStoragesUser.getRootStorage(); 315*cdf0e10cSrcweir if (xRoot.is()) 316*cdf0e10cSrcweir return xRoot; 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir // SAFE -> ---------------------------------- 319*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 320*cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 321*cdf0e10cSrcweir aReadLock.unlock(); 322*cdf0e10cSrcweir // <- SAFE ---------------------------------- 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xPathSettings( 325*cdf0e10cSrcweir xSMGR->createInstance(SERVICENAME_PATHSETTINGS), 326*cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir ::rtl::OUString sUserLayer; 329*cdf0e10cSrcweir xPathSettings->getPropertyValue(BASEPATH_USER_LAYER) >>= sUserLayer ; 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir // Note: May be an user uses URLs without a final slash! Check it ... 332*cdf0e10cSrcweir sal_Int32 nPos = sUserLayer.lastIndexOf('/'); 333*cdf0e10cSrcweir if (nPos != sUserLayer.getLength()-1) 334*cdf0e10cSrcweir sUserLayer += ::rtl::OUString::createFromAscii("/"); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir sUserLayer += RELPATH_USER_LAYER; // storage file 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lArgs(2); 339*cdf0e10cSrcweir lArgs[0] <<= sUserLayer; 340*cdf0e10cSrcweir lArgs[1] <<= css::embed::ElementModes::READWRITE; 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > xStorageFactory(xSMGR->createInstance(SERVICENAME_FILESYSTEMSTORAGEFACTORY) , css::uno::UNO_QUERY_THROW); 343*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xStorage; 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir try 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir xStorage = css::uno::Reference< css::embed::XStorage >(xStorageFactory->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW); 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir throw css::configuration::CorruptedUIConfigurationException( 352*cdf0e10cSrcweir lcl_getLocalizedMessage(ID_CORRUPT_UICONFIG_USER), 353*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >(), 354*cdf0e10cSrcweir ex.Message); 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir m_aSharedStorages->m_lStoragesUser.setRootStorage(xStorage); 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir return xStorage; 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir //----------------------------------------------- 363*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > PresetHandler::getWorkingStorageShare() 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir // SAFE -> ---------------------------------- 366*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 367*cdf0e10cSrcweir return m_xWorkingStorageShare; 368*cdf0e10cSrcweir // <- SAFE ---------------------------------- 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir //----------------------------------------------- 372*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > PresetHandler::getWorkingStorageUser() 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir // SAFE -> ---------------------------------- 375*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 376*cdf0e10cSrcweir return m_xWorkingStorageUser; 377*cdf0e10cSrcweir // <- SAFE ---------------------------------- 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir //----------------------------------------------- 381*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > PresetHandler::getParentStorageShare(const css::uno::Reference< css::embed::XStorage >& /*xChild*/) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir // SAFE -> ---------------------------------- 384*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 385*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xWorking = m_xWorkingStorageShare; 386*cdf0e10cSrcweir aReadLock.unlock(); 387*cdf0e10cSrcweir // <- SAFE ---------------------------------- 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir return m_aSharedStorages->m_lStoragesShare.getParentStorage(xWorking); 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir //----------------------------------------------- 393*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > PresetHandler::getParentStorageUser(const css::uno::Reference< css::embed::XStorage >& /*xChild*/) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir // SAFE -> ---------------------------------- 396*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 397*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xWorking = m_xWorkingStorageUser; 398*cdf0e10cSrcweir aReadLock.unlock(); 399*cdf0e10cSrcweir // <- SAFE ---------------------------------- 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir return m_aSharedStorages->m_lStoragesUser.getParentStorage(xWorking); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir //----------------------------------------------- 405*cdf0e10cSrcweir void PresetHandler::connectToResource( PresetHandler::EConfigType eConfigType , 406*cdf0e10cSrcweir const ::rtl::OUString& sResource , 407*cdf0e10cSrcweir const ::rtl::OUString& sModule , 408*cdf0e10cSrcweir const css::uno::Reference< css::embed::XStorage >& xDocumentRoot, 409*cdf0e10cSrcweir const ::comphelper::Locale& aLocale ) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir // TODO free all current open storages! 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir // SAFE -> ---------------------------------- 414*cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir m_eConfigType = eConfigType ; 417*cdf0e10cSrcweir m_sResourceType = sResource ; 418*cdf0e10cSrcweir m_sModule = sModule ; 419*cdf0e10cSrcweir m_aLocale = aLocale ; 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir aWriteLock.unlock(); 422*cdf0e10cSrcweir // <- SAFE ---------------------------------- 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xShare; 425*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xNoLang; 426*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xUser; 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir // special case for documents 429*cdf0e10cSrcweir // use outside root storage, if we run in E_DOCUMENT mode! 430*cdf0e10cSrcweir if (eConfigType == E_DOCUMENT) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir if (!xDocumentRoot.is()) 433*cdf0e10cSrcweir throw css::uno::RuntimeException( 434*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("There is valid root storage, where the UI configuration can work on."), 435*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >()); 436*cdf0e10cSrcweir m_lDocumentStorages.setRootStorage(xDocumentRoot); 437*cdf0e10cSrcweir xShare = xDocumentRoot; 438*cdf0e10cSrcweir xUser = xDocumentRoot; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir else 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir xShare = getOrCreateRootStorageShare(); 443*cdf0e10cSrcweir xUser = getOrCreateRootStorageUser(); 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir // #...# 447*cdf0e10cSrcweir try 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir // a) inside share layer we should not create any new structures ... We jave to use 451*cdf0e10cSrcweir // existing ones only! 452*cdf0e10cSrcweir // b) inside user layer we can (SOFT mode!) but sometimes we shouldnt (HARD mode!) 453*cdf0e10cSrcweir // create new empty structures. We should preferr using of any existing structure. 454*cdf0e10cSrcweir sal_Int32 eShareMode = (css::embed::ElementModes::READ | css::embed::ElementModes::NOCREATE); 455*cdf0e10cSrcweir sal_Int32 eUserMode = (css::embed::ElementModes::READWRITE ); 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir ::rtl::OUStringBuffer sRelPathBuf(1024); 458*cdf0e10cSrcweir ::rtl::OUString sRelPathShare; 459*cdf0e10cSrcweir ::rtl::OUString sRelPathNoLang; 460*cdf0e10cSrcweir ::rtl::OUString sRelPathUser; 461*cdf0e10cSrcweir switch(eConfigType) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir case E_GLOBAL : 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir sRelPathBuf.append(SUBSTORAGE_GLOBAL); 466*cdf0e10cSrcweir sRelPathBuf.append(PATH_SEPERATOR ); 467*cdf0e10cSrcweir sRelPathBuf.append(sResource ); 468*cdf0e10cSrcweir sRelPathShare = sRelPathBuf.makeStringAndClear(); 469*cdf0e10cSrcweir sRelPathUser = sRelPathShare; 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir xShare = impl_openPathIgnoringErrors(sRelPathShare, eShareMode, sal_True ); 472*cdf0e10cSrcweir xUser = impl_openPathIgnoringErrors(sRelPathUser , eUserMode , sal_False); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir break; 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir case E_MODULES : 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir sRelPathBuf.append(SUBSTORAGE_MODULES); 479*cdf0e10cSrcweir sRelPathBuf.append(PATH_SEPERATOR ); 480*cdf0e10cSrcweir sRelPathBuf.append(sModule ); 481*cdf0e10cSrcweir sRelPathBuf.append(PATH_SEPERATOR ); 482*cdf0e10cSrcweir sRelPathBuf.append(sResource ); 483*cdf0e10cSrcweir sRelPathShare = sRelPathBuf.makeStringAndClear(); 484*cdf0e10cSrcweir sRelPathUser = sRelPathShare; 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir xShare = impl_openPathIgnoringErrors(sRelPathShare, eShareMode, sal_True ); 487*cdf0e10cSrcweir xUser = impl_openPathIgnoringErrors(sRelPathUser , eUserMode , sal_False); 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir break; 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir case E_DOCUMENT : 492*cdf0e10cSrcweir { 493*cdf0e10cSrcweir // A document does not have a share layer in real. 494*cdf0e10cSrcweir // It has one layer only, and this one should be opened READ_WRITE. 495*cdf0e10cSrcweir // So we open the user layer here only and set the share layer equals to it .-) 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir sRelPathBuf.append(sResource); 498*cdf0e10cSrcweir sRelPathUser = sRelPathBuf.makeStringAndClear(); 499*cdf0e10cSrcweir sRelPathShare = sRelPathUser; 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir try 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir xUser = m_lDocumentStorages.openPath(sRelPathUser , eUserMode ); 504*cdf0e10cSrcweir xShare = xUser; 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir catch(const css::uno::RuntimeException& exRun) 507*cdf0e10cSrcweir { throw exRun; } 508*cdf0e10cSrcweir catch(const css::uno::Exception&) 509*cdf0e10cSrcweir { xShare.clear(); xUser.clear(); } 510*cdf0e10cSrcweir } 511*cdf0e10cSrcweir break; 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir // Non-localized global share 515*cdf0e10cSrcweir xNoLang = xShare; 516*cdf0e10cSrcweir sRelPathNoLang = sRelPathShare; 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir if ( 519*cdf0e10cSrcweir (aLocale != ::comphelper::Locale::X_NOTRANSLATE()) && // localized level? 520*cdf0e10cSrcweir (eConfigType != E_DOCUMENT ) // no localization in document mode! 521*cdf0e10cSrcweir ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir // First try to find the right localized set inside share layer. 524*cdf0e10cSrcweir // Fallbacks are allowed there. 525*cdf0e10cSrcweir ::comphelper::Locale aShareLocale = aLocale ; 526*cdf0e10cSrcweir ::rtl::OUString sLocalizedSharePath(sRelPathShare); 527*cdf0e10cSrcweir sal_Bool bAllowFallbacks = sal_True ; 528*cdf0e10cSrcweir xShare = impl_openLocalizedPathIgnoringErrors(sLocalizedSharePath, eShareMode, sal_True , aShareLocale, bAllowFallbacks); 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir // The try to locate the right sub dir inside user layer ... without using fallbacks! 531*cdf0e10cSrcweir // Normaly the corresponding sub dir should be created matching the specified locale. 532*cdf0e10cSrcweir // Because we allow creation of storages inside user layer by default. 533*cdf0e10cSrcweir ::comphelper::Locale aUserLocale = aLocale ; 534*cdf0e10cSrcweir ::rtl::OUString sLocalizedUserPath(sRelPathUser); 535*cdf0e10cSrcweir bAllowFallbacks = sal_False ; 536*cdf0e10cSrcweir xUser = impl_openLocalizedPathIgnoringErrors(sLocalizedUserPath, eUserMode , sal_False, aUserLocale, bAllowFallbacks); 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir sRelPathShare = sLocalizedSharePath; 539*cdf0e10cSrcweir sRelPathUser = sLocalizedUserPath ; 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir // read content of level 3 (presets, targets) 543*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess ; 544*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lNames ; 545*cdf0e10cSrcweir const ::rtl::OUString* pNames ; 546*cdf0e10cSrcweir sal_Int32 c ; 547*cdf0e10cSrcweir sal_Int32 i ; 548*cdf0e10cSrcweir OUStringList lPresets; 549*cdf0e10cSrcweir OUStringList lTargets; 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir // read preset names of share layer 552*cdf0e10cSrcweir xAccess = css::uno::Reference< css::container::XNameAccess >(xShare, css::uno::UNO_QUERY); 553*cdf0e10cSrcweir if (xAccess.is()) 554*cdf0e10cSrcweir { 555*cdf0e10cSrcweir lNames = xAccess->getElementNames(); 556*cdf0e10cSrcweir pNames = lNames.getConstArray(); 557*cdf0e10cSrcweir c = lNames.getLength(); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir for (i=0; i<c; ++i) 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir ::rtl::OUString sTemp = pNames[i]; 562*cdf0e10cSrcweir sal_Int32 nPos = sTemp.indexOf(FILE_EXTENSION); 563*cdf0e10cSrcweir if (nPos > -1) 564*cdf0e10cSrcweir sTemp = sTemp.copy(0,nPos); 565*cdf0e10cSrcweir lPresets.push_back(sTemp); 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir // read preset names of user layer 570*cdf0e10cSrcweir xAccess = css::uno::Reference< css::container::XNameAccess >(xUser, css::uno::UNO_QUERY); 571*cdf0e10cSrcweir if (xAccess.is()) 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir lNames = xAccess->getElementNames(); 574*cdf0e10cSrcweir pNames = lNames.getConstArray(); 575*cdf0e10cSrcweir c = lNames.getLength(); 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir for (i=0; i<c; ++i) 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir ::rtl::OUString sTemp = pNames[i]; 580*cdf0e10cSrcweir sal_Int32 nPos = sTemp.indexOf(FILE_EXTENSION); 581*cdf0e10cSrcweir if (nPos > -1) 582*cdf0e10cSrcweir sTemp = sTemp.copy(0,nPos); 583*cdf0e10cSrcweir lTargets.push_back(sTemp); 584*cdf0e10cSrcweir } 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir // SAFE -> ---------------------------------- 588*cdf0e10cSrcweir aWriteLock.lock(); 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir m_xWorkingStorageShare = xShare ; 591*cdf0e10cSrcweir m_xWorkingStorageNoLang= xNoLang; 592*cdf0e10cSrcweir m_xWorkingStorageUser = xUser ; 593*cdf0e10cSrcweir m_lPresets = lPresets; 594*cdf0e10cSrcweir m_lTargets = lTargets; 595*cdf0e10cSrcweir m_sRelPathShare = sRelPathShare; 596*cdf0e10cSrcweir m_sRelPathNoLang = sRelPathNoLang; 597*cdf0e10cSrcweir m_sRelPathUser = sRelPathUser; 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir aWriteLock.unlock(); 600*cdf0e10cSrcweir // <- SAFE ---------------------------------- 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir throw css::configuration::CorruptedUIConfigurationException( 606*cdf0e10cSrcweir lcl_getLocalizedMessage(ID_CORRUPT_UICONFIG_GENERAL), 607*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >(), 608*cdf0e10cSrcweir ex.Message); 609*cdf0e10cSrcweir } 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir //----------------------------------------------- 613*cdf0e10cSrcweir void PresetHandler::copyPresetToTarget(const ::rtl::OUString& sPreset, 614*cdf0e10cSrcweir const ::rtl::OUString& sTarget) 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir // dont check our preset list, if element exists 617*cdf0e10cSrcweir // We try to open it and forward all errors to the user! 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir // SAFE -> ---------------------------------- 620*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 621*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xWorkingShare = m_xWorkingStorageShare; 622*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xWorkingNoLang= m_xWorkingStorageNoLang; 623*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xWorkingUser = m_xWorkingStorageUser ; 624*cdf0e10cSrcweir aReadLock.unlock(); 625*cdf0e10cSrcweir // <- SAFE ---------------------------------- 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir // e.g. module without any config data ?! 628*cdf0e10cSrcweir if ( 629*cdf0e10cSrcweir (!xWorkingShare.is()) || 630*cdf0e10cSrcweir (!xWorkingUser.is() ) 631*cdf0e10cSrcweir ) 632*cdf0e10cSrcweir { 633*cdf0e10cSrcweir return; 634*cdf0e10cSrcweir } 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir ::rtl::OUString sPresetFile(sPreset); 637*cdf0e10cSrcweir sPresetFile += FILE_EXTENSION; 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir ::rtl::OUString sTargetFile(sTarget); 640*cdf0e10cSrcweir sTargetFile += FILE_EXTENSION; 641*cdf0e10cSrcweir 642*cdf0e10cSrcweir // remove existing elements before you try to copy the preset to that location ... 643*cdf0e10cSrcweir // Otherwise w will get an ElementExistException inside copyElementTo()! 644*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xCheckingUser(xWorkingUser, css::uno::UNO_QUERY_THROW); 645*cdf0e10cSrcweir if (xCheckingUser->hasByName(sTargetFile)) 646*cdf0e10cSrcweir xWorkingUser->removeElement(sTargetFile); 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir xWorkingShare->copyElementTo(sPresetFile, xWorkingUser, sTargetFile); 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir // If our storages work in transacted mode, we have 651*cdf0e10cSrcweir // to commit all changes from bottom to top! 652*cdf0e10cSrcweir commitUserChanges(); 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir //----------------------------------------------- 656*cdf0e10cSrcweir css::uno::Reference< css::io::XStream > PresetHandler::openPreset(const ::rtl::OUString& sPreset, 657*cdf0e10cSrcweir sal_Bool bUseNoLangGlobal) 658*cdf0e10cSrcweir { 659*cdf0e10cSrcweir // SAFE -> ---------------------------------- 660*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 661*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xFolder = bUseNoLangGlobal? m_xWorkingStorageNoLang: m_xWorkingStorageShare; 662*cdf0e10cSrcweir aReadLock.unlock(); 663*cdf0e10cSrcweir // <- SAFE ---------------------------------- 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir // e.g. module without any config data ?! 666*cdf0e10cSrcweir if (!xFolder.is()) 667*cdf0e10cSrcweir return css::uno::Reference< css::io::XStream >(); 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir ::rtl::OUString sFile(sPreset); 670*cdf0e10cSrcweir sFile += FILE_EXTENSION; 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir // inform user about errors (use original exceptions!) 673*cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStream = xFolder->openStreamElement(sFile, css::embed::ElementModes::READ); 674*cdf0e10cSrcweir return xStream; 675*cdf0e10cSrcweir } 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir //----------------------------------------------- 678*cdf0e10cSrcweir css::uno::Reference< css::io::XStream > PresetHandler::openTarget(const ::rtl::OUString& sTarget , 679*cdf0e10cSrcweir sal_Bool bCreateIfMissing) 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir // SAFE -> ---------------------------------- 682*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 683*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xFolder = m_xWorkingStorageUser; 684*cdf0e10cSrcweir aReadLock.unlock(); 685*cdf0e10cSrcweir // <- SAFE ---------------------------------- 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir // e.g. module without any config data ?! 688*cdf0e10cSrcweir if (!xFolder.is()) 689*cdf0e10cSrcweir return css::uno::Reference< css::io::XStream >(); 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir ::rtl::OUString sFile(sTarget); 692*cdf0e10cSrcweir sFile += FILE_EXTENSION; 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir sal_Int32 nOpenMode = css::embed::ElementModes::READWRITE; 695*cdf0e10cSrcweir if (!bCreateIfMissing) 696*cdf0e10cSrcweir nOpenMode |= css::embed::ElementModes::NOCREATE; 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir // try it in read/write mode first and ignore errors. 699*cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStream; 700*cdf0e10cSrcweir try 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir xStream = xFolder->openStreamElement(sFile, nOpenMode); 703*cdf0e10cSrcweir return xStream; 704*cdf0e10cSrcweir } 705*cdf0e10cSrcweir catch(const css::uno::RuntimeException&) 706*cdf0e10cSrcweir { throw; } 707*cdf0e10cSrcweir catch(const css::uno::Exception&) 708*cdf0e10cSrcweir { xStream.clear(); } 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir // try it readonly if it failed before. 711*cdf0e10cSrcweir // inform user about errors (use original exceptions!) 712*cdf0e10cSrcweir nOpenMode &= ~css::embed::ElementModes::WRITE; 713*cdf0e10cSrcweir xStream = xFolder->openStreamElement(sFile, nOpenMode); 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir return xStream; 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir //----------------------------------------------- 719*cdf0e10cSrcweir void PresetHandler::commitUserChanges() 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir // SAFE -> ---------------------------------- 722*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 723*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xWorking = m_xWorkingStorageUser; 724*cdf0e10cSrcweir EConfigType eCfgType = m_eConfigType; 725*cdf0e10cSrcweir aReadLock.unlock(); 726*cdf0e10cSrcweir // <- SAFE ---------------------------------- 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir // e.g. module without any config data ?! 729*cdf0e10cSrcweir if (!xWorking.is()) 730*cdf0e10cSrcweir return; 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir ::rtl::OUString sPath; 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir switch(eCfgType) 735*cdf0e10cSrcweir { 736*cdf0e10cSrcweir case E_GLOBAL : 737*cdf0e10cSrcweir case E_MODULES : 738*cdf0e10cSrcweir { 739*cdf0e10cSrcweir sPath = m_aSharedStorages->m_lStoragesUser.getPathOfStorage(xWorking); 740*cdf0e10cSrcweir m_aSharedStorages->m_lStoragesUser.commitPath(sPath); 741*cdf0e10cSrcweir m_aSharedStorages->m_lStoragesUser.notifyPath(sPath); 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir break; 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir case E_DOCUMENT : 746*cdf0e10cSrcweir { 747*cdf0e10cSrcweir sPath = m_lDocumentStorages.getPathOfStorage(xWorking); 748*cdf0e10cSrcweir m_lDocumentStorages.commitPath(sPath); 749*cdf0e10cSrcweir m_lDocumentStorages.notifyPath(sPath); 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir break; 752*cdf0e10cSrcweir } 753*cdf0e10cSrcweir } 754*cdf0e10cSrcweir 755*cdf0e10cSrcweir //----------------------------------------------- 756*cdf0e10cSrcweir void PresetHandler::addStorageListener(IStorageListener* pListener) 757*cdf0e10cSrcweir { 758*cdf0e10cSrcweir // SAFE -> ---------------------------------- 759*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 760*cdf0e10cSrcweir ::rtl::OUString sRelPath = m_sRelPathUser; // use user path ... because we dont work directly on the share layer! 761*cdf0e10cSrcweir EConfigType eCfgType = m_eConfigType; 762*cdf0e10cSrcweir aReadLock.unlock(); 763*cdf0e10cSrcweir // <- SAFE ---------------------------------- 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir if (!sRelPath.getLength()) 766*cdf0e10cSrcweir return; 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir switch(eCfgType) 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir case E_GLOBAL : 771*cdf0e10cSrcweir case E_MODULES : 772*cdf0e10cSrcweir { 773*cdf0e10cSrcweir m_aSharedStorages->m_lStoragesUser.addStorageListener(pListener, sRelPath); 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir break; 776*cdf0e10cSrcweir 777*cdf0e10cSrcweir case E_DOCUMENT : 778*cdf0e10cSrcweir { 779*cdf0e10cSrcweir m_lDocumentStorages.addStorageListener(pListener, sRelPath); 780*cdf0e10cSrcweir } 781*cdf0e10cSrcweir break; 782*cdf0e10cSrcweir } 783*cdf0e10cSrcweir } 784*cdf0e10cSrcweir 785*cdf0e10cSrcweir //----------------------------------------------- 786*cdf0e10cSrcweir void PresetHandler::removeStorageListener(IStorageListener* pListener) 787*cdf0e10cSrcweir { 788*cdf0e10cSrcweir // SAFE -> ---------------------------------- 789*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 790*cdf0e10cSrcweir ::rtl::OUString sRelPath = m_sRelPathUser; // use user path ... because we dont work directly on the share layer! 791*cdf0e10cSrcweir EConfigType eCfgType = m_eConfigType; 792*cdf0e10cSrcweir aReadLock.unlock(); 793*cdf0e10cSrcweir // <- SAFE ---------------------------------- 794*cdf0e10cSrcweir 795*cdf0e10cSrcweir if (!sRelPath.getLength()) 796*cdf0e10cSrcweir return; 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir switch(eCfgType) 799*cdf0e10cSrcweir { 800*cdf0e10cSrcweir case E_GLOBAL : 801*cdf0e10cSrcweir case E_MODULES : 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir m_aSharedStorages->m_lStoragesUser.removeStorageListener(pListener, sRelPath); 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir break; 806*cdf0e10cSrcweir 807*cdf0e10cSrcweir case E_DOCUMENT : 808*cdf0e10cSrcweir { 809*cdf0e10cSrcweir m_lDocumentStorages.removeStorageListener(pListener, sRelPath); 810*cdf0e10cSrcweir } 811*cdf0e10cSrcweir break; 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir 815*cdf0e10cSrcweir //----------------------------------------------- 816*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openPathIgnoringErrors(const ::rtl::OUString& sPath , 817*cdf0e10cSrcweir sal_Int32 eMode , 818*cdf0e10cSrcweir sal_Bool bShare) 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xPath; 821*cdf0e10cSrcweir try 822*cdf0e10cSrcweir { 823*cdf0e10cSrcweir if (bShare) 824*cdf0e10cSrcweir xPath = m_aSharedStorages->m_lStoragesShare.openPath(sPath, eMode); 825*cdf0e10cSrcweir else 826*cdf0e10cSrcweir xPath = m_aSharedStorages->m_lStoragesUser.openPath(sPath, eMode); 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir catch(const css::uno::RuntimeException& exRun) 829*cdf0e10cSrcweir { throw exRun; } 830*cdf0e10cSrcweir catch(const css::uno::Exception&) 831*cdf0e10cSrcweir { xPath.clear(); } 832*cdf0e10cSrcweir return xPath; 833*cdf0e10cSrcweir } 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir //----------------------------------------------- 836*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator PresetHandler::impl_findMatchingLocalizedValue(const ::std::vector< ::rtl::OUString >& lLocalizedValues, 837*cdf0e10cSrcweir ::comphelper::Locale& aLocale , 838*cdf0e10cSrcweir sal_Bool bAllowFallbacks ) 839*cdf0e10cSrcweir { 840*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pFound = lLocalizedValues.end(); 841*cdf0e10cSrcweir if (bAllowFallbacks) 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir pFound = ::comphelper::Locale::getFallback(lLocalizedValues, aLocale.toISO()); 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir else 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir for ( pFound = lLocalizedValues.begin(); 848*cdf0e10cSrcweir pFound != lLocalizedValues.end() ; 849*cdf0e10cSrcweir ++pFound ) 850*cdf0e10cSrcweir { 851*cdf0e10cSrcweir const ::rtl::OUString& sCheckISO = *pFound; 852*cdf0e10cSrcweir ::comphelper::Locale aCheckLocale(sCheckISO); 853*cdf0e10cSrcweir if (aCheckLocale.equals(aLocale)) 854*cdf0e10cSrcweir break; 855*cdf0e10cSrcweir } 856*cdf0e10cSrcweir } 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir // if we found a valid locale ... take it over to our in/out parameter aLocale 859*cdf0e10cSrcweir if (pFound != lLocalizedValues.end()) 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir const ::rtl::OUString& sISOLocale = *pFound; 862*cdf0e10cSrcweir aLocale.fromISO(sISOLocale); 863*cdf0e10cSrcweir } 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir return pFound; 866*cdf0e10cSrcweir } 867*cdf0e10cSrcweir 868*cdf0e10cSrcweir //----------------------------------------------- 869*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openLocalizedPathIgnoringErrors(::rtl::OUString& sPath , 870*cdf0e10cSrcweir sal_Int32 eMode , 871*cdf0e10cSrcweir sal_Bool bShare , 872*cdf0e10cSrcweir ::comphelper::Locale& aLocale , 873*cdf0e10cSrcweir sal_Bool bAllowFallback) 874*cdf0e10cSrcweir { 875*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xPath = impl_openPathIgnoringErrors(sPath, eMode, bShare); 876*cdf0e10cSrcweir ::std::vector< ::rtl::OUString > lSubFolders = impl_getSubFolderNames(xPath); 877*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pLocaleFolder = impl_findMatchingLocalizedValue(lSubFolders, aLocale, bAllowFallback); 878*cdf0e10cSrcweir 879*cdf0e10cSrcweir // no fallback ... creation not allowed => no storage 880*cdf0e10cSrcweir if ( 881*cdf0e10cSrcweir (pLocaleFolder == lSubFolders.end() ) && 882*cdf0e10cSrcweir ((eMode & css::embed::ElementModes::NOCREATE) == css::embed::ElementModes::NOCREATE) 883*cdf0e10cSrcweir ) 884*cdf0e10cSrcweir return css::uno::Reference< css::embed::XStorage >(); 885*cdf0e10cSrcweir 886*cdf0e10cSrcweir // it doesnt matter, if there is a locale fallback or not 887*cdf0e10cSrcweir // If creation of storages is allowed, we do it anyway. 888*cdf0e10cSrcweir // Otherwhise we have no acc config at all, which can make other trouble. 889*cdf0e10cSrcweir ::rtl::OUString sLocalizedPath; 890*cdf0e10cSrcweir sLocalizedPath = sPath; 891*cdf0e10cSrcweir sLocalizedPath += PATH_SEPERATOR; 892*cdf0e10cSrcweir if (pLocaleFolder != lSubFolders.end()) 893*cdf0e10cSrcweir sLocalizedPath += *pLocaleFolder; 894*cdf0e10cSrcweir else 895*cdf0e10cSrcweir sLocalizedPath += aLocale.toISO(); 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xLocalePath = impl_openPathIgnoringErrors(sLocalizedPath, eMode, bShare); 898*cdf0e10cSrcweir 899*cdf0e10cSrcweir if (xLocalePath.is()) 900*cdf0e10cSrcweir sPath = sLocalizedPath; 901*cdf0e10cSrcweir else 902*cdf0e10cSrcweir sPath = ::rtl::OUString(); 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir return xLocalePath; 905*cdf0e10cSrcweir } 906*cdf0e10cSrcweir 907*cdf0e10cSrcweir //----------------------------------------------- 908*cdf0e10cSrcweir ::std::vector< ::rtl::OUString > PresetHandler::impl_getSubFolderNames(const css::uno::Reference< css::embed::XStorage >& xFolder) 909*cdf0e10cSrcweir { 910*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess(xFolder, css::uno::UNO_QUERY); 911*cdf0e10cSrcweir if (!xAccess.is()) 912*cdf0e10cSrcweir return ::std::vector< ::rtl::OUString >(); 913*cdf0e10cSrcweir 914*cdf0e10cSrcweir ::std::vector< ::rtl::OUString > lSubFolders; 915*cdf0e10cSrcweir const css::uno::Sequence< ::rtl::OUString > lNames = xAccess->getElementNames(); 916*cdf0e10cSrcweir const ::rtl::OUString* pNames = lNames.getConstArray(); 917*cdf0e10cSrcweir sal_Int32 c = lNames.getLength(); 918*cdf0e10cSrcweir sal_Int32 i = 0; 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir for (i=0; i<c; ++i) 921*cdf0e10cSrcweir { 922*cdf0e10cSrcweir try 923*cdf0e10cSrcweir { 924*cdf0e10cSrcweir if (xFolder->isStorageElement(pNames[i])) 925*cdf0e10cSrcweir lSubFolders.push_back(pNames[i]); 926*cdf0e10cSrcweir } 927*cdf0e10cSrcweir catch(const css::uno::RuntimeException& exRun) 928*cdf0e10cSrcweir { throw exRun; } 929*cdf0e10cSrcweir catch(const css::uno::Exception&) 930*cdf0e10cSrcweir {} 931*cdf0e10cSrcweir } 932*cdf0e10cSrcweir 933*cdf0e10cSrcweir return lSubFolders; 934*cdf0e10cSrcweir } 935*cdf0e10cSrcweir 936*cdf0e10cSrcweir //----------------------------------------------- 937*cdf0e10cSrcweir } // namespace framework 938