1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 /**************************************************************************
32 **************************************************************************
34 - XInitialization::initialize does not work any longer!
36 *************************************************************************/
37 #include <osl/diagnose.h>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
41 #include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
42 #include <ucbhelper/contentidentifier.hxx>
43 #include "hierarchyprovider.hxx"
44 #include "hierarchycontent.hxx"
45 #include "hierarchyuri.hxx"
47 #include "../inc/urihelper.hxx"
49 using namespace com::sun::star
;
50 using namespace hierarchy_ucp
;
52 //=========================================================================
53 //=========================================================================
55 // HierarchyContentProvider Implementation.
57 //=========================================================================
58 //=========================================================================
60 HierarchyContentProvider::HierarchyContentProvider(
61 const uno::Reference
< lang::XMultiServiceFactory
>& rXSMgr
)
62 : ::ucbhelper::ContentProviderImplHelper( rXSMgr
)
66 //=========================================================================
68 HierarchyContentProvider::~HierarchyContentProvider()
72 //=========================================================================
74 // XInterface methods.
76 //=========================================================================
78 XINTERFACE_IMPL_4( HierarchyContentProvider
,
81 ucb::XContentProvider
,
82 lang::XInitialization
);
84 //=========================================================================
86 // XTypeProvider methods.
88 //=========================================================================
90 XTYPEPROVIDER_IMPL_4( HierarchyContentProvider
,
93 ucb::XContentProvider
,
94 lang::XInitialization
);
96 //=========================================================================
98 // XServiceInfo methods.
100 //=========================================================================
102 XSERVICEINFO_IMPL_1( HierarchyContentProvider
,
103 rtl::OUString( "com.sun.star.comp.ucb.HierarchyContentProvider" ),
104 rtl::OUString( HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME
) );
106 //=========================================================================
108 // Service factory implementation.
110 //=========================================================================
112 ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyContentProvider
);
114 //=========================================================================
116 // XContentProvider methods.
118 //=========================================================================
121 uno::Reference
< ucb::XContent
> SAL_CALL
122 HierarchyContentProvider::queryContent(
123 const uno::Reference
< ucb::XContentIdentifier
>& Identifier
)
124 throw( ucb::IllegalIdentifierException
, uno::RuntimeException
)
126 HierarchyUri
aUri( Identifier
->getContentIdentifier() );
127 if ( !aUri
.isValid() )
128 throw ucb::IllegalIdentifierException();
130 // Encode URL and create new Id. This may "correct" user-typed-in URL's.
131 uno::Reference
< ucb::XContentIdentifier
> xCanonicId
132 = new ::ucbhelper::ContentIdentifier( m_xSMgr
,
133 ::ucb_impl::urihelper::encodeURI(
135 osl::MutexGuard
aGuard( m_aMutex
);
137 // Check, if a content with given id already exists...
138 uno::Reference
< ucb::XContent
> xContent
139 = queryExistingContent( xCanonicId
).get();
143 // Create a new content.
144 xContent
= HierarchyContent::create( m_xSMgr
, this, xCanonicId
);
145 registerNewContent( xContent
);
147 if ( xContent
.is() && !xContent
->getIdentifier().is() )
148 throw ucb::IllegalIdentifierException();
153 //=========================================================================
155 // XInitialization methods.
157 //=========================================================================
160 void SAL_CALL
HierarchyContentProvider::initialize(
161 const uno::Sequence
< uno::Any
>& aArguments
)
162 throw( uno::Exception
, uno::RuntimeException
)
164 if ( aArguments
.getLength() > 0 )
165 OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" );
168 //=========================================================================
170 // Non-interface methods.
172 //=========================================================================
174 uno::Reference
< lang::XMultiServiceFactory
>
175 HierarchyContentProvider::getConfigProvider(
176 const rtl::OUString
& rServiceSpecifier
)
178 osl::MutexGuard
aGuard( m_aMutex
);
179 ConfigProviderMap::iterator it
= m_aConfigProviderMap
.find(
181 if ( it
== m_aConfigProviderMap
.end() )
185 ConfigProviderMapEntry aEntry
;
186 aEntry
.xConfigProvider
187 = uno::Reference
< lang::XMultiServiceFactory
>(
188 m_xSMgr
->createInstance( rServiceSpecifier
),
191 if ( aEntry
.xConfigProvider
.is() )
193 m_aConfigProviderMap
[ rServiceSpecifier
] = aEntry
;
194 return aEntry
.xConfigProvider
;
197 catch ( uno::Exception
const & )
199 // OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - "
200 // "caught exception!" );
203 OSL_FAIL( "HierarchyContentProvider::getConfigProvider - "
204 "No config provider!" );
206 return uno::Reference
< lang::XMultiServiceFactory
>();
209 return (*it
).second
.xConfigProvider
;
212 //=========================================================================
213 uno::Reference
< container::XHierarchicalNameAccess
>
214 HierarchyContentProvider::getRootConfigReadNameAccess(
215 const rtl::OUString
& rServiceSpecifier
)
217 osl::MutexGuard
aGuard( m_aMutex
);
218 ConfigProviderMap::iterator it
= m_aConfigProviderMap
.find(
220 if ( it
!= m_aConfigProviderMap
.end() )
222 if ( !( (*it
).second
.xRootReadAccess
.is() ) )
224 if ( (*it
).second
.bTriedToGetRootReadAccess
) // #82494#
226 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
227 "Unable to read any config data! -> #82494#" );
228 return uno::Reference
< container::XHierarchicalNameAccess
>();
233 uno::Reference
< lang::XMultiServiceFactory
> xConfigProv
234 = getConfigProvider( rServiceSpecifier
);
236 if ( xConfigProv
.is() )
238 uno::Sequence
< uno::Any
> aArguments( 1 );
239 beans::PropertyValue aProperty
;
240 aProperty
.Name
= rtl::OUString( "nodepath" );
241 aProperty
.Value
<<= rtl::OUString(); // root path
242 aArguments
[ 0 ] <<= aProperty
;
244 (*it
).second
.bTriedToGetRootReadAccess
= true;
246 (*it
).second
.xRootReadAccess
247 = uno::Reference
< container::XHierarchicalNameAccess
>(
248 xConfigProv
->createInstanceWithArguments(
249 rtl::OUString( "com.sun.star.ucb.HierarchyDataReadAccess" ),
254 catch ( uno::RuntimeException
const & )
258 catch ( uno::Exception
const & )
260 // createInstance, createInstanceWithArguments
262 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
263 "caught Exception!" );
268 return (*it
).second
.xRootReadAccess
;
271 //=========================================================================
272 uno::Reference
< util::XOfficeInstallationDirectories
>
273 HierarchyContentProvider::getOfficeInstallationDirectories()
275 if ( !m_xOfficeInstDirs
.is() )
277 osl::MutexGuard
aGuard( m_aMutex
);
278 if ( !m_xOfficeInstDirs
.is() )
280 OSL_ENSURE( m_xSMgr
.is(), "No service manager!" );
282 uno::Reference
< uno::XComponentContext
> xCtx
;
283 uno::Reference
< beans::XPropertySet
> xPropSet(
284 m_xSMgr
, uno::UNO_QUERY
);
287 xPropSet
->getPropertyValue(
288 rtl::OUString( "DefaultContext" ) )
292 OSL_ENSURE( xCtx
.is(),
293 "Unable to obtain component context from "
294 "service manager!" );
298 xCtx
->getValueByName(
299 rtl::OUString( "/singletons/com.sun.star.util.theOfficeInstallationDirectories" ) )
300 >>= m_xOfficeInstDirs
;
302 // Be silent. singleton only available in an Office environment.
303 // OSL_ENSURE( m_xOfficeInstDirs.is(),
304 // "Unable to obtain office directories singleton!" );
308 return m_xOfficeInstDirs
;
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */