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 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_WEBDAVCONTENT_HXX
30 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_WEBDAVCONTENT_HXX
31 
32 #include <config_lgpl.h>
33 #include <memory>
34 #include <list>
35 #include <rtl/ref.hxx>
36 #include <com/sun/star/ucb/ContentCreationException.hpp>
37 #include <com/sun/star/ucb/XContentCreator.hpp>
39 #include "DAVResourceAccess.hxx"
40 #include "PropertyMap.hxx"
41 
42 namespace com { namespace sun { namespace star { namespace beans {
43  struct Property;
44  struct PropertyValue;
45 } } } }
46 
47 namespace com { namespace sun { namespace star { namespace io {
48  class XInputStream;
49 } } } }
50 
51 namespace com { namespace sun { namespace star { namespace sdbc {
52  class XRow;
53 } } } }
54 
55 namespace com { namespace sun { namespace star { namespace ucb {
56  struct OpenCommandArgument3;
57  struct PostCommandArgument2;
58  struct PropertyCommandArgument;
59  struct TransferInfo;
60 } } } }
61 
62 namespace webdav_ucp
63 {
64 
65 
66 // UNO service name for the content.
67 #define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent"
68 
69 
70 class ContentProvider;
71 class ContentProperties;
72 class CachableContentProperties;
73 
75  public css::ucb::XContentCreator
76 {
78  {
79  UNKNOWN, // the type of the Web resource is unknown
80  NOT_FOUND, // the Web resource does not exists
81  FTP, // the Web resource exists but it's ftp
82  NON_DAV, // the Web resource exists but it's not DAV
83  DAV, // the type of the Web resource is DAV with lock/unlock available
84  DAV_NOLOCK // the type of the Web resource is DAV with no lock/unlock available
85  };
86 
87  std::unique_ptr< DAVResourceAccess > m_xResAccess;
88  std::unique_ptr< CachableContentProperties >
89  m_xCachedProps; // locally cached props
90  OUString m_aEscapedTitle;
91  // resource type for general DAV methods
93  // resource type for general LOCK method only
95  ContentProvider* m_pProvider; // No need for a ref, base class holds object
97  bool const m_bCollection;
99  std::vector< OUString > m_aFailedPropNames;
100  // Options Cache lifetime
101  // for web site implementing OPTIONS, but not dav
103  // for WebDAV site where OPTIONS is mandatory
105  // same as above, but when the resource is locked by us
107 // For web site not implementing OPTIONS
108  // during this time we assume the site doesn't turn to WebDAV
109  // but remains a simple Web
111  // When resource is not found
112  // may be the resource is unavailable only briefly?
113  // so better have this small
115 
116  void initOptsCacheLifeTime();
117 
118 private:
119  virtual css::uno::Sequence< css::beans::Property >
120  getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
121  virtual css::uno::Sequence< css::ucb::CommandInfo >
122  getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
123  virtual OUString getParentURL() override;
124 
126  bool isFolder( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
127 
129  css::uno::Reference< css::sdbc::XRow >
130  getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties,
131  const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
132 
134  css::uno::Sequence< css::uno::Any >
135  setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& rValues,
136  const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
137 
139  typedef std::vector< ContentRef > ContentRefList;
140  void queryChildren( ContentRefList& rChildren);
141 
142  bool
143  exchangeIdentity( const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
144 
145  OUString
146  getBaseURI( const std::unique_ptr< DAVResourceAccess > & rResAccess );
147 
150  getResourceType( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv );
151 
154  getResourceType( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
155  const std::unique_ptr< DAVResourceAccess > & rResAccess,
156  bool * networkAccessAllowed = nullptr);
157 
158  // Command "open"
160  css::uno::Any open(
161  const css::ucb::OpenCommandArgument3 & rArg,
162  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
163 
164  // Command "post"
166  void post( const css::ucb::PostCommandArgument2 & rArg,
167  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
168 
169  // Command "insert"
171  void insert( const css::uno::Reference< css::io::XInputStream > & xInputStream,
172  bool bReplaceExisting,
173  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
174 
175  // Command "transfer"
177  void transfer( const css::ucb::TransferInfo & rArgs,
178  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
179 
180  // Command "delete"
182  void destroy( bool bDeletePhysical );
183 
184  // Command "lock"
186  void lock( const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
187 
188  // Command "unlock"
190  void unlock( const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
191 
192  css::uno::Any MapDAVException( const DAVException & e,
193  bool bWrite );
196  const DAVException & e,
197  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv,
198  bool bWrite = false );
199 
200  static bool shouldAccessNetworkAfterException( const DAVException & e );
201 
203  const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnvironment,
204  const std::unique_ptr< DAVResourceAccess > & rResAccess );
205 
207  const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnvironment );
208 
213  void addProperty( const css::ucb::PropertyCommandArgument &aCmdArg,
214  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
215 
219  void removeProperty( const OUString& Name,
220  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment );
221 
222 public:
225  Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
226  ContentProvider* pProvider,
227  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
228  rtl::Reference< DAVSessionFactory > const & rSessionFactory );
231  Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
232  ContentProvider* pProvider,
233  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
234  rtl::Reference< DAVSessionFactory > const & rSessionFactory,
235  bool isCollection );
236  virtual ~Content() override;
237 
238  // XInterface
239  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
240  virtual void SAL_CALL acquire()
241  throw() override;
242  virtual void SAL_CALL release()
243  throw() override;
244 
245  // XTypeProvider
246  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
247  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
248 
249  // XServiceInfo
250  virtual OUString SAL_CALL
251  getImplementationName() override;
252 
253  virtual css::uno::Sequence< OUString > SAL_CALL
254  getSupportedServiceNames() override;
255 
256  // XContent
257  virtual OUString SAL_CALL
258  getContentType() override;
259 
260  // XCommandProcessor
261  virtual css::uno::Any SAL_CALL
262  execute( const css::ucb::Command& aCommand,
263  sal_Int32 CommandId,
264  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override;
265  virtual void SAL_CALL
266  abort( sal_Int32 CommandId ) override;
267 
268  // XPropertyContainer
269  virtual void SAL_CALL
270  addProperty( const OUString& Name,
271  sal_Int16 Attributes,
272  const css::uno::Any& DefaultValue ) override;
273 
274  virtual void SAL_CALL
275  removeProperty( const OUString& Name ) override;
276 
277 
278  // Additional interfaces
279 
280 
281  // XContentCreator
282  virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL
283  queryCreatableContentsInfo() override;
284  virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
285  createNewContent( const css::ucb::ContentInfo& Info ) override;
286 
287 
288  // Non-interface methods.
289 
290 
292 
293  // Called from resultset data supplier.
294  static css::uno::Reference< css::sdbc::XRow >
295  getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
296  const css::uno::Sequence< css::beans::Property >& rProperties,
297  const ContentProperties& rData,
299  const OUString& rContentId );
300 
301  // Use OPTIONS method to retrieve the type of the Web resource
303  void getResourceOptions( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
304  DAVOptions& rDAVOptions,
305  const std::unique_ptr< DAVResourceAccess > & rResAccess,
306  bool * networkAccessAllowed = nullptr);
307 
308  static bool isResourceAvailable( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv,
309  const std::unique_ptr< DAVResourceAccess > & rResAccess,
310  DAVOptions& rDAVOptions );
311 
312  static void removeCachedPropertyNames( const OUString & rURL );
313 
314 };
315 
316 }
317 
318 #endif
319 
320 /* 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)
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)
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)
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)
virtual void SAL_CALL release() override
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
virtual void SAL_CALL acquire() override