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