Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_content.hxx
blob6d3a484462a2a5a640ebbf30cec3e7d7770519a9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_CONTENT_HXX
21 #define INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_CONTENT_HXX
23 #include <ucbhelper/contenthelper.hxx>
24 #include <com/sun/star/ucb/XContentCreator.hpp>
25 #include "tdoc_provider.hxx"
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 } } }
35 namespace tdoc_ucp
39 enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT };
41 class ContentProperties
43 public:
44 ContentProperties()
45 : m_eType( STREAM )
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 )
60 ContentType getType() const { return m_eType; }
62 // Properties
64 const OUString & getContentType() const { return m_aContentType; }
66 bool getIsFolder() const { return m_eType > STREAM; }
67 bool getIsDocument() const { return !getIsFolder(); }
69 const OUString & getTitle() const { return m_aTitle; }
70 void setTitle( const OUString & rTitle ) { m_aTitle = rTitle; }
72 css::uno::Sequence< css::ucb::ContentInfo >
73 getCreatableContentsInfo() const;
75 bool isContentCreator() const;
77 private:
78 ContentType m_eType;
79 OUString m_aContentType;
80 OUString m_aTitle;
84 class Content : public ::ucbhelper::ContentImplHelper,
85 public css::ucb::XContentCreator
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
93 ContentProperties m_aProps;
94 ContentState m_eState;
95 ContentProvider* m_pProvider;
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 );
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;
113 static bool hasData( ContentProvider const * pProvider, const Uri & rUri );
114 bool hasData( const Uri & rUri ) { return hasData( m_pProvider, rUri ); }
116 static bool loadData( ContentProvider const * pProvider,
117 const Uri & rUri,
118 ContentProperties& rProps );
119 /// @throws css::ucb::CommandFailedException
120 /// @throws css::task::DocumentPasswordRequest
121 /// @throws css::uno::RuntimeException
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();
128 bool copyData( const Uri & rSourceUri, const OUString & rNewName );
130 css::uno::Reference< css::ucb::XContentIdentifier >
131 makeNewIdentifier( const OUString& rTitle );
133 typedef rtl::Reference< Content > ContentRef;
134 typedef std::vector< ContentRef > ContentRefList;
135 void queryChildren( ContentRefList& rChildren );
137 bool exchangeIdentity(
138 const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
140 css::uno::Reference< css::sdbc::XRow >
141 getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties );
142 css::uno::Sequence< css::uno::Any >
143 /// @throws css::uno::Exception
144 setPropertyValues(
145 const css::uno::Sequence< css::beans::PropertyValue >& rValues,
146 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
148 /// @throws css::uno::Exception
149 css::uno::Any
150 open( const css::ucb::OpenCommandArgument2& rArg,
151 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
153 /// @throws css::uno::Exception
154 void insert( const css::uno::Reference< css::io::XInputStream >& xData,
155 sal_Int32 nNameClashResolve,
156 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
158 /// @throws css::uno::Exception
159 void destroy( bool bDeletePhysical,
160 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
162 /// @throws css::uno::Exception
163 void transfer( const css::ucb::TransferInfo& rInfo,
164 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
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 );
174 static bool commitStorage(
175 const css::uno::Reference< css::embed::XStorage > & xStorage );
177 static bool closeOutputStream(
178 const css::uno::Reference< css::io::XOutputStream > & xOut );
180 /// @throws css::ucb::CommandFailedException
181 /// @throws css::task::DocumentPasswordRequest
182 /// @throws css::uno::RuntimeException
183 css::uno::Reference< css::io::XInputStream >
184 getInputStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
186 /// @throws css::ucb::CommandFailedException
187 /// @throws css::task::DocumentPasswordRequest
188 /// @throws css::uno::RuntimeException
189 css::uno::Reference< css::io::XOutputStream >
190 getTruncatedOutputStream(
191 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
193 css::uno::Reference< css::ucb::XContent >
194 queryChildContent( const OUString & rRelativeChildUri );
196 /// @throws css::ucb::CommandFailedException
197 /// @throws css::task::DocumentPasswordRequest
198 /// @throws css::uno::RuntimeException
199 css::uno::Reference< css::io::XStream >
200 getStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
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 );
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 );
216 virtual ~Content() override;
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;
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;
229 // XServiceInfo
230 virtual OUString SAL_CALL
231 getImplementationName() override;
232 virtual css::uno::Sequence< OUString > SAL_CALL
233 getSupportedServiceNames() override;
235 // XContent
236 virtual OUString SAL_CALL
237 getContentType() override;
238 virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
239 getIdentifier() override;
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;
250 // Additional interfaces
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;
260 // Non-interface methods.
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 );
269 void notifyDocumentClosed();
270 void notifyChildRemoved( const OUString & rRelativeChildUri );
271 void notifyChildInserted( const OUString & rRelativeChildUri );
273 rtl::Reference< ContentProvider > getContentProvider() const
274 { return rtl::Reference< ContentProvider >( m_pProvider ); }
277 } // namespace tdoc_ucp
279 #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_CONTENT_HXX
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */