LCOV - code coverage report
Current view: top level - sc/source/filter/xml - sheetdata.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 127 70.9 %
Date: 2012-08-25 Functions: 21 25 84.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 52 138 37.7 %

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

Generated by: LCOV version 1.10