LCOV - code coverage report
Current view: top level - sc/source/filter/xml - sheetdata.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 91 127 71.7 %
Date: 2014-04-11 Functions: 21 25 84.0 %
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 <rtl/ustring.hxx>
      21             : #include <xmloff/families.hxx>
      22             : #include <xmloff/xmlaustp.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : 
      25             : #include "sheetdata.hxx"
      26             : 
      27         110 : ScSheetSaveData::ScSheetSaveData() :
      28             :     mnStartTab( -1 ),
      29             :     mnStartOffset( -1 ),
      30             :     maPreviousNote( OUString(), OUString(), ScAddress(ScAddress::INITIALIZE_INVALID) ),
      31         110 :     mbInSupportedSave( false )
      32             : {
      33         110 : }
      34             : 
      35         105 : ScSheetSaveData::~ScSheetSaveData()
      36             : {
      37         105 : }
      38             : 
      39         429 : void ScSheetSaveData::AddCellStyle( const OUString& rName, const ScAddress& rCellPos )
      40             : {
      41         429 :     maCellStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
      42         429 : }
      43             : 
      44         296 : void ScSheetSaveData::AddColumnStyle( const OUString& rName, const ScAddress& rCellPos )
      45             : {
      46         296 :     maColumnStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
      47         296 : }
      48             : 
      49         320 : void ScSheetSaveData::AddRowStyle( const OUString& rName, const ScAddress& rCellPos )
      50             : {
      51         320 :     maRowStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
      52         320 : }
      53             : 
      54         221 : void ScSheetSaveData::AddTableStyle( const OUString& rName, const ScAddress& rCellPos )
      55             : {
      56         221 :     maTableStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
      57         221 : }
      58             : 
      59          15 : void ScSheetSaveData::HandleNoteStyles( const OUString& rStyleName, const OUString& rTextName, const ScAddress& rCellPos )
      60             : {
      61             :     // only consecutive duplicates (most common case) are filtered out here,
      62             :     // the others are found when the styles are created
      63             : 
      64          37 :     if ( rStyleName == maPreviousNote.maStyleName &&
      65          22 :          rTextName  == maPreviousNote.maTextStyle &&
      66           7 :          rCellPos.Tab() == maPreviousNote.maCellPos.Tab() )
      67             :     {
      68             :         // already stored for the same sheet - ignore
      69          15 :         return;
      70             :     }
      71             : 
      72          15 :     ScNoteStyleEntry aNewEntry( rStyleName, rTextName, rCellPos );
      73          15 :     maPreviousNote = aNewEntry;
      74          15 :     maNoteStyles.push_back( aNewEntry );
      75             : }
      76             : 
      77          15 : void ScSheetSaveData::AddNoteContentStyle( sal_uInt16 nFamily, const OUString& rName, const ScAddress& rCellPos, const ESelection& rSelection )
      78             : {
      79          15 :     if ( nFamily == XML_STYLE_FAMILY_TEXT_PARAGRAPH )
      80           9 :         maNoteParaStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
      81             :     else
      82           6 :         maNoteTextStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
      83          15 : }
      84             : 
      85          32 : void ScSheetSaveData::AddTextStyle( const OUString& rName, const ScAddress& rCellPos, const ESelection& rSelection )
      86             : {
      87          32 :     maTextStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
      88          32 : }
      89             : 
      90         108 : void ScSheetSaveData::BlockSheet( SCTAB nTab )
      91             : {
      92         108 :     if ( nTab >= static_cast<SCTAB>(maBlocked.size()) )
      93          44 :         maBlocked.resize( nTab + 1, false );        // fill vector with "false" entries
      94             : 
      95         108 :     maBlocked[nTab] = true;
      96         108 : }
      97             : 
      98         221 : bool ScSheetSaveData::IsSheetBlocked( SCTAB nTab ) const
      99             : {
     100         221 :     if ( nTab < static_cast<SCTAB>(maBlocked.size()) )
     101          45 :         return maBlocked[nTab];
     102             :     else
     103         176 :         return false;
     104             : }
     105             : 
     106         206 : void ScSheetSaveData::AddStreamPos( SCTAB nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset )
     107             : {
     108         206 :     if ( nTab >= static_cast<SCTAB>(maStreamEntries.size()) )
     109         206 :         maStreamEntries.resize( nTab + 1 );
     110             : 
     111         206 :     maStreamEntries[nTab] = ScStreamEntry( nStartOffset, nEndOffset );
     112         206 : }
     113             : 
     114         206 : void ScSheetSaveData::StartStreamPos( SCTAB nTab, sal_Int32 nStartOffset )
     115             : {
     116             :     OSL_ENSURE( mnStartTab < 0, "StartStreamPos without EndStreamPos" );
     117             : 
     118         206 :     mnStartTab = nTab;
     119         206 :     mnStartOffset = nStartOffset;
     120         206 : }
     121             : 
     122         206 : void ScSheetSaveData::EndStreamPos( sal_Int32 nEndOffset )
     123             : {
     124         206 :     if ( mnStartTab >= 0 )
     125             :     {
     126         206 :         AddStreamPos( mnStartTab, mnStartOffset, nEndOffset );
     127         206 :         mnStartTab = -1;
     128         206 :         mnStartOffset = -1;
     129             :     }
     130         206 : }
     131             : 
     132           1 : void ScSheetSaveData::GetStreamPos( SCTAB nTab, sal_Int32& rStartOffset, sal_Int32& rEndOffset ) const
     133             : {
     134           1 :     if ( nTab < static_cast<SCTAB>(maStreamEntries.size()) )
     135             :     {
     136           0 :         const ScStreamEntry& rEntry = maStreamEntries[nTab];
     137           0 :         rStartOffset = rEntry.mnStartOffset;
     138           0 :         rEndOffset = rEntry.mnEndOffset;
     139             :     }
     140             :     else
     141           1 :         rStartOffset = rEndOffset = -1;
     142           1 : }
     143             : 
     144           1 : bool ScSheetSaveData::HasStreamPos( SCTAB nTab ) const
     145             : {
     146           1 :     sal_Int32 nStartOffset = -1;
     147           1 :     sal_Int32 nEndOffset = -1;
     148           1 :     GetStreamPos( nTab, nStartOffset, nEndOffset );
     149           1 :     return ( nStartOffset >= 0 && nEndOffset >= 0 );
     150             : }
     151             : 
     152          18 : void ScSheetSaveData::ResetSaveEntries()
     153             : {
     154          18 :     maSaveEntries.clear();
     155          18 : }
     156             : 
     157           0 : void ScSheetSaveData::AddSavePos( SCTAB nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset )
     158             : {
     159           0 :     if ( nTab >= static_cast<SCTAB>(maSaveEntries.size()) )
     160           0 :         maSaveEntries.resize( nTab + 1 );
     161             : 
     162           0 :     maSaveEntries[nTab] = ScStreamEntry( nStartOffset, nEndOffset );
     163           0 : }
     164             : 
     165           1 : void ScSheetSaveData::UseSaveEntries()
     166             : {
     167           1 :     maStreamEntries = maSaveEntries;
     168           1 : }
     169             : 
     170         107 : void ScSheetSaveData::StoreInitialNamespaces( const SvXMLNamespaceMap& rNamespaces )
     171             : {
     172             :     // the initial namespaces are just removed from the list of loaded namespaces,
     173             :     // so only a boost::unordered_map of the prefixes is needed.
     174             : 
     175         107 :     const NameSpaceHash& rNameHash = rNamespaces.GetAllEntries();
     176         107 :     NameSpaceHash::const_iterator aIter = rNameHash.begin(), aEnd = rNameHash.end();
     177        4066 :     while (aIter != aEnd)
     178             :     {
     179        3852 :         maInitialPrefixes.insert( aIter->first );
     180        3852 :         ++aIter;
     181             :     }
     182         107 : }
     183             : 
     184         107 : void ScSheetSaveData::StoreLoadedNamespaces( const SvXMLNamespaceMap& rNamespaces )
     185             : {
     186             :     // store the loaded namespaces, so the prefixes in copied stream fragments remain valid
     187             : 
     188         107 :     const NameSpaceHash& rNameHash = rNamespaces.GetAllEntries();
     189         107 :     NameSpaceHash::const_iterator aIter = rNameHash.begin(), aEnd = rNameHash.end();
     190        7502 :     while (aIter != aEnd)
     191             :     {
     192             :         // ignore the initial namespaces
     193        7288 :         if ( maInitialPrefixes.find( aIter->first ) == maInitialPrefixes.end() )
     194             :         {
     195        3436 :             const NameSpaceEntry& rEntry = *(aIter->second);
     196        3436 :             maLoadedNamespaces.push_back( ScLoadedNamespaceEntry( rEntry.sPrefix, rEntry.sName, rEntry.nKey ) );
     197             :         }
     198        7288 :         ++aIter;
     199             :     }
     200         107 : }
     201             : 
     202           0 : static bool lcl_NameInHash( const NameSpaceHash& rNameHash, const OUString& rName )
     203             : {
     204           0 :     NameSpaceHash::const_iterator aIter = rNameHash.begin(), aEnd = rNameHash.end();
     205           0 :     while (aIter != aEnd)
     206             :     {
     207           0 :         if ( aIter->second->sName == rName )
     208           0 :             return true;
     209             : 
     210           0 :         ++aIter;
     211             :     }
     212           0 :     return false;   // not found
     213             : }
     214             : 
     215           0 : bool ScSheetSaveData::AddLoadedNamespaces( SvXMLNamespaceMap& rNamespaces ) const
     216             : {
     217             :     // Add the loaded namespaces to the name space map.
     218             : 
     219             :     // first loop: only look for conflicts
     220             :     // (if the loaded namespaces were added first, this might not be necessary)
     221           0 :     const NameSpaceHash& rNameHash = rNamespaces.GetAllEntries();
     222           0 :     std::vector<ScLoadedNamespaceEntry>::const_iterator aIter = maLoadedNamespaces.begin();
     223           0 :     std::vector<ScLoadedNamespaceEntry>::const_iterator aEnd = maLoadedNamespaces.end();
     224           0 :     while (aIter != aEnd)
     225             :     {
     226           0 :         NameSpaceHash::const_iterator aHashIter = rNameHash.find( aIter->maPrefix );
     227           0 :         if ( aHashIter == rNameHash.end() )
     228             :         {
     229           0 :             if ( lcl_NameInHash( rNameHash, aIter->maName ) )
     230             :             {
     231             :                 // a second prefix for the same name would confuse SvXMLNamespaceMap lookup,
     232             :                 // so this is also considered a conflict
     233           0 :                 return false;
     234             :             }
     235             :         }
     236           0 :         else if ( aHashIter->second->sName != aIter->maName )
     237             :         {
     238             :             // same prefix, but different name: loaded namespaces can't be used
     239           0 :             return false;
     240             :         }
     241           0 :         ++aIter;
     242             :     }
     243             : 
     244             :     // only if there were no conflicts, add the entries that aren't in the map already
     245             :     // (the key is needed if the same namespace is added later within an element)
     246           0 :     aIter = maLoadedNamespaces.begin();
     247           0 :     while (aIter != aEnd)
     248             :     {
     249           0 :         NameSpaceHash::const_iterator aHashIter = rNameHash.find( aIter->maPrefix );
     250           0 :         if ( aHashIter == rNameHash.end() )
     251           0 :             rNamespaces.Add( aIter->maPrefix, aIter->maName, aIter->mnKey );
     252           0 :         ++aIter;
     253             :     }
     254             : 
     255           0 :     return true;    // success
     256             : }
     257             : 
     258           0 : bool ScSheetSaveData::IsInSupportedSave() const
     259             : {
     260           0 :     return mbInSupportedSave;
     261             : }
     262             : 
     263          17 : void ScSheetSaveData::SetInSupportedSave( bool bSet )
     264             : {
     265          17 :     mbInSupportedSave = bSet;
     266          17 : }
     267             : 
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10