update dev300-m58
[ooovba.git] / ucb / source / ucp / tdoc / tdoc_content.hxx
blob1e6f03544b5d229bb4fbcfe633f3ad87eaf84dc8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tdoc_content.hxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_TDOC_CONTENT_HXX
32 #define INCLUDED_TDOC_CONTENT_HXX
34 #include <ucbhelper/contenthelper.hxx>
35 #include <com/sun/star/task/DocumentPasswordRequest.hpp>
36 #include <com/sun/star/ucb/XContentCreator.hpp>
37 #include <com/sun/star/ucb/CommandFailedException.hpp>
38 #include "tdoc_provider.hxx"
40 #define NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 1
42 namespace com { namespace sun { namespace star {
43 namespace sdbc { class XRow; }
44 namespace io { class XInputStream; class XOutputStream; }
45 namespace beans { struct PropertyValue; }
46 namespace ucb { struct OpenCommandArgument2; struct TransferInfo; }
47 } } }
49 namespace tdoc_ucp
52 //=========================================================================
54 #define TDOC_ROOT_CONTENT_SERVICE_NAME \
55 "com.sun.star.ucb.TransientDocumentsRootContent"
56 #define TDOC_DOCUMENT_CONTENT_SERVICE_NAME \
57 "com.sun.star.ucb.TransientDocumentsDocumentContent"
58 #define TDOC_FOLDER_CONTENT_SERVICE_NAME \
59 "com.sun.star.ucb.TransientDocumentsFolderContent"
60 #define TDOC_STREAM_CONTENT_SERVICE_NAME \
61 "com.sun.star.ucb.TransientDocumentsStreamContent"
63 //=========================================================================
65 enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT };
67 class ContentProperties
69 public:
70 ContentProperties()
73 ContentProperties( const ContentType & rType, const rtl::OUString & rTitle )
74 : m_eType( rType ),
75 m_aContentType( rType == STREAM
76 ? rtl::OUString::createFromAscii( TDOC_STREAM_CONTENT_TYPE )
77 : rType == FOLDER
78 ? rtl::OUString::createFromAscii( TDOC_FOLDER_CONTENT_TYPE )
79 : rType == DOCUMENT
80 ? rtl::OUString::createFromAscii( TDOC_DOCUMENT_CONTENT_TYPE )
81 : rtl::OUString::createFromAscii( TDOC_ROOT_CONTENT_TYPE ) ),
82 m_aTitle( rTitle )
85 ContentType getType() const { return m_eType; }
87 // Properties
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 private:
98 ContentType m_eType;
99 rtl::OUString m_aContentType;
100 rtl::OUString m_aTitle;
103 //=========================================================================
105 class Content : public ::ucbhelper::ContentImplHelper,
106 public com::sun::star::ucb::XContentCreator
108 enum ContentState { TRANSIENT, // created via createNewContent,
109 // but did not process "insert" yet
110 PERSISTENT, // processed "insert"
111 DEAD // processed "delete" / document was closed
114 ContentProperties m_aProps;
115 ContentState m_eState;
116 ContentProvider* m_pProvider;
118 private:
119 Content( const com::sun::star::uno::Reference<
120 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
121 ContentProvider* pProvider,
122 const com::sun::star::uno::Reference<
123 com::sun::star::ucb::XContentIdentifier >& Identifier,
124 const ContentProperties & rProps );
125 Content( const com::sun::star::uno::Reference<
126 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
127 ContentProvider* pProvider,
128 const com::sun::star::uno::Reference<
129 com::sun::star::ucb::XContentIdentifier >& Identifier,
130 const com::sun::star::ucb::ContentInfo& Info );
132 virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
133 getProperties( const com::sun::star::uno::Reference<
134 com::sun::star::ucb::XCommandEnvironment > & xEnv );
135 virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
136 getCommands( const com::sun::star::uno::Reference<
137 com::sun::star::ucb::XCommandEnvironment > & xEnv );
138 virtual ::rtl::OUString getParentURL();
140 bool isContentCreator();
142 static bool hasData( ContentProvider* pProvider, const Uri & rUri );
143 bool hasData( const Uri & rUri ) { return hasData( m_pProvider, rUri ); }
145 static bool loadData( ContentProvider* pProvider,
146 const Uri & rUri,
147 ContentProperties& rProps );
148 bool storeData( const com::sun::star::uno::Reference<
149 com::sun::star::io::XInputStream >& xData,
150 const com::sun::star::uno::Reference<
151 com::sun::star::ucb::XCommandEnvironment >& xEnv )
152 throw ( ::com::sun::star::ucb::CommandFailedException,
153 ::com::sun::star::task::DocumentPasswordRequest );
154 bool renameData( const com::sun::star::uno::Reference<
155 com::sun::star::ucb::XContentIdentifier >& xOldId,
156 const com::sun::star::uno::Reference<
157 com::sun::star::ucb::XContentIdentifier >& xNewId );
158 bool removeData();
160 bool copyData( const Uri & rSourceUri, const rtl::OUString & rNewName );
162 ::com::sun::star::uno::Reference<
163 ::com::sun::star::ucb::XContentIdentifier >
164 makeNewIdentifier( const rtl::OUString& rTitle );
166 typedef rtl::Reference< Content > ContentRef;
167 typedef std::list< ContentRef > ContentRefList;
168 void queryChildren( ContentRefList& rChildren );
170 sal_Bool exchangeIdentity(
171 const ::com::sun::star::uno::Reference<
172 ::com::sun::star::ucb::XContentIdentifier >& xNewId );
174 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
175 getPropertyValues( const ::com::sun::star::uno::Sequence<
176 ::com::sun::star::beans::Property >& rProperties );
177 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
178 setPropertyValues(
179 const ::com::sun::star::uno::Sequence<
180 ::com::sun::star::beans::PropertyValue >& rValues,
181 const ::com::sun::star::uno::Reference<
182 ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
183 throw( ::com::sun::star::uno::Exception );
185 com::sun::star::uno::Any
186 open( const ::com::sun::star::ucb::OpenCommandArgument2& rArg,
187 const ::com::sun::star::uno::Reference<
188 ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
189 throw( ::com::sun::star::uno::Exception );
191 void insert( const ::com::sun::star::uno::Reference<
192 ::com::sun::star::io::XInputStream >& xData,
193 sal_Int32 nNameClashResolve,
194 const ::com::sun::star::uno::Reference<
195 ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
196 throw( ::com::sun::star::uno::Exception );
198 void destroy( sal_Bool bDeletePhysical,
199 const ::com::sun::star::uno::Reference<
200 ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
201 throw( ::com::sun::star::uno::Exception );
203 void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo,
204 const ::com::sun::star::uno::Reference<
205 ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
206 throw( ::com::sun::star::uno::Exception );
208 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
209 getPropertyValues( const ::com::sun::star::uno::Reference<
210 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
211 const ::com::sun::star::uno::Sequence<
212 ::com::sun::star::beans::Property >& rProperties,
213 const ContentProperties& rData,
214 ContentProvider* pProvider,
215 const ::rtl::OUString& rContentId );
218 static bool commitStorage(
219 const com::sun::star::uno::Reference<
220 com::sun::star::embed::XStorage > & xStorage );
222 static bool closeOutputStream(
223 const com::sun::star::uno::Reference<
224 com::sun::star::io::XOutputStream > & xOut );
226 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
227 getInputStream( const ::com::sun::star::uno::Reference<
228 ::com::sun::star::ucb::XCommandEnvironment > &
229 xEnv )
230 throw ( ::com::sun::star::ucb::CommandFailedException,
231 ::com::sun::star::task::DocumentPasswordRequest );
233 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
234 getTruncatedOutputStream(
235 const ::com::sun::star::uno::Reference<
236 ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
237 throw ( ::com::sun::star::ucb::CommandFailedException,
238 ::com::sun::star::task::DocumentPasswordRequest );
240 ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >
241 queryChildContent( const rtl::OUString & rRelativeChildUri );
243 ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >
244 getStream( const ::com::sun::star::uno::Reference<
245 ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
246 throw ( ::com::sun::star::ucb::CommandFailedException,
247 ::com::sun::star::task::DocumentPasswordRequest );
249 public:
250 // Create existing content. Fail, if not already exists.
251 static Content* create(
252 const com::sun::star::uno::Reference<
253 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
254 ContentProvider* pProvider,
255 const com::sun::star::uno::Reference<
256 com::sun::star::ucb::XContentIdentifier >& Identifier );
258 // Create new content. Fail, if already exists.
259 static Content* create(
260 const com::sun::star::uno::Reference<
261 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
262 ContentProvider* pProvider,
263 const com::sun::star::uno::Reference<
264 com::sun::star::ucb::XContentIdentifier >& Identifier,
265 const com::sun::star::ucb::ContentInfo& Info );
267 virtual ~Content();
269 // XInterface
270 XINTERFACE_DECL()
272 // XTypeProvider
273 XTYPEPROVIDER_DECL()
275 // XServiceInfo
276 virtual ::rtl::OUString SAL_CALL
277 getImplementationName()
278 throw( ::com::sun::star::uno::RuntimeException );
279 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
280 getSupportedServiceNames()
281 throw( ::com::sun::star::uno::RuntimeException );
283 // XContent
284 virtual rtl::OUString SAL_CALL
285 getContentType()
286 throw( com::sun::star::uno::RuntimeException );
287 virtual com::sun::star::uno::Reference<
288 com::sun::star::ucb::XContentIdentifier > SAL_CALL
289 getIdentifier()
290 throw( com::sun::star::uno::RuntimeException );
292 // XCommandProcessor
293 virtual com::sun::star::uno::Any SAL_CALL
294 execute( const com::sun::star::ucb::Command& aCommand,
295 sal_Int32 CommandId,
296 const com::sun::star::uno::Reference<
297 com::sun::star::ucb::XCommandEnvironment >& Environment )
298 throw( com::sun::star::uno::Exception,
299 com::sun::star::ucb::CommandAbortedException,
300 com::sun::star::uno::RuntimeException );
301 virtual void SAL_CALL
302 abort( sal_Int32 CommandId )
303 throw( com::sun::star::uno::RuntimeException );
305 //////////////////////////////////////////////////////////////////////
306 // Additional interfaces
307 //////////////////////////////////////////////////////////////////////
309 // XContentCreator
310 virtual com::sun::star::uno::Sequence<
311 com::sun::star::ucb::ContentInfo > SAL_CALL
312 queryCreatableContentsInfo()
313 throw( com::sun::star::uno::RuntimeException );
314 virtual com::sun::star::uno::Reference<
315 com::sun::star::ucb::XContent > SAL_CALL
316 createNewContent( const com::sun::star::ucb::ContentInfo& Info )
317 throw( com::sun::star::uno::RuntimeException );
319 //////////////////////////////////////////////////////////////////////
320 // Non-interface methods.
321 //////////////////////////////////////////////////////////////////////
323 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
324 getPropertyValues( const ::com::sun::star::uno::Reference<
325 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
326 const ::com::sun::star::uno::Sequence<
327 ::com::sun::star::beans::Property >& rProperties,
328 ContentProvider* pProvider,
329 const ::rtl::OUString& rContentId );
331 void notifyDocumentClosed();
332 void notifyChildRemoved( const rtl::OUString & rRelativeChildUri );
333 void notifyChildInserted( const rtl::OUString & rRelativeChildUri );
335 rtl::Reference< ContentProvider > getContentProvider() const
336 { return rtl::Reference< ContentProvider >( m_pProvider ); }
339 } // namespace tdoc_ucp
341 #endif /* !INCLUDED_TDOC_CONTENT_HXX */