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