LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/oox - excelfilter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 69 76.8 %
Date: 2012-12-27 Functions: 17 24 70.8 %
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             : #include "excelfilter.hxx"
      21             : 
      22             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      23             : #include "oox/helper/binaryinputstream.hxx"
      24             : #include "biffinputstream.hxx"
      25             : #include "excelchartconverter.hxx"
      26             : #include "excelvbaproject.hxx"
      27             : #include "stylesbuffer.hxx"
      28             : #include "themebuffer.hxx"
      29             : #include "workbookfragment.hxx"
      30             : 
      31             : namespace oox {
      32             : namespace xls {
      33             : 
      34             : // ============================================================================
      35             : 
      36             : using namespace ::com::sun::star::lang;
      37             : using namespace ::com::sun::star::sheet;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::xml::sax;
      40             : using namespace ::oox::core;
      41             : 
      42             : using ::rtl::OUString;
      43             : using ::oox::drawingml::table::TableStyleListPtr;
      44             : 
      45             : // ============================================================================
      46             : 
      47          12 : ExcelFilterBase::ExcelFilterBase() :
      48          12 :     mpBookGlob( 0 )
      49             : {
      50          12 : }
      51             : 
      52          12 : ExcelFilterBase::~ExcelFilterBase()
      53             : {
      54             :     OSL_ENSURE( !mpBookGlob, "ExcelFilterBase::~ExcelFilterBase - workbook data not cleared" );
      55          12 : }
      56             : 
      57          11 : void ExcelFilterBase::registerWorkbookGlobals( WorkbookGlobals& rBookGlob )
      58             : {
      59          11 :     mpBookGlob = &rBookGlob;
      60          11 : }
      61             : 
      62          11 : WorkbookGlobals& ExcelFilterBase::getWorkbookGlobals() const
      63             : {
      64             :     OSL_ENSURE( mpBookGlob, "ExcelFilterBase::getWorkbookGlobals - missing workbook data" );
      65          11 :     return *mpBookGlob;
      66             : }
      67             : 
      68          11 : void ExcelFilterBase::unregisterWorkbookGlobals()
      69             : {
      70          11 :     mpBookGlob = 0;
      71          11 : }
      72             : 
      73             : // ============================================================================
      74             : 
      75           4 : OUString SAL_CALL ExcelFilter_getImplementationName() throw()
      76             : {
      77           4 :     return OUString( "com.sun.star.comp.oox.xls.ExcelFilter" );
      78             : }
      79             : 
      80           3 : Sequence< OUString > SAL_CALL ExcelFilter_getSupportedServiceNames() throw()
      81             : {
      82           3 :     Sequence< OUString > aSeq( 2 );
      83           3 :     aSeq[ 0 ] = "com.sun.star.document.ImportFilter";
      84           3 :     aSeq[ 1 ] = "com.sun.star.document.ExportFilter";
      85           3 :     return aSeq;
      86             : }
      87             : 
      88          12 : Reference< XInterface > SAL_CALL ExcelFilter_createInstance(
      89             :         const Reference< XComponentContext >& rxContext ) throw( Exception )
      90             : {
      91          12 :     return static_cast< ::cppu::OWeakObject* >( new ExcelFilter( rxContext ) );
      92             : }
      93             : 
      94             : // ----------------------------------------------------------------------------
      95             : 
      96          12 : ExcelFilter::ExcelFilter( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
      97          12 :     XmlFilterBase( rxContext )
      98             : {
      99          12 : }
     100             : 
     101          24 : ExcelFilter::~ExcelFilter()
     102             : {
     103          24 : }
     104             : 
     105          11 : bool ExcelFilter::importDocument() throw()
     106             : {
     107             :     /*  To activate the XLSX/XLSB dumper, insert the full path to the file
     108             :         file:///<path-to-oox-module>/source/dump/xlsbdumper.ini
     109             :         into the environment variable OOO_XLSBDUMPER and start the office with
     110             :         this variable (nonpro only). */
     111             :     //OOX_DUMP_FILE( ::oox::dump::xlsb::Dumper );
     112             : 
     113          11 :     OUString aWorkbookPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "officeDocument" ) );
     114          11 :     if( aWorkbookPath.isEmpty() )
     115           0 :         return false;
     116             : 
     117             :     /*  Construct the WorkbookGlobals object referred to by every instance of
     118             :         the class WorkbookHelper, and execute the import filter by constructing
     119             :         an instance of WorkbookFragment and loading the file. */
     120          11 :     WorkbookGlobalsRef xBookGlob = WorkbookHelper::constructGlobals( *this );
     121          11 :     if ( xBookGlob.get() && importFragment( new WorkbookFragment( *xBookGlob, aWorkbookPath ) ) )
     122             :     {
     123             :         try
     124             :         {
     125          11 :             importDocumentProperties();
     126             :         }
     127           0 :         catch( const Exception& e )
     128             :         {
     129             :             SAL_WARN("sc", "exception when importing document properties " << e.Message);
     130             :         }
     131          11 :         return true;
     132             :     }
     133           0 :     return false;
     134             : }
     135             : 
     136           1 : bool ExcelFilter::exportDocument() throw()
     137             : {
     138           1 :     return false;
     139             : }
     140             : 
     141           0 : const ::oox::drawingml::Theme* ExcelFilter::getCurrentTheme() const
     142             : {
     143           0 :     return &WorkbookHelper( getWorkbookGlobals() ).getTheme();
     144             : }
     145             : 
     146           0 : ::oox::vml::Drawing* ExcelFilter::getVmlDrawing()
     147             : {
     148           0 :     return 0;
     149             : }
     150             : 
     151           0 : const TableStyleListPtr ExcelFilter::getTableStyles()
     152             : {
     153           0 :     return TableStyleListPtr();
     154             : }
     155             : 
     156           0 : ::oox::drawingml::chart::ChartConverter* ExcelFilter::getChartConverter()
     157             : {
     158           0 :     return WorkbookHelper( getWorkbookGlobals() ).getChartConverter();
     159             : }
     160             : 
     161          11 : GraphicHelper* ExcelFilter::implCreateGraphicHelper() const
     162             : {
     163          11 :     return new ExcelGraphicHelper( getWorkbookGlobals() );
     164             : }
     165             : 
     166           0 : ::oox::ole::VbaProject* ExcelFilter::implCreateVbaProject() const
     167             : {
     168           0 :     return new ExcelVbaProject( getComponentContext(), Reference< XSpreadsheetDocument >( getModel(), UNO_QUERY ) );
     169             : }
     170             : 
     171             : 
     172          12 : sal_Bool SAL_CALL ExcelFilter::filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rDescriptor ) throw( ::com::sun::star::uno::RuntimeException )
     173             : {
     174          12 :     if ( XmlFilterBase::filter( rDescriptor ) )
     175          11 :         return true;
     176             : 
     177           1 :     if ( isExportFilter() )
     178             :     {
     179           1 :         Reference< XExporter > xExporter( getServiceFactory()->createInstance( "com.sun.star.comp.oox.ExcelFilterExport" ), UNO_QUERY );
     180             : 
     181           1 :         if ( xExporter.is() )
     182             :         {
     183           1 :             Reference< XComponent > xDocument( getModel(), UNO_QUERY );
     184           1 :             Reference< XFilter > xFilter( xExporter, UNO_QUERY );
     185             : 
     186           1 :             if ( xFilter.is() )
     187             :             {
     188           1 :                 xExporter->setSourceDocument( xDocument );
     189           1 :                 if ( xFilter->filter( rDescriptor ) )
     190           1 :                     return true;
     191           1 :             }
     192           1 :         }
     193             :     }
     194             : 
     195           0 :     return false;
     196             : }
     197             : 
     198           0 : OUString ExcelFilter::implGetImplementationName() const
     199             : {
     200           0 :     return ExcelFilter_getImplementationName();
     201             : }
     202             : 
     203             : } // namespace xls
     204           9 : } // namespace oox
     205             : 
     206             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10