LCOV - code coverage report
Current view: top level - sc/source/filter/oox - connectionsbuffer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 4 141 2.8 %
Date: 2014-04-11 Functions: 3 19 15.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 "connectionsbuffer.hxx"
      21             : 
      22             : #include "oox/helper/attributelist.hxx"
      23             : #include "biffinputstream.hxx"
      24             : 
      25             : namespace oox {
      26             : namespace xls {
      27             : 
      28             : using namespace ::com::sun::star::uno;
      29             : 
      30             : 
      31             : namespace {
      32             : 
      33             : const sal_Int32 BIFF12_RECONNECT_AS_REQUIRED            = 1;
      34             : 
      35             : const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_ON       = 1;
      36             : 
      37             : const sal_uInt16 BIFF12_CONNECTION_KEEPALIVE            = 0x0001;
      38             : const sal_uInt16 BIFF12_CONNECTION_NEW                  = 0x0002;
      39             : const sal_uInt16 BIFF12_CONNECTION_DELETED              = 0x0004;
      40             : const sal_uInt16 BIFF12_CONNECTION_ONLYUSECONNFILE      = 0x0008;
      41             : const sal_uInt16 BIFF12_CONNECTION_BACKGROUND           = 0x0010;
      42             : const sal_uInt16 BIFF12_CONNECTION_REFRESHONLOAD        = 0x0020;
      43             : const sal_uInt16 BIFF12_CONNECTION_SAVEDATA             = 0x0040;
      44             : 
      45             : const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCEFILE       = 0x0001;
      46             : const sal_uInt16 BIFF12_CONNECTION_HAS_SOURCECONNFILE   = 0x0002;
      47             : const sal_uInt16 BIFF12_CONNECTION_HAS_DESCRIPTION      = 0x0004;
      48             : const sal_uInt16 BIFF12_CONNECTION_HAS_NAME             = 0x0008;
      49             : const sal_uInt16 BIFF12_CONNECTION_HAS_SSOID            = 0x0010;
      50             : 
      51             : const sal_uInt32 BIFF12_WEBPR_XML                       = 0x00000100;
      52             : const sal_uInt32 BIFF12_WEBPR_SOURCEDATA                = 0x00000200;
      53             : const sal_uInt32 BIFF12_WEBPR_PARSEPRE                  = 0x00000400;
      54             : const sal_uInt32 BIFF12_WEBPR_CONSECUTIVE               = 0x00000800;
      55             : const sal_uInt32 BIFF12_WEBPR_FIRSTROW                  = 0x00001000;
      56             : const sal_uInt32 BIFF12_WEBPR_XL97CREATED               = 0x00002000;
      57             : const sal_uInt32 BIFF12_WEBPR_TEXTDATES                 = 0x00004000;
      58             : const sal_uInt32 BIFF12_WEBPR_XL2000REFRESHED           = 0x00008000;
      59             : const sal_uInt32 BIFF12_WEBPR_HTMLTABLES                = 0x00010000;
      60             : 
      61             : const sal_uInt8 BIFF12_WEBPR_HAS_POSTMETHOD             = 0x01;
      62             : const sal_uInt8 BIFF12_WEBPR_HAS_EDITPAGE               = 0x02;
      63             : const sal_uInt8 BIFF12_WEBPR_HAS_URL                    = 0x04;
      64             : 
      65             : } // namespace
      66             : 
      67           0 : WebPrModel::WebPrModel() :
      68             :     mnHtmlFormat( XML_none ),
      69             :     mbXml( false ),
      70             :     mbSourceData( false ),
      71             :     mbParsePre( false ),
      72             :     mbConsecutive( false ),
      73             :     mbFirstRow( false ),
      74             :     mbXl97Created( false ),
      75             :     mbTextDates( false ),
      76             :     mbXl2000Refreshed( false ),
      77           0 :     mbHtmlTables( false )
      78             : {
      79           0 : }
      80             : 
      81           0 : ConnectionModel::ConnectionModel() :
      82             :     mnId( -1 ),
      83             :     mnType( BIFF12_CONNECTION_UNKNOWN ),
      84             :     mnReconnectMethod( BIFF12_RECONNECT_AS_REQUIRED ),
      85             :     mnCredentials( XML_integrated ),
      86             :     mnInterval( 0 ),
      87             :     mbKeepAlive( false ),
      88             :     mbNew( false ),
      89             :     mbDeleted( false ),
      90             :     mbOnlyUseConnFile( false ),
      91             :     mbBackground( false ),
      92             :     mbRefreshOnLoad( false ),
      93             :     mbSaveData( false ),
      94           0 :     mbSavePassword( false )
      95             : {
      96           0 : }
      97             : 
      98           0 : WebPrModel& ConnectionModel::createWebPr()
      99             : {
     100             :     OSL_ENSURE( !mxWebPr.get(), "ConnectionModel::createWebPr - multiple call" );
     101           0 :     mxWebPr.reset( new WebPrModel );
     102           0 :     return *mxWebPr;
     103             : }
     104             : 
     105           0 : Connection::Connection( const WorkbookHelper& rHelper, sal_Int32 nConnId ) :
     106           0 :     WorkbookHelper( rHelper )
     107             : {
     108           0 :     maModel.mnId = nConnId;
     109           0 : }
     110             : 
     111           0 : void Connection::importConnection( const AttributeList& rAttribs )
     112             : {
     113           0 :     maModel.maName            = rAttribs.getXString( XML_name, OUString() );
     114           0 :     maModel.maDescription     = rAttribs.getXString( XML_description, OUString() );
     115           0 :     maModel.maSourceFile      = rAttribs.getXString( XML_sourceFile, OUString() );
     116           0 :     maModel.maSourceConnFile  = rAttribs.getXString( XML_odcFile, OUString() );
     117           0 :     maModel.maSsoId           = rAttribs.getXString( XML_singleSignOnId, OUString() );
     118           0 :     maModel.mnId              = rAttribs.getInteger( XML_id, -1 );
     119             :     // type and reconnectionMethod are using the BIFF12 constants instead of XML tokens
     120           0 :     maModel.mnType            = rAttribs.getInteger( XML_type, BIFF12_CONNECTION_UNKNOWN );
     121           0 :     maModel.mnReconnectMethod = rAttribs.getInteger( XML_reconnectionMethod, BIFF12_RECONNECT_AS_REQUIRED );
     122           0 :     maModel.mnCredentials     = rAttribs.getToken( XML_credentials, XML_integrated );
     123           0 :     maModel.mnInterval        = rAttribs.getInteger( XML_interval, 0 );
     124           0 :     maModel.mbKeepAlive       = rAttribs.getBool( XML_keepAlive, false );
     125           0 :     maModel.mbNew             = rAttribs.getBool( XML_new, false );
     126           0 :     maModel.mbDeleted         = rAttribs.getBool( XML_deleted, false );
     127           0 :     maModel.mbOnlyUseConnFile = rAttribs.getBool( XML_onlyUseConnectionFile, false );
     128           0 :     maModel.mbBackground      = rAttribs.getBool( XML_background, false );
     129           0 :     maModel.mbRefreshOnLoad   = rAttribs.getBool( XML_refreshOnLoad, false );
     130           0 :     maModel.mbSaveData        = rAttribs.getBool( XML_saveData, false );
     131           0 :     maModel.mbSavePassword    = rAttribs.getBool( XML_savePassword, false );
     132           0 : }
     133             : 
     134           0 : void Connection::importWebPr( const AttributeList& rAttribs )
     135             : {
     136           0 :     WebPrModel& rWebPr = maModel.createWebPr();
     137             : 
     138           0 :     rWebPr.maUrl             = rAttribs.getXString( XML_url, OUString() );
     139           0 :     rWebPr.maPostMethod      = rAttribs.getXString( XML_post, OUString() );
     140           0 :     rWebPr.maEditPage        = rAttribs.getXString( XML_editPage, OUString() );
     141           0 :     rWebPr.mnHtmlFormat      = rAttribs.getToken( XML_htmlFormat, XML_none );
     142           0 :     rWebPr.mbXml             = rAttribs.getBool( XML_xml, false );
     143           0 :     rWebPr.mbSourceData      = rAttribs.getBool( XML_sourceData, false );
     144           0 :     rWebPr.mbParsePre        = rAttribs.getBool( XML_parsePre, false );
     145           0 :     rWebPr.mbConsecutive     = rAttribs.getBool( XML_consecutive, false );
     146           0 :     rWebPr.mbFirstRow        = rAttribs.getBool( XML_firstRow, false );
     147           0 :     rWebPr.mbXl97Created     = rAttribs.getBool( XML_xl97, false );
     148           0 :     rWebPr.mbTextDates       = rAttribs.getBool( XML_textDates, false );
     149           0 :     rWebPr.mbXl2000Refreshed = rAttribs.getBool( XML_xl2000, false );
     150           0 :     rWebPr.mbHtmlTables      = rAttribs.getBool( XML_htmlTables, false );
     151           0 : }
     152             : 
     153           0 : void Connection::importTables( const AttributeList& /*rAttribs*/ )
     154             : {
     155           0 :     if( maModel.mxWebPr.get() )
     156             :     {
     157             :         OSL_ENSURE( maModel.mxWebPr->maTables.empty(), "Connection::importTables - multiple calls" );
     158           0 :         maModel.mxWebPr->maTables.clear();
     159             :     }
     160           0 : }
     161             : 
     162           0 : void Connection::importTable( const AttributeList& rAttribs, sal_Int32 nElement )
     163             : {
     164           0 :     if( maModel.mxWebPr.get() )
     165             :     {
     166           0 :         Any aTableAny;
     167           0 :         switch( nElement )
     168             :         {
     169           0 :             case XLS_TOKEN( m ):                                                            break;
     170           0 :             case XLS_TOKEN( s ):    aTableAny <<= rAttribs.getXString( XML_v, OUString() ); break;
     171           0 :             case XLS_TOKEN( x ):    aTableAny <<= rAttribs.getInteger( XML_v, -1 );         break;
     172             :             default:
     173             :                 OSL_ENSURE( false, "Connection::importTable - unexpected element" );
     174           0 :                 return;
     175             :         }
     176           0 :         maModel.mxWebPr->maTables.push_back( aTableAny );
     177             :     }
     178             : }
     179             : 
     180           0 : void Connection::importConnection( SequenceInputStream& rStrm )
     181             : {
     182             :     sal_uInt16 nFlags, nStrFlags;
     183             :     sal_uInt8 nSavePassword, nCredentials;
     184           0 :     rStrm.skip( 2 );
     185           0 :     rStrm >> nSavePassword;
     186           0 :     rStrm.skip( 1 );
     187           0 :     maModel.mnInterval = rStrm.readuInt16();
     188           0 :     rStrm >> nFlags >> nStrFlags >> maModel.mnType >> maModel.mnReconnectMethod >> maModel.mnId >> nCredentials;
     189             : 
     190           0 :     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SOURCEFILE ) )
     191           0 :         rStrm >> maModel.maSourceFile;
     192           0 :     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SOURCECONNFILE ) )
     193           0 :         rStrm >> maModel.maSourceConnFile;
     194           0 :     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_DESCRIPTION ) )
     195           0 :         rStrm >> maModel.maDescription;
     196           0 :     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_NAME ) )
     197           0 :         rStrm >> maModel.maName;
     198           0 :     if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SSOID ) )
     199           0 :         rStrm >> maModel.maSsoId;
     200             : 
     201             :     static const sal_Int32 spnCredentials[] = { XML_integrated, XML_none, XML_stored, XML_prompt };
     202           0 :     maModel.mnCredentials = STATIC_ARRAY_SELECT( spnCredentials, nCredentials, XML_integrated );
     203             : 
     204           0 :     maModel.mbKeepAlive       = getFlag( nFlags, BIFF12_CONNECTION_KEEPALIVE );
     205           0 :     maModel.mbNew             = getFlag( nFlags, BIFF12_CONNECTION_NEW );
     206           0 :     maModel.mbDeleted         = getFlag( nFlags, BIFF12_CONNECTION_DELETED );
     207           0 :     maModel.mbOnlyUseConnFile = getFlag( nFlags, BIFF12_CONNECTION_ONLYUSECONNFILE );
     208           0 :     maModel.mbBackground      = getFlag( nFlags, BIFF12_CONNECTION_BACKGROUND );
     209           0 :     maModel.mbRefreshOnLoad   = getFlag( nFlags, BIFF12_CONNECTION_REFRESHONLOAD );
     210           0 :     maModel.mbSaveData        = getFlag( nFlags, BIFF12_CONNECTION_SAVEDATA );
     211           0 :     maModel.mbSavePassword    = nSavePassword == BIFF12_CONNECTION_SAVEPASSWORD_ON;
     212           0 : }
     213             : 
     214           0 : void Connection::importWebPr( SequenceInputStream& rStrm )
     215             : {
     216           0 :     WebPrModel& rWebPr = maModel.createWebPr();
     217             : 
     218             :     sal_uInt32 nFlags;
     219             :     sal_uInt8 nStrFlags;
     220           0 :     rStrm >> nFlags >> nStrFlags;
     221             : 
     222           0 :     if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_URL ) )
     223           0 :         rStrm >> rWebPr.maUrl;
     224           0 :     if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_POSTMETHOD ) )
     225           0 :         rStrm >> rWebPr.maPostMethod;
     226           0 :     if( getFlag( nStrFlags, BIFF12_WEBPR_HAS_EDITPAGE ) )
     227           0 :         rStrm >> rWebPr.maEditPage;
     228             : 
     229             :     static const sal_Int32 spnHmlFormats[] = { XML_none, XML_rtf, XML_all };
     230           0 :     rWebPr.mnHtmlFormat = STATIC_ARRAY_SELECT( spnHmlFormats, extractValue< sal_uInt8 >( nFlags, 0, 8 ), XML_none );
     231             : 
     232           0 :     rWebPr.mbXml             = getFlag( nFlags, BIFF12_WEBPR_XML );
     233           0 :     rWebPr.mbSourceData      = getFlag( nFlags, BIFF12_WEBPR_SOURCEDATA );
     234           0 :     rWebPr.mbParsePre        = getFlag( nFlags, BIFF12_WEBPR_PARSEPRE );
     235           0 :     rWebPr.mbConsecutive     = getFlag( nFlags, BIFF12_WEBPR_CONSECUTIVE );
     236           0 :     rWebPr.mbFirstRow        = getFlag( nFlags, BIFF12_WEBPR_FIRSTROW );
     237           0 :     rWebPr.mbXl97Created     = getFlag( nFlags, BIFF12_WEBPR_XL97CREATED );
     238           0 :     rWebPr.mbTextDates       = getFlag( nFlags, BIFF12_WEBPR_TEXTDATES );
     239           0 :     rWebPr.mbXl2000Refreshed = getFlag( nFlags, BIFF12_WEBPR_XL2000REFRESHED );
     240           0 :     rWebPr.mbHtmlTables      = getFlag( nFlags, BIFF12_WEBPR_HTMLTABLES );
     241           0 : }
     242             : 
     243           0 : void Connection::importWebPrTables( SequenceInputStream& /*rStrm*/ )
     244             : {
     245           0 :     if( maModel.mxWebPr.get() )
     246             :     {
     247             :         OSL_ENSURE( maModel.mxWebPr->maTables.empty(), "Connection::importWebPrTables - multiple calls" );
     248           0 :         maModel.mxWebPr->maTables.clear();
     249             :     }
     250           0 : }
     251             : 
     252           0 : void Connection::importWebPrTable( SequenceInputStream& rStrm, sal_Int32 nRecId )
     253             : {
     254           0 :     if( maModel.mxWebPr.get() )
     255             :     {
     256           0 :         Any aTableAny;
     257           0 :         switch( nRecId )
     258             :         {
     259           0 :             case BIFF12_ID_PCITEM_MISSING:                                                  break;
     260           0 :             case BIFF12_ID_PCITEM_STRING:   aTableAny <<= BiffHelper::readString( rStrm );  break;
     261           0 :             case BIFF12_ID_PCITEM_INDEX:    aTableAny <<= rStrm.readInt32();                break;
     262             :             default:
     263             :                 OSL_ENSURE( false, "Connection::importWebPrTable - unexpected record" );
     264           0 :                 return;
     265             :         }
     266           0 :         maModel.mxWebPr->maTables.push_back( aTableAny );
     267             :     }
     268             : }
     269             : 
     270          44 : ConnectionsBuffer::ConnectionsBuffer( const WorkbookHelper& rHelper ) :
     271             :     WorkbookHelper( rHelper ),
     272          44 :     mnUnusedId( 1 )
     273             : {
     274          44 : }
     275             : 
     276           0 : Connection& ConnectionsBuffer::createConnection()
     277             : {
     278           0 :     ConnectionRef xConnection( new Connection( *this ) );
     279           0 :     maConnections.push_back( xConnection );
     280           0 :     return *xConnection;
     281             : }
     282             : 
     283           0 : void ConnectionsBuffer::finalizeImport()
     284             : {
     285           0 :     for( ConnectionVector::iterator aIt = maConnections.begin(), aEnd = maConnections.end(); aIt != aEnd; ++aIt )
     286           0 :         insertConnectionToMap( *aIt );
     287           0 : }
     288             : 
     289           0 : ConnectionRef ConnectionsBuffer::getConnection( sal_Int32 nConnId ) const
     290             : {
     291           0 :     return maConnectionsById.get( nConnId );
     292             : }
     293             : 
     294           0 : void ConnectionsBuffer::insertConnectionToMap( const ConnectionRef& rxConnection )
     295             : {
     296           0 :     sal_Int32 nConnId = rxConnection->getConnectionId();
     297           0 :     if( nConnId > 0 )
     298             :     {
     299             :         OSL_ENSURE( !maConnectionsById.has( nConnId ), "ConnectionsBuffer::insertConnectionToMap - multiple connection identifier" );
     300           0 :         maConnectionsById[ nConnId ] = rxConnection;
     301           0 :         mnUnusedId = ::std::max< sal_Int32 >( mnUnusedId, nConnId + 1 );
     302             :     }
     303           0 : }
     304             : 
     305             : } // namespace xls
     306          18 : } // namespace oox
     307             : 
     308             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10