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