LCOV - code coverage report
Current view: top level - svx/source/smarttags - SmartTagMgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 80 243 32.9 %
Date: 2012-08-25 Functions: 8 18 44.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 78 486 16.0 %

           Branch data     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                 :            : // SMARTTAGS
      21                 :            : 
      22                 :            : #include <svx/SmartTagMgr.hxx>
      23                 :            : 
      24                 :            : #include <osl/mutex.hxx>
      25                 :            : #include <vcl/svapp.hxx>
      26                 :            : #include <com/sun/star/smarttags/XSmartTagRecognizer.hpp>
      27                 :            : #include <com/sun/star/smarttags/XSmartTagAction.hpp>
      28                 :            : #include <com/sun/star/deployment/ExtensionManager.hpp>
      29                 :            : #include <com/sun/star/text/XTextMarkup.hpp>
      30                 :            : #include <com/sun/star/smarttags/SmartTagRecognizerMode.hpp>
      31                 :            : #include <com/sun/star/i18n/XBreakIterator.hpp>
      32                 :            : #include <com/sun/star/lang/Locale.hpp>
      33                 :            : #include <com/sun/star/lang/EventObject.hpp>
      34                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      35                 :            : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
      36                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      37                 :            : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      38                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      39                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      40                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      41                 :            : #include <com/sun/star/util/XChangesBatch.hpp>
      42                 :            : #include <com/sun/star/util/XChangesNotifier.hpp>
      43                 :            : #include <comphelper/processfactory.hxx>
      44                 :            : #include <rtl/ustring.hxx>
      45                 :            : 
      46                 :            : using namespace com::sun::star;
      47                 :            : using namespace com::sun::star::uno;
      48                 :            : 
      49                 :            : #define C2U(cChar) rtl::OUString::createFromAscii(cChar)
      50                 :            : 
      51                 :            : 
      52                 :         46 : SmartTagMgr::SmartTagMgr( const rtl::OUString& rApplicationName )
      53                 :            :     : maApplicationName( rApplicationName ),
      54                 :            :       maRecognizerList(),
      55                 :            :       maActionList(),
      56                 :            :       maDisabledSmartTagTypes(),
      57                 :            :       maSmartTagMap(),
      58                 :            :       mxMSF( ::comphelper::getProcessServiceFactory() ),
      59 [ +  - ][ +  - ]:         46 :       mbLabelTextWithSmartTags(true)
         [ +  - ][ +  - ]
                 [ +  - ]
      60                 :            : {
      61                 :         46 : }
      62                 :            : 
      63                 :          0 : SmartTagMgr::~SmartTagMgr()
      64                 :            : {
      65         [ #  # ]:          0 : }
      66                 :            : 
      67                 :         46 : void SmartTagMgr::Init( const rtl::OUString& rConfigurationGroupName )
      68                 :            : {
      69                 :            :     // get component context to pass to components:
      70         [ +  - ]:         46 :     if ( mxMSF.is() )
      71                 :            :     {
      72         [ +  - ]:         46 :         Reference< beans::XPropertySet > xPropSet = Reference< beans::XPropertySet>( mxMSF, UNO_QUERY);
      73 [ +  - ][ +  - ]:         46 :         const Any aAny = xPropSet->getPropertyValue( C2U("DefaultContext"));
      74         [ +  - ]:         46 :         aAny >>= mxContext;
      75                 :            : 
      76         [ +  - ]:         46 :         if ( mxContext.is() )
      77                 :            :         {
      78         [ +  - ]:         46 :             PrepareConfiguration( rConfigurationGroupName );
      79         [ +  - ]:         46 :             ReadConfiguration( true, true );
      80         [ +  - ]:         46 :             RegisterListener();
      81         [ +  - ]:         46 :             LoadLibraries();
      82                 :         46 :         }
      83                 :            :     }
      84                 :         46 : }
      85                 :          0 : void SmartTagMgr::CreateBreakIterator() const
      86                 :            : {
      87 [ #  # ][ #  # ]:          0 :     if ( !mxBreakIter.is() && mxMSF.is() && mxContext.is() )
         [ #  # ][ #  # ]
      88                 :            :     {
      89                 :            :         // get the break iterator
      90 [ #  # ][ #  # ]:          0 :         mxBreakIter.set(mxMSF->createInstance( C2U( "com.sun.star.i18n.BreakIterator" ) ), UNO_QUERY);
      91                 :            :     }
      92                 :          0 : }
      93                 :            : 
      94                 :            : /** Dispatches the recognize call to all installed smart tag recognizers
      95                 :            : */
      96                 :          0 : void SmartTagMgr::Recognize( const rtl::OUString& rText,
      97                 :            :                              const Reference< text::XTextMarkup > xMarkup,
      98                 :            :                              const Reference< frame::XController > xController,
      99                 :            :                              const lang::Locale& rLocale,
     100                 :            :                              sal_uInt32 nStart, sal_uInt32 nLen ) const
     101                 :            : {
     102         [ #  # ]:          0 :     for ( sal_uInt32 i = 0; i < maRecognizerList.size(); i++ )
     103                 :            :     {
     104                 :          0 :         Reference < smarttags::XSmartTagRecognizer > xRecognizer = maRecognizerList[i];
     105                 :            : 
     106                 :            :         // if all smart tag types supported by this recognizer have been
     107                 :            :         // disabled, we do not have to call the recognizer:
     108                 :          0 :         bool bCallRecognizer = false;
     109 [ #  # ][ #  # ]:          0 :         const sal_uInt32 nSmartTagCount = xRecognizer->getSmartTagCount();
     110 [ #  # ][ #  # ]:          0 :         for ( sal_uInt32 j = 0; j < nSmartTagCount && !bCallRecognizer; ++j )
                 [ #  # ]
     111                 :            :         {
     112 [ #  # ][ #  # ]:          0 :             const rtl::OUString aSmartTagName = xRecognizer->getSmartTagName(j);
     113 [ #  # ][ #  # ]:          0 :             if ( IsSmartTagTypeEnabled( aSmartTagName ) )
     114                 :          0 :                 bCallRecognizer = true;
     115                 :          0 :         }
     116                 :            : 
     117         [ #  # ]:          0 :         if ( bCallRecognizer )
     118                 :            :         {
     119         [ #  # ]:          0 :             CreateBreakIterator();
     120         [ #  # ]:          0 :             maRecognizerList[i]->recognize( rText, nStart, nLen,
     121                 :            :                                             smarttags::SmartTagRecognizerMode_PARAGRAPH,
     122                 :            :                                             rLocale, xMarkup, maApplicationName, xController,
     123         [ #  # ]:          0 :                                             mxBreakIter );
     124                 :            :         }
     125                 :          0 :     }
     126                 :          0 : }
     127                 :            : 
     128                 :            : typedef std::multimap < rtl::OUString, ActionReference >::const_iterator SmartTagMapIter;
     129                 :            : 
     130                 :          0 : void SmartTagMgr::GetActionSequences( Sequence < rtl::OUString >& rSmartTagTypes,
     131                 :            :                                       Sequence < Sequence< Reference< smarttags::XSmartTagAction > > >& rActionComponentsSequence,
     132                 :            :                                       Sequence < Sequence< sal_Int32 > >& rActionIndicesSequence ) const
     133                 :            : {
     134                 :          0 :     rActionComponentsSequence.realloc( rSmartTagTypes.getLength() );
     135                 :          0 :     rActionIndicesSequence.realloc( rSmartTagTypes.getLength() );
     136                 :            : 
     137         [ #  # ]:          0 :     for ( sal_uInt16 j = 0; j < rSmartTagTypes.getLength(); ++j )
     138                 :            :     {
     139         [ #  # ]:          0 :         const rtl::OUString& rSmartTagType = rSmartTagTypes[j];
     140                 :            : 
     141         [ #  # ]:          0 :         const sal_Int32 nNumberOfActionRefs = maSmartTagMap.count( rSmartTagType );
     142                 :            : 
     143         [ #  # ]:          0 :         Sequence< Reference< smarttags::XSmartTagAction > > aActions( nNumberOfActionRefs );
     144         [ #  # ]:          0 :         Sequence< sal_Int32 > aIndices( nNumberOfActionRefs );
     145                 :            : 
     146                 :          0 :         sal_uInt16 i = 0;
     147                 :          0 :         SmartTagMapIter aActionsIter;
     148         [ #  # ]:          0 :         SmartTagMapIter aEnd = maSmartTagMap.upper_bound( rSmartTagType );
     149                 :            : 
     150 [ #  # ][ #  # ]:          0 :         for ( aActionsIter = maSmartTagMap.lower_bound( rSmartTagType ); aActionsIter != aEnd; ++aActionsIter )
     151                 :            :         {
     152 [ #  # ][ #  # ]:          0 :             aActions[ i ] = (*aActionsIter).second.mxSmartTagAction;
     153         [ #  # ]:          0 :             aIndices[ i++ ] = (*aActionsIter).second.mnSmartTagIndex;
     154                 :            :         }
     155                 :            : 
     156 [ #  # ][ #  # ]:          0 :         rActionComponentsSequence[ j ] = aActions;
     157 [ #  # ][ #  # ]:          0 :         rActionIndicesSequence[ j ]  = aIndices;
     158 [ #  # ][ #  # ]:          0 :     }
     159                 :          0 : }
     160                 :            : 
     161                 :            : /** Returns the caption for a smart tag type.
     162                 :            : */
     163                 :          0 : rtl::OUString SmartTagMgr::GetSmartTagCaption( const rtl::OUString& rSmartTagType, const com::sun::star::lang::Locale& rLocale ) const
     164                 :            : {
     165                 :          0 :     rtl::OUString aRet;
     166                 :            : 
     167         [ #  # ]:          0 :     SmartTagMapIter aLower = maSmartTagMap.lower_bound( rSmartTagType );
     168                 :            : 
     169         [ #  # ]:          0 :     if ( aLower != maSmartTagMap.end() )
     170                 :            :     {
     171                 :          0 :         const ActionReference& rActionRef = (*aLower).second;
     172                 :          0 :         Reference< smarttags::XSmartTagAction > xAction = rActionRef.mxSmartTagAction;
     173                 :            : 
     174         [ #  # ]:          0 :         if ( xAction.is() )
     175                 :            :         {
     176                 :          0 :             const sal_Int32 nSmartTagIndex = rActionRef.mnSmartTagIndex;
     177 [ #  # ][ #  # ]:          0 :             aRet = xAction->getSmartTagCaption( nSmartTagIndex, rLocale );
     178                 :          0 :         }
     179                 :            :     }
     180                 :            : 
     181                 :          0 :     return aRet;
     182                 :            : }
     183                 :            : 
     184                 :            : 
     185                 :            : /** Returns true if the given smart tag type is enabled.
     186                 :            : */
     187                 :          0 : bool SmartTagMgr::IsSmartTagTypeEnabled( const rtl::OUString& rSmartTagType ) const
     188                 :            : {
     189                 :          0 :     return maDisabledSmartTagTypes.end() == maDisabledSmartTagTypes.find( rSmartTagType );
     190                 :            : }
     191                 :            : 
     192                 :            : /** Writes currently disabled smart tag types to configuration.
     193                 :            : */
     194                 :          0 : void SmartTagMgr::WriteConfiguration( const bool* pIsLabelTextWithSmartTags,
     195                 :            :                                       const std::vector< rtl::OUString >* pDisabledTypes ) const
     196                 :            : {
     197         [ #  # ]:          0 :     if ( mxConfigurationSettings.is() )
     198                 :            :     {
     199                 :          0 :         bool bCommit = false;
     200                 :            : 
     201         [ #  # ]:          0 :         if ( pIsLabelTextWithSmartTags )
     202                 :            :         {
     203         [ #  # ]:          0 :             const Any aEnabled = makeAny( *pIsLabelTextWithSmartTags );
     204                 :            : 
     205                 :            :             try
     206                 :            :             {
     207 [ #  # ][ #  # ]:          0 :                 mxConfigurationSettings->setPropertyValue( C2U("RecognizeSmartTags"), aEnabled );
                 [ #  # ]
     208                 :          0 :                 bCommit = true;
     209                 :            :             }
     210         [ #  # ]:          0 :             catch ( ::com::sun::star::uno::Exception& )
     211                 :            :             {
     212                 :          0 :             }
     213                 :            :         }
     214                 :            : 
     215         [ #  # ]:          0 :         if ( pDisabledTypes )
     216                 :            :         {
     217                 :          0 :             const sal_Int32 nNumberOfDisabledSmartTagTypes = pDisabledTypes->size();
     218         [ #  # ]:          0 :             Sequence< rtl::OUString > aTypes( nNumberOfDisabledSmartTagTypes );
     219                 :            : 
     220                 :          0 :             std::vector< rtl::OUString >::const_iterator aIter;
     221                 :          0 :             sal_Int32 nCount = 0;
     222 [ #  # ][ #  # ]:          0 :             for ( aIter = pDisabledTypes->begin(); aIter != pDisabledTypes->end(); ++aIter )
     223         [ #  # ]:          0 :                 aTypes[ nCount++ ] = *aIter;
     224                 :            : 
     225         [ #  # ]:          0 :             const Any aNewTypes = makeAny( aTypes );
     226                 :            : 
     227                 :            :             try
     228                 :            :             {
     229 [ #  # ][ #  # ]:          0 :                 mxConfigurationSettings->setPropertyValue( C2U("ExcludedSmartTagTypes"), aNewTypes );
                 [ #  # ]
     230                 :          0 :                 bCommit = true;
     231                 :            :             }
     232         [ #  # ]:          0 :             catch ( ::com::sun::star::uno::Exception& )
     233                 :            :             {
     234         [ #  # ]:          0 :             }
     235                 :            :         }
     236                 :            : 
     237         [ #  # ]:          0 :         if ( bCommit )
     238                 :            :         {
     239                 :            :             try
     240                 :            :             {
     241 [ #  # ][ #  # ]:          0 :                 Reference< util::XChangesBatch >( mxConfigurationSettings, UNO_QUERY_THROW )->commitChanges();
         [ #  # ][ #  # ]
     242                 :            :             }
     243                 :          0 :             catch ( ::com::sun::star::uno::Exception& )
     244                 :            :             {
     245                 :            :             }
     246                 :            :         }
     247                 :            :     }
     248                 :          0 : }
     249                 :            : 
     250                 :            : // ::com::sun::star::util::XModifyListener
     251                 :          8 : void SmartTagMgr::modified( const lang::EventObject& )  throw( RuntimeException )
     252                 :            : {
     253         [ +  - ]:          8 :     SolarMutexGuard aGuard;
     254                 :            : 
     255                 :          8 :     maRecognizerList.clear();
     256                 :          8 :     maActionList.clear();
     257                 :          8 :     maSmartTagMap.clear();
     258                 :            : 
     259 [ +  - ][ +  - ]:          8 :     LoadLibraries();
     260                 :          8 : }
     261                 :            : 
     262                 :            : // ::com::sun::star::lang::XEventListener
     263                 :         40 : void SmartTagMgr::disposing( const lang::EventObject& rEvent ) throw( RuntimeException )
     264                 :            : {
     265         [ +  - ]:         40 :     SolarMutexGuard aGuard;
     266                 :            : 
     267         [ +  - ]:         40 :     uno::Reference< frame::XModel >  xModel( rEvent.Source, uno::UNO_QUERY );
     268         [ +  - ]:         40 :     uno::Reference< util::XModifyBroadcaster >  xMB(xModel, uno::UNO_QUERY);
     269         [ +  - ]:         40 :     uno::Reference< util::XChangesNotifier >  xCN(xModel, uno::UNO_QUERY);
     270                 :            : 
     271                 :            :     try
     272                 :            :     {
     273         [ -  + ]:         40 :         if( xMB.is() )
     274                 :            :         {
     275         [ #  # ]:          0 :             uno::Reference< util::XModifyListener >  xListener( this );
     276 [ #  # ][ #  # ]:          0 :             xMB->removeModifyListener( xListener );
     277                 :            :         }
     278         [ -  + ]:         40 :         else if ( xCN.is() )
     279                 :            :         {
     280         [ #  # ]:          0 :             uno::Reference< util::XChangesListener >  xListener( this );
     281 [ #  # ][ #  # ]:          0 :             xCN->removeChangesListener( xListener );
                 [ #  # ]
     282                 :            :         }
     283                 :            :     }
     284         [ #  # ]:          0 :     catch(Exception& )
     285                 :            :     {
     286         [ +  - ]:         40 :     }
     287                 :         40 : }
     288                 :            : 
     289                 :            : // ::com::sun::star::util::XChangesListener
     290                 :          0 : void SmartTagMgr::changesOccurred( const util::ChangesEvent& rEvent ) throw( RuntimeException)
     291                 :            : {
     292         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     293                 :            : 
     294                 :          0 :     const util::ElementChange* pElementChanges = rEvent.Changes.getConstArray();
     295                 :          0 :     const sal_Int32 nNumberOfChanges = rEvent.Changes.getLength();
     296                 :          0 :     bool bExcludedTypes = false;
     297                 :          0 :     bool bRecognize = false;
     298                 :            : 
     299         [ #  # ]:          0 :     for( sal_Int32 i = 0; i < nNumberOfChanges; ++i)
     300                 :            :     {
     301                 :          0 :         rtl::OUString sTemp;
     302                 :          0 :         pElementChanges[i].Accessor >>= sTemp;
     303                 :            : 
     304         [ #  # ]:          0 :         if ( sTemp == C2U( "ExcludedSmartTagTypes" ) )
     305                 :          0 :             bExcludedTypes = true;
     306         [ #  # ]:          0 :         else if ( sTemp == C2U( "RecognizeSmartTags" ) )
     307                 :          0 :             bRecognize = true;
     308                 :          0 :     }
     309                 :            : 
     310 [ #  # ][ #  # ]:          0 :     ReadConfiguration( bExcludedTypes, bRecognize );
     311                 :          0 : }
     312                 :            : 
     313                 :            : //------------- PRIVATE -----------------------------------------------
     314                 :            : 
     315                 :            : /**
     316                 :            : */
     317                 :         54 : void SmartTagMgr::LoadLibraries()
     318                 :            : {
     319         [ +  - ]:         54 :     Reference< container::XContentEnumerationAccess > rContent( mxMSF , UNO_QUERY );
     320         [ -  + ]:         54 :     if ( !rContent.is() )
     321                 :            :         return;
     322                 :            : 
     323                 :            :     // load recognizers: No recognizers -> nothing to do.
     324 [ +  - ][ +  - ]:         54 :     Reference < container::XEnumeration > rEnum = rContent->createContentEnumeration( C2U("com.sun.star.smarttags.SmartTagRecognizer"));
     325 [ +  - ][ +  - ]:         54 :     if ( !rEnum.is() || !rEnum->hasMoreElements() )
         [ +  - ][ +  - ]
                 [ +  - ]
     326                 :            :         return;
     327                 :            : 
     328                 :            :     // iterate over all implementations of the smart tag recognizer service:
     329 [ #  # ][ #  # ]:          0 :     while( rEnum->hasMoreElements())
                 [ #  # ]
     330                 :            :     {
     331 [ #  # ][ #  # ]:          0 :         const Any a = rEnum->nextElement();
     332                 :          0 :         Reference< lang::XSingleComponentFactory > xSCF;
     333                 :          0 :         Reference< lang::XServiceInfo > xsInfo;
     334                 :            : 
     335 [ #  # ][ #  # ]:          0 :         if (a >>= xsInfo)
     336 [ #  # ][ #  # ]:          0 :             xSCF = Reference< lang::XSingleComponentFactory >(xsInfo, UNO_QUERY);
     337                 :            :         else
     338                 :          0 :             continue;
     339                 :            : 
     340         [ #  # ]:          0 :         Reference< smarttags::XSmartTagRecognizer > xLib ( xSCF->
     341 [ #  # ][ #  # ]:          0 :                    createInstanceWithContext(mxContext), UNO_QUERY );
     342                 :            : 
     343         [ #  # ]:          0 :         if (!xLib.is())
     344                 :          0 :             continue;
     345                 :            : 
     346 [ #  # ][ #  # ]:          0 :         xLib->initialize( Sequence< Any >() );
         [ #  # ][ #  # ]
     347 [ #  # ][ #  # ]:          0 :         maRecognizerList.push_back(xLib);
     348 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
     349                 :            : 
     350                 :            :     // load actions: No actions -> nothing to do.
     351 [ #  # ][ #  # ]:          0 :     rEnum = rContent->createContentEnumeration( C2U("com.sun.star.smarttags.SmartTagAction"));
                 [ #  # ]
     352         [ #  # ]:          0 :     if ( !rEnum.is() )
     353                 :            :         return;
     354                 :            : 
     355                 :            :     // iterate over all implementations of the smart tag action service:
     356 [ #  # ][ #  # ]:          0 :     while( rEnum->hasMoreElements())
                 [ #  # ]
     357                 :            :     {
     358 [ #  # ][ #  # ]:          0 :         const Any a = rEnum->nextElement();
     359                 :          0 :         Reference< lang::XServiceInfo > xsInfo;
     360                 :          0 :         Reference< lang::XSingleComponentFactory > xSCF;
     361                 :            : 
     362 [ #  # ][ #  # ]:          0 :         if (a >>= xsInfo)
     363 [ #  # ][ #  # ]:          0 :             xSCF = Reference< lang::XSingleComponentFactory >(xsInfo, UNO_QUERY);
     364                 :            :         else
     365                 :          0 :             continue;
     366                 :            : 
     367         [ #  # ]:          0 :         Reference< smarttags::XSmartTagAction > xLib ( xSCF->
     368 [ #  # ][ #  # ]:          0 :                     createInstanceWithContext(mxContext), UNO_QUERY );
     369                 :            : 
     370         [ #  # ]:          0 :         if (!xLib.is())
     371                 :          0 :             continue;
     372                 :            : 
     373 [ #  # ][ #  # ]:          0 :         xLib->initialize( Sequence< Any >() );
         [ #  # ][ #  # ]
     374 [ #  # ][ #  # ]:          0 :         maActionList.push_back(xLib);
     375 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
     376                 :            : 
     377 [ #  # ][ +  - ]:         54 :     AssociateActionsWithRecognizers();
                 [ -  + ]
     378                 :            : 
     379                 :            : }
     380                 :            : 
     381                 :            : /**
     382                 :            : */
     383                 :         46 : void SmartTagMgr::PrepareConfiguration( const rtl::OUString& rConfigurationGroupName )
     384                 :            : {
     385         [ +  - ]:         46 :     Any aAny = makeAny( C2U( "/org.openoffice.Office.Common/SmartTags/" ) + rConfigurationGroupName );
     386                 :         46 :     beans::PropertyValue aPathArgument;
     387                 :         46 :     aPathArgument.Name = C2U( "nodepath" );
     388                 :         46 :     aPathArgument.Value = aAny;
     389         [ +  - ]:         46 :     Sequence< Any > aArguments( 1 );
     390 [ +  - ][ +  - ]:         46 :     aArguments[ 0 ] <<= aPathArgument;
     391 [ +  - ][ +  - ]:         46 :     Reference< lang::XMultiServiceFactory > xConfProv( mxMSF->createInstance(C2U ("com.sun.star.configuration.ConfigurationProvider")), UNO_QUERY );
                 [ +  - ]
     392                 :            : 
     393         [ -  + ]:         46 :     if ( !xConfProv.is() )
     394                 :         46 :         return;
     395                 :            : 
     396                 :            :     // try to get read-write access to configuration:
     397                 :         46 :     Reference< XInterface > xConfigurationAccess;
     398                 :            :     try
     399                 :            :     {
     400         [ +  - ]:         46 :         xConfigurationAccess = xConfProv->createInstanceWithArguments(
     401 [ +  - ][ +  - ]:         46 :             C2U("com.sun.star.configuration.ConfigurationUpdateAccess" ), aArguments );
                 [ #  # ]
     402                 :            :     }
     403         [ #  # ]:          0 :     catch ( uno::Exception& )
     404                 :            :     {
     405                 :            :     }
     406                 :            : 
     407                 :            :     // fallback: try read-only access to configuration:
     408         [ -  + ]:         46 :     if ( !xConfigurationAccess.is() )
     409                 :            :     {
     410                 :            :         try
     411                 :            :         {
     412         [ #  # ]:          0 :             xConfigurationAccess = xConfProv->createInstanceWithArguments(
     413 [ #  # ][ #  # ]:          0 :                 C2U("com.sun.star.configuration.ConfigurationAccess" ), aArguments );
                 [ #  # ]
     414                 :            :         }
     415         [ #  # ]:          0 :         catch ( uno::Exception& )
     416                 :            :         {
     417                 :            :         }
     418                 :            :     }
     419                 :            : 
     420         [ +  - ]:         46 :     if ( xConfigurationAccess.is() )
     421                 :            :     {
     422 [ +  - ][ +  - ]:         46 :         mxConfigurationSettings = Reference< beans::XPropertySet >( xConfigurationAccess, UNO_QUERY );
     423 [ -  + ][ +  - ]:         46 :     }
         [ -  + ][ -  + ]
                 [ +  - ]
     424                 :            : }
     425                 :            : 
     426                 :            : 
     427                 :         46 : void SmartTagMgr::ReadConfiguration( bool bExcludedTypes, bool bRecognize )
     428                 :            : {
     429         [ +  - ]:         46 :     if ( mxConfigurationSettings.is() )
     430                 :            :     {
     431         [ +  - ]:         46 :         if ( bExcludedTypes )
     432                 :            :         {
     433                 :         46 :             maDisabledSmartTagTypes.clear();
     434                 :            : 
     435 [ +  - ][ +  - ]:         46 :             Any aAny = mxConfigurationSettings->getPropertyValue( C2U("ExcludedSmartTagTypes") );
     436         [ +  - ]:         46 :             Sequence< rtl::OUString > aValues;
     437         [ +  - ]:         46 :             aAny >>= aValues;
     438                 :            : 
     439                 :         46 :             const sal_Int32 nValues = aValues.getLength();
     440                 :            : 
     441         [ -  + ]:         46 :             for ( sal_Int32 nI = 0; nI < nValues; ++nI )
     442 [ #  # ][ #  # ]:         46 :                 maDisabledSmartTagTypes.insert( aValues[nI] );
                 [ +  - ]
     443                 :            :         }
     444                 :            : 
     445         [ +  - ]:         46 :         if ( bRecognize )
     446                 :            :         {
     447 [ +  - ][ +  - ]:         46 :             Any aAny = mxConfigurationSettings->getPropertyValue( C2U("RecognizeSmartTags") );
     448                 :         46 :             sal_Bool bValue = sal_True;
     449                 :         46 :             aAny >>= bValue;
     450                 :            : 
     451                 :         46 :             mbLabelTextWithSmartTags = bValue;
     452                 :            :         }
     453                 :            :     }
     454                 :         46 : }
     455                 :            : 
     456                 :            : /**
     457                 :            : */
     458                 :         46 : void SmartTagMgr::RegisterListener()
     459                 :            : {
     460                 :            :     // register as listener at package manager
     461                 :            :     try
     462                 :            :     {
     463                 :            :         Reference<deployment::XExtensionManager> xExtensionManager(
     464         [ +  + ]:         46 :                 deployment::ExtensionManager::get( mxContext ) );
     465         [ +  - ]:         40 :         Reference< util::XModifyBroadcaster > xMB ( xExtensionManager, UNO_QUERY_THROW );
     466                 :            : 
     467         [ +  - ]:         40 :         Reference< util::XModifyListener > xListener( this );
     468 [ +  - ][ +  - ]:         46 :         xMB->addModifyListener( xListener );
                 [ -  + ]
     469                 :            :     }
     470                 :          6 :     catch ( uno::Exception& )
     471                 :            :     {
     472                 :            :     }
     473                 :            : 
     474                 :            :     // register as listener at configuration
     475                 :            :     try
     476                 :            :     {
     477         [ +  - ]:         46 :         Reference<util::XChangesNotifier> xCN( mxConfigurationSettings, UNO_QUERY_THROW );
     478         [ +  - ]:         46 :         Reference< util::XChangesListener > xListener( this );
     479 [ +  - ][ +  - ]:         46 :         xCN->addChangesListener( xListener );
                 [ #  # ]
     480                 :            :     }
     481                 :          0 :     catch ( uno::Exception& )
     482                 :            :     {
     483                 :            :     }
     484                 :         46 : }
     485                 :            : 
     486                 :            : typedef std::pair < const rtl::OUString, ActionReference > SmartTagMapElement;
     487                 :            : 
     488                 :            : /** Sets up a map that maps smart tag type names to actions references.
     489                 :            : */
     490                 :          0 : void SmartTagMgr::AssociateActionsWithRecognizers()
     491                 :            : {
     492                 :          0 :     const sal_uInt32 nActionLibCount = maActionList.size();
     493                 :          0 :     const sal_uInt32 nRecognizerCount = maRecognizerList.size();
     494                 :            : 
     495         [ #  # ]:          0 :     for ( sal_uInt32 i = 0; i < nRecognizerCount; ++i )
     496                 :            :     {
     497                 :          0 :         Reference < smarttags::XSmartTagRecognizer > xRecognizer = maRecognizerList[i];
     498 [ #  # ][ #  # ]:          0 :         const sal_uInt32 nSmartTagCount = xRecognizer->getSmartTagCount();
     499         [ #  # ]:          0 :         for ( sal_uInt32 j = 0; j < nSmartTagCount; ++j )
     500                 :            :         {
     501 [ #  # ][ #  # ]:          0 :             const rtl::OUString aSmartTagName = xRecognizer->getSmartTagName(j);
     502                 :            : 
     503                 :            :             // check if smart tag type has already been processed:
     504 [ #  # ][ #  # ]:          0 :             if ( maSmartTagMap.find( aSmartTagName ) != maSmartTagMap.end() )
     505                 :          0 :                 continue;
     506                 :            : 
     507                 :          0 :             bool bFound = false;
     508         [ #  # ]:          0 :             for ( sal_uInt32 k = 0; k < nActionLibCount; ++k )
     509                 :            :             {
     510                 :          0 :                 Reference< smarttags::XSmartTagAction > xActionLib = maActionList[k];
     511 [ #  # ][ #  # ]:          0 :                 const sal_uInt32 nSmartTagCountInActionLib = xActionLib->getSmartTagCount();
     512         [ #  # ]:          0 :                 for ( sal_uInt32 l = 0; l < nSmartTagCountInActionLib; ++l )
     513                 :            :                 {
     514 [ #  # ][ #  # ]:          0 :                     const rtl::OUString aSmartTagNameInActionLib = xActionLib->getSmartTagName(l);
     515         [ #  # ]:          0 :                     if ( aSmartTagName.equals( aSmartTagNameInActionLib ) )
     516                 :            :                     {
     517                 :            :                         // found actions and recognizer for same smarttag
     518         [ #  # ]:          0 :                         ActionReference aActionRef( xActionLib, l );
     519                 :            : 
     520                 :            :                         // add recognizer/action pair to map
     521 [ #  # ][ #  # ]:          0 :                         maSmartTagMap.insert( SmartTagMapElement( aSmartTagName, aActionRef ));
                 [ #  # ]
     522                 :            : 
     523         [ #  # ]:          0 :                         bFound = true;
     524                 :            :                     }
     525                 :          0 :                 }
     526                 :          0 :             }
     527                 :            : 
     528         [ #  # ]:          0 :             if ( !bFound )
     529                 :            :             {
     530                 :            :                 // insert 'empty' action reference if there is no action associated with
     531                 :            :                 // the current smart tag type:
     532                 :          0 :                 Reference< smarttags::XSmartTagAction > xActionLib;
     533         [ #  # ]:          0 :                 ActionReference aActionRef( xActionLib, 0 );
     534                 :            : 
     535                 :            :                 // add recognizer/action pair to map
     536 [ #  # ][ #  # ]:          0 :                 maSmartTagMap.insert( SmartTagMapElement( aSmartTagName, aActionRef ));
         [ #  # ][ #  # ]
     537                 :            :             }
     538         [ #  # ]:          0 :         }
     539                 :          0 :     }
     540                 :          0 : }
     541                 :            : 
     542                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10