Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / ucb / source / ucp / hierarchy / hierarchyprovider.cxx
blob0fc6ec64c89a392aad128bc2c0762f416e3b4d18
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/XOfficeInstallationDirectories.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;
43 //=========================================================================
44 //=========================================================================
46 // HierarchyContentProvider Implementation.
48 //=========================================================================
49 //=========================================================================
51 HierarchyContentProvider::HierarchyContentProvider(
52 const uno::Reference< uno::XComponentContext >& rxContext )
53 : ::ucbhelper::ContentProviderImplHelper( rxContext )
57 //=========================================================================
58 // virtual
59 HierarchyContentProvider::~HierarchyContentProvider()
63 //=========================================================================
65 // XInterface methods.
67 //=========================================================================
69 XINTERFACE_IMPL_4( HierarchyContentProvider,
70 lang::XTypeProvider,
71 lang::XServiceInfo,
72 ucb::XContentProvider,
73 lang::XInitialization );
75 //=========================================================================
77 // XTypeProvider methods.
79 //=========================================================================
81 XTYPEPROVIDER_IMPL_4( HierarchyContentProvider,
82 lang::XTypeProvider,
83 lang::XServiceInfo,
84 ucb::XContentProvider,
85 lang::XInitialization );
87 //=========================================================================
89 // XServiceInfo methods.
91 //=========================================================================
93 XSERVICEINFO_IMPL_1_CTX( HierarchyContentProvider,
94 rtl::OUString( "com.sun.star.comp.ucb.HierarchyContentProvider" ),
95 rtl::OUString( HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME ) );
97 //=========================================================================
99 // Service factory implementation.
101 //=========================================================================
103 ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyContentProvider );
105 //=========================================================================
107 // XContentProvider methods.
109 //=========================================================================
111 // virtual
112 uno::Reference< ucb::XContent > SAL_CALL
113 HierarchyContentProvider::queryContent(
114 const uno::Reference< ucb::XContentIdentifier >& Identifier )
115 throw( ucb::IllegalIdentifierException, uno::RuntimeException )
117 HierarchyUri aUri( Identifier->getContentIdentifier() );
118 if ( !aUri.isValid() )
119 throw ucb::IllegalIdentifierException();
121 // Encode URL and create new Id. This may "correct" user-typed-in URL's.
122 uno::Reference< ucb::XContentIdentifier > xCanonicId
123 = new ::ucbhelper::ContentIdentifier( ::ucb_impl::urihelper::encodeURI( aUri.getUri() ) );
124 osl::MutexGuard aGuard( m_aMutex );
126 // Check, if a content with given id already exists...
127 uno::Reference< ucb::XContent > xContent
128 = queryExistingContent( xCanonicId ).get();
129 if ( xContent.is() )
130 return xContent;
132 // Create a new content.
133 xContent = HierarchyContent::create( m_xContext, this, xCanonicId );
134 registerNewContent( xContent );
136 if ( xContent.is() && !xContent->getIdentifier().is() )
137 throw ucb::IllegalIdentifierException();
139 return xContent;
142 //=========================================================================
144 // XInitialization methods.
146 //=========================================================================
148 // virtual
149 void SAL_CALL HierarchyContentProvider::initialize(
150 const uno::Sequence< uno::Any >& aArguments )
151 throw( uno::Exception, uno::RuntimeException )
153 if ( aArguments.getLength() > 0 )
154 OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" );
157 //=========================================================================
159 // Non-interface methods.
161 //=========================================================================
163 uno::Reference< lang::XMultiServiceFactory >
164 HierarchyContentProvider::getConfigProvider(
165 const rtl::OUString & rServiceSpecifier )
167 osl::MutexGuard aGuard( m_aMutex );
168 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
169 rServiceSpecifier );
170 if ( it == m_aConfigProviderMap.end() )
174 ConfigProviderMapEntry aEntry;
175 aEntry.xConfigProvider
176 = uno::Reference< lang::XMultiServiceFactory >(
177 m_xContext->getServiceManager()->createInstanceWithContext(rServiceSpecifier, m_xContext),
178 uno::UNO_QUERY );
180 if ( aEntry.xConfigProvider.is() )
182 m_aConfigProviderMap[ rServiceSpecifier ] = aEntry;
183 return aEntry.xConfigProvider;
186 catch ( uno::Exception const & )
188 // OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - "
189 // "caught exception!" );
192 OSL_FAIL( "HierarchyContentProvider::getConfigProvider - "
193 "No config provider!" );
195 return uno::Reference< lang::XMultiServiceFactory >();
198 return (*it).second.xConfigProvider;
201 //=========================================================================
202 uno::Reference< container::XHierarchicalNameAccess >
203 HierarchyContentProvider::getRootConfigReadNameAccess(
204 const rtl::OUString & rServiceSpecifier )
206 osl::MutexGuard aGuard( m_aMutex );
207 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
208 rServiceSpecifier );
209 if ( it != m_aConfigProviderMap.end() )
211 if ( !( (*it).second.xRootReadAccess.is() ) )
213 if ( (*it).second.bTriedToGetRootReadAccess ) // #82494#
215 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
216 "Unable to read any config data! -> #82494#" );
217 return uno::Reference< container::XHierarchicalNameAccess >();
222 uno::Reference< lang::XMultiServiceFactory > xConfigProv
223 = getConfigProvider( rServiceSpecifier );
225 if ( xConfigProv.is() )
227 uno::Sequence< uno::Any > aArguments( 1 );
228 beans::PropertyValue aProperty;
229 aProperty.Name = rtl::OUString( "nodepath" );
230 aProperty.Value <<= rtl::OUString(); // root path
231 aArguments[ 0 ] <<= aProperty;
233 (*it).second.bTriedToGetRootReadAccess = true;
235 (*it).second.xRootReadAccess
236 = uno::Reference< container::XHierarchicalNameAccess >(
237 xConfigProv->createInstanceWithArguments(
238 rtl::OUString( "com.sun.star.ucb.HierarchyDataReadAccess" ),
239 aArguments ),
240 uno::UNO_QUERY );
243 catch ( uno::RuntimeException const & )
245 throw;
247 catch ( uno::Exception const & )
249 // createInstance, createInstanceWithArguments
251 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
252 "caught Exception!" );
257 return (*it).second.xRootReadAccess;
260 //=========================================================================
261 uno::Reference< util::XOfficeInstallationDirectories >
262 HierarchyContentProvider::getOfficeInstallationDirectories()
264 if ( !m_xOfficeInstDirs.is() )
266 osl::MutexGuard aGuard( m_aMutex );
267 if ( !m_xOfficeInstDirs.is() )
269 OSL_ENSURE( m_xContext.is(), "No service manager!" );
271 m_xContext->getValueByName(
272 rtl::OUString( "/singletons/com.sun.star.util.theOfficeInstallationDirectories" ) )
273 >>= m_xOfficeInstDirs;
275 // Be silent. singleton only available in an Office environment.
276 // OSL_ENSURE( m_xOfficeInstDirs.is(),
277 // "Unable to obtain office directories singleton!" );
280 return m_xOfficeInstDirs;
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */