bump product version to 4.1.6.2
[LibreOffice.git] / package / source / zippackage / ZipPackageEntry.cxx
blobc109c196f0b07f98c6783a3c7cb392544ecea2bb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/packages/zip/ZipConstants.hpp>
22 #include <osl/diagnose.h>
24 #include <ZipPackageFolder.hxx>
25 #include <ZipPackageStream.hxx>
26 #include <ContentInfo.hxx>
28 #include <comphelper/storagehelper.hxx>
30 using namespace com::sun::star;
31 using namespace com::sun::star::uno;
32 using namespace com::sun::star::lang;
33 using namespace com::sun::star::container;
34 using namespace com::sun::star::packages::zip;
35 using namespace com::sun::star::packages::zip::ZipConstants;
37 ZipPackageEntry::ZipPackageEntry ( bool bNewFolder )
38 : mbIsFolder ( bNewFolder )
39 , mbAllowRemoveOnInsert( sal_True )
40 , pParent ( NULL )
44 ZipPackageEntry::~ZipPackageEntry()
46 // When the entry is destroyed it must be already disconnected from the parent
47 OSL_ENSURE( !pParent, "The parent must be disconnected already! Memory corruption is possible!\n" );
50 // XChild
51 OUString SAL_CALL ZipPackageEntry::getName( )
52 throw(RuntimeException)
54 return msName;
56 void SAL_CALL ZipPackageEntry::setName( const OUString& aName )
57 throw(RuntimeException)
59 if ( pParent && !msName.isEmpty() && pParent->hasByName ( msName ) )
60 pParent->removeByName ( msName );
62 // unfortunately no other exception than RuntimeException can be thrown here
63 // usually the package is used through storage implementation, the problem should be detected there
64 if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_True ) )
65 throw RuntimeException(OSL_LOG_PREFIX "Unexpected character is used in file name.", uno::Reference< XInterface >() );
67 msName = aName;
69 if ( pParent )
70 pParent->doInsertByName ( this, sal_False );
72 uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( )
73 throw(RuntimeException)
75 // return uno::Reference< XInterface >( xParent, UNO_QUERY );
76 return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY );
79 void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert )
81 // xParent = pParent = pNewParent;
82 pParent = pNewParent;
83 if ( bInsert && !msName.isEmpty() && !pNewParent->hasByName ( msName ) )
84 pNewParent->doInsertByName ( this, sal_False );
87 void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent )
88 throw(NoSupportException, RuntimeException)
90 sal_Int64 nTest(0);
91 uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY );
92 if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 )
93 throw NoSupportException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
95 ZipPackageFolder *pNewParent = reinterpret_cast < ZipPackageFolder * > ( nTest );
97 if ( pNewParent != pParent )
99 if ( pParent && !msName.isEmpty() && pParent->hasByName ( msName ) && mbAllowRemoveOnInsert )
100 pParent->removeByName( msName );
101 doSetParent ( pNewParent, sal_True );
104 //XPropertySet
105 uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( )
106 throw(RuntimeException)
108 return uno::Reference < beans::XPropertySetInfo > ();
110 void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
111 throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
114 void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
115 throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
118 void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
119 throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
122 void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
123 throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */