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 #include <com/sun/star/packages/zip/ZipConstants.hpp>
35 #include <osl/diagnose.h>
37 #include <ZipPackageFolder.hxx>
38 #include <ZipPackageStream.hxx>
39 #include <ContentInfo.hxx>
41 #include <comphelper/storagehelper.hxx>
44 using namespace com::sun::star
;
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::lang
;
47 using namespace com::sun::star::container
;
48 using namespace com::sun::star::packages::zip
;
49 using namespace com::sun::star::packages::zip::ZipConstants
;
51 ZipPackageEntry::ZipPackageEntry ( bool bNewFolder
)
52 : mbIsFolder ( bNewFolder
)
53 , mbAllowRemoveOnInsert( sal_True
)
58 ZipPackageEntry::~ZipPackageEntry()
60 // When the entry is destroyed it must be already disconnected from the parent
61 OSL_ENSURE( !pParent
, "The parent must be disconnected already! Memory corruption is possible!\n" );
65 OUString SAL_CALL
ZipPackageEntry::getName( )
66 throw(RuntimeException
)
70 void SAL_CALL
ZipPackageEntry::setName( const OUString
& aName
)
71 throw(RuntimeException
)
73 if ( pParent
&& pParent
->hasByName ( aEntry
.sName
) )
74 pParent
->removeByName ( aEntry
.sName
);
76 // unfortunately no other exception than RuntimeException can be thrown here
77 // usually the package is used through storage implementation, the problem should be detected there
78 if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName
, sal_True
) )
79 throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"Unexpected character is used in file name." ) ), Reference
< XInterface
>() );
84 pParent
->doInsertByName ( this, sal_False
);
86 Reference
< XInterface
> SAL_CALL
ZipPackageEntry::getParent( )
87 throw(RuntimeException
)
89 // return Reference< XInterface >( xParent, UNO_QUERY );
90 return Reference
< XInterface
>( static_cast< ::cppu::OWeakObject
* >( pParent
), UNO_QUERY
);
93 void ZipPackageEntry::doSetParent ( ZipPackageFolder
* pNewParent
, sal_Bool bInsert
)
95 // xParent = pParent = pNewParent;
97 if ( bInsert
&& !pNewParent
->hasByName ( aEntry
.sName
) )
98 pNewParent
->doInsertByName ( this, sal_False
);
101 void SAL_CALL
ZipPackageEntry::setParent( const Reference
< XInterface
>& xNewParent
)
102 throw(NoSupportException
, RuntimeException
)
105 Reference
< XUnoTunnel
> xTunnel ( xNewParent
, UNO_QUERY
);
106 if ( !xNewParent
.is() || ( nTest
= xTunnel
->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 )
107 throw NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>() );
109 ZipPackageFolder
*pNewParent
= reinterpret_cast < ZipPackageFolder
* > ( nTest
);
111 if ( pNewParent
!= pParent
)
113 if ( pParent
&& pParent
->hasByName ( aEntry
.sName
) && mbAllowRemoveOnInsert
)
114 pParent
->removeByName( aEntry
.sName
);
115 doSetParent ( pNewParent
, sal_True
);
119 Reference
< beans::XPropertySetInfo
> SAL_CALL
ZipPackageEntry::getPropertySetInfo( )
120 throw(RuntimeException
)
122 return Reference
< beans::XPropertySetInfo
> ();
124 void SAL_CALL
ZipPackageEntry::addPropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
125 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
128 void SAL_CALL
ZipPackageEntry::removePropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
129 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
132 void SAL_CALL
ZipPackageEntry::addVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
133 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
136 void SAL_CALL
ZipPackageEntry::removeVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
137 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)