LibreOffice Module ucb (master)  1
neon/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  *
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 #include <sal/config.h>
30 
31 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
34 #include <ucbhelper/macros.hxx>
36 #include "webdavprovider.hxx"
37 #include "webdavcontent.hxx"
38 
39 #include <osl/mutex.hxx>
40 #include <tools/urlobj.hxx>
41 
42 using namespace com::sun::star;
43 using namespace webdav_ucp;
44 
45 
46 // ContentProvider Implementation.
47 
48 
50  const uno::Reference< uno::XComponentContext >& rxContext )
51 : ::ucbhelper::ContentProviderImplHelper( rxContext ),
52  m_xDAVSessionFactory( new DAVSessionFactory )
53 {
54 }
55 
56 
57 // virtual
59 {
60 }
61 
62 
63 // XInterface methods.
64 
65 void SAL_CALL ContentProvider::acquire()
66  throw()
67 {
68  OWeakObject::acquire();
69 }
70 
71 void SAL_CALL ContentProvider::release()
72  throw()
73 {
74  OWeakObject::release();
75 }
76 
77 css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
78 {
79  css::uno::Any aRet = cppu::queryInterface( rType,
80  static_cast< lang::XTypeProvider* >(this),
81  static_cast< lang::XServiceInfo* >(this),
82  static_cast< ucb::XContentProvider* >(this)
83  );
84  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
85 }
86 
87 // XTypeProvider methods.
88 
89 
91  lang::XTypeProvider,
92  lang::XServiceInfo,
93  ucb::XContentProvider );
94 
95 
96 // XServiceInfo methods.
97 
98 OUString
100 {
101  return "com.sun.star.comp.WebDAVContentProvider";
102 }
103 
104 css::uno::Sequence< OUString >
106 {
108 }
109 
110 sal_Bool
112 {
113  return cppu::supportsService(this, s);
114 }
115 
116 // XContentProvider methods.
117 
118 
119 // virtual
120 uno::Reference< ucb::XContent > SAL_CALL
122  const uno::Reference<
123  ucb::XContentIdentifier >& Identifier )
124 {
125  // Check URL scheme...
126  INetURLObject aURL( Identifier->getContentIdentifier() );
127 
128  if ( aURL.isSchemeEqualTo( INetProtocol::NotValid ) )
129  throw ucb::IllegalIdentifierException();
130 
131  if ( !aURL.isAnyKnownWebDAVScheme() )
132  throw ucb::IllegalIdentifierException();
133 
134  uno::Reference< ucb::XContentIdentifier > xCanonicId;
135 
136  if (aURL.isSchemeEqualTo( INetProtocol::VndSunStarWebdav ) ||
137  aURL.isSchemeEqualTo(DAV_URL_SCHEME) ||
138  aURL.isSchemeEqualTo( WEBDAV_URL_SCHEME ) )
139  {
140  aURL.changeScheme( INetProtocol::Http );
141  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
142  }
143  else if ( aURL.isSchemeEqualTo( VNDSUNSTARWEBDAVS_URL_SCHEME ) ||
144  aURL.isSchemeEqualTo( DAVS_URL_SCHEME ) ||
145  aURL.isSchemeEqualTo( WEBDAVS_URL_SCHEME ))
146  {
147  aURL.changeScheme( INetProtocol::Https );
148  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
149  }
150  else
151  {
152  xCanonicId = Identifier;
153  }
154 
155  osl::MutexGuard aGuard( m_aMutex );
156 
157  // Check, if a content with given id already exists...
158  uno::Reference< ucb::XContent > xContent
159  = queryExistingContent( xCanonicId );
160  if ( xContent.is() )
161  return xContent;
162 
163  // Create a new content.
164 
165  try
166  {
167  xContent = new ::webdav_ucp::Content(
168  m_xContext, this, xCanonicId, m_xDAVSessionFactory );
169  registerNewContent( xContent );
170  }
171  catch ( ucb::ContentCreationException const & )
172  {
173  throw ucb::IllegalIdentifierException();
174  }
175 
176  if ( !xContent->getIdentifier().is() )
177  throw ucb::IllegalIdentifierException();
178 
179  return xContent;
180 }
181 
182 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
184  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
185 {
186  return cppu::acquire(new ContentProvider(context));
187 }
188 
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
#define DAVS_URL_SCHEME
virtual void SAL_CALL acquire() override
#define WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
#define WEBDAV_URL_SCHEME
#define WEBDAVS_URL_SCHEME
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
#define DAV_URL_SCHEME
unsigned char sal_Bool
rtl::Reference< ContentImplHelper > queryExistingContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
#define VNDSUNSTARWEBDAVS_URL_SCHEME
OUString aURL
css::uno::Reference< css::uno::XComponentContext > m_xContext
void registerNewContent(const css::uno::Reference< css::ucb::XContent > &xContent)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_webdav_neon_ContentProvider_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
virtual void SAL_CALL release() override
XTYPEPROVIDER_IMPL_3(ContentProvider, lang::XTypeProvider, lang::XServiceInfo, ucb::XContentProvider)
rtl::Reference< DAVSessionFactory > m_xDAVSessionFactory
friend ContentProvider
Definition: pkgprovider.cxx:53
uno::Reference< ucb::XContent > xContent
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual ~ContentProvider() override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)