bump product version to 5.0.4.1
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / databases.hxx
blob50d61236c5355915cb946ab65212b967de5055da
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 <set>
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/ucb/XContent.hpp>
34 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
35 #include <com/sun/star/io/XInputStream.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 OUString m_aHeading;
63 OUString m_aFulltext;
64 int m_nOrder;
66 public:
68 StaticModuleInformation( const OUString& aTitle,
69 const OUString& aStartId,
70 const OUString& aProgramSwitch,
71 const OUString& aHeading,
72 const OUString& aFulltext,
73 const OUString& aOrder )
74 : m_aStartId( aStartId ),
75 m_aProgramSwitch( aProgramSwitch ),
76 m_aTitle( aTitle ),
77 m_aHeading( aHeading ),
78 m_aFulltext( aFulltext ),
79 m_nOrder( aOrder.toInt32() )
83 ~StaticModuleInformation() { }
85 OUString get_title() const { return m_aTitle; }
86 OUString get_id() const { return m_aStartId; }
87 OUString get_program() const { return m_aProgramSwitch; }
88 OUString get_heading() const { return m_aHeading; }
89 OUString get_fulltext() const { return m_aFulltext; }
90 int get_order() const { return m_nOrder; }
91 }; // end class StaticModuleInformation
93 class KeywordInfo
95 public:
97 class KeywordElement
99 friend struct KeywordElementComparator;
100 friend class KeywordInfo;
102 public:
104 KeywordElement( Databases* pDatabases,
105 helpdatafileproxy::Hdf* pHdf,
106 OUString& key,
107 OUString& ids );
109 private:
111 OUString key;
112 com::sun::star::uno::Sequence< OUString > listId;
113 com::sun::star::uno::Sequence< OUString > listAnchor;
114 com::sun::star::uno::Sequence< OUString > listTitle;
116 void init( Databases *pDatabases,helpdatafileproxy::Hdf* pHdf,const OUString& ids );
119 KeywordInfo( const std::vector< KeywordElement >& aVector );
121 ~KeywordInfo() { };
123 com::sun::star::uno::Sequence< OUString >&
124 getKeywordList() { return listKey; }
126 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > >&
127 getIdList() { return listId; }
129 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > >&
130 getAnchorList() { return listAnchor; }
132 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > >&
133 getTitleList() { return listTitle; }
135 private:
137 com::sun::star::uno::Sequence< OUString > listKey;
138 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > > listId,listAnchor,listTitle;
139 }; // end class KeywordInfo
141 class Databases
143 public:
146 * Input is the installdirectory in system dependent notation
149 Databases( bool showBasic,
150 const OUString& instPath,
151 const OUString& productName,
152 const OUString& productVersion,
153 const OUString& styleSheet,
154 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext );
156 ~Databases();
158 OString getImageTheme();
160 OUString getInstallPathAsURL();
162 const std::vector< OUString >& getModuleList( const OUString& Language );
164 StaticModuleInformation* getStaticInformationForModule( const OUString& Module,
165 const OUString& Language );
167 bool checkModuleMatchForExtension( const OUString& Database, const OUString& doclist );
168 KeywordInfo* getKeyword( const OUString& Module,
169 const OUString& Language );
171 helpdatafileproxy::Hdf* getHelpDataFile( const OUString& Module,
172 const OUString& Language, bool helpText = false,
173 const OUString* pExtensionPath = NULL );
176 * The following method returns the Collator for the given language-country combination
179 com::sun::star::uno::Reference< com::sun::star::i18n::XCollator >
180 getCollator( const OUString& Language,
181 const OUString& System ); // System not used by current implementation
182 // // of XCollator
185 * Returns the cascading style sheet used to format the HTML-output.
186 * First try is language directory, second try is main installation directory.
189 void cascadingStylesheet( const OUString& Language,
190 char** buffer,
191 int* byteCount );
194 * Changes the stylesheet for further reads.
197 void changeCSS(const OUString& newStyleSheet);
200 * Returns the active help text for the given module, language and id.
203 void setActiveText( const OUString& Module,
204 const OUString& Language,
205 const OUString& Id,
206 char** buffer,
207 int* byteCount );
210 * Has the purpose of forcing the jarfile to stay open
213 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
214 jarFile( const OUString& jar,
215 const OUString& Language );
217 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
218 findJarFileForPath( const OUString& jar, const OUString& Language,
219 const OUString& path, OUString* o_pExtensionPath = NULL,
220 OUString* o_pExtensionRegistryPath = NULL );
223 * Maps a given language-locale combination to language.
226 OUString processLang( const OUString& Language );
229 * Maps a given language-locale combination to locale.
230 * The returned string maybe empty
233 static OUString country( const OUString& Language );
235 void replaceName( OUString& oustring ) const;
237 OUString getProductName() const { return m_vReplacement[0]; }
238 OUString getProductVersion() const { return m_vReplacement[1]; }
240 OUString expandURL( const OUString& aURL );
242 static OUString expandURL( const OUString& aURL,
243 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext );
245 private:
247 osl::Mutex m_aMutex;
248 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
249 com::sun::star::uno::Reference< com::sun::star::lang::XMultiComponentFactory > m_xSMgr;
250 com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 > m_xSFA;
252 bool m_bShowBasic;
253 char* m_pErrorDoc;
255 int m_nCustomCSSDocLength;
256 char* m_pCustomCSSDoc;
257 OUString m_aCSS;
259 enum {
260 PRODUCTNAME = 0,
261 PRODUCTVERSION,
262 VENDORNAME,
263 VENDORVERSION,
264 VENDORSHORT,
265 NEWPRODUCTNAME,
266 NEWPRODUCTVERSION
269 int m_vAdd[7];
270 OUString m_vReplacement[7];
271 OUString newProdName,newProdVersion,
272 prodName,prodVersion,vendName,vendVersion,vendShort;
274 OUString m_aInstallDirectory; // Installation directory
276 std::vector< OUString > m_avModules;
278 typedef std::unordered_map< OUString,helpdatafileproxy::Hdf*,OUStringHash > DatabasesTable;
279 DatabasesTable m_aDatabases; // Language and module dependent databases
281 typedef std::unordered_map< OUString,OUString,OUStringHash > LangSetTable;
282 LangSetTable m_aLangSet; // Mapping to of lang-country to lang
284 typedef std::unordered_map< OUString,StaticModuleInformation*,OUStringHash > ModInfoTable;
285 ModInfoTable m_aModInfo; // Module information
287 typedef std::unordered_map< OUString,KeywordInfo*,OUStringHash > KeywordInfoTable;
288 KeywordInfoTable m_aKeywordInfo; // Module information
290 typedef
291 std::unordered_map<
292 OUString,
293 ::com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >,
294 OUStringHash > ZipFileTable;
295 ZipFileTable m_aZipFileTable; // No closing of an once opened jarfile
297 typedef
298 std::unordered_map<
299 OUString,
300 ::com::sun::star::uno::Reference< com::sun::star::i18n::XCollator >,
301 OUStringHash > CollatorTable;
302 CollatorTable m_aCollatorTable;
305 typedef
306 std::unordered_set<
307 OString,
308 OStringHash > EmptyActiveTextSet;
309 EmptyActiveTextSet m_aEmptyActiveTextSet;
311 // methods
313 void setInstallPath( const OUString& aInstallDirectory );
315 }; // end class Databases
317 enum IteratorState
319 INITIAL_MODULE,
320 //SHARED_MODULE, // Later, avoids redundancies in help compiling
321 USER_EXTENSIONS,
322 SHARED_EXTENSIONS,
323 BUNDLED_EXTENSIONS,
324 END_REACHED
327 // Hashtable to cache extension help status
328 typedef std::unordered_map
330 OUString,
331 bool,
332 OUStringHash
334 ExtensionHelpExistanceMap;
336 class ExtensionIteratorBase
338 static ExtensionHelpExistanceMap aHelpExistanceMap;
340 public:
341 ExtensionIteratorBase( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
342 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage );
343 ExtensionIteratorBase( Databases& rDatabases, const OUString& aInitialModule,
344 const OUString& aLanguage );
345 void init();
347 private:
348 static com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetHelpPackageFromPackage
349 ( const com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
350 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
352 protected:
353 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextUserHelpPackage
354 ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
355 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextSharedHelpPackage
356 ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
357 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextBundledHelpPackage
358 ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
359 OUString implGetFileFromPackage( const OUString& rFileExtension,
360 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
361 void implGetLanguageVectorFromPackage( ::std::vector< OUString > &rv,
362 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
364 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
365 com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 > m_xSFA;
366 Databases& m_rDatabases;
368 IteratorState m_eState;
369 OUString m_aExtensionPath;
371 OUString m_aInitialModule;
372 OUString m_aLanguage;
374 com::sun::star::uno::Sequence< com::sun::star::uno::Reference
375 < com::sun::star::deployment::XPackage > > m_aUserPackagesSeq;
376 bool m_bUserPackagesLoaded;
378 com::sun::star::uno::Sequence< com::sun::star::uno::Reference
379 < com::sun::star::deployment::XPackage > > m_aSharedPackagesSeq;
380 bool m_bSharedPackagesLoaded;
382 com::sun::star::uno::Sequence< com::sun::star::uno::Reference
383 < com::sun::star::deployment::XPackage > > m_aBundledPackagesSeq;
384 bool m_bBundledPackagesLoaded;
386 int m_iUserPackage;
387 int m_iSharedPackage;
388 int m_iBundledPackage;
390 }; // end class ExtensionIteratorBase
392 class DataBaseIterator : public ExtensionIteratorBase
394 public:
395 DataBaseIterator( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
396 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage, bool bHelpText )
397 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
398 , m_bHelpText( bHelpText )
400 DataBaseIterator( Databases& rDatabases, const OUString& aInitialModule,
401 const OUString& aLanguage, bool bHelpText )
402 : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
403 , m_bHelpText( bHelpText )
406 helpdatafileproxy::Hdf* nextHdf( OUString* o_pExtensionPath = NULL, OUString* o_pExtensionRegistryPath = NULL );
408 private:
409 helpdatafileproxy::Hdf* implGetHdfFromPackage(
410 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
411 OUString* o_pExtensionPath, OUString* o_pExtensionRegistryPath );
413 bool m_bHelpText;
415 }; // end class DataBaseIterator
417 class KeyDataBaseFileIterator : public ExtensionIteratorBase
419 public:
420 KeyDataBaseFileIterator( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
421 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
422 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
424 //Returns a file URL
425 OUString nextDbFile( bool& o_rbExtension );
427 private:
428 OUString implGetDbFileFromPackage(
429 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
431 }; // end class KeyDataBaseFileIterator
433 class JarFileIterator : public ExtensionIteratorBase
435 public:
436 JarFileIterator( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
437 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
438 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
441 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
442 nextJarFile( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle,
443 OUString* o_pExtensionPath = NULL, OUString* o_pExtensionRegistryPath = NULL );
445 private:
446 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
447 implGetJarFromPackage(com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
448 OUString* o_pExtensionPath = NULL, OUString* o_pExtensionRegistryPath = NULL );
450 }; // end class JarFileIterator
452 class IndexFolderIterator : public ExtensionIteratorBase
454 public:
455 IndexFolderIterator( Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
456 : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
459 OUString nextIndexFolder( bool& o_rbExtension, bool& o_rbTemporary );
460 void deleteTempIndexFolder( const OUString& aIndexFolder );
462 private:
463 OUString implGetIndexFolderFromPackage( bool& o_rbTemporary,
464 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
466 }; // end class KeyDataBaseFileIterator
468 } // end namespace chelp
470 #endif
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */