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

Generated by: LCOV version 1.10