LCOV - code coverage report
Current view: top level - package/source/zippackage - ZipPackageEntry.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 29 45 64.4 %
Date: 2014-04-11 Functions: 6 13 46.2 %
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 <ZipPackageEntry.hxx>
      21             : #include <com/sun/star/packages/zip/ZipConstants.hpp>
      22             : #include <osl/diagnose.h>
      23             : 
      24             : #include <ZipPackageFolder.hxx>
      25             : #include <ZipPackageStream.hxx>
      26             : #include <ContentInfo.hxx>
      27             : 
      28             : #include <comphelper/storagehelper.hxx>
      29             : 
      30             : using namespace com::sun::star;
      31             : using namespace com::sun::star::uno;
      32             : using namespace com::sun::star::lang;
      33             : using namespace com::sun::star::container;
      34             : using namespace com::sun::star::packages::zip;
      35             : using namespace com::sun::star::packages::zip::ZipConstants;
      36             : 
      37             : #if OSL_DEBUG_LEVEL > 0
      38             : #define THROW_WHERE SAL_WHERE
      39             : #else
      40             : #define THROW_WHERE ""
      41             : #endif
      42             : 
      43      209594 : ZipPackageEntry::ZipPackageEntry ( bool bNewFolder )
      44             : : mbIsFolder ( bNewFolder )
      45             : , mbAllowRemoveOnInsert( true )
      46      209594 : , pParent ( NULL )
      47             : {
      48      209594 : }
      49             : 
      50      209031 : ZipPackageEntry::~ZipPackageEntry()
      51             : {
      52             :     // When the entry is destroyed it must be already disconnected from the parent
      53             :     OSL_ENSURE( !pParent, "The parent must be disconnected already! Memory corruption is possible!\n" );
      54      209031 : }
      55             : 
      56             : // XChild
      57      226391 : OUString SAL_CALL ZipPackageEntry::getName(  )
      58             :     throw(RuntimeException, std::exception)
      59             : {
      60      226391 :     return msName;
      61             : }
      62      159503 : void SAL_CALL ZipPackageEntry::setName( const OUString& aName )
      63             :     throw(RuntimeException, std::exception)
      64             : {
      65      159503 :     if ( pParent && !msName.isEmpty() && pParent->hasByName ( msName ) )
      66           1 :         pParent->removeByName ( msName );
      67             : 
      68             :     // unfortunately no other exception than RuntimeException can be thrown here
      69             :     // usually the package is used through storage implementation, the problem should be detected there
      70      159503 :     if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, true ) )
      71           0 :         throw RuntimeException(THROW_WHERE "Unexpected character is used in file name.", uno::Reference< XInterface >() );
      72             : 
      73      159503 :     msName = aName;
      74             : 
      75      159503 :     if ( pParent )
      76           0 :         pParent->doInsertByName ( this, sal_False );
      77      159503 : }
      78           0 : uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent(  )
      79             :         throw(RuntimeException, std::exception)
      80             : {
      81             :     // return uno::Reference< XInterface >( xParent, UNO_QUERY );
      82           0 :     return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY );
      83             : }
      84             : 
      85      159505 : void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert )
      86             : {
      87             :     // xParent = pParent = pNewParent;
      88      159505 :     pParent = pNewParent;
      89      159505 :     if ( bInsert && !msName.isEmpty() && !pNewParent->hasByName ( msName ) )
      90      149883 :         pNewParent->doInsertByName ( this, sal_False );
      91      159505 : }
      92             : 
      93        9622 : void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent )
      94             :         throw(NoSupportException, RuntimeException, std::exception)
      95             : {
      96        9622 :     sal_Int64 nTest(0);
      97        9622 :     uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY );
      98        9622 :     if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 )
      99           0 :         throw NoSupportException(THROW_WHERE, uno::Reference< uno::XInterface >() );
     100             : 
     101        9622 :     ZipPackageFolder *pNewParent = reinterpret_cast < ZipPackageFolder * > ( nTest );
     102             : 
     103        9622 :     if ( pNewParent != pParent )
     104             :     {
     105        9622 :         if ( pParent && !msName.isEmpty() && pParent->hasByName ( msName ) && mbAllowRemoveOnInsert )
     106           0 :             pParent->removeByName( msName );
     107        9622 :         doSetParent ( pNewParent, sal_True );
     108        9622 :     }
     109        9622 : }
     110             :     //XPropertySet
     111           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo(  )
     112             :         throw(RuntimeException, std::exception)
     113             : {
     114           0 :     return uno::Reference < beans::XPropertySetInfo > ();
     115             : }
     116           0 : void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
     117             :         throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     118             : {
     119           0 : }
     120           0 : void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
     121             :         throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     122             : {
     123           0 : }
     124           0 : void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
     125             :         throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     126             : {
     127           0 : }
     128           0 : void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
     129             :         throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     130             : {
     131           0 : }
     132             : 
     133             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10