Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_TDOC_CONTENT_HXX
30 : : #define INCLUDED_TDOC_CONTENT_HXX
31 : :
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"
37 : :
38 : : #define NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 1
39 : :
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;
45 : : struct ContentInfo; }
46 : : } } }
47 : :
48 : : namespace tdoc_ucp
49 : : {
50 : :
51 : : //=========================================================================
52 : :
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"
61 : :
62 : : //=========================================================================
63 : :
64 : : enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT };
65 : :
66 : 475 : class ContentProperties
67 : : {
68 : : public:
69 : 95 : ContentProperties()
70 : 95 : : m_eType( STREAM )
71 : 95 : {}
72 : :
73 : 95 : ContentProperties( const ContentType & rType, const rtl::OUString & rTitle )
74 : : : m_eType( rType ),
75 : : m_aContentType( rType == STREAM
76 : : ? rtl::OUString( TDOC_STREAM_CONTENT_TYPE )
77 : : : rType == FOLDER
78 : : ? rtl::OUString( TDOC_FOLDER_CONTENT_TYPE )
79 : : : rType == DOCUMENT
80 : : ? rtl::OUString( TDOC_DOCUMENT_CONTENT_TYPE )
81 : : : rtl::OUString( TDOC_ROOT_CONTENT_TYPE ) ),
82 [ - + ][ - + ]: 95 : m_aTitle( rTitle )
[ + - ][ - + ]
[ + - ][ - + ]
[ - + ]
83 : 95 : {}
84 : :
85 : 45 : ContentType getType() const { return m_eType; }
86 : :
87 : : // Properties
88 : :
89 : 0 : const rtl::OUString & getContentType() const { return m_aContentType; }
90 : :
91 : 0 : bool getIsFolder() const { return m_eType > STREAM; }
92 : 0 : bool getIsDocument() const { return !getIsFolder(); }
93 : :
94 : 0 : const rtl::OUString & getTitle() const { return m_aTitle; }
95 : 0 : void setTitle( const rtl::OUString & rTitle ) { m_aTitle = rTitle; }
96 : :
97 : : com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo >
98 : : getCreatableContentsInfo() const;
99 : :
100 : : bool isContentCreator() const;
101 : :
102 : : private:
103 : : ContentType m_eType;
104 : : rtl::OUString m_aContentType;
105 : : rtl::OUString m_aTitle;
106 : : };
107 : :
108 : : //=========================================================================
109 : :
110 : : class Content : public ::ucbhelper::ContentImplHelper,
111 : : public com::sun::star::ucb::XContentCreator
112 : : {
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
117 : : };
118 : :
119 : : ContentProperties m_aProps;
120 : : ContentState m_eState;
121 : : ContentProvider* m_pProvider;
122 : :
123 : : private:
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 );
136 : :
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();
144 : :
145 : : static bool hasData( ContentProvider* pProvider, const Uri & rUri );
146 : 0 : bool hasData( const Uri & rUri ) { return hasData( m_pProvider, rUri ); }
147 : :
148 : : static bool loadData( ContentProvider* pProvider,
149 : : const Uri & rUri,
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 );
161 : : bool removeData();
162 : :
163 : : bool copyData( const Uri & rSourceUri, const rtl::OUString & rNewName );
164 : :
165 : : ::com::sun::star::uno::Reference<
166 : : ::com::sun::star::ucb::XContentIdentifier >
167 : : makeNewIdentifier( const rtl::OUString& rTitle );
168 : :
169 : : typedef rtl::Reference< Content > ContentRef;
170 : : typedef std::list< ContentRef > ContentRefList;
171 : : void queryChildren( ContentRefList& rChildren );
172 : :
173 : : sal_Bool exchangeIdentity(
174 : : const ::com::sun::star::uno::Reference<
175 : : ::com::sun::star::ucb::XContentIdentifier >& xNewId );
176 : :
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 >
181 : : setPropertyValues(
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 );
187 : :
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 );
193 : :
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 );
200 : :
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 );
205 : :
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 );
210 : :
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 );
219 : :
220 : :
221 : : static bool commitStorage(
222 : : const com::sun::star::uno::Reference<
223 : : com::sun::star::embed::XStorage > & xStorage );
224 : :
225 : : static bool closeOutputStream(
226 : : const com::sun::star::uno::Reference<
227 : : com::sun::star::io::XOutputStream > & xOut );
228 : :
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 > &
232 : : xEnv )
233 : : throw ( ::com::sun::star::ucb::CommandFailedException,
234 : : ::com::sun::star::task::DocumentPasswordRequest );
235 : :
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 );
242 : :
243 : : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >
244 : : queryChildContent( const rtl::OUString & rRelativeChildUri );
245 : :
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 );
251 : :
252 : : public:
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 );
260 : :
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 );
269 : :
270 : : virtual ~Content();
271 : :
272 : : // XInterface
273 : : XINTERFACE_DECL()
274 : :
275 : : // XTypeProvider
276 : : XTYPEPROVIDER_DECL()
277 : :
278 : : // XServiceInfo
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 );
285 : :
286 : : // XContent
287 : : virtual rtl::OUString SAL_CALL
288 : : getContentType()
289 : : throw( com::sun::star::uno::RuntimeException );
290 : : virtual com::sun::star::uno::Reference<
291 : : com::sun::star::ucb::XContentIdentifier > SAL_CALL
292 : : getIdentifier()
293 : : throw( com::sun::star::uno::RuntimeException );
294 : :
295 : : // XCommandProcessor
296 : : virtual com::sun::star::uno::Any SAL_CALL
297 : : execute( const com::sun::star::ucb::Command& aCommand,
298 : : sal_Int32 CommandId,
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 );
307 : :
308 : : //////////////////////////////////////////////////////////////////////
309 : : // Additional interfaces
310 : : //////////////////////////////////////////////////////////////////////
311 : :
312 : : // XContentCreator
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 );
321 : :
322 : : //////////////////////////////////////////////////////////////////////
323 : : // Non-interface methods.
324 : : //////////////////////////////////////////////////////////////////////
325 : :
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 );
333 : :
334 : : void notifyDocumentClosed();
335 : : void notifyChildRemoved( const rtl::OUString & rRelativeChildUri );
336 : : void notifyChildInserted( const rtl::OUString & rRelativeChildUri );
337 : :
338 : 0 : rtl::Reference< ContentProvider > getContentProvider() const
339 : 0 : { return rtl::Reference< ContentProvider >( m_pProvider ); }
340 : : };
341 : :
342 : : } // namespace tdoc_ucp
343 : :
344 : : #endif /* !INCLUDED_TDOC_CONTENT_HXX */
345 : :
346 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|