fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / databases.hxx
blob85857003761d39c269b2c296e4790f0dc70bfa95
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 _DATABASES_HXX_
21 #define _DATABASES_HXX_
23 #include <set>
24 #include <vector>
25 #ifndef HAVE_CXX0X
26 #define BOOST_NO_0X_HDR_TYPEINDEX
27 #endif
28 #include <boost/unordered_map.hpp>
29 #include <boost/unordered_set.hpp>
30 #include <osl/mutex.hxx>
31 #include <rtl/ustring.hxx>
32 #include <rtl/string.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <com/sun/star/ucb/XContent.hpp>
35 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
36 #include <com/sun/star/io/XInputStream.hpp>
37 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <com/sun/star/i18n/XCollator.hpp>
40 #include <com/sun/star/deployment/XPackage.hpp>
41 #include "com/sun/star/ucb/XSimpleFileAccess3.hpp"
43 // Forward declaration
46 namespace helpdatafileproxy {
48 class Hdf;
53 namespace chelp {
56 class Databases;
57 class URLParameter;
59 class StaticModuleInformation
61 private:
63 OUString m_aStartId;
64 OUString m_aProgramSwitch;
65 OUString m_aTitle;
66 OUString m_aHeading;
67 OUString m_aFulltext;
68 int m_nOrder;
71 public:
73 StaticModuleInformation( OUString aTitle,
74 OUString aStartId,
75 OUString aProgramSwitch,
76 OUString aHeading,
77 OUString aFulltext,
78 OUString aOrder )
79 : m_aStartId( aStartId ),
80 m_aProgramSwitch( aProgramSwitch ),
81 m_aTitle( aTitle ),
82 m_aHeading( aHeading ),
83 m_aFulltext( aFulltext ),
84 m_nOrder( aOrder.toInt32() )
88 ~StaticModuleInformation() { }
90 OUString get_title() const { return m_aTitle; }
91 OUString get_id() const { return m_aStartId; }
92 OUString get_program() const { return m_aProgramSwitch; }
93 OUString get_heading() const { return m_aHeading; }
94 OUString get_fulltext() const { return m_aFulltext; }
95 int get_order() const { return m_nOrder; }
96 }; // end class StaticModuleInformation
100 class KeywordInfo
102 public:
104 class KeywordElement
106 friend struct KeywordElementComparator;
107 friend class KeywordInfo;
109 public:
111 KeywordElement( Databases* pDatabases,
112 helpdatafileproxy::Hdf* pHdf,
113 OUString& key,
114 OUString& ids );
116 private:
118 OUString key;
119 com::sun::star::uno::Sequence< OUString > listId;
120 com::sun::star::uno::Sequence< OUString > listAnchor;
121 com::sun::star::uno::Sequence< OUString > listTitle;
123 void init( Databases *pDatabases,helpdatafileproxy::Hdf* pHdf,const OUString& ids );
127 KeywordInfo( const std::vector< KeywordElement >& aVector );
129 ~KeywordInfo() { };
131 com::sun::star::uno::Sequence< OUString >&
132 getKeywordList() { return listKey; }
134 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > >&
135 getIdList() { return listId; }
137 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > >&
138 getAnchorList() { return listAnchor; }
140 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > >&
141 getTitleList() { return listTitle; }
143 private:
145 com::sun::star::uno::Sequence< OUString > listKey;
146 com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > > listId,listAnchor,listTitle;
147 }; // end class KeywordInfo
151 class Databases
153 public:
155 struct eq
157 bool operator()( const OUString& rKey1, const OUString& rKey2 ) const
159 return (rKey1 == rKey2);
163 struct ha
165 size_t operator()( const OUString& rName ) const
167 return rName.hashCode();
173 * Input is the installdirectory in system dependent notation
176 Databases( sal_Bool showBasic,
177 const OUString& instPath,
178 const com::sun::star::uno::Sequence< OUString >& imagesZipPaths,
179 const OUString& productName,
180 const OUString& productVersion,
181 const OUString& styleSheet,
182 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext );
184 ~Databases();
186 OString getImagesZipFileURL();
188 OUString getInstallPathAsURL();
190 const std::vector< OUString >& getModuleList( const OUString& Language );
192 StaticModuleInformation* getStaticInformationForModule( const OUString& Module,
193 const OUString& Language );
195 bool checkModuleMatchForExtension( const OUString& Database, const OUString& doclist );
196 KeywordInfo* getKeyword( const OUString& Module,
197 const OUString& Language );
199 helpdatafileproxy::Hdf* getHelpDataFile( const OUString& Module,
200 const OUString& Language, bool helpText = false,
201 const OUString* pExtensionPath = NULL );
205 * The following method returns the Collator for the given language-country combination
208 com::sun::star::uno::Reference< com::sun::star::i18n::XCollator >
209 getCollator( const OUString& Language,
210 const OUString& System ); // System not used by current implementation
211 // // of XCollator
214 * Returns a copy of the popupfile
217 void popupDocument( URLParameter* urlPar,char **buffer,int *byteCount );
221 * Returns the cascading stlye sheet used to format the HTML-output.
222 * First try is language directory, second try is main installation directory.
225 void cascadingStylesheet( const OUString& Language,
226 char** buffer,
227 int* byteCount );
231 * Changes the stylesheet for further reads.
234 void changeCSS(const OUString& newStyleSheet);
238 * Returns the active help text for the given module, language and id.
241 void setActiveText( const OUString& Module,
242 const OUString& Language,
243 const OUString& Id,
244 char** buffer,
245 int* byteCount );
248 * Has the purpose of forcing the jarfile to stay open
251 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
252 jarFile( const OUString& jar,
253 const OUString& Language );
255 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
256 findJarFileForPath( const OUString& jar, const OUString& Language,
257 const OUString& path, OUString* o_pExtensionPath = NULL,
258 OUString* o_pExtensionRegistryPath = NULL );
261 * Maps a given language-locale combination to language.
264 OUString processLang( const OUString& Language );
268 * Maps a given language-locale combination to locale.
269 * The returned string maybe empty
272 OUString country( const OUString& Language );
275 void replaceName( OUString& oustring ) const;
277 OUString getProductName() const { return m_vReplacement[0]; }
278 OUString getProductVersion() const { return m_vReplacement[1]; }
280 OUString expandURL( const OUString& aURL );
282 static OUString expandURL( const OUString& aURL,
283 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext );
285 private:
287 osl::Mutex m_aMutex;
288 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
289 com::sun::star::uno::Reference< com::sun::star::lang::XMultiComponentFactory > m_xSMgr;
290 com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 > m_xSFA;
292 bool m_bShowBasic;
293 char* m_pErrorDoc;
295 int m_nCustomCSSDocLength;
296 char* m_pCustomCSSDoc;
297 OUString m_aCSS;
299 enum {
300 PRODUCTNAME = 0,
301 PRODUCTVERSION,
302 VENDORNAME,
303 VENDORVERSION,
304 VENDORSHORT,
305 NEWPRODUCTNAME,
306 NEWPRODUCTVERSION
309 int m_vAdd[7];
310 OUString m_vReplacement[7];
311 OUString newProdName,newProdVersion,
312 prodName,prodVersion,vendName,vendVersion,vendShort;
314 OUString m_aInstallDirectory; // Installation directory
315 com::sun::star::uno::Sequence< OUString > m_aImagesZipPaths;
316 OString m_aImagesZipFileURL;
317 OUString m_aSymbolsStyleName;
319 std::vector< OUString > m_avModules;
321 typedef boost::unordered_map< OUString,helpdatafileproxy::Hdf*,ha,eq > DatabasesTable;
322 DatabasesTable m_aDatabases; // Language and module dependent databases
324 typedef boost::unordered_map< OUString,OUString,ha,eq > LangSetTable;
325 LangSetTable m_aLangSet; // Mapping to of lang-country to lang
327 typedef boost::unordered_map< OUString,StaticModuleInformation*,ha,eq > ModInfoTable;
328 ModInfoTable m_aModInfo; // Module information
330 typedef boost::unordered_map< OUString,KeywordInfo*,ha,eq > KeywordInfoTable;
331 KeywordInfoTable m_aKeywordInfo; // Module information
333 typedef
334 boost::unordered_map<
335 OUString,
336 ::com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >,
338 eq > ZipFileTable;
339 ZipFileTable m_aZipFileTable; // No closing of an once opened jarfile
341 typedef
342 boost::unordered_map<
343 OUString,
344 ::com::sun::star::uno::Reference< com::sun::star::i18n::XCollator >,
346 eq > CollatorTable;
347 CollatorTable m_aCollatorTable;
350 struct ostring_eq
352 bool operator()( const OString& rKey1, const OString& rKey2 ) const
354 return (rKey1 == rKey2);
358 struct ostring_ha
360 size_t operator()( const OString& rName ) const
362 return rName.hashCode();
366 typedef
367 boost::unordered_set<
368 OString,
369 ostring_ha,
370 ostring_eq > EmptyActiveTextSet;
371 EmptyActiveTextSet m_aEmptyActiveTextSet;
374 // methods
376 void setInstallPath( const OUString& aInstallDirectory );
378 }; // end class Databases
381 //===================================================================
382 enum IteratorState
384 INITIAL_MODULE,
385 //SHARED_MODULE, // Later, avoids redundancies in help compiling
386 USER_EXTENSIONS,
387 SHARED_EXTENSIONS,
388 BUNDLED_EXTENSIONS,
389 END_REACHED
392 // Hashtable to cache extension help status
393 typedef boost::unordered_map
395 OUString,
396 bool,
397 Databases::ha,
398 Databases::eq
400 ExtensionHelpExistanceMap;
403 class ExtensionIteratorBase
405 static ExtensionHelpExistanceMap aHelpExistanceMap;
407 public:
408 ExtensionIteratorBase( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
409 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage );
410 ExtensionIteratorBase( Databases& rDatabases, const OUString& aInitialModule,
411 const OUString& aLanguage );
412 void init( void );
414 private:
415 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetHelpPackageFromPackage
416 ( const com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
417 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
419 protected:
420 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextUserHelpPackage
421 ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
422 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextSharedHelpPackage
423 ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
424 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextBundledHelpPackage
425 ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
426 OUString implGetFileFromPackage( const OUString& rFileExtension,
427 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
428 void implGetLanguageVectorFromPackage( ::std::vector< OUString > &rv,
429 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
431 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
432 com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 > m_xSFA;
433 Databases& m_rDatabases;
435 IteratorState m_eState;
436 OUString m_aExtensionPath;
438 OUString m_aInitialModule;
439 OUString m_aLanguage;
441 com::sun::star::uno::Sequence< com::sun::star::uno::Reference
442 < com::sun::star::deployment::XPackage > > m_aUserPackagesSeq;
443 bool m_bUserPackagesLoaded;
445 com::sun::star::uno::Sequence< com::sun::star::uno::Reference
446 < com::sun::star::deployment::XPackage > > m_aSharedPackagesSeq;
447 bool m_bSharedPackagesLoaded;
449 com::sun::star::uno::Sequence< com::sun::star::uno::Reference
450 < com::sun::star::deployment::XPackage > > m_aBundledPackagesSeq;
451 bool m_bBundledPackagesLoaded;
453 int m_iUserPackage;
454 int m_iSharedPackage;
455 int m_iBundledPackage;
457 }; // end class ExtensionIteratorBase
460 //===================================================================
461 class DataBaseIterator : public ExtensionIteratorBase
463 public:
464 DataBaseIterator( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
465 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage, bool bHelpText )
466 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
467 , m_bHelpText( bHelpText )
469 DataBaseIterator( Databases& rDatabases, const OUString& aInitialModule,
470 const OUString& aLanguage, bool bHelpText )
471 : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
472 , m_bHelpText( bHelpText )
475 helpdatafileproxy::Hdf* nextHdf( OUString* o_pExtensionPath = NULL, OUString* o_pExtensionRegistryPath = NULL );
478 private:
479 helpdatafileproxy::Hdf* implGetHdfFromPackage(
480 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
481 OUString* o_pExtensionPath, OUString* o_pExtensionRegistryPath );
483 bool m_bHelpText;
485 }; // end class DataBaseIterator
487 //===================================================================
488 class KeyDataBaseFileIterator : public ExtensionIteratorBase
490 public:
491 KeyDataBaseFileIterator( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
492 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
493 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
495 //Returns a file URL
496 OUString nextDbFile( bool& o_rbExtension );
498 private:
499 OUString implGetDbFileFromPackage(
500 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
502 }; // end class KeyDataBaseFileIterator
504 //===================================================================
505 class JarFileIterator : public ExtensionIteratorBase
507 public:
508 JarFileIterator( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
509 Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
510 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
513 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
514 nextJarFile( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle,
515 OUString* o_pExtensionPath = NULL, OUString* o_pExtensionRegistryPath = NULL );
517 private:
518 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
519 implGetJarFromPackage(com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
520 OUString* o_pExtensionPath = NULL, OUString* o_pExtensionRegistryPath = NULL );
522 }; // end class JarFileIterator
524 //===================================================================
525 class IndexFolderIterator : public ExtensionIteratorBase
527 public:
528 IndexFolderIterator( Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
529 : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
532 OUString nextIndexFolder( bool& o_rbExtension, bool& o_rbTemporary );
533 void deleteTempIndexFolder( const OUString& aIndexFolder );
535 private:
536 OUString implGetIndexFolderFromPackage( bool& o_rbTemporary,
537 com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
539 }; // end class KeyDataBaseFileIterator
541 //===================================================================
543 } // end namespace chelp
546 #endif
548 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */