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

Generated by: LCOV version 1.10