LCOV - code coverage report
Current view: top level - xmloff/source/style - xmlexppr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 354 426 83.1 %
Date: 2012-08-25 Functions: 31 32 96.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 350 664 52.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 <com/sun/star/container/XNameContainer.hpp>
      30                 :            : #include <com/sun/star/xml/AttributeData.hpp>
      31                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      32                 :            : #include <com/sun/star/beans/XPropertyState.hpp>
      33                 :            : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      34                 :            : #include <com/sun/star/beans/XTolerantMultiPropertySet.hpp>
      35                 :            : #include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
      36                 :            : #include <rtl/ustrbuf.hxx>
      37                 :            : #include <list>
      38                 :            : #include <boost/unordered_map.hpp>
      39                 :            : 
      40                 :            : #include <xmloff/xmlexppr.hxx>
      41                 :            : #include <xmloff/xmltoken.hxx>
      42                 :            : #include <xmloff/attrlist.hxx>
      43                 :            : #include <xmloff/nmspmap.hxx>
      44                 :            : #include "xmloff/xmlnmspe.hxx"
      45                 :            : #include <xmloff/xmlexp.hxx>
      46                 :            : #include <xmloff/xmlprmap.hxx>
      47                 :            : #include <xmloff/PropertySetInfoHash.hxx>
      48                 :            : #include <comphelper/stl_types.hxx>
      49                 :            : 
      50                 :            : using ::rtl::OUString;
      51                 :            : using ::rtl::OUStringBuffer;
      52                 :            : 
      53                 :            : using namespace ::std;
      54                 :            : using namespace ::com::sun::star;
      55                 :            : using namespace ::com::sun::star::beans;
      56                 :            : using namespace ::com::sun::star::uno;
      57                 :            : using namespace ::com::sun::star::lang;
      58                 :            : using namespace ::xmloff::token;
      59                 :            : 
      60                 :            : #define GET_PROP_TYPE( f ) static_cast<sal_uInt16>((f & XML_TYPE_PROP_MASK) >> XML_TYPE_PROP_SHIFT)
      61                 :            : 
      62                 :            : struct XMLPropTokens_Impl
      63                 :            : {
      64                 :            :     sal_uInt16 nType;
      65                 :            :     XMLTokenEnum eToken;
      66                 :            : };
      67                 :            : 
      68                 :            : #define ENTRY(t) { GET_PROP_TYPE(XML_TYPE_PROP_##t), XML_##t##_PROPERTIES }
      69                 :            : const sal_uInt16 MAX_PROP_TYPES =
      70                 :            :     (XML_TYPE_PROP_END >> XML_TYPE_PROP_SHIFT) -
      71                 :            :     (XML_TYPE_PROP_START >> XML_TYPE_PROP_SHIFT);
      72                 :            : 
      73                 :            : static  XMLPropTokens_Impl aPropTokens[MAX_PROP_TYPES] =
      74                 :            : {
      75                 :            :     ENTRY(CHART),
      76                 :            :     ENTRY(GRAPHIC),
      77                 :            :     ENTRY(TABLE),
      78                 :            :     ENTRY(TABLE_COLUMN),
      79                 :            :     ENTRY(TABLE_ROW),
      80                 :            :     ENTRY(TABLE_CELL),
      81                 :            :     ENTRY(LIST_LEVEL),
      82                 :            :     ENTRY(PARAGRAPH),
      83                 :            :     ENTRY(TEXT),
      84                 :            :     ENTRY(DRAWING_PAGE),
      85                 :            :     ENTRY(PAGE_LAYOUT),
      86                 :            :     ENTRY(HEADER_FOOTER),
      87                 :            :     ENTRY(RUBY),
      88                 :            :     ENTRY(SECTION)
      89                 :            : };
      90                 :            : 
      91                 :            : ///////////////////////////////////////////////////////////////////////////////
      92                 :            : //
      93                 :            : // public methods
      94                 :            : //
      95                 :            : 
      96                 :            : ///////////////////////////////////////////////////////////////////////////
      97                 :            : //
      98                 :            : // Take all properties of the XPropertySet which are also found in the
      99                 :            : // XMLPropertyMapEntry-array and which are not set to their default-value,
     100                 :            : // if a state is available.
     101                 :            : //
     102                 :            : // After that I call the method 'ContextFilter'.
     103                 :            : //
     104                 :            : 
     105                 :            : typedef std::list<XMLPropertyState> XMLPropertyStateList_Impl;
     106                 :            : 
     107                 :       5493 : class XMLPropertyStates_Impl
     108                 :            : {
     109                 :            :     XMLPropertyStateList_Impl           aPropStates;
     110                 :            :     XMLPropertyStateList_Impl::iterator aLastItr;
     111                 :            :     sal_uInt32                          nCount;
     112                 :            : public:
     113                 :            :     XMLPropertyStates_Impl();
     114                 :            :     void AddPropertyState(const XMLPropertyState& rPropState);
     115                 :            :     void FillPropertyStateVector(std::vector<XMLPropertyState>& rVector);
     116                 :            : };
     117                 :            : 
     118                 :       5493 : XMLPropertyStates_Impl::XMLPropertyStates_Impl() :
     119                 :            :     aPropStates(),
     120                 :       5493 :     nCount(0)
     121                 :            : {
     122                 :       5493 :     aLastItr = aPropStates.begin();
     123                 :       5493 : }
     124                 :            : 
     125                 :      11452 : void XMLPropertyStates_Impl::AddPropertyState(
     126                 :            :         const XMLPropertyState& rPropState)
     127                 :            : {
     128                 :      11452 :     XMLPropertyStateList_Impl::iterator aItr = aPropStates.begin();
     129                 :      11452 :     sal_Bool bInserted(sal_False);
     130         [ +  + ]:      11452 :     if (nCount)
     131                 :            :     {
     132         [ +  + ]:      10288 :         if (aLastItr->mnIndex < rPropState.mnIndex)
     133                 :       6653 :             aItr = ++aLastItr;
     134                 :            :     }
     135   [ +  +  +  - ]:     104162 :     do
                 [ +  + ]
     136                 :            :     {
     137                 :            :         // TODO: one path required only
     138         [ +  + ]:      38538 :         if (aItr == aPropStates.end())
     139                 :            :         {
     140         [ +  - ]:       3645 :             aLastItr = aPropStates.insert(aPropStates.end(), rPropState);
     141                 :       3645 :             bInserted = sal_True;
     142                 :       3645 :             nCount++;
     143                 :            :         }
     144         [ +  + ]:      34893 :         else if (aItr->mnIndex > rPropState.mnIndex)
     145                 :            :         {
     146         [ +  - ]:       7807 :             aLastItr = aPropStates.insert(aItr, rPropState);
     147                 :       7807 :             bInserted = sal_True;
     148                 :       7807 :             nCount++;
     149                 :            :         }
     150                 :            :     }
     151 [ +  + ][ +  + ]:      65624 :     while(!bInserted && (aItr++ != aPropStates.end()));
     152                 :      11452 : }
     153                 :            : 
     154                 :       5493 : void XMLPropertyStates_Impl::FillPropertyStateVector(
     155                 :            :         std::vector<XMLPropertyState>& rVector)
     156                 :            : {
     157         [ +  + ]:       5493 :     if (nCount)
     158                 :            :     {
     159         [ +  - ]:       1164 :         rVector.resize(nCount, XMLPropertyState(-1));
     160                 :       1164 :         ::std::copy( aPropStates.begin(), aPropStates.end(), rVector.begin() );
     161                 :            :     }
     162                 :       5493 : }
     163                 :            : 
     164         [ +  - ]:     120726 : class FilterPropertyInfo_Impl
     165                 :            : {
     166                 :            :     const rtl::OUString     sApiName;
     167                 :            :     std::list<sal_uInt32>   aIndexes;
     168                 :            :     sal_uInt32              nCount;
     169                 :            : 
     170                 :            : public:
     171                 :            : 
     172                 :            :     FilterPropertyInfo_Impl( const rtl::OUString& rApiName,
     173                 :            :                              const sal_uInt32 nIndex);
     174                 :            : 
     175                 :     554997 :     const OUString& GetApiName() const { return sApiName; }
     176                 :      52544 :     std::list<sal_uInt32>& GetIndexes() { return aIndexes; }
     177                 :            : 
     178                 :            :     void AddIndex( sal_uInt32 nIndex )
     179                 :            :     {
     180                 :            :         aIndexes.push_back(nIndex);
     181                 :            :         nCount++;
     182                 :            :     }
     183                 :            : 
     184                 :            :     // for sort
     185                 :     213861 :     sal_Bool operator< ( const FilterPropertyInfo_Impl& rArg ) const
     186                 :            :     {
     187                 :     213861 :         return (GetApiName() < rArg.GetApiName());
     188                 :            :     }
     189                 :            : };
     190                 :            : 
     191                 :      40268 : FilterPropertyInfo_Impl::FilterPropertyInfo_Impl(
     192                 :            :         const rtl::OUString& rApiName,
     193                 :            :         const sal_uInt32 nIndex ) :
     194                 :            :     sApiName( rApiName ),
     195                 :            :     aIndexes(),
     196         [ +  - ]:      40268 :     nCount(1)
     197                 :            : {
     198         [ +  - ]:      40268 :     aIndexes.push_back(nIndex);
     199                 :      40268 : }
     200                 :            : 
     201                 :            : typedef std::list<FilterPropertyInfo_Impl> FilterPropertyInfoList_Impl;
     202                 :            : 
     203                 :            : // ----------------------------------------------------------------------------
     204                 :            : 
     205                 :            : class FilterPropertiesInfo_Impl
     206                 :            : {
     207                 :            :     sal_uInt32                              nCount;
     208                 :            :     FilterPropertyInfoList_Impl             aPropInfos;
     209                 :            :     FilterPropertyInfoList_Impl::iterator   aLastItr;
     210                 :            : 
     211                 :            :     Sequence <OUString>                     *pApiNames;
     212                 :            : 
     213                 :            : public:
     214                 :            :     FilterPropertiesInfo_Impl();
     215                 :            :     ~FilterPropertiesInfo_Impl();
     216                 :            : 
     217                 :            :     void AddProperty(const rtl::OUString& rApiName, const sal_uInt32 nIndex);
     218                 :            :     const uno::Sequence<OUString>& GetApiNames();
     219                 :            :     void FillPropertyStateArray(
     220                 :            :             vector< XMLPropertyState >& rPropStates,
     221                 :            :             const Reference< XPropertySet >& xPropSet,
     222                 :            :             const UniReference< XMLPropertySetMapper >& maPropMapper,
     223                 :            :             const sal_Bool bDefault = sal_False);
     224                 :       5517 :     sal_uInt32 GetPropertyCount() const { return nCount; }
     225                 :            : };
     226                 :            : 
     227                 :            : // ----------------------------------------------------------------------------
     228                 :            : 
     229                 :            : typedef boost::unordered_map
     230                 :            : <
     231                 :            :     Reference< XPropertySetInfo >,
     232                 :            :     FilterPropertiesInfo_Impl *,
     233                 :            :     PropertySetInfoHash,
     234                 :            :     PropertySetInfoHash
     235                 :            : >
     236                 :            : FilterOropertiesHashMap_Impl;
     237                 :            : 
     238         [ +  - ]:        247 : class FilterPropertiesInfos_Impl : public FilterOropertiesHashMap_Impl
     239                 :            : {
     240                 :            : public:
     241                 :            :     ~FilterPropertiesInfos_Impl ();
     242                 :            : };
     243                 :            : 
     244                 :        245 : FilterPropertiesInfos_Impl::~FilterPropertiesInfos_Impl ()
     245                 :            : {
     246         [ +  - ]:        245 :     FilterOropertiesHashMap_Impl::iterator aIter = begin();
     247         [ +  - ]:        245 :     FilterOropertiesHashMap_Impl::iterator aEnd = end();
     248         [ +  + ]:        729 :     while( aIter != aEnd )
     249                 :            :     {
     250 [ +  - ][ +  - ]:        484 :         delete (*aIter).second;
                 [ +  - ]
     251         [ +  - ]:        484 :         (*aIter).second = 0;
     252                 :        484 :         ++aIter;
     253                 :            :     }
     254                 :        245 : }
     255                 :            : 
     256                 :            : // ----------------------------------------------------------------------------
     257                 :            : 
     258                 :        490 : FilterPropertiesInfo_Impl::FilterPropertiesInfo_Impl() :
     259                 :            :     nCount(0),
     260                 :            :     aPropInfos(),
     261                 :        490 :     pApiNames( 0 )
     262                 :            : {
     263                 :        490 :     aLastItr = aPropInfos.begin();
     264                 :        490 : }
     265                 :            : 
     266                 :        484 : FilterPropertiesInfo_Impl::~FilterPropertiesInfo_Impl()
     267                 :            : {
     268 [ +  + ][ +  - ]:        484 :     delete pApiNames;
     269                 :        484 : }
     270                 :            : 
     271                 :      40268 : void FilterPropertiesInfo_Impl::AddProperty(
     272                 :            :         const rtl::OUString& rApiName, const sal_uInt32 nIndex)
     273                 :            : {
     274         [ +  - ]:      40268 :     aPropInfos.push_back(FilterPropertyInfo_Impl(rApiName, nIndex));
     275                 :      40268 :     nCount++;
     276                 :            : 
     277                 :            :     OSL_ENSURE( !pApiNames, "perfomance warning: API names already retrieved" );
     278         [ -  + ]:      40268 :     if( pApiNames )
     279                 :            :     {
     280         [ #  # ]:          0 :         delete pApiNames;
     281                 :          0 :         pApiNames = NULL;
     282                 :            :     }
     283                 :      40268 : }
     284                 :       5493 : const uno::Sequence<OUString>& FilterPropertiesInfo_Impl::GetApiNames()
     285                 :            : {
     286                 :            :     OSL_ENSURE(nCount == aPropInfos.size(), "wrong property count");
     287         [ +  + ]:       5493 :     if( !pApiNames )
     288                 :            :     {
     289                 :            :         // we have to do three things:
     290                 :            :         // 1) sort API names,
     291                 :            :         // 2) merge duplicates,
     292                 :            :         // 3) construct sequence
     293                 :            : 
     294                 :            :         // sort names
     295         [ +  - ]:        486 :         aPropInfos.sort();
     296                 :            : 
     297                 :            :         // merge duplicates
     298         [ +  + ]:        486 :         if ( nCount > 1 )
     299                 :            :         {
     300                 :        438 :             FilterPropertyInfoList_Impl::iterator aOld = aPropInfos.begin();
     301                 :        438 :             FilterPropertyInfoList_Impl::iterator aEnd = aPropInfos.end();
     302                 :        438 :             FilterPropertyInfoList_Impl::iterator aCurrent = aOld;
     303                 :        438 :             ++aCurrent;
     304                 :            : 
     305         [ +  + ]:      40220 :             while ( aCurrent != aEnd )
     306                 :            :             {
     307                 :            :                 // equal to next element?
     308         [ +  + ]:      39782 :                 if ( aOld->GetApiName().equals( aCurrent->GetApiName() ) )
     309                 :            :                 {
     310                 :            :                     // if equal: merge index lists
     311         [ +  - ]:       7568 :                     aOld->GetIndexes().merge( aCurrent->GetIndexes() );
     312                 :            :                     // erase element, and continue with next
     313         [ +  - ]:       7568 :                     aCurrent = aPropInfos.erase( aCurrent );
     314                 :       7568 :                     nCount--;
     315                 :            :                 }
     316                 :            :                 else
     317                 :            :                 {
     318                 :            :                     // remember old element and continue with next
     319                 :      32214 :                     aOld = aCurrent;
     320                 :      32214 :                     ++aCurrent;
     321                 :            :                 }
     322                 :            :             }
     323                 :            :         }
     324                 :            : 
     325                 :            :         // construct sequence
     326         [ +  - ]:        486 :         pApiNames = new Sequence < OUString >( nCount );
     327         [ +  - ]:        486 :         OUString *pNames = pApiNames->getArray();
     328                 :        486 :         FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
     329                 :        486 :         FilterPropertyInfoList_Impl::iterator aEnd = aPropInfos.end();
     330         [ +  + ]:      33186 :         for ( ; aItr != aEnd; ++aItr, ++pNames)
     331                 :      32700 :             *pNames = aItr->GetApiName();
     332                 :            :     }
     333                 :            : 
     334                 :       5493 :     return *pApiNames;
     335                 :            : }
     336                 :            : 
     337                 :       5493 : void FilterPropertiesInfo_Impl::FillPropertyStateArray(
     338                 :            :         vector< XMLPropertyState >& rPropStates,
     339                 :            :         const Reference< XPropertySet >& rPropSet,
     340                 :            :         const UniReference< XMLPropertySetMapper >& rPropMapper,
     341                 :            :         const sal_Bool bDefault )
     342                 :            : {
     343         [ +  - ]:       5493 :     XMLPropertyStates_Impl aPropStates;
     344                 :            : 
     345         [ +  - ]:       5493 :     const uno::Sequence<OUString>& rApiNames = GetApiNames();
     346                 :            : 
     347         [ +  - ]:       5493 :     Reference < XTolerantMultiPropertySet > xTolPropSet( rPropSet, UNO_QUERY );
     348         [ +  + ]:       5493 :     if (xTolPropSet.is())
     349                 :            :     {
     350         [ +  - ]:       4008 :         if (!bDefault)
     351                 :            :         {
     352 [ +  - ][ +  - ]:       4008 :             Sequence < beans::GetDirectPropertyTolerantResult > aResults(xTolPropSet->getDirectPropertyValuesTolerant(rApiNames));
     353                 :       4008 :             sal_Int32 nResultCount(aResults.getLength());
     354         [ +  + ]:       4008 :             if (nResultCount > 0)
     355                 :            :             {
     356                 :        101 :                 const beans::GetDirectPropertyTolerantResult *pResults = aResults.getConstArray();
     357                 :        101 :                 FilterPropertyInfoList_Impl::iterator aPropIter(aPropInfos.begin());
     358                 :        101 :                 XMLPropertyState aNewProperty( -1 );
     359                 :        101 :                 sal_uInt32 i = 0;
     360 [ +  + ][ +  - ]:       5073 :                 while (nResultCount > 0 && i < nCount)
                 [ +  + ]
     361                 :            :                 {
     362         [ +  + ]:       4972 :                     if (pResults->Name == aPropIter->GetApiName())
     363                 :            :                     {
     364                 :        144 :                         aNewProperty.mnIndex = -1;
     365                 :        144 :                         aNewProperty.maValue = pResults->Value;
     366                 :            : 
     367   [ +  -  +  - ]:        576 :                         for( std::list<sal_uInt32>::iterator aIndexItr(aPropIter->GetIndexes().begin());
                 [ +  + ]
     368                 :        288 :                             aIndexItr != aPropIter->GetIndexes().end();
     369                 :            :                             ++aIndexItr )
     370                 :            :                         {
     371         [ +  - ]:        144 :                             aNewProperty.mnIndex = *aIndexItr;
     372         [ +  - ]:        144 :                             aPropStates.AddPropertyState( aNewProperty );
     373                 :            :                         }
     374                 :        144 :                         ++pResults;
     375                 :        144 :                         --nResultCount;
     376                 :            :                     }
     377                 :       4972 :                     ++aPropIter;
     378                 :       4972 :                     ++i;
     379                 :        101 :                 }
     380         [ +  - ]:       4008 :             }
     381                 :            :         }
     382                 :            :         else
     383                 :            :         {
     384 [ #  # ][ #  # ]:          0 :             Sequence < beans::GetPropertyTolerantResult > aResults(xTolPropSet->getPropertyValuesTolerant(rApiNames));
     385                 :            :             OSL_ENSURE( rApiNames.getLength() == aResults.getLength(), "wrong implemented XTolerantMultiPropertySet" );
     386                 :          0 :             const beans::GetPropertyTolerantResult *pResults = aResults.getConstArray();
     387                 :          0 :             FilterPropertyInfoList_Impl::iterator aPropIter(aPropInfos.begin());
     388                 :          0 :             XMLPropertyState aNewProperty( -1 );
     389                 :          0 :             sal_uInt32 nResultCount(aResults.getLength());
     390                 :            :             OSL_ENSURE( nCount == nResultCount, "wrong implemented XTolerantMultiPropertySet??" );
     391         [ #  # ]:          0 :             for( sal_uInt32 i = 0; i < nResultCount; ++i )
     392                 :            :             {
     393 [ #  # ][ #  # ]:          0 :                 if ((pResults->Result == beans::TolerantPropertySetResultType::SUCCESS) &&
                 [ #  # ]
     394                 :            :                     ((pResults->State == PropertyState_DIRECT_VALUE) || (pResults->State == PropertyState_DEFAULT_VALUE)))
     395                 :            :                 {
     396                 :          0 :                     aNewProperty.mnIndex = -1;
     397                 :          0 :                     aNewProperty.maValue = pResults->Value;
     398                 :            : 
     399   [ #  #  #  # ]:          0 :                     for( std::list<sal_uInt32>::iterator aIndexItr(aPropIter->GetIndexes().begin());
                 [ #  # ]
     400                 :          0 :                         aIndexItr != aPropIter->GetIndexes().end();
     401                 :            :                         ++aIndexItr )
     402                 :            :                     {
     403         [ #  # ]:          0 :                         aNewProperty.mnIndex = *aIndexItr;
     404         [ #  # ]:          0 :                         aPropStates.AddPropertyState( aNewProperty );
     405                 :            :                     }
     406                 :            :                 }
     407                 :          0 :                 ++pResults;
     408                 :          0 :                 ++aPropIter;
     409         [ #  # ]:          0 :             }
     410                 :            :         }
     411                 :            :     }
     412                 :            :     else
     413                 :            :     {
     414         [ +  - ]:       1485 :         Sequence < PropertyState > aStates;
     415                 :       1485 :         const PropertyState *pStates = 0;
     416         [ +  - ]:       1485 :         Reference< XPropertyState > xPropState( rPropSet, UNO_QUERY );
     417         [ +  + ]:       1485 :            if( xPropState.is() )
     418                 :            :         {
     419 [ +  - ][ +  - ]:       1461 :             aStates = xPropState->getPropertyStates( rApiNames );
         [ +  - ][ +  - ]
     420                 :       1461 :             pStates = aStates.getConstArray();
     421                 :            :         }
     422                 :            : 
     423         [ +  - ]:       1485 :         Reference < XMultiPropertySet > xMultiPropSet( rPropSet, UNO_QUERY );
     424 [ +  + ][ +  + ]:       1485 :         if( xMultiPropSet.is() && !bDefault )
                 [ +  + ]
     425                 :            :         {
     426         [ +  - ]:       1070 :             Sequence < Any > aValues;
     427         [ +  + ]:       1070 :             if( pStates )
     428                 :            :             {
     429                 :            :                 // step 1: get value count
     430                 :       1046 :                 sal_uInt32 nValueCount = 0;
     431                 :            :                 sal_uInt32 i;
     432                 :            : 
     433         [ +  + ]:      68597 :                 for( i = 0; i < nCount; ++i, ++pStates )
     434                 :            :                 {
     435         [ +  + ]:      67551 :                     if( (*pStates == PropertyState_DIRECT_VALUE)/* || (bDefault && (*pStates == PropertyState_DEFAULT_VALUE))*/ )
     436                 :       5385 :                         nValueCount++;
     437                 :            :                 }
     438                 :            : 
     439         [ +  + ]:       1046 :                 if( nValueCount )
     440                 :            :                 {
     441                 :            :                     // step 2: collect property names
     442         [ +  - ]:        670 :                     Sequence < OUString > aAPINames( nValueCount );
     443         [ +  - ]:        670 :                     OUString *pAPINames = aAPINames.getArray();
     444                 :            : 
     445         [ +  - ]:        670 :                     ::std::vector< FilterPropertyInfoList_Impl::iterator > aPropIters;
     446         [ +  - ]:        670 :                     aPropIters.reserve( nValueCount );
     447                 :            : 
     448                 :        670 :                     FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
     449                 :            :                     OSL_ENSURE(aItr != aPropInfos.end(),"Invalid iterator!");
     450                 :            : 
     451                 :        670 :                     pStates = aStates.getConstArray();
     452                 :        670 :                     i = 0;
     453         [ +  + ]:      40355 :                     while( i < nValueCount )
     454                 :            :                     {
     455         [ +  + ]:      39685 :                         if( (*pStates == PropertyState_DIRECT_VALUE)/* || (bDefault && (*pStates == PropertyState_DEFAULT_VALUE))*/ )
     456                 :            :                         {
     457                 :       5385 :                             *pAPINames++ = aItr->GetApiName();
     458         [ +  - ]:       5385 :                             aPropIters.push_back( aItr );
     459                 :       5385 :                             ++i;
     460                 :            :                         }
     461                 :      39685 :                         ++aItr;
     462                 :      39685 :                         ++pStates;
     463                 :            :                     }
     464                 :            : 
     465 [ +  - ][ +  - ]:        670 :                     aValues = xMultiPropSet->getPropertyValues( aAPINames );
         [ +  - ][ +  - ]
     466                 :        670 :                     const Any *pValues = aValues.getConstArray();
     467                 :            : 
     468                 :            :                     ::std::vector< FilterPropertyInfoList_Impl::iterator >::const_iterator
     469         [ +  - ]:        670 :                         pPropIter = aPropIters.begin();
     470                 :            : 
     471                 :        670 :                     XMLPropertyState aNewProperty( -1 );
     472         [ +  + ]:       6055 :                     for( i = 0; i < nValueCount; ++i )
     473                 :            :                     {
     474                 :       5385 :                         aNewProperty.mnIndex = -1;
     475                 :       5385 :                         aNewProperty.maValue = *pValues;
     476                 :            : 
     477                 :       5385 :                         const ::std::list< sal_uInt32 >& rIndexes( (*pPropIter)->GetIndexes() );
     478   [ +  -  +  - ]:      22218 :                         for (   std::list<sal_uInt32>::const_iterator aIndexItr = rIndexes.begin();
                 [ +  + ]
     479                 :      11109 :                                 aIndexItr != rIndexes.end();
     480                 :            :                                 ++aIndexItr
     481                 :            :                             )
     482                 :            :                         {
     483         [ +  - ]:       5724 :                             aNewProperty.mnIndex = *aIndexItr;
     484         [ +  - ]:       5724 :                             aPropStates.AddPropertyState( aNewProperty );
     485                 :            :                         }
     486                 :            : 
     487                 :       5385 :                         ++pPropIter;
     488                 :       5385 :                         ++pValues;
     489         [ +  - ]:        670 :                     }
     490                 :            :                 }
     491                 :            :             }
     492                 :            :             else
     493                 :            :             {
     494 [ +  - ][ +  - ]:         24 :                 aValues = xMultiPropSet->getPropertyValues( rApiNames );
         [ +  - ][ +  - ]
     495                 :         24 :                 const Any *pValues = aValues.getConstArray();
     496                 :            : 
     497                 :         24 :                 FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
     498         [ +  + ]:        140 :                 for(sal_uInt32 i = 0; i < nCount; ++i)
     499                 :            :                 {
     500                 :            :                     // The value is stored in the PropertySet itself, add to list.
     501                 :        116 :                     XMLPropertyState aNewProperty( -1 );
     502                 :        116 :                     aNewProperty.maValue = *pValues;
     503                 :        116 :                     ++pValues;
     504   [ +  -  +  - ]:        464 :                     for( std::list<sal_uInt32>::iterator aIndexItr =
                 [ +  + ]
     505                 :        116 :                             aItr->GetIndexes().begin();
     506                 :        232 :                         aIndexItr != aItr->GetIndexes().end();
     507                 :            :                         ++aIndexItr )
     508                 :            :                     {
     509         [ +  - ]:        116 :                         aNewProperty.mnIndex = *aIndexItr;
     510         [ +  - ]:        116 :                         aPropStates.AddPropertyState( aNewProperty );
     511                 :            :                     }
     512                 :        116 :                     ++aItr;
     513                 :        116 :                 }
     514         [ +  - ]:       1070 :             }
     515                 :            :         }
     516                 :            :         else
     517                 :            :         {
     518                 :        415 :             FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
     519         [ +  + ]:      43015 :             for(sal_uInt32 i = 0; i < nCount; ++i)
     520                 :            :             {
     521                 :            :                 sal_Bool bDirectValue =
     522 [ +  - ][ +  + ]:      42600 :                     !pStates || *pStates == PropertyState_DIRECT_VALUE;
     523 [ +  + ][ +  + ]:      42600 :                 if( bDirectValue || bDefault )
     524                 :            :                 {
     525                 :            :                     // The value is stored in the PropertySet itself, add to list.
     526                 :       9790 :                     sal_Bool bGotValue = sal_False;
     527                 :       9790 :                     XMLPropertyState aNewProperty( -1 );
     528 [ +  - ][ +  - ]:      42906 :                     for( std::list<sal_uInt32>::const_iterator aIndexItr =
                 [ +  + ]
     529   [ +  -  #  # ]:       9790 :                             aItr->GetIndexes().begin();
     530         [ +  - ]:      21453 :                         aIndexItr != aItr->GetIndexes().end();
     531                 :            :                         ++aIndexItr )
     532                 :            :                     {
     533 [ +  + ][ +  + ]:      18059 :                         if( bDirectValue ||
                 [ +  + ]
     534 [ +  - ][ +  - ]:       6396 :                             (rPropMapper->GetEntryFlags( *aIndexItr ) &
                 [ +  - ]
     535                 :            :                                             MID_FLAG_DEFAULT_ITEM_EXPORT) != 0 )
     536                 :            :                         {
     537                 :            :                             try
     538                 :            :                             {
     539         [ +  + ]:       5468 :                                 if( !bGotValue )
     540                 :            :                                 {
     541                 :            :                                     aNewProperty.maValue =
     542 [ +  - ][ +  - ]:       4654 :                                         rPropSet->getPropertyValue( aItr->GetApiName() );
     543                 :       4654 :                                     bGotValue = sal_True;
     544                 :            :                                 }
     545         [ +  - ]:       5468 :                                 aNewProperty.mnIndex = *aIndexItr;
     546         [ +  - ]:       5468 :                                 aPropStates.AddPropertyState( aNewProperty );
     547                 :            :                             }
     548         [ #  # ]:          0 :                             catch( UnknownPropertyException& )
     549                 :            :                             {
     550                 :            :                                 // might be a problem of getImplemenetationId
     551                 :            :                                 OSL_ENSURE( !this, "unknown property in getPropertyValue" );
     552                 :            :                             }
     553                 :            : 
     554                 :            :                         }
     555                 :       9790 :                     }
     556                 :            :                 }
     557                 :            : 
     558                 :      42600 :                 ++aItr;
     559         [ +  - ]:      42600 :                 if( pStates )
     560                 :      42600 :                     ++pStates;
     561                 :            :             }
     562         [ +  - ]:       1485 :         }
     563                 :            :     }
     564         [ +  - ]:       5493 :     aPropStates.FillPropertyStateVector(rPropStates);
     565                 :       5493 : }
     566                 :            : 
     567                 :            : ///////////////////////////////////////////////////////////////////////////////
     568                 :            : //
     569                 :            : // ctor/dtor , class SvXMLExportPropertyMapper
     570                 :            : //
     571                 :            : 
     572                 :       3013 : SvXMLExportPropertyMapper::SvXMLExportPropertyMapper(
     573                 :            :         const UniReference< XMLPropertySetMapper >& rMapper ) :
     574                 :            :     pCache( 0 ),
     575         [ +  - ]:       3013 :     maPropMapper( rMapper )
     576                 :            : {
     577                 :       3013 : }
     578                 :            : 
     579 [ +  - ][ +  - ]:       2983 : SvXMLExportPropertyMapper::~SvXMLExportPropertyMapper()
     580                 :            : {
     581 [ +  + ][ +  - ]:       2983 :     delete pCache;
     582         [ +  - ]:       2983 :     mxNextMapper = 0;
     583         [ -  + ]:       3622 : }
     584                 :            : 
     585                 :        349 : void SvXMLExportPropertyMapper::ChainExportMapper(
     586                 :            :         const UniReference< SvXMLExportPropertyMapper>& rMapper )
     587                 :            : {
     588                 :            :     // add map entries from rMapper to current map
     589 [ +  - ][ +  - ]:        349 :     maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() );
                 [ +  - ]
     590                 :            :     // rMapper uses the same map as 'this'
     591 [ +  - ][ +  - ]:        349 :     rMapper->maPropMapper = maPropMapper;
     592                 :            : 
     593                 :            :     // set rMapper as last mapper in current chain
     594         [ +  - ]:        349 :     UniReference< SvXMLExportPropertyMapper > xNext = mxNextMapper;
     595         [ +  + ]:        349 :     if( xNext.is())
     596                 :            :     {
     597 [ +  - ][ -  + ]:         60 :         while( xNext->mxNextMapper.is())
     598 [ #  # ][ #  # ]:          0 :             xNext = xNext->mxNextMapper;
     599 [ +  - ][ +  - ]:         60 :         xNext->mxNextMapper = rMapper;
     600                 :            :     }
     601                 :            :     else
     602         [ +  - ]:        289 :         mxNextMapper = rMapper;
     603                 :            : 
     604                 :            :     // if rMapper was already chained, correct
     605                 :            :     // map pointer of successors
     606         [ +  - ]:        349 :     xNext = rMapper;
     607                 :            : 
     608 [ +  - ][ -  + ]:        349 :     while( xNext->mxNextMapper.is())
     609                 :            :     {
     610 [ #  # ][ #  # ]:          0 :         xNext = xNext->mxNextMapper;
     611 [ #  # ][ #  # ]:          0 :         xNext->maPropMapper = maPropMapper;
     612         [ +  - ]:        349 :     }
     613                 :        349 : }
     614                 :            : 
     615                 :            : 
     616                 :       5517 : vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter(
     617                 :            :         const Reference< XPropertySet > xPropSet,
     618                 :            :         const sal_Bool bDefault ) const
     619                 :            : {
     620         [ +  - ]:       5517 :     vector< XMLPropertyState > aPropStateArray;
     621                 :            : 
     622                 :            :     // Retrieve XPropertySetInfo and XPropertyState
     623 [ +  - ][ +  - ]:       5517 :     Reference< XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
     624         [ +  - ]:       5517 :     if( !xInfo.is() )
     625                 :            :         return aPropStateArray;
     626                 :            : 
     627         [ +  - ]:       5517 :     sal_Int32 nProps = maPropMapper->GetEntryCount();
     628                 :            : 
     629                 :       5517 :     FilterPropertiesInfo_Impl *pFilterInfo = 0;
     630                 :            : 
     631         [ +  + ]:       5517 :     if( pCache )
     632                 :            :     {
     633                 :            :         FilterPropertiesInfos_Impl::iterator aIter =
     634         [ +  - ]:       5270 :             pCache->find( xInfo );
     635 [ +  - ][ +  + ]:       5270 :         if( aIter != pCache->end() )
     636         [ +  - ]:       5270 :             pFilterInfo = (*aIter).second;
     637                 :            :     }
     638                 :            : 
     639                 :       5517 :     sal_Bool bDelInfo = sal_False;
     640         [ +  + ]:       5517 :     if( !pFilterInfo )
     641                 :            :     {
     642 [ +  - ][ +  - ]:        490 :         pFilterInfo = new FilterPropertiesInfo_Impl;
     643         [ +  + ]:     102624 :         for( sal_Int32 i=0; i < nProps; i++ )
     644                 :            :         {
     645                 :            :             // Are we allowed to ask for the property? (MID_FLAG_NO_PROP..)
     646                 :            :             // Does the PropertySet contain name of mpEntries-array ?
     647 [ +  - ][ +  - ]:     102134 :             const OUString& rAPIName = maPropMapper->GetEntryAPIName( i );
     648 [ +  - ][ +  - ]:     102134 :             const sal_Int32 nFlags = maPropMapper->GetEntryFlags( i );
     649 [ +  + ][ +  - ]:     202875 :             if( (0 == (nFlags & MID_FLAG_NO_PROPERTY_EXPORT)) &&
         [ +  + ][ +  + ]
     650                 :            :                 ( (0 != (nFlags & MID_FLAG_MUST_EXIST)) ||
     651 [ +  - ][ +  - ]:     100741 :                   xInfo->hasPropertyByName( rAPIName ) ) )
     652                 :            :             {
     653 [ +  - ][ +  - ]:      40268 :                 const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
                 [ +  - ]
     654                 :            :                 const SvtSaveOptions::ODFDefaultVersion nEarliestODFVersionForExport(
     655 [ +  - ][ +  - ]:      40268 :                         maPropMapper->GetEarliestODFVersionForExport( i ) );
     656 [ -  + ][ #  # ]:      40268 :                 if( nCurrentVersion >= nEarliestODFVersionForExport
                 [ #  # ]
     657                 :            :                         || nCurrentVersion == SvtSaveOptions::ODFVER_UNKNOWN
     658                 :            :                         || nEarliestODFVersionForExport == SvtSaveOptions::ODFVER_UNKNOWN )
     659         [ +  - ]:      40268 :                     pFilterInfo->AddProperty(rAPIName, i);
     660                 :            :             }
     661                 :            :         }
     662                 :            : 
     663                 :            :         // Check whether the property set info is destroyed if it is
     664                 :            :         // assigned to a weak reference only. If it is destroyed, then
     665                 :            :         // every instance of getPropertySetInfo returns a new object.
     666                 :            :         // Such property set infos must not be cached.
     667         [ +  - ]:        490 :         WeakReference < XPropertySetInfo > xWeakInfo( xInfo );
     668         [ +  - ]:        490 :         xInfo = 0;
     669 [ +  - ][ +  - ]:        490 :         xInfo = xWeakInfo;
     670         [ +  - ]:        490 :         if( xInfo.is() )
     671                 :            :         {
     672         [ +  + ]:        490 :             if( !pCache )
     673                 :            :                 ((SvXMLExportPropertyMapper *)this)->pCache =
     674 [ +  - ][ +  - ]:        247 :                     new FilterPropertiesInfos_Impl;
     675         [ +  - ]:        490 :             (*pCache)[xInfo] = pFilterInfo;
     676                 :            :         }
     677                 :            :         else
     678 [ +  - ][ #  # ]:        490 :             bDelInfo = sal_True;
     679                 :            :     }
     680                 :            : 
     681         [ +  + ]:       5517 :     if( pFilterInfo->GetPropertyCount() )
     682                 :            :     {
     683                 :            :         try
     684                 :            :         {
     685                 :            :             pFilterInfo->FillPropertyStateArray(aPropStateArray,
     686                 :            :                                                 xPropSet, maPropMapper,
     687         [ +  - ]:       5493 :                                                 bDefault);
     688                 :            :         }
     689         [ #  # ]:          0 :         catch( UnknownPropertyException& )
     690                 :            :         {
     691                 :            :             // might be a problem of getImplemenetationId
     692                 :            :             OSL_ENSURE( !this, "unknown property in getPropertyStates" );
     693                 :            :         }
     694                 :            :     }
     695                 :            : 
     696                 :            :     // Call centext-filter
     697         [ +  + ]:       5517 :     if( !aPropStateArray.empty() )
     698         [ +  - ]:       1164 :         ContextFilter( aPropStateArray, xPropSet );
     699                 :            : 
     700                 :            :     // Have to do if we change from a vector to a list or something like that
     701                 :            : 
     702         [ -  + ]:       5517 :     if( bDelInfo )
     703 [ #  # ][ #  # ]:          0 :         delete pFilterInfo;
     704                 :            : 
     705                 :       5517 :     return aPropStateArray;
     706                 :            : }
     707                 :            : 
     708                 :       2106 : void SvXMLExportPropertyMapper::ContextFilter(
     709                 :            :         vector< XMLPropertyState >& rProperties,
     710                 :            :         Reference< XPropertySet > rPropSet ) const
     711                 :            : {
     712                 :            :     // Derived class could implement this.
     713         [ +  + ]:       2106 :     if( mxNextMapper.is() )
     714         [ +  - ]:        946 :         mxNextMapper->ContextFilter( rProperties, rPropSet );
     715                 :       2106 : }
     716                 :            : 
     717                 :            : ///////////////////////////////////////////////////////////////////////////
     718                 :            : //
     719                 :            : // Compares two Sequences of XMLPropertyState:
     720                 :            : //  1.Number of elements equal ?
     721                 :            : //  2.Index of each element equal ? (So I know whether the propertynames are the same)
     722                 :            : //  3.Value of each element equal ?
     723                 :            : //
     724                 :        496 : sal_Bool SvXMLExportPropertyMapper::Equals(
     725                 :            :         const vector< XMLPropertyState >& aProperties1,
     726                 :            :         const vector< XMLPropertyState >& aProperties2 ) const
     727                 :            : {
     728                 :        496 :     sal_Bool bRet = sal_True;
     729                 :        496 :     sal_uInt32 nCount = aProperties1.size();
     730                 :            : 
     731         [ +  - ]:        496 :     if( nCount == aProperties2.size() )
     732                 :            :     {
     733                 :        496 :         sal_uInt32 nIndex = 0;
     734 [ +  + ][ +  + ]:       1925 :         while( bRet && nIndex < nCount )
                 [ +  + ]
     735                 :            :         {
     736                 :       1429 :             const XMLPropertyState& rProp1 = aProperties1[ nIndex ];
     737                 :       1429 :             const XMLPropertyState& rProp2 = aProperties2[ nIndex ];
     738                 :            : 
     739                 :            :             // Compare index. If equal, compare value
     740         [ +  + ]:       1429 :             if( rProp1.mnIndex == rProp2.mnIndex )
     741                 :            :             {
     742         [ +  + ]:       1414 :                 if( rProp1.mnIndex != -1 )
     743                 :            :                 {
     744                 :            :                     // Now compare values
     745         [ +  + ]:       1342 :                     if( ( maPropMapper->GetEntryType( rProp1.mnIndex ) &
     746                 :            :                           XML_TYPE_BUILDIN_CMP ) != 0 )
     747                 :            :                         // simple type ( binary compare )
     748                 :        443 :                         bRet = ( rProp1.maValue == rProp2.maValue );
     749                 :            :                     else
     750                 :            :                         // complex type ( ask for compare-function )
     751                 :            :                         bRet = maPropMapper->GetPropertyHandler(
     752                 :        899 :                                     rProp1.mnIndex )->equals( rProp1.maValue,
     753                 :        899 :                                                               rProp2.maValue );
     754                 :            :                 }
     755                 :            :             }
     756                 :            :             else
     757                 :         15 :                 bRet = sal_False;
     758                 :            : 
     759                 :       1429 :             nIndex++;
     760                 :            :         }
     761                 :            :     }
     762                 :            :     else
     763                 :          0 :         bRet = sal_False;
     764                 :            : 
     765                 :        496 :     return bRet;
     766                 :            : }
     767                 :            : 
     768                 :            : 
     769                 :            : /** fills the given attribute list with the items in the given set
     770                 :            : void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList,
     771                 :            :         const ::std::vector< XMLPropertyState >& rProperties,
     772                 :            :         const SvXMLUnitConverter& rUnitConverter,
     773                 :            :         const SvXMLNamespaceMap& rNamespaceMap,
     774                 :            :         sal_uInt16 nFlags ) const
     775                 :            : {
     776                 :            :     _exportXML( rAttrList, rProperties, rUnitConverter, rNamespaceMap,
     777                 :            :                 nFlags, 0, -1, -1 );
     778                 :            : }
     779                 :            : 
     780                 :            : 
     781                 :            : void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList,
     782                 :            :         const ::std::vector< XMLPropertyState >& rProperties,
     783                 :            :         const SvXMLUnitConverter& rUnitConverter,
     784                 :            :         const SvXMLNamespaceMap& rNamespaceMap,
     785                 :            :         sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx,
     786                 :            :         sal_uInt16 nFlags ) const
     787                 :            : {
     788                 :            :     _exportXML( rAttrList, rProperties, rUnitConverter, rNamespaceMap,
     789                 :            :                 nFlags, 0, nPropMapStartIdx, nPropMapEndIdx );
     790                 :            : }
     791                 :            : */
     792                 :            : 
     793                 :        512 : void SvXMLExportPropertyMapper::exportXML(
     794                 :            :         SvXMLExport& rExport,
     795                 :            :         const ::std::vector< XMLPropertyState >& rProperties,
     796                 :            :         sal_uInt16 nFlags ) const
     797                 :            : {
     798                 :        512 :     exportXML( rExport, rProperties, -1, -1,  nFlags );
     799                 :        512 : }
     800                 :            : 
     801                 :        826 : void SvXMLExportPropertyMapper::exportXML(
     802                 :            :         SvXMLExport& rExport,
     803                 :            :         const ::std::vector< XMLPropertyState >& rProperties,
     804                 :            :         sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx,
     805                 :            :         sal_uInt16 nFlags ) const
     806                 :            : {
     807                 :        826 :     sal_uInt16 nPropTypeFlags = 0;
     808         [ +  + ]:      12390 :     for( sal_uInt16 i=0; i<MAX_PROP_TYPES; ++i )
     809                 :            :     {
     810                 :      11564 :         sal_uInt16 nPropType = aPropTokens[i].nType;
     811 [ +  + ][ +  + ]:      11564 :         if( 0==i || (nPropTypeFlags & (1 << nPropType)) != 0 )
     812                 :            :         {
     813         [ +  - ]:       2105 :             std::vector<sal_uInt16> aIndexArray;
     814                 :            : 
     815                 :            :             _exportXML( nPropType, nPropTypeFlags,
     816                 :       2105 :                         rExport.GetAttrList(), rProperties,
     817                 :       2105 :                         rExport.GetMM100UnitConverter(),
     818                 :       2105 :                         rExport.GetNamespaceMap(),
     819                 :            :                         nFlags, &aIndexArray,
     820         [ +  - ]:       2105 :                         nPropMapStartIdx, nPropMapEndIdx );
     821                 :            : 
     822 [ +  - ][ +  + ]:       2911 :             if( rExport.GetAttrList().getLength() > 0L ||
           [ +  -  -  + ]
                 [ +  + ]
     823                 :            :                 (nFlags & XML_EXPORT_FLAG_EMPTY) != 0 ||
     824                 :        806 :                 !aIndexArray.empty() )
     825                 :            :             {
     826                 :            :                 SvXMLElementExport aElem( rExport, XML_NAMESPACE_STYLE,
     827                 :            :                                   aPropTokens[i].eToken,
     828                 :            :                                   (nFlags & XML_EXPORT_FLAG_IGN_WS) != 0,
     829         [ +  - ]:       1299 :                                   sal_False );
     830                 :            : 
     831 [ +  - ][ +  - ]:       1299 :                 exportElementItems( rExport, rProperties, nFlags, aIndexArray );
     832                 :       2105 :             }
     833                 :            :         }
     834                 :            :     }
     835                 :        826 : }
     836                 :            : 
     837                 :            : /** this method is called for every item that has the
     838                 :            :     MID_FLAG_SPECIAL_ITEM_EXPORT flag set */
     839                 :          0 : void SvXMLExportPropertyMapper::handleSpecialItem(
     840                 :            :         SvXMLAttributeList& rAttrList,
     841                 :            :         const XMLPropertyState& rProperty,
     842                 :            :         const SvXMLUnitConverter& rUnitConverter,
     843                 :            :         const SvXMLNamespaceMap& rNamespaceMap,
     844                 :            :         const ::std::vector< XMLPropertyState > *pProperties,
     845                 :            :         sal_uInt32 nIdx ) const
     846                 :            : {
     847                 :            :     OSL_ENSURE( mxNextMapper.is(), "special item not handled in xml export" );
     848         [ #  # ]:          0 :     if( mxNextMapper.is() )
     849                 :          0 :         mxNextMapper->handleSpecialItem( rAttrList, rProperty, rUnitConverter,
     850                 :          0 :                                         rNamespaceMap, pProperties, nIdx );
     851                 :          0 : }
     852                 :            : 
     853                 :            : /** this method is called for every item that has the
     854                 :            :     MID_FLAG_ELEMENT_EXPORT flag set */
     855                 :         33 : void SvXMLExportPropertyMapper::handleElementItem(
     856                 :            :         SvXMLExport& rExport,
     857                 :            :         const XMLPropertyState& rProperty,
     858                 :            :         sal_uInt16 nFlags,
     859                 :            :         const ::std::vector< XMLPropertyState > *pProperties,
     860                 :            :         sal_uInt32 nIdx ) const
     861                 :            : {
     862                 :            :     OSL_ENSURE( mxNextMapper.is(), "element item not handled in xml export" );
     863         [ +  - ]:         33 :     if( mxNextMapper.is() )
     864                 :         33 :         mxNextMapper->handleElementItem( rExport, rProperty, nFlags,
     865                 :         33 :                                          pProperties, nIdx );
     866                 :         33 : }
     867                 :            : 
     868                 :            : ///////////////////////////////////////////////////////////////////////////////
     869                 :            : //
     870                 :            : // protected methods
     871                 :            : //
     872                 :            : 
     873                 :            : /** fills the given attribute list with the items in the given set */
     874                 :       2105 : void SvXMLExportPropertyMapper::_exportXML(
     875                 :            :         sal_uInt16 nPropType, sal_uInt16& rPropTypeFlags,
     876                 :            :         SvXMLAttributeList& rAttrList,
     877                 :            :         const ::std::vector< XMLPropertyState >& rProperties,
     878                 :            :         const SvXMLUnitConverter& rUnitConverter,
     879                 :            :         const SvXMLNamespaceMap& rNamespaceMap,
     880                 :            :         sal_uInt16 nFlags,
     881                 :            :         std::vector<sal_uInt16>* pIndexArray,
     882                 :            :         sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx ) const
     883                 :            : {
     884                 :       2105 :     const sal_uInt32 nCount = rProperties.size();
     885                 :       2105 :     sal_uInt32 nIndex = 0;
     886                 :            : 
     887         [ +  + ]:       2105 :     if( -1 == nPropMapStartIdx )
     888                 :       1961 :         nPropMapStartIdx = 0;
     889         [ +  + ]:       2105 :     if( -1 == nPropMapEndIdx )
     890                 :       1961 :         nPropMapEndIdx = maPropMapper->GetEntryCount();
     891                 :            : 
     892         [ +  + ]:      35189 :     while( nIndex < nCount )
     893                 :            :     {
     894                 :      33084 :         sal_Int32 nPropMapIdx = rProperties[nIndex].mnIndex;
     895 [ +  + ][ +  + ]:      33084 :         if( nPropMapIdx >= nPropMapStartIdx &&
     896                 :            :             nPropMapIdx < nPropMapEndIdx  )// valid entry?
     897                 :            :         {
     898                 :      22218 :             sal_uInt32 nEFlags = maPropMapper->GetEntryFlags( nPropMapIdx );
     899                 :      22218 :             sal_uInt16 nEPType = GET_PROP_TYPE(nEFlags);
     900                 :            :             OSL_ENSURE( nEPType >= (XML_TYPE_PROP_START>>XML_TYPE_PROP_SHIFT),
     901                 :            :                         "no prop type sepcified" );
     902                 :      22218 :             rPropTypeFlags |= (1 << nEPType);
     903         [ +  + ]:      22218 :             if( nEPType == nPropType )
     904                 :            :             {
     905                 :            :                 // we have a valid map entry here, so lets use it...
     906         [ +  + ]:       6909 :                 if( ( nEFlags & MID_FLAG_ELEMENT_ITEM_EXPORT ) != 0 )
     907                 :            :                 {
     908                 :            :                     // element items do not add any properties,
     909                 :            :                     // we export it later
     910         [ +  - ]:        127 :                     if( pIndexArray )
     911                 :            :                     {
     912         [ +  - ]:        127 :                         pIndexArray->push_back( (sal_uInt16)nIndex );
     913                 :            :                     }
     914                 :            :                 }
     915                 :            :                 else
     916                 :            :                 {
     917                 :       6782 :                     _exportXML( rAttrList, rProperties[nIndex], rUnitConverter,
     918                 :       6782 :                                 rNamespaceMap, nFlags, &rProperties, nIndex );
     919                 :            :                 }
     920                 :            :             }
     921                 :            :         }
     922                 :            : 
     923                 :      33084 :         nIndex++;
     924                 :            :     }
     925                 :       2105 : }
     926                 :            : 
     927                 :       6782 : void SvXMLExportPropertyMapper::_exportXML(
     928                 :            :         SvXMLAttributeList& rAttrList,
     929                 :            :         const XMLPropertyState& rProperty,
     930                 :            :         const SvXMLUnitConverter& rUnitConverter,
     931                 :            :         const SvXMLNamespaceMap& rNamespaceMap,
     932                 :            :         sal_uInt16 /*nFlags*/,
     933                 :            :         const ::std::vector< XMLPropertyState > *pProperties,
     934                 :            :         sal_uInt32 nIdx ) const
     935                 :            : {
     936         [ +  - ]:       6782 :     OUString sCDATA( GetXMLToken(XML_CDATA) );
     937                 :            : 
     938 [ +  - ][ +  + ]:       6782 :     if ( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
                 [ +  - ]
     939                 :            :                 MID_FLAG_SPECIAL_ITEM_EXPORT ) != 0 )
     940                 :            :     {
     941                 :        266 :         uno::Reference< container::XNameContainer > xAttrContainer;
     942 [ +  + ][ +  - ]:        266 :         if( (rProperty.maValue >>= xAttrContainer) && xAttrContainer.is() )
         [ +  + ][ +  - ]
     943                 :            :         {
     944                 :         32 :             SvXMLNamespaceMap *pNewNamespaceMap = 0;
     945                 :         32 :             const SvXMLNamespaceMap *pNamespaceMap = &rNamespaceMap;
     946                 :            : 
     947 [ +  - ][ +  - ]:         32 :             uno::Sequence< OUString > aAttribNames( xAttrContainer->getElementNames() );
     948                 :         32 :             const OUString* pAttribName = aAttribNames.getConstArray();
     949                 :            : 
     950                 :         32 :             const sal_Int32 nCount = aAttribNames.getLength();
     951                 :            : 
     952                 :         32 :             OUStringBuffer sNameBuffer;
     953                 :         32 :             xml::AttributeData aData;
     954         [ -  + ]:         32 :             for( sal_Int32 i=0; i < nCount; i++, pAttribName++ )
     955                 :            :             {
     956 [ #  # ][ #  # ]:          0 :                 xAttrContainer->getByName( *pAttribName ) >>= aData;
                 [ #  # ]
     957                 :          0 :                 OUString sAttribName( *pAttribName );
     958                 :            : 
     959                 :            :                 // extract namespace prefix from attribute name if it exists
     960                 :          0 :                 OUString sPrefix;
     961                 :            :                 const sal_Int32 nColonPos =
     962                 :          0 :                     pAttribName->indexOf( sal_Unicode(':') );
     963         [ #  # ]:          0 :                 if( nColonPos != -1 )
     964                 :          0 :                     sPrefix = pAttribName->copy( 0, nColonPos );
     965                 :            : 
     966         [ #  # ]:          0 :                 if( !sPrefix.isEmpty() )
     967                 :            :                 {
     968                 :          0 :                     OUString sNamespace( aData.Namespace );
     969                 :            : 
     970                 :            :                     // if the prefix isn't defined yet or has another meaning,
     971                 :            :                     // we have to redefine it now.
     972         [ #  # ]:          0 :                     sal_uInt16 nKey = pNamespaceMap->GetKeyByPrefix( sPrefix );
     973 [ #  # ][ #  # ]:          0 :                     if( USHRT_MAX == nKey || pNamespaceMap->GetNameByKey( nKey ) != sNamespace )
         [ #  # ][ #  # ]
     974                 :            :                     {
     975                 :          0 :                         sal_Bool bAddNamespace = sal_False;
     976         [ #  # ]:          0 :                         if( USHRT_MAX == nKey )
     977                 :            :                         {
     978                 :            :                             // The prefix is unused, so it is sufficient
     979                 :            :                             // to add it to the namespace map.
     980                 :          0 :                             bAddNamespace = sal_True;
     981                 :            :                         }
     982                 :            :                         else
     983                 :            :                         {
     984                 :            :                             // check if there is a prefix registered for the
     985                 :            :                             // namepsace URI
     986         [ #  # ]:          0 :                             nKey = pNamespaceMap->GetKeyByName( sNamespace );
     987         [ #  # ]:          0 :                             if( XML_NAMESPACE_UNKNOWN == nKey )
     988                 :            :                             {
     989                 :            :                                 // There is no prefix for the namespace, so
     990                 :            :                                 // we have to generate one and have to add it.
     991                 :          0 :                                 sal_Int32 n=0;
     992                 :          0 :                                 OUString sOrigPrefix( sPrefix );
     993         [ #  # ]:          0 :                                 do
     994                 :            :                                 {
     995         [ #  # ]:          0 :                                     sNameBuffer.append( sOrigPrefix );
     996         [ #  # ]:          0 :                                     sNameBuffer.append( ++n );
     997         [ #  # ]:          0 :                                     sPrefix = sNameBuffer.makeStringAndClear();
     998         [ #  # ]:          0 :                                     nKey = pNamespaceMap->GetKeyByPrefix( sPrefix );
     999                 :            :                                 }
    1000                 :            :                                 while( nKey != USHRT_MAX );
    1001                 :            : 
    1002                 :          0 :                                 bAddNamespace = sal_True;
    1003                 :            :                             }
    1004                 :            :                             else
    1005                 :            :                             {
    1006                 :            :                                 // If there is a prefix for the namespace,
    1007                 :            :                                 // we reuse that.
    1008         [ #  # ]:          0 :                                 sPrefix = pNamespaceMap->GetPrefixByKey( nKey );
    1009                 :            :                             }
    1010                 :            :                             // In any case, the attribute name has to be adapted.
    1011         [ #  # ]:          0 :                             sNameBuffer.append( sPrefix );
    1012         [ #  # ]:          0 :                             sNameBuffer.append( sal_Unicode(':') );
    1013         [ #  # ]:          0 :                             sNameBuffer.append( pAttribName->copy( nColonPos+1 ) );
    1014         [ #  # ]:          0 :                             sAttribName = sNameBuffer.makeStringAndClear();
    1015                 :            :                         }
    1016                 :            : 
    1017         [ #  # ]:          0 :                         if( bAddNamespace )
    1018                 :            :                         {
    1019         [ #  # ]:          0 :                             if( !pNewNamespaceMap )
    1020                 :            :                             {
    1021 [ #  # ][ #  # ]:          0 :                                 pNewNamespaceMap = new SvXMLNamespaceMap( rNamespaceMap );
    1022                 :          0 :                                 pNamespaceMap = pNewNamespaceMap;
    1023                 :            :                             }
    1024         [ #  # ]:          0 :                             pNewNamespaceMap->Add( sPrefix, sNamespace );
    1025 [ #  # ][ #  # ]:          0 :                             sNameBuffer.append( GetXMLToken(XML_XMLNS) );
    1026         [ #  # ]:          0 :                             sNameBuffer.append( sal_Unicode(':') );
    1027         [ #  # ]:          0 :                             sNameBuffer.append( sPrefix );
    1028                 :            :                             rAttrList.AddAttribute( sNameBuffer.makeStringAndClear(),
    1029 [ #  # ][ #  # ]:          0 :                                                     sNamespace );
    1030                 :            :                         }
    1031                 :          0 :                     }
    1032                 :            :                 }
    1033         [ #  # ]:          0 :                 OUString sOldValue( rAttrList.getValueByName( sAttribName ) );
    1034                 :            :                 OSL_ENSURE( sOldValue.isEmpty(), "alien attribute exists already" );
    1035                 :            :                 OSL_ENSURE(aData.Type == GetXMLToken(XML_CDATA), "different type to our default type which should be written out");
    1036         [ #  # ]:          0 :                 if( sOldValue.isEmpty() )
    1037         [ #  # ]:          0 :                     rAttrList.AddAttribute( sAttribName, aData.Value );
    1038                 :          0 :             }
    1039                 :            : 
    1040 [ -  + ][ #  # ]:         32 :             delete pNewNamespaceMap;
                 [ +  - ]
    1041                 :            :         }
    1042                 :            :         else
    1043                 :            :         {
    1044                 :            :             handleSpecialItem( rAttrList, rProperty, rUnitConverter,
    1045         [ +  - ]:        234 :                                rNamespaceMap, pProperties, nIdx );
    1046                 :        266 :         }
    1047                 :            :     }
    1048 [ +  - ][ +  - ]:       6516 :     else if ( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
                 [ +  - ]
    1049                 :            :                     MID_FLAG_ELEMENT_ITEM_EXPORT ) == 0 )
    1050                 :            :     {
    1051                 :       6516 :         OUString aValue;
    1052                 :            :         const OUString sName( rNamespaceMap.GetQNameByKey(
    1053 [ +  - ][ +  - ]:       6516 :                     maPropMapper->GetEntryNameSpace( rProperty.mnIndex ),
    1054 [ +  - ][ +  - ]:      13032 :                     maPropMapper->GetEntryXMLName( rProperty.mnIndex ) ) );
                 [ +  - ]
    1055                 :            : 
    1056                 :       6516 :         sal_Bool bRemove = sal_False;
    1057 [ +  - ][ +  - ]:       6516 :         if( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
                 [ +  + ]
    1058                 :            :                     MID_FLAG_MERGE_ATTRIBUTE ) != 0 )
    1059                 :            :         {
    1060         [ +  - ]:         64 :             aValue = rAttrList.getValueByName( sName );
    1061                 :         64 :             bRemove = sal_True;
    1062                 :            :         }
    1063                 :            : 
    1064 [ +  - ][ +  - ]:       6516 :         if( maPropMapper->exportXML( aValue, rProperty, rUnitConverter ) )
                 [ +  + ]
    1065                 :            :         {
    1066         [ +  + ]:       5941 :             if( bRemove )
    1067         [ +  - ]:         56 :                 rAttrList.RemoveAttribute( sName );
    1068         [ +  - ]:       5941 :             rAttrList.AddAttribute( sName, aValue );
    1069                 :       6516 :         }
    1070                 :       6782 :     }
    1071                 :       6782 : }
    1072                 :            : 
    1073                 :       1299 : void SvXMLExportPropertyMapper::exportElementItems(
    1074                 :            :         SvXMLExport& rExport,
    1075                 :            :         const ::std::vector< XMLPropertyState >& rProperties,
    1076                 :            :         sal_uInt16 nFlags,
    1077                 :            :         const std::vector<sal_uInt16>& rIndexArray ) const
    1078                 :            : {
    1079                 :       1299 :     const sal_uInt16 nCount = rIndexArray.size();
    1080                 :            : 
    1081                 :       1299 :     sal_Bool bItemsExported = sal_False;
    1082         [ +  - ]:       1299 :     OUString sWS( GetXMLToken(XML_WS) );
    1083         [ +  + ]:       1426 :     for( sal_uInt16 nIndex = 0; nIndex < nCount; nIndex++ )
    1084                 :            :     {
    1085         [ +  - ]:        127 :         const sal_uInt16 nElement = rIndexArray[nIndex];
    1086                 :            : 
    1087                 :            :         OSL_ENSURE( 0 != ( maPropMapper->GetEntryFlags(
    1088                 :            :                 rProperties[nElement].mnIndex ) & MID_FLAG_ELEMENT_ITEM_EXPORT),
    1089                 :            :                 "wrong mid flag!" );
    1090                 :            : 
    1091         [ +  - ]:        127 :         rExport.IgnorableWhitespace();
    1092                 :        127 :         handleElementItem( rExport, rProperties[nElement],
    1093         [ +  - ]:        127 :                            nFlags, &rProperties, nElement );
    1094                 :        127 :         bItemsExported = sal_True;
    1095                 :            :     }
    1096                 :            : 
    1097         [ +  + ]:       1299 :     if( bItemsExported )
    1098         [ +  - ]:       1299 :         rExport.IgnorableWhitespace();
    1099                 :       1299 : }
    1100                 :            : 
    1101                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10