xref: /AOO41X/main/ucb/source/ucp/webdav/webdavcontent.hxx (revision b5da552ccefc4034e06a43bfae43fb8a8b64a7ad)
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 PostCommandArgument2;
52     struct TransferInfo;
53 } } } }
54 
55 namespace webdav_ucp
56 {
57 
58 //=========================================================================
59 
60 // UNO service name for the content.
61 #define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent"
62 
63 //=========================================================================
64 
65 class ContentProvider;
66 class ContentProperties;
67 class CachableContentProperties;
68 
69 class Content : public ::ucbhelper::ContentImplHelper,
70                 public com::sun::star::ucb::XContentCreator
71 {
72     enum ResourceType
73     {
74         UNKNOWN,
75         FTP,
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 public:
197     Content( const ::com::sun::star::uno::Reference<
198                  ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
199              ContentProvider* pProvider,
200              const ::com::sun::star::uno::Reference<
201                  ::com::sun::star::ucb::XContentIdentifier >& Identifier,
202              rtl::Reference< DAVSessionFactory > const & rSessionFactory )
203         throw ( ::com::sun::star::ucb::ContentCreationException );
204     Content( const ::com::sun::star::uno::Reference<
205                  ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
206              ContentProvider* pProvider,
207              const ::com::sun::star::uno::Reference<
208                  ::com::sun::star::ucb::XContentIdentifier >& Identifier,
209              rtl::Reference< DAVSessionFactory > const & rSessionFactory,
210              sal_Bool isCollection )
211         throw ( ::com::sun::star::ucb::ContentCreationException );
212     virtual ~Content();
213 
214     // XInterface
215     XINTERFACE_DECL()
216 
217     // XTypeProvider
218     XTYPEPROVIDER_DECL()
219 
220     // XServiceInfo
221     virtual ::rtl::OUString SAL_CALL
222     getImplementationName()
223         throw( ::com::sun::star::uno::RuntimeException );
224 
225     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
226     getSupportedServiceNames()
227         throw( ::com::sun::star::uno::RuntimeException );
228 
229     // XContent
230     virtual rtl::OUString SAL_CALL
231     getContentType()
232         throw( com::sun::star::uno::RuntimeException );
233 
234     // XCommandProcessor
235     virtual com::sun::star::uno::Any SAL_CALL
236     execute( const com::sun::star::ucb::Command& aCommand,
237              sal_Int32 CommandId,
238              const com::sun::star::uno::Reference<
239                  com::sun::star::ucb::XCommandEnvironment >& Environment )
240         throw( com::sun::star::uno::Exception,
241                com::sun::star::ucb::CommandAbortedException,
242                com::sun::star::uno::RuntimeException );
243     virtual void SAL_CALL
244     abort( sal_Int32 CommandId )
245         throw( com::sun::star::uno::RuntimeException );
246 
247     // XPropertyContainer
248     virtual void SAL_CALL
249     addProperty( const rtl::OUString& Name,
250                  sal_Int16 Attributes,
251                  const com::sun::star::uno::Any& DefaultValue )
252         throw( com::sun::star::beans::PropertyExistException,
253                com::sun::star::beans::IllegalTypeException,
254                com::sun::star::lang::IllegalArgumentException,
255                com::sun::star::uno::RuntimeException );
256 
257     virtual void SAL_CALL
258     removeProperty( const rtl::OUString& Name )
259         throw( com::sun::star::beans::UnknownPropertyException,
260                com::sun::star::beans::NotRemoveableException,
261                com::sun::star::uno::RuntimeException );
262 
263     //////////////////////////////////////////////////////////////////////
264     // Additional interfaces
265     //////////////////////////////////////////////////////////////////////
266 
267     // XContentCreator
268     virtual com::sun::star::uno::Sequence<
269         com::sun::star::ucb::ContentInfo > SAL_CALL
270    queryCreatableContentsInfo()
271         throw( com::sun::star::uno::RuntimeException );
272     virtual com::sun::star::uno::Reference<
273         com::sun::star::ucb::XContent > SAL_CALL
274     createNewContent( const com::sun::star::ucb::ContentInfo& Info )
275         throw( com::sun::star::uno::RuntimeException );
276 
277     //////////////////////////////////////////////////////////////////////
278     // Non-interface methods.
279     //////////////////////////////////////////////////////////////////////
280 
281     DAVResourceAccess & getResourceAccess() { return *m_xResAccess; }
282 
283     // Called from resultset data supplier.
284     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
285     getPropertyValues( const ::com::sun::star::uno::Reference<
286                            ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
287                        const ::com::sun::star::uno::Sequence<
288                            ::com::sun::star::beans::Property >& rProperties,
289                        const ContentProperties& rData,
290                        const rtl::Reference<
291                            ::ucbhelper::ContentProviderImplHelper >& rProvider,
292                        const ::rtl::OUString& rContentId );
293 };
294 
295 }
296 
297 #endif
298