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 17272 : ZipPackageEntry::ZipPackageEntry ( bool bNewFolder )
38 : : mbIsFolder ( bNewFolder )
39 : , mbAllowRemoveOnInsert( sal_True )
40 17272 : , pParent ( NULL )
41 : {
42 17272 : }
43 :
44 14210 : ZipPackageEntry::~ZipPackageEntry()
45 : {
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" );
48 14210 : }
49 :
50 : // XChild
51 13859 : OUString SAL_CALL ZipPackageEntry::getName( )
52 : throw(RuntimeException)
53 : {
54 13859 : return msName;
55 : }
56 8712 : void SAL_CALL ZipPackageEntry::setName( const OUString& aName )
57 : throw(RuntimeException)
58 : {
59 8712 : if ( pParent && !msName.isEmpty() && pParent->hasByName ( msName ) )
60 0 : pParent->removeByName ( msName );
61 :
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 8712 : if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_True ) )
65 0 : throw RuntimeException(OSL_LOG_PREFIX "Unexpected character is used in file name.", uno::Reference< XInterface >() );
66 :
67 8712 : msName = aName;
68 :
69 8712 : if ( pParent )
70 0 : pParent->doInsertByName ( this, sal_False );
71 8712 : }
72 0 : uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( )
73 : throw(RuntimeException)
74 : {
75 : // return uno::Reference< XInterface >( xParent, UNO_QUERY );
76 0 : return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY );
77 : }
78 :
79 8712 : void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert )
80 : {
81 : // xParent = pParent = pNewParent;
82 8712 : pParent = pNewParent;
83 8712 : if ( bInsert && !msName.isEmpty() && !pNewParent->hasByName ( msName ) )
84 7672 : pNewParent->doInsertByName ( this, sal_False );
85 8712 : }
86 :
87 1040 : void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent )
88 : throw(NoSupportException, RuntimeException)
89 : {
90 1040 : sal_Int64 nTest(0);
91 1040 : uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY );
92 1040 : if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 )
93 0 : throw NoSupportException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() );
94 :
95 1040 : ZipPackageFolder *pNewParent = reinterpret_cast < ZipPackageFolder * > ( nTest );
96 :
97 1040 : if ( pNewParent != pParent )
98 : {
99 1040 : if ( pParent && !msName.isEmpty() && pParent->hasByName ( msName ) && mbAllowRemoveOnInsert )
100 0 : pParent->removeByName( msName );
101 1040 : doSetParent ( pNewParent, sal_True );
102 1040 : }
103 1040 : }
104 : //XPropertySet
105 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( )
106 : throw(RuntimeException)
107 : {
108 0 : return uno::Reference < beans::XPropertySetInfo > ();
109 : }
110 0 : void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
111 : throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
112 : {
113 0 : }
114 0 : void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
115 : throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
116 : {
117 0 : }
118 0 : void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
119 : throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
120 : {
121 0 : }
122 0 : void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
123 : throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
124 : {
125 0 : }
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|