LCOV - code coverage report
Current view: top level - sdext/source/pdfimport - services.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 40 40 100.0 %
Date: 2015-06-13 12:38:46 Functions: 9 9 100.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 "pdfiadaptor.hxx"
      22             : #include "filterdet.hxx"
      23             : #include "treevisitorfactory.hxx"
      24             : 
      25             : #include <cppuhelper/factory.hxx>
      26             : #include <cppuhelper/implementationentry.hxx>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::com::sun::star::uno;
      30             : using namespace ::com::sun::star::lang;
      31             : using namespace ::com::sun::star::registry;
      32             : 
      33             : 
      34             : namespace
      35             : {
      36           1 :     static Reference< XInterface > Create_PDFIHybridAdaptor( const Reference< XComponentContext >& _rxContext )
      37             :     {
      38           1 :         return *(new pdfi::PDFIHybridAdaptor( _rxContext ));
      39             :     }
      40             : 
      41           1 :     static Reference< XInterface > Create_PDFIRawAdaptor_Writer( const Reference< XComponentContext >& _rxContext )
      42             :     {
      43           1 :         pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.WriterPDFImport", _rxContext );
      44             : 
      45           1 :         pAdaptor->setTreeVisitorFactory(pdfi::createWriterTreeVisitorFactory());
      46           1 :         pAdaptor->enableToplevelText(); // TEMP! TEMP!
      47             : 
      48           1 :         return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
      49             :     }
      50             : 
      51           3 :     static Reference< XInterface > Create_PDFIRawAdaptor_Draw( const Reference< XComponentContext >& _rxContext )
      52             :     {
      53           3 :         pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.DrawPDFImport", _rxContext );
      54             : 
      55           3 :         pAdaptor->setTreeVisitorFactory(pdfi::createDrawTreeVisitorFactory());
      56             : 
      57           3 :         return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
      58             :     }
      59             : 
      60           1 :     static Reference< XInterface > Create_PDFIRawAdaptor_Impress( const Reference< XComponentContext >& _rxContext )
      61             :     {
      62           1 :         pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.ImpressPDFImport", _rxContext );
      63             : 
      64           1 :         pAdaptor->setTreeVisitorFactory(pdfi::createImpressTreeVisitorFactory());
      65             : 
      66           1 :         return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
      67             :     }
      68             : 
      69          85 :     static Reference< XInterface > Create_PDFDetector( const Reference< XComponentContext >& _rxContext )
      70             :     {
      71          85 :         return *(new pdfi::PDFDetector( _rxContext ) );
      72             :     }
      73             : }
      74             : 
      75             : namespace
      76             : {
      77             :     typedef Reference< XInterface > (SAL_CALL * ComponentFactory)( const Reference< XComponentContext >& );
      78             : 
      79             :     struct ComponentDescription
      80             :     {
      81             :         const sal_Char*     pAsciiServiceName;
      82             :         const sal_Char*     pAsciiImplementationName;
      83             :         ComponentFactory    pFactory;
      84             : 
      85           4 :         ComponentDescription()
      86             :             :pAsciiServiceName( NULL )
      87             :             ,pAsciiImplementationName( NULL )
      88           4 :             ,pFactory( NULL )
      89             :         {
      90           4 :         }
      91          20 :         ComponentDescription( const sal_Char* _pAsciiServiceName, const sal_Char* _pAsciiImplementationName, ComponentFactory _pFactory )
      92             :             :pAsciiServiceName( _pAsciiServiceName )
      93             :             ,pAsciiImplementationName( _pAsciiImplementationName )
      94          20 :             ,pFactory( _pFactory )
      95             :         {
      96          20 :         }
      97             :     };
      98             : 
      99           8 :     static const ComponentDescription* lcl_getComponents()
     100             :     {
     101             :         static const ComponentDescription aDescriptions[] = {
     102             :             ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.HybridPDFImport", Create_PDFIHybridAdaptor ),
     103             :             ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.WriterPDFImport", Create_PDFIRawAdaptor_Writer ),
     104             :             ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.DrawPDFImport", Create_PDFIRawAdaptor_Draw ),
     105             :             ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.ImpressPDFImport", Create_PDFIRawAdaptor_Impress ),
     106             :             ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.PDFDetector", Create_PDFDetector ),
     107             :             ComponentDescription()
     108           8 :         };
     109           8 :         return aDescriptions;
     110             :     }
     111             : }
     112             : 
     113           8 : extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL pdfimport_component_getFactory(
     114             :     const sal_Char* pImplementationName,
     115             :     SAL_UNUSED_PARAMETER void* /*pServiceManager*/,
     116             :     SAL_UNUSED_PARAMETER void* /*pRegistryKey*/ )
     117             : {
     118           8 :     OUString sImplementationName( OUString::createFromAscii( pImplementationName ) );
     119             : 
     120          16 :     Reference< XSingleComponentFactory > xFactory;
     121             : 
     122           8 :     const ComponentDescription* pComponents = lcl_getComponents();
     123          36 :     while ( pComponents->pAsciiServiceName != NULL )
     124             :     {
     125          28 :         if ( sImplementationName.equalsAscii( pComponents->pAsciiImplementationName ) )
     126             :         {
     127           8 :             Sequence< OUString > sServices(1);
     128           8 :             sServices[0] = OUString::createFromAscii( pComponents->pAsciiServiceName );
     129             : 
     130          16 :             xFactory = ::cppu::createSingleComponentFactory(
     131             :                 pComponents->pFactory,
     132             :                 sImplementationName,
     133             :                 sServices,
     134             :                 NULL
     135           8 :             );
     136           8 :             break;
     137             :         }
     138             : 
     139          20 :         ++pComponents;
     140             :     }
     141             : 
     142             :     // by definition, objects returned via this C API need to ber acquired once
     143           8 :     xFactory->acquire();
     144          16 :     return xFactory.get();
     145             : }
     146             : 
     147             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11