xref: /trunk/main/package/source/package/zippackage/ZipPackageEntry.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_package.hxx"
26 #include <ZipPackageEntry.hxx>
27 #include <com/sun/star/packages/zip/ZipConstants.hpp>
28 #include <osl/diagnose.h>
29 
30 #include <ZipPackageFolder.hxx>
31 #include <ZipPackageStream.hxx>
32 #include <ContentInfo.hxx>
33 
34 #include <comphelper/storagehelper.hxx>
35 
36 using namespace rtl;
37 using namespace com::sun::star;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::lang;
40 using namespace com::sun::star::container;
41 using namespace com::sun::star::packages::zip;
42 using namespace com::sun::star::packages::zip::ZipConstants;
43 
ZipPackageEntry(bool bNewFolder)44 ZipPackageEntry::ZipPackageEntry ( bool bNewFolder )
45 : mbIsFolder ( bNewFolder )
46 , mbAllowRemoveOnInsert( sal_True )
47 , pParent ( NULL )
48 {
49 }
50 
~ZipPackageEntry()51 ZipPackageEntry::~ZipPackageEntry()
52 {
53     // When the entry is destroyed it must be already disconnected from the parent
54     OSL_ENSURE( !pParent, "The parent must be disconnected already! Memory corruption is possible!\n" );
55 }
56 
57 // XChild
getName()58 OUString SAL_CALL ZipPackageEntry::getName(  )
59 {
60     return msName;
61 }
setName(const OUString & aName)62 void SAL_CALL ZipPackageEntry::setName( const OUString& aName )
63 {
64     if ( pParent && msName.getLength() && pParent->hasByName ( msName ) )
65         pParent->removeByName ( msName );
66 
67     // unfortunately no other exception than RuntimeException can be thrown here
68     // usually the package is used through storage implementation, the problem should be detected there
69     if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_True ) )
70         throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() );
71 
72     msName = aName;
73 
74     if ( pParent )
75         pParent->doInsertByName ( this, sal_False );
76 }
getParent()77 uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent(  )
78 {
79     // return uno::Reference< XInterface >( xParent, UNO_QUERY );
80     return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY );
81 }
82 
doSetParent(ZipPackageFolder * pNewParent,sal_Bool bInsert)83 void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert )
84 {
85     // xParent = pParent = pNewParent;
86     pParent = pNewParent;
87     if ( bInsert && msName.getLength() && !pNewParent->hasByName ( msName ) )
88         pNewParent->doInsertByName ( this, sal_False );
89 }
90 
setParent(const uno::Reference<XInterface> & xNewParent)91 void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent )
92 {
93     sal_Int64 nTest(0);
94     uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY );
95     if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 )
96         throw NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
97 
98     ZipPackageFolder *pNewParent = reinterpret_cast < ZipPackageFolder * > ( nTest );
99 
100     if ( pNewParent != pParent )
101     {
102         if ( pParent && msName.getLength() && pParent->hasByName ( msName ) && mbAllowRemoveOnInsert )
103             pParent->removeByName( msName );
104         doSetParent ( pNewParent, sal_True );
105     }
106 }
107     //XPropertySet
getPropertySetInfo()108 uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo(  )
109 {
110     return uno::Reference < beans::XPropertySetInfo > ();
111 }
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)112 void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
113 {
114 }
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)115 void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
116 {
117 }
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)118 void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
119 {
120 }
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)121 void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
122 {
123 }
124