1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 /**************************************************************************
23 **************************************************************************
25 *************************************************************************/
28 #include <osl/file.hxx>
29 #include <osl/diagnose.h>
30 #include <ucbhelper/contentidentifier.hxx>
31 #include <com/sun/star/frame/XConfigManager.hpp>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #include <com/sun/star/configuration/theDefaultProvider.hpp>
35 #include <com/sun/star/container/XContainer.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <com/sun/star/container/XNameReplace.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <comphelper/processfactory.hxx>
40 #include <unotools/configmgr.hxx>
41 #include <rtl/bootstrap.hxx>
43 #include "databases.hxx"
44 #include "provider.hxx"
45 #include "content.hxx"
47 using namespace com::sun::star
;
48 using namespace chelp
;
50 //=========================================================================
51 //=========================================================================
53 // ContentProvider Implementation.
55 //=========================================================================
56 //=========================================================================
58 ContentProvider::ContentProvider(
59 const uno::Reference
< uno::XComponentContext
>& rxContext
)
60 : ::ucbhelper::ContentProviderImplHelper( rxContext
),
61 isInitialized( false ),
62 m_aScheme(MYUCP_URL_SCHEME
),
67 //=========================================================================
69 ContentProvider::~ContentProvider()
74 //=========================================================================
76 // XInterface methods.
78 //=========================================================================
80 XINTERFACE_IMPL_6( ContentProvider
,
83 ucb::XContentProvider
,
85 lang::XEventListener
, /* base of XContainerListener */
86 container::XContainerListener
);
88 //=========================================================================
90 // XTypeProvider methods.
92 //=========================================================================
94 XTYPEPROVIDER_IMPL_5( ContentProvider
,
97 ucb::XContentProvider
,
99 container::XContainerListener
);
101 //=========================================================================
103 // XServiceInfo methods.
105 //=========================================================================
107 OUString SAL_CALL
ContentProvider::getImplementationName()
108 throw( uno::RuntimeException
)
110 return getImplementationName_Static();
113 OUString
ContentProvider::getImplementationName_Static()
115 return OUString("CHelpContentProvider" );
119 ContentProvider::supportsService(const OUString
& ServiceName
)
120 throw( uno::RuntimeException
)
122 uno::Sequence
< OUString
> aSNL
= getSupportedServiceNames();
123 const OUString
* pArray
= aSNL
.getArray();
124 for( sal_Int32 i
= 0; i
< aSNL
.getLength(); i
++ )
126 if( pArray
[ i
] == ServiceName
)
133 uno::Sequence
< OUString
> SAL_CALL
134 ContentProvider::getSupportedServiceNames()
135 throw( uno::RuntimeException
)
137 return getSupportedServiceNames_Static();
140 static uno::Reference
< uno::XInterface
> SAL_CALL
141 ContentProvider_CreateInstance(
142 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
143 throw( uno::Exception
)
145 lang::XServiceInfo
* pX
= static_cast< lang::XServiceInfo
* >(
146 new ContentProvider( comphelper::getComponentContext(rSMgr
) ) );
147 return uno::Reference
< uno::XInterface
>::query( pX
);
150 uno::Sequence
< OUString
>
151 ContentProvider::getSupportedServiceNames_Static()
153 uno::Sequence
< OUString
> aSNS( 2 );
154 aSNS
.getArray()[ 0 ] =
156 MYUCP_CONTENT_PROVIDER_SERVICE_NAME1
);
157 aSNS
.getArray()[ 1 ] =
159 MYUCP_CONTENT_PROVIDER_SERVICE_NAME2
);
164 //=========================================================================
166 // Service factory implementation.
168 //=========================================================================
170 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider
);
172 //=========================================================================
174 // XContentProvider methods.
176 //=========================================================================
179 uno::Reference
< ucb::XContent
> SAL_CALL
180 ContentProvider::queryContent(
181 const uno::Reference
< ucb::XContentIdentifier
>& xCanonicId
)
182 throw( ucb::IllegalIdentifierException
, uno::RuntimeException
)
184 if ( !xCanonicId
->getContentProviderScheme()
185 .equalsIgnoreAsciiCase( m_aScheme
) )
186 { // Wrong URL-scheme
187 throw ucb::IllegalIdentifierException();
191 osl::MutexGuard
aGuard( m_aMutex
);
197 throw uno::RuntimeException();
199 // Check, if a content with given id already exists...
200 uno::Reference
< ucb::XContent
> xContent
201 = queryExistingContent( xCanonicId
).get();
205 xContent
= new Content( m_xContext
, this, xCanonicId
, m_pDatabases
);
207 // register new content
208 registerNewContent( xContent
);
212 if ( !xContent
->getIdentifier().is() )
213 throw ucb::IllegalIdentifierException();
219 ContentProvider::dispose()
220 throw ( uno::RuntimeException
)
222 if(m_xContainer
.is())
224 m_xContainer
->removeContainerListener(this);
225 m_xContainer
.clear();
230 ContentProvider::elementReplaced(const container::ContainerEvent
& Event
)
231 throw (uno::RuntimeException
)
237 Event
.Accessor
>>= accessor
;
238 if(accessor
.compareToAscii("HelpStyleSheet"))
241 OUString replacedElement
,element
;
242 Event
.ReplacedElement
>>= replacedElement
;
243 Event
.Element
>>= element
;
245 if(replacedElement
== element
)
248 m_pDatabases
->changeCSS(element
);
251 void ContentProvider::init()
253 osl::MutexGuard
aGuard( m_aMutex
);
255 isInitialized
= true;
256 uno::Reference
< lang::XMultiServiceFactory
> sProvider(
257 getConfiguration() );
258 uno::Reference
< container::XHierarchicalNameAccess
> xHierAccess(
259 getHierAccess( sProvider
,
260 "org.openoffice.Office.Common" ) );
262 OUString
instPath( getKey( xHierAccess
,"Path/Current/Help" ) );
263 if( instPath
.isEmpty() )
264 // try to determine path from default
265 instPath
= OUString( "$(instpath)/help" );
266 // replace anything like $(instpath);
269 OUString
stylesheet( getKey( xHierAccess
,"Help/HelpStyleSheet" ) );
272 // now adding as configuration change listener for the stylesheet
273 uno::Reference
< container::XNameAccess
> xAccess(
274 xHierAccess
, uno::UNO_QUERY
);
278 xAccess
->getByName( OUString( "Help" ) );
279 aAny
>>= m_xContainer
;
280 if( m_xContainer
.is() )
281 m_xContainer
->addContainerListener( this );
284 catch( uno::Exception
const & )
288 xHierAccess
= getHierAccess( sProvider
, "org.openoffice.Setup" );
290 OUString
setupversion(
291 getKey( xHierAccess
,"Product/ooSetupVersion" ) );
292 OUString setupextension
;
296 uno::Reference
< lang::XMultiServiceFactory
> xConfigProvider
=
297 configuration::theDefaultProvider::get( m_xContext
);
299 uno::Sequence
< uno::Any
> lParams(1);
300 beans::PropertyValue aParam
;
301 aParam
.Name
= OUString("nodepath");
302 aParam
.Value
<<= OUString("/org.openoffice.Setup/Product");
303 lParams
[0] = uno::makeAny(aParam
);
306 uno::Reference
< uno::XInterface
> xCFG( xConfigProvider
->createInstanceWithArguments(
307 OUString("com.sun.star.configuration.ConfigurationAccess"),
310 uno::Reference
< container::XNameAccess
> xDirectAccess(xCFG
, uno::UNO_QUERY
);
311 uno::Any aRet
= xDirectAccess
->getByName(OUString("ooSetupExtension"));
313 aRet
>>= setupextension
;
315 catch ( uno::Exception
& )
319 OUString
productversion(
324 uno::Sequence
< OUString
> aImagesZipPaths( 2 );
325 xHierAccess
= getHierAccess( sProvider
, "org.openoffice.Office.Common" );
327 OUString
aPath( getKey( xHierAccess
, "Path/Current/UserConfig" ) );
329 aImagesZipPaths
[ 0 ] = aPath
;
331 aPath
= OUString("$BRAND_BASE_DIR/share/config");
332 rtl::Bootstrap::expandMacros(aPath
);
333 aImagesZipPaths
[ 1 ] = aPath
;
335 sal_Bool showBasic
= getBooleanKey(xHierAccess
,"Help/ShowBasic");
336 m_pDatabases
= new Databases( showBasic
,
339 utl::ConfigManager::getProductName(),
345 uno::Reference
< lang::XMultiServiceFactory
>
346 ContentProvider::getConfiguration() const
348 uno::Reference
< lang::XMultiServiceFactory
> xProvider
;
349 if( m_xContext
.is() )
353 xProvider
= configuration::theDefaultProvider::get( m_xContext
);
355 catch( const uno::Exception
& )
357 OSL_ENSURE( xProvider
.is(), "cant instantiate configuration" );
364 uno::Reference
< container::XHierarchicalNameAccess
>
365 ContentProvider::getHierAccess(
366 const uno::Reference
< lang::XMultiServiceFactory
>& sProvider
,
367 const char* file
) const
369 uno::Reference
< container::XHierarchicalNameAccess
> xHierAccess
;
373 uno::Sequence
< uno::Any
> seq( 1 );
374 OUString
sReaderService(
376 "com.sun.star.configuration.ConfigurationAccess" ) );
378 seq
[ 0 ] <<= OUString::createFromAscii( file
);
383 uno::Reference
< container::XHierarchicalNameAccess
>(
384 sProvider
->createInstanceWithArguments(
385 sReaderService
, seq
),
388 catch( const uno::Exception
& )
398 ContentProvider::getKey(
399 const uno::Reference
< container::XHierarchicalNameAccess
>& xHierAccess
,
400 const char* key
) const
403 if( xHierAccess
.is() )
409 xHierAccess
->getByHierarchicalName(
410 OUString::createFromAscii( key
) );
412 catch( const container::NoSuchElementException
& )
421 ContentProvider::getBooleanKey(
422 const uno::Reference
< container::XHierarchicalNameAccess
>& xHierAccess
,
423 const char* key
) const
425 sal_Bool ret
= sal_False
;
426 if( xHierAccess
.is() )
432 xHierAccess
->getByHierarchicalName(
433 OUString::createFromAscii( key
) );
435 catch( const container::NoSuchElementException
& )
443 void ContentProvider::subst( OUString
& instpath
) const
445 uno::Reference
< frame::XConfigManager
> xCfgMgr
;
446 if( m_xContext
.is() )
451 uno::Reference
< frame::XConfigManager
>(
452 m_xContext
->getServiceManager()->createInstanceWithContext("com.sun.star.config.SpecialConfigManager", m_xContext
),
455 catch( const uno::Exception
&)
457 OSL_ENSURE( xCfgMgr
.is(),
458 "cant instantiate the special config manager " );
462 OSL_ENSURE( xCfgMgr
.is(), "specialconfigmanager not found\n" );
465 instpath
= xCfgMgr
->substituteVariables( instpath
);
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */