LibreOffice Module xmlhelp (master) 1
provider.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_folders.h>
21
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>
34
35#include "databases.hxx"
36#include "provider.hxx"
37#include "content.hxx"
38
39using namespace com::sun::star;
40using namespace chelp;
41
42
43// ContentProvider Implementation.
44
45ContentProvider::ContentProvider( const uno::Reference< uno::XComponentContext >& rxContext )
46 : ContentProvider_Base( rxContext )
47 , isInitialized( false )
48{
49}
50
51// virtual
52ContentProvider::~ContentProvider()
53{
54}
55
56// XServiceInfo methods.
57
59{
60 return "CHelpContentProvider";
61}
62
63sal_Bool SAL_CALL
64ContentProvider::supportsService(const OUString& ServiceName )
65{
67}
68
69uno::Sequence< OUString > SAL_CALL
71{
72 return { "com.sun.star.help.XMLHelp", "com.sun.star.ucb.HelpContentProvider" };
73}
74
75// XContentProvider methods.
76
77// virtual
78uno::Reference< ucb::XContent > SAL_CALL
80 const uno::Reference< ucb::XContentIdentifier >& xCanonicId )
81{
82 if ( !xCanonicId->getContentProviderScheme()
83 .equalsIgnoreAsciiCase( MYUCP_URL_SCHEME ) )
84 { // Wrong URL-scheme
85 throw ucb::IllegalIdentifierException();
86 }
87
88 {
89 osl::MutexGuard aGuard( m_aMutex );
90 if( !isInitialized )
91 init();
92 }
93
94 if( !m_pDatabases )
95 throw uno::RuntimeException();
96
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;
102
103 xContent = new Content( m_xContext, this, xCanonicId, m_pDatabases.get() );
104
105 // register new content
106 registerNewContent( xContent );
107
108 // Further checks
109
110 if ( !xContent->getIdentifier().is() )
111 throw ucb::IllegalIdentifierException();
112
113 return xContent;
114}
115
116void SAL_CALL
118{
119 if(m_xContainer.is())
120 {
121 m_xContainer->removeContainerListener(this);
122 m_xContainer.clear();
123 }
124}
125
126void SAL_CALL
127ContentProvider::elementReplaced(const container::ContainerEvent& Event)
128{
129 if(!m_pDatabases)
130 return;
131
132 OUString accessor;
133 Event.Accessor >>= accessor;
134 if(accessor != "HelpStyleSheet")
135 return;
136
137 OUString replacedElement,element;
138 Event.ReplacedElement >>= replacedElement;
139 Event.Element >>= element;
140
141 if(replacedElement == element)
142 return;
143
144 m_pDatabases->changeCSS(element);
145}
146
148{
149 osl::MutexGuard aGuard( m_aMutex );
150
151 isInitialized = true;
152
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 );
160
161 OUString stylesheet(
162 officecfg::Office::Common::Help::HelpStyleSheet::get());
163
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 );
169
170 OUString setupversion(
171 officecfg::Setup::Product::ooSetupVersion::get());
172 OUString setupextension(
173 officecfg::Setup::Product::ooSetupExtension::get());
174 OUString productversion( setupversion + " " + setupextension );
175
176 bool showBasic = officecfg::Office::Common::Help::ShowBasic::get();
177 m_pDatabases.reset( new Databases( showBasic,
178 instPath,
180 productversion,
181 stylesheet,
182 m_xContext ) );
183}
184
185void ContentProvider::subst( OUString& instpath )
186{
187 SvtPathOptions aOptions;
188 instpath = aOptions.SubstituteVariable( instpath );
189}
190
191extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
193 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
194{
195 return cppu::acquire(new ContentProvider(context));
196}
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
OUString SubstituteVariable(const OUString &rVar) const
std::unique_ptr< Databases > m_pDatabases
Definition: provider.hxx:94
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
virtual OUString SAL_CALL getImplementationName() override
Definition: provider.cxx:58
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: provider.cxx:64
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: provider.cxx:70
virtual void SAL_CALL dispose() override
Definition: provider.cxx:117
virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent &Event) override
Definition: provider.cxx:127
static void subst(OUString &instpath)
Definition: provider.cxx:185
css::uno::Reference< css::container::XContainer > m_xContainer
Definition: provider.hxx:95
static OUString getProductName()
std::mutex m_aMutex
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * CHelpContentProvider_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: provider.cxx:192
#define MYUCP_URL_SCHEME
Definition: provider.hxx:37
unsigned char sal_Bool