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