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 // ---------------- 25 // - SimpleResMgr - 26 // ---------------- 27 28 // a simple resource manager : no stacks, no sharing of the impl class, only loading of strings and blobs 29 // but thread-safety !! :) 30 31 #ifndef _TOOLS_SIMPLERESMGR_HXX_ 32 #define _TOOLS_SIMPLERESMGR_HXX_ 33 34 #include <vos/mutex.hxx> 35 #include <tools/resid.hxx> 36 #include <i18npool/lang.h> 37 #include <tools/string.hxx> 38 #include <com/sun/star/lang/Locale.hpp> 39 #include "tools/toolsdllapi.h" 40 41 class InternalResMgr; 42 class TOOLS_DLLPUBLIC SimpleResMgr 43 { 44 protected: 45 vos::OMutex m_aAccessSafety; 46 InternalResMgr* m_pResImpl; 47 48 public: 49 /** creates a new SimpleResManager 50 @param pPrefixName 51 denotes the prefix of the resource file name, in ThreadTextEncoding 52 @param rLocale 53 denotes the locale of the resource file to load. If empty, a default locale 54 will be used. 55 */ 56 SimpleResMgr( const sal_Char* pPrefixName, 57 const ::com::sun::star::lang::Locale& _rLocale); 58 59 /** creates a new SimpleResManager 60 @param _rPrefixName 61 denotes the prefix of the resource file name 62 @param _inout_Locale 63 denotes the locale of the resource file to load. If empty, no default handling 64 (like in the other constructor) will happen, instead an unlocalized version will be 65 attempted to be loaded. 66 Upon return, the variable will contain the actual locale of the loaded resource file. 67 For instance, if "en-US" is requested, but only "en" exists, the latter will be loaded 68 and returned. Furthermore, if an unlocalized resource file with only the base name exists, 69 this one will be loaded as final fallback. 70 */ 71 SimpleResMgr( const ::rtl::OUString& _rPrefixName, ::com::sun::star::lang::Locale& _inout_Locale ); 72 virtual ~SimpleResMgr(); 73 74 static SimpleResMgr* Create( const sal_Char* pPrefixName, 75 ::com::sun::star::lang::Locale aLocale = ::com::sun::star::lang::Locale( rtl::OUString(), 76 rtl::OUString(), 77 rtl::OUString()));// nur in VCL 78 IsValid() const79 bool IsValid() const { return m_pResImpl != NULL; } 80 81 /** retrieves the locale of the resource file represented by this instance 82 @precond 83 IsValid returns <TRUE/> 84 */ 85 const ::com::sun::star::lang::Locale& 86 GetLocale() const; 87 88 /** reads the string with the given resource id 89 @param nId 90 the resource id of the string to read 91 @return 92 the string with the given resource id, or an empty string if the id does not denote 93 an existent string 94 @seealso IsAvailable 95 */ 96 UniString ReadString( sal_uInt32 nId ); 97 98 /** checks whether a certain resource is availble 99 @param _resourceType 100 the type of the resource to check. Currently, only RSC_STRING (strings) and RSC_RESOURCE (blobs) 101 are supported, for every other type, <FALSE/> will be returned. 102 @param _resourceId 103 the id of the resource to lookup. 104 @return 105 <TRUE/> if and only if a resource of the given type, with the given id, is available. 106 */ 107 bool IsAvailable( RESOURCE_TYPE _resourceType, sal_uInt32 _resourceId ); 108 109 sal_uInt32 ReadBlob( sal_uInt32 nId, void** pBuffer ); 110 void FreeBlob( void* pBuffer ); 111 }; 112 113 #endif // _TOOLS_SIMPLERESMGR_HXX_ 114