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