fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / hierarchy / hierarchyprovider.cxx
blob7a107c1e7b29b8d6a899bfc43f1a2bc02028401c
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/util/theOfficeInstallationDirectories.hpp>
32 #include <comphelper/processfactory.hxx>
33 #include <ucbhelper/contentidentifier.hxx>
34 #include "hierarchyprovider.hxx"
35 #include "hierarchycontent.hxx"
36 #include "hierarchyuri.hxx"
38 #include "../inc/urihelper.hxx"
40 using namespace com::sun::star;
41 using namespace hierarchy_ucp;
46 // HierarchyContentProvider Implementation.
51 HierarchyContentProvider::HierarchyContentProvider(
52 const uno::Reference< uno::XComponentContext >& rxContext )
53 : ::ucbhelper::ContentProviderImplHelper( rxContext )
58 // virtual
59 HierarchyContentProvider::~HierarchyContentProvider()
65 // XInterface methods.
67 void SAL_CALL HierarchyContentProvider::acquire()
68 throw()
70 OWeakObject::acquire();
73 void SAL_CALL HierarchyContentProvider::release()
74 throw()
76 OWeakObject::release();
79 css::uno::Any SAL_CALL HierarchyContentProvider::queryInterface( const css::uno::Type & rType )
80 throw( css::uno::RuntimeException, std::exception )
82 css::uno::Any aRet = cppu::queryInterface( rType,
83 (static_cast< lang::XTypeProvider* >(this)),
84 (static_cast< lang::XServiceInfo* >(this)),
85 (static_cast< ucb::XContentProvider* >(this)),
86 (static_cast< lang::XInitialization* >(this))
88 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
91 // XTypeProvider methods.
95 XTYPEPROVIDER_IMPL_4( HierarchyContentProvider,
96 lang::XTypeProvider,
97 lang::XServiceInfo,
98 ucb::XContentProvider,
99 lang::XInitialization );
103 // XServiceInfo methods.
107 XSERVICEINFO_IMPL_1_CTX( HierarchyContentProvider,
108 OUString( "com.sun.star.comp.ucb.HierarchyContentProvider" ),
109 HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME );
113 // Service factory implementation.
117 ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyContentProvider );
121 // XContentProvider methods.
125 // virtual
126 uno::Reference< ucb::XContent > SAL_CALL
127 HierarchyContentProvider::queryContent(
128 const uno::Reference< ucb::XContentIdentifier >& Identifier )
129 throw( ucb::IllegalIdentifierException, uno::RuntimeException, std::exception )
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;
158 // XInitialization methods.
162 // virtual
163 void SAL_CALL HierarchyContentProvider::initialize(
164 const uno::Sequence< uno::Any >& aArguments )
165 throw( uno::Exception, uno::RuntimeException, std::exception )
167 if ( aArguments.getLength() > 0 )
168 OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" );
173 // Non-interface methods.
177 uno::Reference< lang::XMultiServiceFactory >
178 HierarchyContentProvider::getConfigProvider(
179 const OUString & rServiceSpecifier )
181 osl::MutexGuard aGuard( m_aMutex );
182 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
183 rServiceSpecifier );
184 if ( it == m_aConfigProviderMap.end() )
188 ConfigProviderMapEntry aEntry;
189 aEntry.xConfigProvider
190 = uno::Reference< lang::XMultiServiceFactory >(
191 m_xContext->getServiceManager()->createInstanceWithContext(rServiceSpecifier, m_xContext),
192 uno::UNO_QUERY );
194 if ( aEntry.xConfigProvider.is() )
196 m_aConfigProviderMap[ rServiceSpecifier ] = aEntry;
197 return aEntry.xConfigProvider;
200 catch ( uno::Exception const & )
202 // OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - "
203 // "caught exception!" );
206 OSL_FAIL( "HierarchyContentProvider::getConfigProvider - "
207 "No config provider!" );
209 return uno::Reference< lang::XMultiServiceFactory >();
212 return (*it).second.xConfigProvider;
216 uno::Reference< container::XHierarchicalNameAccess >
217 HierarchyContentProvider::getRootConfigReadNameAccess(
218 const OUString & rServiceSpecifier )
220 osl::MutexGuard aGuard( m_aMutex );
221 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
222 rServiceSpecifier );
223 if ( it != m_aConfigProviderMap.end() )
225 if ( !( (*it).second.xRootReadAccess.is() ) )
227 if ( (*it).second.bTriedToGetRootReadAccess ) // #82494#
229 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
230 "Unable to read any config data! -> #82494#" );
231 return uno::Reference< container::XHierarchicalNameAccess >();
236 uno::Reference< lang::XMultiServiceFactory > xConfigProv
237 = getConfigProvider( rServiceSpecifier );
239 if ( xConfigProv.is() )
241 uno::Sequence< uno::Any > aArguments( 1 );
242 beans::PropertyValue aProperty;
243 aProperty.Name = "nodepath" ;
244 aProperty.Value <<= OUString(); // root path
245 aArguments[ 0 ] <<= aProperty;
247 (*it).second.bTriedToGetRootReadAccess = true;
249 (*it).second.xRootReadAccess
250 = uno::Reference< container::XHierarchicalNameAccess >(
251 xConfigProv->createInstanceWithArguments(
252 OUString( "com.sun.star.ucb.HierarchyDataReadAccess" ),
253 aArguments ),
254 uno::UNO_QUERY );
257 catch ( uno::RuntimeException const & )
259 throw;
261 catch ( uno::Exception const & )
263 // createInstance, createInstanceWithArguments
265 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
266 "caught Exception!" );
271 return (*it).second.xRootReadAccess;
275 uno::Reference< util::XOfficeInstallationDirectories >
276 HierarchyContentProvider::getOfficeInstallationDirectories()
278 if ( !m_xOfficeInstDirs.is() )
280 osl::MutexGuard aGuard( m_aMutex );
281 if ( !m_xOfficeInstDirs.is() )
283 OSL_ENSURE( m_xContext.is(), "No service manager!" );
285 m_xOfficeInstDirs = util::theOfficeInstallationDirectories::get(m_xContext);
288 return m_xOfficeInstDirs;
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */