Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <ZipPackageEntry.hxx>
21 : #include <com/sun/star/packages/zip/ZipConstants.hpp>
22 : #include <osl/diagnose.h>
23 :
24 : #include <ZipPackageFolder.hxx>
25 : #include <ZipPackageStream.hxx>
26 : #include <ContentInfo.hxx>
27 :
28 : #include <comphelper/storagehelper.hxx>
29 :
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;
36 :
37 : #if OSL_DEBUG_LEVEL > 0
38 : #define THROW_WHERE SAL_WHERE
39 : #else
40 : #define THROW_WHERE ""
41 : #endif
42 :
43 384106 : ZipPackageEntry::ZipPackageEntry()
44 : : mbIsFolder( false )
45 : , mbAllowRemoveOnInsert(false)
46 : , mpParent ( NULL )
47 384106 : , m_nFormat(0)
48 : {
49 384106 : }
50 :
51 383820 : ZipPackageEntry::~ZipPackageEntry()
52 : {
53 : // When the entry is destroyed it must be already disconnected from the parent
54 : OSL_ENSURE( !mpParent, "The parent must be disconnected already! Memory corruption is possible!\n" );
55 383820 : }
56 :
57 : // XChild
58 432739 : OUString SAL_CALL ZipPackageEntry::getName( )
59 : throw(RuntimeException, std::exception)
60 : {
61 432739 : return msName;
62 : }
63 306941 : void SAL_CALL ZipPackageEntry::setName( const OUString& aName )
64 : throw(RuntimeException, std::exception)
65 : {
66 306941 : if ( mpParent && !msName.isEmpty() && mpParent->hasByName ( msName ) )
67 1 : mpParent->removeByName ( msName );
68 :
69 : // unfortunately no other exception than RuntimeException can be thrown here
70 : // usually the package is used through storage implementation, the problem should be detected there
71 306941 : if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, true ) )
72 0 : throw RuntimeException(THROW_WHERE "Unexpected character is used in file name." );
73 :
74 306941 : msName = aName;
75 :
76 306941 : if ( mpParent )
77 0 : mpParent->doInsertByName ( this, false );
78 306941 : }
79 0 : uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( )
80 : throw(RuntimeException, std::exception)
81 : {
82 : // return uno::Reference< XInterface >( xParent, UNO_QUERY );
83 0 : return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( mpParent ), UNO_QUERY );
84 : }
85 :
86 306949 : void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, bool bInsert )
87 : {
88 : // xParent = mpParent = pNewParent;
89 306949 : mpParent = pNewParent;
90 306949 : if ( bInsert && !msName.isEmpty() && !pNewParent->hasByName ( msName ) )
91 289699 : pNewParent->doInsertByName ( this, false );
92 306949 : }
93 :
94 17250 : void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent )
95 : throw(NoSupportException, RuntimeException, std::exception)
96 : {
97 17250 : sal_Int64 nTest(0);
98 17250 : uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY );
99 17250 : if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 )
100 0 : throw NoSupportException(THROW_WHERE );
101 :
102 17250 : ZipPackageFolder *pNewParent = reinterpret_cast < ZipPackageFolder * > ( nTest );
103 :
104 17250 : if ( pNewParent != mpParent )
105 : {
106 17250 : if ( mpParent && !msName.isEmpty() && mpParent->hasByName ( msName ) && mbAllowRemoveOnInsert )
107 0 : mpParent->removeByName( msName );
108 17250 : doSetParent ( pNewParent, true );
109 17250 : }
110 17250 : }
111 : //XPropertySet
112 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( )
113 : throw(RuntimeException, std::exception)
114 : {
115 0 : return uno::Reference < beans::XPropertySetInfo > ();
116 : }
117 0 : void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
118 : throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
119 : {
120 0 : }
121 0 : void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
122 : throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
123 : {
124 0 : }
125 0 : void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
126 : throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
127 : {
128 0 : }
129 0 : void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
130 : throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
131 : {
132 0 : }
133 :
134 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|