bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / hierarchy / hierarchyprovider.cxx
blobfa8cdaca888772f4b30ff6d23a4bffa3dcacd11d
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 <cppuhelper/weak.hxx>
35 #include <ucbhelper/contentidentifier.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 noexcept
68 OWeakObject::acquire();
71 void SAL_CALL HierarchyContentProvider::release()
72 noexcept
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 OUString SAL_CALL HierarchyContentProvider::getImplementationName() \
102 return "com.sun.star.comp.ucb.HierarchyContentProvider";
104 sal_Bool SAL_CALL HierarchyContentProvider::supportsService( const OUString& ServiceName )
106 return cppu::supportsService( this, ServiceName );
108 css::uno::Sequence< OUString > HierarchyContentProvider::getSupportedServiceNames()
110 return { "com.sun.star.ucb.HierarchyContentProvider" };
113 // Service factory implementation.
115 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
116 ucb_HierarchyContentProvider_get_implementation(
117 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
119 return cppu::acquire(new HierarchyContentProvider(context));
122 // XContentProvider methods.
125 // virtual
126 uno::Reference< ucb::XContent > SAL_CALL
127 HierarchyContentProvider::queryContent(
128 const uno::Reference< ucb::XContentIdentifier >& Identifier )
130 HierarchyUri aUri( Identifier->getContentIdentifier() );
131 if ( !aUri.isValid() )
132 throw ucb::IllegalIdentifierException();
134 // Encode URL and create new Id. This may "correct" user-typed-in URL's.
135 uno::Reference< ucb::XContentIdentifier > xCanonicId
136 = new ::ucbhelper::ContentIdentifier( ::ucb_impl::urihelper::encodeURI( aUri.getUri() ) );
137 osl::MutexGuard aGuard( m_aMutex );
139 // Check, if a content with given id already exists...
140 uno::Reference< ucb::XContent > xContent
141 = queryExistingContent( xCanonicId );
142 if ( xContent.is() )
143 return xContent;
145 // Create a new content.
146 xContent = HierarchyContent::create( m_xContext, this, xCanonicId );
147 registerNewContent( xContent );
149 if ( xContent.is() && !xContent->getIdentifier().is() )
150 throw ucb::IllegalIdentifierException();
152 return xContent;
156 // XInitialization methods.
159 // virtual
160 void SAL_CALL HierarchyContentProvider::initialize(
161 const uno::Sequence< uno::Any >& aArguments )
163 if ( aArguments.hasElements() )
164 OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" );
168 // Non-interface methods.
171 uno::Reference< lang::XMultiServiceFactory >
172 HierarchyContentProvider::getConfigProvider(
173 const OUString & rServiceSpecifier )
175 osl::MutexGuard aGuard( m_aMutex );
176 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
177 rServiceSpecifier );
178 if ( it == m_aConfigProviderMap.end() )
182 ConfigProviderMapEntry aEntry;
183 aEntry.xConfigProvider.set(
184 m_xContext->getServiceManager()->createInstanceWithContext(rServiceSpecifier, m_xContext),
185 uno::UNO_QUERY );
187 if ( aEntry.xConfigProvider.is() )
189 m_aConfigProviderMap[ rServiceSpecifier ] = aEntry;
190 return aEntry.xConfigProvider;
193 catch ( uno::Exception const & )
195 // OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - "
196 // "caught exception!" );
199 OSL_FAIL( "HierarchyContentProvider::getConfigProvider - "
200 "No config provider!" );
202 return uno::Reference< lang::XMultiServiceFactory >();
205 return (*it).second.xConfigProvider;
208 uno::Reference< container::XHierarchicalNameAccess >
209 HierarchyContentProvider::getRootConfigReadNameAccess(
210 const OUString & rServiceSpecifier )
212 osl::MutexGuard aGuard( m_aMutex );
213 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
214 rServiceSpecifier );
215 if (it == m_aConfigProviderMap.end())
216 return uno::Reference< container::XHierarchicalNameAccess >();
218 if ( !( (*it).second.xRootReadAccess.is() ) )
220 if ( (*it).second.bTriedToGetRootReadAccess )
222 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
223 "Unable to read any config data! -> #82494#" );
224 return uno::Reference< container::XHierarchicalNameAccess >();
229 uno::Reference< lang::XMultiServiceFactory > xConfigProv
230 = getConfigProvider( rServiceSpecifier );
232 if ( xConfigProv.is() )
234 uno::Sequence< uno::Any > aArguments( 1 );
235 beans::PropertyValue aProperty;
236 aProperty.Name = "nodepath" ;
237 aProperty.Value <<= OUString(); // root path
238 aArguments[ 0 ] <<= aProperty;
240 (*it).second.bTriedToGetRootReadAccess = true;
242 (*it).second.xRootReadAccess.set(
243 xConfigProv->createInstanceWithArguments(
244 "com.sun.star.ucb.HierarchyDataReadAccess",
245 aArguments ),
246 uno::UNO_QUERY );
249 catch ( uno::RuntimeException const & )
251 throw;
253 catch ( uno::Exception const & )
255 // createInstance, createInstanceWithArguments
257 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
258 "caught Exception!" );
262 return (*it).second.xRootReadAccess;
265 uno::Reference< util::XOfficeInstallationDirectories >
266 HierarchyContentProvider::getOfficeInstallationDirectories()
268 if ( !m_xOfficeInstDirs.is() )
270 osl::MutexGuard aGuard( m_aMutex );
271 if ( !m_xOfficeInstDirs.is() )
273 OSL_ENSURE( m_xContext.is(), "No service manager!" );
275 m_xOfficeInstDirs = util::theOfficeInstallationDirectories::get(m_xContext);
278 return m_xOfficeInstDirs;
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */