LCOV - code coverage report
Current view: top level - editeng/source/items - xmlcnitm.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 34 91 37.4 %
Date: 2014-04-11 Functions: 13 26 50.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 <com/sun/star/xml/AttributeData.hpp>
      21             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      22             : #include <xmloff/xmlcnimp.hxx>
      23             : #include <xmloff/unoatrcn.hxx>
      24             : #include <editeng/xmlcnitm.hxx>
      25             : 
      26             : using namespace ::com::sun::star::uno;
      27             : using namespace ::com::sun::star::container;
      28             : using namespace ::com::sun::star::lang;
      29             : using namespace ::com::sun::star::xml;
      30             : 
      31             : 
      32      229311 : TYPEINIT1(SvXMLAttrContainerItem, SfxPoolItem);
      33             : 
      34        4112 : SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich ) :
      35        4112 :     SfxPoolItem( _nWhich )
      36             : {
      37        4112 :     pImpl = new SvXMLAttrContainerData;
      38        4112 : }
      39             : 
      40        2215 : SvXMLAttrContainerItem::SvXMLAttrContainerItem(
      41             :                                         const SvXMLAttrContainerItem& rItem ) :
      42        2215 :     SfxPoolItem( rItem )
      43             : {
      44        2215 :     pImpl = new SvXMLAttrContainerData( *rItem.pImpl );
      45        2215 : }
      46             : 
      47       17643 : SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
      48             : {
      49        5895 :     delete pImpl;
      50       11748 : }
      51             : 
      52        4182 : bool SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const
      53             : {
      54             :     DBG_ASSERT( rItem.ISA(SvXMLAttrContainerItem),
      55             :                "SvXMLAttrContainerItem::operator ==(): Bad type");
      56        4182 :     return *pImpl == *((const SvXMLAttrContainerItem&)rItem).pImpl;
      57             : }
      58             : 
      59           0 : int SvXMLAttrContainerItem::Compare( const SfxPoolItem &/*rWith*/ ) const
      60             : {
      61             :     DBG_ASSERT( !this, "not yet implemented" );
      62             : 
      63           0 :     return 0;
      64             : }
      65             : 
      66           0 : SfxItemPresentation SvXMLAttrContainerItem::GetPresentation(
      67             :                     SfxItemPresentation /*ePresentation*/,
      68             :                     SfxMapUnit /*eCoreMetric*/,
      69             :                     SfxMapUnit /*ePresentationMetric*/,
      70             :                     OUString & /*rText*/,
      71             :                     const IntlWrapper * /*pIntlWrapper*/ ) const
      72             : {
      73           0 :     return SFX_ITEM_PRESENTATION_NONE;
      74             : }
      75             : 
      76       13776 : sal_uInt16 SvXMLAttrContainerItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
      77             : {
      78             :     // This item should never be stored
      79       13776 :     return USHRT_MAX;
      80             : }
      81             : 
      82         304 : bool SvXMLAttrContainerItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
      83             : {
      84             :     Reference<XNameContainer> xContainer =
      85         304 :         new SvUnoAttributeContainer( new SvXMLAttrContainerData( *pImpl ) );
      86             : 
      87         304 :     rVal.setValue( &xContainer, ::getCppuType((Reference<XNameContainer>*)0) );
      88         304 :     return true;
      89             : }
      90             : 
      91          15 : bool SvXMLAttrContainerItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
      92             : {
      93          15 :     Reference<XInterface> xRef;
      94          15 :     SvUnoAttributeContainer* pContainer = NULL;
      95             : 
      96          15 :     if( rVal.getValue() != NULL && rVal.getValueType().getTypeClass() == TypeClass_INTERFACE )
      97             :     {
      98          15 :         xRef = *(Reference<XInterface>*)rVal.getValue();
      99          15 :         Reference<XUnoTunnel> xTunnel(xRef, UNO_QUERY);
     100          15 :         if( xTunnel.is() )
     101          15 :             pContainer = (SvUnoAttributeContainer*)(sal_uLong)xTunnel->getSomething(SvUnoAttributeContainer::getUnoTunnelId());
     102             :     }
     103             : 
     104          15 :     if( pContainer )
     105             :     {
     106          15 :         delete pImpl;
     107          15 :         pImpl = new SvXMLAttrContainerData( * pContainer->GetContainerImpl() );
     108             :     }
     109             :     else
     110             :     {
     111           0 :         std::auto_ptr<SvXMLAttrContainerData> pNewImpl(new SvXMLAttrContainerData);
     112             : 
     113             :         try
     114             :         {
     115           0 :             Reference<XNameContainer> xContainer( xRef, UNO_QUERY );
     116           0 :             if( !xContainer.is() )
     117           0 :                 return false;
     118             : 
     119           0 :             const Sequence< OUString > aNameSequence( xContainer->getElementNames() );
     120           0 :             const OUString* pNames = aNameSequence.getConstArray();
     121           0 :             const sal_Int32 nCount = aNameSequence.getLength();
     122           0 :             Any aAny;
     123             :             AttributeData* pData;
     124             :             sal_Int32 nAttr;
     125             : 
     126           0 :             for( nAttr = 0; nAttr < nCount; nAttr++ )
     127             :             {
     128           0 :                 const OUString aName( *pNames++ );
     129             : 
     130           0 :                 aAny = xContainer->getByName( aName );
     131           0 :                 if( aAny.getValue() == NULL || aAny.getValueType() != ::getCppuType((AttributeData*)0) )
     132           0 :                     return false;
     133             : 
     134           0 :                 pData = (AttributeData*)aAny.getValue();
     135           0 :                 sal_Int32 pos = aName.indexOf( ':' );
     136           0 :                 if( pos != -1 )
     137             :                 {
     138           0 :                     const OUString aPrefix( aName.copy( 0, pos ));
     139           0 :                     const OUString aLName( aName.copy( pos+1 ));
     140             : 
     141           0 :                     if( pData->Namespace.isEmpty() )
     142             :                     {
     143           0 :                         if( !pNewImpl->AddAttr( aPrefix, aLName, pData->Value ) )
     144           0 :                             break;
     145             :                     }
     146             :                     else
     147             :                     {
     148           0 :                         if( !pNewImpl->AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
     149           0 :                             break;
     150           0 :                     }
     151             :                 }
     152             :                 else
     153             :                 {
     154           0 :                     if( !pNewImpl->AddAttr( aName, pData->Value ) )
     155           0 :                         break;
     156             :                 }
     157           0 :             }
     158             : 
     159           0 :             if( nAttr == nCount )
     160           0 :                 pImpl = pNewImpl.release();
     161             :             else
     162           0 :                 return false;
     163             :         }
     164           0 :         catch(...)
     165             :         {
     166           0 :             return false;
     167           0 :         }
     168             :     }
     169          15 :     return true;
     170             : }
     171             : 
     172             : 
     173           0 : bool SvXMLAttrContainerItem::AddAttr( const OUString& rLName,
     174             :                                         const OUString& rValue )
     175             : {
     176           0 :     return pImpl->AddAttr( rLName, rValue );
     177             : }
     178             : 
     179           0 : bool SvXMLAttrContainerItem::AddAttr( const OUString& rPrefix,
     180             :           const OUString& rNamespace, const OUString& rLName,
     181             :           const OUString& rValue )
     182             : {
     183           0 :     return pImpl->AddAttr( rPrefix, rNamespace, rLName, rValue );
     184             : }
     185             : 
     186          16 : sal_uInt16 SvXMLAttrContainerItem::GetAttrCount() const
     187             : {
     188          16 :     return (sal_uInt16)pImpl->GetAttrCount();
     189             : }
     190             : 
     191           0 : OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const
     192             : {
     193           0 :     return pImpl->GetAttrNamespace( i );
     194             : }
     195             : 
     196           0 : OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const
     197             : {
     198           0 :     return pImpl->GetAttrPrefix( i );
     199             : }
     200             : 
     201           0 : const OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const
     202             : {
     203           0 :     return pImpl->GetAttrLName( i );
     204             : }
     205             : 
     206           0 : const OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const
     207             : {
     208           0 :     return pImpl->GetAttrValue( i );
     209             : }
     210             : 
     211             : 
     212           0 : sal_uInt16 SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
     213             : {
     214           0 :     return pImpl->GetFirstNamespaceIndex();
     215             : }
     216             : 
     217           0 : sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
     218             : {
     219           0 :     return pImpl->GetNextNamespaceIndex( nIdx );
     220             : }
     221             : 
     222           0 : const OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const
     223             : {
     224           0 :     return pImpl->GetNamespace( i );
     225             : }
     226             : 
     227           0 : const OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const
     228             : {
     229           0 :     return pImpl->GetPrefix( i );
     230             : }
     231             : 
     232             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10