nss: upgrade to release 3.73
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / databases.hxx
blobf45032da7e12fd2fa429bad9a9e3c210f2651817
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 #ifndef INCLUDED_XMLHELP_SOURCE_CXXHELP_PROVIDER_DATABASES_HXX
21 #define INCLUDED_XMLHELP_SOURCE_CXXHELP_PROVIDER_DATABASES_HXX
23 #include <sal/config.h>
25 #include <memory>
26 #include <unordered_map>
27 #include <unordered_set>
28 #include <vector>
29 #include <osl/mutex.hxx>
30 #include <rtl/ustring.hxx>
31 #include <rtl/string.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
34 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <com/sun/star/i18n/XCollator.hpp>
37 #include <com/sun/star/deployment/XPackage.hpp>
38 #include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
40 // Forward declaration
42 namespace helpdatafileproxy {
44 class Hdf;
48 namespace chelp {
50 class Databases;
51 class URLParameter;
53 class StaticModuleInformation
55 private:
57 OUString m_aStartId;
58 OUString m_aProgramSwitch;
59 OUString m_aTitle;
60 int m_nOrder;
62 public:
64 StaticModuleInformation( const OUString& aTitle,
65 const OUString& aStartId,
66 const OUString& aProgramSwitch,
67 const OUString& aOrder )
68 : m_aStartId( aStartId ),
69 m_aProgramSwitch( aProgramSwitch ),
70 m_aTitle( aTitle ),
71 m_nOrder( aOrder.toInt32() )
75 const OUString& get_title() const { return m_aTitle; }
76 const OUString& get_id() const { return m_aStartId; }
77 const OUString& get_program() const { return m_aProgramSwitch; }
78 int get_order() const { return m_nOrder; }
79 }; // end class StaticModuleInformation
81 class KeywordInfo
83 public:
85 class KeywordElement
87 friend struct KeywordElementComparator;
88 friend class KeywordInfo;
90 public:
92 KeywordElement( Databases const * pDatabases,
93 helpdatafileproxy::Hdf* pHdf,
94 OUString const & key,
95 OUString const & ids );
97 private:
99 OUString key;
100 css::uno::Sequence< OUString > listId;
101 css::uno::Sequence< OUString > listAnchor;
102 css::uno::Sequence< OUString > listTitle;
104 void init( Databases const *pDatabases,helpdatafileproxy::Hdf* pHdf,const OUString& ids );
107 explicit KeywordInfo( const std::vector< KeywordElement >& aVector );
109 css::uno::Sequence< OUString >&
110 getKeywordList() { return listKey; }
112 css::uno::Sequence< css::uno::Sequence< OUString > >&
113 getIdList() { return listId; }
115 css::uno::Sequence< css::uno::Sequence< OUString > >&
116 getAnchorList() { return listAnchor; }
118 css::uno::Sequence< css::uno::Sequence< OUString > >&
119 getTitleList() { return listTitle; }
121 private:
123 css::uno::Sequence< OUString > listKey;
124 css::uno::Sequence< css::uno::Sequence< OUString > > listId,listAnchor,listTitle;
125 }; // end class KeywordInfo
127 class Databases
129 public:
132 * Input is the installdirectory in system dependent notation
135 Databases( bool showBasic,
136 const OUString& instPath,
137 const OUString& productName,
138 const OUString& productVersion,
139 const OUString& styleSheet,
140 css::uno::Reference< css::uno::XComponentContext > const & xContext );
142 ~Databases();
144 OString getImageTheme() const;
146 OUString getInstallPathAsURL();
148 const std::vector< OUString >& getModuleList( const OUString& Language );
150 StaticModuleInformation* getStaticInformationForModule( const OUString& Module,
151 const OUString& Language );
153 bool checkModuleMatchForExtension( const OUString& Database, const OUString& doclist );
154 KeywordInfo* getKeyword( const OUString& Module,
155 const OUString& Language );
157 helpdatafileproxy::Hdf* getHelpDataFile( const OUString& Module,
158 const OUString& Language, bool helpText = false,
159 const OUString* pExtensionPath = nullptr );
162 * The following method returns the Collator for the given language-country combination
164 css::uno::Reference< css::i18n::XCollator >
165 getCollator( const OUString& Language );
168 * Returns the cascading style sheet used to format the HTML-output.
169 * First try is language directory, second try is main installation directory.
172 void cascadingStylesheet( const OUString& Language,
173 OStringBuffer& buffer );
176 * Changes the stylesheet for further reads.
179 void changeCSS(const OUString& newStyleSheet);
182 * Returns the active help text for the given module, language and id.
185 void setActiveText( const OUString& Module,
186 const OUString& Language,
187 const OUString& Id,
188 OStringBuffer& buffer );
191 * Has the purpose of forcing the jarfile to stay open
194 css::uno::Reference< css::container::XHierarchicalNameAccess >
195 jarFile( const OUString& jar,
196 const OUString& Language );
198 css::uno::Reference< css::container::XHierarchicalNameAccess >
199 findJarFileForPath( const OUString& jar, const OUString& Language,
200 const OUString& path, OUString* o_pExtensionPath = nullptr,
201 OUString* o_pExtensionRegistryPath = nullptr );
204 * Maps a given language-locale combination to language or locale.
207 OUString processLang( const OUString& Language );
209 void replaceName( OUString& oustring ) const;
211 const OUString& getProductName() const { return m_vReplacement[0]; }
212 const OUString& getProductVersion() const { return m_vReplacement[1]; }
214 OUString expandURL( const OUString& aURL );
216 static OUString expandURL( const OUString& aURL,
217 const css::uno::Reference< css::uno::XComponentContext >& xContext );
219 private:
221 osl::Mutex m_aMutex;
222 css::uno::Reference< css::uno::XComponentContext > m_xContext;
223 css::uno::Reference< css::lang::XMultiComponentFactory > m_xSMgr;
224 css::uno::Reference< css::ucb::XSimpleFileAccess3 > m_xSFA;
226 bool m_bShowBasic;
228 std::vector<char> m_vCustomCSSDoc;
229 OUString m_aCSS;
231 enum {
232 PRODUCTNAME = 0,
233 PRODUCTVERSION,
234 VENDORNAME,
235 VENDORVERSION,
236 VENDORSHORT,
237 NEWPRODUCTNAME,
238 NEWPRODUCTVERSION
241 int m_vAdd[7];
242 OUString m_vReplacement[7];
244 OUString m_aInstallDirectory; // Installation directory
246 std::vector< OUString > m_avModules;
248 typedef std::unordered_map< OUString, std::unique_ptr<helpdatafileproxy::Hdf> > DatabasesTable;
249 DatabasesTable m_aDatabases; // Language and module dependent databases
251 typedef std::unordered_map< OUString,OUString > LangSetTable;
252 LangSetTable m_aLangSet; // Mapping to of lang-country to lang
254 typedef std::unordered_map< OUString, std::unique_ptr<StaticModuleInformation> > ModInfoTable;
255 ModInfoTable m_aModInfo; // Module information
257 typedef std::unordered_map< OUString, std::unique_ptr<KeywordInfo> > KeywordInfoTable;
258 KeywordInfoTable m_aKeywordInfo; // Module information
260 typedef
261 std::unordered_map<
262 OUString,
263 css::uno::Reference< css::container::XHierarchicalNameAccess > > ZipFileTable;
264 ZipFileTable m_aZipFileTable; // No closing of an once opened jarfile
266 typedef
267 std::unordered_map<
268 OUString,
269 css::uno::Reference< css::i18n::XCollator > > CollatorTable;
270 CollatorTable m_aCollatorTable;
273 typedef
274 std::unordered_set<
275 OString > EmptyActiveTextSet;
276 EmptyActiveTextSet m_aEmptyActiveTextSet;
278 // methods
280 void setInstallPath( const OUString& aInstallDirectory );
282 }; // end class Databases
284 enum class IteratorState
286 InitialModule,
287 //SHARED_MODULE, // Later, avoids redundancies in help compiling
288 UserExtensions,
289 SharedExtensions,
290 BundledExtensions,
291 EndReached
294 // Hashtable to cache extension help status
295 typedef std::unordered_map
297 OUString,
298 bool
300 ExtensionHelpExistenceMap;
302 class ExtensionIteratorBase
304 static ExtensionHelpExistenceMap aHelpExistenceMap;
306 public:
307 ExtensionIteratorBase( css::uno::Reference< css::uno::XComponentContext > const & xContext,
308 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage );
309 ExtensionIteratorBase( Databases& rDatabases, const OUString& aInitialModule,
310 const OUString& aLanguage );
311 void init();
313 private:
314 static css::uno::Reference< css::deployment::XPackage > implGetHelpPackageFromPackage
315 ( const css::uno::Reference< css::deployment::XPackage >& xPackage,
316 css::uno::Reference< css::deployment::XPackage >& o_xParentPackageBundle );
318 protected:
319 css::uno::Reference< css::deployment::XPackage > implGetNextUserHelpPackage
320 ( css::uno::Reference< css::deployment::XPackage >& o_xParentPackageBundle );
321 css::uno::Reference< css::deployment::XPackage > implGetNextSharedHelpPackage
322 ( css::uno::Reference< css::deployment::XPackage >& o_xParentPackageBundle );
323 css::uno::Reference< css::deployment::XPackage > implGetNextBundledHelpPackage
324 ( css::uno::Reference< css::deployment::XPackage >& o_xParentPackageBundle );
325 OUString implGetFileFromPackage( const OUString& rFileExtension,
326 const css::uno::Reference< css::deployment::XPackage >& xPackage );
327 void implGetLanguageVectorFromPackage( ::std::vector< OUString > &rv,
328 const css::uno::Reference< css::deployment::XPackage >& xPackage );
330 css::uno::Reference< css::uno::XComponentContext > m_xContext;
331 css::uno::Reference< css::ucb::XSimpleFileAccess3 > m_xSFA;
332 Databases& m_rDatabases;
334 IteratorState m_eState;
336 OUString m_aInitialModule;
337 OUString m_aLanguage;
339 css::uno::Sequence< css::uno::Reference
340 < css::deployment::XPackage > > m_aUserPackagesSeq;
341 bool m_bUserPackagesLoaded;
343 css::uno::Sequence< css::uno::Reference
344 < css::deployment::XPackage > > m_aSharedPackagesSeq;
345 bool m_bSharedPackagesLoaded;
347 css::uno::Sequence< css::uno::Reference
348 < css::deployment::XPackage > > m_aBundledPackagesSeq;
349 bool m_bBundledPackagesLoaded;
351 int m_iUserPackage;
352 int m_iSharedPackage;
353 int m_iBundledPackage;
355 }; // end class ExtensionIteratorBase
357 class DataBaseIterator : public ExtensionIteratorBase
359 public:
360 DataBaseIterator( css::uno::Reference< css::uno::XComponentContext > const & xContext,
361 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage, bool bHelpText )
362 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
363 , m_bHelpText( bHelpText )
365 DataBaseIterator( Databases& rDatabases, const OUString& aInitialModule,
366 const OUString& aLanguage, bool bHelpText )
367 : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
368 , m_bHelpText( bHelpText )
371 helpdatafileproxy::Hdf* nextHdf( OUString* o_pExtensionPath = nullptr, OUString* o_pExtensionRegistryPath = nullptr );
373 private:
374 helpdatafileproxy::Hdf* implGetHdfFromPackage(
375 const css::uno::Reference< css::deployment::XPackage >& xPackage,
376 OUString* o_pExtensionPath, OUString* o_pExtensionRegistryPath );
378 bool m_bHelpText;
380 }; // end class DataBaseIterator
382 class KeyDataBaseFileIterator : public ExtensionIteratorBase
384 public:
385 KeyDataBaseFileIterator( css::uno::Reference< css::uno::XComponentContext > const & xContext,
386 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
387 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
389 //Returns a file URL
390 OUString nextDbFile( bool& o_rbExtension );
392 private:
393 OUString implGetDbFileFromPackage(
394 const css::uno::Reference< css::deployment::XPackage >& xPackage );
396 }; // end class KeyDataBaseFileIterator
398 class JarFileIterator : public ExtensionIteratorBase
400 public:
401 JarFileIterator( css::uno::Reference< css::uno::XComponentContext > const & xContext,
402 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
403 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
406 css::uno::Reference< css::container::XHierarchicalNameAccess >
407 nextJarFile( css::uno::Reference< css::deployment::XPackage >& o_xParentPackageBundle,
408 OUString* o_pExtensionPath, OUString* o_pExtensionRegistryPath );
410 private:
411 css::uno::Reference< css::container::XHierarchicalNameAccess >
412 implGetJarFromPackage(const css::uno::Reference< css::deployment::XPackage >& xPackage,
413 OUString* o_pExtensionPath, OUString* o_pExtensionRegistryPath );
415 }; // end class JarFileIterator
417 class IndexFolderIterator : public ExtensionIteratorBase
419 public:
420 IndexFolderIterator( Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
421 : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
424 OUString nextIndexFolder( bool& o_rbExtension, bool& o_rbTemporary );
425 void deleteTempIndexFolder( const OUString& aIndexFolder );
427 private:
428 OUString implGetIndexFolderFromPackage( bool& o_rbTemporary,
429 const css::uno::Reference< css::deployment::XPackage >& xPackage );
431 }; // end class KeyDataBaseFileIterator
433 } // end namespace chelp
435 #endif
437 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */