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_comphelper.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <comphelper/logging.hxx> 32*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir /** === begin UNO includes === **/ 35*cdf0e10cSrcweir #include <com/sun/star/logging/LoggerPool.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/logging/LogLevel.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/resource/XResourceBundle.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/resource/XResourceBundleLoader.hpp> 39*cdf0e10cSrcweir /** === end UNO includes === **/ 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir //........................................................................ 44*cdf0e10cSrcweir namespace comphelper 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir //........................................................................ 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir /** === begin UNO using === **/ 49*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 50*cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext; 51*cdf0e10cSrcweir using ::com::sun::star::logging::XLoggerPool; 52*cdf0e10cSrcweir using ::com::sun::star::logging::LoggerPool; 53*cdf0e10cSrcweir using ::com::sun::star::logging::XLogger; 54*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 55*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 56*cdf0e10cSrcweir using ::com::sun::star::logging::XLogHandler; 57*cdf0e10cSrcweir using ::com::sun::star::resource::XResourceBundle; 58*cdf0e10cSrcweir using ::com::sun::star::resource::XResourceBundleLoader; 59*cdf0e10cSrcweir /** === end UNO using === **/ 60*cdf0e10cSrcweir namespace LogLevel = ::com::sun::star::logging::LogLevel; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir //==================================================================== 63*cdf0e10cSrcweir //= EventLogger_Impl - declaration 64*cdf0e10cSrcweir //==================================================================== 65*cdf0e10cSrcweir class EventLogger_Impl 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir private: 68*cdf0e10cSrcweir ::comphelper::ComponentContext m_aContext; 69*cdf0e10cSrcweir ::rtl::OUString m_sLoggerName; 70*cdf0e10cSrcweir Reference< XLogger > m_xLogger; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir public: 73*cdf0e10cSrcweir EventLogger_Impl( const Reference< XComponentContext >& _rxContext, const ::rtl::OUString& _rLoggerName ) 74*cdf0e10cSrcweir :m_aContext( _rxContext ) 75*cdf0e10cSrcweir ,m_sLoggerName( _rLoggerName ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir impl_createLogger_nothrow(); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir inline bool isValid() const { return m_xLogger.is(); } 81*cdf0e10cSrcweir inline const ::rtl::OUString& getName() const { return m_sLoggerName; } 82*cdf0e10cSrcweir inline const Reference< XLogger >& getLogger() const { return m_xLogger; } 83*cdf0e10cSrcweir inline const ::comphelper::ComponentContext& getContext() const { return m_aContext; } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir private: 86*cdf0e10cSrcweir void impl_createLogger_nothrow(); 87*cdf0e10cSrcweir }; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir //==================================================================== 90*cdf0e10cSrcweir //= EventLogger_Impl - implementation 91*cdf0e10cSrcweir //==================================================================== 92*cdf0e10cSrcweir //-------------------------------------------------------------------- 93*cdf0e10cSrcweir void EventLogger_Impl::impl_createLogger_nothrow() 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir try 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir Reference< XLoggerPool > xPool( LoggerPool::get( m_aContext.getUNOContext() ), UNO_QUERY_THROW ); 98*cdf0e10cSrcweir if ( m_sLoggerName.getLength() ) 99*cdf0e10cSrcweir m_xLogger = xPool->getNamedLogger( m_sLoggerName ); 100*cdf0e10cSrcweir else 101*cdf0e10cSrcweir m_xLogger = xPool->getDefaultLogger(); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir catch( const Exception& e ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir (void)e; 106*cdf0e10cSrcweir OSL_ENSURE( false, "EventLogger_Impl::impl_createLogger_nothrow: caught an exception!" ); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir //==================================================================== 111*cdf0e10cSrcweir //= EventLogger 112*cdf0e10cSrcweir //==================================================================== 113*cdf0e10cSrcweir //-------------------------------------------------------------------- 114*cdf0e10cSrcweir EventLogger::EventLogger( const Reference< XComponentContext >& _rxContext, const ::rtl::OUString& _rLoggerName ) 115*cdf0e10cSrcweir :m_pImpl( new EventLogger_Impl( _rxContext, _rLoggerName ) ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir //-------------------------------------------------------------------- 120*cdf0e10cSrcweir EventLogger::EventLogger( const Reference< XComponentContext >& _rxContext, const sal_Char* _pAsciiLoggerName ) 121*cdf0e10cSrcweir :m_pImpl( new EventLogger_Impl( _rxContext, ::rtl::OUString::createFromAscii( _pAsciiLoggerName ) ) ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir //-------------------------------------------------------------------- 126*cdf0e10cSrcweir EventLogger::~EventLogger() 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir //-------------------------------------------------------------------- 131*cdf0e10cSrcweir const ::rtl::OUString& EventLogger::getName() const 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir return m_pImpl->getName(); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //-------------------------------------------------------------------- 137*cdf0e10cSrcweir sal_Int32 EventLogger::getLogLevel() const 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir try 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir if ( m_pImpl->isValid() ) 142*cdf0e10cSrcweir return m_pImpl->getLogger()->getLevel(); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir catch( const Exception& e ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir (void)e; 147*cdf0e10cSrcweir OSL_ENSURE( false, "EventLogger::getLogLevel: caught an exception!" ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir return LogLevel::OFF; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir //-------------------------------------------------------------------- 154*cdf0e10cSrcweir void EventLogger::setLogLevel( const sal_Int32 _nLogLevel ) const 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir try 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir if ( m_pImpl->isValid() ) 159*cdf0e10cSrcweir m_pImpl->getLogger()->setLevel( _nLogLevel ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir catch( const Exception& e ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir (void)e; 164*cdf0e10cSrcweir OSL_ENSURE( false, "EventLogger::setLogLevel: caught an exception!" ); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir //-------------------------------------------------------------------- 169*cdf0e10cSrcweir bool EventLogger::isLoggable( const sal_Int32 _nLogLevel ) const 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir if ( !m_pImpl->isValid() ) 172*cdf0e10cSrcweir return false; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir try 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir return m_pImpl->getLogger()->isLoggable( _nLogLevel ); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir catch( const Exception& e ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir (void)e; 181*cdf0e10cSrcweir OSL_ENSURE( false, "EventLogger::isLoggable: caught an exception!" ); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir return false; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir //-------------------------------------------------------------------- 188*cdf0e10cSrcweir bool EventLogger::addLogHandler( const Reference< XLogHandler >& _rxLogHandler ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir try 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir if ( m_pImpl->isValid() ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir m_pImpl->getLogger()->addLogHandler( _rxLogHandler ); 195*cdf0e10cSrcweir return true; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir catch( const Exception& e ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir (void)e; 201*cdf0e10cSrcweir OSL_ENSURE( false, "EventLogger::addLogHandler: caught an exception!" ); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir return false; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //-------------------------------------------------------------------- 207*cdf0e10cSrcweir bool EventLogger::removeLogHandler( const Reference< XLogHandler >& _rxLogHandler ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir try 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir if ( m_pImpl->isValid() ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir m_pImpl->getLogger()->removeLogHandler( _rxLogHandler ); 214*cdf0e10cSrcweir return true; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir catch( const Exception& e ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir (void)e; 220*cdf0e10cSrcweir OSL_ENSURE( false, "EventLogger::removeLogHandler: caught an exception!" ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir return false; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir //-------------------------------------------------------------------- 226*cdf0e10cSrcweir namespace 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir void lcl_replaceParameter( ::rtl::OUString& _inout_Message, const ::rtl::OUString& _rPlaceHolder, const ::rtl::OUString& _rReplacement ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir sal_Int32 nPlaceholderPosition = _inout_Message.indexOf( _rPlaceHolder ); 231*cdf0e10cSrcweir OSL_ENSURE( nPlaceholderPosition >= 0, "lcl_replaceParameter: placeholder not found!" ); 232*cdf0e10cSrcweir if ( nPlaceholderPosition < 0 ) 233*cdf0e10cSrcweir return; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir _inout_Message = _inout_Message.replaceAt( nPlaceholderPosition, _rPlaceHolder.getLength(), _rReplacement ); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir //-------------------------------------------------------------------- 240*cdf0e10cSrcweir bool EventLogger::impl_log( const sal_Int32 _nLogLevel, 241*cdf0e10cSrcweir const sal_Char* _pSourceClass, const sal_Char* _pSourceMethod, const ::rtl::OUString& _rMessage, 242*cdf0e10cSrcweir const OptionalString& _rArgument1, const OptionalString& _rArgument2, 243*cdf0e10cSrcweir const OptionalString& _rArgument3, const OptionalString& _rArgument4, 244*cdf0e10cSrcweir const OptionalString& _rArgument5, const OptionalString& _rArgument6 ) const 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir // (if ::rtl::OUString had an indexOfAscii, we could save those ugly statics ...) 247*cdf0e10cSrcweir static ::rtl::OUString sPH1( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$1$" ) ) ); 248*cdf0e10cSrcweir static ::rtl::OUString sPH2( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$2$" ) ) ); 249*cdf0e10cSrcweir static ::rtl::OUString sPH3( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$3$" ) ) ); 250*cdf0e10cSrcweir static ::rtl::OUString sPH4( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$4$" ) ) ); 251*cdf0e10cSrcweir static ::rtl::OUString sPH5( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$5$" ) ) ); 252*cdf0e10cSrcweir static ::rtl::OUString sPH6( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "$6$" ) ) ); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir ::rtl::OUString sMessage( _rMessage ); 255*cdf0e10cSrcweir if ( !!_rArgument1 ) 256*cdf0e10cSrcweir lcl_replaceParameter( sMessage, sPH1, *_rArgument1 ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir if ( !!_rArgument2 ) 259*cdf0e10cSrcweir lcl_replaceParameter( sMessage, sPH2, *_rArgument2 ); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir if ( !!_rArgument3 ) 262*cdf0e10cSrcweir lcl_replaceParameter( sMessage, sPH3, *_rArgument3 ); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir if ( !!_rArgument4 ) 265*cdf0e10cSrcweir lcl_replaceParameter( sMessage, sPH4, *_rArgument4 ); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir if ( !!_rArgument5 ) 268*cdf0e10cSrcweir lcl_replaceParameter( sMessage, sPH5, *_rArgument5 ); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir if ( !!_rArgument6 ) 271*cdf0e10cSrcweir lcl_replaceParameter( sMessage, sPH6, *_rArgument6 ); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir try 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir Reference< XLogger > xLogger( m_pImpl->getLogger() ); 276*cdf0e10cSrcweir OSL_PRECOND( xLogger.is(), "EventLogger::impl_log: should never be called without a logger!" ); 277*cdf0e10cSrcweir if ( _pSourceClass && _pSourceMethod ) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir xLogger->logp( 280*cdf0e10cSrcweir _nLogLevel, 281*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( _pSourceClass ), 282*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( _pSourceMethod ), 283*cdf0e10cSrcweir sMessage 284*cdf0e10cSrcweir ); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir else 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir xLogger->log( _nLogLevel, sMessage ); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir catch( const Exception& e ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir (void)e; 294*cdf0e10cSrcweir OSL_ENSURE( false, "EventLogger::impl_log: caught an exception!" ); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir return false; 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir //==================================================================== 301*cdf0e10cSrcweir //= ResourceBasedEventLogger_Data 302*cdf0e10cSrcweir //==================================================================== 303*cdf0e10cSrcweir struct ResourceBasedEventLogger_Data 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir /// the base name of the resource bundle 306*cdf0e10cSrcweir ::rtl::OUString sBundleBaseName; 307*cdf0e10cSrcweir /// did we already attempt to load the bundle? 308*cdf0e10cSrcweir bool bBundleLoaded; 309*cdf0e10cSrcweir /// the lazily loaded bundle 310*cdf0e10cSrcweir Reference< XResourceBundle > xBundle; 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir ResourceBasedEventLogger_Data() 313*cdf0e10cSrcweir :sBundleBaseName() 314*cdf0e10cSrcweir ,bBundleLoaded( false ) 315*cdf0e10cSrcweir ,xBundle() 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir }; 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir //-------------------------------------------------------------------- 321*cdf0e10cSrcweir bool lcl_loadBundle_nothrow( const ComponentContext& _rContext, ResourceBasedEventLogger_Data& _rLoggerData ) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir if ( _rLoggerData.bBundleLoaded ) 324*cdf0e10cSrcweir return _rLoggerData.xBundle.is(); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir // no matter what happens below, don't attempt creation ever again 327*cdf0e10cSrcweir _rLoggerData.bBundleLoaded = true; 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir try 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir Reference< XResourceBundleLoader > xLoader( _rContext.getSingleton( "com.sun.star.resource.OfficeResourceLoader" ), UNO_QUERY_THROW ); 332*cdf0e10cSrcweir _rLoggerData.xBundle = Reference< XResourceBundle >( xLoader->loadBundle_Default( _rLoggerData.sBundleBaseName ), UNO_QUERY_THROW ); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir catch( const Exception& e ) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir (void)e; 337*cdf0e10cSrcweir OSL_ENSURE( false, "lcl_loadBundle_nothrow: caught an exception!" ); 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir return _rLoggerData.xBundle.is(); 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir //-------------------------------------------------------------------- 344*cdf0e10cSrcweir ::rtl::OUString lcl_loadString_nothrow( const Reference< XResourceBundle >& _rxBundle, const sal_Int32 _nMessageResID ) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir OSL_PRECOND( _rxBundle.is(), "lcl_loadString_nothrow: this will crash!" ); 347*cdf0e10cSrcweir ::rtl::OUString sMessage; 348*cdf0e10cSrcweir try 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir ::rtl::OUStringBuffer aBuffer; 351*cdf0e10cSrcweir aBuffer.appendAscii( "string:" ); 352*cdf0e10cSrcweir aBuffer.append( _nMessageResID ); 353*cdf0e10cSrcweir OSL_VERIFY( _rxBundle->getDirectElement( aBuffer.makeStringAndClear() ) >>= sMessage ); 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir catch( const Exception& e ) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir (void)e; 358*cdf0e10cSrcweir OSL_ENSURE( false, "lcl_loadString_nothrow: caught an exception!" ); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir return sMessage; 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir //==================================================================== 364*cdf0e10cSrcweir //= ResourceBasedEventLogger 365*cdf0e10cSrcweir //==================================================================== 366*cdf0e10cSrcweir //-------------------------------------------------------------------- 367*cdf0e10cSrcweir ResourceBasedEventLogger::ResourceBasedEventLogger( const Reference< XComponentContext >& _rxContext, const ::rtl::OUString& _rResourceBundleBaseName, 368*cdf0e10cSrcweir const ::rtl::OUString& _rLoggerName ) 369*cdf0e10cSrcweir :EventLogger( _rxContext, _rLoggerName ) 370*cdf0e10cSrcweir ,m_pData( new ResourceBasedEventLogger_Data ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir m_pData->sBundleBaseName = _rResourceBundleBaseName; 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir //-------------------------------------------------------------------- 376*cdf0e10cSrcweir ResourceBasedEventLogger::ResourceBasedEventLogger( const Reference< XComponentContext >& _rxContext, const sal_Char* _pResourceBundleBaseName, 377*cdf0e10cSrcweir const sal_Char* _pAsciiLoggerName ) 378*cdf0e10cSrcweir :EventLogger( _rxContext, _pAsciiLoggerName ) 379*cdf0e10cSrcweir ,m_pData( new ResourceBasedEventLogger_Data ) 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir m_pData->sBundleBaseName = ::rtl::OUString::createFromAscii( _pResourceBundleBaseName ); 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir //-------------------------------------------------------------------- 385*cdf0e10cSrcweir ::rtl::OUString ResourceBasedEventLogger::impl_loadStringMessage_nothrow( const sal_Int32 _nMessageResID ) const 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir ::rtl::OUString sMessage; 388*cdf0e10cSrcweir if ( lcl_loadBundle_nothrow( m_pImpl->getContext(), *m_pData ) ) 389*cdf0e10cSrcweir sMessage = lcl_loadString_nothrow( m_pData->xBundle, _nMessageResID ); 390*cdf0e10cSrcweir if ( sMessage.getLength() == 0 ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir ::rtl::OUStringBuffer aBuffer; 393*cdf0e10cSrcweir aBuffer.appendAscii( "<invalid event resource: '" ); 394*cdf0e10cSrcweir aBuffer.append( m_pData->sBundleBaseName ); 395*cdf0e10cSrcweir aBuffer.appendAscii( ":" ); 396*cdf0e10cSrcweir aBuffer.append( _nMessageResID ); 397*cdf0e10cSrcweir aBuffer.appendAscii( "'>" ); 398*cdf0e10cSrcweir sMessage = aBuffer.makeStringAndClear(); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir return sMessage; 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir //........................................................................ 404*cdf0e10cSrcweir } // namespace comphelper 405*cdf0e10cSrcweir //........................................................................ 406