Simplify using designated initializers
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / databases.hxx
blobc7c81845cbe0864121e40cfdd2ceb301bc56065c
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 #pragma once
22 #include <sal/config.h>
24 #include <memory>
25 #include <mutex>
26 #include <string_view>
27 #include <unordered_map>
28 #include <unordered_set>
29 #include <utility>
30 #include <vector>
31 #include <rtl/ustring.hxx>
32 #include <rtl/strbuf.hxx>
33 #include <o3tl/string_view.hxx>
34 #include <com/sun/star/uno/Sequence.hxx>
35 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
36 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/i18n/XCollator.hpp>
39 #include <com/sun/star/deployment/XPackage.hpp>
40 #include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
42 // Forward declaration
44 namespace helpdatafileproxy {
46 class Hdf;
50 namespace chelp {
52 class Databases;
53 class URLParameter;
55 class StaticModuleInformation
57 private:
59 OUString m_aStartId;
60 OUString m_aProgramSwitch;
61 OUString m_aTitle;
62 int m_nOrder;
64 public:
66 StaticModuleInformation( OUString aTitle,
67 OUString aStartId,
68 OUString aProgramSwitch,
69 std::u16string_view aOrder )
70 : m_aStartId(std::move( aStartId )),
71 m_aProgramSwitch(std::move( aProgramSwitch )),
72 m_aTitle(std::move( aTitle )),
73 m_nOrder( o3tl::toInt32(aOrder) )
77 const OUString& get_title() const { return m_aTitle; }
78 const OUString& get_id() const { return m_aStartId; }
79 const OUString& get_program() const { return m_aProgramSwitch; }
80 int get_order() const { return m_nOrder; }
81 }; // end class StaticModuleInformation
83 class KeywordInfo
85 public:
87 class KeywordElement
89 friend struct KeywordElementComparator;
90 friend class KeywordInfo;
92 public:
94 KeywordElement( Databases const * pDatabases,
95 helpdatafileproxy::Hdf* pHdf,
96 OUString key,
97 std::u16string_view ids );
99 private:
101 OUString key;
102 css::uno::Sequence< OUString > listId;
103 css::uno::Sequence< OUString > listAnchor;
104 css::uno::Sequence< OUString > listTitle;
106 void init( Databases const *pDatabases,helpdatafileproxy::Hdf* pHdf, std::u16string_view ids );
109 explicit KeywordInfo( const std::vector< KeywordElement >& aVector );
111 css::uno::Sequence< OUString >&
112 getKeywordList() { return listKey; }
114 css::uno::Sequence< css::uno::Sequence< OUString > >&
115 getIdList() { return listId; }
117 css::uno::Sequence< css::uno::Sequence< OUString > >&
118 getAnchorList() { return listAnchor; }
120 css::uno::Sequence< css::uno::Sequence< OUString > >&
121 getTitleList() { return listTitle; }
123 private:
125 css::uno::Sequence< OUString > listKey;
126 css::uno::Sequence< css::uno::Sequence< OUString > > listId,listAnchor,listTitle;
127 }; // end class KeywordInfo
129 class Databases
131 public:
134 * Input is the installdirectory in system dependent notation
137 Databases( bool showBasic,
138 const OUString& instPath,
139 const OUString& productName,
140 const OUString& productVersion,
141 const OUString& styleSheet,
142 css::uno::Reference< css::uno::XComponentContext > const & xContext );
144 ~Databases();
146 static OString getImageTheme();
148 OUString getInstallPathAsURL();
149 const OUString & getInstallPathAsURL(std::unique_lock<std::mutex>& rGuard);
151 const std::vector< OUString >& getModuleList( const OUString& Language );
153 StaticModuleInformation* getStaticInformationForModule( std::u16string_view Module,
154 const OUString& Language );
156 bool checkModuleMatchForExtension( std::u16string_view Database, const OUString& doclist );
157 KeywordInfo* getKeyword( const OUString& Module,
158 const OUString& Language );
160 helpdatafileproxy::Hdf* getHelpDataFile( std::u16string_view Module,
161 const OUString& Language, bool helpText = false,
162 const OUString* pExtensionPath = nullptr );
163 helpdatafileproxy::Hdf* getHelpDataFile(std::unique_lock<std::mutex>& rGuard,
164 std::u16string_view Module,
165 const OUString& Language, bool helpText = false,
166 const OUString* pExtensionPath = nullptr );
170 * The following method returns the Collator for the given language-country combination
172 css::uno::Reference< css::i18n::XCollator >
173 getCollator(std::unique_lock<std::mutex>& rGuard, const OUString& Language);
176 * Returns the cascading style sheet used to format the HTML-output.
177 * First try is language directory, second try is main installation directory.
180 void cascadingStylesheet( const OUString& Language,
181 OStringBuffer& buffer );
184 * Changes the stylesheet for further reads.
187 void changeCSS(const OUString& newStyleSheet);
190 * Returns the active help text for the given module, language and id.
193 void setActiveText( const OUString& Module,
194 const OUString& Language,
195 std::u16string_view Id,
196 OStringBuffer& buffer );
199 * Has the purpose of forcing the jarfile to stay open
202 css::uno::Reference< css::container::XHierarchicalNameAccess >
203 jarFile(std::unique_lock<std::mutex>& rGuard, std::u16string_view jar,
204 const OUString& Language );
206 css::uno::Reference< css::container::XHierarchicalNameAccess >
207 findJarFileForPath( const OUString& jar, const OUString& Language,
208 const OUString& path, OUString* o_pExtensionPath = nullptr,
209 OUString* o_pExtensionRegistryPath = nullptr );
212 * Maps a given language-locale combination to language or locale.
214 OUString processLang( const OUString& Language );
215 OUString processLang( std::unique_lock<std::mutex>& rGuard, const OUString& Language );
217 void replaceName( OUString& oustring ) const;
219 const OUString& getProductName() const { return m_vReplacement[0]; }
220 const OUString& getProductVersion() const { return m_vReplacement[1]; }
222 OUString expandURL( const OUString& aURL );
223 OUString expandURL( std::unique_lock<std::mutex>& rGuard, const OUString& aURL );
225 static OUString expandURL( const OUString& aURL,
226 const css::uno::Reference< css::uno::XComponentContext >& xContext );
228 private:
230 std::mutex m_aMutex;
231 css::uno::Reference< css::uno::XComponentContext > m_xContext;
232 css::uno::Reference< css::lang::XMultiComponentFactory > m_xSMgr;
233 css::uno::Reference< css::ucb::XSimpleFileAccess3 > m_xSFA;
235 bool m_bShowBasic;
237 std::vector<char> m_vCustomCSSDoc;
238 OUString m_aCSS;
240 enum {
241 PRODUCTNAME = 0,
242 PRODUCTVERSION,
243 VENDORNAME,
244 VENDORVERSION,
245 VENDORSHORT,
246 NEWPRODUCTNAME,
247 NEWPRODUCTVERSION
250 int m_vAdd[7];
251 OUString m_vReplacement[7];
253 OUString m_aInstallDirectory; // Installation directory
255 std::vector< OUString > m_avModules;
257 typedef std::unordered_map< OUString, std::unique_ptr<helpdatafileproxy::Hdf> > DatabasesTable;
258 DatabasesTable m_aDatabases; // Language and module dependent databases
260 typedef std::unordered_map< OUString,OUString > LangSetTable;
261 LangSetTable m_aLangSet; // Mapping to of lang-country to lang
263 typedef std::unordered_map< OUString, std::unique_ptr<StaticModuleInformation> > ModInfoTable;
264 ModInfoTable m_aModInfo; // Module information
266 typedef std::unordered_map< OUString, std::unique_ptr<KeywordInfo> > KeywordInfoTable;
267 KeywordInfoTable m_aKeywordInfo; // Module information
269 typedef
270 std::unordered_map<
271 OUString,
272 css::uno::Reference< css::container::XHierarchicalNameAccess > > ZipFileTable;
273 ZipFileTable m_aZipFileTable; // No closing of an once opened jarfile
275 typedef
276 std::unordered_map<
277 OUString,
278 css::uno::Reference< css::i18n::XCollator > > CollatorTable;
279 CollatorTable m_aCollatorTable;
282 typedef
283 std::unordered_set<
284 OString > EmptyActiveTextSet;
285 EmptyActiveTextSet m_aEmptyActiveTextSet;
287 // methods
289 void setInstallPath( const OUString& aInstallDirectory );
291 }; // end class Databases
293 enum class IteratorState
295 InitialModule,
296 //SHARED_MODULE, // Later, avoids redundancies in help compiling
297 UserExtensions,
298 SharedExtensions,
299 BundledExtensions,
300 EndReached
303 // Hashtable to cache extension help status
304 typedef std::unordered_map
306 OUString,
307 bool
309 ExtensionHelpExistenceMap;
311 class ExtensionIteratorBase
313 static ExtensionHelpExistenceMap aHelpExistenceMap;
315 public:
316 ExtensionIteratorBase( css::uno::Reference< css::uno::XComponentContext > const & xContext,
317 Databases& rDatabases, OUString aInitialModule, OUString aLanguage );
318 ExtensionIteratorBase( Databases& rDatabases, OUString aInitialModule,
319 OUString aLanguage );
320 void init();
322 private:
323 static css::uno::Reference< css::deployment::XPackage > implGetHelpPackageFromPackage
324 ( const css::uno::Reference< css::deployment::XPackage >& xPackage,
325 css::uno::Reference< css::deployment::XPackage >& o_xParentPackageBundle );
327 protected:
328 css::uno::Reference< css::deployment::XPackage > implGetNextUserHelpPackage
329 ( css::uno::Reference< css::deployment::XPackage >& o_xParentPackageBundle );
330 css::uno::Reference< css::deployment::XPackage > implGetNextSharedHelpPackage
331 ( css::uno::Reference< css::deployment::XPackage >& o_xParentPackageBundle );
332 css::uno::Reference< css::deployment::XPackage > implGetNextBundledHelpPackage
333 ( css::uno::Reference< css::deployment::XPackage >& o_xParentPackageBundle );
334 OUString implGetFileFromPackage( std::u16string_view rFileExtension,
335 const css::uno::Reference< css::deployment::XPackage >& xPackage );
336 OUString implGetFileFromPackage(std::unique_lock<std::mutex>& rGuard,
337 std::u16string_view rFileExtension,
338 const css::uno::Reference< css::deployment::XPackage >& xPackage );
339 void implGetLanguageVectorFromPackage( ::std::vector< OUString > &rv,
340 const css::uno::Reference< css::deployment::XPackage >& xPackage );
342 css::uno::Reference< css::uno::XComponentContext > m_xContext;
343 css::uno::Reference< css::ucb::XSimpleFileAccess3 > m_xSFA;
344 Databases& m_rDatabases;
346 IteratorState m_eState;
348 OUString m_aInitialModule;
349 OUString m_aLanguage;
351 css::uno::Sequence< css::uno::Reference
352 < css::deployment::XPackage > > m_aUserPackagesSeq;
353 bool m_bUserPackagesLoaded;
355 css::uno::Sequence< css::uno::Reference
356 < css::deployment::XPackage > > m_aSharedPackagesSeq;
357 bool m_bSharedPackagesLoaded;
359 css::uno::Sequence< css::uno::Reference
360 < css::deployment::XPackage > > m_aBundledPackagesSeq;
361 bool m_bBundledPackagesLoaded;
363 int m_iUserPackage;
364 int m_iSharedPackage;
365 int m_iBundledPackage;
367 }; // end class ExtensionIteratorBase
369 class DataBaseIterator : public ExtensionIteratorBase
371 public:
372 DataBaseIterator( css::uno::Reference< css::uno::XComponentContext > const & xContext,
373 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage, bool bHelpText )
374 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
375 , m_bHelpText( bHelpText )
377 DataBaseIterator( Databases& rDatabases, const OUString& aInitialModule,
378 const OUString& aLanguage, bool bHelpText )
379 : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
380 , m_bHelpText( bHelpText )
383 helpdatafileproxy::Hdf* nextHdf( OUString* o_pExtensionPath = nullptr, OUString* o_pExtensionRegistryPath = nullptr );
385 private:
386 helpdatafileproxy::Hdf* implGetHdfFromPackage(
387 const css::uno::Reference< css::deployment::XPackage >& xPackage,
388 OUString* o_pExtensionPath, OUString* o_pExtensionRegistryPath );
390 bool m_bHelpText;
392 }; // end class DataBaseIterator
394 class KeyDataBaseFileIterator : public ExtensionIteratorBase
396 public:
397 KeyDataBaseFileIterator( css::uno::Reference< css::uno::XComponentContext > const & xContext,
398 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
399 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
401 //Returns a file URL
402 OUString nextDbFile(std::unique_lock<std::mutex>& rGuard, bool& o_rbExtension);
404 private:
405 OUString implGetDbFileFromPackage(std::unique_lock<std::mutex>& rGuard,
406 const css::uno::Reference< css::deployment::XPackage >& xPackage );
408 }; // end class KeyDataBaseFileIterator
410 class JarFileIterator : public ExtensionIteratorBase
412 public:
413 JarFileIterator( css::uno::Reference< css::uno::XComponentContext > const & xContext,
414 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
415 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
418 css::uno::Reference< css::container::XHierarchicalNameAccess >
419 nextJarFile(std::unique_lock<std::mutex>& rGuard,
420 css::uno::Reference<css::deployment::XPackage>& o_xParentPackageBundle,
421 OUString* o_pExtensionPath, OUString* o_pExtensionRegistryPath );
423 private:
424 css::uno::Reference< css::container::XHierarchicalNameAccess >
425 implGetJarFromPackage(std::unique_lock<std::mutex>& rGuard,
426 const css::uno::Reference< css::deployment::XPackage >& xPackage,
427 OUString* o_pExtensionPath, OUString* o_pExtensionRegistryPath );
429 }; // end class JarFileIterator
431 class IndexFolderIterator : public ExtensionIteratorBase
433 public:
434 IndexFolderIterator( Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
435 : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
438 OUString nextIndexFolder( bool& o_rbExtension, bool& o_rbTemporary );
439 void deleteTempIndexFolder( std::u16string_view aIndexFolder );
441 private:
442 OUString implGetIndexFolderFromPackage( bool& o_rbTemporary,
443 const css::uno::Reference< css::deployment::XPackage >& xPackage );
445 }; // end class KeyDataBaseFileIterator
447 } // end namespace chelp
449 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */