Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/package/source/zippackage/ZipPackageEntry.cxx
Line
Count
Source
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
28
#include <comphelper/servicehelper.hxx>
29
#include <comphelper/storagehelper.hxx>
30
31
using namespace com::sun::star;
32
using namespace com::sun::star::uno;
33
using namespace com::sun::star::lang;
34
using namespace com::sun::star::container;
35
using namespace com::sun::star::packages::zip;
36
using namespace com::sun::star::packages::zip::ZipConstants;
37
38
ZipPackageEntry::ZipPackageEntry()
39
606k
: mbIsFolder( false )
40
606k
, mbAllowRemoveOnInsert(false)
41
606k
, mpParent ( nullptr )
42
606k
, m_nFormat(0)
43
606k
{
44
606k
}
45
46
ZipPackageEntry::~ZipPackageEntry()
47
606k
{
48
    // When the entry is destroyed it must be already disconnected from the parent
49
606k
    OSL_ENSURE( !mpParent, "The parent must be disconnected already! Memory corruption is possible!" );
50
606k
}
51
52
// XChild
53
OUString SAL_CALL ZipPackageEntry::getName(  )
54
773k
{
55
773k
    return msName;
56
773k
}
57
void SAL_CALL ZipPackageEntry::setName( const OUString& aName )
58
497k
{
59
497k
    if ( mpParent && !msName.isEmpty() && mpParent->hasByName ( msName ) )
60
0
        mpParent->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
497k
    if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, true ) )
65
0
        throw RuntimeException(u"Unexpected character is used in file name."_ustr );
66
67
497k
    msName = aName;
68
69
497k
    if ( mpParent )
70
0
        mpParent->doInsertByName ( this, false );
71
497k
}
72
uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent(  )
73
0
{
74
    // return uno::Reference< XInterface >( xParent, UNO_QUERY );
75
0
    return cppu::getXWeak( mpParent );
76
0
}
77
78
void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent )
79
497k
{
80
    // xParent = mpParent = pNewParent;
81
497k
    mpParent = pNewParent;
82
497k
    if ( !msName.isEmpty() && !pNewParent->hasByName ( msName ) )
83
497k
        pNewParent->doInsertByName ( this, false );
84
497k
}
85
86
void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent )
87
0
{
88
0
    if ( !xNewParent.is() )
89
0
        throw NoSupportException();
90
0
    ZipPackageFolder* pNewParent = dynamic_cast<ZipPackageFolder*>(xNewParent.get());
91
0
    if (!pNewParent)
92
0
        throw NoSupportException();
93
94
0
    if ( pNewParent != mpParent )
95
0
    {
96
0
        if ( mpParent && !msName.isEmpty() && mpParent->hasByName ( msName ) && mbAllowRemoveOnInsert )
97
0
            mpParent->removeByName( msName );
98
0
        doSetParent ( pNewParent );
99
0
    }
100
0
}
101
    //XPropertySet
102
uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo(  )
103
0
{
104
0
    return uno::Reference < beans::XPropertySetInfo > ();
105
0
}
106
void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
107
0
{
108
0
}
109
void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
110
0
{
111
0
}
112
void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
113
0
{
114
0
}
115
void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
116
0
{
117
0
}
118
119
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */