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_extensions.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "log_module.hxx" 32*cdf0e10cSrcweir #include "methodguard.hxx" 33*cdf0e10cSrcweir #include "loghandler.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir /** === begin UNO includes === **/ 36*cdf0e10cSrcweir #include <com/sun/star/logging/XLogHandler.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/ucb/AlreadyInitializedException.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/util/XStringSubstitution.hpp> 42*cdf0e10cSrcweir /** === end UNO includes === **/ 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <cppuhelper/compbase3.hxx> 49*cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #include <osl/thread.h> 52*cdf0e10cSrcweir #include <osl/file.hxx> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #include <rtl/strbuf.hxx> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include <memory> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir //........................................................................ 59*cdf0e10cSrcweir namespace logging 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir //........................................................................ 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir /** === begin UNO using === **/ 64*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 65*cdf0e10cSrcweir using ::com::sun::star::logging::LogRecord; 66*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 67*cdf0e10cSrcweir using ::com::sun::star::logging::XLogFormatter; 68*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 69*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 70*cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext; 71*cdf0e10cSrcweir using ::com::sun::star::logging::XLogHandler; 72*cdf0e10cSrcweir using ::com::sun::star::lang::XServiceInfo; 73*cdf0e10cSrcweir using ::com::sun::star::ucb::AlreadyInitializedException; 74*cdf0e10cSrcweir using ::com::sun::star::lang::XInitialization; 75*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 76*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 77*cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException; 78*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 79*cdf0e10cSrcweir using ::com::sun::star::util::XStringSubstitution; 80*cdf0e10cSrcweir using ::com::sun::star::beans::NamedValue; 81*cdf0e10cSrcweir /** === end UNO using === **/ 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir //==================================================================== 84*cdf0e10cSrcweir //= FileHandler - declaration 85*cdf0e10cSrcweir //==================================================================== 86*cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper3 < XLogHandler 87*cdf0e10cSrcweir , XServiceInfo 88*cdf0e10cSrcweir , XInitialization 89*cdf0e10cSrcweir > FileHandler_Base; 90*cdf0e10cSrcweir class FileHandler :public ::cppu::BaseMutex 91*cdf0e10cSrcweir ,public FileHandler_Base 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir private: 94*cdf0e10cSrcweir enum FileValidity 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir /// never attempted to open the file 97*cdf0e10cSrcweir eUnknown, 98*cdf0e10cSrcweir /// file is valid 99*cdf0e10cSrcweir eValid, 100*cdf0e10cSrcweir /// file is invalid 101*cdf0e10cSrcweir eInvalid 102*cdf0e10cSrcweir }; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir private: 105*cdf0e10cSrcweir ::comphelper::ComponentContext m_aContext; 106*cdf0e10cSrcweir LogHandlerHelper m_aHandlerHelper; 107*cdf0e10cSrcweir ::rtl::OUString m_sFileURL; 108*cdf0e10cSrcweir ::std::auto_ptr< ::osl::File > m_pFile; 109*cdf0e10cSrcweir FileValidity m_eFileValidity; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir protected: 112*cdf0e10cSrcweir FileHandler( const Reference< XComponentContext >& _rxContext ); 113*cdf0e10cSrcweir virtual ~FileHandler(); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir // XLogHandler 116*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getEncoding() throw (RuntimeException); 117*cdf0e10cSrcweir virtual void SAL_CALL setEncoding( const ::rtl::OUString& _encoding ) throw (RuntimeException); 118*cdf0e10cSrcweir virtual Reference< XLogFormatter > SAL_CALL getFormatter() throw (RuntimeException); 119*cdf0e10cSrcweir virtual void SAL_CALL setFormatter( const Reference< XLogFormatter >& _formatter ) throw (RuntimeException); 120*cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getLevel() throw (RuntimeException); 121*cdf0e10cSrcweir virtual void SAL_CALL setLevel( ::sal_Int32 _level ) throw (RuntimeException); 122*cdf0e10cSrcweir virtual void SAL_CALL flush( ) throw (RuntimeException); 123*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL publish( const LogRecord& Record ) throw (RuntimeException); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // XInitialization 126*cdf0e10cSrcweir virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // XServiceInfo 129*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException); 130*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException); 131*cdf0e10cSrcweir virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // OComponentHelper 134*cdf0e10cSrcweir virtual void SAL_CALL disposing(); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir public: 137*cdf0e10cSrcweir // XServiceInfo - static version 138*cdf0e10cSrcweir static ::rtl::OUString SAL_CALL getImplementationName_static(); 139*cdf0e10cSrcweir static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(); 140*cdf0e10cSrcweir static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir public: 143*cdf0e10cSrcweir typedef ComponentMethodGuard< FileHandler > MethodGuard; 144*cdf0e10cSrcweir void enterMethod( MethodGuard::Access ); 145*cdf0e10cSrcweir void leaveMethod( MethodGuard::Access ); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir private: 148*cdf0e10cSrcweir /** prepares our output file for writing 149*cdf0e10cSrcweir */ 150*cdf0e10cSrcweir bool impl_prepareFile_nothrow(); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir /// writes the given string to our file 153*cdf0e10cSrcweir void impl_writeString_nothrow( const ::rtl::OString& _rEntry ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir /** does string substitution on a (usually externally provided) file url 156*cdf0e10cSrcweir */ 157*cdf0e10cSrcweir void impl_doStringsubstitution_nothrow( ::rtl::OUString& _inout_rURL ); 158*cdf0e10cSrcweir }; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //==================================================================== 161*cdf0e10cSrcweir //= FileHandler - implementation 162*cdf0e10cSrcweir //==================================================================== 163*cdf0e10cSrcweir //-------------------------------------------------------------------- 164*cdf0e10cSrcweir FileHandler::FileHandler( const Reference< XComponentContext >& _rxContext ) 165*cdf0e10cSrcweir :FileHandler_Base( m_aMutex ) 166*cdf0e10cSrcweir ,m_aContext( _rxContext ) 167*cdf0e10cSrcweir ,m_aHandlerHelper( _rxContext, m_aMutex, rBHelper ) 168*cdf0e10cSrcweir ,m_sFileURL( ) 169*cdf0e10cSrcweir ,m_pFile( ) 170*cdf0e10cSrcweir ,m_eFileValidity( eUnknown ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir //-------------------------------------------------------------------- 175*cdf0e10cSrcweir FileHandler::~FileHandler() 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir if ( !rBHelper.bDisposed ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir acquire(); 180*cdf0e10cSrcweir dispose(); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir //-------------------------------------------------------------------- 185*cdf0e10cSrcweir bool FileHandler::impl_prepareFile_nothrow() 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir if ( m_eFileValidity == eUnknown ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir m_pFile.reset( new ::osl::File( m_sFileURL ) ); 190*cdf0e10cSrcweir // check whether the log file already exists 191*cdf0e10cSrcweir ::osl::DirectoryItem aFileItem; 192*cdf0e10cSrcweir ::osl::DirectoryItem::get( m_sFileURL, aFileItem ); 193*cdf0e10cSrcweir ::osl::FileStatus aStatus( FileStatusMask_Validate ); 194*cdf0e10cSrcweir if ( ::osl::FileBase::E_None == aFileItem.getFileStatus( aStatus ) ) 195*cdf0e10cSrcweir ::osl::File::remove( m_sFileURL ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir ::osl::FileBase::RC res = m_pFile->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ); 198*cdf0e10cSrcweir m_eFileValidity = res == ::osl::FileBase::E_None 199*cdf0e10cSrcweir ? eValid 200*cdf0e10cSrcweir : eInvalid; 201*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 202*cdf0e10cSrcweir if ( m_eFileValidity == eInvalid ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir ::rtl::OStringBuffer sMessage; 205*cdf0e10cSrcweir sMessage.append( "FileHandler::impl_prepareFile_nothrow: could not open the designated log file:" ); 206*cdf0e10cSrcweir sMessage.append( "\nURL: " ); 207*cdf0e10cSrcweir sMessage.append( ::rtl::OString( m_sFileURL.getStr(), m_sFileURL.getLength(), osl_getThreadTextEncoding() ) ); 208*cdf0e10cSrcweir sMessage.append( "\nerror code: " ); 209*cdf0e10cSrcweir sMessage.append( (sal_Int32)res ); 210*cdf0e10cSrcweir OSL_ENSURE( false, sMessage.makeStringAndClear() ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir #endif 213*cdf0e10cSrcweir if ( m_eFileValidity == eValid ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir ::rtl::OString sHead; 216*cdf0e10cSrcweir if ( m_aHandlerHelper.getEncodedHead( sHead ) ) 217*cdf0e10cSrcweir impl_writeString_nothrow( sHead ); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir return m_eFileValidity == eValid; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir //-------------------------------------------------------------------- 225*cdf0e10cSrcweir void FileHandler::impl_writeString_nothrow( const ::rtl::OString& _rEntry ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir OSL_PRECOND( m_pFile.get(), "FileHandler::impl_writeString_nothrow: no file!" ); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir sal_uInt64 nBytesToWrite( _rEntry.getLength() ); 230*cdf0e10cSrcweir sal_uInt64 nBytesWritten( 0 ); 231*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 232*cdf0e10cSrcweir ::osl::FileBase::RC res = 233*cdf0e10cSrcweir #endif 234*cdf0e10cSrcweir m_pFile->write( _rEntry.getStr(), nBytesToWrite, nBytesWritten ); 235*cdf0e10cSrcweir OSL_ENSURE( ( res == ::osl::FileBase::E_None ) && ( nBytesWritten == nBytesToWrite ), 236*cdf0e10cSrcweir "FileHandler::impl_writeString_nothrow: could not write the log entry!" ); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir //-------------------------------------------------------------------- 240*cdf0e10cSrcweir void FileHandler::impl_doStringsubstitution_nothrow( ::rtl::OUString& _inout_rURL ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir try 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir Reference< XStringSubstitution > xStringSubst; 245*cdf0e10cSrcweir if ( m_aContext.createComponent( "com.sun.star.util.PathSubstitution", xStringSubst ) ) 246*cdf0e10cSrcweir _inout_rURL = xStringSubst->substituteVariables( _inout_rURL, true ); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir catch( const Exception& ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir //-------------------------------------------------------------------- 255*cdf0e10cSrcweir void SAL_CALL FileHandler::disposing() 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir if ( m_eFileValidity == eValid ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir ::rtl::OString sTail; 260*cdf0e10cSrcweir if ( m_aHandlerHelper.getEncodedTail( sTail ) ) 261*cdf0e10cSrcweir impl_writeString_nothrow( sTail ); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir m_pFile.reset( NULL ); 265*cdf0e10cSrcweir m_aHandlerHelper.setFormatter( NULL ); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir //-------------------------------------------------------------------- 269*cdf0e10cSrcweir void FileHandler::enterMethod( MethodGuard::Access ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir m_aHandlerHelper.enterMethod(); 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir //-------------------------------------------------------------------- 275*cdf0e10cSrcweir void FileHandler::leaveMethod( MethodGuard::Access ) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir m_aMutex.release(); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir //-------------------------------------------------------------------- 281*cdf0e10cSrcweir ::rtl::OUString SAL_CALL FileHandler::getEncoding() throw (RuntimeException) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir MethodGuard aGuard( *this ); 284*cdf0e10cSrcweir ::rtl::OUString sEncoding; 285*cdf0e10cSrcweir OSL_VERIFY( m_aHandlerHelper.getEncoding( sEncoding ) ); 286*cdf0e10cSrcweir return sEncoding; 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir //-------------------------------------------------------------------- 290*cdf0e10cSrcweir void SAL_CALL FileHandler::setEncoding( const ::rtl::OUString& _rEncoding ) throw (RuntimeException) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir MethodGuard aGuard( *this ); 293*cdf0e10cSrcweir OSL_VERIFY( m_aHandlerHelper.setEncoding( _rEncoding ) ); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir //-------------------------------------------------------------------- 297*cdf0e10cSrcweir Reference< XLogFormatter > SAL_CALL FileHandler::getFormatter() throw (RuntimeException) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir MethodGuard aGuard( *this ); 300*cdf0e10cSrcweir return m_aHandlerHelper.getFormatter(); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir //-------------------------------------------------------------------- 304*cdf0e10cSrcweir void SAL_CALL FileHandler::setFormatter( const Reference< XLogFormatter >& _rxFormatter ) throw (RuntimeException) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir MethodGuard aGuard( *this ); 307*cdf0e10cSrcweir m_aHandlerHelper.setFormatter( _rxFormatter ); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir //-------------------------------------------------------------------- 311*cdf0e10cSrcweir ::sal_Int32 SAL_CALL FileHandler::getLevel() throw (RuntimeException) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir MethodGuard aGuard( *this ); 314*cdf0e10cSrcweir return m_aHandlerHelper.getLevel(); 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir //-------------------------------------------------------------------- 318*cdf0e10cSrcweir void SAL_CALL FileHandler::setLevel( ::sal_Int32 _nLevel ) throw (RuntimeException) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir MethodGuard aGuard( *this ); 321*cdf0e10cSrcweir m_aHandlerHelper.setLevel( _nLevel ); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir //-------------------------------------------------------------------- 325*cdf0e10cSrcweir void SAL_CALL FileHandler::flush( ) throw (RuntimeException) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir MethodGuard aGuard( *this ); 328*cdf0e10cSrcweir if(!m_pFile.get()) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir OSL_PRECOND(false, "FileHandler::flush: no file!"); 331*cdf0e10cSrcweir return; 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 334*cdf0e10cSrcweir ::osl::FileBase::RC res = 335*cdf0e10cSrcweir #endif 336*cdf0e10cSrcweir m_pFile->sync(); 337*cdf0e10cSrcweir OSL_ENSURE(res == ::osl::FileBase::E_None, "FileHandler::flush: Could not sync logfile to filesystem."); 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir //-------------------------------------------------------------------- 341*cdf0e10cSrcweir ::sal_Bool SAL_CALL FileHandler::publish( const LogRecord& _rRecord ) throw (RuntimeException) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir MethodGuard aGuard( *this ); 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir if ( !impl_prepareFile_nothrow() ) 346*cdf0e10cSrcweir return sal_False; 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir ::rtl::OString sEntry; 349*cdf0e10cSrcweir if ( !m_aHandlerHelper.formatForPublishing( _rRecord, sEntry ) ) 350*cdf0e10cSrcweir return sal_False; 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir impl_writeString_nothrow( sEntry ); 353*cdf0e10cSrcweir return sal_True; 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir //-------------------------------------------------------------------- 357*cdf0e10cSrcweir void SAL_CALL FileHandler::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir if ( m_aHandlerHelper.getIsInitialized() ) 362*cdf0e10cSrcweir throw AlreadyInitializedException(); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir if ( _rArguments.getLength() != 1 ) 365*cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir Sequence< NamedValue > aSettings; 368*cdf0e10cSrcweir if ( _rArguments[0] >>= m_sFileURL ) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir // create( [in] string URL ); 371*cdf0e10cSrcweir impl_doStringsubstitution_nothrow( m_sFileURL ); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir else if ( _rArguments[0] >>= aSettings ) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir // createWithSettings( [in] sequence< ::com::sun::star::beans::NamedValue > Settings ) 376*cdf0e10cSrcweir ::comphelper::NamedValueCollection aTypedSettings( aSettings ); 377*cdf0e10cSrcweir m_aHandlerHelper.initFromSettings( aTypedSettings ); 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir if ( aTypedSettings.get_ensureType( "FileURL", m_sFileURL ) ) 380*cdf0e10cSrcweir impl_doStringsubstitution_nothrow( m_sFileURL ); 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir else 383*cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir m_aHandlerHelper.setIsInitialized(); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir //-------------------------------------------------------------------- 389*cdf0e10cSrcweir ::rtl::OUString SAL_CALL FileHandler::getImplementationName() throw(RuntimeException) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir return getImplementationName_static(); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir //-------------------------------------------------------------------- 395*cdf0e10cSrcweir ::sal_Bool SAL_CALL FileHandler::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir const Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() ); 398*cdf0e10cSrcweir for ( const ::rtl::OUString* pServiceNames = aServiceNames.getConstArray(); 399*cdf0e10cSrcweir pServiceNames != aServiceNames.getConstArray() + aServiceNames.getLength(); 400*cdf0e10cSrcweir ++pServiceNames 401*cdf0e10cSrcweir ) 402*cdf0e10cSrcweir if ( _rServiceName == *pServiceNames ) 403*cdf0e10cSrcweir return sal_True; 404*cdf0e10cSrcweir return sal_False; 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir //-------------------------------------------------------------------- 408*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL FileHandler::getSupportedServiceNames() throw(RuntimeException) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir return getSupportedServiceNames_static(); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir //-------------------------------------------------------------------- 414*cdf0e10cSrcweir ::rtl::OUString SAL_CALL FileHandler::getImplementationName_static() 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.FileHandler" ) ); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir //-------------------------------------------------------------------- 420*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL FileHandler::getSupportedServiceNames_static() 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir Sequence< ::rtl::OUString > aServiceNames(1); 423*cdf0e10cSrcweir aServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.FileHandler" ) ); 424*cdf0e10cSrcweir return aServiceNames; 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir //-------------------------------------------------------------------- 428*cdf0e10cSrcweir Reference< XInterface > FileHandler::Create( const Reference< XComponentContext >& _rxContext ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir return *( new FileHandler( _rxContext ) ); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir //-------------------------------------------------------------------- 434*cdf0e10cSrcweir void createRegistryInfo_FileHandler() 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir static OAutoRegistration< FileHandler > aAutoRegistration; 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir //........................................................................ 440*cdf0e10cSrcweir } // namespace logging 441*cdf0e10cSrcweir //........................................................................ 442