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

Generated by: LCOV version 1.10