LibreOffice Module package (master) 1
ZipPackageEntry.cxx
Go to the documentation of this file.
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/lang/NoSupportException.hpp>
22#include <com/sun/star/packages/zip/ZipConstants.hpp>
23#include <osl/diagnose.h>
24#include <sal/log.hxx>
25
26#include <ZipPackageFolder.hxx>
27
30
31using namespace com::sun::star;
32using namespace com::sun::star::uno;
33using namespace com::sun::star::lang;
34using namespace com::sun::star::container;
35using namespace com::sun::star::packages::zip;
36using namespace com::sun::star::packages::zip::ZipConstants;
37
38#if OSL_DEBUG_LEVEL > 0
39#define THROW_WHERE SAL_WHERE
40#else
41#define THROW_WHERE ""
42#endif
43
45: mbIsFolder( false )
46, mbAllowRemoveOnInsert(false)
47, mpParent ( nullptr )
48, m_nFormat(0)
49{
50}
51
53{
54 // When the entry is destroyed it must be already disconnected from the parent
55 OSL_ENSURE( !mpParent, "The parent must be disconnected already! Memory corruption is possible!" );
56}
57
58// XChild
59OUString SAL_CALL ZipPackageEntry::getName( )
60{
61 return msName;
62}
63void SAL_CALL ZipPackageEntry::setName( const OUString& aName )
64{
65 if ( mpParent && !msName.isEmpty() && mpParent->hasByName ( msName ) )
67
68 // unfortunately no other exception than RuntimeException can be thrown here
69 // usually the package is used through storage implementation, the problem should be detected there
71 throw RuntimeException(THROW_WHERE "Unexpected character is used in file name." );
72
73 msName = aName;
74
75 if ( mpParent )
76 mpParent->doInsertByName ( this, false );
77}
78uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( )
79{
80 // return uno::Reference< XInterface >( xParent, UNO_QUERY );
81 return cppu::getXWeak( mpParent );
82}
83
85{
86 // xParent = mpParent = pNewParent;
87 mpParent = pNewParent;
88 if ( !msName.isEmpty() && !pNewParent->hasByName ( msName ) )
89 pNewParent->doInsertByName ( this, false );
90}
91
92void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent )
93{
94 if ( !xNewParent.is() )
95 throw NoSupportException(THROW_WHERE );
96 ZipPackageFolder* pNewParent = dynamic_cast<ZipPackageFolder*>(xNewParent.get());
97 if (!pNewParent)
98 throw NoSupportException(THROW_WHERE );
99
100 if ( pNewParent != mpParent )
101 {
102 if ( mpParent && !msName.isEmpty() && mpParent->hasByName ( msName ) && mbAllowRemoveOnInsert )
104 doSetParent ( pNewParent );
105 }
106}
107 //XPropertySet
108uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( )
109{
110 return uno::Reference < beans::XPropertySetInfo > ();
111}
112void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
113{
114}
115void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
116{
117}
118void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
119{
120}
121void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
122{
123}
124
125/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define THROW_WHERE
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual OUString SAL_CALL getName() override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual ~ZipPackageEntry() override
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
ZipPackageFolder * mpParent
void doSetParent(ZipPackageFolder *pNewParent)
virtual void SAL_CALL setName(const OUString &aName) override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
void doInsertByName(ZipPackageEntry *pEntry, bool bSetParent)
virtual void SAL_CALL removeByName(const OUString &Name) override
static bool IsValidZipEntryFileName(std::u16string_view aName, bool bSlashAllowed)
RegionData_Impl * mpParent
OUString aName
sal_uInt16 const m_nFormat