LCOV - code coverage report
Current view: top level - xmloff/source/style - xmlprmap.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 88 90 97.8 %
Date: 2014-04-11 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/debug.hxx>
      21             : #include <xmloff/xmlprhdl.hxx>
      22             : #include "xmlbahdl.hxx"
      23             : #include <xmloff/xmlprmap.hxx>
      24             : #include <xmloff/xmltypes.hxx>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/beans/XPropertyState.hpp>
      27             : #include <com/sun/star/uno/Any.hxx>
      28             : #include <xmloff/xmltoken.hxx>
      29             : 
      30             : using namespace ::std;
      31             : 
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star::beans;
      34             : using ::xmloff::token::GetXMLToken;
      35             : 
      36     1702416 : XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
      37             :     const XMLPropertyMapEntry& rMapEntry,
      38             :     const UniReference< XMLPropertyHandlerFactory >& rFactory ) :
      39     1702416 :     sXMLAttributeName( GetXMLToken(rMapEntry.meXMLName) ),
      40             :     sAPIPropertyName( OUString(rMapEntry.msApiName, rMapEntry.nApiNameLength,
      41             :                                RTL_TEXTENCODING_ASCII_US ) ),
      42             :     nType( rMapEntry.mnType ),
      43             :     nXMLNameSpace( rMapEntry.mnNameSpace ),
      44             :     nContextId( rMapEntry.mnContextId ),
      45             :     nEarliestODFVersionForExport( rMapEntry.mnEarliestODFVersionForExport ),
      46             :     bImportOnly( rMapEntry.mbImportOnly),
      47     1702416 :     pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) )
      48             : {
      49     1702416 : }
      50             : 
      51     5401068 : XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
      52             :         const XMLPropertySetMapperEntry_Impl& rEntry ) :
      53             :     sXMLAttributeName( rEntry.sXMLAttributeName),
      54             :     sAPIPropertyName( rEntry.sAPIPropertyName),
      55             :     nType( rEntry.nType),
      56             :     nXMLNameSpace( rEntry.nXMLNameSpace),
      57             :     nContextId( rEntry.nContextId),
      58             :     nEarliestODFVersionForExport( rEntry.nEarliestODFVersionForExport ),
      59             :     bImportOnly( rEntry.bImportOnly),
      60     5401068 :     pHdl( rEntry.pHdl)
      61             : {
      62             :     DBG_ASSERT( pHdl, "Unknown XML property type handler!" );
      63     5401068 : }
      64             : 
      65             : // Ctor
      66       19587 : XMLPropertySetMapper::XMLPropertySetMapper(
      67             :         const XMLPropertyMapEntry* pEntries,
      68             :         const UniReference< XMLPropertyHandlerFactory >& rFactory,
      69             :         bool bForExport )
      70             :     :
      71       19587 :         mbOnlyExportMappings( bForExport)
      72             : {
      73       19587 :     aHdlFactories.push_back( rFactory );
      74       19587 :     if( pEntries )
      75             :     {
      76       19587 :         const XMLPropertyMapEntry* pIter = pEntries;
      77             : 
      78       19587 :         if (mbOnlyExportMappings)
      79             :         {
      80      832462 :             while( pIter->msApiName )
      81             :             {
      82      814968 :                 if (!pIter->mbImportOnly)
      83             :                 {
      84      808552 :                     XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
      85      808552 :                     aMapEntries.push_back( aEntry );
      86             :                 }
      87      814968 :                 pIter++;
      88             :             }
      89             :         }
      90             :         else
      91             :         {
      92      915544 :             while( pIter->msApiName )
      93             :             {
      94      893864 :                 XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
      95      893864 :                 aMapEntries.push_back( aEntry );
      96      893864 :                 pIter++;
      97      893864 :             }
      98             :         }
      99             :     }
     100       19587 : }
     101             : 
     102       23744 : XMLPropertySetMapper::~XMLPropertySetMapper()
     103             : {
     104       23744 : }
     105             : 
     106        4206 : void XMLPropertySetMapper::AddMapperEntry(
     107             :     const UniReference < XMLPropertySetMapper >& rMapper )
     108             : {
     109       27450 :     for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator
     110        4206 :             aFIter = rMapper->aHdlFactories.begin();
     111       18300 :          aFIter != rMapper->aHdlFactories.end();
     112             :          ++aFIter )
     113             :     {
     114        4944 :         aHdlFactories.push_back( *aFIter );
     115             :     }
     116             : 
     117     1806747 :     for( vector < XMLPropertySetMapperEntry_Impl >::iterator
     118        4206 :             aEIter = rMapper->aMapEntries.begin();
     119     1204498 :          aEIter != rMapper->aMapEntries.end();
     120             :          ++aEIter )
     121             :     {
     122      598043 :         if (!mbOnlyExportMappings || !(*aEIter).bImportOnly)
     123      598043 :             aMapEntries.push_back( *aEIter );
     124             :     }
     125        4206 : }
     126             : 
     127             : // Export a Property
     128       31483 : bool XMLPropertySetMapper::exportXML(
     129             :         OUString& rStrExpValue,
     130             :         const XMLPropertyState& rProperty,
     131             :         const SvXMLUnitConverter& rUnitConverter ) const
     132             : {
     133       31483 :     bool bRet = false;
     134             : 
     135       31483 :     const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
     136             : 
     137             :     DBG_ASSERT( pHdl, "Unknown XML Type!" );
     138       31483 :     if( pHdl )
     139             :         bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue,
     140       31483 :                                 rUnitConverter );
     141             : 
     142       31483 :     return bRet;
     143             : }
     144             : 
     145             : // Import a Property
     146       62292 : bool XMLPropertySetMapper::importXML(
     147             :         const OUString& rStrImpValue,
     148             :         XMLPropertyState& rProperty,
     149             :         const SvXMLUnitConverter& rUnitConverter ) const
     150             : {
     151       62292 :     bool bRet = false;
     152             : 
     153       62292 :     const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
     154             : 
     155       62292 :     if( pHdl )
     156             :         bRet = pHdl->importXML( rStrImpValue, rProperty.maValue,
     157       62292 :                                 rUnitConverter );
     158             : 
     159       62292 :     return bRet;
     160             : }
     161             : 
     162             : // Search for the given name and the namespace in the list and return
     163             : // the index of the entry
     164             : // If there is no matching entry the method returns -1
     165       75372 : sal_Int32 XMLPropertySetMapper::GetEntryIndex(
     166             :         sal_uInt16 nNamespace,
     167             :         const OUString& rStrName,
     168             :         sal_uInt32 nPropType,
     169             :         sal_Int32 nStartAt /* = -1 */ ) const
     170             : {
     171       75372 :     sal_Int32 nEntries = GetEntryCount();
     172       75372 :     sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1;
     173             : 
     174       75372 :     if ( nEntries )
     175             :     {
     176     6630234 :         do
     177             :         {
     178     6697734 :             const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
     179    16349022 :             if( (!nPropType || nPropType == rEntry.GetPropType()) &&
     180    11047854 :                 rEntry.nXMLNameSpace == nNamespace &&
     181     1394276 :                 rStrName == rEntry.sXMLAttributeName )
     182       67500 :                 return nIndex;
     183             :             else
     184     6630234 :                 nIndex++;
     185             : 
     186             :         } while( nIndex<nEntries );
     187             :     }
     188             : 
     189        7872 :     return -1;
     190             : }
     191             : 
     192             : /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
     193         767 : sal_Int32 XMLPropertySetMapper::FindEntryIndex(
     194             :         const sal_Char* sApiName,
     195             :         sal_uInt16 nNameSpace,
     196             :         const OUString& sXMLName ) const
     197             : {
     198         767 :     sal_Int32 nIndex = 0;
     199         767 :     sal_Int32 nEntries = GetEntryCount();
     200             : 
     201       66413 :     do
     202             :     {
     203       67180 :         const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
     204      176984 :         if( rEntry.nXMLNameSpace == nNameSpace &&
     205       68611 :             rEntry.sXMLAttributeName.equals( sXMLName ) &&
     206        1431 :             rEntry.sAPIPropertyName.equalsAscii( sApiName ) )
     207         767 :             return nIndex;
     208             :         else
     209       66413 :             nIndex++;
     210             : 
     211             :     } while( nIndex < nEntries );
     212             : 
     213           0 :     return -1;
     214             : }
     215             : 
     216        1898 : sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const
     217             : {
     218        1898 :     const sal_Int32 nEntries = GetEntryCount();
     219             : 
     220        1898 :     if ( nEntries )
     221             :     {
     222        1898 :         sal_Int32 nIndex = 0;
     223       99006 :         do
     224             :         {
     225      100904 :             const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
     226      100904 :             if( rEntry.nContextId == nContextId )
     227        1898 :                 return nIndex;
     228             :             else
     229       99006 :                 nIndex++;
     230             : 
     231             :         } while( nIndex < nEntries );
     232             :     }
     233             : 
     234           0 :     return -1;
     235             : }
     236             : 
     237          83 : void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex )
     238             : {
     239          83 :     const sal_Int32 nEntries = GetEntryCount();
     240          83 :     if( nIndex>=nEntries || nIndex<0 )
     241          83 :         return;
     242          83 :     vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin();
     243       12284 :     for( sal_Int32 nN=0; nN<nIndex; nN++ )
     244       12201 :         ++aEIter;
     245          83 :     aMapEntries.erase( aEIter );
     246             : }
     247             : 
     248             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10