bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_content.hxx
blob56117b1b08534a4a69c991157952f660f19f6b74
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 #pragma once
22 #include <ucbhelper/contenthelper.hxx>
23 #include <com/sun/star/ucb/XContentCreator.hpp>
24 #include "tdoc_provider.hxx"
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; }
34 namespace tdoc_ucp
38 enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT };
40 class ContentProperties
42 public:
43 ContentProperties()
44 : m_eType( STREAM )
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 )
59 ContentType getType() const { return m_eType; }
61 // Properties
63 const OUString & getContentType() const { return m_aContentType; }
65 bool getIsFolder() const { return m_eType > STREAM; }
66 bool getIsDocument() const { return !getIsFolder(); }
68 const OUString & getTitle() const { return m_aTitle; }
69 void setTitle( const OUString & rTitle ) { m_aTitle = rTitle; }
71 css::uno::Sequence< css::ucb::ContentInfo >
72 getCreatableContentsInfo() const;
74 bool isContentCreator() const;
76 private:
77 ContentType m_eType;
78 OUString m_aContentType;
79 OUString m_aTitle;
83 class Content : public ::ucbhelper::ContentImplHelper,
84 public css::ucb::XContentCreator
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
92 ContentProperties m_aProps;
93 ContentState m_eState;
94 ContentProvider* m_pProvider;
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 );
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;
112 static bool hasData( ContentProvider const * pProvider, const Uri & rUri );
113 bool hasData( const Uri & rUri ) { return hasData( m_pProvider, rUri ); }
115 static bool loadData( ContentProvider const * pProvider,
116 const Uri & rUri,
117 ContentProperties& rProps );
118 /// @throws css::ucb::CommandFailedException
119 /// @throws css::task::DocumentPasswordRequest
120 /// @throws css::uno::RuntimeException
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();
127 bool copyData( const Uri & rSourceUri, const OUString & rNewName );
129 css::uno::Reference< css::ucb::XContentIdentifier >
130 makeNewIdentifier( const OUString& rTitle );
132 typedef rtl::Reference< Content > ContentRef;
133 typedef std::vector< ContentRef > ContentRefList;
134 void queryChildren( ContentRefList& rChildren );
136 bool exchangeIdentity(
137 const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
139 css::uno::Reference< css::sdbc::XRow >
140 getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties );
141 css::uno::Sequence< css::uno::Any >
142 /// @throws css::uno::Exception
143 setPropertyValues(
144 const css::uno::Sequence< css::beans::PropertyValue >& rValues,
145 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
147 /// @throws css::uno::Exception
148 css::uno::Any
149 open( const css::ucb::OpenCommandArgument2& rArg,
150 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
152 /// @throws css::uno::Exception
153 void insert( const css::uno::Reference< css::io::XInputStream >& xData,
154 sal_Int32 nNameClashResolve,
155 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
157 /// @throws css::uno::Exception
158 void destroy( bool bDeletePhysical,
159 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
161 /// @throws css::uno::Exception
162 void transfer( const css::ucb::TransferInfo& rInfo,
163 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
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 );
173 static bool commitStorage(
174 const css::uno::Reference< css::embed::XStorage > & xStorage );
176 static bool closeOutputStream(
177 const css::uno::Reference< css::io::XOutputStream > & xOut );
179 /// @throws css::ucb::CommandFailedException
180 /// @throws css::task::DocumentPasswordRequest
181 /// @throws css::uno::RuntimeException
182 css::uno::Reference< css::io::XInputStream >
183 getInputStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
185 /// @throws css::ucb::CommandFailedException
186 /// @throws css::task::DocumentPasswordRequest
187 /// @throws css::uno::RuntimeException
188 css::uno::Reference< css::io::XOutputStream >
189 getTruncatedOutputStream(
190 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
192 css::uno::Reference< css::ucb::XContent >
193 queryChildContent( const OUString & rRelativeChildUri );
195 /// @throws css::ucb::CommandFailedException
196 /// @throws css::task::DocumentPasswordRequest
197 /// @throws css::uno::RuntimeException
198 css::uno::Reference< css::io::XStream >
199 getStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
201 public:
202 // Create existing content. Fail, if not already exists.
203 static rtl::Reference<Content> create(
204 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
205 ContentProvider* pProvider,
206 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier );
208 // Create new content. Fail, if already exists.
209 static rtl::Reference<Content> create(
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 );
215 virtual ~Content() override;
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;
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;
228 // XServiceInfo
229 virtual OUString SAL_CALL
230 getImplementationName() override;
231 virtual css::uno::Sequence< OUString > SAL_CALL
232 getSupportedServiceNames() override;
234 // XContent
235 virtual OUString SAL_CALL
236 getContentType() override;
237 virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
238 getIdentifier() override;
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;
249 // Additional interfaces
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;
259 // Non-interface methods.
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 );
268 void notifyDocumentClosed();
269 void notifyChildRemoved( const OUString & rRelativeChildUri );
270 void notifyChildInserted( const OUString & rRelativeChildUri );
272 rtl::Reference< ContentProvider > getContentProvider() const
273 { return rtl::Reference< ContentProvider >( m_pProvider ); }
276 } // namespace tdoc_ucp
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */