1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ZipPackageEntry.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_package.hxx"
33 #include <ZipPackageEntry.hxx>
34 #ifndef _COM_SUN_STAR_PACKAGE_ZIP_ZIPCONSTANTS_HPP_
35 #include <com/sun/star/packages/zip/ZipConstants.hpp>
37 #include <vos/diagnose.hxx>
39 #include <ZipPackageFolder.hxx>
40 #include <ZipPackageStream.hxx>
41 #include <ContentInfo.hxx>
43 #include <comphelper/storagehelper.hxx>
46 using namespace com::sun::star
;
47 using namespace com::sun::star::uno
;
48 using namespace com::sun::star::lang
;
49 using namespace com::sun::star::container
;
50 using namespace com::sun::star::packages::zip
;
51 using namespace com::sun::star::packages::zip::ZipConstants
;
53 ZipPackageEntry::ZipPackageEntry ( bool bNewFolder
)
54 : mbIsFolder ( bNewFolder
)
55 , mbAllowRemoveOnInsert( sal_True
)
60 ZipPackageEntry::~ZipPackageEntry()
62 // When the entry is destroyed it must be already disconnected from the parent
63 OSL_ENSURE( !pParent
, "The parent must be disconnected already! Memory corruption is possible!\n" );
67 OUString SAL_CALL
ZipPackageEntry::getName( )
68 throw(RuntimeException
)
72 void SAL_CALL
ZipPackageEntry::setName( const OUString
& aName
)
73 throw(RuntimeException
)
75 if ( pParent
&& pParent
->hasByName ( aEntry
.sName
) )
76 pParent
->removeByName ( aEntry
.sName
);
78 // unfortunately no other exception than RuntimeException can be thrown here
79 // usually the package is used through storage implementation, the problem should be detected there
80 if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName
, sal_True
) )
81 throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference
< XInterface
>() );
86 pParent
->doInsertByName ( this, sal_False
);
88 Reference
< XInterface
> SAL_CALL
ZipPackageEntry::getParent( )
89 throw(RuntimeException
)
91 // return Reference< XInterface >( xParent, UNO_QUERY );
92 return Reference
< XInterface
>( static_cast< ::cppu::OWeakObject
* >( pParent
), UNO_QUERY
);
95 void ZipPackageEntry::doSetParent ( ZipPackageFolder
* pNewParent
, sal_Bool bInsert
)
97 // xParent = pParent = pNewParent;
99 if ( bInsert
&& !pNewParent
->hasByName ( aEntry
.sName
) )
100 pNewParent
->doInsertByName ( this, sal_False
);
103 void SAL_CALL
ZipPackageEntry::setParent( const Reference
< XInterface
>& xNewParent
)
104 throw(NoSupportException
, RuntimeException
)
107 Reference
< XUnoTunnel
> xTunnel ( xNewParent
, UNO_QUERY
);
108 if ( !xNewParent
.is() || ( nTest
= xTunnel
->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 )
109 throw NoSupportException();
111 ZipPackageFolder
*pNewParent
= reinterpret_cast < ZipPackageFolder
* > ( nTest
);
113 if ( pNewParent
!= pParent
)
115 if ( pParent
&& pParent
->hasByName ( aEntry
.sName
) && mbAllowRemoveOnInsert
)
116 pParent
->removeByName( aEntry
.sName
);
117 doSetParent ( pNewParent
, sal_True
);
121 Reference
< beans::XPropertySetInfo
> SAL_CALL
ZipPackageEntry::getPropertySetInfo( )
122 throw(RuntimeException
)
124 return Reference
< beans::XPropertySetInfo
> ();
126 void SAL_CALL
ZipPackageEntry::addPropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
127 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
130 void SAL_CALL
ZipPackageEntry::removePropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
131 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
134 void SAL_CALL
ZipPackageEntry::addVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
135 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
138 void SAL_CALL
ZipPackageEntry::removeVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
139 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)