LibreOffice Module ucb (master) 1
hierarchyprovider.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21/**************************************************************************
22 TODO
23 **************************************************************************
24
25 - XInitialization::initialize does not work any longer!
26
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>
34#include <cppuhelper/weak.hxx>
36#include <ucbhelper/macros.hxx>
37#include "hierarchyprovider.hxx"
38#include "hierarchycontent.hxx"
39#include "hierarchyuri.hxx"
40
41#include "../inc/urihelper.hxx"
42
43using namespace com::sun::star;
44using namespace hierarchy_ucp;
45
46
47// HierarchyContentProvider Implementation.
48
49
50HierarchyContentProvider::HierarchyContentProvider(
51 const uno::Reference< uno::XComponentContext >& rxContext )
53{
54}
55
56
57// virtual
59{
60}
61
62// XServiceInfo methods.
63
65{
66 return "com.sun.star.comp.ucb.HierarchyContentProvider";
67}
68sal_Bool SAL_CALL HierarchyContentProvider::supportsService( const OUString& ServiceName )
69{
70 return cppu::supportsService( this, ServiceName );
71}
73{
74 return { "com.sun.star.ucb.HierarchyContentProvider" };
75}
76
77// Service factory implementation.
78
79extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
81 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
82{
83 return cppu::acquire(new HierarchyContentProvider(context));
84}
85
86// XContentProvider methods.
87
88
89// virtual
90uno::Reference< ucb::XContent > SAL_CALL
92 const uno::Reference< ucb::XContentIdentifier >& Identifier )
93{
94 HierarchyUri aUri( Identifier->getContentIdentifier() );
95 if ( !aUri.isValid() )
96 throw ucb::IllegalIdentifierException();
97
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 );
102
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;
108
109 // Create a new content.
110 xContent = HierarchyContent::create( m_xContext, this, xCanonicId );
111 registerNewContent( xContent );
112
113 if ( xContent.is() && !xContent->getIdentifier().is() )
114 throw ucb::IllegalIdentifierException();
115
116 return xContent;
117}
118
119
120// XInitialization methods.
121
122
123// virtual
125 const uno::Sequence< uno::Any >& aArguments )
126{
127 if ( aArguments.hasElements() )
128 OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" );
129}
130
131
132// Non-interface methods.
133
134
135uno::Reference< lang::XMultiServiceFactory >
137 const OUString & rServiceSpecifier )
138{
139 osl::MutexGuard aGuard( m_aMutex );
140 ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
141 rServiceSpecifier );
142 if ( it == m_aConfigProviderMap.end() )
143 {
144 try
145 {
147 aEntry.xConfigProvider.set(
148 m_xContext->getServiceManager()->createInstanceWithContext(rServiceSpecifier, m_xContext),
149 uno::UNO_QUERY );
150
151 if ( aEntry.xConfigProvider.is() )
152 {
153 m_aConfigProviderMap[ rServiceSpecifier ] = aEntry;
154 return aEntry.xConfigProvider;
155 }
156 }
157 catch ( uno::Exception const & )
158 {
159// OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - "
160// "caught exception!" );
161 }
162
163 OSL_FAIL( "HierarchyContentProvider::getConfigProvider - "
164 "No config provider!" );
165
166 return uno::Reference< lang::XMultiServiceFactory >();
167 }
168
169 return (*it).second.xConfigProvider;
170}
171
172uno::Reference< container::XHierarchicalNameAccess >
174 const OUString & rServiceSpecifier )
175{
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 >();
181
182 if ( !( (*it).second.xRootReadAccess.is() ) )
183 {
184 if ( (*it).second.bTriedToGetRootReadAccess )
185 {
186 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
187 "Unable to read any config data! -> #82494#" );
188 return uno::Reference< container::XHierarchicalNameAccess >();
189 }
190
191 try
192 {
193 uno::Reference< lang::XMultiServiceFactory > xConfigProv
194 = getConfigProvider( rServiceSpecifier );
195
196 if ( xConfigProv.is() )
197 {
198 beans::PropertyValue aProperty;
199 aProperty.Name = "nodepath" ;
200 aProperty.Value <<= OUString(); // root path
201 uno::Sequence< uno::Any > aArguments{ uno::Any(aProperty) };
202
203 (*it).second.bTriedToGetRootReadAccess = true;
204
205 (*it).second.xRootReadAccess.set(
206 xConfigProv->createInstanceWithArguments(
207 "com.sun.star.ucb.HierarchyDataReadAccess",
208 aArguments ),
209 uno::UNO_QUERY );
210 }
211 }
212 catch ( uno::RuntimeException const & )
213 {
214 throw;
215 }
216 catch ( uno::Exception const & )
217 {
218 // createInstance, createInstanceWithArguments
219
220 OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
221 "caught Exception!" );
222 }
223 }
224
225 return (*it).second.xRootReadAccess;
226}
227
228uno::Reference< util::XOfficeInstallationDirectories >
230{
231 if ( !m_xOfficeInstDirs.is() )
232 {
233 osl::MutexGuard aGuard( m_aMutex );
234 if ( !m_xOfficeInstDirs.is() )
235 {
236 OSL_ENSURE( m_xContext.is(), "No service manager!" );
237
238 m_xOfficeInstDirs = util::theOfficeInstallationDirectories::get(m_xContext);
239 }
240 }
241 return m_xOfficeInstDirs;
242}
243
244/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
css::uno::Reference< css::lang::XMultiServiceFactory > getConfigProvider(const OUString &rServiceSpecifier)
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
css::uno::Reference< css::util::XOfficeInstallationDirectories > m_xOfficeInstDirs
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::container::XHierarchicalNameAccess > getRootConfigReadNameAccess(const OUString &rServiceSpecifier)
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::util::XOfficeInstallationDirectories > getOfficeInstallationDirectories()
static rtl::Reference< HierarchyContent > create(const css::uno::Reference< css::uno::XComponentContext > &rxContext, HierarchyContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
const OUString & getUri() const
std::mutex m_aMutex
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_HierarchyContentProvider_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Sequence< PropertyValue > aArguments
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
cppu::ImplInheritanceHelper< ::ucbhelper::ContentProviderImplHelper, css::lang::XInitialization > HierarchyContentProvider_Base
OUString encodeURI(const OUString &rURI)
Definition: urihelper.hxx:44
css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider
unsigned char sal_Bool