1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 
27 #include "core_resource.hxx"
28 
29 #include <tools/resmgr.hxx>
30 
31 // ---- needed as long as we have no contexts for components ---
32 #ifndef _SV_SVAPP_HXX
33 #include <vcl/svapp.hxx>
34 #endif
35 //---------------------------------------------------
36 
37 #ifndef _SOLAR_HRC
38 #include <svl/solar.hrc>
39 #endif
40 
41 //.........................................................................
42 namespace dbaccess
43 {
44 
45 	//==================================================================
46 	//= ResourceManager
47 	//==================================================================
48     ::osl::Mutex	ResourceManager::s_aMutex;
49     sal_Int32		ResourceManager::s_nClients = 0;
50 	ResMgr*         ResourceManager::m_pImpl = NULL;
51 
52 	//------------------------------------------------------------------
ensureImplExists()53 	void ResourceManager::ensureImplExists()
54 	{
55 		if (m_pImpl)
56 			return;
57 
58 		::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
59 
60 		ByteString sFileName("dba");
61 
62 		m_pImpl = ResMgr::CreateResMgr(sFileName.GetBuffer(), aLocale);
63 	}
64 
65 	//------------------------------------------------------------------
loadString(sal_uInt16 _nResId)66 	::rtl::OUString ResourceManager::loadString(sal_uInt16 _nResId)
67 	{
68 		::rtl::OUString sReturn;
69 
70 		ensureImplExists();
71 		if (m_pImpl)
72 			sReturn = String(ResId(_nResId,*m_pImpl));
73 
74 		return sReturn;
75 	}
76 
77 	//------------------------------------------------------------------
loadString(sal_uInt16 _nResId,const sal_Char * _pPlaceholderAscii,const::rtl::OUString & _rReplace)78     ::rtl::OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii, const ::rtl::OUString& _rReplace )
79     {
80         String sString( loadString( _nResId ) );
81         sString.SearchAndReplaceAscii( _pPlaceholderAscii, _rReplace );
82         return sString;
83     }
84 
85 	//------------------------------------------------------------------
loadString(sal_uInt16 _nResId,const sal_Char * _pPlaceholderAscii1,const::rtl::OUString & _rReplace1,const sal_Char * _pPlaceholderAscii2,const::rtl::OUString & _rReplace2)86     ::rtl::OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii1, const ::rtl::OUString& _rReplace1,
87         const sal_Char* _pPlaceholderAscii2, const ::rtl::OUString& _rReplace2 )
88     {
89         String sString( loadString( _nResId ) );
90         sString.SearchAndReplaceAscii( _pPlaceholderAscii1, _rReplace1 );
91         sString.SearchAndReplaceAscii( _pPlaceholderAscii2, _rReplace2 );
92         return sString;
93     }
94 
95     //-------------------------------------------------------------------------
registerClient()96     void ResourceManager::registerClient()
97     {
98 	    ::osl::MutexGuard aGuard(s_aMutex);
99 	    ++s_nClients;
100     }
101 
102     //-------------------------------------------------------------------------
revokeClient()103     void ResourceManager::revokeClient()
104     {
105 	    ::osl::MutexGuard aGuard(s_aMutex);
106 	    if (!--s_nClients && m_pImpl)
107 	    {
108 		    delete m_pImpl;
109 		    m_pImpl = NULL;
110 	    }
111     }
112 //.........................................................................
113 }
114 //.........................................................................
115 
116