LCOV - code coverage report
Current view: top level - sc/source/filter/xml - sheetdata.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 91 125 72.8 %
Date: 2014-11-03 Functions: 21 24 87.5 %
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         330 : ScSheetSaveData::ScSheetSaveData() :
      28             :     mnStartTab( -1 ),
      29             :     mnStartOffset( -1 ),
      30             :     maPreviousNote( OUString(), OUString(), ScAddress(ScAddress::INITIALIZE_INVALID) ),
      31         330 :     mbInSupportedSave( false )
      32             : {
      33         330 : }
      34             : 
      35         330 : ScSheetSaveData::~ScSheetSaveData()
      36             : {
      37         330 : }
      38             : 
      39        1614 : void ScSheetSaveData::AddCellStyle( const OUString& rName, const ScAddress& rCellPos )
      40             : {
      41        1614 :     maCellStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
      42        1614 : }
      43             : 
      44        2128 : void ScSheetSaveData::AddColumnStyle( const OUString& rName, const ScAddress& rCellPos )
      45             : {
      46        2128 :     maColumnStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
      47        2128 : }
      48             : 
      49         806 : void ScSheetSaveData::AddRowStyle( const OUString& rName, const ScAddress& rCellPos )
      50             : {
      51         806 :     maRowStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
      52         806 : }
      53             : 
      54         578 : void ScSheetSaveData::AddTableStyle( const OUString& rName, const ScAddress& rCellPos )
      55             : {
      56         578 :     maTableStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
      57         578 : }
      58             : 
      59          32 : 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          80 :     if ( rStyleName == maPreviousNote.maStyleName &&
      65          48 :          rTextName  == maPreviousNote.maTextStyle &&
      66          16 :          rCellPos.Tab() == maPreviousNote.maCellPos.Tab() )
      67             :     {
      68             :         // already stored for the same sheet - ignore
      69          32 :         return;
      70             :     }
      71             : 
      72          32 :     ScNoteStyleEntry aNewEntry( rStyleName, rTextName, rCellPos );
      73          32 :     maPreviousNote = aNewEntry;
      74          32 :     maNoteStyles.push_back( aNewEntry );
      75             : }
      76             : 
      77          34 : void ScSheetSaveData::AddNoteContentStyle( sal_uInt16 nFamily, const OUString& rName, const ScAddress& rCellPos, const ESelection& rSelection )
      78             : {
      79          34 :     if ( nFamily == XML_STYLE_FAMILY_TEXT_PARAGRAPH )
      80          20 :         maNoteParaStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
      81             :     else
      82          14 :         maNoteTextStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
      83          34 : }
      84             : 
      85         784 : void ScSheetSaveData::AddTextStyle( const OUString& rName, const ScAddress& rCellPos, const ESelection& rSelection )
      86             : {
      87         784 :     maTextStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
      88         784 : }
      89             : 
      90         242 : void ScSheetSaveData::BlockSheet( SCTAB nTab )
      91             : {
      92         242 :     if ( nTab >= static_cast<SCTAB>(maBlocked.size()) )
      93         104 :         maBlocked.resize( nTab + 1, false );        // fill vector with "false" entries
      94             : 
      95         242 :     maBlocked[nTab] = true;
      96         242 : }
      97             : 
      98         578 : bool ScSheetSaveData::IsSheetBlocked( SCTAB nTab ) const
      99             : {
     100         578 :     if ( nTab < static_cast<SCTAB>(maBlocked.size()) )
     101         106 :         return maBlocked[nTab];
     102             :     else
     103         472 :         return false;
     104             : }
     105             : 
     106         492 : void ScSheetSaveData::AddStreamPos( SCTAB nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset )
     107             : {
     108         492 :     if ( nTab >= static_cast<SCTAB>(maStreamEntries.size()) )
     109         492 :         maStreamEntries.resize( nTab + 1 );
     110             : 
     111         492 :     maStreamEntries[nTab] = ScStreamEntry( nStartOffset, nEndOffset );
     112         492 : }
     113             : 
     114         492 : void ScSheetSaveData::StartStreamPos( SCTAB nTab, sal_Int32 nStartOffset )
     115             : {
     116             :     OSL_ENSURE( mnStartTab < 0, "StartStreamPos without EndStreamPos" );
     117             : 
     118         492 :     mnStartTab = nTab;
     119         492 :     mnStartOffset = nStartOffset;
     120         492 : }
     121             : 
     122         492 : void ScSheetSaveData::EndStreamPos( sal_Int32 nEndOffset )
     123             : {
     124         492 :     if ( mnStartTab >= 0 )
     125             :     {
     126         492 :         AddStreamPos( mnStartTab, mnStartOffset, nEndOffset );
     127         492 :         mnStartTab = -1;
     128         492 :         mnStartOffset = -1;
     129             :     }
     130         492 : }
     131             : 
     132           2 : void ScSheetSaveData::GetStreamPos( SCTAB nTab, sal_Int32& rStartOffset, sal_Int32& rEndOffset ) const
     133             : {
     134           2 :     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           2 :         rStartOffset = rEndOffset = -1;
     142           2 : }
     143             : 
     144           2 : bool ScSheetSaveData::HasStreamPos( SCTAB nTab ) const
     145             : {
     146           2 :     sal_Int32 nStartOffset = -1;
     147           2 :     sal_Int32 nEndOffset = -1;
     148           2 :     GetStreamPos( nTab, nStartOffset, nEndOffset );
     149           2 :     return ( nStartOffset >= 0 && nEndOffset >= 0 );
     150             : }
     151             : 
     152          48 : void ScSheetSaveData::ResetSaveEntries()
     153             : {
     154          48 :     maSaveEntries.clear();
     155          48 : }
     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           2 : void ScSheetSaveData::UseSaveEntries()
     166             : {
     167           2 :     maStreamEntries = maSaveEntries;
     168           2 : }
     169             : 
     170         322 : 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         322 :     const NameSpaceHash& rNameHash = rNamespaces.GetAllEntries();
     176         322 :     NameSpaceHash::const_iterator aIter = rNameHash.begin(), aEnd = rNameHash.end();
     177       12236 :     while (aIter != aEnd)
     178             :     {
     179       11592 :         maInitialPrefixes.insert( aIter->first );
     180       11592 :         ++aIter;
     181             :     }
     182         322 : }
     183             : 
     184         322 : void ScSheetSaveData::StoreLoadedNamespaces( const SvXMLNamespaceMap& rNamespaces )
     185             : {
     186             :     // store the loaded namespaces, so the prefixes in copied stream fragments remain valid
     187             : 
     188         322 :     const NameSpaceHash& rNameHash = rNamespaces.GetAllEntries();
     189         322 :     NameSpaceHash::const_iterator aIter = rNameHash.begin(), aEnd = rNameHash.end();
     190       21954 :     while (aIter != aEnd)
     191             :     {
     192             :         // ignore the initial namespaces
     193       21310 :         if ( maInitialPrefixes.find( aIter->first ) == maInitialPrefixes.end() )
     194             :         {
     195        9718 :             const NameSpaceEntry& rEntry = *(aIter->second);
     196        9718 :             maLoadedNamespaces.push_back( ScLoadedNamespaceEntry( rEntry.sPrefix, rEntry.sName, rEntry.nKey ) );
     197             :         }
     198       21310 :         ++aIter;
     199             :     }
     200         322 : }
     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          50 : void ScSheetSaveData::SetInSupportedSave( bool bSet )
     259             : {
     260          50 :     mbInSupportedSave = bSet;
     261          50 : }
     262             : 
     263             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10