LibreOffice Module ucb (master)  1
webdavprovider.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
22 #include <ucbhelper/macros.hxx>
23 #include "webdavprovider.hxx"
24 #include "webdavcontent.hxx"
25 
27 #include <osl/mutex.hxx>
28 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
29 
30 #include <tools/urlobj.hxx>
31 
32 using namespace com::sun::star;
33 using namespace http_dav_ucp;
34 
35 
36 // ContentProvider Implementation.
37 
38 
39 ContentProvider::ContentProvider(
40  const uno::Reference< uno::XComponentContext >& rContext )
41 : ::ucbhelper::ContentProviderImplHelper( rContext ),
42  m_xDAVSessionFactory( new DAVSessionFactory )
43 {
44 }
45 
46 
47 // virtual
49 {}
50 
51 
52 // XInterface methods.
53 void SAL_CALL ContentProvider::acquire()
54  throw()
55 {
56  OWeakObject::acquire();
57 }
58 
59 void SAL_CALL ContentProvider::release()
60  throw()
61 {
62  OWeakObject::release();
63 }
64 
65 css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
66 {
67  css::uno::Any aRet = cppu::queryInterface( rType,
68  static_cast< lang::XTypeProvider* >(this),
69  static_cast< lang::XServiceInfo* >(this),
70  static_cast< ucb::XContentProvider* >(this)
71  );
72  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
73 }
74 
75 // XTypeProvider methods.
76 
77 
79  lang::XTypeProvider,
80  lang::XServiceInfo,
81  ucb::XContentProvider );
82 
83 
84 // XServiceInfo methods.
85 
87  OUString( "com.sun.star.comp.WebDAVContentProvider" ) )
89 static css::uno::Reference< css::uno::XInterface >
90 ContentProvider_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
91 {
92  css::lang::XServiceInfo* pX =
93  static_cast<css::lang::XServiceInfo*>(new ContentProvider( ucbhelper::getComponentContext(rSMgr) ));
94  return css::uno::Reference< css::uno::XInterface >::query( pX );
95 }
96 
97 css::uno::Sequence< OUString >
99 {
100  css::uno::Sequence< OUString > aSNS { WEBDAV_CONTENT_PROVIDER_SERVICE_NAME };
101  return aSNS;
102 }
103 
104 // Service factory implementation.
105 
106 
108 
109 
110 // XContentProvider methods.
111 
112 
113 // virtual
114 uno::Reference< ucb::XContent > SAL_CALL
116  const uno::Reference<
117  ucb::XContentIdentifier >& Identifier )
118 {
119  // Check URL scheme...
120  INetURLObject aURL(Identifier->getContentIdentifier());
121 
122  if (aURL.isSchemeEqualTo(INetProtocol::NotValid))
123  throw ucb::IllegalIdentifierException();
124 
125  if (!aURL.isAnyKnownWebDAVScheme())
126  throw ucb::IllegalIdentifierException();
127 
128  uno::Reference< ucb::XContentIdentifier > xCanonicId;
129 
130  if (aURL.isSchemeEqualTo(INetProtocol::VndSunStarWebdav) ||
131  aURL.isSchemeEqualTo(DAV_URL_SCHEME) ||
132  aURL.isSchemeEqualTo(WEBDAV_URL_SCHEME))
133  {
134  aURL.changeScheme(INetProtocol::Http);
135  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
136  }
137  else if (aURL.isSchemeEqualTo(VNDSUNSTARWEBDAVS_URL_SCHEME) ||
138  aURL.isSchemeEqualTo(DAVS_URL_SCHEME) ||
139  aURL.isSchemeEqualTo(WEBDAVS_URL_SCHEME))
140  {
141  aURL.changeScheme(INetProtocol::Https);
142  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
143  }
144  else
145  {
146  xCanonicId = Identifier;
147  }
148 
149  osl::MutexGuard aGuard( m_aMutex );
150 
151  // Check, if a content with given id already exists...
152  uno::Reference< ucb::XContent > xContent
153  = queryExistingContent( xCanonicId ).get();
154  if ( xContent.is() )
155  return xContent;
156 
157  // Create a new content.
158 
159  try
160  {
161  xContent = new ::http_dav_ucp::Content(
162  m_xContext, this, xCanonicId, m_xDAVSessionFactory );
163  registerNewContent( xContent );
164  }
165  catch ( ucb::ContentCreationException const & )
166  {
167  throw ucb::IllegalIdentifierException();
168  }
169 
170  if ( !xContent->getIdentifier().is() )
171  throw ucb::IllegalIdentifierException();
172 
173  return xContent;
174 }
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
UCBHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > getComponentContext(css::uno::Reference< css::lang::XMultiServiceFactory > const &factory)
#define DAVS_URL_SCHEME
#define WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
#define WEBDAV_URL_SCHEME
XTYPEPROVIDER_IMPL_3(ContentProvider, lang::XTypeProvider, lang::XServiceInfo, ucb::XContentProvider)
#define WEBDAVS_URL_SCHEME
static css::uno::Sequence< OUString > getSupportedServiceNames_Static()
virtual void SAL_CALL acquire() override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
virtual void SAL_CALL release() override
#define DAV_URL_SCHEME
ONE_INSTANCE_SERVICE_FACTORY_IMPL(ContentProvider)
rtl::Reference< ContentImplHelper > queryExistingContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
#define VNDSUNSTARWEBDAVS_URL_SCHEME
css::uno::Reference< css::uno::XComponentContext > m_xContext
void registerNewContent(const css::uno::Reference< css::ucb::XContent > &xContent)
rtl::Reference< DAVSessionFactory > m_xDAVSessionFactory
void changeScheme(INetProtocol eTargetScheme)
XSERVICEINFO_COMMOM_IMPL(ContentProvider, OUString("com.sun.star.comp.WebDAVContentProvider")) static css
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override