1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include "ModuleHelper.hxx" 28 #include <comphelper/configurationhelper.hxx> 29 #include <comphelper/processfactory.hxx> 30 #include <osl/thread.h> 31 #include <com/sun/star/util/XMacroExpander.hpp> 32 #include <com/sun/star/beans/XPropertySet.hpp> 33 #include <com/sun/star/uno/XComponentContext.hpp> 34 #include <rtl/uri.hxx> 35 #include <tools/debug.hxx> 36 #ifndef _SOLAR_HRC 37 #include <svl/solar.hrc> 38 #endif 39 40 #define EXPAND_PROTOCOL "vnd.sun.star.expand:" 41 #define ENTER_MOD_METHOD() \ 42 ::osl::MutexGuard aGuard(s_aMutex); \ 43 ensureImpl() 44 45 //......................................................................... 46 namespace formula 47 { 48 //......................................................................... 49 using namespace ::com::sun::star; 50 //========================================================================= 51 //= OModuleImpl 52 //========================================================================= 53 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner 54 */ 55 class OModuleImpl 56 { 57 ResMgr* m_pRessources; 58 59 public: 60 /// ctor 61 OModuleImpl(); 62 ~OModuleImpl(); 63 64 /// get the manager for the ressources of the module 65 ResMgr* getResManager(); 66 }; 67 68 DBG_NAME( rpt_OModuleImpl ) 69 //------------------------------------------------------------------------- 70 OModuleImpl::OModuleImpl() 71 :m_pRessources(NULL) 72 { 73 DBG_CTOR( rpt_OModuleImpl,NULL); 74 75 } 76 77 //------------------------------------------------------------------------- 78 OModuleImpl::~OModuleImpl() 79 { 80 if (m_pRessources) 81 delete m_pRessources; 82 83 DBG_DTOR( rpt_OModuleImpl,NULL); 84 } 85 86 //------------------------------------------------------------------------- 87 ResMgr* OModuleImpl::getResManager() 88 { 89 // note that this method is not threadsafe, which counts for the whole class ! 90 91 if (!m_pRessources) 92 { 93 // create a manager with a fixed prefix 94 rtl::OString sName = rtl::OString( "forui" ); 95 m_pRessources = ResMgr::CreateResMgr(sName); 96 } 97 return m_pRessources; 98 } 99 100 //========================================================================= 101 //= OModule 102 //========================================================================= 103 ::osl::Mutex OModule::s_aMutex; 104 sal_Int32 OModule::s_nClients = 0; 105 OModuleImpl* OModule::s_pImpl = NULL; 106 //------------------------------------------------------------------------- 107 ResMgr* OModule::getResManager() 108 { 109 ENTER_MOD_METHOD(); 110 return s_pImpl->getResManager(); 111 } 112 113 //------------------------------------------------------------------------- 114 void OModule::registerClient() 115 { 116 ::osl::MutexGuard aGuard(s_aMutex); 117 ++s_nClients; 118 } 119 120 //------------------------------------------------------------------------- 121 void OModule::revokeClient() 122 { 123 ::osl::MutexGuard aGuard(s_aMutex); 124 if (!--s_nClients && s_pImpl) 125 { 126 delete s_pImpl; 127 s_pImpl = NULL; 128 } 129 } 130 131 //------------------------------------------------------------------------- 132 void OModule::ensureImpl() 133 { 134 if (s_pImpl) 135 return; 136 s_pImpl = new OModuleImpl(); 137 } 138 139 //......................................................................... 140 } // namespace formula 141 //......................................................................... 142 143