Revert "Revert "Revert "stronger typing for SwClient::GetRegisteredIn"" and fix SwIte...
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / provider.cxx
blob457dec5b71d7c4ff58c60e70b486d957455f85d3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 )
51 // virtual
52 ContentProvider::~ContentProvider()
56 // XServiceInfo methods.
58 OUString SAL_CALL ContentProvider::getImplementationName()
60 return u"CHelpContentProvider"_ustr;
63 sal_Bool SAL_CALL
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.
77 // virtual
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 ) )
84 { // Wrong URL-scheme
85 throw ucb::IllegalIdentifierException();
89 osl::MutexGuard aGuard( m_aMutex );
90 if( !isInitialized )
91 init();
94 if( !m_pDatabases )
95 throw uno::RuntimeException();
97 // Check, if a content with given id already exists...
98 uno::Reference< ucb::XContent > xContent
99 = queryExistingContent( xCanonicId );
100 if ( xContent.is() )
101 return xContent;
103 xContent = new Content( m_xContext, this, xCanonicId, m_pDatabases.get() );
105 // register new content
106 registerNewContent( xContent );
108 // Further checks
110 if ( !xContent->getIdentifier().is() )
111 throw ucb::IllegalIdentifierException();
113 return xContent;
116 void SAL_CALL
117 ContentProvider::dispose()
119 if(m_xContainer.is())
121 m_xContainer->removeContainerListener(this);
122 m_xContainer.clear();
126 void SAL_CALL
127 ContentProvider::elementReplaced(const container::ContainerEvent& Event)
129 if(!m_pDatabases)
130 return;
132 OUString accessor;
133 Event.Accessor >>= accessor;
134 if(accessor != "HelpStyleSheet")
135 return;
137 OUString replacedElement,element;
138 Event.ReplacedElement >>= replacedElement;
139 Event.Element >>= element;
141 if(replacedElement == element)
142 return;
144 m_pDatabases->changeCSS(element);
147 void ContentProvider::init()
149 osl::MutexGuard aGuard( m_aMutex );
151 isInitialized = true;
153 OUString instPath(
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);
159 subst( instPath );
161 OUString stylesheet(
162 officecfg::Office::Common::Help::HelpStyleSheet::get());
164 // now adding as configuration change listener for the stylesheet
165 m_xContainer.set(
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,
178 instPath,
179 utl::ConfigManager::getProductName(),
180 productversion,
181 stylesheet,
182 m_xContext ) );
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: */