1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_TDOC_CONTENT_HXX
21 #define INCLUDED_TDOC_CONTENT_HXX
23 #include <ucbhelper/contenthelper.hxx>
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"
29 #define NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 1
31 namespace com
{ namespace sun
{ namespace star
{
32 namespace sdbc
{ class XRow
; }
33 namespace io
{ class XInputStream
; class XOutputStream
; }
34 namespace beans
{ struct PropertyValue
; }
35 namespace ucb
{ struct OpenCommandArgument2
; struct TransferInfo
;
42 //=========================================================================
44 #define TDOC_ROOT_CONTENT_SERVICE_NAME \
45 "com.sun.star.ucb.TransientDocumentsRootContent"
46 #define TDOC_DOCUMENT_CONTENT_SERVICE_NAME \
47 "com.sun.star.ucb.TransientDocumentsDocumentContent"
48 #define TDOC_FOLDER_CONTENT_SERVICE_NAME \
49 "com.sun.star.ucb.TransientDocumentsFolderContent"
50 #define TDOC_STREAM_CONTENT_SERVICE_NAME \
51 "com.sun.star.ucb.TransientDocumentsStreamContent"
53 //=========================================================================
55 enum ContentType
{ STREAM
, FOLDER
, DOCUMENT
, ROOT
};
57 class ContentProperties
64 ContentProperties( const ContentType
& rType
, const rtl::OUString
& rTitle
)
66 m_aContentType( rType
== STREAM
67 ? rtl::OUString( TDOC_STREAM_CONTENT_TYPE
)
69 ? rtl::OUString( TDOC_FOLDER_CONTENT_TYPE
)
71 ? rtl::OUString( TDOC_DOCUMENT_CONTENT_TYPE
)
72 : rtl::OUString( TDOC_ROOT_CONTENT_TYPE
) ),
76 ContentType
getType() const { return m_eType
; }
80 const rtl::OUString
& getContentType() const { return m_aContentType
; }
82 bool getIsFolder() const { return m_eType
> STREAM
; }
83 bool getIsDocument() const { return !getIsFolder(); }
85 const rtl::OUString
& getTitle() const { return m_aTitle
; }
86 void setTitle( const rtl::OUString
& rTitle
) { m_aTitle
= rTitle
; }
88 com::sun::star::uno::Sequence
< com::sun::star::ucb::ContentInfo
>
89 getCreatableContentsInfo() const;
91 bool isContentCreator() const;
95 rtl::OUString m_aContentType
;
96 rtl::OUString m_aTitle
;
99 //=========================================================================
101 class Content
: public ::ucbhelper::ContentImplHelper
,
102 public com::sun::star::ucb::XContentCreator
104 enum ContentState
{ TRANSIENT
, // created via createNewContent,
105 // but did not process "insert" yet
106 PERSISTENT
, // processed "insert"
107 DEAD
// processed "delete" / document was closed
110 ContentProperties m_aProps
;
111 ContentState m_eState
;
112 ContentProvider
* m_pProvider
;
115 Content( const com::sun::star::uno::Reference
<
116 com::sun::star::uno::XComponentContext
>& rxContext
,
117 ContentProvider
* pProvider
,
118 const com::sun::star::uno::Reference
<
119 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
120 const ContentProperties
& rProps
);
121 Content( const com::sun::star::uno::Reference
<
122 com::sun::star::uno::XComponentContext
>& rxContext
,
123 ContentProvider
* pProvider
,
124 const com::sun::star::uno::Reference
<
125 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
126 const com::sun::star::ucb::ContentInfo
& Info
);
128 virtual com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>
129 getProperties( const com::sun::star::uno::Reference
<
130 com::sun::star::ucb::XCommandEnvironment
> & xEnv
);
131 virtual com::sun::star::uno::Sequence
< com::sun::star::ucb::CommandInfo
>
132 getCommands( const com::sun::star::uno::Reference
<
133 com::sun::star::ucb::XCommandEnvironment
> & xEnv
);
134 virtual ::rtl::OUString
getParentURL();
136 static bool hasData( ContentProvider
* pProvider
, const Uri
& rUri
);
137 bool hasData( const Uri
& rUri
) { return hasData( m_pProvider
, rUri
); }
139 static bool loadData( ContentProvider
* pProvider
,
141 ContentProperties
& rProps
);
142 bool storeData( const com::sun::star::uno::Reference
<
143 com::sun::star::io::XInputStream
>& xData
,
144 const com::sun::star::uno::Reference
<
145 com::sun::star::ucb::XCommandEnvironment
>& xEnv
)
146 throw ( ::com::sun::star::ucb::CommandFailedException
,
147 ::com::sun::star::task::DocumentPasswordRequest
);
148 bool renameData( const com::sun::star::uno::Reference
<
149 com::sun::star::ucb::XContentIdentifier
>& xOldId
,
150 const com::sun::star::uno::Reference
<
151 com::sun::star::ucb::XContentIdentifier
>& xNewId
);
154 bool copyData( const Uri
& rSourceUri
, const rtl::OUString
& rNewName
);
156 ::com::sun::star::uno::Reference
<
157 ::com::sun::star::ucb::XContentIdentifier
>
158 makeNewIdentifier( const rtl::OUString
& rTitle
);
160 typedef rtl::Reference
< Content
> ContentRef
;
161 typedef std::list
< ContentRef
> ContentRefList
;
162 void queryChildren( ContentRefList
& rChildren
);
164 sal_Bool
exchangeIdentity(
165 const ::com::sun::star::uno::Reference
<
166 ::com::sun::star::ucb::XContentIdentifier
>& xNewId
);
168 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
169 getPropertyValues( const ::com::sun::star::uno::Sequence
<
170 ::com::sun::star::beans::Property
>& rProperties
);
171 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>
173 const ::com::sun::star::uno::Sequence
<
174 ::com::sun::star::beans::PropertyValue
>& rValues
,
175 const ::com::sun::star::uno::Reference
<
176 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
177 throw( ::com::sun::star::uno::Exception
);
179 com::sun::star::uno::Any
180 open( const ::com::sun::star::ucb::OpenCommandArgument2
& rArg
,
181 const ::com::sun::star::uno::Reference
<
182 ::com::sun::star::ucb::XCommandEnvironment
>& xEnv
)
183 throw( ::com::sun::star::uno::Exception
);
185 void insert( const ::com::sun::star::uno::Reference
<
186 ::com::sun::star::io::XInputStream
>& xData
,
187 sal_Int32 nNameClashResolve
,
188 const ::com::sun::star::uno::Reference
<
189 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
190 throw( ::com::sun::star::uno::Exception
);
192 void destroy( sal_Bool bDeletePhysical
,
193 const ::com::sun::star::uno::Reference
<
194 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
195 throw( ::com::sun::star::uno::Exception
);
197 void transfer( const ::com::sun::star::ucb::TransferInfo
& rInfo
,
198 const ::com::sun::star::uno::Reference
<
199 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
200 throw( ::com::sun::star::uno::Exception
);
202 static ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
203 getPropertyValues( const ::com::sun::star::uno::Reference
<
204 ::com::sun::star::uno::XComponentContext
>& rxContext
,
205 const ::com::sun::star::uno::Sequence
<
206 ::com::sun::star::beans::Property
>& rProperties
,
207 const ContentProperties
& rData
,
208 ContentProvider
* pProvider
,
209 const ::rtl::OUString
& rContentId
);
212 static bool commitStorage(
213 const com::sun::star::uno::Reference
<
214 com::sun::star::embed::XStorage
> & xStorage
);
216 static bool closeOutputStream(
217 const com::sun::star::uno::Reference
<
218 com::sun::star::io::XOutputStream
> & xOut
);
220 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>
221 getInputStream( const ::com::sun::star::uno::Reference
<
222 ::com::sun::star::ucb::XCommandEnvironment
> &
224 throw ( ::com::sun::star::ucb::CommandFailedException
,
225 ::com::sun::star::task::DocumentPasswordRequest
);
227 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>
228 getTruncatedOutputStream(
229 const ::com::sun::star::uno::Reference
<
230 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
231 throw ( ::com::sun::star::ucb::CommandFailedException
,
232 ::com::sun::star::task::DocumentPasswordRequest
);
234 ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>
235 queryChildContent( const rtl::OUString
& rRelativeChildUri
);
237 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>
238 getStream( const ::com::sun::star::uno::Reference
<
239 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
240 throw ( ::com::sun::star::ucb::CommandFailedException
,
241 ::com::sun::star::task::DocumentPasswordRequest
);
244 // Create existing content. Fail, if not already exists.
245 static Content
* create(
246 const com::sun::star::uno::Reference
<
247 com::sun::star::uno::XComponentContext
>& rxContext
,
248 ContentProvider
* pProvider
,
249 const com::sun::star::uno::Reference
<
250 com::sun::star::ucb::XContentIdentifier
>& Identifier
);
252 // Create new content. Fail, if already exists.
253 static Content
* create(
254 const com::sun::star::uno::Reference
<
255 com::sun::star::uno::XComponentContext
>& rxContext
,
256 ContentProvider
* pProvider
,
257 const com::sun::star::uno::Reference
<
258 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
259 const com::sun::star::ucb::ContentInfo
& Info
);
270 virtual ::rtl::OUString SAL_CALL
271 getImplementationName()
272 throw( ::com::sun::star::uno::RuntimeException
);
273 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
274 getSupportedServiceNames()
275 throw( ::com::sun::star::uno::RuntimeException
);
278 virtual rtl::OUString SAL_CALL
280 throw( com::sun::star::uno::RuntimeException
);
281 virtual com::sun::star::uno::Reference
<
282 com::sun::star::ucb::XContentIdentifier
> SAL_CALL
284 throw( com::sun::star::uno::RuntimeException
);
287 virtual com::sun::star::uno::Any SAL_CALL
288 execute( const com::sun::star::ucb::Command
& aCommand
,
290 const com::sun::star::uno::Reference
<
291 com::sun::star::ucb::XCommandEnvironment
>& Environment
)
292 throw( com::sun::star::uno::Exception
,
293 com::sun::star::ucb::CommandAbortedException
,
294 com::sun::star::uno::RuntimeException
);
295 virtual void SAL_CALL
296 abort( sal_Int32 CommandId
)
297 throw( com::sun::star::uno::RuntimeException
);
299 //////////////////////////////////////////////////////////////////////
300 // Additional interfaces
301 //////////////////////////////////////////////////////////////////////
304 virtual com::sun::star::uno::Sequence
<
305 com::sun::star::ucb::ContentInfo
> SAL_CALL
306 queryCreatableContentsInfo()
307 throw( com::sun::star::uno::RuntimeException
);
308 virtual com::sun::star::uno::Reference
<
309 com::sun::star::ucb::XContent
> SAL_CALL
310 createNewContent( const com::sun::star::ucb::ContentInfo
& Info
)
311 throw( com::sun::star::uno::RuntimeException
);
313 //////////////////////////////////////////////////////////////////////
314 // Non-interface methods.
315 //////////////////////////////////////////////////////////////////////
317 static ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
318 getPropertyValues( const ::com::sun::star::uno::Reference
<
319 ::com::sun::star::uno::XComponentContext
>& rxContext
,
320 const ::com::sun::star::uno::Sequence
<
321 ::com::sun::star::beans::Property
>& rProperties
,
322 ContentProvider
* pProvider
,
323 const ::rtl::OUString
& rContentId
);
325 void notifyDocumentClosed();
326 void notifyChildRemoved( const rtl::OUString
& rRelativeChildUri
);
327 void notifyChildInserted( const rtl::OUString
& rRelativeChildUri
);
329 rtl::Reference
< ContentProvider
> getContentProvider() const
330 { return rtl::Reference
< ContentProvider
>( m_pProvider
); }
333 } // namespace tdoc_ucp
335 #endif /* !INCLUDED_TDOC_CONTENT_HXX */
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */