LCOV - code coverage report
Current view: top level - filter/source/filtertracer - filtertracer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 112 0.0 %
Date: 2012-08-25 Functions: 0 21 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "filtertracer.hxx"
      30                 :            : #include <uno/mapping.hxx>
      31                 :            : #include <unotools/streamwrap.hxx>
      32                 :            : #include <unotools/ucbstreamhelper.hxx>
      33                 :            : #include <com/sun/star/util/TextSearch.hpp>
      34                 :            : #include <comphelper/componentcontext.hxx>
      35                 :            : // ----------------
      36                 :            : // - FILTERTRACER -
      37                 :            : // ----------------
      38                 :            : 
      39                 :            : using namespace ::com::sun::star;
      40                 :            : 
      41                 :          0 : rtl::OUString FilterTracer_getImplementationName()
      42                 :            :     throw( NMSP_UNO::RuntimeException )
      43                 :            : {
      44                 :          0 :     return B2UCONST( "com.sun.star.util.FilterTracer" );
      45                 :            : }
      46                 :          0 : sal_Bool SAL_CALL FilterTracer_supportsService( const rtl::OUString& ServiceName )
      47                 :            :     throw( NMSP_UNO::RuntimeException )
      48                 :            : {
      49                 :          0 :     return ServiceName == "com.sun.star.util.logging.Logger";
      50                 :            : }
      51                 :          0 : SEQ( rtl::OUString ) SAL_CALL FilterTracer_getSupportedServiceNames()
      52                 :            :     throw( NMSP_UNO::RuntimeException )
      53                 :            : {
      54                 :          0 :     SEQ( rtl::OUString ) aRet(1);
      55                 :          0 :     rtl::OUString* pArray = aRet.getArray();
      56                 :          0 :     pArray[0] = B2UCONST( "com.sun.star.util.logging.Logger" );
      57                 :          0 :     return aRet;
      58                 :            : }
      59                 :            : 
      60                 :            : // -----------------------------------------------------------------------------
      61                 :            : 
      62                 :          0 : FilterTracer::FilterTracer( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ) :
      63                 :            :     xFact       ( rxMgr ),
      64                 :            :     mpStream    ( NULL ),
      65                 :          0 :     mnLogLevel  ( NMSP_LOGGING::LogLevel::ALL )
      66                 :            : {
      67                 :          0 :     uno::Reference< uno::XComponentContext > xContext( comphelper::ComponentContext(rxMgr).getUNOContext() );
      68                 :          0 :     mxTextSearch = com::sun::star::util::TextSearch::create(xContext);
      69                 :          0 : }
      70                 :          0 : FilterTracer::~FilterTracer()
      71                 :            : {
      72                 :          0 :     if ( mpStream )
      73                 :            :     {
      74                 :          0 :         mxOutputStream = NULL;
      75                 :          0 :         delete mpStream;
      76                 :            :     }
      77                 :          0 : }
      78                 :            : 
      79                 :            : // -----------------------------------------------------------------------------
      80                 :            : 
      81                 :            : // XInterface
      82                 :          0 : void SAL_CALL FilterTracer::acquire() throw()
      83                 :            : {
      84                 :          0 :     OWeakObject::acquire();
      85                 :          0 : }
      86                 :          0 : void SAL_CALL FilterTracer::release() throw()
      87                 :            : {
      88                 :          0 :     OWeakObject::release();
      89                 :          0 : }
      90                 :            : 
      91                 :            : // -----------------------------------------------------------------------------
      92                 :            : 
      93                 :            : // checks if the tokens of rFilter can be found in rString
      94                 :          0 : sal_Bool FilterTracer::ImplFilter( const rtl::OUString& rFilter, const rtl::OUString& rString )
      95                 :            : {
      96                 :          0 :     sal_Bool bFilter = sal_False;
      97                 :          0 :     if ( mxTextSearch.is() )
      98                 :            :     {
      99                 :          0 :         maSearchOptions.searchString = rFilter;
     100                 :          0 :         mxTextSearch->setOptions( maSearchOptions );
     101                 :          0 :         NMSP_UTIL::SearchResult aSearchResult = mxTextSearch->searchForward( rString, 0, rString.getLength() );
     102                 :          0 :         bFilter = aSearchResult.subRegExpressions != 0;
     103                 :            :     }
     104                 :          0 :     return bFilter;
     105                 :            : }
     106                 :            : 
     107                 :            : // -----------------------------------------------------------------------------
     108                 :            : 
     109                 :            : // XInitialization
     110                 :          0 : void SAL_CALL FilterTracer::initialize( const SEQ( NMSP_UNO::Any )& aArguments )
     111                 :            :     throw ( NMSP_UNO::Exception, NMSP_UNO::RuntimeException )
     112                 :            : {
     113                 :            :     sal_Int32 i;
     114                 :          0 :     SEQ( NMSP_BEANS::PropertyValue ) aParameter;
     115                 :          0 :     for ( i = 0; i < aArguments.getLength(); i++ )
     116                 :            :     {
     117                 :          0 :         if ( aArguments[ i ] >>= aParameter )
     118                 :          0 :             break;
     119                 :            :     }
     120                 :          0 :     for ( i = 0; i < aParameter.getLength(); i++ )
     121                 :            :     {
     122                 :          0 :         const NMSP_BEANS::PropertyValue& rProp = aParameter[ i ];
     123                 :          0 :         if ( rProp.Name == "LogLevel" )
     124                 :          0 :             rProp.Value >>= mnLogLevel;
     125                 :          0 :         else if ( rProp.Name == "ClassFilter" )
     126                 :          0 :             rProp.Value >>= msClassFilter;
     127                 :          0 :         else if ( rProp.Name == "MethodFilter" )
     128                 :          0 :             rProp.Value >>= msMethodFilter;
     129                 :          0 :         else if ( rProp.Name == "MessageFilter" )
     130                 :          0 :             rProp.Value >>= msMessageFilter;
     131                 :          0 :         else if ( rProp.Name == "OutputStream" )
     132                 :          0 :             rProp.Value >>= mxOutputStream;
     133                 :          0 :         else if ( rProp.Name == "URL" )
     134                 :          0 :             rProp.Value >>= msURL;
     135                 :          0 :         else if ( rProp.Name == "DocumentHandler" )
     136                 :          0 :             rProp.Value >>= mxDocumentHandler;
     137                 :            :     }
     138                 :            : 
     139                 :            :     // check if we have to create the XOutputStream
     140                 :          0 :     if ( !(mxOutputStream.is() || msURL.isEmpty()) )
     141                 :            :     {
     142                 :          0 :         mpStream = ::utl::UcbStreamHelper::CreateStream( msURL, STREAM_WRITE | STREAM_TRUNC | STREAM_SHARE_DENYNONE );
     143                 :          0 :         if ( mpStream )
     144                 :            :         {
     145                 :          0 :             ::utl::OOutputStreamWrapper* pHelper = new ::utl::OOutputStreamWrapper( *mpStream );
     146                 :          0 :             mxOutputStream = pHelper;
     147                 :            :         }
     148                 :          0 :     }
     149                 :          0 : }
     150                 :            : 
     151                 :            : // -----------------------------------------------------------------------------
     152                 :            : 
     153                 :            : // XServiceInfo
     154                 :          0 : rtl::OUString SAL_CALL FilterTracer::getImplementationName()
     155                 :            :     throw( NMSP_UNO::RuntimeException )
     156                 :            : {
     157                 :          0 :     return FilterTracer_getImplementationName();
     158                 :            : }
     159                 :          0 : sal_Bool SAL_CALL FilterTracer::supportsService( const rtl::OUString& rServiceName )
     160                 :            :     throw( NMSP_UNO::RuntimeException )
     161                 :            : {
     162                 :          0 :     return FilterTracer_supportsService( rServiceName );
     163                 :            : }
     164                 :          0 : SEQ( rtl::OUString ) SAL_CALL FilterTracer::getSupportedServiceNames()
     165                 :            :     throw ( NMSP_UNO::RuntimeException )
     166                 :            : {
     167                 :          0 :     return FilterTracer_getSupportedServiceNames();
     168                 :            : }
     169                 :            : 
     170                 :            : // -----------------------------------------------------------------------------
     171                 :            : 
     172                 :            : // XLogger
     173                 :          0 : REF( NMSP_LOGGING::XLogger ) SAL_CALL  FilterTracer::getLogger( const rtl::OUString& /* rName */ )
     174                 :            :      throw (::com::sun::star::uno::RuntimeException)
     175                 :            : {
     176                 :          0 :     REF( NMSP_LOGGING::XLogger ) xLog( this );
     177                 :          0 :     return xLog;
     178                 :            : }
     179                 :          0 : sal_Int32 SAL_CALL FilterTracer::getLevel() throw (::com::sun::star::uno::RuntimeException)
     180                 :            : {
     181                 :          0 :     return mnLogLevel;
     182                 :            : }
     183                 :          0 : rtl::OUString SAL_CALL FilterTracer::getName() throw (::com::sun::star::uno::RuntimeException)
     184                 :            : {
     185                 :          0 :     rtl::OUString aName;
     186                 :          0 :     return aName;
     187                 :            : }
     188                 :          0 : sal_Bool SAL_CALL FilterTracer::isLoggable( sal_Int32 nLevel )
     189                 :            :      throw (::com::sun::star::uno::RuntimeException)
     190                 :            : {
     191                 :          0 :     return mnLogLevel <= nLevel;
     192                 :            : }
     193                 :          0 : void SAL_CALL FilterTracer::logp( sal_Int32 /* nLevel */, const rtl::OUString& rSourceClass,
     194                 :            :         const rtl::OUString& rSourceMethod, const rtl::OUString& rMessage )
     195                 :            :      throw (::com::sun::star::uno::RuntimeException)
     196                 :            : {
     197                 :          0 :     if ( mxOutputStream.is() || mxDocumentHandler.is() )
     198                 :            :     {
     199                 :          0 :         if ( ! ( ImplFilter( msClassFilter, rSourceClass ) || ImplFilter( msMethodFilter, rSourceMethod )
     200                 :          0 :             || ImplFilter( msMessageFilter, rMessage ) ) )
     201                 :            :         {
     202                 :          0 :             rtl::OString sClass( rtl::OUStringToOString( rSourceClass, RTL_TEXTENCODING_UTF8 ) );
     203                 :          0 :             rtl::OString sMethod( rtl::OUStringToOString( rSourceMethod, RTL_TEXTENCODING_UTF8 ) );
     204                 :          0 :             rtl::OString sMessage( rtl::OUStringToOString( rMessage, RTL_TEXTENCODING_UTF8 ) );
     205                 :            :             try
     206                 :            :             {
     207                 :          0 :                 SEQ( sal_Int8 ) aData( sClass.getLength() + sMethod.getLength() + sMessage.getLength() );
     208                 :          0 :                 sal_Int8* pPtr = aData.getArray();
     209                 :          0 :                 memcpy( pPtr, sClass.getStr(), sClass.getLength() );
     210                 :          0 :                 pPtr += sClass.getLength();
     211                 :          0 :                 memcpy( pPtr, sMethod.getStr(), sMethod.getLength() );
     212                 :          0 :                 pPtr += sMethod.getLength();
     213                 :          0 :                 memcpy( pPtr, sMessage.getStr(), sMessage.getLength() );
     214                 :          0 :                 pPtr += sMessage.getLength();
     215                 :          0 :                 if ( mxOutputStream.is() )
     216                 :          0 :                     mxOutputStream->writeBytes( aData );
     217                 :          0 :                 if ( mxDocumentHandler.is() )
     218                 :          0 :                     mxDocumentHandler->characters( ::rtl::OUString( (sal_Char*)aData.getArray(), aData.getLength(), RTL_TEXTENCODING_UTF8 ) );
     219                 :            :             }
     220                 :          0 :             catch ( ... )
     221                 :            :             {
     222                 :            : 
     223                 :          0 :             }
     224                 :            :         }
     225                 :            :     }
     226                 :          0 : }
     227                 :            : 
     228                 :            : // -----------------------------------------------------------------------------
     229                 :            : 
     230                 :            : // XTextSearch
     231                 :          0 : void SAL_CALL  FilterTracer::setOptions( const NMSP_UTIL::SearchOptions& rSearchOptions )
     232                 :            :     throw (::com::sun::star::uno::RuntimeException)
     233                 :            : {
     234                 :          0 :     maSearchOptions = rSearchOptions;
     235                 :          0 : }
     236                 :            : 
     237                 :            : // -----------------------------------------------------------------------------
     238                 :            : 
     239                 :          0 : NMSP_UTIL::SearchResult SAL_CALL FilterTracer::searchForward( const rtl::OUString& rSearchStr,
     240                 :            :         sal_Int32 nStartPos, sal_Int32 nEndPos ) throw (::com::sun::star::uno::RuntimeException)
     241                 :            : {
     242                 :          0 :     NMSP_UTIL::SearchResult nSearchResult;
     243                 :          0 :     if ( mxTextSearch.is() )
     244                 :          0 :         mxTextSearch->searchForward( rSearchStr, nStartPos, nEndPos );
     245                 :          0 :     return nSearchResult;
     246                 :            : }
     247                 :            : 
     248                 :            : // -----------------------------------------------------------------------------
     249                 :            : 
     250                 :          0 : NMSP_UTIL::SearchResult SAL_CALL FilterTracer::searchBackward( const rtl::OUString& rSearchStr,
     251                 :            :         sal_Int32 nStartPos, sal_Int32 nEndPos ) throw (::com::sun::star::uno::RuntimeException)
     252                 :            : {
     253                 :          0 :     NMSP_UTIL::SearchResult nSearchResult;
     254                 :          0 :     if ( mxTextSearch.is() )
     255                 :          0 :         mxTextSearch->searchBackward( rSearchStr, nStartPos, nEndPos );
     256                 :          0 :     return nSearchResult;
     257                 :            : }
     258                 :            : 
     259                 :            : 
     260                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10