Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : /**************************************************************************
31 : : TODO
32 : : **************************************************************************
33 : :
34 : : - XInitialization::initialize does not work any longer!
35 : :
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"
46 : :
47 : : #include "../inc/urihelper.hxx"
48 : :
49 : : using namespace com::sun::star;
50 : : using namespace hierarchy_ucp;
51 : :
52 : : //=========================================================================
53 : : //=========================================================================
54 : : //
55 : : // HierarchyContentProvider Implementation.
56 : : //
57 : : //=========================================================================
58 : : //=========================================================================
59 : :
60 : 4 : HierarchyContentProvider::HierarchyContentProvider(
61 : : const uno::Reference< lang::XMultiServiceFactory >& rXSMgr )
62 [ + - ]: 4 : : ::ucbhelper::ContentProviderImplHelper( rXSMgr )
63 : : {
64 : 4 : }
65 : :
66 : : //=========================================================================
67 : : // virtual
68 [ + - ]: 4 : HierarchyContentProvider::~HierarchyContentProvider()
69 : : {
70 [ - + ]: 8 : }
71 : :
72 : : //=========================================================================
73 : : //
74 : : // XInterface methods.
75 : : //
76 : : //=========================================================================
77 : :
78 [ + - ][ + + ]: 7426 : XINTERFACE_IMPL_4( HierarchyContentProvider,
[ + - ]
79 : : lang::XTypeProvider,
80 : : lang::XServiceInfo,
81 : : ucb::XContentProvider,
82 : : lang::XInitialization );
83 : :
84 : : //=========================================================================
85 : : //
86 : : // XTypeProvider methods.
87 : : //
88 : : //=========================================================================
89 : :
90 [ # # ][ # # ]: 0 : XTYPEPROVIDER_IMPL_4( HierarchyContentProvider,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
91 : : lang::XTypeProvider,
92 : : lang::XServiceInfo,
93 : : ucb::XContentProvider,
94 : : lang::XInitialization );
95 : :
96 : : //=========================================================================
97 : : //
98 : : // XServiceInfo methods.
99 : : //
100 : : //=========================================================================
101 : :
102 [ + - ][ + - ]: 24 : XSERVICEINFO_IMPL_1( HierarchyContentProvider,
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
103 : : rtl::OUString( "com.sun.star.comp.ucb.HierarchyContentProvider" ),
104 : 4 : rtl::OUString( HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME ) );
105 : :
106 : : //=========================================================================
107 : : //
108 : : // Service factory implementation.
109 : : //
110 : : //=========================================================================
111 : :
112 [ + - ][ + - ]: 4 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyContentProvider );
113 : :
114 : : //=========================================================================
115 : : //
116 : : // XContentProvider methods.
117 : : //
118 : : //=========================================================================
119 : :
120 : : // virtual
121 : : uno::Reference< ucb::XContent > SAL_CALL
122 : 82 : HierarchyContentProvider::queryContent(
123 : : const uno::Reference< ucb::XContentIdentifier >& Identifier )
124 : : throw( ucb::IllegalIdentifierException, uno::RuntimeException )
125 : : {
126 [ + - ][ + - ]: 82 : HierarchyUri aUri( Identifier->getContentIdentifier() );
127 [ - + ][ + - ]: 82 : if ( !aUri.isValid() )
128 [ # # ]: 0 : throw ucb::IllegalIdentifierException();
129 : :
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(
134 [ + - ][ + - ]: 82 : aUri.getUri() ) );
[ + - ][ + - ]
[ + - ]
135 [ + - ]: 82 : osl::MutexGuard aGuard( m_aMutex );
136 : :
137 : : // Check, if a content with given id already exists...
138 : : uno::Reference< ucb::XContent > xContent
139 [ + - ][ + + ]: 82 : = queryExistingContent( xCanonicId ).get();
[ + - ]
140 [ + + ]: 82 : if ( xContent.is() )
141 : : return xContent;
142 : :
143 : : // Create a new content.
144 [ + - ][ + + ]: 54 : xContent = HierarchyContent::create( m_xSMgr, this, xCanonicId );
[ + - ]
145 [ + - ]: 54 : registerNewContent( xContent );
146 : :
147 [ + + ][ + - ]: 54 : if ( xContent.is() && !xContent->getIdentifier().is() )
[ + - ][ - + ]
[ + + ]
[ - + # # ]
148 [ # # ]: 0 : throw ucb::IllegalIdentifierException();
149 : :
150 [ + - ]: 82 : return xContent;
151 : : }
152 : :
153 : : //=========================================================================
154 : : //
155 : : // XInitialization methods.
156 : : //
157 : : //=========================================================================
158 : :
159 : : // virtual
160 : 0 : void SAL_CALL HierarchyContentProvider::initialize(
161 : : const uno::Sequence< uno::Any >& aArguments )
162 : : throw( uno::Exception, uno::RuntimeException )
163 : : {
164 : 0 : if ( aArguments.getLength() > 0 )
165 : : OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" );
166 : 0 : }
167 : :
168 : : //=========================================================================
169 : : //
170 : : // Non-interface methods.
171 : : //
172 : : //=========================================================================
173 : :
174 : : uno::Reference< lang::XMultiServiceFactory >
175 : 160 : HierarchyContentProvider::getConfigProvider(
176 : : const rtl::OUString & rServiceSpecifier )
177 : : {
178 [ + - ]: 160 : osl::MutexGuard aGuard( m_aMutex );
179 : : ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
180 [ + - ]: 160 : rServiceSpecifier );
181 [ + - ][ + + ]: 160 : if ( it == m_aConfigProviderMap.end() )
182 : : {
183 : : try
184 : : {
185 [ + - ]: 2 : ConfigProviderMapEntry aEntry;
186 : : aEntry.xConfigProvider
187 : : = uno::Reference< lang::XMultiServiceFactory >(
188 [ + - ]: 2 : m_xSMgr->createInstance( rServiceSpecifier ),
189 [ + - ][ + - ]: 2 : uno::UNO_QUERY );
[ + - ]
190 : :
191 [ + - ]: 2 : if ( aEntry.xConfigProvider.is() )
192 : : {
193 [ + - ][ + - ]: 2 : m_aConfigProviderMap[ rServiceSpecifier ] = aEntry;
194 : 2 : return aEntry.xConfigProvider;
195 [ + - ][ - + ]: 2 : }
[ # # ]
196 : : }
197 [ # # ]: 0 : catch ( uno::Exception const & )
198 : : {
199 : : // OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - "
200 : : // "caught exception!" );
201 : : }
202 : :
203 : : OSL_FAIL( "HierarchyContentProvider::getConfigProvider - "
204 : : "No config provider!" );
205 : :
206 : 0 : return uno::Reference< lang::XMultiServiceFactory >();
207 : : }
208 : :
209 [ + - ][ + - ]: 160 : return (*it).second.xConfigProvider;
210 : : }
211 : :
212 : : //=========================================================================
213 : : uno::Reference< container::XHierarchicalNameAccess >
214 : 126 : HierarchyContentProvider::getRootConfigReadNameAccess(
215 : : const rtl::OUString & rServiceSpecifier )
216 : : {
217 [ + - ]: 126 : osl::MutexGuard aGuard( m_aMutex );
218 : : ConfigProviderMap::iterator it = m_aConfigProviderMap.find(
219 [ + - ]: 126 : rServiceSpecifier );
220 [ + - ][ + - ]: 126 : if ( it != m_aConfigProviderMap.end() )
221 : : {
222 [ + - ][ + + ]: 126 : if ( !( (*it).second.xRootReadAccess.is() ) )
223 : : {
224 [ + - ][ - + ]: 2 : if ( (*it).second.bTriedToGetRootReadAccess ) // #82494#
225 : : {
226 : : OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
227 : : "Unable to read any config data! -> #82494#" );
228 : 0 : return uno::Reference< container::XHierarchicalNameAccess >();
229 : : }
230 : :
231 : : try
232 : : {
233 : : uno::Reference< lang::XMultiServiceFactory > xConfigProv
234 [ + - ]: 2 : = getConfigProvider( rServiceSpecifier );
235 : :
236 [ + - ]: 2 : if ( xConfigProv.is() )
237 : : {
238 [ + - ]: 2 : uno::Sequence< uno::Any > aArguments( 1 );
239 : 2 : beans::PropertyValue aProperty;
240 : 2 : aProperty.Name = rtl::OUString( "nodepath" );
241 [ + - ]: 2 : aProperty.Value <<= rtl::OUString(); // root path
242 [ + - ][ + - ]: 2 : aArguments[ 0 ] <<= aProperty;
243 : :
244 [ + - ]: 2 : (*it).second.bTriedToGetRootReadAccess = true;
245 : :
246 [ + - ]: 2 : (*it).second.xRootReadAccess
247 : : = uno::Reference< container::XHierarchicalNameAccess >(
248 [ + - ]: 2 : xConfigProv->createInstanceWithArguments(
249 : : rtl::OUString( "com.sun.star.ucb.HierarchyDataReadAccess" ),
250 : 2 : aArguments ),
251 [ + - ][ + - ]: 4 : uno::UNO_QUERY );
[ + - ][ + - ]
252 : 2 : }
253 : : }
254 [ # # # ]: 0 : catch ( uno::RuntimeException const & )
255 : : {
256 : 0 : throw;
257 : : }
258 [ # # ]: 0 : catch ( uno::Exception const & )
259 : : {
260 : : // createInstance, createInstanceWithArguments
261 : :
262 : : OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - "
263 : : "caught Exception!" );
264 : : }
265 : : }
266 : : }
267 : :
268 [ + - ][ + - ]: 126 : return (*it).second.xRootReadAccess;
269 : : }
270 : :
271 : : //=========================================================================
272 : : uno::Reference< util::XOfficeInstallationDirectories >
273 : 126 : HierarchyContentProvider::getOfficeInstallationDirectories()
274 : : {
275 [ + + ]: 126 : if ( !m_xOfficeInstDirs.is() )
276 : : {
277 [ + - ]: 2 : osl::MutexGuard aGuard( m_aMutex );
278 [ + - ]: 2 : if ( !m_xOfficeInstDirs.is() )
279 : : {
280 : : OSL_ENSURE( m_xSMgr.is(), "No service manager!" );
281 : :
282 : 2 : uno::Reference< uno::XComponentContext > xCtx;
283 : : uno::Reference< beans::XPropertySet > xPropSet(
284 [ + - ]: 2 : m_xSMgr, uno::UNO_QUERY );
285 [ + - ]: 2 : if ( xPropSet.is() )
286 : : {
287 [ + - ]: 2 : xPropSet->getPropertyValue(
288 : 2 : rtl::OUString( "DefaultContext" ) )
289 [ + - ][ + - ]: 2 : >>= xCtx;
290 : : }
291 : :
292 : : OSL_ENSURE( xCtx.is(),
293 : : "Unable to obtain component context from "
294 : : "service manager!" );
295 : :
296 [ + - ]: 2 : if ( xCtx.is() )
297 : : {
298 [ + - ]: 2 : xCtx->getValueByName(
299 : 2 : rtl::OUString( "/singletons/com.sun.star.util.theOfficeInstallationDirectories" ) )
300 [ + - ][ + - ]: 2 : >>= m_xOfficeInstDirs;
301 : :
302 : : // Be silent. singleton only available in an Office environment.
303 : : // OSL_ENSURE( m_xOfficeInstDirs.is(),
304 : : // "Unable to obtain office directories singleton!" );
305 : 2 : }
306 [ + - ]: 2 : }
307 : : }
308 : 126 : return m_xOfficeInstDirs;
309 : : }
310 : :
311 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|