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

Generated by: LCOV version 1.10