Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/ucb/source/ucp/package/pkgcontent.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
20
#pragma once
21
22
#include <sal/config.h>
23
24
#include <string_view>
25
#include <vector>
26
#include <rtl/ref.hxx>
27
28
#include <com/sun/star/ucb/XContentCreator.hpp>
29
#include <ucbhelper/contenthelper.hxx>
30
#include "pkguri.hxx"
31
32
namespace com::sun::star {
33
    namespace beans
34
    {
35
        struct Property;
36
        struct PropertyValue;
37
    }
38
    namespace container
39
    {
40
        class XHierarchicalNameAccess;
41
        class XEnumeration;
42
    }
43
    namespace io
44
    {
45
        class XInputStream;
46
    }
47
    namespace sdbc
48
    {
49
        class XRow;
50
    }
51
    namespace ucb
52
    {
53
        struct OpenCommandArgument2;
54
        struct TransferInfo;
55
    }
56
}
57
58
namespace package_ucp
59
{
60
61
62
struct ContentProperties
63
{
64
    OUString     aTitle;                // Title
65
    OUString     aContentType;          // ContentType
66
    bool         bIsDocument;           // IsDocument
67
    bool         bIsFolder;             // IsFolder
68
    OUString     aMediaType;            // MediaType
69
    css::uno::Sequence < sal_Int8 >   aEncryptionKey;        // EncryptionKey
70
    sal_Int64    nSize;                 // Size
71
    bool         bCompressed;           // Compressed
72
    bool         bEncrypted;            // Encrypted
73
    bool         bHasEncryptedEntries;  // HasEncryptedEntries
74
75
    ContentProperties()
76
0
    : bIsDocument( true ), bIsFolder( false ), nSize( 0 ),
77
0
      bCompressed( true ), bEncrypted( false ),
78
0
      bHasEncryptedEntries( false ) {}
79
80
    explicit ContentProperties( const OUString& rContentType );
81
82
    css::uno::Sequence< css::ucb::ContentInfo >
83
    getCreatableContentsInfo( PackageUri const & rUri ) const;
84
};
85
86
87
class ContentProvider;
88
89
class Content : public ::ucbhelper::ContentImplHelper,
90
                public css::ucb::XContentCreator
91
{
92
    enum ContentState { TRANSIENT,  // created via CreateNewContent,
93
                                        // but did not process "insert" yet
94
                        PERSISTENT, // processed "insert"
95
                        DEAD        // processed "delete"
96
                      };
97
98
    PackageUri              m_aUri;
99
    ContentProperties       m_aProps;
100
    ContentState            m_eState;
101
    css::uno::Reference<
102
        css::container::XHierarchicalNameAccess > m_xPackage;
103
    ContentProvider*        m_pProvider;
104
    sal_uInt32              m_nModifiedProps;
105
106
private:
107
    Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
108
             ContentProvider* pProvider,
109
             const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
110
             css::uno::Reference< css::container::XHierarchicalNameAccess > Package,
111
             PackageUri aUri,
112
             ContentProperties  aProps );
113
    Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
114
             ContentProvider* pProvider,
115
             const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
116
             css::uno::Reference< css::container::XHierarchicalNameAccess > Package,
117
             PackageUri aUri,
118
             const css::ucb::ContentInfo& Info );
119
120
    virtual css::uno::Sequence< css::beans::Property >
121
    getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
122
    virtual css::uno::Sequence< css::ucb::CommandInfo >
123
    getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
124
    virtual OUString getParentURL() override;
125
126
    static css::uno::Reference< css::sdbc::XRow >
127
    getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
128
                       const css::uno::Sequence< css::beans::Property >& rProperties,
129
                       const ContentProperties& rData,
130
                       const rtl::Reference< ::ucbhelper::ContentProviderImplHelper >& rProvider,
131
                       const OUString& rContentId );
132
133
    css::uno::Reference< css::sdbc::XRow >
134
    getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties );
135
    /// @throws css::uno::Exception
136
    css::uno::Sequence< css::uno::Any >
137
    setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& rValues,
138
                       const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
139
140
    css::uno::Reference< css::container::XHierarchicalNameAccess >
141
    getPackage( const PackageUri& rURI );
142
    css::uno::Reference< css::container::XHierarchicalNameAccess >
143
    getPackage();
