1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef INCLUDED_TDOC_CONTENT_HXX
30 #define INCLUDED_TDOC_CONTENT_HXX
32 #include <ucbhelper/contenthelper.hxx>
33 #include <com/sun/star/task/DocumentPasswordRequest.hpp>
34 #include <com/sun/star/ucb/XContentCreator.hpp>
35 #include <com/sun/star/ucb/CommandFailedException.hpp>
36 #include "tdoc_provider.hxx"
38 #define NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 1
40 namespace com
{ namespace sun
{ namespace star
{
41 namespace sdbc
{ class XRow
; }
42 namespace io
{ class XInputStream
; class XOutputStream
; }
43 namespace beans
{ struct PropertyValue
; }
44 namespace ucb
{ struct OpenCommandArgument2
; struct TransferInfo
;
51 //=========================================================================
53 #define TDOC_ROOT_CONTENT_SERVICE_NAME \
54 "com.sun.star.ucb.TransientDocumentsRootContent"
55 #define TDOC_DOCUMENT_CONTENT_SERVICE_NAME \
56 "com.sun.star.ucb.TransientDocumentsDocumentContent"
57 #define TDOC_FOLDER_CONTENT_SERVICE_NAME \
58 "com.sun.star.ucb.TransientDocumentsFolderContent"
59 #define TDOC_STREAM_CONTENT_SERVICE_NAME \
60 "com.sun.star.ucb.TransientDocumentsStreamContent"
62 //=========================================================================
64 enum ContentType
{ STREAM
, FOLDER
, DOCUMENT
, ROOT
};
66 class ContentProperties
73 ContentProperties( const ContentType
& rType
, const rtl::OUString
& rTitle
)
75 m_aContentType( rType
== STREAM
76 ? rtl::OUString( TDOC_STREAM_CONTENT_TYPE
)
78 ? rtl::OUString( TDOC_FOLDER_CONTENT_TYPE
)
80 ? rtl::OUString( TDOC_DOCUMENT_CONTENT_TYPE
)
81 : rtl::OUString( TDOC_ROOT_CONTENT_TYPE
) ),
85 ContentType
getType() const { return m_eType
; }
89 const rtl::OUString
& getContentType() const { return m_aContentType
; }
91 bool getIsFolder() const { return m_eType
> STREAM
; }
92 bool getIsDocument() const { return !getIsFolder(); }
94 const rtl::OUString
& getTitle() const { return m_aTitle
; }
95 void setTitle( const rtl::OUString
& rTitle
) { m_aTitle
= rTitle
; }
97 com::sun::star::uno::Sequence
< com::sun::star::ucb::ContentInfo
>
98 getCreatableContentsInfo() const;
100 bool isContentCreator() const;
104 rtl::OUString m_aContentType
;
105 rtl::OUString m_aTitle
;
108 //=========================================================================
110 class Content
: public ::ucbhelper::ContentImplHelper
,
111 public com::sun::star::ucb::XContentCreator
113 enum ContentState
{ TRANSIENT
, // created via createNewContent,
114 // but did not process "insert" yet
115 PERSISTENT
, // processed "insert"
116 DEAD
// processed "delete" / document was closed
119 ContentProperties m_aProps
;
120 ContentState m_eState
;
121 ContentProvider
* m_pProvider
;
124 Content( const com::sun::star::uno::Reference
<
125 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
126 ContentProvider
* pProvider
,
127 const com::sun::star::uno::Reference
<
128 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
129 const ContentProperties
& rProps
);
130 Content( const com::sun::star::uno::Reference
<
131 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
132 ContentProvider
* pProvider
,
133 const com::sun::star::uno::Reference
<
134 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
135 const com::sun::star::ucb::ContentInfo
& Info
);
137 virtual com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>
138 getProperties( const com::sun::star::uno::Reference
<
139 com::sun::star::ucb::XCommandEnvironment
> & xEnv
);
140 virtual com::sun::star::uno::Sequence
< com::sun::star::ucb::CommandInfo
>
141 getCommands( const com::sun::star::uno::Reference
<
142 com::sun::star::ucb::XCommandEnvironment
> & xEnv
);
143 virtual ::rtl::OUString
getParentURL();
145 static bool hasData( ContentProvider
* pProvider
, const Uri
& rUri
);
146 bool hasData( const Uri
& rUri
) { return hasData( m_pProvider
, rUri
); }
148 static bool loadData( ContentProvider
* pProvider
,
150 ContentProperties
& rProps
);
151 bool storeData( const com::sun::star::uno::Reference
<
152 com::sun::star::io::XInputStream
>& xData
,
153 const com::sun::star::uno::Reference
<
154 com::sun::star::ucb::XCommandEnvironment
>& xEnv
)
155 throw ( ::com::sun::star::ucb::CommandFailedException
,
156 ::com::sun::star::task::DocumentPasswordRequest
);
157 bool renameData( const com::sun::star::uno::Reference
<
158 com::sun::star::ucb::XContentIdentifier
>& xOldId
,
159 const com::sun::star::uno::Reference
<
160 com::sun::star::ucb::XContentIdentifier
>& xNewId
);
163 bool copyData( const Uri
& rSourceUri
, const rtl::OUString
& rNewName
);
165 ::com::sun::star::uno::Reference
<
166 ::com::sun::star::ucb::XContentIdentifier
>
167 makeNewIdentifier( const rtl::OUString
& rTitle
);
169 typedef rtl::Reference
< Content
> ContentRef
;
170 typedef std::list
< ContentRef
> ContentRefList
;
171 void queryChildren( ContentRefList
& rChildren
);
173 sal_Bool
exchangeIdentity(
174 const ::com::sun::star::uno::Reference
<
175 ::com::sun::star::ucb::XContentIdentifier
>& xNewId
);
177 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
178 getPropertyValues( const ::com::sun::star::uno::Sequence
<
179 ::com::sun::star::beans::Property
>& rProperties
);
180 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>
182 const ::com::sun::star::uno::Sequence
<
183 ::com::sun::star::beans::PropertyValue
>& rValues
,
184 const ::com::sun::star::uno::Reference
<
185 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
186 throw( ::com::sun::star::uno::Exception
);
188 com::sun::star::uno::Any
189 open( const ::com::sun::star::ucb::OpenCommandArgument2
& rArg
,
190 const ::com::sun::star::uno::Reference
<
191 ::com::sun::star::ucb::XCommandEnvironment
>& xEnv
)
192 throw( ::com::sun::star::uno::Exception
);
194 void insert( const ::com::sun::star::uno::Reference
<
195 ::com::sun::star::io::XInputStream
>& xData
,
196 sal_Int32 nNameClashResolve
,
197 const ::com::sun::star::uno::Reference
<
198 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
199 throw( ::com::sun::star::uno::Exception
);
201 void destroy( sal_Bool bDeletePhysical
,
202 const ::com::sun::star::uno::Reference
<
203 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
204 throw( ::com::sun::star::uno::Exception
);
206 void transfer( const ::com::sun::star::ucb::TransferInfo
& rInfo
,
207 const ::com::sun::star::uno::Reference
<
208 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
209 throw( ::com::sun::star::uno::Exception
);
211 static ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
212 getPropertyValues( const ::com::sun::star::uno::Reference
<
213 ::com::sun::star::lang::XMultiServiceFactory
>& rSMgr
,
214 const ::com::sun::star::uno::Sequence
<
215 ::com::sun::star::beans::Property
>& rProperties
,
216 const ContentProperties
& rData
,
217 ContentProvider
* pProvider
,
218 const ::rtl::OUString
& rContentId
);
221 static bool commitStorage(
222 const com::sun::star::uno::Reference
<
223 com::sun::star::embed::XStorage
> & xStorage
);
225 static bool closeOutputStream(
226 const com::sun::star::uno::Reference
<
227 com::sun::star::io::XOutputStream
> & xOut
);
229 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>
230 getInputStream( const ::com::sun::star::uno::Reference
<
231 ::com::sun::star::ucb::XCommandEnvironment
> &
233 throw ( ::com::sun::star::ucb::CommandFailedException
,
234 ::com::sun::star::task::DocumentPasswordRequest
);
236 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>
237 getTruncatedOutputStream(
238 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
);
243 ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>
244 queryChildContent( const rtl::OUString
& rRelativeChildUri
);
246 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>
247 getStream( const ::com::sun::star::uno::Reference
<
248 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
249 throw ( ::com::sun::star::ucb::CommandFailedException
,
250 ::com::sun::star::task::DocumentPasswordRequest
);
253 // Create existing content. Fail, if not already exists.
254 static Content
* create(
255 const com::sun::star::uno::Reference
<
256 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
257 ContentProvider
* pProvider
,
258 const com::sun::star::uno::Reference
<
259 com::sun::star::ucb::XContentIdentifier
>& Identifier
);
261 // Create new content. Fail, if already exists.
262 static Content
* create(
263 const com::sun::star::uno::Reference
<
264 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
265 ContentProvider
* pProvider
,
266 const com::sun::star::uno::Reference
<
267 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
268 const com::sun::star::ucb::ContentInfo
& Info
);
279 virtual ::rtl::OUString SAL_CALL
280 getImplementationName()
281 throw( ::com::sun::star::uno::RuntimeException
);
282 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
283 getSupportedServiceNames()
284 throw( ::com::sun::star::uno::RuntimeException
);
287 virtual rtl::OUString SAL_CALL
289 throw( com::sun::star::uno::RuntimeException
);
290 virtual com::sun::star::uno::Reference
<
291 com::sun::star::ucb::XContentIdentifier
> SAL_CALL
293 throw( com::sun::star::uno::RuntimeException
);
296 virtual com::sun::star::uno::Any SAL_CALL
297 execute( const com::sun::star::ucb::Command
& aCommand
,
299 const com::sun::star::uno::Reference
<
300 com::sun::star::ucb::XCommandEnvironment
>& Environment
)
301 throw( com::sun::star::uno::Exception
,
302 com::sun::star::ucb::CommandAbortedException
,
303 com::sun::star::uno::RuntimeException
);
304 virtual void SAL_CALL
305 abort( sal_Int32 CommandId
)
306 throw( com::sun::star::uno::RuntimeException
);
308 //////////////////////////////////////////////////////////////////////
309 // Additional interfaces
310 //////////////////////////////////////////////////////////////////////
313 virtual com::sun::star::uno::Sequence
<
314 com::sun::star::ucb::ContentInfo
> SAL_CALL
315 queryCreatableContentsInfo()
316 throw( com::sun::star::uno::RuntimeException
);
317 virtual com::sun::star::uno::Reference
<
318 com::sun::star::ucb::XContent
> SAL_CALL
319 createNewContent( const com::sun::star::ucb::ContentInfo
& Info
)
320 throw( com::sun::star::uno::RuntimeException
);
322 //////////////////////////////////////////////////////////////////////
323 // Non-interface methods.
324 //////////////////////////////////////////////////////////////////////
326 static ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
327 getPropertyValues( const ::com::sun::star::uno::Reference
<
328 ::com::sun::star::lang::XMultiServiceFactory
>& rSMgr
,
329 const ::com::sun::star::uno::Sequence
<
330 ::com::sun::star::beans::Property
>& rProperties
,
331 ContentProvider
* pProvider
,
332 const ::rtl::OUString
& rContentId
);
334 void notifyDocumentClosed();
335 void notifyChildRemoved( const rtl::OUString
& rRelativeChildUri
);
336 void notifyChildInserted( const rtl::OUString
& rRelativeChildUri
);
338 rtl::Reference
< ContentProvider
> getContentProvider() const
339 { return rtl::Reference
< ContentProvider
>( m_pProvider
); }
342 } // namespace tdoc_ucp
344 #endif /* !INCLUDED_TDOC_CONTENT_HXX */
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */