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

Generated by: LCOV version 1.10