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 _WEBDAV_UCP_CONTENT_HXX
25 #define _WEBDAV_UCP_CONTENT_HXX
26 
27 #include <memory>
28 #include <list>
29 #include <rtl/ref.hxx>
30 #include <com/sun/star/ucb/ContentCreationException.hpp>
31 #include <com/sun/star/ucb/XContentCreator.hpp>
32 #include <ucbhelper/contenthelper.hxx>
33 #include "DAVResourceAccess.hxx"
34 #include "PropertyMap.hxx"
35 
36 namespace com { namespace sun { namespace star { namespace beans {
37     struct Property;
38     struct PropertyValue;
39 } } } }
40 
41 namespace com { namespace sun { namespace star { namespace io {
42     class XInputStream;
43 } } } }
44 
45 namespace com { namespace sun { namespace star { namespace sdbc {
46     class XRow;
47 } } } }
48 
49 namespace com { namespace sun { namespace star { namespace ucb {
50     struct OpenCommandArgument2;
51     struct PropertyCommandArgument;
52     struct PostCommandArgument2;
53     struct TransferInfo;
54 } } } }
55 
56 namespace http_dav_ucp
57 {
58 
59 //=========================================================================
60 
61 // UNO service name for the content.
62 #define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent"
63 
64 //=========================================================================
65 
66 class ContentProvider;
67 class ContentProperties;
68 class CachableContentProperties;
69 
70 class Content : public ::ucbhelper::ContentImplHelper,
71                 public com::sun::star::ucb::XContentCreator
72 {
73     enum ResourceType
74     {
75         UNKNOWN,
76         NON_DAV,
77         DAV
78     };
79 
80     std::auto_ptr< DAVResourceAccess > m_xResAccess;
81     std::auto_ptr< CachableContentProperties >
82                       m_xCachedProps; // locally cached props
83     rtl::OUString     m_aEscapedTitle;
84     ResourceType      m_eResourceType;
85     ContentProvider*  m_pProvider; // No need for a ref, base class holds object
86     // True if the DEV resource is a 'unmapped URL' as it is named in RFC4918
87     bool              m_bTransient;
88     bool              m_bCollection;
89     bool              m_bDidGetOrHead;
90     std::vector< rtl::OUString > m_aFailedPropNames;
91 
92 private:
93     virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
94     getProperties( const com::sun::star::uno::Reference<
95                        com::sun::star::ucb::XCommandEnvironment > & xEnv );
96     virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
97     getCommands( const com::sun::star::uno::Reference<
98                      com::sun::star::ucb::XCommandEnvironment > & xEnv );
99     virtual ::rtl::OUString getParentURL();
100 
101     sal_Bool isFolder( const ::com::sun::star::uno::Reference<
102                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
103         throw ( ::com::sun::star::uno::Exception );
104 
105     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
106     getPropertyValues( const ::com::sun::star::uno::Sequence<
107                            ::com::sun::star::beans::Property >& rProperties,
108                        const ::com::sun::star::uno::Reference<
109                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
110         throw ( ::com::sun::star::uno::Exception );
111 
112     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
113     setPropertyValues( const ::com::sun::star::uno::Sequence<
114                            ::com::sun::star::beans::PropertyValue >& rValues,
115                        const ::com::sun::star::uno::Reference<
116                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
117         throw ( ::com::sun::star::uno::Exception );
118 
119     typedef rtl::Reference< Content > ContentRef;
120     typedef std::list< ContentRef > ContentRefList;
121     void queryChildren( ContentRefList& rChildren);
122 
123     sal_Bool
124     exchangeIdentity( const ::com::sun::star::uno::Reference<
125                           ::com::sun::star::ucb::XContentIdentifier >& xNewId );
126 
127     const rtl::OUString
128     getBaseURI( const std::auto_ptr< DAVResourceAccess > & rResAccess );
129 
130     const ResourceType &
131     getResourceType( const ::com::sun::star::uno::Reference<
132                          ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
133         throw ( ::com::sun::star::uno::Exception );
134 
135     const ResourceType &
136     getResourceType( const ::com::sun::star::uno::Reference<
137                           ::com::sun::star::ucb::XCommandEnvironment >& xEnv,
138                      const std::auto_ptr< DAVResourceAccess > & rResAccess )
139         throw ( ::com::sun::star::uno::Exception );
140 
141     /// Command "open"
142     com::sun::star::uno::Any open(
143                 const com::sun::star::ucb::OpenCommandArgument2 & rArg,
144                 const com::sun::star::uno::Reference<
145                     com::sun::star::ucb::XCommandEnvironment > & xEnv )
146         throw( ::com::sun::star::uno::Exception );
147 
148     /// Command "post"
149     void post( const com::sun::star::ucb::PostCommandArgument2 & rArg,
150                const com::sun::star::uno::Reference<
151                     com::sun::star::ucb::XCommandEnvironment > & xEnv )
152         throw( ::com::sun::star::uno::Exception );
153 
154     /// Command "insert"
155     void insert( const ::com::sun::star::uno::Reference<
156                      ::com::sun::star::io::XInputStream > & xInputStream,
157                  sal_Bool bReplaceExisting,
158                  const com::sun::star::uno::Reference<
159                      com::sun::star::ucb::XCommandEnvironment >& Environment )
160         throw( ::com::sun::star::uno::Exception );
161 
162     /// Command "transfer"
163     void transfer( const ::com::sun::star::ucb::TransferInfo & rArgs,
164                    const com::sun::star::uno::Reference<
165                        com::sun::star::ucb::XCommandEnvironment >& Environment )
166         throw( ::com::sun::star::uno::Exception );
167 
168     /// Command "delete"
169     void destroy( sal_Bool bDeletePhysical )
170         throw( ::com::sun::star::uno::Exception );
171 
172     /// Command "lock"
173     void lock( const com::sun::star::uno::Reference<
174                   com::sun::star::ucb::XCommandEnvironment >& Environment )
175         throw( ::com::sun::star::uno::Exception );
176 
177     /// Command "unlock"
178     void unlock( const com::sun::star::uno::Reference<
179                   com::sun::star::ucb::XCommandEnvironment >& Environment )
180         throw( ::com::sun::star::uno::Exception );
181 
182     ::com::sun::star::uno::Any MapDAVException( const DAVException & e,
183                                                 sal_Bool bWrite );
184     void cancelCommandExecution(
185                     const DAVException & e,
186                     const ::com::sun::star::uno::Reference<
187                         com::sun::star::ucb::XCommandEnvironment > & xEnv,
188                     sal_Bool bWrite = sal_False )
189         throw( ::com::sun::star::uno::Exception );
190 
191     static bool shouldAccessNetworkAfterException( const DAVException & e );
192 
193     bool supportsExclusiveWriteLock(
194         const com::sun::star::uno::Reference<
195             com::sun::star::ucb::XCommandEnvironment >& Environment );
196 
197     /// XPropertyContainer replacement
198     void addProperty( const com::sun::star::ucb::PropertyCommandArgument &aCmdArg,
199                       const com::sun::star::uno::Reference<
200                       com::sun::star::ucb::XCommandEnvironment >& Environment )
201     throw( com::sun::star::beans::PropertyExistException,
202            com::sun::star::beans::IllegalTypeException,
203            com::sun::star::lang::IllegalArgumentException,
204            com::sun::star::uno::RuntimeException );
205 
206     void removeProperty( const rtl::OUString& Name,
207                          const com::sun::star::uno::Reference<
208                          com::sun::star::ucb::XCommandEnvironment >& Environment )
209     throw( com::sun::star::beans::UnknownPropertyException,
210            com::sun::star::beans::NotRemoveableException,
211            com::sun::star::uno::RuntimeException );
212 public:
213     Content( const ::com::sun::star::uno::Reference<
214                  ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
215              ContentProvider* pProvider,
216              const ::com::sun::star::uno::Reference<
217                  ::com::sun::star::ucb::XContentIdentifier >& Identifier,
218              rtl::Reference< DAVSessionFactory > const & rSessionFactory )
219         throw ( ::com::sun::star::ucb::ContentCreationException );
220     Content( const ::com::sun::star::uno::Reference<
221                  ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
222              ContentProvider* pProvider,
223              const ::com::sun::star::uno::Reference<
224                  ::com::sun::star::ucb::XContentIdentifier >& Identifier,
225              rtl::Reference< DAVSessionFactory > const & rSessionFactory,
226              sal_Bool isCollection )
227         throw ( ::com::sun::star::ucb::ContentCreationException );
228     virtual ~Content();
229 
230     /// XInterface
231     XINTERFACE_DECL()
232 
233     /// XTypeProvider
234     XTYPEPROVIDER_DECL()
235 
236     /// XServiceInfo
237     virtual ::rtl::OUString SAL_CALL
238     getImplementationName()
239         throw( ::com::sun::star::uno::RuntimeException );
240 
241     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
242     getSupportedServiceNames()
243         throw( ::com::sun::star::uno::RuntimeException );
244 
245     /// XContent
246     virtual rtl::OUString SAL_CALL
247     getContentType()
248         throw( com::sun::star::uno::RuntimeException );
249 
250     /// XCommandProcessor
251     virtual com::sun::star::uno::Any SAL_CALL
252     execute( const com::sun::star::ucb::Command& aCommand,
253              sal_Int32 CommandId,
254              const com::sun::star::uno::Reference<
255                  com::sun::star::ucb::XCommandEnvironment >& Environment )
256         throw( com::sun::star::uno::Exception,
257                com::sun::star::ucb::CommandAbortedException,
258                com::sun::star::uno::RuntimeException );
259     virtual void SAL_CALL
260     abort( sal_Int32 CommandId )
261         throw( com::sun::star::uno::RuntimeException );
262 
263     /// XPropertyContainer
264     virtual void SAL_CALL
265     addProperty( const rtl::OUString& Name,
266                  sal_Int16 Attributes,
267                  const com::sun::star::uno::Any& DefaultValue )
268         throw( com::sun::star::beans::PropertyExistException,
269                com::sun::star::beans::IllegalTypeException,
270                com::sun::star::lang::IllegalArgumentException,
271                com::sun::star::uno::RuntimeException );
272 
273     virtual void SAL_CALL
274     removeProperty( const rtl::OUString& Name )
275         throw( com::sun::star::beans::UnknownPropertyException,
276                com::sun::star::beans::NotRemoveableException,
277                com::sun::star::uno::RuntimeException );
278 
279     //////////////////////////////////////////////////////////////////////
280     // Additional interfaces
281     //////////////////////////////////////////////////////////////////////
282 
283     // XContentCreator
284     virtual com::sun::star::uno::Sequence<
285         com::sun::star::ucb::ContentInfo > SAL_CALL
286    queryCreatableContentsInfo()
287         throw( com::sun::star::uno::RuntimeException );
288     virtual com::sun::star::uno::Reference<
289         com::sun::star::ucb::XContent > SAL_CALL
290     createNewContent( const com::sun::star::ucb::ContentInfo& Info )
291         throw( com::sun::star::uno::RuntimeException );
292 
293     //////////////////////////////////////////////////////////////////////
294     // Non-interface methods.
295     //////////////////////////////////////////////////////////////////////
296 
getResourceAccess()297     DAVResourceAccess & getResourceAccess() { return *m_xResAccess; }
298 
299     /** Called from resultset data supplier. */
300     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
301     getPropertyValues( const ::com::sun::star::uno::Reference<
302                            ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
303                        const ::com::sun::star::uno::Sequence<
304                            ::com::sun::star::beans::Property >& rProperties,
305                        const ContentProperties& rData,
306                        const rtl::Reference<
307                            ::ucbhelper::ContentProviderImplHelper >& rProvider,
308                        const ::rtl::OUString& rContentId );
309 
310     /** returns the owner of current resource lock */
311     rtl::OUString getLockOwner( const uno::Reference< ucb::XCommandEnvironment >& Environment );
312 };
313 
314 }
315 
316 #endif
317