LibreOffice Module ucb (master) 1
tdoc_content.hxx
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#pragma once
21
22#include <sal/config.h>
23
24#include <string_view>
25
27#include <com/sun/star/ucb/XContentCreator.hpp>
28#include <utility>
29#include "tdoc_provider.hxx"
30
31namespace com::sun::star {
32 namespace sdbc { class XRow; }
33 namespace io { class XInputStream; class XOutputStream; }
34 namespace beans { struct PropertyValue; }
35 namespace ucb { struct OpenCommandArgument2; struct TransferInfo;
36 struct ContentInfo; }
37}
38
39namespace tdoc_ucp
40{
41
42
44
46{
47public:
49 : m_eType( STREAM )
50 {}
51
52 ContentProperties( const ContentType & rType, OUString aTitle )
53 : m_eType( rType ),
54 m_aContentType( rType == STREAM
55 ? OUString( TDOC_STREAM_CONTENT_TYPE )
56 : rType == FOLDER
57 ? OUString( TDOC_FOLDER_CONTENT_TYPE )
58 : rType == DOCUMENT
59 ? OUString( TDOC_DOCUMENT_CONTENT_TYPE )
60 : OUString( TDOC_ROOT_CONTENT_TYPE ) ),
61 m_aTitle(std::move( aTitle ))
62 {}
63
64 ContentType getType() const { return m_eType; }
65
66 // Properties
67
68 const OUString & getContentType() const { return m_aContentType; }
69
70 bool getIsFolder() const { return m_eType > STREAM; }
71 bool getIsDocument() const { return !getIsFolder(); }
72
73 const OUString & getTitle() const { return m_aTitle; }
74 void setTitle( const OUString & rTitle ) { m_aTitle = rTitle; }
75
76 css::uno::Sequence< css::ucb::ContentInfo >
78
79 bool isContentCreator() const;
80
81private:
84 OUString m_aTitle;
85};
86
87
89 public css::ucb::XContentCreator
90{
91 enum ContentState { TRANSIENT, // created via createNewContent,
92 // but did not process "insert" yet
93 PERSISTENT, // processed "insert"
94 DEAD // processed "delete" / document was closed
95 };
96
100
101private:
102 Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
103 ContentProvider* pProvider,
104 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
105 ContentProperties aProps );
106 Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
107 ContentProvider* pProvider,
108 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
109 const css::ucb::ContentInfo& Info );
110
111 virtual css::uno::Sequence< css::beans::Property >
112 getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
113 virtual css::uno::Sequence< css::ucb::CommandInfo >
114 getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
115 virtual OUString getParentURL() override;
116
117 static bool hasData( ContentProvider const * pProvider, const Uri & rUri );
118 bool hasData( const Uri & rUri ) const { return hasData( m_pProvider, rUri ); }
119
120 static bool loadData( ContentProvider const * pProvider,
121 const Uri & rUri,
122 ContentProperties& rProps );
126 bool storeData( const css::uno::Reference< css::io::XInputStream >& xData,
127 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
128 void renameData( const css::uno::Reference< css::ucb::XContentIdentifier >& xOldId,
129 const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
130 bool removeData();
131
132 bool copyData( const Uri & rSourceUri, const OUString & rNewName );
133
134 css::uno::Reference< css::ucb::XContentIdentifier >
135 makeNewIdentifier( const OUString& rTitle );
136
138 typedef std::vector< ContentRef > ContentRefList;
139 void queryChildren( ContentRefList& rChildren );
140
142 const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
143
144 css::uno::Reference< css::sdbc::XRow >
145 getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties );
146 css::uno::Sequence< css::uno::Any >
149 const css::uno::Sequence< css::beans::PropertyValue >& rValues,
150 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
151
153 css::uno::Any
154 open( const css::ucb::OpenCommandArgument2& rArg,
155 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
156
158 void insert( const css::uno::Reference< css::io::XInputStream >& xData,
159 sal_Int32 nNameClashResolve,
160 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
161
163 void destroy( bool bDeletePhysical,
164 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
165
167 void transfer( const css::ucb::TransferInfo& rInfo,
168 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
169
170 static css::uno::Reference< css::sdbc::XRow >
171 getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
172 const css::uno::Sequence< css::beans::Property >& rProperties,
173 const ContentProperties& rData,
174 ContentProvider* pProvider,
175 const OUString& rContentId );
176
177
178 static bool commitStorage(
179 const css::uno::Reference< css::embed::XStorage > & xStorage );
180
181 static bool closeOutputStream(
182 const css::uno::Reference< css::io::XOutputStream > & xOut );
183
187 css::uno::Reference< css::io::XInputStream >
188 getInputStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
189
193 css::uno::Reference< css::io::XOutputStream >
195 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
196
197 css::uno::Reference< css::ucb::XContent >
198 queryChildContent( std::u16string_view rRelativeChildUri );
199
203 css::uno::Reference< css::io::XStream >
204 getStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
205
206public:
207 // Create existing content. Fail, if not already exists.
209 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
210 ContentProvider* pProvider,
211 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier );
212
213 // Create new content. Fail, if already exists.
215 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
216 ContentProvider* pProvider,
217 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
218 const css::ucb::ContentInfo& Info );
219
220 virtual ~Content() override;
221
222 // XInterface
223 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
224 virtual void SAL_CALL acquire()
225 noexcept override;
226 virtual void SAL_CALL release()
227 noexcept override;
228
229 // XTypeProvider
230 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
231 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
232
233 // XServiceInfo
234 virtual OUString SAL_CALL
235 getImplementationName() override;
236 virtual css::uno::Sequence< OUString > SAL_CALL
237 getSupportedServiceNames() override;
238
239 // XContent
240 virtual OUString SAL_CALL
241 getContentType() override;
242 virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
243 getIdentifier() override;
244
245 // XCommandProcessor
246 virtual css::uno::Any SAL_CALL
247 execute( const css::ucb::Command& aCommand,
248 sal_Int32 CommandId,
249 const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override;
250 virtual void SAL_CALL
251 abort( sal_Int32 CommandId ) override;
252
253
254 // Additional interfaces
255
256
257 // XContentCreator
258 virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL
260 virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
261 createNewContent( const css::ucb::ContentInfo& Info ) override;
262
263
264 // Non-interface methods.
265
266
267 static css::uno::Reference< css::sdbc::XRow >
268 getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
269 const css::uno::Sequence< css::beans::Property >& rProperties,
270 ContentProvider* pProvider,
271 const OUString& rContentId );
272
274 void notifyChildRemoved( std::u16string_view rRelativeChildUri );
275 void notifyChildInserted( std::u16string_view rRelativeChildUri );
276
279};
280
281} // namespace tdoc_ucp
282
283/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ContentType getType() const
css::uno::Sequence< css::ucb::ContentInfo > getCreatableContentsInfo() const
const OUString & getContentType() const
void setTitle(const OUString &rTitle)
const OUString & getTitle() const
ContentProperties(const ContentType &rType, OUString aTitle)
static bool hasData(ContentProvider const *pProvider, const Uri &rUri)
static bool commitStorage(const css::uno::Reference< css::embed::XStorage > &xStorage)
virtual css::uno::Sequence< css::ucb::CommandInfo > getCommands(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
virtual css::uno::Sequence< css::beans::Property > getProperties(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
css::uno::Reference< css::io::XOutputStream > getTruncatedOutputStream(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL getIdentifier() override
Content(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier, const css::ucb::ContentInfo &Info)
bool exchangeIdentity(const css::uno::Reference< css::ucb::XContentIdentifier > &xNewId)
void renameData(const css::uno::Reference< css::ucb::XContentIdentifier > &xOldId, const css::uno::Reference< css::ucb::XContentIdentifier > &xNewId)
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &rValues, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
bool copyData(const Uri &rSourceUri, const OUString &rNewName)
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL queryCreatableContentsInfo() override
ContentProvider * m_pProvider
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
ContentState m_eState
void insert(const css::uno::Reference< css::io::XInputStream > &xData, sal_Int32 nNameClashResolve, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
std::vector< ContentRef > ContentRefList
css::uno::Any open(const css::ucb::OpenCommandArgument2 &rArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void destroy(bool bDeletePhysical, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createNewContent(const css::ucb::ContentInfo &Info) override
rtl::Reference< Content > ContentRef
static rtl::Reference< Content > create(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &rProperties)
void notifyChildInserted(std::u16string_view rRelativeChildUri)
css::uno::Reference< css::io::XStream > getStream(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Reference< css::io::XInputStream > getInputStream(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void notifyChildRemoved(std::u16string_view rRelativeChildUri)
virtual OUString SAL_CALL getImplementationName() override
void transfer(const css::ucb::TransferInfo &rInfo, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::ucb::XContentIdentifier > makeNewIdentifier(const OUString &rTitle)
virtual void SAL_CALL release() noexcept override
static bool closeOutputStream(const css::uno::Reference< css::io::XOutputStream > &xOut)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
bool storeData(const css::uno::Reference< css::io::XInputStream > &xData, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void queryChildren(ContentRefList &rChildren)
rtl::Reference< ContentProvider > getContentProvider() const
virtual OUString SAL_CALL getContentType() override
virtual void SAL_CALL abort(sal_Int32 CommandId) override
bool hasData(const Uri &rUri) const
virtual OUString getParentURL() override
ContentProperties m_aProps
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
static rtl::Reference< Content > create(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier, const css::ucb::ContentInfo &Info)
static bool loadData(ContentProvider const *pProvider, const Uri &rUri, ContentProperties &rProps)
static css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Sequence< css::beans::Property > &rProperties, const ContentProperties &rData, ContentProvider *pProvider, const OUString &rContentId)
virtual ~Content() override
Content(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier, ContentProperties aProps)
css::uno::Reference< css::ucb::XContent > queryChildContent(std::u16string_view rRelativeChildUri)
Type
constexpr OUStringLiteral TDOC_ROOT_CONTENT_TYPE
constexpr OUStringLiteral TDOC_STREAM_CONTENT_TYPE
constexpr OUStringLiteral TDOC_DOCUMENT_CONTENT_TYPE
constexpr OUStringLiteral TDOC_FOLDER_CONTENT_TYPE
signed char sal_Int8