1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_package.hxx"
30 #include <ZipPackageEntry.hxx>
31 #include <com/sun/star/packages/zip/ZipConstants.hpp>
32 #include <osl/diagnose.h>
34 #include <ZipPackageFolder.hxx>
35 #include <ZipPackageStream.hxx>
36 #include <ContentInfo.hxx>
38 #include <comphelper/storagehelper.hxx>
41 using namespace com::sun::star
;
42 using namespace com::sun::star::uno
;
43 using namespace com::sun::star::lang
;
44 using namespace com::sun::star::container
;
45 using namespace com::sun::star::packages::zip
;
46 using namespace com::sun::star::packages::zip::ZipConstants
;
48 ZipPackageEntry::ZipPackageEntry ( bool bNewFolder
)
49 : mbIsFolder ( bNewFolder
)
50 , mbAllowRemoveOnInsert( sal_True
)
55 ZipPackageEntry::~ZipPackageEntry()
57 // When the entry is destroyed it must be already disconnected from the parent
58 OSL_ENSURE( !pParent
, "The parent must be disconnected already! Memory corruption is possible!\n" );
62 OUString SAL_CALL
ZipPackageEntry::getName( )
63 throw(RuntimeException
)
67 void SAL_CALL
ZipPackageEntry::setName( const OUString
& aName
)
68 throw(RuntimeException
)
70 if ( pParent
&& msName
.getLength() && pParent
->hasByName ( msName
) )
71 pParent
->removeByName ( msName
);
73 // unfortunately no other exception than RuntimeException can be thrown here
74 // usually the package is used through storage implementation, the problem should be detected there
75 if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName
, sal_True
) )
76 throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
"Unexpected character is used in file name." ) ), uno::Reference
< XInterface
>() );
81 pParent
->doInsertByName ( this, sal_False
);
83 uno::Reference
< XInterface
> SAL_CALL
ZipPackageEntry::getParent( )
84 throw(RuntimeException
)
86 // return uno::Reference< XInterface >( xParent, UNO_QUERY );
87 return uno::Reference
< XInterface
>( static_cast< ::cppu::OWeakObject
* >( pParent
), UNO_QUERY
);
90 void ZipPackageEntry::doSetParent ( ZipPackageFolder
* pNewParent
, sal_Bool bInsert
)
92 // xParent = pParent = pNewParent;
94 if ( bInsert
&& msName
.getLength() && !pNewParent
->hasByName ( msName
) )
95 pNewParent
->doInsertByName ( this, sal_False
);
98 void SAL_CALL
ZipPackageEntry::setParent( const uno::Reference
< XInterface
>& xNewParent
)
99 throw(NoSupportException
, RuntimeException
)
102 uno::Reference
< XUnoTunnel
> xTunnel ( xNewParent
, UNO_QUERY
);
103 if ( !xNewParent
.is() || ( nTest
= xTunnel
->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 )
104 throw NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>() );
106 ZipPackageFolder
*pNewParent
= reinterpret_cast < ZipPackageFolder
* > ( nTest
);
108 if ( pNewParent
!= pParent
)
110 if ( pParent
&& msName
.getLength() && pParent
->hasByName ( msName
) && mbAllowRemoveOnInsert
)
111 pParent
->removeByName( msName
);
112 doSetParent ( pNewParent
, sal_True
);
116 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ZipPackageEntry::getPropertySetInfo( )
117 throw(RuntimeException
)
119 return uno::Reference
< beans::XPropertySetInfo
> ();
121 void SAL_CALL
ZipPackageEntry::addPropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
122 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
125 void SAL_CALL
ZipPackageEntry::removePropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
126 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
129 void SAL_CALL
ZipPackageEntry::addVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
130 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
133 void SAL_CALL
ZipPackageEntry::removeVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
134 throw(beans::UnknownPropertyException
, WrappedTargetException
, RuntimeException
)