1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 #include <comphelper/servicehelper.hxx>
29 #include <comphelper/storagehelper.hxx>
31 using namespace com::sun::star
;
32 using namespace com::sun::star::uno
;
33 using namespace com::sun::star::lang
;
34 using namespace com::sun::star::container
;
35 using namespace com::sun::star::packages::zip
;
36 using namespace com::sun::star::packages::zip::ZipConstants
;
38 #if OSL_DEBUG_LEVEL > 0
39 #define THROW_WHERE SAL_WHERE
41 #define THROW_WHERE ""
44 ZipPackageEntry::ZipPackageEntry()
46 , mbAllowRemoveOnInsert(false)
47 , mpParent ( nullptr )
52 ZipPackageEntry::~ZipPackageEntry()
54 // When the entry is destroyed it must be already disconnected from the parent
55 OSL_ENSURE( !mpParent
, "The parent must be disconnected already! Memory corruption is possible!" );
59 OUString SAL_CALL
ZipPackageEntry::getName( )
63 void SAL_CALL
ZipPackageEntry::setName( const OUString
& aName
)
65 if ( mpParent
&& !msName
.isEmpty() && mpParent
->hasByName ( msName
) )
66 mpParent
->removeByName ( msName
);
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 if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName
, true ) )
71 throw RuntimeException(THROW_WHERE
"Unexpected character is used in file name." );
76 mpParent
->doInsertByName ( this, false );
78 uno::Reference
< XInterface
> SAL_CALL
ZipPackageEntry::getParent( )
80 // return uno::Reference< XInterface >( xParent, UNO_QUERY );
81 return cppu::getXWeak( mpParent
);
84 void ZipPackageEntry::doSetParent ( ZipPackageFolder
* pNewParent
)
86 // xParent = mpParent = pNewParent;
87 mpParent
= pNewParent
;
88 if ( !msName
.isEmpty() && !pNewParent
->hasByName ( msName
) )
89 pNewParent
->doInsertByName ( this, false );
92 void SAL_CALL
ZipPackageEntry::setParent( const uno::Reference
< XInterface
>& xNewParent
)
94 if ( !xNewParent
.is() )
95 throw NoSupportException(THROW_WHERE
);
96 ZipPackageFolder
* pNewParent
= dynamic_cast<ZipPackageFolder
*>(xNewParent
.get());
98 throw NoSupportException(THROW_WHERE
);
100 if ( pNewParent
!= mpParent
)
102 if ( mpParent
&& !msName
.isEmpty() && mpParent
->hasByName ( msName
) && mbAllowRemoveOnInsert
)
103 mpParent
->removeByName( msName
);
104 doSetParent ( pNewParent
);
108 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ZipPackageEntry::getPropertySetInfo( )
110 return uno::Reference
< beans::XPropertySetInfo
> ();
112 void SAL_CALL
ZipPackageEntry::addPropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
115 void SAL_CALL
ZipPackageEntry::removePropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
118 void SAL_CALL
ZipPackageEntry::addVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
121 void SAL_CALL
ZipPackageEntry::removeVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */