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     bool              m_bTransient;
87     bool              m_bCollection;
88     bool              m_bDidGetOrHead;
89     std::vector< rtl::OUString > m_aFailedPropNames;
90 
91 private:
92     virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
93     getProperties( const com::sun::star::uno::Reference<
94                        com::sun::star::ucb::XCommandEnvironment > & xEnv );
95     virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
96     getCommands( const com::sun::star::uno::Reference<
97                      com::sun::star::ucb::XCommandEnvironment > & xEnv );
98     virtual ::rtl::OUString getParentURL();
99 
100     sal_Bool isFolder( const ::com::sun::star::uno::Reference<
101                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
102         throw ( ::com::sun::star::uno::Exception );
103 
104     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
105     getPropertyValues( const ::com::sun::star::uno::Sequence<
106                            ::com::sun::star::beans::Property >& rProperties,
107                        const ::com::sun::star::uno::Reference<
108                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
109         throw ( ::com::sun::star::uno::Exception );
110 
111     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
112     setPropertyValues( const ::com::sun::star::uno::Sequence<
113                            ::com::sun::star::beans::PropertyValue >& rValues,
114                        const ::com::sun::star::uno::Reference<
115                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
116         throw ( ::com::sun::star::uno::Exception );
117 
118     typedef rtl::Reference< Content > ContentRef;
119     typedef std::list< ContentRef > ContentRefList;
120     void queryChildren( ContentRefList& rChildren);
121 
122     sal_Bool
123     exchangeIdentity( const ::com::sun::star::uno::Reference<
124                           ::com::sun::star::ucb::XContentIdentifier >& xNewId );
125 
126     const rtl::OUString
127     getBaseURI( const std::auto_ptr< DAVResourceAccess > & rResAccess );
128 
129     const ResourceType &
130     getResourceType( const ::com::sun::star::uno::Reference<
131                          ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
132         throw ( ::com::sun::star::uno::Exception );
133 
134     const ResourceType &
135     getResourceType( const ::com::sun::star::uno::Reference<
136                           ::com::sun::star::ucb::XCommandEnvironment >& xEnv,
137                      const std::auto_ptr< DAVResourceAccess > & rResAccess )
138         throw ( ::com::sun::star::uno::Exception );
139 
140     // Command "open"
141     com::sun::star::uno::Any open(
142                 const com::sun::star::ucb::OpenCommandArgument2 & rArg,
143                 const com::sun::star::uno::Reference<
144                     com::sun::star::ucb::XCommandEnvironment > & xEnv )
145         throw( ::com::sun::star::uno::Exception );
146 
147     // Command "post"
148     void post( const com::sun::star::ucb::PostCommandArgument2 & rArg,
149                const com::sun::star::uno::Reference<
150                     com::sun::star::ucb::XCommandEnvironment > & xEnv )
151         throw( ::com::sun::star::uno::Exception );
152 
153     // Command "insert"
154     void insert( const ::com::sun::star::uno::Reference<
155                      ::com::sun::star::io::XInputStream > & xInputStream,
156                  sal_Bool bReplaceExisting,
157                  const com::sun::star::uno::Reference<
158                      com::sun::star::ucb::XCommandEnvironment >& Environment )
159         throw( ::com::sun::star::uno::Exception );
160 
161     // Command "transfer"
162     void transfer( const ::com::sun::star::ucb::TransferInfo & rArgs,
163                    const com::sun::star::uno::Reference<
164                        com::sun::star::ucb::XCommandEnvironment >& Environment )
165         throw( ::com::sun::star::uno::Exception );
166 
167     // Command "delete"
168     void destroy( sal_Bool bDeletePhysical )
169         throw( ::com::sun::star::uno::Exception );
170 
171     // Command "lock"
172     void lock( const com::sun::star::uno::Reference<
173                   com::sun::star::ucb::XCommandEnvironment >& Environment )
174         throw( ::com::sun::star::uno::Exception );
175 
176     // Command "unlock"
177     void unlock( const com::sun::star::uno::Reference<
178                   com::sun::star::ucb::XCommandEnvironment >& Environment )
179         throw( ::com::sun::star::uno::Exception );
180 
181     ::com::sun::star::uno::Any MapDAVException( const DAVException & e,
182                                                 sal_Bool bWrite );
183     void cancelCommandExecution(
184                     const DAVException & e,
185                     const ::com::sun::star::uno::Reference<
186                         com::sun::star::ucb::XCommandEnvironment > & xEnv,
187                     sal_Bool bWrite = sal_False )
188         throw( ::com::sun::star::uno::Exception );
189 
190     static bool shouldAccessNetworkAfterException( const DAVException & e );
191 
192     bool supportsExclusiveWriteLock(
193         const com::sun::star::uno::Reference<
194             com::sun::star::ucb::XCommandEnvironment >& Environment );
195 
196     // XPropertyContainer replacement
197     void addProperty( const com::sun::star::ucb::PropertyCommandArgument &aCmdArg,
198                       const com::sun::star::uno::Reference<
199                       com::sun::star::ucb::XCommandEnvironment >& Environment )
200     throw( com::sun::star::beans::PropertyExistException,
201            com::sun::star::beans::IllegalTypeException,
202            com::sun::star::lang::IllegalArgumentException,
203            com::sun::star::uno::RuntimeException );
204 
205     void removeProperty( const rtl::OUString& Name,
206                          const com::sun::star::uno::Reference<
207                          com::sun::star::ucb::XCommandEnvironment >& Environment )
208     throw( com::sun::star::beans::UnknownPropertyException,
209            com::sun::star::beans::NotRemoveableException,
210            com::sun::star::uno::RuntimeException );
211 public:
212     Content( const ::com::sun::star::uno::Reference<
213                  ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
214              ContentProvider* pProvider,
215              const ::com::sun::star::uno::Reference<
216                  ::com::sun::star::ucb::XContentIdentifier >& Identifier,
217              rtl::Reference< DAVSessionFactory > const & rSessionFactory )
218         throw ( ::com::sun::star::ucb::ContentCreationException );
219     Content( const ::com::sun::star::uno::Reference<
220                  ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
221              ContentProvider* pProvider,
222              const ::com::sun::star::uno::Reference<
223                  ::com::sun::star::ucb::XContentIdentifier >& Identifier,
224              rtl::Reference< DAVSessionFactory > const & rSessionFactory,
225              sal_Bool isCollection )
226         throw ( ::com::sun::star::ucb::ContentCreationException );
227     virtual ~Content();
228 
229     // XInterface
230     XINTERFACE_DECL()
231 
232     // XTypeProvider
233     XTYPEPROVIDER_DECL()
234 
235     // XServiceInfo
236     virtual ::rtl::OUString SAL_CALL
237     getImplementationName()
238         throw( ::com::sun::star::uno::RuntimeException );
239 
240     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
241     getSupportedServiceNames()
242         throw( ::com::sun::star::uno::RuntimeException );
243 
244     // XContent
245     virtual rtl::OUString SAL_CALL
246     getContentType()
247         throw( com::sun::star::uno::RuntimeException );
248 
249     // XCommandProcessor
250     virtual com::sun::star::uno::Any SAL_CALL
251     execute( const com::sun::star::ucb::Command& aCommand,
252              sal_Int32 CommandId,
253              const com::sun::star::uno::Reference<
254                  com::sun::star::ucb::XCommandEnvironment >& Environment )
255         throw( com::sun::star::uno::Exception,
256                com::sun::star::ucb::CommandAbortedException,
257                com::sun::star::uno::RuntimeException );
258     virtual void SAL_CALL
259     abort( sal_Int32 CommandId )
260         throw( com::sun::star::uno::RuntimeException );
261 
262     // XPropertyContainer
263     virtual void SAL_CALL
264     addProperty( const rtl::OUString& Name,
265                  sal_Int16 Attributes,
266                  const com::sun::star::uno::Any& DefaultValue )
267         throw( com::sun::star::beans::PropertyExistException,
268                com::sun::star::beans::IllegalTypeException,
269                com::sun::star::lang::IllegalArgumentException,
270                com::sun::star::uno::RuntimeException );
271 
272     virtual void SAL_CALL
273     removeProperty( const rtl::OUString& Name )
274         throw( com::sun::star::beans::UnknownPropertyException,
275                com::sun::star::beans::NotRemoveableException,
276                com::sun::star::uno::RuntimeException );
277 
278     //////////////////////////////////////////////////////////////////////
279     // Additional interfaces
280     //////////////////////////////////////////////////////////////////////
281 
282     // XContentCreator
283     virtual com::sun::star::uno::Sequence<
284         com::sun::star::ucb::ContentInfo > SAL_CALL
285    queryCreatableContentsInfo()
286         throw( com::sun::star::uno::RuntimeException );
287     virtual com::sun::star::uno::Reference<
288         com::sun::star::ucb::XContent > SAL_CALL
289     createNewContent( const com::sun::star::ucb::ContentInfo& Info )
290         throw( com::sun::star::uno::RuntimeException );
291 
292     //////////////////////////////////////////////////////////////////////
293     // Non-interface methods.
294     //////////////////////////////////////////////////////////////////////
295 
296     DAVResourceAccess & getResourceAccess() { return *m_xResAccess; }
297 
298     // Called from resultset data supplier.
299     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
300     getPropertyValues( const ::com::sun::star::uno::Reference<
301                            ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
302                        const ::com::sun::star::uno::Sequence<
303                            ::com::sun::star::beans::Property >& rProperties,
304                        const ContentProperties& rData,
305                        const rtl::Reference<
306                            ::ucbhelper::ContentProviderImplHelper >& rProvider,
307                        const ::rtl::OUString& rContentId );
308 };
309 
310 }
311 
312 #endif
313