Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / ucp / hierarchy / hierarchyprovider.cxx
blobd95d39dd0a9d79e2024da4a57b781a67fef56310
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 /**************************************************************************
22 TODO
23 **************************************************************************
25 - XInitialization::initialize does not work any longer!
27 *************************************************************************/
28 #include <osl/diagnose.h>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
31 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
32 #include <com/sun/star/util/theOfficeInstallationDirectories.hpp>
33 #include <cppuhelper/queryinterface.hxx>
34 #include <ucbhelper/contentidentifier.hxx>
35 #include <ucbhelper/getcomponentcontext.hxx>
36 #include <ucbhelper/macros.hxx>
37 #include "hierarchyprovider.hxx"
38 #include "hierarchycontent.hxx"
39 #include "hierarchyuri.hxx"
41 #include "../inc/urihelper.hxx"
43 using namespace com::sun::star;
44 using namespace hierarchy_ucp;
47 // HierarchyContentProvider Implementation.
50 HierarchyContentProvider::HierarchyContentProvider(
51 const uno::Reference< uno::XComponentContext >& rxContext )
52 : ::ucbhelper::ContentProviderImplHelper( rxContext )
57 // virtual
58 HierarchyContentProvider::~HierarchyContentProvider()
63 // XInterface methods.
65 void SAL_CALL HierarchyContentProvider::acquire()
66 throw()
68 OWeakObject::acquire();
71 void SAL_CALL HierarchyContentProvider::release()
72 throw()
74 OWeakObject::release();
77 css::uno::Any SAL_CALL HierarchyContentProvider::queryInterface( const css::uno::Type & rType )
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 static_cast< lang::XInitialization* >(this)
85 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
88 // XTypeProvider methods.
91 XTYPEPROVIDER_IMPL_4( HierarchyContentProvider,
92 lang::XTypeProvider,
93 lang::XServiceInfo,
94 ucb::XContentProvider,
95 lang::XInitialization );
98 // XServiceInfo methods.
100 XSERVICEINFO_COMMOM_IMPL( HierarchyContentProvider,
101 "com.sun.star.comp.ucb.HierarchyContentProvider" )
102 /// @throws css::uno::Exception
103 static css::uno::Reference< css::uno::XInterface >
104 HierarchyContentProvider_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
106 css::lang::XServiceInfo* pX = new HierarchyContentProvider( ucbhelper::getComponentContext(rSMgr) );
107 return css::uno::Reference< css::uno::XInterface >::query( pX );
110 css::uno::Sequence< OUString >
111 HierarchyContentProvider::getSupportedServiceNames_Static()
113 css::uno::Sequence< OUString > aSNS { "com.sun.star.ucb.HierarchyContentProvider" };
114 return aSNS;
117 // Service factory implementation.
120 ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyContentProvider );
123 // XContentProvider methods.
126 // virtual
127 uno::Reference< ucb::XContent > SAL_CALL
128 HierarchyContentProvider::queryContent(
129 const uno::Reference< ucb::XContentIdentifier >& Identifier )
131 HierarchyUri aUri( Identifier->getContentIdentifier() );
132 if ( !aUri.isValid() )
133 throw ucb::IllegalIdentifierException();
135 // Encode URL and create new Id. This may "correct" user-typed-in URL's.
136 uno::Reference< ucb::XContentIdentifier > xCanonicId
137 = new ::ucbhelper::ContentIdentifier( ::ucb_impl::urihelper::encodeURI( aUri.getUri() ) );
138 osl::MutexGuard aGuard( m_aMutex );
140 // Check, if a content with given id already exists...
141 uno::Reference< ucb::XContent > xContent
142 = queryExistingContent( xCanonicId ).get();
143 if ( xContent.is() )
144 return xContent;
146 // Create a new content.
147 xContent = HierarchyContent::create( m_xContext, this, xCanonicId );
148 registerNewContent( xContent );
150 if ( xContent.is() && !xContent->getIdentifier().is() )
151 throw ucb::IllegalIdentifierException();
153 return xContent;
157 // XInitialization methods.
160 // virtual
161 void SAL_CALL HierarchyContentProvider::initialize(
162 const uno::Sequence< uno::Any >& aArguments )
164 if ( aArguments.hasElements() )
165 OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" );
169 // Non-interface methods.
172 uno::Reference< lang::XMultiServiceFactory >
173 HierarchyContentProvider::getConfigProvider(
174 const OUString & rServiceSpecifier )
176 osl::MutexGuard aGuard( m_aMutex );
177 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
178 rServiceSpecifier );
179 if ( it == m_aConfigProviderMap.end() )
183 ConfigProviderMapEntry aEntry;
184 aEntry.xConfigProvider.set(
185 m_xContext->getServiceManager()->createInstanceWithContext(rServiceSpecifier, m_xContext),
186 uno::UNO_QUERY );
188 if ( aEntry.xConfigProvider.is() )
190 m_aConfigProviderMap[ rServiceSpecifier ] = aEntry;
191 return aEntry.xConfigProvider;
194 catch ( uno::Exception const & )
196 // OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - "
197 // "caught exception!" );
200 OSL_FAIL( "HierarchyContentProvider::getConfigProvider - "
201 "No config provider!" );
203 return uno::Reference< lang::XMultiServiceFactory >();
206 return (*it).second.xConfigProvider;
209 uno::Reference< container::XHierarchicalNameAccess >
210 HierarchyContentProvider::getRootConfigReadNameAccess(
211 const OUString & rServiceSpecifier )
213 osl::MutexGuard aGuard( m_aMutex );
214 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
215 rServiceSpecifier );
216 if (it == m_aConfigProviderMap.end())
217 return uno::Reference< container::XHierarchicalNameAccess >();
219 if ( !( (*it).second.xRootReadAccess.is() ) )
221 if ( (*it).second.bTriedToGetRootReadAccess )
223 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
224 "Unable to read any config data! -> #82494#" );
225 return uno::Reference< container::XHierarchicalNameAccess >();
230 uno::Reference< lang::XMultiServiceFactory > xConfigProv
231 = getConfigProvider( rServiceSpecifier );
233 if ( xConfigProv.is() )
235 uno::Sequence< uno::Any > aArguments( 1 );
236 beans::PropertyValue aProperty;
237 aProperty.Name = "nodepath" ;
238 aProperty.Value <<= OUString(); // root path
239 aArguments[ 0 ] <<= aProperty;
241 (*it).second.bTriedToGetRootReadAccess = true;
243 (*it).second.xRootReadAccess.set(
244 xConfigProv->createInstanceWithArguments(
245 "com.sun.star.ucb.HierarchyDataReadAccess",
246 aArguments ),
247 uno::UNO_QUERY );
250 catch ( uno::RuntimeException const & )
252 throw;
254 catch ( uno::Exception const & )
256 // createInstance, createInstanceWithArguments
258 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
259 "caught Exception!" );
263 return (*it).second.xRootReadAccess;
266 uno::Reference< util::XOfficeInstallationDirectories >
267 HierarchyContentProvider::getOfficeInstallationDirectories()
269 if ( !m_xOfficeInstDirs.is() )
271 osl::MutexGuard aGuard( m_aMutex );
272 if ( !m_xOfficeInstDirs.is() )
274 OSL_ENSURE( m_xContext.is(), "No service manager!" );
276 m_xOfficeInstDirs = util::theOfficeInstallationDirectories::get(m_xContext);
279 return m_xOfficeInstDirs;
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */