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

Generated by: LCOV version 1.10