1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _WEBDAV_UCP_CONTENT_HXX
29 #define _WEBDAV_UCP_CONTENT_HXX
30 
31 #include <memory>
32 #include <list>
33 #include <rtl/ref.hxx>
34 #include <com/sun/star/ucb/ContentCreationException.hpp>
35 #include <com/sun/star/ucb/XContentCreator.hpp>
36 #include <ucbhelper/contenthelper.hxx>
37 #include "DAVResourceAccess.hxx"
38 #include "PropertyMap.hxx"
39 
40 namespace com { namespace sun { namespace star { namespace beans {
41     struct Property;
42     struct PropertyValue;
43 } } } }
44 
45 namespace com { namespace sun { namespace star { namespace io {
46     class XInputStream;
47 } } } }
48 
49 namespace com { namespace sun { namespace star { namespace sdbc {
50     class XRow;
51 } } } }
52 
53 namespace com { namespace sun { namespace star { namespace ucb {
54     struct OpenCommandArgument2;
55     struct PostCommandArgument2;
56     struct TransferInfo;
57 } } } }
58 
59 namespace webdav_ucp
60 {
61 
62 //=========================================================================
63 
64 // UNO service name for the content.
65 #define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent"
66 
67 //=========================================================================
68 
69 class ContentProvider;
70 class ContentProperties;
71 class CachableContentProperties;
72 
73 class Content : public ::ucbhelper::ContentImplHelper,
74                 public com::sun::star::ucb::XContentCreator
75 {
76     enum ResourceType
77     {
78         UNKNOWN,
79         FTP,
80         NON_DAV,
81         DAV
82     };
83 
84     std::auto_ptr< DAVResourceAccess > m_xResAccess;
85     std::auto_ptr< CachableContentProperties >
86                       m_xCachedProps; // locally cached props
87     rtl::OUString     m_aEscapedTitle;
88     ResourceType      m_eResourceType;
89     ContentProvider*  m_pProvider; // No need for a ref, base class holds object
90     bool              m_bTransient;
91     bool              m_bCollection;
92     bool              m_bDidGetOrHead;
93     std::vector< rtl::OUString > m_aFailedPropNames;
94 
95 private:
96     virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
97     getProperties( const com::sun::star::uno::Reference<
98                        com::sun::star::ucb::XCommandEnvironment > & xEnv );
99     virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
100     getCommands( const com::sun::star::uno::Reference<
101                      com::sun::star::ucb::XCommandEnvironment > & xEnv );
102     virtual ::rtl::OUString getParentURL();
103 
104     sal_Bool isFolder( const ::com::sun::star::uno::Reference<
105                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
106         throw ( ::com::sun::star::uno::Exception );
107 
108     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
109     getPropertyValues( const ::com::sun::star::uno::Sequence<
110                            ::com::sun::star::beans::Property >& rProperties,
111                        const ::com::sun::star::uno::Reference<
112                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
113         throw ( ::com::sun::star::uno::Exception );
114 
115     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
116     setPropertyValues( const ::com::sun::star::uno::Sequence<
117                            ::com::sun::star::beans::PropertyValue >& rValues,
118                        const ::com::sun::star::uno::Reference<
119                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
120         throw ( ::com::sun::star::uno::Exception );
121 
122     typedef rtl::Reference< Content > ContentRef;
123     typedef std::list< ContentRef > ContentRefList;
124     void queryChildren( ContentRefList& rChildren);
125 
126     sal_Bool
127     exchangeIdentity( const ::com::sun::star::uno::Reference<
128                           ::com::sun::star::ucb::XContentIdentifier >& xNewId );
129 
130     const rtl::OUString
131     getBaseURI( const std::auto_ptr< DAVResourceAccess > & rResAccess );
132 
133     const ResourceType &
134     getResourceType( const ::com::sun::star::uno::Reference<
135                          ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
136         throw ( ::com::sun::star::uno::Exception );
137 
138     const ResourceType &
139     getResourceType( const ::com::sun::star::uno::Reference<
140                           ::com::sun::star::ucb::XCommandEnvironment >& xEnv,
141                      const std::auto_ptr< DAVResourceAccess > & rResAccess )
142         throw ( ::com::sun::star::uno::Exception );
143 
144     // Command "open"
145     com::sun::star::uno::Any open(
146                 const com::sun::star::ucb::OpenCommandArgument2 & rArg,
147                 const com::sun::star::uno::Reference<
148                     com::sun::star::ucb::XCommandEnvironment > & xEnv )
149         throw( ::com::sun::star::uno::Exception );
150 
151     // Command "post"
152     void post( const com::sun::star::ucb::PostCommandArgument2 & rArg,
153                const com::sun::star::uno::Reference<
154                     com::sun::star::ucb::XCommandEnvironment > & xEnv )
155         throw( ::com::sun::star::uno::Exception );
156 
157     // Command "insert"
158     void insert( const ::com::sun::star::uno::Reference<
159                      ::com::sun::star::io::XInputStream > & xInputStream,
160                  sal_Bool bReplaceExisting,
161                  const com::sun::star::uno::Reference<
162                      com::sun::star::ucb::XCommandEnvironment >& Environment )
163         throw( ::com::sun::star::uno::Exception );
164 
165     // Command "transfer"
166     void transfer( const ::com::sun::star::ucb::TransferInfo & rArgs,
167                    const com::sun::star::uno::Reference<
168                        com::sun::star::ucb::XCommandEnvironment >& Environment )
169         throw( ::com::sun::star::uno::Exception );
170 
171     // Command "delete"
172     void destroy( sal_Bool bDeletePhysical )
173         throw( ::com::sun::star::uno::Exception );
174 
175     // Command "lock"
176     void lock( const com::sun::star::uno::Reference<
177                   com::sun::star::ucb::XCommandEnvironment >& Environment )
178         throw( ::com::sun::star::uno::Exception );
179 
180     // Command "unlock"
181     void unlock( const com::sun::star::uno::Reference<
182                   com::sun::star::ucb::XCommandEnvironment >& Environment )
183         throw( ::com::sun::star::uno::Exception );
184 
185     ::com::sun::star::uno::Any MapDAVException( const DAVException & e,
186                                                 sal_Bool bWrite );
187     void cancelCommandExecution(
188                     const DAVException & e,
189                     const ::com::sun::star::uno::Reference<
190                         com::sun::star::ucb::XCommandEnvironment > & xEnv,
191                     sal_Bool bWrite = sal_False )
192         throw( ::com::sun::star::uno::Exception );
193 
194     static bool shouldAccessNetworkAfterException( const DAVException & e );
195 
196     bool supportsExclusiveWriteLock(
197         const com::sun::star::uno::Reference<
198             com::sun::star::ucb::XCommandEnvironment >& Environment );
199 
200 public:
201     Content( const ::com::sun::star::uno::Reference<
202                  ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
203              ContentProvider* pProvider,
204              const ::com::sun::star::uno::Reference<
205                  ::com::sun::star::ucb::XContentIdentifier >& Identifier,
206              rtl::Reference< DAVSessionFactory > const & rSessionFactory )
207         throw ( ::com::sun::star::ucb::ContentCreationException );
208     Content( const ::com::sun::star::uno::Reference<
209                  ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
210              ContentProvider* pProvider,
211              const ::com::sun::star::uno::Reference<
212                  ::com::sun::star::ucb::XContentIdentifier >& Identifier,
213              rtl::Reference< DAVSessionFactory > const & rSessionFactory,
214              sal_Bool isCollection )
215         throw ( ::com::sun::star::ucb::ContentCreationException );
216     virtual ~Content();
217 
218     // XInterface
219     XINTERFACE_DECL()
220 
221     // XTypeProvider
222     XTYPEPROVIDER_DECL()
223 
224     // XServiceInfo
225     virtual ::rtl::OUString SAL_CALL
226     getImplementationName()
227         throw( ::com::sun::star::uno::RuntimeException );
228 
229     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
230     getSupportedServiceNames()
231         throw( ::com::sun::star::uno::RuntimeException );
232 
233     // XContent
234     virtual rtl::OUString SAL_CALL
235     getContentType()
236         throw( com::sun::star::uno::RuntimeException );
237 
238     // XCommandProcessor
239     virtual com::sun::star::uno::Any SAL_CALL
240     execute( const com::sun::star::ucb::Command& aCommand,
241              sal_Int32 CommandId,
242              const com::sun::star::uno::Reference<
243                  com::sun::star::ucb::XCommandEnvironment >& Environment )
244         throw( com::sun::star::uno::Exception,
245                com::sun::star::ucb::CommandAbortedException,
246                com::sun::star::uno::RuntimeException );
247     virtual void SAL_CALL
248     abort( sal_Int32 CommandId )
249         throw( com::sun::star::uno::RuntimeException );
250 
251     // XPropertyContainer
252     virtual void SAL_CALL
253     addProperty( const rtl::OUString& Name,
254                  sal_Int16 Attributes,
255                  const com::sun::star::uno::Any& DefaultValue )
256         throw( com::sun::star::beans::PropertyExistException,
257                com::sun::star::beans::IllegalTypeException,
258                com::sun::star::lang::IllegalArgumentException,
259                com::sun::star::uno::RuntimeException );
260 
261     virtual void SAL_CALL
262     removeProperty( const rtl::OUString& Name )
263         throw( com::sun::star::beans::UnknownPropertyException,
264                com::sun::star::beans::NotRemoveableException,
265                com::sun::star::uno::RuntimeException );
266 
267     //////////////////////////////////////////////////////////////////////
268     // Additional interfaces
269     //////////////////////////////////////////////////////////////////////
270 
271     // XContentCreator
272     virtual com::sun::star::uno::Sequence<
273         com::sun::star::ucb::ContentInfo > SAL_CALL
274    queryCreatableContentsInfo()
275         throw( com::sun::star::uno::RuntimeException );
276     virtual com::sun::star::uno::Reference<
277         com::sun::star::ucb::XContent > SAL_CALL
278     createNewContent( const com::sun::star::ucb::ContentInfo& Info )
279         throw( com::sun::star::uno::RuntimeException );
280 
281     //////////////////////////////////////////////////////////////////////
282     // Non-interface methods.
283     //////////////////////////////////////////////////////////////////////
284 
285     DAVResourceAccess & getResourceAccess() { return *m_xResAccess; }
286 
287     // Called from resultset data supplier.
288     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
289     getPropertyValues( const ::com::sun::star::uno::Reference<
290                            ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
291                        const ::com::sun::star::uno::Sequence<
292                            ::com::sun::star::beans::Property >& rProperties,
293                        const ContentProperties& rData,
294                        const rtl::Reference<
295                            ::ucbhelper::ContentProviderImplHelper >& rProvider,
296                        const ::rtl::OUString& rContentId );
297 };
298 
299 }
300 
301 #endif
302