bump product version to 6.4.0.3
[LibreOffice.git] / package / source / zippackage / ZipPackageEntry.cxx
blob35789653b35dd05602b8cf24d1cafb6d38f95852
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <ZipPackageEntry.hxx>
21 #include <com/sun/star/lang/NoSupportException.hpp>
22 #include <com/sun/star/packages/zip/ZipConstants.hpp>
23 #include <osl/diagnose.h>
24 #include <sal/log.hxx>
26 #include <ZipPackageFolder.hxx>
27 #include <ZipPackageStream.hxx>
28 #include "ContentInfo.hxx"
30 #include <comphelper/storagehelper.hxx>
32 using namespace com::sun::star;
33 using namespace com::sun::star::uno;
34 using namespace com::sun::star::lang;
35 using namespace com::sun::star::container;
36 using namespace com::sun::star::packages::zip;
37 using namespace com::sun::star::packages::zip::ZipConstants;
39 #if OSL_DEBUG_LEVEL > 0
40 #define THROW_WHERE SAL_WHERE
41 #else
42 #define THROW_WHERE ""
43 #endif
45 ZipPackageEntry::ZipPackageEntry()
46 : mbIsFolder( false )
47 , mbAllowRemoveOnInsert(false)
48 , mpParent ( nullptr )
49 , m_nFormat(0)
53 ZipPackageEntry::~ZipPackageEntry()
55 // When the entry is destroyed it must be already disconnected from the parent
56 OSL_ENSURE( !mpParent, "The parent must be disconnected already! Memory corruption is possible!" );
59 // XChild
60 OUString SAL_CALL ZipPackageEntry::getName( )
62 return msName;
64 void SAL_CALL ZipPackageEntry::setName( const OUString& aName )
66 if ( mpParent && !msName.isEmpty() && mpParent->hasByName ( msName ) )
67 mpParent->removeByName ( msName );
69 // unfortunately no other exception than RuntimeException can be thrown here
70 // usually the package is used through storage implementation, the problem should be detected there
71 if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, true ) )
72 throw RuntimeException(THROW_WHERE "Unexpected character is used in file name." );
74 msName = aName;
76 if ( mpParent )
77 mpParent->doInsertByName ( this, false );
79 uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( )
81 // return uno::Reference< XInterface >( xParent, UNO_QUERY );
82 return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( mpParent ), UNO_QUERY );
85 void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent )
87 // xParent = mpParent = pNewParent;
88 mpParent = pNewParent;
89 if ( !msName.isEmpty() && !pNewParent->hasByName ( msName ) )
90 pNewParent->doInsertByName ( this, false );
93 void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent )
95 sal_Int64 nTest(0);
96 uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY );
97 if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::getUnoTunnelId () ) ) == 0 )
98 throw NoSupportException(THROW_WHERE );
100 ZipPackageFolder *pNewParent = reinterpret_cast < ZipPackageFolder * > ( nTest );
102 if ( pNewParent != mpParent )
104 if ( mpParent && !msName.isEmpty() && mpParent->hasByName ( msName ) && mbAllowRemoveOnInsert )
105 mpParent->removeByName( msName );
106 doSetParent ( pNewParent );
109 //XPropertySet
110 uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( )
112 return uno::Reference < beans::XPropertySetInfo > ();
114 void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
117 void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
120 void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
123 void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */