LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/style - xmlprmap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 81 83 97.6 %
Date: 2013-07-09 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             : 
      31             : using namespace ::std;
      32             : 
      33             : using namespace ::com::sun::star::uno;
      34             : using namespace ::com::sun::star::beans;
      35             : using ::xmloff::token::GetXMLToken;
      36             : 
      37      497446 : XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
      38             :     const XMLPropertyMapEntry& rMapEntry,
      39             :     const UniReference< XMLPropertyHandlerFactory >& rFactory ) :
      40      497446 :     sXMLAttributeName( GetXMLToken(rMapEntry.meXMLName) ),
      41             :     sAPIPropertyName( OUString(rMapEntry.msApiName, rMapEntry.nApiNameLength,
      42             :                                RTL_TEXTENCODING_ASCII_US ) ),
      43             :     nXMLNameSpace( rMapEntry.mnNameSpace ),
      44             :     nType( rMapEntry.mnType ),
      45             :     nContextId( rMapEntry.mnContextId ),
      46             :     nEarliestODFVersionForExport( rMapEntry.mnEarliestODFVersionForExport ),
      47      497446 :     pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) )
      48             : {
      49      497446 : }
      50             : 
      51     1660309 : XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
      52             :         const XMLPropertySetMapperEntry_Impl& rEntry ) :
      53             :     sXMLAttributeName( rEntry.sXMLAttributeName),
      54             :     sAPIPropertyName( rEntry.sAPIPropertyName),
      55             :     nXMLNameSpace( rEntry.nXMLNameSpace),
      56             :     nType( rEntry.nType),
      57             :     nContextId( rEntry.nContextId),
      58             :     nEarliestODFVersionForExport( rEntry.nEarliestODFVersionForExport ),
      59     1660309 :     pHdl( rEntry.pHdl)
      60             : {
      61             :     DBG_ASSERT( pHdl, "Unknown XML property type handler!" );
      62     1660309 : }
      63             : 
      64             : ///////////////////////////////////////////////////////////////////////////
      65             : //
      66             : // Ctor
      67             : //
      68        7582 : XMLPropertySetMapper::XMLPropertySetMapper(
      69             :         const XMLPropertyMapEntry* pEntries,
      70        7582 :         const UniReference< XMLPropertyHandlerFactory >& rFactory )
      71             : {
      72        7582 :     aHdlFactories.push_back( rFactory );
      73        7582 :     if( pEntries )
      74             :     {
      75        7582 :         const XMLPropertyMapEntry* pIter = pEntries;
      76             : 
      77             :         // count entries
      78      512610 :         while( pIter->msApiName )
      79             :         {
      80      497446 :             XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
      81      497446 :             aMapEntries.push_back( aEntry );
      82      497446 :             pIter++;
      83      497446 :         }
      84             :     }
      85        7582 : }
      86             : 
      87       10173 : XMLPropertySetMapper::~XMLPropertySetMapper()
      88             : {
      89       10173 : }
      90             : 
      91        1464 : void XMLPropertySetMapper::AddMapperEntry(
      92             :     const UniReference < XMLPropertySetMapper >& rMapper )
      93             : {
      94        9804 :     for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator
      95        1464 :             aFIter = rMapper->aHdlFactories.begin();
      96        6536 :          aFIter != rMapper->aHdlFactories.end();
      97             :          ++aFIter )
      98             :     {
      99        1804 :         aHdlFactories.push_back( *aFIter );
     100             :     }
     101             : 
     102      500241 :     for( vector < XMLPropertySetMapperEntry_Impl >::iterator
     103        1464 :             aEIter = rMapper->aMapEntries.begin();
     104      333494 :          aEIter != rMapper->aMapEntries.end();
     105             :          ++aEIter )
     106             :     {
     107      165283 :         aMapEntries.push_back( *aEIter );
     108             :     }
     109        1464 : }
     110             : 
     111             : ///////////////////////////////////////////////////////////////////////////
     112             : //
     113             : // Export a Property
     114             : //
     115        4784 : sal_Bool XMLPropertySetMapper::exportXML(
     116             :         OUString& rStrExpValue,
     117             :         const XMLPropertyState& rProperty,
     118             :         const SvXMLUnitConverter& rUnitConverter ) const
     119             : {
     120        4784 :     sal_Bool bRet = sal_False;
     121             : 
     122        4784 :     const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
     123             : 
     124             :     DBG_ASSERT( pHdl, "Unknown XML Type!" );
     125        4784 :     if( pHdl )
     126             :         bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue,
     127        4784 :                                 rUnitConverter );
     128             : 
     129        4784 :     return bRet;
     130             : }
     131             : 
     132             : ///////////////////////////////////////////////////////////////////////////
     133             : //
     134             : // Import a Property
     135             : //
     136       20046 : sal_Bool XMLPropertySetMapper::importXML(
     137             :         const OUString& rStrImpValue,
     138             :         XMLPropertyState& rProperty,
     139             :         const SvXMLUnitConverter& rUnitConverter ) const
     140             : {
     141       20046 :     sal_Bool bRet = sal_False;
     142             : 
     143       20046 :     const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
     144             : 
     145       20046 :     if( pHdl )
     146             :         bRet = pHdl->importXML( rStrImpValue, rProperty.maValue,
     147       20046 :                                 rUnitConverter );
     148             : 
     149       20046 :     return bRet;
     150             : }
     151             : 
     152             : ///////////////////////////////////////////////////////////////////////////
     153             : //
     154             : // Search for the given name and the namespace in the list and return
     155             : // the index of the entry
     156             : // If there is no matching entry the method returns -1
     157             : //
     158       23720 : sal_Int32 XMLPropertySetMapper::GetEntryIndex(
     159             :         sal_uInt16 nNamespace,
     160             :         const OUString& rStrName,
     161             :         sal_uInt32 nPropType,
     162             :         sal_Int32 nStartAt /* = -1 */ ) const
     163             : {
     164       23720 :     sal_Int32 nEntries = GetEntryCount();
     165       23720 :     sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1;
     166             : 
     167       23720 :     if ( nEntries )
     168             :     {
     169     1819022 :         do
     170             :         {
     171     1840582 :             const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
     172     4445273 :             if( (!nPropType || nPropType == rEntry.GetPropType()) &&
     173     2990753 :                 rEntry.nXMLNameSpace == nNamespace &&
     174      386062 :                 rStrName == rEntry.sXMLAttributeName )
     175       21560 :                 return nIndex;
     176             :             else
     177     1819022 :                 nIndex++;
     178             : 
     179             :         } while( nIndex<nEntries );
     180             :     }
     181             : 
     182        2160 :     return -1;
     183             : }
     184             : 
     185             : 
     186             : /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
     187         118 : sal_Int32 XMLPropertySetMapper::FindEntryIndex(
     188             :         const sal_Char* sApiName,
     189             :         sal_uInt16 nNameSpace,
     190             :         const OUString& sXMLName ) const
     191             : {
     192         118 :     sal_Int32 nIndex = 0;
     193         118 :     sal_Int32 nEntries = GetEntryCount();
     194             : 
     195        9580 :     do
     196             :     {
     197        9698 :         const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
     198       24784 :         if( rEntry.nXMLNameSpace == nNameSpace &&
     199        9904 :             rEntry.sXMLAttributeName.equals( sXMLName ) &&
     200         206 :             0 == rEntry.sAPIPropertyName.compareToAscii( sApiName ) )
     201         118 :             return nIndex;
     202             :         else
     203        9580 :             nIndex++;
     204             : 
     205             :     } while( nIndex < nEntries );
     206             : 
     207           0 :     return -1;
     208             : }
     209             : 
     210         880 : sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const
     211             : {
     212         880 :     const sal_Int32 nEntries = GetEntryCount();
     213             : 
     214         880 :     if ( nEntries )
     215             :     {
     216         880 :         sal_Int32 nIndex = 0;
     217       40387 :         do
     218             :         {
     219       41267 :             const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
     220       41267 :             if( rEntry.nContextId == nContextId )
     221         880 :                 return nIndex;
     222             :             else
     223       40387 :                 nIndex++;
     224             : 
     225             :         } while( nIndex < nEntries );
     226             :     }
     227             : 
     228           0 :     return -1;
     229             : }
     230             : 
     231          22 : void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex )
     232             : {
     233          22 :     const sal_Int32 nEntries = GetEntryCount();
     234          22 :     if( nIndex>=nEntries || nIndex<0 )
     235          22 :         return;
     236          22 :     vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin();
     237        2882 :     for( sal_Int32 nN=0; nN<nIndex; nN++ )
     238        2860 :         ++aEIter;
     239          22 :     aMapEntries.erase( aEIter );
     240             : }
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10