Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / webdav-curl / webdavcontent.hxx
bloba44eb1c99d439c469e8caadf0aa3821cb853d164
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #pragma once
23 #include <memory>
24 #include <list>
25 #include <rtl/ref.hxx>
26 #include <com/sun/star/ucb/ContentCreationException.hpp>
27 #include <com/sun/star/ucb/XContentCreator.hpp>
28 #include <ucbhelper/contenthelper.hxx>
29 #include "DAVResourceAccess.hxx"
30 #include "PropertyMap.hxx"
32 namespace com::sun::star::beans {
33 struct Property;
34 struct PropertyValue;
37 namespace com::sun::star::io {
38 class XInputStream;
41 namespace com::sun::star::sdbc {
42 class XRow;
45 namespace com::sun::star::ucb {
46 struct OpenCommandArgument3;
47 struct PropertyCommandArgument;
48 struct PostCommandArgument2;
49 struct TransferInfo;
52 namespace http_dav_ucp
56 // UNO service name for the content.
57 inline constexpr OUStringLiteral WEBDAV_CONTENT_SERVICE_NAME = u"com.sun.star.ucb.WebDAVContent";
60 class ContentProvider;
61 class ContentProperties;
62 class CachableContentProperties;
64 class Content : public ::ucbhelper::ContentImplHelper,
65 public css::ucb::XContentCreator
67 enum ResourceType
69 UNKNOWN, // the type of the Web resource is unknown
70 NOT_FOUND, // the Web resource does not exists
71 NON_DAV, // the Web resource exists but it's not DAV
72 DAV, // the type of the Web resource is DAV with lock/unlock available
73 DAV_NOLOCK // the type of the Web resource is DAV with no lock/unlock available
76 std::unique_ptr< DAVResourceAccess > m_xResAccess;
77 std::unique_ptr< CachableContentProperties > m_xCachedProps; // locally cached props
78 OUString m_aEscapedTitle;
79 // resource type for general DAV methods
80 ResourceType m_eResourceType;
81 // resource type for general LOCK method only
82 ResourceType m_eResourceTypeForLocks;
83 ContentProvider* m_pProvider; // No need for a ref, base class holds object
84 bool m_bTransient;
85 bool const m_bCollection;
86 bool m_bDidGetOrHead;
87 std::vector< OUString > m_aFailedPropNames;
88 // Options Cache lifetime
89 // for web site implementing OPTIONS, but not dav
90 sal_uInt32 m_nOptsCacheLifeImplWeb;
91 // for WebDAV site where OPTIONS is mandatory
92 sal_uInt32 m_nOptsCacheLifeDAV;
93 // same as above, but when the resource is locked by us
94 sal_uInt32 m_nOptsCacheLifeDAVLocked;
95 // For web site not implementing OPTIONS
96 // during this time we assume the site doesn't turn to WebDAV
97 // but remains a simple Web
98 sal_uInt32 m_nOptsCacheLifeNotImpl;
99 // When resource is not found
100 // may be the resource is unavailable only briefly?
101 // so better have this small
102 sal_uInt32 m_nOptsCacheLifeNotFound;
104 void initOptsCacheLifeTime();
106 private:
107 virtual css::uno::Sequence< css::beans::Property >
108 getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
109 virtual css::uno::Sequence< css::ucb::CommandInfo >
110 getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
111 virtual OUString getParentURL() override;
113 /// @throws css::uno::Exception
114 bool isFolder( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
116 /// @throws css::uno::Exception
117 css::uno::Reference< css::sdbc::XRow >
118 getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties,
119 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
121 /// @throws css::uno::Exception
122 css::uno::Sequence< css::uno::Any >
123 setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& rValues,
124 const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
126 typedef rtl::Reference< Content > ContentRef;
127 typedef std::vector< ContentRef > ContentRefList;
128 void queryChildren( ContentRefList& rChildren);
130 bool
131 exchangeIdentity( const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
133 OUString
134 getBaseURI( const std::unique_ptr< DAVResourceAccess > & rResAccess );
136 /// @throws css::uno::Exception
137 ResourceType
138 getResourceType( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
140 /// @throws css::uno::Exception
141 ResourceType
142 getResourceType( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
143 const std::unique_ptr< DAVResourceAccess > & rResAccess,
144 bool * networkAccessAllowed = nullptr );
146 // Command "open"
147 /// @throws css::uno::Exception
148 css::uno::Any open(
149 const css::ucb::OpenCommandArgument3 & rArg,
150 const css::uno::Reference<
151 css::ucb::XCommandEnvironment > & xEnv );
153 // Command "post"
154 /// @throws css::uno::Exception
155 void post( const css::ucb::PostCommandArgument2 & rArg,
156 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
158 // Command "insert"
159 /// @throws css::uno::Exception
160 void insert( const css::uno::Reference< css::io::XInputStream > & xInputStream,
161 bool bReplaceExisting,
162 const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
164 // Command "transfer"
165 /// @throws css::uno::Exception
166 void transfer( const css::ucb::TransferInfo & rArgs,
167 const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
169 // Command "delete"
170 /// @throws css::uno::Exception
171 void destroy( bool bDeletePhysical );
173 // Command "lock"
174 /// @throws css::uno::Exception
175 void lock( const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
177 // Command "unlock"
178 /// @throws css::uno::Exception
179 void unlock( const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
181 css::uno::Any MapDAVException( const DAVException & e,
182 bool bWrite );
183 /// @throws css::uno::Exception
184 void cancelCommandExecution(
185 const DAVException & e,
186 const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv,
187 bool bWrite = false );
189 static bool shouldAccessNetworkAfterException( const DAVException & e );
191 ResourceType resourceTypeForLocks(
192 const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnvironment,
193 const std::unique_ptr< DAVResourceAccess > & rResAccess );
195 ResourceType resourceTypeForLocks(
196 const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnvironment );
198 // XPropertyContainer replacement
199 /// @throws css::beans::PropertyExistException
200 /// @throws css::beans::IllegalTypeException
201 /// @throws css::lang::IllegalArgumentException
202 /// @throws css::uno::RuntimeException
203 void addProperty( const css::ucb::PropertyCommandArgument &aCmdArg,
204 const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
206 /// @throws css::beans::PropertyExistException
207 /// @throws css::beans::NotRemoveableException
208 /// @throws css::uno::RuntimeException
209 void removeProperty( const OUString& Name,
210 const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
211 public:
212 /// @throws css::ucb::ContentCreationException
213 Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
214 ContentProvider* pProvider,
215 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
216 rtl::Reference< DAVSessionFactory > const & rSessionFactory );
217 /// @throws css::ucb::ContentCreationException
218 Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
219 ContentProvider* pProvider,
220 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
221 rtl::Reference< DAVSessionFactory > const & rSessionFactory,
222 bool isCollection );
223 virtual ~Content() override;
225 // XInterface
226 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
227 virtual void SAL_CALL acquire()
228 noexcept override;
229 virtual void SAL_CALL release()
230 noexcept override;
232 // XTypeProvider
233 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
234 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
236 // XServiceInfo
237 virtual OUString SAL_CALL
238 getImplementationName() override;
240 virtual css::uno::Sequence< OUString > SAL_CALL
241 getSupportedServiceNames() override;
243 // XContent
244 virtual OUString SAL_CALL
245 getContentType() override;
247 // XCommandProcessor
248 virtual css::uno::Any SAL_CALL
249 execute( const css::ucb::Command& aCommand,
250 sal_Int32 CommandId,
251 const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override;
252 virtual void SAL_CALL
253 abort( sal_Int32 CommandId ) override;
255 // XPropertyContainer
256 virtual void SAL_CALL
257 addProperty( const OUString& Name,
258 sal_Int16 Attributes,
259 const css::uno::Any& DefaultValue ) override;
261 virtual void SAL_CALL
262 removeProperty( const OUString& Name ) override;
265 // Additional interfaces
268 // XContentCreator
269 virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL
270 queryCreatableContentsInfo() override;
271 virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
272 createNewContent( const css::ucb::ContentInfo& Info ) override;
275 // Non-interface methods.
278 DAVResourceAccess & getResourceAccess() { return *m_xResAccess; }
280 // Called from resultset data supplier.
281 static css::uno::Reference< css::sdbc::XRow >
282 getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rContext,
283 const css::uno::Sequence< css::beans::Property >& rProperties,
284 const ContentProperties& rData,
285 const rtl::Reference< ::ucbhelper::ContentProviderImplHelper >& rProvider,
286 const OUString& rContentId );
288 /// Use OPTIONS method to retrieve the type of the Web resource
289 /// @throws css::uno::Exception
290 void getResourceOptions( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
291 DAVOptions& rDAVOptions,
292 const std::unique_ptr< DAVResourceAccess > & rResAccess,
293 bool * networkAccessAllowed = nullptr);
295 static bool isResourceAvailable( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
296 const std::unique_ptr< DAVResourceAccess > & rResAccess,
297 DAVOptions& rDAVOptions );
299 static void removeCachedPropertyNames( const OUString & rURL );
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */