LCOV - code coverage report
Current view: top level - sc/source/core/tool - formulaparserpool.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 43 0.0 %
Date: 2012-08-25 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 110 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                 :            : 
      30                 :            : #include "formulaparserpool.hxx"
      31                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      32                 :            : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      33                 :            : #include <com/sun/star/lang/XComponent.hpp>
      34                 :            : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
      35                 :            : #include <com/sun/star/sheet/XFilterFormulaParser.hpp>
      36                 :            : #include <rtl/instance.hxx>
      37                 :            : #include <comphelper/processfactory.hxx>
      38                 :            : #include <sfx2/objsh.hxx>
      39                 :            : #include "document.hxx"
      40                 :            : 
      41                 :            : using ::rtl::OUString;
      42                 :            : using ::rtl::OUStringHash;
      43                 :            : using namespace ::com::sun::star::beans;
      44                 :            : using namespace ::com::sun::star::container;
      45                 :            : using namespace ::com::sun::star::lang;
      46                 :            : using namespace ::com::sun::star::sheet;
      47                 :            : using namespace ::com::sun::star::uno;
      48                 :            : 
      49                 :            : // ============================================================================
      50                 :            : 
      51                 :            : namespace {
      52                 :            : 
      53         [ #  # ]:          0 : class ScParserFactoryMap
      54                 :            : {
      55                 :            : public:
      56                 :            :     explicit            ScParserFactoryMap();
      57                 :            : 
      58                 :            :     Reference< XFormulaParser > createFormulaParser(
      59                 :            :                             const Reference< XComponent >& rxComponent,
      60                 :            :                             const OUString& rNamespace );
      61                 :            : 
      62                 :            : private:
      63                 :            :     typedef ::boost::unordered_map<
      64                 :            :         OUString,
      65                 :            :         Reference< XSingleComponentFactory >,
      66                 :            :         OUStringHash,
      67                 :            :         ::std::equal_to< OUString > > FactoryMap;
      68                 :            : 
      69                 :            :     Reference< XComponentContext > mxContext;   /// Global component context.
      70                 :            :     FactoryMap          maFactories;            /// All parser factories, mapped by formula namespace.
      71                 :            : };
      72                 :            : 
      73                 :          0 : ScParserFactoryMap::ScParserFactoryMap() :
      74         [ #  # ]:          0 :     mxContext( ::comphelper::getProcessComponentContext() )
      75                 :            : {
      76         [ #  # ]:          0 :     if( mxContext.is() ) try
      77                 :            :     {
      78                 :            :         // enumerate all implementations of the FormulaParser service
      79 [ #  # ][ #  # ]:          0 :         Reference< XContentEnumerationAccess > xFactoryEA( mxContext->getServiceManager(), UNO_QUERY_THROW );
                 [ #  # ]
      80 [ #  # ][ #  # ]:          0 :         Reference< XEnumeration > xEnum( xFactoryEA->createContentEnumeration( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.FilterFormulaParser" ) ) ), UNO_SET_THROW );
         [ #  # ][ #  # ]
      81 [ #  # ][ #  # ]:          0 :         while( xEnum->hasMoreElements() ) try // single try/catch for every element
                 [ #  # ]
      82                 :            :         {
      83                 :            :             // create an instance of the formula parser implementation
      84 [ #  # ][ #  # ]:          0 :             Reference< XSingleComponentFactory > xCompFactory( xEnum->nextElement(), UNO_QUERY_THROW );
                 [ #  # ]
      85 [ #  # ][ #  # ]:          0 :             Reference< XFilterFormulaParser > xParser( xCompFactory->createInstanceWithContext( mxContext ), UNO_QUERY_THROW );
                 [ #  # ]
      86                 :            : 
      87                 :            :             // store factory in the map
      88 [ #  # ][ #  # ]:          0 :             OUString aNamespace = xParser->getSupportedNamespace();
      89         [ #  # ]:          0 :             if( !aNamespace.isEmpty() )
      90 [ #  # ][ #  # ]:          0 :                 maFactories[ aNamespace ] = xCompFactory;
                 [ #  # ]
      91                 :            :         }
      92         [ #  # ]:          0 :         catch( Exception& )
      93                 :            :         {
      94         [ #  # ]:          0 :         }
      95                 :            :     }
      96         [ #  # ]:          0 :     catch( Exception& )
      97                 :            :     {
      98                 :            :     }
      99                 :          0 : }
     100                 :            : 
     101                 :          0 : Reference< XFormulaParser > ScParserFactoryMap::createFormulaParser(
     102                 :            :         const Reference< XComponent >& rxComponent, const OUString& rNamespace )
     103                 :            : {
     104                 :          0 :     Reference< XFormulaParser > xParser;
     105         [ #  # ]:          0 :     FactoryMap::const_iterator aIt = maFactories.find( rNamespace );
     106 [ #  # ][ #  # ]:          0 :     if( aIt != maFactories.end() ) try
     107                 :            :     {
     108         [ #  # ]:          0 :         Sequence< Any > aArgs( 1 );
     109 [ #  # ][ #  # ]:          0 :         aArgs[ 0 ] <<= rxComponent;
     110 [ #  # ][ #  # ]:          0 :         xParser.set( aIt->second->createInstanceWithArgumentsAndContext( aArgs, mxContext ), UNO_QUERY_THROW );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     111                 :            :     }
     112         [ #  # ]:          0 :     catch( Exception& )
     113                 :            :     {
     114                 :            :     }
     115                 :          0 :     return xParser;
     116                 :            : }
     117                 :            : 
     118                 :            : struct ScParserFactorySingleton : public ::rtl::Static< ScParserFactoryMap, ScParserFactorySingleton > {};
     119                 :            : 
     120                 :            : } // namespace
     121                 :            : 
     122                 :            : // ============================================================================
     123                 :            : 
     124                 :          0 : ScFormulaParserPool::ScFormulaParserPool( const ScDocument& rDoc ) :
     125         [ #  # ]:          0 :     mrDoc( rDoc )
     126                 :            : {
     127                 :          0 : }
     128                 :            : 
     129                 :          0 : ScFormulaParserPool::~ScFormulaParserPool()
     130                 :            : {
     131                 :          0 : }
     132                 :            : 
     133                 :          0 : bool ScFormulaParserPool::hasFormulaParser( const OUString& rNamespace )
     134                 :            : {
     135                 :          0 :     return getFormulaParser( rNamespace ).is();
     136                 :            : }
     137                 :            : 
     138                 :          0 : Reference< XFormulaParser > ScFormulaParserPool::getFormulaParser( const OUString& rNamespace )
     139                 :            : {
     140                 :            :     // try to find an existing parser entry
     141         [ #  # ]:          0 :     ParserMap::iterator aIt = maParsers.find( rNamespace );
     142 [ #  # ][ #  # ]:          0 :     if( aIt != maParsers.end() )
     143         [ #  # ]:          0 :         return aIt->second;
     144                 :            : 
     145                 :            :     // always create a new entry in the map (even if the following initialization fails)
     146         [ #  # ]:          0 :     Reference< XFormulaParser >& rxParser = maParsers[ rNamespace ];
     147                 :            : 
     148                 :            :     // try to create a new parser object
     149         [ #  # ]:          0 :     if( SfxObjectShell* pDocShell = mrDoc.GetDocumentShell() ) try
     150                 :            :     {
     151 [ #  # ][ #  # ]:          0 :         Reference< XComponent > xComponent( pDocShell->GetModel(), UNO_QUERY_THROW );
     152         [ #  # ]:          0 :         ScParserFactoryMap& rFactoryMap = ScParserFactorySingleton::get();
     153 [ #  # ][ #  # ]:          0 :         rxParser = rFactoryMap.createFormulaParser( xComponent, rNamespace );
                 [ #  # ]
     154                 :            :     }
     155         [ #  # ]:          0 :     catch( Exception& )
     156                 :            :     {
     157                 :            :     }
     158                 :          0 :     return rxParser;
     159                 :            : }
     160                 :            : 
     161                 :            : // ============================================================================
     162                 :            : 
     163                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10