144
145
    static bool
146
    loadData( ContentProvider* pProvider,
147
              const PackageUri& rURI,
148
              ContentProperties& rProps,
149
              css::uno::Reference< css::container::XHierarchicalNameAccess > & rxPackage );
150
    static bool
151
    hasData( ContentProvider* pProvider,
152
             const PackageUri& rURI,
153
             css::uno::Reference< css::container::XHierarchicalNameAccess > & rxPackage );
154
155
    bool
156
    hasData( const PackageUri& rURI );
157
    void
158
    renameData( const css::uno::Reference< css::ucb::XContentIdentifier >& xOldId,
159
                const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
160
    bool
161
    storeData( const css::uno::Reference< css::io::XInputStream >& xStream );
162
    bool
163
    removeData();
164
165
    bool
166
    flushData();
167
168
    typedef rtl::Reference< Content > ContentRef;
169
    typedef std::vector< ContentRef > ContentRefList;
170
    void queryChildren( ContentRefList& rChildren );
171
172
    bool
173
    exchangeIdentity( const css::uno::Reference<
174
                        css::ucb::XContentIdentifier >& xNewId );
175
176
    /// @throws css::uno::Exception
177
    css::uno::Any
178
    open( const css::ucb::OpenCommandArgument2& rArg,
179
          const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
180
181
    /// @throws css::uno::Exception
182
    void insert( const css::uno::Reference< css::io::XInputStream >& xStream,
183
                 sal_Int32 nNameClashResolve,
184
                 const css::uno::Reference<
185
                    css::ucb::XCommandEnvironment > & xEnv );
186
187
    /// @throws css::uno::Exception
188
    void destroy( bool bDeletePhysical,
189
                  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
190
191
    /// @throws css::uno::Exception
192
    void transfer( const css::ucb::TransferInfo& rInfo,
193
                   const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
194
195
    css::uno::Reference< css::io::XInputStream >
196
    getInputStream();
197
198
0
    bool isFolder() const { return m_aProps.bIsFolder; }
199
200
public:
201
    // Create existing content. Fail, if not already exists.
202
    static rtl::Reference<Content> create(
203
            const css::uno::Reference< css::uno::XComponentContext >& rxContext,
204
            ContentProvider* pProvider,
205
            const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier );
206
207
    // Create new content. Fail, if already exists.
208
    static rtl::Reference<Content> create(
209
            const css::uno::Reference< css::uno::XComponentContext >& rxContext,
210
            ContentProvider* pProvider,
211
            const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
212
            const css::ucb::ContentInfo& Info );
213
214
    virtual ~Content() override;
215
216
    // XInterface
217
    virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
218
    virtual void SAL_CALL acquire()
219
        noexcept override;
220
    virtual void SAL_CALL release()
221
        noexcept override;
222
223
    // XTypeProvider
224
    virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
225
    virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
226
227
    // XServiceInfo
228
    virtual OUString SAL_CALL
229
    getImplementationName() override;
230
    virtual css::uno::Sequence< OUString > SAL_CALL
231
    getSupportedServiceNames() override;
232
233
    // XContent
234
    virtual OUString SAL_CALL
235
    getContentType() override;
236
237
    // XCommandProcessor
238
    virtual css::uno::Any SAL_CALL
239
    execute( const css::ucb::Command& aCommand,
240
             sal_Int32 CommandId,
241
             const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override;
242
    virtual void SAL_CALL
243
    abort( sal_Int32 CommandId ) override;
244
245
246
    // Additional interfaces
247
248
249
    // XContentCreator
250
    virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL
251
    queryCreatableContentsInfo() override;
252
    virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
253
    createNewContent( const css::ucb::ContentInfo& Info ) override;
254
255
256
    // Non-interface methods.
257
258
259
    // Called from resultset data supplier.
260
    static css::uno::Reference< css::sdbc::XRow >
261
    getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
262
                       const css::uno::Sequence< css::beans::Property >& rProperties,
263
                       ContentProvider* pProvider,
264
                       const OUString& rContentId );
265
266
    // Called from resultset data supplier.
267
    css::uno::Reference< css::container::XEnumeration >
268
    getIterator();
269
270
    static OUString
271
    getContentType( std::u16string_view aScheme,  bool bFolder );
272
};
273
274
}
275
276
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */