xref: /trunk/main/ucb/source/ucp/tdoc/tdoc_content.hxx (revision 6df1ea1f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_TDOC_CONTENT_HXX
25 #define INCLUDED_TDOC_CONTENT_HXX
26 
27 #include <ucbhelper/contenthelper.hxx>
28 #include <com/sun/star/task/DocumentPasswordRequest.hpp>
29 #include <com/sun/star/ucb/XContentCreator.hpp>
30 #include <com/sun/star/ucb/CommandFailedException.hpp>
31 #include "tdoc_provider.hxx"
32 
33 #define NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 1
34 
35 namespace com { namespace sun { namespace star {
36     namespace sdbc  { class XRow; }
37     namespace io    { class XInputStream; class XOutputStream; }
38     namespace beans { struct PropertyValue; }
39     namespace ucb   { struct OpenCommandArgument2; struct TransferInfo;
40                       struct ContentInfo; }
41 } } }
42 
43 namespace tdoc_ucp
44 {
45 
46 //=========================================================================
47 
48 #define TDOC_ROOT_CONTENT_SERVICE_NAME \
49                 "com.sun.star.ucb.TransientDocumentsRootContent"
50 #define TDOC_DOCUMENT_CONTENT_SERVICE_NAME \
51                 "com.sun.star.ucb.TransientDocumentsDocumentContent"
52 #define TDOC_FOLDER_CONTENT_SERVICE_NAME \
53                 "com.sun.star.ucb.TransientDocumentsFolderContent"
54 #define TDOC_STREAM_CONTENT_SERVICE_NAME \
55                 "com.sun.star.ucb.TransientDocumentsStreamContent"
56 
57 //=========================================================================
58 
59 enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT };
60 
61 class ContentProperties
62 {
63 public:
ContentProperties()64     ContentProperties()
65     {}
66 
ContentProperties(const ContentType & rType,const rtl::OUString & rTitle)67     ContentProperties( const ContentType & rType, const rtl::OUString & rTitle )
68     : m_eType( rType ),
69       m_aContentType( rType == STREAM
70         ? rtl::OUString::createFromAscii( TDOC_STREAM_CONTENT_TYPE )
71         : rType == FOLDER
72             ? rtl::OUString::createFromAscii( TDOC_FOLDER_CONTENT_TYPE )
73             : rType == DOCUMENT
74                 ? rtl::OUString::createFromAscii( TDOC_DOCUMENT_CONTENT_TYPE )
75                 : rtl::OUString::createFromAscii( TDOC_ROOT_CONTENT_TYPE ) ),
76       m_aTitle( rTitle )
77     {}
78 
getType() const79     ContentType getType() const { return m_eType; }
80 
81     // Properties
82 
getContentType() const83     const rtl::OUString & getContentType() const { return m_aContentType; }
84 
getIsFolder() const85     bool getIsFolder()   const { return m_eType > STREAM; }
getIsDocument() const86     bool getIsDocument() const { return !getIsFolder(); }
87 
getTitle() const88     const rtl::OUString & getTitle() const { return m_aTitle; }
setTitle(const rtl::OUString & rTitle)89     void setTitle( const rtl::OUString & rTitle ) { m_aTitle = rTitle; }
90 
91     com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo >
92     getCreatableContentsInfo() const;
93 
94     bool isContentCreator() const;
95 
96 private:
97     ContentType   m_eType;
98     rtl::OUString m_aContentType;
99     rtl::OUString m_aTitle;
100 };
101 
102 //=========================================================================
103 
104 class Content : public ::ucbhelper::ContentImplHelper,
105                 public com::sun::star::ucb::XContentCreator
106 {
107     enum ContentState { TRANSIENT,  // created via createNewContent,
108                                         // but did not process "insert" yet
109                         PERSISTENT, // processed "insert"
110                         DEAD        // processed "delete" / document was closed
111                       };
112 
113     ContentProperties m_aProps;
114     ContentState      m_eState;
115     ContentProvider*  m_pProvider;
116 
117 private:
118     Content( const com::sun::star::uno::Reference<
119                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
120              ContentProvider* pProvider,
121              const com::sun::star::uno::Reference<
122                 com::sun::star::ucb::XContentIdentifier >& Identifier,
123             const ContentProperties & rProps );
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 com::sun::star::ucb::ContentInfo& Info );
130 
131     virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
132     getProperties( const com::sun::star::uno::Reference<
133                     com::sun::star::ucb::XCommandEnvironment > & xEnv );
134     virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
135     getCommands( const com::sun::star::uno::Reference<
136                     com::sun::star::ucb::XCommandEnvironment > & xEnv );
137     virtual ::rtl::OUString getParentURL();
138 
139     static bool hasData( ContentProvider* pProvider, const Uri & rUri );
hasData(const Uri & rUri)140     bool hasData( const Uri & rUri ) { return hasData( m_pProvider, rUri ); }
141 
142     static bool loadData( ContentProvider* pProvider,
143                           const Uri & rUri,
144                           ContentProperties& rProps );
145     bool storeData( const com::sun::star::uno::Reference<
146                         com::sun::star::io::XInputStream >& xData,
147                     const com::sun::star::uno::Reference<
148                         com::sun::star::ucb::XCommandEnvironment >& xEnv )
149         throw ( ::com::sun::star::ucb::CommandFailedException,
150                 ::com::sun::star::task::DocumentPasswordRequest );
151     bool renameData( const com::sun::star::uno::Reference<
152                         com::sun::star::ucb::XContentIdentifier >& xOldId,
153                      const com::sun::star::uno::Reference<
154                         com::sun::star::ucb::XContentIdentifier >& xNewId );
155     bool removeData();
156 
157     bool copyData( const Uri & rSourceUri, const rtl::OUString & rNewName );
158 
159     ::com::sun::star::uno::Reference<
160         ::com::sun::star::ucb::XContentIdentifier >
161     makeNewIdentifier( const rtl::OUString& rTitle );
162 
163     typedef rtl::Reference< Content > ContentRef;
164     typedef std::list< ContentRef > ContentRefList;
165     void queryChildren( ContentRefList& rChildren );
166 
167     sal_Bool exchangeIdentity(
168                 const ::com::sun::star::uno::Reference<
169                         ::com::sun::star::ucb::XContentIdentifier >& xNewId	);
170 
171     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
172     getPropertyValues( const ::com::sun::star::uno::Sequence<
173                             ::com::sun::star::beans::Property >& rProperties );
174     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
175     setPropertyValues(
176             const ::com::sun::star::uno::Sequence<
177                     ::com::sun::star::beans::PropertyValue >& rValues,
178             const ::com::sun::star::uno::Reference<
179                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
180         throw( ::com::sun::star::uno::Exception );
181 
182     com::sun::star::uno::Any
183     open( const ::com::sun::star::ucb::OpenCommandArgument2& rArg,
184           const ::com::sun::star::uno::Reference<
185             ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
186         throw( ::com::sun::star::uno::Exception );
187 
188     void insert( const ::com::sun::star::uno::Reference<
189                     ::com::sun::star::io::XInputStream >& xData,
190                  sal_Int32 nNameClashResolve,
191                  const ::com::sun::star::uno::Reference<
192                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
193         throw( ::com::sun::star::uno::Exception );
194 
195     void destroy( sal_Bool bDeletePhysical,
196                   const ::com::sun::star::uno::Reference<
197                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
198         throw( ::com::sun::star::uno::Exception );
199 
200     void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo,
201                    const ::com::sun::star::uno::Reference<
202                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
203         throw( ::com::sun::star::uno::Exception );
204 
205     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
206     getPropertyValues( const ::com::sun::star::uno::Reference<
207                         ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
208                        const ::com::sun::star::uno::Sequence<
209                         ::com::sun::star::beans::Property >& rProperties,
210                        const ContentProperties& rData,
211                        ContentProvider* pProvider,
212                        const ::rtl::OUString& rContentId );
213 
214 
215     static bool commitStorage(
216         const com::sun::star::uno::Reference<
217             com::sun::star::embed::XStorage > & xStorage );
218 
219     static bool closeOutputStream(
220         const com::sun::star::uno::Reference<
221             com::sun::star::io::XOutputStream > & xOut );
222 
223     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
224     getInputStream( const ::com::sun::star::uno::Reference<
225                         ::com::sun::star::ucb::XCommandEnvironment > &
226                             xEnv )
227         throw ( ::com::sun::star::ucb::CommandFailedException,
228                 ::com::sun::star::task::DocumentPasswordRequest );
229 
230     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
231     getTruncatedOutputStream(
232         const ::com::sun::star::uno::Reference<
233             ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
234         throw ( ::com::sun::star::ucb::CommandFailedException,
235                 ::com::sun::star::task::DocumentPasswordRequest );
236 
237     ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >
238     queryChildContent( const rtl::OUString & rRelativeChildUri );
239 
240     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >
241     getStream( const ::com::sun::star::uno::Reference<
242                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
243         throw ( ::com::sun::star::ucb::CommandFailedException,
244                 ::com::sun::star::task::DocumentPasswordRequest );
245 
246 public:
247     // Create existing content. Fail, if not already exists.
248     static Content* create(
249             const com::sun::star::uno::Reference<
250                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
251             ContentProvider* pProvider,
252             const com::sun::star::uno::Reference<
253                 com::sun::star::ucb::XContentIdentifier >& Identifier );
254 
255     // Create new content. Fail, if already exists.
256     static Content* create(
257             const com::sun::star::uno::Reference<
258                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
259             ContentProvider* pProvider,
260             const com::sun::star::uno::Reference<
261                 com::sun::star::ucb::XContentIdentifier >& Identifier,
262             const com::sun::star::ucb::ContentInfo& Info );
263 
264     virtual ~Content();
265 
266     // XInterface
267     XINTERFACE_DECL()
268 
269     // XTypeProvider
270     XTYPEPROVIDER_DECL()
271 
272     // XServiceInfo
273     virtual ::rtl::OUString SAL_CALL
274     getImplementationName()
275         throw( ::com::sun::star::uno::RuntimeException );
276     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
277     getSupportedServiceNames()
278         throw( ::com::sun::star::uno::RuntimeException );
279 
280     // XContent
281     virtual rtl::OUString SAL_CALL
282     getContentType()
283         throw( com::sun::star::uno::RuntimeException );
284     virtual com::sun::star::uno::Reference<
285                 com::sun::star::ucb::XContentIdentifier > SAL_CALL
286     getIdentifier()
287         throw( com::sun::star::uno::RuntimeException );
288 
289     // XCommandProcessor
290     virtual com::sun::star::uno::Any SAL_CALL
291     execute( const com::sun::star::ucb::Command& aCommand,
292              sal_Int32 CommandId,
293              const com::sun::star::uno::Reference<
294                 com::sun::star::ucb::XCommandEnvironment >& Environment )
295         throw( com::sun::star::uno::Exception,
296                com::sun::star::ucb::CommandAbortedException,
297                com::sun::star::uno::RuntimeException );
298     virtual void SAL_CALL
299     abort( sal_Int32 CommandId )
300         throw( com::sun::star::uno::RuntimeException );
301 
302     //////////////////////////////////////////////////////////////////////
303     // Additional interfaces
304     //////////////////////////////////////////////////////////////////////
305 
306     // XContentCreator
307     virtual com::sun::star::uno::Sequence<
308                 com::sun::star::ucb::ContentInfo > SAL_CALL
309     queryCreatableContentsInfo()
310         throw( com::sun::star::uno::RuntimeException );
311     virtual com::sun::star::uno::Reference<
312                 com::sun::star::ucb::XContent > SAL_CALL
313     createNewContent( const com::sun::star::ucb::ContentInfo& Info )
314         throw( com::sun::star::uno::RuntimeException );
315 
316     //////////////////////////////////////////////////////////////////////
317     // Non-interface methods.
318     //////////////////////////////////////////////////////////////////////
319 
320     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
321     getPropertyValues( const ::com::sun::star::uno::Reference<
322                         ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
323                        const ::com::sun::star::uno::Sequence<
324                         ::com::sun::star::beans::Property >& rProperties,
325                        ContentProvider* pProvider,
326                        const ::rtl::OUString& rContentId );
327 
328     void notifyDocumentClosed();
329     void notifyChildRemoved( const rtl::OUString & rRelativeChildUri );
330     void notifyChildInserted( const rtl::OUString & rRelativeChildUri );
331 
getContentProvider() const332     rtl::Reference< ContentProvider > getContentProvider() const
333     { return rtl::Reference< ContentProvider >( m_pProvider ); }
334 };
335 
336 } // namespace tdoc_ucp
337 
338 #endif /* !INCLUDED_TDOC_CONTENT_HXX */
339