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

Generated by: LCOV version 1.11