LibreOffice Module ucb (master)  1
neon/webdavcontent.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #pragma once
30 
31 #include <config_lgpl.h>
32 #include <memory>
33 #include <list>
34 #include <rtl/ref.hxx>
35 #include <com/sun/star/ucb/ContentCreationException.hpp>
36 #include <com/sun/star/ucb/XContentCreator.hpp>
38 #include "DAVResourceAccess.hxx"
39 #include "PropertyMap.hxx"
40 
41 namespace com::sun::star::beans {
42  struct Property;
43  struct PropertyValue;
44 }
45 
46 namespace com::sun::star::io {
47  class XInputStream;
48 }
49 
50 namespace com::sun::star::sdbc {
51  class XRow;
52 }
53 
54 namespace com::sun::star::ucb {
55  struct OpenCommandArgument3;
56  struct PostCommandArgument2;
57  struct PropertyCommandArgument;
58  struct TransferInfo;
59 }
60 
61 namespace webdav_ucp
62 {
63 
64 
65 // UNO service name for the content.
66 #define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent"
67 
68 
69 class ContentProvider;
70 class ContentProperties;
71 class CachableContentProperties;
72 
74  public css::ucb::XContentCreator
75 {
77  {
78  UNKNOWN, // the type of the Web resource is unknown
79  NOT_FOUND, // the Web resource does not exists
80  FTP, // the Web resource exists but it's ftp
81  NON_DAV, // the Web resource exists but it's not DAV
82  DAV, // the type of the Web resource is DAV with lock/unlock available
83  DAV_NOLOCK // the type of the Web resource is DAV with no lock/unlock available
84  };
85 
86  std::unique_ptr< DAVResourceAccess > m_xResAccess;
87  std::unique_ptr< CachableContentProperties >
88  m_xCachedProps; // locally cached props
89  OUString m_aEscapedTitle;
90  // resource type for general DAV methods
92  // resource type for general LOCK method only
94  ContentProvider* m_pProvider; // No need for a ref, base class holds object
98  std::vector< OUString > m_aFailedPropNames;
99  // Options Cache lifetime
100  // for web site implementing OPTIONS, but not dav
102  // for WebDAV site where OPTIONS is mandatory
104  // same as above, but when the resource is locked by us
106 // For web site not implementing OPTIONS
107  // during this time we assume the site doesn't turn to WebDAV
108  // but remains a simple Web
110  // When resource is not found
111  // may be the resource is unavailable only briefly?
112  // so better have this small
114 
115  void initOptsCacheLifeTime();
116 
117 private:
118  virtual css::uno::Sequence< css::beans::Property >
119  getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
120  virtual css::uno::Sequence< css::ucb::CommandInfo >
121  getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
122  virtual OUString getParentURL() override;
123 
125  bool isFolder( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
126 
128  css::uno::Reference< css::sdbc::XRow >
129  getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties,
130  const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
131 
133  css::uno::Sequence< css::uno::Any >
134  setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& rValues,
135  const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
136 
138  typedef std::vector< ContentRef > ContentRefList;
139  void queryChildren( ContentRefList& rChildren);
140 
141  bool
142  exchangeIdentity( const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
143 
144  OUString
145  getBaseURI( const std::unique_ptr< DAVResourceAccess > & rResAccess );
146 
149  getResourceType( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
150 
153  getResourceType( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
154  const std::unique_ptr< DAVResourceAccess > & rResAccess,
155  bool * networkAccessAllowed = nullptr);
156 
157  // Command "open"
159  css::uno::Any open(
160  const css::ucb::OpenCommandArgument3 & rArg,
161  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
162 
163  // Command "post"
165  void post( const css::ucb::PostCommandArgument2 & rArg,
166  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
167 
168  // Command "insert"
170  void insert( const css::uno::Reference< css::io::XInputStream > & xInputStream,
171  bool bReplaceExisting,
172  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
173 
174  // Command "transfer"
176  void transfer( const css::ucb::TransferInfo & rArgs,
177  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
178 
179  // Command "delete"
181  void destroy( bool bDeletePhysical );
182 
183  // Command "lock"
185  void lock( const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
186 
187  // Command "unlock"
189  void unlock( const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
190 
191  css::uno::Any MapDAVException( const DAVException & e,
192  bool bWrite );
195  const DAVException & e,
196  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv,
197  bool bWrite = false );
198 
199  static bool shouldAccessNetworkAfterException( const DAVException & e );
200 
202  const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnvironment,
203  const std::unique_ptr< DAVResourceAccess > & rResAccess );
204 
206  const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnvironment );
207 
212  void addProperty( const css::ucb::PropertyCommandArgument &aCmdArg,
213  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
214 
218  void removeProperty( const OUString& Name,
219  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
220 
221 public:
224  Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
225  ContentProvider* pProvider,
226  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
227  rtl::Reference< DAVSessionFactory > const & rSessionFactory );
230  Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
231  ContentProvider* pProvider,
232  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
233  rtl::Reference< DAVSessionFactory > const & rSessionFactory,
234  bool isCollection );
235  virtual ~Content() override;
236 
237  // XInterface
238  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
239  virtual void SAL_CALL acquire()
240  noexcept override;
241  virtual void SAL_CALL release()
242  noexcept override;
243 
244  // XTypeProvider
245  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
246  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
247 
248  // XServiceInfo
249  virtual OUString SAL_CALL
250  getImplementationName() override;
251 
252  virtual css::uno::Sequence< OUString > SAL_CALL
253  getSupportedServiceNames() override;
254 
255  // XContent
256  virtual OUString SAL_CALL
257  getContentType() override;
258 
259  // XCommandProcessor
260  virtual css::uno::Any SAL_CALL
261  execute( const css::ucb::Command& aCommand,
262  sal_Int32 CommandId,
263  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override;
264  virtual void SAL_CALL
265  abort( sal_Int32 CommandId ) override;
266 
267  // XPropertyContainer
268  virtual void SAL_CALL
269  addProperty( const OUString& Name,
270  sal_Int16 Attributes,
271  const css::uno::Any& DefaultValue ) override;
272 
273  virtual void SAL_CALL
274  removeProperty( const OUString& Name ) override;
275 
276 
277  // Additional interfaces
278 
279 
280  // XContentCreator
281  virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL
282  queryCreatableContentsInfo() override;
283  virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
284  createNewContent( const css::ucb::ContentInfo& Info ) override;
285 
286 
287  // Non-interface methods.
288 
289 
291 
292  // Called from resultset data supplier.
293  static css::uno::Reference< css::sdbc::XRow >
294  getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
295  const css::uno::Sequence< css::beans::Property >& rProperties,
296  const ContentProperties& rData,
298  const OUString& rContentId );
299 
300  // Use OPTIONS method to retrieve the type of the Web resource
302  void getResourceOptions( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
303  DAVOptions& rDAVOptions,
304  const std::unique_ptr< DAVResourceAccess > & rResAccess,
305  bool * networkAccessAllowed = nullptr);
306 
307  static bool isResourceAvailable( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
308  const std::unique_ptr< DAVResourceAccess > & rResAccess,
309  DAVOptions& rDAVOptions );
310 
311  static void removeCachedPropertyNames( const OUString & rURL );
312 
313 };
314 
315 }
316 
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
void transfer(const css::ucb::TransferInfo &rArgs, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment)
virtual void SAL_CALL acquire() noexcept override
void getResourceOptions(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, DAVOptions &rDAVOptions, const std::unique_ptr< DAVResourceAccess > &rResAccess, bool *networkAccessAllowed=nullptr)
DAVResourceAccess & getResourceAccess()
signed char sal_Int8
ResourceType m_eResourceTypeForLocks
bool exchangeIdentity(const css::uno::Reference< css::ucb::XContentIdentifier > &xNewId)
static void removeCachedPropertyNames(const OUString &rURL)
void insert(const css::uno::Reference< css::io::XInputStream > &xInputStream, bool bReplaceExisting, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment)
sal_uInt32 m_nOptsCacheLifeDAVLocked
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString getParentURL() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
std::vector< ContentRef > ContentRefList
std::vector< OUString > m_aFailedPropNames
void post(const css::ucb::PostCommandArgument2 &rArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual void SAL_CALL release() noexcept override
void removeProperty(const OUString &Name, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment)
css::uno::Any open(const css::ucb::OpenCommandArgument3 &rArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
ContentProvider * m_pProvider
css::uno::Any MapDAVException(const DAVException &e, bool bWrite)
void lock(const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment)
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &rProperties, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
static bool isResourceAvailable(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, const std::unique_ptr< DAVResourceAccess > &rResAccess, DAVOptions &rDAVOptions)
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createNewContent(const css::ucb::ContentInfo &Info) override
Content(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier, rtl::Reference< DAVSessionFactory > const &rSessionFactory)
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL queryCreatableContentsInfo() override
void cancelCommandExecution(const DAVException &e, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bWrite=false)
ResourceType resourceTypeForLocks(const css::uno::Reference< css::ucb::XCommandEnvironment > &rEnvironment, const std::unique_ptr< DAVResourceAccess > &rResAccess)
static bool shouldAccessNetworkAfterException(const DAVException &e)
std::unique_ptr< DAVResourceAccess > m_xResAccess
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual void SAL_CALL abort(sal_Int32 CommandId) override
virtual OUString SAL_CALL getImplementationName() override
virtual ~Content() override
virtual css::uno::Sequence< css::ucb::CommandInfo > getCommands(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
bool isFolder(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void destroy(bool bDeletePhysical)
std::unique_ptr< CachableContentProperties > m_xCachedProps
OUString getBaseURI(const std::unique_ptr< DAVResourceAccess > &rResAccess)
void unlock(const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment)
friend ContentProvider
Definition: pkgprovider.cxx:53
ResourceType getResourceType(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void addProperty(const css::ucb::PropertyCommandArgument &aCmdArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment)
virtual OUString SAL_CALL getContentType() override
virtual css::uno::Sequence< css::beans::Property > getProperties(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
void queryChildren(ContentRefList &rChildren)
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &rValues, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
rtl::Reference< Content > ContentRef