Fix GNU C++ version check
[LibreOffice.git] / ucb / source / ucp / hierarchy / hierarchyprovider.cxx
blob8837f36111be793a264acd217a1ed2e10d5d0528
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 : HierarchyContentProvider_Base( rxContext )
57 // virtual
58 HierarchyContentProvider::~HierarchyContentProvider()
62 // XServiceInfo methods.
64 OUString SAL_CALL HierarchyContentProvider::getImplementationName() \
66 return u"com.sun.star.comp.ucb.HierarchyContentProvider"_ustr;
68 sal_Bool SAL_CALL HierarchyContentProvider::supportsService( const OUString& ServiceName )
70 return cppu::supportsService( this, ServiceName );
72 css::uno::Sequence< OUString > HierarchyContentProvider::getSupportedServiceNames()
74 return { u"com.sun.star.ucb.HierarchyContentProvider"_ustr };
77 // Service factory implementation.
79 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
80 ucb_HierarchyContentProvider_get_implementation(
81 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
83 return cppu::acquire(new HierarchyContentProvider(context));
86 // XContentProvider methods.
89 // virtual
90 uno::Reference< ucb::XContent > SAL_CALL
91 HierarchyContentProvider::queryContent(
92 const uno::Reference< ucb::XContentIdentifier >& Identifier )
94 HierarchyUri aUri( Identifier->getContentIdentifier() );
95 if ( !aUri.isValid() )
96 throw ucb::IllegalIdentifierException();
98 // Encode URL and create new Id. This may "correct" user-typed-in URL's.
99 uno::Reference< ucb::XContentIdentifier > xCanonicId
100 = new ::ucbhelper::ContentIdentifier( ::ucb_impl::urihelper::encodeURI( aUri.getUri() ) );
101 osl::MutexGuard aGuard( m_aMutex );
103 // Check, if a content with given id already exists...
104 uno::Reference< ucb::XContent > xContent
105 = queryExistingContent( xCanonicId );
106 if ( xContent.is() )
107 return xContent;
109 // Create a new content.
110 xContent = HierarchyContent::create( m_xContext, this, xCanonicId );
111 registerNewContent( xContent );
113 if ( xContent.is() && !xContent->getIdentifier().is() )
114 throw ucb::IllegalIdentifierException();
116 return xContent;
120 // XInitialization methods.
123 // virtual
124 void SAL_CALL HierarchyContentProvider::initialize(
125 const uno::Sequence< uno::Any >& aArguments )
127 if ( aArguments.hasElements() )
128 OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" );
132 // Non-interface methods.
135 uno::Reference< lang::XMultiServiceFactory >
136 HierarchyContentProvider::getConfigProvider(
137 const OUString & rServiceSpecifier )
139 osl::MutexGuard aGuard( m_aMutex );
140 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
141 rServiceSpecifier );
142 if ( it == m_aConfigProviderMap.end() )
146 ConfigProviderMapEntry aEntry;
147 aEntry.xConfigProvider.set(
148 m_xContext->getServiceManager()->createInstanceWithContext(rServiceSpecifier, m_xContext),
149 uno::UNO_QUERY );
151 if ( aEntry.xConfigProvider.is() )
153 m_aConfigProviderMap[ rServiceSpecifier ] = aEntry;
154 return aEntry.xConfigProvider;
157 catch ( uno::Exception const & )
159 // OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - "
160 // "caught exception!" );
163 OSL_FAIL( "HierarchyContentProvider::getConfigProvider - "
164 "No config provider!" );
166 return uno::Reference< lang::XMultiServiceFactory >();
169 return (*it).second.xConfigProvider;
172 uno::Reference< container::XHierarchicalNameAccess >
173 HierarchyContentProvider::getRootConfigReadNameAccess(
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())
180 return uno::Reference< container::XHierarchicalNameAccess >();
182 if ( !( (*it).second.xRootReadAccess.is() ) )
184 if ( (*it).second.bTriedToGetRootReadAccess )
186 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
187 "Unable to read any config data! -> #82494#" );
188 return uno::Reference< container::XHierarchicalNameAccess >();
193 uno::Reference< lang::XMultiServiceFactory > xConfigProv
194 = getConfigProvider( rServiceSpecifier );
196 if ( xConfigProv.is() )
198 beans::PropertyValue aProperty;
199 aProperty.Name = "nodepath" ;
200 aProperty.Value <<= OUString(); // root path
201 uno::Sequence< uno::Any > aArguments{ uno::Any(aProperty) };
203 (*it).second.bTriedToGetRootReadAccess = true;
205 (*it).second.xRootReadAccess.set(
206 xConfigProv->createInstanceWithArguments(
207 u"com.sun.star.ucb.HierarchyDataReadAccess"_ustr,
208 aArguments ),
209 uno::UNO_QUERY );
212 catch ( uno::RuntimeException const & )
214 throw;
216 catch ( uno::Exception const & )
218 // createInstance, createInstanceWithArguments
220 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
221 "caught Exception!" );
225 return (*it).second.xRootReadAccess;
228 uno::Reference< util::XOfficeInstallationDirectories >
229 HierarchyContentProvider::getOfficeInstallationDirectories()
231 if ( !m_xOfficeInstDirs.is() )
233 osl::MutexGuard aGuard( m_aMutex );
234 if ( !m_xOfficeInstDirs.is() )
236 OSL_ENSURE( m_xContext.is(), "No service manager!" );
238 m_xOfficeInstDirs = util::theOfficeInstallationDirectories::get(m_xContext);
241 return m_xOfficeInstDirs;
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */