Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/sfx2/Metadatable.hxx
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
#ifndef INCLUDED_SFX2_METADATABLE_HXX
20
#define INCLUDED_SFX2_METADATABLE_HXX
21
22
#include <sal/config.h>
23
24
#include <sfx2/dllapi.h>
25
26
#include <cppuhelper/implbase.hxx>
27
#include <com/sun/star/rdf/XMetadatable.hpp>
28
29
#include <memory>
30
31
32
namespace com::sun::star {
33
    namespace frame { class XModel; }
34
}
35
36
namespace sfx2 {
37
    class IXmlIdRegistry;
38
}
39
40
namespace sfx2 {
41
42
class XmlIdRegistry;
43
class MetadatableUndo;
44
45
46
// XML ID handling ---------------------------------------------------
47
48
49
/// create a sfx2::XmlIdRegistryDocument or a sfx2::XmlIdRegistryClipboard
50
SFX2_DLLPUBLIC ::sfx2::IXmlIdRegistry *
51
createXmlIdRegistry(const bool i_DocIsClipboard);
52
53
54
/** base class for core objects that may have xml:id.
55
56
    <p>The interface of this class consists of 3 parts:
57
    <ul><li>implementations that are used by the MetadatableMixin
58
            below</li>
59
        <li>hooks to be called by the sw core whenever actions that are
60
            relevant to the uniqueness of xml:ids are taken (copying,
61
            splitting, merging, deletion, undo, etc.)</li>
62
        <li>abstract methods that are called by the implementation of the
63
            previous hooks</li></ul>
64
    </p>
65
 */
66
class SFX2_DLLPUBLIC SAL_LOPLUGIN_ANNOTATE("crosscast") Metadatable
67
{
68
public:
69
5.33M
    Metadatable() : m_pReg(nullptr) {}
70
71
    // destructor calls RemoveMetadataReference
72
    virtual ~Metadatable();
73
74
    // for MetadatableMixin ----------------------------------------------
75
76
    css::beans::StringPair GetMetadataReference() const;
77
    void SetMetadataReference( const css::beans::StringPair & i_rReference);
78
    void EnsureMetadataReference();
79
80
    // hooks -------------------------------------------------------------
81
82
    // called from dtor!
83
    void RemoveMetadataReference();
84
85
    /** register this as a copy of i_rSource */
86
    void RegisterAsCopyOf(Metadatable const & i_rSource,
87
        const bool i_bCopyPrecedesSource = false);
88
89
    /** create an Undo Metadatable, which remembers this' reference */
90
    std::shared_ptr<MetadatableUndo> CreateUndo() const;
91
    std::shared_ptr<MetadatableUndo> CreateUndoForDelete();
92
93
    /** restore this from Undo Metadatable */
94
    void RestoreMetadata(std::shared_ptr<MetadatableUndo> const& i_pUndo);
95
96
    /** merge this and i_rOther into this */
97
    void JoinMetadatable(Metadatable const & i_rOther,
98
        const bool i_isMergedEmpty, const bool i_isOtherEmpty);
99
100
    // abstract methods --------------------------------------------------
101
102
    /** get the registry from the SwDoc */
103
    virtual ::sfx2::IXmlIdRegistry& GetRegistry() = 0;
104
105
    /** is this in a clipboard document? */
106
    virtual bool IsInClipboard() const = 0;
107
108
    /** is this in undo array? */
109
    virtual bool IsInUndo() const = 0;
110
111
    /** which stream is this in? true: content.xml; false: styles.xml */
112
    virtual bool IsInContent() const = 0;
113
114
    /** create XMetadatable from this.
115
        note: if IsInUndo or IsInClipboard return true,
116
        MakeUnoObject <em>must not</em> be called!
117
     */
118
    virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() = 0;
119
120
private:
121
    Metadatable(const Metadatable&) = delete;
122
    Metadatable& operator=(const Metadatable&) = delete;
123
124
    friend class MetadatableClipboard;
125
    friend class MetadatableUndo;
126
127
    // note that Reg may be a XmlIdRegistryDocument or a XmlIdRegistryClipboard
128
    XmlIdRegistry* m_pReg; // null => no XmlId
129
};
130
131
132
/** base class for UNO objects that implement XMetadatable.
133
134
    <p>An instance of this base class is associated with an instance of
135
       Metadatable.</p>
136
 */
137
class SFX2_DLLPUBLIC MetadatableMixin :
138
    public cppu::WeakImplHelper<css::rdf::XMetadatable>
139
{
140
141
public:
142
185k
    MetadatableMixin() {};
143
144
    // css::rdf::XNode:
145
    virtual OUString SAL_CALL getStringValue() override;
146
147
    // css::rdf::XURI:
148
    virtual OUString SAL_CALL getLocalName() override;
149
    virtual OUString SAL_CALL getNamespace() override;
150
151
    // css::rdf::XMetadatable:
152
    virtual css::beans::StringPair SAL_CALL getMetadataReference() override;
153
    virtual void SAL_CALL setMetadataReference(
154
        const css::beans::StringPair & i_rReference) override;
155
    virtual void SAL_CALL ensureMetadataReference() override;
156
157
protected:
158
    /// get the core object corresponding to this UNO object.
159
    virtual Metadatable * GetCoreObject() = 0;
160
    /// get the XModel for the document
161
    virtual css::uno::Reference< css::frame::XModel >
162
        GetModel() = 0;
163
164
};
165
166
} // namespace sfx2
167
168
#endif // INCLUDED_SFX2_METADATABLE_HXX
169
170
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */