LCOV - code coverage report
Current view: top level - sc/source/filter/excel - xeroot.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 128 0.8 %
Date: 2012-08-25 Functions: 2 32 6.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 225 0.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <rtl/random.h>
      31                 :            : #include <sfx2/docfile.hxx>
      32                 :            : #include <sfx2/request.hxx>
      33                 :            : #include <sfx2/frame.hxx>
      34                 :            : #include <sfx2/sfxsids.hrc>
      35                 :            : #include <unotools/saveopt.hxx>
      36                 :            : #include <svl/itemset.hxx>
      37                 :            : #include <svl/stritem.hxx>
      38                 :            : #include <svl/intitem.hxx>
      39                 :            : #include <svl/eitem.hxx>
      40                 :            : #include "xecontent.hxx"
      41                 :            : #include "xltracer.hxx"
      42                 :            : #include "xeescher.hxx"
      43                 :            : #include "xeformula.hxx"
      44                 :            : #include "xehelper.hxx"
      45                 :            : #include "xelink.hxx"
      46                 :            : #include "xename.hxx"
      47                 :            : #include "xepivot.hxx"
      48                 :            : #include "xestyle.hxx"
      49                 :            : #include "xeroot.hxx"
      50                 :            : 
      51                 :            : #include "excrecds.hxx"  // for filter manager
      52                 :            : #include "tabprotection.hxx"
      53                 :            : #include "document.hxx"
      54                 :            : #include "scextopt.hxx"
      55                 :            : 
      56                 :            : using namespace ::com::sun::star;
      57                 :            : 
      58                 :            : // Global data ================================================================
      59                 :            : 
      60                 :          0 : XclExpRootData::XclExpRootData( XclBiff eBiff, SfxMedium& rMedium,
      61                 :            :         SotStorageRef xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc ) :
      62 [ #  # ][ #  # ]:          0 :     XclRootData( eBiff, rMedium, xRootStrg, rDoc, eTextEnc, true )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      63                 :            : {
      64         [ #  # ]:          0 :     SvtSaveOptions aSaveOpt;
      65 [ #  # ][ #  # ]:          0 :     mbRelUrl = mrMedium.IsRemote() ? aSaveOpt.IsSaveRelINet() : aSaveOpt.IsSaveRelFSys();
         [ #  # ][ #  # ]
                 [ #  # ]
      66                 :          0 : }
      67                 :            : 
      68 [ #  # ][ #  # ]:          0 : XclExpRootData::~XclExpRootData()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      69                 :            : {
      70         [ #  # ]:          0 : }
      71                 :            : 
      72                 :            : // ----------------------------------------------------------------------------
      73                 :            : 
      74                 :          0 : XclExpRoot::XclExpRoot( XclExpRootData& rExpRootData ) :
      75                 :            :     XclRoot( rExpRootData ),
      76                 :          0 :     mrExpData( rExpRootData )
      77                 :            : {
      78                 :          0 : }
      79                 :            : 
      80                 :          0 : XclExpTabInfo& XclExpRoot::GetTabInfo() const
      81                 :            : {
      82                 :            :     OSL_ENSURE( mrExpData.mxTabInfo, "XclExpRoot::GetTabInfo - missing object (wrong BIFF?)" );
      83                 :          0 :     return *mrExpData.mxTabInfo;
      84                 :            : }
      85                 :            : 
      86                 :          0 : XclExpAddressConverter& XclExpRoot::GetAddressConverter() const
      87                 :            : {
      88                 :            :     OSL_ENSURE( mrExpData.mxAddrConv, "XclExpRoot::GetAddressConverter - missing object (wrong BIFF?)" );
      89                 :          0 :     return *mrExpData.mxAddrConv;
      90                 :            : }
      91                 :            : 
      92                 :          0 : XclExpFormulaCompiler& XclExpRoot::GetFormulaCompiler() const
      93                 :            : {
      94                 :            :     OSL_ENSURE( mrExpData.mxFmlaComp, "XclExpRoot::GetFormulaCompiler - missing object (wrong BIFF?)" );
      95                 :          0 :     return *mrExpData.mxFmlaComp;
      96                 :            : }
      97                 :            : 
      98                 :          0 : XclExpProgressBar& XclExpRoot::GetProgressBar() const
      99                 :            : {
     100                 :            :     OSL_ENSURE( mrExpData.mxProgress, "XclExpRoot::GetProgressBar - missing object (wrong BIFF?)" );
     101                 :          0 :     return *mrExpData.mxProgress;
     102                 :            : }
     103                 :            : 
     104                 :          0 : XclExpSst& XclExpRoot::GetSst() const
     105                 :            : {
     106                 :            :     OSL_ENSURE( mrExpData.mxSst, "XclExpRoot::GetSst - missing object (wrong BIFF?)" );
     107                 :          0 :     return *mrExpData.mxSst;
     108                 :            : }
     109                 :            : 
     110                 :          0 : XclExpPalette& XclExpRoot::GetPalette() const
     111                 :            : {
     112                 :            :     OSL_ENSURE( mrExpData.mxPalette, "XclExpRoot::GetPalette - missing object (wrong BIFF?)" );
     113                 :          0 :     return *mrExpData.mxPalette;
     114                 :            : }
     115                 :            : 
     116                 :          0 : XclExpFontBuffer& XclExpRoot::GetFontBuffer() const
     117                 :            : {
     118                 :            :     OSL_ENSURE( mrExpData.mxFontBfr, "XclExpRoot::GetFontBuffer - missing object (wrong BIFF?)" );
     119                 :          0 :     return *mrExpData.mxFontBfr;
     120                 :            : }
     121                 :            : 
     122                 :          0 : XclExpNumFmtBuffer& XclExpRoot::GetNumFmtBuffer() const
     123                 :            : {
     124                 :            :     OSL_ENSURE( mrExpData.mxNumFmtBfr, "XclExpRoot::GetNumFmtBuffer - missing object (wrong BIFF?)" );
     125                 :          0 :     return *mrExpData.mxNumFmtBfr;
     126                 :            : }
     127                 :            : 
     128                 :          0 : XclExpXFBuffer& XclExpRoot::GetXFBuffer() const
     129                 :            : {
     130                 :            :     OSL_ENSURE( mrExpData.mxXFBfr, "XclExpRoot::GetXFBuffer - missing object (wrong BIFF?)" );
     131                 :          0 :     return *mrExpData.mxXFBfr;
     132                 :            : }
     133                 :            : 
     134                 :          0 : XclExpLinkManager& XclExpRoot::GetGlobalLinkManager() const
     135                 :            : {
     136                 :            :     OSL_ENSURE( mrExpData.mxGlobLinkMgr, "XclExpRoot::GetGlobalLinkManager - missing object (wrong BIFF?)" );
     137                 :          0 :     return *mrExpData.mxGlobLinkMgr;
     138                 :            : }
     139                 :            : 
     140                 :          0 : XclExpLinkManager& XclExpRoot::GetLocalLinkManager() const
     141                 :            : {
     142                 :            :     OSL_ENSURE( GetLocalLinkMgrRef(), "XclExpRoot::GetLocalLinkManager - missing object (wrong BIFF?)" );
     143                 :          0 :     return *GetLocalLinkMgrRef();
     144                 :            : }
     145                 :            : 
     146                 :          0 : XclExpNameManager& XclExpRoot::GetNameManager() const
     147                 :            : {
     148                 :            :     OSL_ENSURE( mrExpData.mxNameMgr, "XclExpRoot::GetNameManager - missing object (wrong BIFF?)" );
     149                 :          0 :     return *mrExpData.mxNameMgr;
     150                 :            : }
     151                 :            : 
     152                 :          0 : XclExpObjectManager& XclExpRoot::GetObjectManager() const
     153                 :            : {
     154                 :            :     OSL_ENSURE( mrExpData.mxObjMgr, "XclExpRoot::GetObjectManager - missing object (wrong BIFF?)" );
     155                 :          0 :     return *mrExpData.mxObjMgr;
     156                 :            : }
     157                 :            : 
     158                 :          0 : XclExpFilterManager& XclExpRoot::GetFilterManager() const
     159                 :            : {
     160                 :            :     OSL_ENSURE( mrExpData.mxFilterMgr, "XclExpRoot::GetFilterManager - missing object (wrong BIFF?)" );
     161                 :          0 :     return *mrExpData.mxFilterMgr;
     162                 :            : }
     163                 :            : 
     164                 :          0 : XclExpDxfs& XclExpRoot::GetDxfs() const
     165                 :            : {
     166                 :            :     OSL_ENSURE( mrExpData.mxDxfs, "XclExpRoot::GetDxfs - missing object ( wrong BIFF?)" );
     167                 :          0 :     return *mrExpData.mxDxfs;
     168                 :            : }
     169                 :            : 
     170                 :          0 : XclExpPivotTableManager& XclExpRoot::GetPivotTableManager() const
     171                 :            : {
     172                 :            :     OSL_ENSURE( mrExpData.mxPTableMgr, "XclExpRoot::GetPivotTableManager - missing object (wrong BIFF?)" );
     173                 :          0 :     return *mrExpData.mxPTableMgr;
     174                 :            : }
     175                 :            : 
     176                 :          0 : void XclExpRoot::InitializeConvert()
     177                 :            : {
     178         [ #  # ]:          0 :     mrExpData.mxTabInfo.reset( new XclExpTabInfo( GetRoot() ) );
     179         [ #  # ]:          0 :     mrExpData.mxAddrConv.reset( new XclExpAddressConverter( GetRoot() ) );
     180         [ #  # ]:          0 :     mrExpData.mxFmlaComp.reset( new XclExpFormulaCompiler( GetRoot() ) );
     181         [ #  # ]:          0 :     mrExpData.mxProgress.reset( new XclExpProgressBar( GetRoot() ) );
     182                 :            : 
     183                 :          0 :     GetProgressBar().Initialize();
     184                 :          0 : }
     185                 :            : 
     186                 :          0 : void XclExpRoot::InitializeGlobals()
     187                 :            : {
     188                 :          0 :     SetCurrScTab( SCTAB_GLOBAL );
     189                 :            : 
     190         [ #  # ]:          0 :     if( GetBiff() >= EXC_BIFF5 )
     191                 :            :     {
     192         [ #  # ]:          0 :         mrExpData.mxPalette.reset( new XclExpPalette( GetRoot() ) );
     193         [ #  # ]:          0 :         mrExpData.mxFontBfr.reset( new XclExpFontBuffer( GetRoot() ) );
     194         [ #  # ]:          0 :         mrExpData.mxNumFmtBfr.reset( new XclExpNumFmtBuffer( GetRoot() ) );
     195         [ #  # ]:          0 :         mrExpData.mxXFBfr.reset( new XclExpXFBuffer( GetRoot() ) );
     196         [ #  # ]:          0 :         mrExpData.mxGlobLinkMgr.reset( new XclExpLinkManager( GetRoot() ) );
     197         [ #  # ]:          0 :         mrExpData.mxNameMgr.reset( new XclExpNameManager( GetRoot() ) );
     198                 :            :     }
     199                 :            : 
     200         [ #  # ]:          0 :     if( GetBiff() == EXC_BIFF8 )
     201                 :            :     {
     202         [ #  # ]:          0 :         mrExpData.mxSst.reset( new XclExpSst );
     203         [ #  # ]:          0 :         mrExpData.mxObjMgr.reset( new XclExpObjectManager( GetRoot() ) );
     204         [ #  # ]:          0 :         mrExpData.mxFilterMgr.reset( new XclExpFilterManager( GetRoot() ) );
     205         [ #  # ]:          0 :         mrExpData.mxPTableMgr.reset( new XclExpPivotTableManager( GetRoot() ) );
     206                 :            :         // BIFF8: only one link manager for all sheets
     207                 :          0 :         mrExpData.mxLocLinkMgr = mrExpData.mxGlobLinkMgr;
     208         [ #  # ]:          0 :         mrExpData.mxDxfs.reset( new XclExpDxfs( GetRoot() ) );
     209                 :            :     }
     210                 :            : 
     211                 :          0 :     GetXFBuffer().Initialize();
     212                 :          0 :     GetNameManager().Initialize();
     213                 :          0 : }
     214                 :            : 
     215                 :          0 : void XclExpRoot::InitializeTable( SCTAB nScTab )
     216                 :            : {
     217                 :          0 :     SetCurrScTab( nScTab );
     218         [ #  # ]:          0 :     if( GetBiff() == EXC_BIFF5 )
     219                 :            :     {
     220                 :            :         // local link manager per sheet
     221         [ #  # ]:          0 :         mrExpData.mxLocLinkMgr.reset( new XclExpLinkManager( GetRoot() ) );
     222                 :            :     }
     223                 :          0 : }
     224                 :            : 
     225                 :          0 : void XclExpRoot::InitializeSave()
     226                 :            : {
     227                 :          0 :     GetPalette().Finalize();
     228                 :          0 :     GetXFBuffer().Finalize();
     229                 :          0 : }
     230                 :            : 
     231                 :          0 : XclExpRecordRef XclExpRoot::CreateRecord( sal_uInt16 nRecId ) const
     232                 :            : {
     233                 :          0 :     XclExpRecordRef xRec;
     234   [ #  #  #  #  :          0 :     switch( nRecId )
             #  #  #  #  
                      # ]
     235                 :            :     {
     236         [ #  # ]:          0 :         case EXC_ID_PALETTE:        xRec = mrExpData.mxPalette;     break;
     237         [ #  # ]:          0 :         case EXC_ID_FONTLIST:       xRec = mrExpData.mxFontBfr;     break;
     238         [ #  # ]:          0 :         case EXC_ID_FORMATLIST:     xRec = mrExpData.mxNumFmtBfr;   break;
     239         [ #  # ]:          0 :         case EXC_ID_XFLIST:         xRec = mrExpData.mxXFBfr;       break;
     240         [ #  # ]:          0 :         case EXC_ID_SST:            xRec = mrExpData.mxSst;         break;
     241 [ #  # ][ #  # ]:          0 :         case EXC_ID_EXTERNSHEET:    xRec = GetLocalLinkMgrRef();    break;
                 [ #  # ]
     242         [ #  # ]:          0 :         case EXC_ID_NAME:           xRec = mrExpData.mxNameMgr;     break;
     243         [ #  # ]:          0 :         case EXC_ID_DXFS:           xRec = mrExpData.mxDxfs;        break;
     244                 :            :     }
     245                 :            :     OSL_ENSURE( xRec, "XclExpRoot::CreateRecord - unknown record ID or missing object" );
     246                 :          0 :     return xRec;
     247                 :            : }
     248                 :            : 
     249                 :          0 : bool XclExpRoot::IsDocumentEncrypted() const
     250                 :            : {
     251                 :            :     // We need to encrypt the content when the document structure is protected.
     252                 :          0 :     const ScDocProtection* pDocProt = GetDoc().GetDocProtection();
     253 [ #  # ][ #  # ]:          0 :     if (pDocProt && pDocProt->isProtected() && pDocProt->isOptionEnabled(ScDocProtection::STRUCTURE))
         [ #  # ][ #  # ]
     254                 :          0 :         return true;
     255                 :            : 
     256         [ #  # ]:          0 :     if ( GetEncryptionData().getLength() > 0 )
     257                 :            :         // Password is entered directly into the save dialog.
     258                 :          0 :         return true;
     259                 :            : 
     260                 :          0 :     return false;
     261                 :            : }
     262                 :            : 
     263                 :          0 : uno::Sequence< beans::NamedValue > XclExpRoot::GenerateEncryptionData( const ::rtl::OUString& aPass ) const
     264                 :            : {
     265                 :          0 :     uno::Sequence< beans::NamedValue > aEncryptionData;
     266                 :            : 
     267 [ #  # ][ #  # ]:          0 :     if ( !aPass.isEmpty() && aPass.getLength() < 16 )
                 [ #  # ]
     268                 :            :     {
     269                 :            :         TimeValue aTime;
     270         [ #  # ]:          0 :         osl_getSystemTime( &aTime );
     271                 :          0 :         rtlRandomPool aRandomPool = rtl_random_createPool ();
     272                 :          0 :         rtl_random_addBytes ( aRandomPool, &aTime, 8 );
     273                 :            : 
     274                 :            :         sal_uInt8 pnDocId[16];
     275                 :          0 :         rtl_random_getBytes( aRandomPool, pnDocId, 16 );
     276                 :            : 
     277                 :          0 :         rtl_random_destroyPool( aRandomPool );
     278                 :            : 
     279                 :            :         sal_uInt16 pnPasswd[16];
     280                 :          0 :         memset( pnPasswd, 0, sizeof( pnPasswd ) );
     281         [ #  # ]:          0 :         for (xub_StrLen nChar = 0; nChar < aPass.getLength(); ++nChar )
     282                 :          0 :             pnPasswd[nChar] = aPass.getStr()[nChar];
     283                 :            : 
     284         [ #  # ]:          0 :         ::msfilter::MSCodec_Std97 aCodec;
     285         [ #  # ]:          0 :         aCodec.InitKey( pnPasswd, pnDocId );
     286 [ #  # ][ #  # ]:          0 :         aEncryptionData = aCodec.GetEncryptionData();
         [ #  # ][ #  # ]
     287                 :            :     }
     288                 :            : 
     289                 :          0 :     return aEncryptionData;
     290                 :            : }
     291                 :            : 
     292                 :          0 : uno::Sequence< beans::NamedValue > XclExpRoot::GetEncryptionData() const
     293                 :            : {
     294                 :          0 :     uno::Sequence< beans::NamedValue > aEncryptionData;
     295 [ #  # ][ #  # ]:          0 :     SFX_ITEMSET_ARG( GetMedium().GetItemSet(), pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, false );
                 [ #  # ]
     296         [ #  # ]:          0 :     if ( pEncryptionDataItem )
     297         [ #  # ]:          0 :         pEncryptionDataItem->GetValue() >>= aEncryptionData;
     298                 :            :     else
     299                 :            :     {
     300                 :            :         // try to get the encryption data from the password
     301 [ #  # ][ #  # ]:          0 :         SFX_ITEMSET_ARG( GetMedium().GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, false );
                 [ #  # ]
     302 [ #  # ][ #  # ]:          0 :         if ( pPasswordItem && pPasswordItem->GetValue().Len() )
                 [ #  # ]
     303 [ #  # ][ #  # ]:          0 :             aEncryptionData = GenerateEncryptionData( pPasswordItem->GetValue() );
         [ #  # ][ #  # ]
     304                 :            :     }
     305                 :            : 
     306                 :          0 :     return aEncryptionData;
     307                 :            : }
     308                 :            : 
     309                 :          0 : uno::Sequence< beans::NamedValue > XclExpRoot::GenerateDefaultEncryptionData() const
     310                 :            : {
     311                 :          0 :     uno::Sequence< beans::NamedValue > aEncryptionData;
     312         [ #  # ]:          0 :     if ( GetDefaultPassword().Len() > 0 )
     313 [ #  # ][ #  # ]:          0 :         aEncryptionData = GenerateEncryptionData( GetDefaultPassword() );
         [ #  # ][ #  # ]
     314                 :            : 
     315                 :          0 :     return aEncryptionData;
     316                 :            : }
     317                 :            : 
     318                 :          0 : XclExpRootData::XclExpLinkMgrRef XclExpRoot::GetLocalLinkMgrRef() const
     319                 :            : {
     320         [ #  # ]:          0 :     return IsInGlobals() ? mrExpData.mxGlobLinkMgr : mrExpData.mxLocLinkMgr;
     321 [ +  - ][ +  - ]:         24 : }
     322                 :            : 
     323                 :            : // ============================================================================
     324                 :            : 
     325                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10