LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/xml - XMLCodeNameProvider.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 91 0.0 %
Date: 2012-12-27 Functions: 0 10 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 "XMLCodeNameProvider.hxx"
      21             : #include "document.hxx"
      22             : 
      23             : using namespace com::sun::star;
      24             : 
      25             : using ::rtl::OUString;
      26             : 
      27           0 : sal_Bool XMLCodeNameProvider::_getCodeName( const uno::Any& aAny, String& rCodeName )
      28             : {
      29           0 :     uno::Sequence<beans::PropertyValue> aProps;
      30           0 :     if( !(aAny >>= aProps) )
      31           0 :         return false;
      32             : 
      33           0 :     OUString sCodeNameProp( RTL_CONSTASCII_USTRINGPARAM("CodeName") );
      34           0 :     sal_Int32 nPropCount = aProps.getLength();
      35           0 :     for( sal_Int32 i=0; i<nPropCount; i++ )
      36             :     {
      37           0 :         if( aProps[i].Name == sCodeNameProp )
      38             :         {
      39           0 :             OUString sCodeName;
      40           0 :             if( aProps[i].Value >>= sCodeName )
      41             :             {
      42           0 :                 rCodeName = sCodeName;
      43           0 :                 return sal_True;
      44           0 :             }
      45             :         }
      46             :     }
      47             : 
      48           0 :     return false;
      49             : }
      50             : 
      51             : 
      52           0 : XMLCodeNameProvider::XMLCodeNameProvider( ScDocument* pDoc ) :
      53             :     mpDoc( pDoc ),
      54             :     msDocName( RTL_CONSTASCII_USTRINGPARAM("*doc*") ),
      55           0 :     msCodeNameProp( RTL_CONSTASCII_USTRINGPARAM("CodeName") )
      56             : {
      57           0 : }
      58             : 
      59           0 : XMLCodeNameProvider::~XMLCodeNameProvider()
      60             : {
      61           0 : }
      62             : 
      63           0 : ::sal_Bool SAL_CALL XMLCodeNameProvider::hasByName( const OUString& aName )
      64             :     throw (uno::RuntimeException )
      65             : {
      66           0 :     if( aName == msDocName )
      67           0 :         return !mpDoc->GetCodeName().isEmpty();
      68             : 
      69           0 :     SCTAB nCount = mpDoc->GetTableCount();
      70           0 :     rtl::OUString sSheetName, sCodeName;
      71           0 :     for( SCTAB i = 0; i < nCount; i++ )
      72             :     {
      73           0 :         if( mpDoc->GetName( i, sSheetName ) && sSheetName.equals(aName) )
      74             :         {
      75           0 :             mpDoc->GetCodeName( i, sCodeName );
      76           0 :             return !sCodeName.isEmpty();
      77             :         }
      78             :     }
      79             : 
      80           0 :     return false;
      81             : }
      82             : 
      83           0 : uno::Any SAL_CALL XMLCodeNameProvider::getByName( const OUString& aName )
      84             :     throw (container::NoSuchElementException,
      85             :            lang::WrappedTargetException, uno::RuntimeException)
      86             : {
      87           0 :     uno::Any aRet;
      88           0 :     uno::Sequence<beans::PropertyValue> aProps(1);
      89           0 :     aProps[0].Name = msCodeNameProp;
      90           0 :     if( aName == msDocName )
      91             :     {
      92           0 :         OUString sUCodeName( mpDoc->GetCodeName() );
      93           0 :         aProps[0].Value <<= sUCodeName;
      94           0 :         aRet <<= aProps;
      95           0 :         return aRet;
      96             :     }
      97             : 
      98           0 :     SCTAB nCount = mpDoc->GetTableCount();
      99           0 :     rtl::OUString sSheetName, sCodeName;
     100           0 :     for( SCTAB i = 0; i < nCount; i++ )
     101             :     {
     102           0 :         if( mpDoc->GetName( i, sSheetName ) && sSheetName.equals(aName) )
     103             :         {
     104           0 :             mpDoc->GetCodeName( i, sCodeName );
     105           0 :             aProps[0].Value <<= sCodeName;
     106           0 :             aRet <<= aProps;
     107             :             return aRet;
     108             :         }
     109             :     }
     110             : 
     111           0 :     return aRet;
     112             : }
     113             : 
     114           0 : uno::Sequence< OUString > SAL_CALL XMLCodeNameProvider::getElementNames(  )
     115             :     throw (uno::RuntimeException)
     116             : {
     117           0 :     SCTAB nCount = mpDoc->GetTableCount() + 1;
     118           0 :     uno::Sequence< OUString > aNames( nCount );
     119           0 :     sal_Int32 nRealCount = 0;
     120             : 
     121           0 :     if( !mpDoc->GetCodeName().isEmpty() )
     122           0 :         aNames[nRealCount++] = msDocName;
     123             : 
     124           0 :     rtl::OUString sSheetName, sCodeName;
     125           0 :     for( SCTAB i = 0; i < nCount; i++ )
     126             :     {
     127           0 :         mpDoc->GetCodeName( i, sCodeName );
     128           0 :         if (!sCodeName.isEmpty())
     129             :         {
     130           0 :             if( mpDoc->GetName( i, sSheetName ) )
     131           0 :                 aNames[nRealCount++] = sSheetName;
     132             :         }
     133             :     }
     134             : 
     135           0 :     if( nCount != nRealCount )
     136           0 :         aNames.realloc( nRealCount );
     137             : 
     138           0 :     return aNames;
     139             : }
     140             : 
     141           0 : uno::Type SAL_CALL XMLCodeNameProvider::getElementType(  )
     142             :     throw (uno::RuntimeException)
     143             : {
     144           0 :     return getCppuType(static_cast<uno::Sequence<beans::PropertyValue>*>(0));
     145             : }
     146             : 
     147           0 : ::sal_Bool SAL_CALL XMLCodeNameProvider::hasElements()
     148             :     throw (uno::RuntimeException )
     149             : {
     150           0 :     if( !mpDoc->GetCodeName().isEmpty() )
     151           0 :         return sal_True;
     152             : 
     153           0 :     SCTAB nCount = mpDoc->GetTableCount();
     154           0 :     rtl::OUString sSheetName, sCodeName;
     155           0 :     for( SCTAB i = 0; i < nCount; i++ )
     156             :     {
     157           0 :         mpDoc->GetCodeName( i, sCodeName );
     158           0 :         if (!sCodeName.isEmpty() && mpDoc->GetName(i, sSheetName))
     159           0 :             return sal_True;
     160             :     }
     161             : 
     162           0 :     return false;
     163             : }
     164             : 
     165           0 : void XMLCodeNameProvider::set( const uno::Reference< container::XNameAccess>& xNameAccess, ScDocument *pDoc )
     166             : {
     167           0 :     uno::Any aAny;
     168           0 :     OUString sDocName( RTL_CONSTASCII_USTRINGPARAM("*doc*") );
     169           0 :     String sCodeName;
     170           0 :     if( xNameAccess->hasByName( sDocName ) )
     171             :     {
     172           0 :         aAny = xNameAccess->getByName( sDocName );
     173           0 :         if( _getCodeName( aAny, sCodeName ) )
     174           0 :             pDoc->SetCodeName( sCodeName );
     175             :     }
     176             : 
     177           0 :     SCTAB nCount = pDoc->GetTableCount();
     178           0 :     rtl::OUString sSheetName;
     179           0 :     for( SCTAB i = 0; i < nCount; i++ )
     180             :     {
     181           0 :         if( pDoc->GetName( i, sSheetName ) &&
     182           0 :             xNameAccess->hasByName( sSheetName ) )
     183             :         {
     184           0 :             aAny = xNameAccess->getByName( sSheetName );
     185           0 :             if( _getCodeName( aAny, sCodeName ) )
     186           0 :                 pDoc->SetCodeName( i, sCodeName );
     187             :         }
     188           0 :     }
     189           0 : }
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10