LCOV - code coverage report
Current view: top level - sc/source/filter/oox - tablebuffer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 58 13.8 %
Date: 2012-08-25 Functions: 4 13 30.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 102 6.9 %

           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 "tablebuffer.hxx"
      30                 :            : 
      31                 :            : #include <com/sun/star/sheet/XDatabaseRange.hpp>
      32                 :            : #include "oox/helper/attributelist.hxx"
      33                 :            : #include "oox/helper/binaryinputstream.hxx"
      34                 :            : #include "oox/helper/propertyset.hxx"
      35                 :            : #include "oox/token/properties.hxx"
      36                 :            : #include "addressconverter.hxx"
      37                 :            : 
      38                 :            : namespace oox {
      39                 :            : namespace xls {
      40                 :            : 
      41                 :            : // ============================================================================
      42                 :            : 
      43                 :            : using namespace ::com::sun::star::container;
      44                 :            : using namespace ::com::sun::star::sheet;
      45                 :            : using namespace ::com::sun::star::uno;
      46                 :            : 
      47                 :            : using ::rtl::OUString;
      48                 :            : 
      49                 :            : // ============================================================================
      50                 :            : 
      51                 :          0 : TableModel::TableModel() :
      52                 :            :     mnId( -1 ),
      53                 :            :     mnType( XML_worksheet ),
      54                 :            :     mnHeaderRows( 1 ),
      55                 :          0 :     mnTotalsRows( 0 )
      56                 :            : {
      57                 :          0 : }
      58                 :            : 
      59                 :            : // ============================================================================
      60                 :            : 
      61                 :          0 : Table::Table( const WorkbookHelper& rHelper ) :
      62                 :            :     WorkbookHelper( rHelper ),
      63                 :            :     maAutoFilters( rHelper ),
      64         [ #  # ]:          0 :     mnTokenIndex( -1 )
      65                 :            : {
      66                 :          0 : }
      67                 :            : 
      68                 :          0 : void Table::importTable( const AttributeList& rAttribs, sal_Int16 nSheet )
      69                 :            : {
      70 [ #  # ][ #  # ]:          0 :     getAddressConverter().convertToCellRangeUnchecked( maModel.maRange, rAttribs.getString( XML_ref, OUString() ), nSheet );
                 [ #  # ]
      71         [ #  # ]:          0 :     maModel.maProgName    = rAttribs.getXString( XML_name, OUString() );
      72         [ #  # ]:          0 :     maModel.maDisplayName = rAttribs.getXString( XML_displayName, OUString() );
      73                 :          0 :     maModel.mnId          = rAttribs.getInteger( XML_id, -1 );
      74                 :          0 :     maModel.mnType        = rAttribs.getToken( XML_tableType, XML_worksheet );
      75                 :          0 :     maModel.mnHeaderRows  = rAttribs.getInteger( XML_headerRowCount, 1 );
      76                 :          0 :     maModel.mnTotalsRows  = rAttribs.getInteger( XML_totalsRowCount, 0 );
      77                 :          0 : }
      78                 :            : 
      79                 :          0 : void Table::importTable( SequenceInputStream& rStrm, sal_Int16 nSheet )
      80                 :            : {
      81                 :          0 :     BinRange aBinRange;
      82                 :            :     sal_Int32 nType;
      83 [ #  # ][ #  # ]:          0 :     rStrm >> aBinRange >> nType >> maModel.mnId >> maModel.mnHeaderRows >> maModel.mnTotalsRows;
         [ #  # ][ #  # ]
                 [ #  # ]
      84         [ #  # ]:          0 :     rStrm.skip( 32 );
      85 [ #  # ][ #  # ]:          0 :     rStrm >> maModel.maProgName >> maModel.maDisplayName;
      86                 :            : 
      87 [ #  # ][ #  # ]:          0 :     getAddressConverter().convertToCellRangeUnchecked( maModel.maRange, aBinRange, nSheet );
      88                 :            :     static const sal_Int32 spnTypes[] = { XML_worksheet, XML_TOKEN_INVALID, XML_TOKEN_INVALID, XML_queryTable };
      89         [ #  # ]:          0 :     maModel.mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_TOKEN_INVALID );
      90                 :          0 : }
      91                 :            : 
      92                 :          0 : void Table::finalizeImport()
      93                 :            : {
      94                 :            :     // Create database range.  Note that Excel 2007 and later names database
      95                 :            :     // ranges (or tables in their terminology) as Table1, Table2 etc.  We need
      96                 :            :     // to import them as named db ranges because they may be referenced by
      97                 :            :     // name in formula expressions.
      98 [ #  # ][ #  # ]:          0 :     if( (maModel.mnId > 0) && !maModel.maDisplayName.isEmpty() ) try
                 [ #  # ]
      99                 :            :     {
     100                 :          0 :         maDBRangeName = maModel.maDisplayName;
     101                 :            :         Reference< XDatabaseRange > xDatabaseRange(
     102 [ #  # ][ #  # ]:          0 :             createDatabaseRangeObject( maDBRangeName, maModel.maRange ), UNO_SET_THROW);
     103 [ #  # ][ #  # ]:          0 :         maDestRange = xDatabaseRange->getDataArea();
     104                 :            : 
     105                 :            :         // get formula token index of the database range
     106         [ #  # ]:          0 :         PropertySet aPropSet( xDatabaseRange );
     107 [ #  # ][ #  # ]:          0 :         if( !aPropSet.getProperty( mnTokenIndex, PROP_TokenIndex ) )
     108                 :          0 :             mnTokenIndex = -1;
     109                 :            : 
     110                 :            :         // filter settings
     111 [ #  # ][ #  # ]:          0 :         maAutoFilters.finalizeImport( xDatabaseRange );
                 [ #  # ]
     112                 :            :     }
     113                 :          0 :     catch( Exception& )
     114                 :            :     {
     115                 :            :         OSL_FAIL( "Table::finalizeImport - cannot create database range" );
     116                 :            :     }
     117                 :          0 : }
     118                 :            : 
     119                 :            : // ============================================================================
     120                 :            : 
     121                 :         24 : TableBuffer::TableBuffer( const WorkbookHelper& rHelper ) :
     122 [ +  - ][ +  - ]:         24 :     WorkbookHelper( rHelper )
                 [ +  - ]
     123                 :            : {
     124                 :         24 : }
     125                 :            : 
     126                 :          0 : Table& TableBuffer::createTable()
     127                 :            : {
     128 [ #  # ][ #  # ]:          0 :     TableVector::value_type xTable( new Table( *this ) );
                 [ #  # ]
     129         [ #  # ]:          0 :     maTables.push_back( xTable );
     130         [ #  # ]:          0 :     return *xTable;
     131                 :            : }
     132                 :            : 
     133                 :         24 : void TableBuffer::finalizeImport()
     134                 :            : {
     135                 :            :     // map all tables by identifier and display name
     136 [ +  - ][ -  + ]:         24 :     for( TableVector::iterator aIt = maTables.begin(), aEnd = maTables.end(); aIt != aEnd; ++aIt )
     137         [ #  # ]:          0 :         insertTableToMaps( *aIt );
     138                 :            :     // finalize all valid tables
     139                 :         24 :     maIdTables.forEachMem( &Table::finalizeImport );
     140                 :         24 : }
     141                 :            : 
     142                 :          0 : TableRef TableBuffer::getTable( sal_Int32 nTableId ) const
     143                 :            : {
     144                 :          0 :     return maIdTables.get( nTableId );
     145                 :            : }
     146                 :            : 
     147                 :          0 : TableRef TableBuffer::getTable( const OUString& rDispName ) const
     148                 :            : {
     149         [ #  # ]:          0 :     return maNameTables.get( rDispName );
     150                 :            : }
     151                 :            : 
     152                 :            : // private --------------------------------------------------------------------
     153                 :            : 
     154                 :          0 : void TableBuffer::insertTableToMaps( const TableRef& rxTable )
     155                 :            : {
     156                 :          0 :     sal_Int32 nTableId = rxTable->getTableId();
     157                 :          0 :     const OUString& rDispName = rxTable->getDisplayName();
     158 [ #  # ][ #  # ]:          0 :     if( (nTableId > 0) && !rDispName.isEmpty() )
                 [ #  # ]
     159                 :            :     {
     160                 :            :         OSL_ENSURE( !maIdTables.has( nTableId ), "TableBuffer::insertTableToMaps - multiple table identifier" );
     161 [ #  # ][ #  # ]:          0 :         maIdTables[ nTableId ] = rxTable;
     162                 :            :         OSL_ENSURE( !maNameTables.has( rDispName ), "TableBuffer::insertTableToMaps - multiple table name" );
     163 [ #  # ][ #  # ]:          0 :         maNameTables[ rDispName ] = rxTable;
     164                 :            :     }
     165                 :          0 : }
     166                 :            : 
     167                 :            : // ============================================================================
     168                 :            : 
     169                 :            : } // namespace xls
     170 [ +  - ][ +  - ]:         24 : } // namespace oox
     171                 :            : 
     172                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10