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>
35 #include <ucbhelper/macros.hxx>
37 #include "webdavprovider.hxx"
38 #include "webdavcontent.hxx"
39 
40 #include <osl/mutex.hxx>
41 #include <tools/urlobj.hxx>
42 
43 using namespace com::sun::star;
44 using namespace webdav_ucp;
45 
46 
47 // ContentProvider Implementation.
48 
49 
50 ContentProvider::ContentProvider(
51  const uno::Reference< uno::XComponentContext >& rxContext )
52 : ::ucbhelper::ContentProviderImplHelper( rxContext ),
53  m_xDAVSessionFactory( new DAVSessionFactory )
54 {
55 }
56 
57 
58 // virtual
60 {
61 }
62 
63 
64 // XInterface methods.
65 
66 void SAL_CALL ContentProvider::acquire()
67  throw()
68 {
69  OWeakObject::acquire();
70 }
71 
72 void SAL_CALL ContentProvider::release()
73  throw()
74 {
75  OWeakObject::release();
76 }
77 
78 css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
79 {
80  css::uno::Any aRet = cppu::queryInterface( rType,
81  static_cast< lang::XTypeProvider* >(this),
82  static_cast< lang::XServiceInfo* >(this),
83  static_cast< ucb::XContentProvider* >(this)
84  );
85  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
86 }
87 
88 // XTypeProvider methods.
89 
90 
92  lang::XTypeProvider,
93  lang::XServiceInfo,
94  ucb::XContentProvider );
95 
96 
97 // XServiceInfo methods.
98 
100  "com.sun.star.comp.WebDAVContentProvider" )
102 static css::uno::Reference< css::uno::XInterface >
103 ContentProvider_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
104 {
105  css::lang::XServiceInfo* pX = new ContentProvider( ucbhelper::getComponentContext(rSMgr) );
106  return css::uno::Reference< css::uno::XInterface >::query( pX );
107 }
108 
109 css::uno::Sequence< OUString >
111 {
112  css::uno::Sequence< OUString > aSNS { WEBDAV_CONTENT_PROVIDER_SERVICE_NAME };
113  return aSNS;
114 }
115 
116 // Service factory implementation.
117 
118 
120 
121 
122 // XContentProvider methods.
123 
124 
125 // virtual
126 uno::Reference< ucb::XContent > SAL_CALL
128  const uno::Reference<
129  ucb::XContentIdentifier >& Identifier )
130 {
131  // Check URL scheme...
132  INetURLObject aURL( Identifier->getContentIdentifier() );
133 
134  if ( aURL.isSchemeEqualTo( INetProtocol::NotValid ) )
135  throw ucb::IllegalIdentifierException();
136 
137  if ( !aURL.isAnyKnownWebDAVScheme() )
138  throw ucb::IllegalIdentifierException();
139 
140  uno::Reference< ucb::XContentIdentifier > xCanonicId;
141 
142  if (aURL.isSchemeEqualTo( INetProtocol::VndSunStarWebdav ) ||
143  aURL.isSchemeEqualTo(DAV_URL_SCHEME) ||
144  aURL.isSchemeEqualTo( WEBDAV_URL_SCHEME ) )
145  {
146  aURL.changeScheme( INetProtocol::Http );
147  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
148  }
149  else if ( aURL.isSchemeEqualTo( VNDSUNSTARWEBDAVS_URL_SCHEME ) ||
150  aURL.isSchemeEqualTo( DAVS_URL_SCHEME ) ||
151  aURL.isSchemeEqualTo( WEBDAVS_URL_SCHEME ))
152  {
153  aURL.changeScheme( INetProtocol::Https );
154  xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() );
155  }
156  else
157  {
158  xCanonicId = Identifier;
159  }
160 
161  osl::MutexGuard aGuard( m_aMutex );
162 
163  // Check, if a content with given id already exists...
164  uno::Reference< ucb::XContent > xContent
165  = queryExistingContent( xCanonicId ).get();
166  if ( xContent.is() )
167  return xContent;
168 
169  // Create a new content.
170 
171  try
172  {
173  xContent = new ::webdav_ucp::Content(
174  m_xContext, this, xCanonicId, m_xDAVSessionFactory );
175  registerNewContent( xContent );
176  }
177  catch ( ucb::ContentCreationException const & )
178  {
179  throw ucb::IllegalIdentifierException();
180  }
181 
182  if ( !xContent->getIdentifier().is() )
183  throw ucb::IllegalIdentifierException();
184 
185  return xContent;
186 }
187 
188 /* 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
UCBHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > getComponentContext(css::uno::Reference< css::lang::XMultiServiceFactory > const &factory)
#define DAVS_URL_SCHEME
virtual void SAL_CALL acquire() override
#define WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
#define WEBDAV_URL_SCHEME
#define WEBDAVS_URL_SCHEME
#define DAV_URL_SCHEME
rtl::Reference< ContentImplHelper > queryExistingContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
#define VNDSUNSTARWEBDAVS_URL_SCHEME
ONE_INSTANCE_SERVICE_FACTORY_IMPL(ContentProvider)
css::uno::Reference< css::uno::XComponentContext > m_xContext
static css::uno::Sequence< OUString > getSupportedServiceNames_Static()
void registerNewContent(const css::uno::Reference< css::ucb::XContent > &xContent)
XSERVICEINFO_COMMOM_IMPL(ContentProvider,"com.sun.star.comp.WebDAVContentProvider") static css
virtual void SAL_CALL release() override
XTYPEPROVIDER_IMPL_3(ContentProvider, lang::XTypeProvider, lang::XServiceInfo, ucb::XContentProvider)
void changeScheme(INetProtocol eTargetScheme)
rtl::Reference< DAVSessionFactory > m_xDAVSessionFactory
virtual ~ContentProvider() override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)