update dev300-m58
[ooovba.git] / ucb / source / ucp / hierarchy / hierarchyprovider.cxx
blobcef8e4759eaed16908a4ff2d6cdf540b600537b2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hierarchyprovider.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 /**************************************************************************
35 TODO
36 **************************************************************************
38 - XInitialization::initialize does not work any longer!
40 *************************************************************************/
41 #include <osl/diagnose.h>
42 #include <com/sun/star/beans/PropertyValue.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
45 #include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
46 #include <ucbhelper/contentidentifier.hxx>
47 #include "hierarchyprovider.hxx"
48 #include "hierarchycontent.hxx"
49 #include "hierarchyuri.hxx"
51 #include "../inc/urihelper.hxx"
53 using namespace com::sun::star;
54 using namespace hierarchy_ucp;
56 //=========================================================================
57 //=========================================================================
59 // HierarchyContentProvider Implementation.
61 //=========================================================================
62 //=========================================================================
64 HierarchyContentProvider::HierarchyContentProvider(
65 const uno::Reference< lang::XMultiServiceFactory >& rXSMgr )
66 : ::ucbhelper::ContentProviderImplHelper( rXSMgr )
70 //=========================================================================
71 // virtual
72 HierarchyContentProvider::~HierarchyContentProvider()
76 //=========================================================================
78 // XInterface methods.
80 //=========================================================================
82 XINTERFACE_IMPL_4( HierarchyContentProvider,
83 lang::XTypeProvider,
84 lang::XServiceInfo,
85 ucb::XContentProvider,
86 lang::XInitialization );
88 //=========================================================================
90 // XTypeProvider methods.
92 //=========================================================================
94 XTYPEPROVIDER_IMPL_4( HierarchyContentProvider,
95 lang::XTypeProvider,
96 lang::XServiceInfo,
97 ucb::XContentProvider,
98 lang::XInitialization );
100 //=========================================================================
102 // XServiceInfo methods.
104 //=========================================================================
106 XSERVICEINFO_IMPL_1( HierarchyContentProvider,
107 rtl::OUString::createFromAscii(
108 "com.sun.star.comp.ucb.HierarchyContentProvider" ),
109 rtl::OUString::createFromAscii(
110 HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME ) );
112 //=========================================================================
114 // Service factory implementation.
116 //=========================================================================
118 ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyContentProvider );
120 //=========================================================================
122 // XContentProvider methods.
124 //=========================================================================
126 // virtual
127 uno::Reference< ucb::XContent > SAL_CALL
128 HierarchyContentProvider::queryContent(
129 const uno::Reference< ucb::XContentIdentifier >& Identifier )
130 throw( ucb::IllegalIdentifierException, uno::RuntimeException )
132 HierarchyUri aUri( Identifier->getContentIdentifier() );
133 if ( !aUri.isValid() )
134 throw ucb::IllegalIdentifierException();
136 // Encode URL and create new Id. This may "correct" user-typed-in URL's.
137 uno::Reference< ucb::XContentIdentifier > xCanonicId
138 = new ::ucbhelper::ContentIdentifier( m_xSMgr,
139 ::ucb_impl::urihelper::encodeURI(
140 aUri.getUri() ) );
141 osl::MutexGuard aGuard( m_aMutex );
143 // Check, if a content with given id already exists...
144 uno::Reference< ucb::XContent > xContent
145 = queryExistingContent( xCanonicId ).get();
146 if ( xContent.is() )
147 return xContent;
149 // Create a new content.
150 xContent = HierarchyContent::create( m_xSMgr, this, xCanonicId );
151 registerNewContent( xContent );
153 if ( xContent.is() && !xContent->getIdentifier().is() )
154 throw ucb::IllegalIdentifierException();
156 return xContent;
159 //=========================================================================
161 // XInitialization methods.
163 //=========================================================================
165 // virtual
166 void SAL_CALL HierarchyContentProvider::initialize(
167 const uno::Sequence< uno::Any >& aArguments )
168 throw( uno::Exception, uno::RuntimeException )
170 #if 0
171 if ( aArguments.getLength() > 0 )
173 // Extract config provider from service init args.
174 aArguments[ 0 ] >>= m_xConfigProvider;
176 OSL_ENSURE( m_xConfigProvider.is(),
177 "HierarchyContentProvider::initialize - "
178 "No config provider!" );
180 #else
181 if ( aArguments.getLength() > 0 )
182 OSL_ENSURE( false,
183 "HierarchyContentProvider::initialize : not supported!" );
184 #endif
187 //=========================================================================
189 // Non-interface methods.
191 //=========================================================================
193 uno::Reference< lang::XMultiServiceFactory >
194 HierarchyContentProvider::getConfigProvider(
195 const rtl::OUString & rServiceSpecifier )
197 osl::MutexGuard aGuard( m_aMutex );
198 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
199 rServiceSpecifier );
200 if ( it == m_aConfigProviderMap.end() )
204 ConfigProviderMapEntry aEntry;
205 aEntry.xConfigProvider
206 = uno::Reference< lang::XMultiServiceFactory >(
207 m_xSMgr->createInstance( rServiceSpecifier ),
208 uno::UNO_QUERY );
210 if ( aEntry.xConfigProvider.is() )
212 m_aConfigProviderMap[ rServiceSpecifier ] = aEntry;
213 return aEntry.xConfigProvider;
216 catch ( uno::Exception const & )
218 // OSL_ENSURE( sal_False,
219 // "HierarchyContentProvider::getConfigProvider - "
220 // "caught exception!" );
223 OSL_ENSURE( sal_False,
224 "HierarchyContentProvider::getConfigProvider - "
225 "No config provider!" );
227 return uno::Reference< lang::XMultiServiceFactory >();
230 return (*it).second.xConfigProvider;
233 //=========================================================================
234 uno::Reference< container::XHierarchicalNameAccess >
235 HierarchyContentProvider::getRootConfigReadNameAccess(
236 const rtl::OUString & rServiceSpecifier )
238 osl::MutexGuard aGuard( m_aMutex );
239 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
240 rServiceSpecifier );
241 if ( it != m_aConfigProviderMap.end() )
243 if ( !( (*it).second.xRootReadAccess.is() ) )
245 if ( (*it).second.bTriedToGetRootReadAccess ) // #82494#
247 OSL_ENSURE( sal_False,
248 "HierarchyContentProvider::getRootConfigReadNameAccess - "
249 "Unable to read any config data! -> #82494#" );
250 return uno::Reference< container::XHierarchicalNameAccess >();
255 uno::Reference< lang::XMultiServiceFactory > xConfigProv
256 = getConfigProvider( rServiceSpecifier );
258 if ( xConfigProv.is() )
260 uno::Sequence< uno::Any > aArguments( 1 );
261 beans::PropertyValue aProperty;
262 aProperty.Name
263 = rtl::OUString(
264 RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) );
265 aProperty.Value <<= rtl::OUString(); // root path
266 aArguments[ 0 ] <<= aProperty;
268 (*it).second.bTriedToGetRootReadAccess = true;
270 (*it).second.xRootReadAccess
271 = uno::Reference< container::XHierarchicalNameAccess >(
272 xConfigProv->createInstanceWithArguments(
273 rtl::OUString(
274 RTL_CONSTASCII_USTRINGPARAM(
275 "com.sun.star.ucb."
276 "HierarchyDataReadAccess" ) ),
277 aArguments ),
278 uno::UNO_QUERY );
281 catch ( uno::RuntimeException const & )
283 throw;
285 catch ( uno::Exception const & )
287 // createInstance, createInstanceWithArguments
289 OSL_ENSURE( sal_False,
290 "HierarchyContentProvider::getRootConfigReadNameAccess - "
291 "caught Exception!" );
296 return (*it).second.xRootReadAccess;
299 //=========================================================================
300 uno::Reference< util::XOfficeInstallationDirectories >
301 HierarchyContentProvider::getOfficeInstallationDirectories()
303 if ( !m_xOfficeInstDirs.is() )
305 osl::MutexGuard aGuard( m_aMutex );
306 if ( !m_xOfficeInstDirs.is() )
308 OSL_ENSURE( m_xSMgr.is(), "No service manager!" );
310 uno::Reference< uno::XComponentContext > xCtx;
311 uno::Reference< beans::XPropertySet > xPropSet(
312 m_xSMgr, uno::UNO_QUERY );
313 if ( xPropSet.is() )
315 xPropSet->getPropertyValue(
316 rtl::OUString(
317 RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) )
318 >>= xCtx;
321 OSL_ENSURE( xCtx.is(),
322 "Unable to obtain component context from "
323 "service manager!" );
325 if ( xCtx.is() )
327 xCtx->getValueByName(
328 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
329 "/singletons/"
330 "com.sun.star.util.theOfficeInstallationDirectories" ) ) )
331 >>= m_xOfficeInstDirs;
333 // Be silent. singleton only available in an Office environment.
334 // OSL_ENSURE( m_xOfficeInstDirs.is(),
335 // "Unable to obtain office directories singleton!" );
339 return m_xOfficeInstDirs;