LCOV - code coverage report
Current view: top level - extensions/source/logging - loghandler.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 59 0.0 %
Date: 2014-04-14 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "loghandler.hxx"
      22             : 
      23             : #include <com/sun/star/logging/LogLevel.hpp>
      24             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      25             : #include <com/sun/star/lang/DisposedException.hpp>
      26             : #include <com/sun/star/logging/PlainTextFormatter.hpp>
      27             : 
      28             : #include <tools/diagnose_ex.h>
      29             : #include <rtl/tencinfo.h>
      30             : 
      31             : 
      32             : namespace logging
      33             : {
      34             : 
      35             : 
      36             :     using ::com::sun::star::uno::Reference;
      37             :     using ::com::sun::star::uno::XComponentContext;
      38             :     using ::com::sun::star::uno::Any;
      39             :     using ::com::sun::star::logging::LogRecord;
      40             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      41             :     using ::com::sun::star::logging::XLogFormatter;
      42             :     using ::com::sun::star::uno::Exception;
      43             :     using ::com::sun::star::lang::IllegalArgumentException;
      44             :     using ::com::sun::star::lang::DisposedException;
      45             :     using ::com::sun::star::logging::PlainTextFormatter;
      46             : 
      47             :     namespace LogLevel = ::com::sun::star::logging::LogLevel;
      48             : 
      49             : 
      50             :     //= LogHandlerHelper
      51             : 
      52             : 
      53           0 :     LogHandlerHelper::LogHandlerHelper( const Reference< XComponentContext >& _rxContext, ::osl::Mutex& _rMutex, ::cppu::OBroadcastHelper& _rBHelper )
      54             :         :m_eEncoding( RTL_TEXTENCODING_UTF8 )
      55             :         ,m_nLevel( LogLevel::SEVERE )
      56             :         ,m_xFormatter( NULL )
      57             :         ,m_xContext( _rxContext )
      58             :         ,m_rMutex( _rMutex )
      59             :         ,m_rBHelper( _rBHelper )
      60           0 :         ,m_bInitialized( false )
      61             :     {
      62           0 :     }
      63             : 
      64             : 
      65           0 :     void LogHandlerHelper::initFromSettings( const ::comphelper::NamedValueCollection& _rSettings )
      66             :     {
      67           0 :         OUString sEncoding;
      68           0 :         if ( _rSettings.get_ensureType( "Encoding", sEncoding ) )
      69             :         {
      70           0 :             if ( !setEncoding( sEncoding ) )
      71           0 :                 throw IllegalArgumentException();
      72             :         }
      73             : 
      74           0 :         _rSettings.get_ensureType( "Formatter", m_xFormatter );
      75           0 :         _rSettings.get_ensureType( "Level", m_nLevel );
      76           0 :     }
      77             : 
      78             : 
      79           0 :     void LogHandlerHelper::enterMethod()
      80             :     {
      81           0 :         m_rMutex.acquire();
      82             : 
      83           0 :         if ( !getIsInitialized() )
      84           0 :             throw DisposedException("component not initialized", NULL );
      85             : 
      86           0 :         if ( m_rBHelper.bDisposed )
      87           0 :             throw DisposedException("component already disposed", NULL );
      88             : 
      89             :         // fallback settings, in case they weren't passed at construction time
      90           0 :         if ( !getFormatter().is() )
      91             :         {
      92             :             try
      93             :             {
      94           0 :                 Reference< XLogFormatter > xFormatter( PlainTextFormatter::create( m_xContext ), UNO_QUERY_THROW );
      95           0 :                 setFormatter( xFormatter );
      96             :             }
      97           0 :             catch( const Exception& )
      98             :             {
      99             :                 DBG_UNHANDLED_EXCEPTION();
     100             :             }
     101             :         }
     102           0 :     }
     103             : 
     104             : 
     105           0 :     bool LogHandlerHelper::getEncoding( OUString& _out_rEncoding ) const
     106             :     {
     107           0 :         const char* pMimeCharset = rtl_getMimeCharsetFromTextEncoding( m_eEncoding );
     108           0 :         if ( pMimeCharset )
     109             :         {
     110           0 :             _out_rEncoding = OUString::createFromAscii( pMimeCharset );
     111           0 :             return true;
     112             :         }
     113           0 :         _out_rEncoding = OUString();
     114           0 :         return false;
     115             :     }
     116             : 
     117             : 
     118           0 :     bool LogHandlerHelper::setEncoding( const OUString& _rEncoding )
     119             :     {
     120           0 :         OString sAsciiEncoding( OUStringToOString( _rEncoding, RTL_TEXTENCODING_ASCII_US ) );
     121           0 :         rtl_TextEncoding eEncoding = rtl_getTextEncodingFromMimeCharset( sAsciiEncoding.getStr() );
     122           0 :         if ( eEncoding != RTL_TEXTENCODING_DONTKNOW )
     123             :         {
     124           0 :             m_eEncoding = eEncoding;
     125           0 :             return true;
     126             :         }
     127           0 :         return false;
     128             :     }
     129             : 
     130             : 
     131           0 :     bool LogHandlerHelper::formatForPublishing( const LogRecord& _rRecord, OString& _out_rEntry ) const
     132             :     {
     133           0 :         if ( _rRecord.Level < getLevel() )
     134             :             // not to be published due to low level
     135           0 :             return false;
     136             : 
     137             :         try
     138             :         {
     139           0 :             Reference< XLogFormatter > xFormatter( getFormatter(), UNO_QUERY_THROW );
     140           0 :             OUString sEntry( xFormatter->format( _rRecord ) );
     141           0 :             _out_rEntry = OUStringToOString( sEntry, getTextEncoding() );
     142           0 :             return true;
     143             :         }
     144           0 :         catch( const Exception& )
     145             :         {
     146             :             DBG_UNHANDLED_EXCEPTION();
     147             :         }
     148           0 :         return false;
     149             :     }
     150             : 
     151             : 
     152           0 :     bool LogHandlerHelper::getEncodedHead( OString& _out_rHead ) const
     153             :     {
     154             :         try
     155             :         {
     156           0 :             Reference< XLogFormatter > xFormatter( getFormatter(), UNO_QUERY_THROW );
     157           0 :             OUString sHead( xFormatter->getHead() );
     158           0 :             _out_rHead = OUStringToOString( sHead, getTextEncoding() );
     159           0 :             return true;
     160             :         }
     161           0 :         catch( const Exception& )
     162             :         {
     163             :             DBG_UNHANDLED_EXCEPTION();
     164             :         }
     165           0 :         return false;
     166             :     }
     167             : 
     168             : 
     169           0 :     bool LogHandlerHelper::getEncodedTail( OString& _out_rTail ) const
     170             :     {
     171             :         try
     172             :         {
     173           0 :             Reference< XLogFormatter > xFormatter( getFormatter(), UNO_QUERY_THROW );
     174           0 :             OUString sTail( xFormatter->getTail() );
     175           0 :             _out_rTail = OUStringToOString( sTail, getTextEncoding() );
     176           0 :             return true;
     177             :         }
     178           0 :         catch( const Exception& )
     179             :         {
     180             :             DBG_UNHANDLED_EXCEPTION();
     181             :         }
     182           0 :         return false;
     183             :     }
     184             : 
     185             : 
     186             : } // namespace logging
     187             : 
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10