LCOV - code coverage report
Current view: top level - xmloff/source/style - xmlprmap.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 90 0.0 %
Date: 2014-04-14 Functions: 0 12 0.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           0 : XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
      37             :     const XMLPropertyMapEntry& rMapEntry,
      38             :     const UniReference< XMLPropertyHandlerFactory >& rFactory ) :
      39           0 :     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           0 :     pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) )
      48             : {
      49           0 : }
      50             : 
      51           0 : 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           0 :     pHdl( rEntry.pHdl)
      61             : {
      62             :     DBG_ASSERT( pHdl, "Unknown XML property type handler!" );
      63           0 : }
      64             : 
      65             : // Ctor
      66           0 : XMLPropertySetMapper::XMLPropertySetMapper(
      67             :         const XMLPropertyMapEntry* pEntries,
      68             :         const UniReference< XMLPropertyHandlerFactory >& rFactory,
      69             :         bool bForExport )
      70             :     :
      71           0 :         mbOnlyExportMappings( bForExport)
      72             : {
      73           0 :     aHdlFactories.push_back( rFactory );
      74           0 :     if( pEntries )
      75             :     {
      76           0 :         const XMLPropertyMapEntry* pIter = pEntries;
      77             : 
      78           0 :         if (mbOnlyExportMappings)
      79             :         {
      80           0 :             while( pIter->msApiName )
      81             :             {
      82           0 :                 if (!pIter->mbImportOnly)
      83             :                 {
      84           0 :                     XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
      85           0 :                     aMapEntries.push_back( aEntry );
      86             :                 }
      87           0 :                 pIter++;
      88             :             }
      89             :         }
      90             :         else
      91             :         {
      92           0 :             while( pIter->msApiName )
      93             :             {
      94           0 :                 XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
      95           0 :                 aMapEntries.push_back( aEntry );
      96           0 :                 pIter++;
      97           0 :             }
      98             :         }
      99             :     }
     100           0 : }
     101             : 
     102           0 : XMLPropertySetMapper::~XMLPropertySetMapper()
     103             : {
     104           0 : }
     105             : 
     106           0 : void XMLPropertySetMapper::AddMapperEntry(
     107             :     const UniReference < XMLPropertySetMapper >& rMapper )
     108             : {
     109           0 :     for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator
     110           0 :             aFIter = rMapper->aHdlFactories.begin();
     111           0 :          aFIter != rMapper->aHdlFactories.end();
     112             :          ++aFIter )
     113             :     {
     114           0 :         aHdlFactories.push_back( *aFIter );
     115             :     }
     116             : 
     117           0 :     for( vector < XMLPropertySetMapperEntry_Impl >::iterator
     118           0 :             aEIter = rMapper->aMapEntries.begin();
     119           0 :          aEIter != rMapper->aMapEntries.end();
     120             :          ++aEIter )
     121             :     {
     122           0 :         if (!mbOnlyExportMappings || !(*aEIter).bImportOnly)
     123           0 :             aMapEntries.push_back( *aEIter );
     124             :     }
     125           0 : }
     126             : 
     127             : // Export a Property
     128           0 : bool XMLPropertySetMapper::exportXML(
     129             :         OUString& rStrExpValue,
     130             :         const XMLPropertyState& rProperty,
     131             :         const SvXMLUnitConverter& rUnitConverter ) const
     132             : {
     133           0 :     bool bRet = false;
     134             : 
     135           0 :     const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
     136             : 
     137             :     DBG_ASSERT( pHdl, "Unknown XML Type!" );
     138           0 :     if( pHdl )
     139             :         bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue,
     140           0 :                                 rUnitConverter );
     141             : 
     142           0 :     return bRet;
     143             : }
     144             : 
     145             : // Import a Property
     146           0 : bool XMLPropertySetMapper::importXML(
     147             :         const OUString& rStrImpValue,
     148             :         XMLPropertyState& rProperty,
     149             :         const SvXMLUnitConverter& rUnitConverter ) const
     150             : {
     151           0 :     bool bRet = false;
     152             : 
     153           0 :     const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
     154             : 
     155           0 :     if( pHdl )
     156             :         bRet = pHdl->importXML( rStrImpValue, rProperty.maValue,
     157           0 :                                 rUnitConverter );
     158             : 
     159           0 :     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           0 : sal_Int32 XMLPropertySetMapper::GetEntryIndex(
     166             :         sal_uInt16 nNamespace,
     167             :         const OUString& rStrName,
     168             :         sal_uInt32 nPropType,
     169             :         sal_Int32 nStartAt /* = -1 */ ) const
     170             : {
     171           0 :     sal_Int32 nEntries = GetEntryCount();
     172           0 :     sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1;
     173             : 
     174           0 :     if ( nEntries )
     175             :     {
     176           0 :         do
     177             :         {
     178           0 :             const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
     179           0 :             if( (!nPropType || nPropType == rEntry.GetPropType()) &&
     180           0 :                 rEntry.nXMLNameSpace == nNamespace &&
     181           0 :                 rStrName == rEntry.sXMLAttributeName )
     182           0 :                 return nIndex;
     183             :             else
     184           0 :                 nIndex++;
     185             : 
     186             :         } while( nIndex<nEntries );
     187             :     }
     188             : 
     189           0 :     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           0 : sal_Int32 XMLPropertySetMapper::FindEntryIndex(
     194             :         const sal_Char* sApiName,
     195             :         sal_uInt16 nNameSpace,
     196             :         const OUString& sXMLName ) const
     197             : {
     198           0 :     sal_Int32 nIndex = 0;
     199           0 :     sal_Int32 nEntries = GetEntryCount();
     200             : 
     201           0 :     do
     202             :     {
     203           0 :         const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
     204           0 :         if( rEntry.nXMLNameSpace == nNameSpace &&
     205           0 :             rEntry.sXMLAttributeName.equals( sXMLName ) &&
     206           0 :             rEntry.sAPIPropertyName.equalsAscii( sApiName ) )
     207           0 :             return nIndex;
     208             :         else
     209           0 :             nIndex++;
     210             : 
     211             :     } while( nIndex < nEntries );
     212             : 
     213           0 :     return -1;
     214             : }
     215             : 
     216           0 : sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const
     217             : {
     218           0 :     const sal_Int32 nEntries = GetEntryCount();
     219             : 
     220           0 :     if ( nEntries )
     221             :     {
     222           0 :         sal_Int32 nIndex = 0;
     223           0 :         do
     224             :         {
     225           0 :             const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
     226           0 :             if( rEntry.nContextId == nContextId )
     227           0 :                 return nIndex;
     228             :             else
     229           0 :                 nIndex++;
     230             : 
     231             :         } while( nIndex < nEntries );
     232             :     }
     233             : 
     234           0 :     return -1;
     235             : }
     236             : 
     237           0 : void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex )
     238             : {
     239           0 :     const sal_Int32 nEntries = GetEntryCount();
     240           0 :     if( nIndex>=nEntries || nIndex<0 )
     241           0 :         return;
     242           0 :     vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin();
     243           0 :     for( sal_Int32 nN=0; nN<nIndex; nN++ )
     244           0 :         ++aEIter;
     245           0 :     aMapEntries.erase( aEIter );
     246             : }
     247             : 
     248             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10