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 .
20 #include <config_folders.h>
22 #include <officecfg/Office/Common.hxx>
23 #include <officecfg/Setup.hxx>
24 #include <com/sun/star/container/XContainer.hpp>
25 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <comphelper/processfactory.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <cppuhelper/queryinterface.hxx>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <cppuhelper/factory.hxx>
32 #include <unotools/configmgr.hxx>
33 #include <unotools/pathoptions.hxx>
35 #include "databases.hxx"
36 #include "provider.hxx"
37 #include "content.hxx"
39 using namespace com::sun::star
;
40 using namespace chelp
;
43 // ContentProvider Implementation.
45 ContentProvider::ContentProvider( const uno::Reference
< uno::XComponentContext
>& rxContext
)
46 : ContentProvider_Base( rxContext
)
47 , isInitialized( false )
52 ContentProvider::~ContentProvider()
56 // XServiceInfo methods.
58 OUString SAL_CALL
ContentProvider::getImplementationName()
60 return u
"CHelpContentProvider"_ustr
;
64 ContentProvider::supportsService(const OUString
& ServiceName
)
66 return cppu::supportsService(this, ServiceName
);
69 uno::Sequence
< OUString
> SAL_CALL
70 ContentProvider::getSupportedServiceNames()
72 return { u
"com.sun.star.help.XMLHelp"_ustr
, u
"com.sun.star.ucb.HelpContentProvider"_ustr
};
75 // XContentProvider methods.
78 uno::Reference
< ucb::XContent
> SAL_CALL
79 ContentProvider::queryContent(
80 const uno::Reference
< ucb::XContentIdentifier
>& xCanonicId
)
82 if ( !xCanonicId
->getContentProviderScheme()
83 .equalsIgnoreAsciiCase( MYUCP_URL_SCHEME
) )
85 throw ucb::IllegalIdentifierException();
89 osl::MutexGuard
aGuard( m_aMutex
);
95 throw uno::RuntimeException();
97 // Check, if a content with given id already exists...
98 uno::Reference
< ucb::XContent
> xContent
99 = queryExistingContent( xCanonicId
);
103 xContent
= new Content( m_xContext
, this, xCanonicId
, m_pDatabases
.get() );
105 // register new content
106 registerNewContent( xContent
);
110 if ( !xContent
->getIdentifier().is() )
111 throw ucb::IllegalIdentifierException();
117 ContentProvider::dispose()
119 if(m_xContainer
.is())
121 m_xContainer
->removeContainerListener(this);
122 m_xContainer
.clear();
127 ContentProvider::elementReplaced(const container::ContainerEvent
& Event
)
133 Event
.Accessor
>>= accessor
;
134 if(accessor
!= "HelpStyleSheet")
137 OUString replacedElement
,element
;
138 Event
.ReplacedElement
>>= replacedElement
;
139 Event
.Element
>>= element
;
141 if(replacedElement
== element
)
144 m_pDatabases
->changeCSS(element
);
147 void ContentProvider::init()
149 osl::MutexGuard
aGuard( m_aMutex
);
151 isInitialized
= true;
154 officecfg::Office::Common::Path::Current::Help::get());
155 if( instPath
.isEmpty() )
156 // try to determine path from default
157 instPath
= "$(instpath)/" LIBO_SHARE_HELP_FOLDER
;
158 // replace anything like $(instpath);
162 officecfg::Office::Common::Help::HelpStyleSheet::get());
164 // now adding as configuration change listener for the stylesheet
166 officecfg::Office::Common::Help::get(),
167 css::uno::UNO_QUERY_THROW
);
168 m_xContainer
->addContainerListener( this );
170 OUString
setupversion(
171 officecfg::Setup::Product::ooSetupVersion::get());
172 OUString
setupextension(
173 officecfg::Setup::Product::ooSetupExtension::get());
174 OUString
productversion( setupversion
+ " " + setupextension
);
176 bool showBasic
= officecfg::Office::Common::Help::ShowBasic::get();
177 m_pDatabases
.reset( new Databases( showBasic
,
179 utl::ConfigManager::getProductName(),
185 void ContentProvider::subst( OUString
& instpath
)
187 SvtPathOptions aOptions
;
188 instpath
= aOptions
.SubstituteVariable( instpath
);
191 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
192 CHelpContentProvider_get_implementation(
193 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
195 return cppu::acquire(new ContentProvider(context
));
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */