1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: provider.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlhelp.hxx"
34 /**************************************************************************
36 **************************************************************************
38 *************************************************************************/
41 #include <osl/file.hxx>
42 #ifndef _VOS_DIAGNOSE_HXX_
43 #include <vos/diagnose.hxx>
45 #include <ucbhelper/contentidentifier.hxx>
46 #include <com/sun/star/frame/XConfigManager.hpp>
47 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_
48 #include <com/sun/star/beans/PropertyAttribute.hpp>
50 #include <com/sun/star/beans/PropertyValue.hpp>
51 #include <com/sun/star/beans/PropertyState.hpp>
52 #include <com/sun/star/container/XContainer.hpp>
53 #include <com/sun/star/container/XNameAccess.hpp>
54 #include <com/sun/star/container/XNameReplace.hpp>
55 #include <com/sun/star/uno/XComponentContext.hpp>
56 #include <com/sun/star/beans/XPropertySet.hpp>
57 #include <rtl/bootstrap.hxx>
58 #include <unotools/configmgr.hxx>
60 #include "databases.hxx"
61 #include "provider.hxx"
62 #include "content.hxx"
63 #include "databases.hxx"
65 using namespace com::sun::star
;
66 using namespace chelp
;
68 //=========================================================================
69 //=========================================================================
71 // ContentProvider Implementation.
73 //=========================================================================
74 //=========================================================================
76 ContentProvider::ContentProvider(
77 const uno::Reference
< lang::XMultiServiceFactory
>& rSMgr
)
78 : ::ucbhelper::ContentProviderImplHelper( rSMgr
),
79 isInitialized( false ),
80 m_aScheme( rtl::OUString::createFromAscii( MYUCP_URL_SCHEME
) ),
85 //=========================================================================
87 ContentProvider::~ContentProvider()
92 //=========================================================================
94 // XInterface methods.
96 //=========================================================================
98 XINTERFACE_IMPL_6( ContentProvider
,
101 ucb::XContentProvider
,
103 lang::XEventListener
, /* base of XContainerListener */
104 container::XContainerListener
);
106 //=========================================================================
108 // XTypeProvider methods.
110 //=========================================================================
112 XTYPEPROVIDER_IMPL_5( ContentProvider
,
115 ucb::XContentProvider
,
117 container::XContainerListener
);
119 //=========================================================================
121 // XServiceInfo methods.
123 //=========================================================================
125 rtl::OUString SAL_CALL
ContentProvider::getImplementationName()
126 throw( uno::RuntimeException
)
128 return getImplementationName_Static();
131 rtl::OUString
ContentProvider::getImplementationName_Static()
133 return rtl::OUString::createFromAscii("CHelpContentProvider" );
137 ContentProvider::supportsService(const rtl::OUString
& ServiceName
)
138 throw( uno::RuntimeException
)
140 uno::Sequence
< rtl::OUString
> aSNL
= getSupportedServiceNames();
141 const rtl::OUString
* pArray
= aSNL
.getArray();
142 for( sal_Int32 i
= 0; i
< aSNL
.getLength(); i
++ )
144 if( pArray
[ i
] == ServiceName
)
151 uno::Sequence
< rtl::OUString
> SAL_CALL
152 ContentProvider::getSupportedServiceNames()
153 throw( uno::RuntimeException
)
155 return getSupportedServiceNames_Static();
158 static uno::Reference
< uno::XInterface
> SAL_CALL
159 ContentProvider_CreateInstance(
160 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
161 throw( uno::Exception
)
163 lang::XServiceInfo
* pX
= static_cast< lang::XServiceInfo
* >(
164 new ContentProvider( rSMgr
) );
165 return uno::Reference
< uno::XInterface
>::query( pX
);
168 uno::Sequence
< rtl::OUString
>
169 ContentProvider::getSupportedServiceNames_Static()
171 uno::Sequence
< rtl::OUString
> aSNS( 2 );
172 aSNS
.getArray()[ 0 ] =
173 rtl::OUString::createFromAscii(
174 MYUCP_CONTENT_PROVIDER_SERVICE_NAME1
);
175 aSNS
.getArray()[ 1 ] =
176 rtl::OUString::createFromAscii(
177 MYUCP_CONTENT_PROVIDER_SERVICE_NAME2
);
182 //=========================================================================
184 // Service factory implementation.
186 //=========================================================================
188 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider
);
190 //=========================================================================
192 // XContentProvider methods.
194 //=========================================================================
197 uno::Reference
< ucb::XContent
> SAL_CALL
198 ContentProvider::queryContent(
199 const uno::Reference
< ucb::XContentIdentifier
>& xCanonicId
)
200 throw( ucb::IllegalIdentifierException
, uno::RuntimeException
)
202 if ( !xCanonicId
->getContentProviderScheme()
203 .equalsIgnoreAsciiCase( m_aScheme
) )
204 { // Wrong URL-scheme
205 throw ucb::IllegalIdentifierException();
209 osl::MutexGuard
aGuard( m_aMutex
);
215 throw uno::RuntimeException();
217 rtl::OUString
aOUString( m_pDatabases
->getInstallPathAsURL() );
218 rtl::OString
aOString( aOUString
.getStr(),
219 aOUString
.getLength(),
220 RTL_TEXTENCODING_UTF8
);
222 // Check, if a content with given id already exists...
223 uno::Reference
< ucb::XContent
> xContent
224 = queryExistingContent( xCanonicId
).get();
228 xContent
= new Content( m_xSMgr
, this, xCanonicId
, m_pDatabases
);
230 // register new content
231 registerNewContent( xContent
);
235 if ( !xContent
->getIdentifier().is() )
236 throw ucb::IllegalIdentifierException();
242 ContentProvider::dispose()
243 throw ( uno::RuntimeException
)
245 if(m_xContainer
.is())
247 m_xContainer
->removeContainerListener(this);
248 m_xContainer
.clear();
253 ContentProvider::elementReplaced(const container::ContainerEvent
& Event
)
254 throw (uno::RuntimeException
)
259 rtl::OUString accessor
;
260 Event
.Accessor
>>= accessor
;
261 if(accessor
.compareToAscii("HelpStyleSheet"))
264 rtl::OUString replacedElement
,element
;
265 Event
.ReplacedElement
>>= replacedElement
;
266 Event
.Element
>>= element
;
268 if(replacedElement
== element
)
271 m_pDatabases
->changeCSS(element
);
274 void ContentProvider::init()
276 osl::MutexGuard
aGuard( m_aMutex
);
278 isInitialized
= true;
279 uno::Reference
< lang::XMultiServiceFactory
> sProvider(
280 getConfiguration() );
281 uno::Reference
< container::XHierarchicalNameAccess
> xHierAccess(
282 getHierAccess( sProvider
,
283 "org.openoffice.Office.Common" ) );
285 rtl::OUString
instPath( getKey( xHierAccess
,"Path/Current/Help" ) );
286 if( ! instPath
.getLength() )
287 // try to determine path from default
288 instPath
= rtl::OUString::createFromAscii( "$(instpath)/help" );
289 // replace anything like $(instpath);
292 rtl::OUString
stylesheet( getKey( xHierAccess
,"Help/HelpStyleSheet" ) );
295 // now adding as configuration change listener for the stylesheet
296 uno::Reference
< container::XNameAccess
> xAccess(
297 xHierAccess
, uno::UNO_QUERY
);
301 xAccess
->getByName( rtl::OUString::createFromAscii( "Help" ) );
302 aAny
>>= m_xContainer
;
303 if( m_xContainer
.is() )
304 m_xContainer
->addContainerListener( this );
307 catch( uno::Exception
const & )
320 xHierAccess
= getHierAccess( sProvider
, "org.openoffice.Setup" );
321 rtl::OUString
productname(
322 getKey( xHierAccess
,"Product/ooName" ) );
324 rtl::OUString
setupversion(
325 getKey( xHierAccess
,"Product/ooSetupVersion" ) );
326 rtl::OUString setupextension
;
327 utl::ConfigManager
* mgr
= utl::ConfigManager::GetConfigManager();
329 mgr
->GetDirectConfigProperty(utl::ConfigManager::PRODUCTEXTENSION
) >>=
332 rtl::OUString
productversion(
334 rtl::OUString::createFromAscii( " " ) +
337 xHierAccess
= getHierAccess( sProvider
, "org.openoffice.Webtop.Common" );
338 rtl::OUString
vendorname(
339 getKey( xHierAccess
,"Product/ooName" ) );
341 setupversion
= rtl::OUString(
342 getKey( xHierAccess
,"Product/ooSetupVersion" ) );
343 setupextension
= rtl::OUString(
344 getKey( xHierAccess
,"Product/ooSetupExtension") );
345 rtl::OUString
vendorversion(
347 rtl::OUString::createFromAscii( " " ) +
349 rtl::OUString vendorshort
= vendorname
;
351 uno::Sequence
< rtl::OUString
> aImagesZipPaths( 3 );
352 xHierAccess
= getHierAccess( sProvider
, "org.openoffice.Office.Common" );
354 rtl::OUString
aPath( getKey( xHierAccess
, "Path/Current/UserConfig" ) );
356 aImagesZipPaths
[ 0 ] = aPath
;
358 aPath
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/share/config"));
359 rtl::Bootstrap::expandMacros(aPath
);
360 aImagesZipPaths
[ 2 ] = aPath
;
362 // try also /usr/share and even before /usr/lib
363 ::rtl::OUString aDataDir
= ::rtl::OUString::createFromAscii ( "/usr/share/" );
365 ::rtl::OUString aLibDir
= ::rtl::OUString::createFromAscii ( "/usr/lib64/" );
367 ::rtl::OUString aLibDir
= ::rtl::OUString::createFromAscii ( "/usr/lib/" );
369 sal_Int32 nLibDirPos
= aPath
.indexOf( aLibDir
);
371 if ( nLibDirPos
>= 0 )
372 aPath
= aPath
.replaceAt( nLibDirPos
, aLibDir
.getLength(), aDataDir
);
373 aImagesZipPaths
[ 1 ] = aPath
;
375 uno::Reference
< uno::XComponentContext
> xContext
;
376 uno::Reference
< beans::XPropertySet
> xProps( m_xSMgr
, uno::UNO_QUERY
);
377 OSL_ASSERT( xProps
.is() );
380 xProps
->getPropertyValue(
381 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext
;
382 OSL_ASSERT( xContext
.is() );
385 sal_Bool showBasic
= getBooleanKey(xHierAccess
,"Help/ShowBasic");
386 m_pDatabases
= new Databases( showBasic
,
398 uno::Reference
< lang::XMultiServiceFactory
>
399 ContentProvider::getConfiguration() const
401 uno::Reference
< lang::XMultiServiceFactory
> sProvider
;
405 aAny
<<= rtl::OUString::createFromAscii( "plugin" );
406 beans::PropertyValue
aProp(
407 rtl::OUString::createFromAscii( "servertype" ),
410 beans::PropertyState_DIRECT_VALUE
);
412 uno::Sequence
< uno::Any
> seq(1);
417 rtl::OUString sProviderService
=
418 rtl::OUString::createFromAscii(
419 "com.sun.star.configuration.ConfigurationProvider" );
421 uno::Reference
< lang::XMultiServiceFactory
>(
422 m_xSMgr
->createInstanceWithArguments(
423 sProviderService
,seq
),
426 catch( const uno::Exception
& )
428 OSL_ENSURE( sProvider
.is(), "cant instantiate configuration" );
435 uno::Reference
< container::XHierarchicalNameAccess
>
436 ContentProvider::getHierAccess(
437 const uno::Reference
< lang::XMultiServiceFactory
>& sProvider
,
438 const char* file
) const
440 uno::Reference
< container::XHierarchicalNameAccess
> xHierAccess
;
444 uno::Sequence
< uno::Any
> seq( 1 );
445 rtl::OUString
sReaderService(
446 rtl::OUString::createFromAscii(
447 "com.sun.star.configuration.ConfigurationAccess" ) );
449 seq
[ 0 ] <<= rtl::OUString::createFromAscii( file
);
454 uno::Reference
< container::XHierarchicalNameAccess
>(
455 sProvider
->createInstanceWithArguments(
456 sReaderService
, seq
),
459 catch( const uno::Exception
& )
469 ContentProvider::getKey(
470 const uno::Reference
< container::XHierarchicalNameAccess
>& xHierAccess
,
471 const char* key
) const
473 rtl::OUString instPath
;
474 if( xHierAccess
.is() )
480 xHierAccess
->getByHierarchicalName(
481 rtl::OUString::createFromAscii( key
) );
483 catch( const container::NoSuchElementException
& )
492 ContentProvider::getBooleanKey(
493 const uno::Reference
< container::XHierarchicalNameAccess
>& xHierAccess
,
494 const char* key
) const
496 sal_Bool ret
= sal_False
;
497 if( xHierAccess
.is() )
503 xHierAccess
->getByHierarchicalName(
504 rtl::OUString::createFromAscii( key
) );
506 catch( const container::NoSuchElementException
& )
514 void ContentProvider::subst( rtl::OUString
& instpath
) const
516 uno::Reference
< frame::XConfigManager
> xCfgMgr
;
522 uno::Reference
< frame::XConfigManager
>(
523 m_xSMgr
->createInstance(
524 rtl::OUString::createFromAscii(
525 "com.sun.star.config.SpecialConfigManager" ) ),
528 catch( const uno::Exception
&)
530 OSL_ENSURE( xCfgMgr
.is(),
531 "cant instantiate the special config manager " );
535 OSL_ENSURE( xCfgMgr
.is(), "specialconfigmanager not found\n" );
538 instpath
= xCfgMgr
->substituteVariables( instpath
);