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 #ifndef LOGHANDLER_HXX 29*cdf0e10cSrcweir #define LOGHANDLER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir /** === begin UNO includes === **/ 32*cdf0e10cSrcweir #include <com/sun/star/logging/XLogFormatter.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/logging/LogRecord.hpp> 35*cdf0e10cSrcweir /** === end UNO includes === **/ 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 38*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 39*cdf0e10cSrcweir #include <rtl/string.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //........................................................................ 42*cdf0e10cSrcweir namespace logging 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir //........................................................................ 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //==================================================================== 47*cdf0e10cSrcweir //= 48*cdf0e10cSrcweir //==================================================================== 49*cdf0e10cSrcweir class LogHandlerHelper 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir private: 52*cdf0e10cSrcweir // <attributes> 53*cdf0e10cSrcweir rtl_TextEncoding m_eEncoding; 54*cdf0e10cSrcweir sal_Int32 m_nLevel; 55*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter > 56*cdf0e10cSrcweir m_xFormatter; 57*cdf0e10cSrcweir // <//attributes> 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > 60*cdf0e10cSrcweir m_xContext; 61*cdf0e10cSrcweir ::osl::Mutex& m_rMutex; 62*cdf0e10cSrcweir ::cppu::OBroadcastHelper& m_rBHelper; 63*cdf0e10cSrcweir bool m_bInitialized; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir public: 66*cdf0e10cSrcweir LogHandlerHelper( 67*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext, 68*cdf0e10cSrcweir ::osl::Mutex& _rMutex, 69*cdf0e10cSrcweir ::cppu::OBroadcastHelper& _rBHelper 70*cdf0e10cSrcweir ); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir public: 73*cdf0e10cSrcweir bool getIsInitialized() const { return m_bInitialized; } 74*cdf0e10cSrcweir void setIsInitialized() { m_bInitialized = true; } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir bool getEncoding( ::rtl::OUString& _out_rEncoding ) const; 77*cdf0e10cSrcweir bool setEncoding( const ::rtl::OUString& _rEncoding ); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir inline rtl_TextEncoding 80*cdf0e10cSrcweir getTextEncoding() const { return m_eEncoding; } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter > 83*cdf0e10cSrcweir getFormatter() const { return m_xFormatter; } 84*cdf0e10cSrcweir inline void 85*cdf0e10cSrcweir setFormatter( const ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >& _rxFormatter ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir m_xFormatter = _rxFormatter; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir inline sal_Int32 91*cdf0e10cSrcweir getLevel() const { return m_nLevel; } 92*cdf0e10cSrcweir inline void 93*cdf0e10cSrcweir setLevel( const sal_Int32 _nLevel ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir m_nLevel = _nLevel; 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir /** prepares implementation of an public accessible method of a log handler 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir <code>enterMethod</code> does the following things: 101*cdf0e10cSrcweir <ul><li>It acquires the mutex given in the constructor.</li> 102*cdf0e10cSrcweir <li>It checks whether the component is already initialized, and throws an exception if not os.</li> 103*cdf0e10cSrcweir <li>It checks whether the component is already disposed, and throws an exception if not os.</li> 104*cdf0e10cSrcweir <li>It creates a default formatter (PlainTextFormatter), if no formatter exists at this time.</li> 105*cdf0e10cSrcweir </ul> 106*cdf0e10cSrcweir */ 107*cdf0e10cSrcweir void enterMethod(); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /** formats a record for publishing it 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir The method first checks whether the records log level is greater or equal our own 112*cdf0e10cSrcweir log level. If not, <FALSE/> is returned. 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir Second, our formatter is used to create a unicode string from the log record. If an error occurs 115*cdf0e10cSrcweir during this, e.g. if the formatter is <NULL/> or throws an exception during formatting, 116*cdf0e10cSrcweir <FALSE/> is returned. 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir Finally, the unicode string is encoded into a byte string, using our encoding setting. Then, 119*cdf0e10cSrcweir <TRUE/> is returned. 120*cdf0e10cSrcweir */ 121*cdf0e10cSrcweir bool formatForPublishing( const ::com::sun::star::logging::LogRecord& _rRecord, ::rtl::OString& _out_rEntry ) const; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir /** retrieves our formatter's heading, encoded with our encoding 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir @return <TRUE/> in case of success, <FALSE/> if any error occured 126*cdf0e10cSrcweir */ 127*cdf0e10cSrcweir bool getEncodedHead( ::rtl::OString& _out_rHead ) const; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir /** retrieves our formatter's tail, encoded with our encoding 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir @return <TRUE/> in case of success, <FALSE/> if any error occured 132*cdf0e10cSrcweir */ 133*cdf0e10cSrcweir bool getEncodedTail( ::rtl::OString& _out_rTail ) const; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir /** initializes the instance from a collection of named settings 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir The recognized named settings are <code>Encoding</code>, <code>Formatter</code>, and <code>Level</code>, 138*cdf0e10cSrcweir which initialize the respective attributes. 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir Settings which are recognized are remove from the given collection. This allows 141*cdf0e10cSrcweir the caller to determine whether or not the collection contained any unsupported 142*cdf0e10cSrcweir items, and react appropriately. 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir @throws IllegalArgumentException 145*cdf0e10cSrcweir if one of the values in the collection is of wrong type. 146*cdf0e10cSrcweir */ 147*cdf0e10cSrcweir void initFromSettings( const ::comphelper::NamedValueCollection& _rSettings ); 148*cdf0e10cSrcweir }; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir //........................................................................ 151*cdf0e10cSrcweir } // namespace logging 152*cdf0e10cSrcweir //........................................................................ 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir #endif // LOGHANDLER_HXX 155