Line data Source code
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/util/theOfficeInstallationDirectories.hpp>
32 : #include <comphelper/processfactory.hxx>
33 : #include <ucbhelper/contentidentifier.hxx>
34 : #include "hierarchyprovider.hxx"
35 : #include "hierarchycontent.hxx"
36 : #include "hierarchyuri.hxx"
37 :
38 : #include "../inc/urihelper.hxx"
39 :
40 : using namespace com::sun::star;
41 : using namespace hierarchy_ucp;
42 :
43 : //=========================================================================
44 : //=========================================================================
45 : //
46 : // HierarchyContentProvider Implementation.
47 : //
48 : //=========================================================================
49 : //=========================================================================
50 :
51 3 : HierarchyContentProvider::HierarchyContentProvider(
52 : const uno::Reference< uno::XComponentContext >& rxContext )
53 3 : : ::ucbhelper::ContentProviderImplHelper( rxContext )
54 : {
55 3 : }
56 :
57 : //=========================================================================
58 : // virtual
59 6 : HierarchyContentProvider::~HierarchyContentProvider()
60 : {
61 6 : }
62 :
63 : //=========================================================================
64 : //
65 : // XInterface methods.
66 : //
67 : //=========================================================================
68 :
69 4346 : XINTERFACE_IMPL_4( HierarchyContentProvider,
70 : lang::XTypeProvider,
71 : lang::XServiceInfo,
72 : ucb::XContentProvider,
73 : lang::XInitialization );
74 :
75 : //=========================================================================
76 : //
77 : // XTypeProvider methods.
78 : //
79 : //=========================================================================
80 :
81 0 : XTYPEPROVIDER_IMPL_4( HierarchyContentProvider,
82 : lang::XTypeProvider,
83 : lang::XServiceInfo,
84 : ucb::XContentProvider,
85 : lang::XInitialization );
86 :
87 : //=========================================================================
88 : //
89 : // XServiceInfo methods.
90 : //
91 : //=========================================================================
92 :
93 17 : XSERVICEINFO_IMPL_1_CTX( HierarchyContentProvider,
94 : OUString( "com.sun.star.comp.ucb.HierarchyContentProvider" ),
95 : OUString( HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME ) );
96 :
97 : //=========================================================================
98 : //
99 : // Service factory implementation.
100 : //
101 : //=========================================================================
102 :
103 3 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyContentProvider );
104 :
105 : //=========================================================================
106 : //
107 : // XContentProvider methods.
108 : //
109 : //=========================================================================
110 :
111 : // virtual
112 : uno::Reference< ucb::XContent > SAL_CALL
113 52 : HierarchyContentProvider::queryContent(
114 : const uno::Reference< ucb::XContentIdentifier >& Identifier )
115 : throw( ucb::IllegalIdentifierException, uno::RuntimeException )
116 : {
117 52 : HierarchyUri aUri( Identifier->getContentIdentifier() );
118 52 : if ( !aUri.isValid() )
119 0 : throw ucb::IllegalIdentifierException();
120 :
121 : // Encode URL and create new Id. This may "correct" user-typed-in URL's.
122 : uno::Reference< ucb::XContentIdentifier > xCanonicId
123 104 : = new ::ucbhelper::ContentIdentifier( ::ucb_impl::urihelper::encodeURI( aUri.getUri() ) );
124 104 : osl::MutexGuard aGuard( m_aMutex );
125 :
126 : // Check, if a content with given id already exists...
127 : uno::Reference< ucb::XContent > xContent
128 52 : = queryExistingContent( xCanonicId ).get();
129 52 : if ( xContent.is() )
130 12 : return xContent;
131 :
132 : // Create a new content.
133 40 : xContent = HierarchyContent::create( m_xContext, this, xCanonicId );
134 40 : registerNewContent( xContent );
135 :
136 40 : if ( xContent.is() && !xContent->getIdentifier().is() )
137 0 : throw ucb::IllegalIdentifierException();
138 :
139 92 : return xContent;
140 : }
141 :
142 : //=========================================================================
143 : //
144 : // XInitialization methods.
145 : //
146 : //=========================================================================
147 :
148 : // virtual
149 0 : void SAL_CALL HierarchyContentProvider::initialize(
150 : const uno::Sequence< uno::Any >& aArguments )
151 : throw( uno::Exception, uno::RuntimeException )
152 : {
153 0 : if ( aArguments.getLength() > 0 )
154 : OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" );
155 0 : }
156 :
157 : //=========================================================================
158 : //
159 : // Non-interface methods.
160 : //
161 : //=========================================================================
162 :
163 : uno::Reference< lang::XMultiServiceFactory >
164 116 : HierarchyContentProvider::getConfigProvider(
165 : const OUString & rServiceSpecifier )
166 : {
167 116 : osl::MutexGuard aGuard( m_aMutex );
168 : ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
169 116 : rServiceSpecifier );
170 116 : if ( it == m_aConfigProviderMap.end() )
171 : {
172 : try
173 : {
174 2 : ConfigProviderMapEntry aEntry;
175 : aEntry.xConfigProvider
176 4 : = uno::Reference< lang::XMultiServiceFactory >(
177 4 : m_xContext->getServiceManager()->createInstanceWithContext(rServiceSpecifier, m_xContext),
178 2 : uno::UNO_QUERY );
179 :
180 2 : if ( aEntry.xConfigProvider.is() )
181 : {
182 2 : m_aConfigProviderMap[ rServiceSpecifier ] = aEntry;
183 2 : return aEntry.xConfigProvider;
184 0 : }
185 : }
186 0 : catch ( uno::Exception const & )
187 : {
188 : // OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - "
189 : // "caught exception!" );
190 : }
191 :
192 : OSL_FAIL( "HierarchyContentProvider::getConfigProvider - "
193 : "No config provider!" );
194 :
195 0 : return uno::Reference< lang::XMultiServiceFactory >();
196 : }
197 :
198 114 : return (*it).second.xConfigProvider;
199 : }
200 :
201 : //=========================================================================
202 : uno::Reference< container::XHierarchicalNameAccess >
203 88 : HierarchyContentProvider::getRootConfigReadNameAccess(
204 : const OUString & rServiceSpecifier )
205 : {
206 88 : osl::MutexGuard aGuard( m_aMutex );
207 : ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
208 88 : rServiceSpecifier );
209 88 : if ( it != m_aConfigProviderMap.end() )
210 : {
211 88 : if ( !( (*it).second.xRootReadAccess.is() ) )
212 : {
213 2 : if ( (*it).second.bTriedToGetRootReadAccess ) // #82494#
214 : {
215 : OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
216 : "Unable to read any config data! -> #82494#" );
217 0 : return uno::Reference< container::XHierarchicalNameAccess >();
218 : }
219 :
220 : try
221 : {
222 : uno::Reference< lang::XMultiServiceFactory > xConfigProv
223 2 : = getConfigProvider( rServiceSpecifier );
224 :
225 2 : if ( xConfigProv.is() )
226 : {
227 2 : uno::Sequence< uno::Any > aArguments( 1 );
228 4 : beans::PropertyValue aProperty;
229 2 : aProperty.Name = OUString( "nodepath" );
230 2 : aProperty.Value <<= OUString(); // root path
231 2 : aArguments[ 0 ] <<= aProperty;
232 :
233 2 : (*it).second.bTriedToGetRootReadAccess = true;
234 :
235 2 : (*it).second.xRootReadAccess
236 6 : = uno::Reference< container::XHierarchicalNameAccess >(
237 2 : xConfigProv->createInstanceWithArguments(
238 : OUString( "com.sun.star.ucb.HierarchyDataReadAccess" ),
239 2 : aArguments ),
240 4 : uno::UNO_QUERY );
241 2 : }
242 : }
243 0 : catch ( uno::RuntimeException const & )
244 : {
245 0 : throw;
246 : }
247 0 : catch ( uno::Exception const & )
248 : {
249 : // createInstance, createInstanceWithArguments
250 :
251 : OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
252 : "caught Exception!" );
253 : }
254 : }
255 : }
256 :
257 88 : return (*it).second.xRootReadAccess;
258 : }
259 :
260 : //=========================================================================
261 : uno::Reference< util::XOfficeInstallationDirectories >
262 88 : HierarchyContentProvider::getOfficeInstallationDirectories()
263 : {
264 88 : if ( !m_xOfficeInstDirs.is() )
265 : {
266 2 : osl::MutexGuard aGuard( m_aMutex );
267 2 : if ( !m_xOfficeInstDirs.is() )
268 : {
269 : OSL_ENSURE( m_xContext.is(), "No service manager!" );
270 :
271 2 : m_xOfficeInstDirs = util::theOfficeInstallationDirectories::get(m_xContext);
272 2 : }
273 : }
274 88 : return m_xOfficeInstDirs;
275 : }
276 :
277 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|