1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_
26 #define BOOST_NO_0X_HDR_TYPEINDEX
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
{
59 class StaticModuleInformation
64 OUString m_aProgramSwitch
;
73 StaticModuleInformation( OUString aTitle
,
75 OUString aProgramSwitch
,
79 : m_aStartId( aStartId
),
80 m_aProgramSwitch( aProgramSwitch
),
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
106 friend struct KeywordElementComparator
;
107 friend class KeywordInfo
;
111 KeywordElement( Databases
* pDatabases
,
112 helpdatafileproxy::Hdf
* pHdf
,
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
);
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
; }
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
157 bool operator()( const OUString
& rKey1
, const OUString
& rKey2
) const
159 return (rKey1
== rKey2
);
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
);
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
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
,
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
,
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
);
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
;
295 int m_nCustomCSSDocLength
;
296 char* m_pCustomCSSDoc
;
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
334 boost::unordered_map
<
336 ::com::sun::star::uno::Reference
< com::sun::star::container::XHierarchicalNameAccess
>,
339 ZipFileTable m_aZipFileTable
; // No closing of an once opened jarfile
342 boost::unordered_map
<
344 ::com::sun::star::uno::Reference
< com::sun::star::i18n::XCollator
>,
347 CollatorTable m_aCollatorTable
;
352 bool operator()( const OString
& rKey1
, const OString
& rKey2
) const
354 return (rKey1
== rKey2
);
360 size_t operator()( const OString
& rName
) const
362 return rName
.hashCode();
367 boost::unordered_set
<
370 ostring_eq
> EmptyActiveTextSet
;
371 EmptyActiveTextSet m_aEmptyActiveTextSet
;
376 void setInstallPath( const OUString
& aInstallDirectory
);
378 }; // end class Databases
381 //===================================================================
385 //SHARED_MODULE, // Later, avoids redundancies in help compiling
392 // Hashtable to cache extension help status
393 typedef boost::unordered_map
400 ExtensionHelpExistanceMap
;
403 class ExtensionIteratorBase
405 static ExtensionHelpExistanceMap aHelpExistanceMap
;
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
);
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
);
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
;
454 int m_iSharedPackage
;
455 int m_iBundledPackage
;
457 }; // end class ExtensionIteratorBase
460 //===================================================================
461 class DataBaseIterator
: public ExtensionIteratorBase
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
);
479 helpdatafileproxy::Hdf
* implGetHdfFromPackage(
480 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> xPackage
,
481 OUString
* o_pExtensionPath
, OUString
* o_pExtensionRegistryPath
);
485 }; // end class DataBaseIterator
487 //===================================================================
488 class KeyDataBaseFileIterator
: public ExtensionIteratorBase
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
)
496 OUString
nextDbFile( bool& o_rbExtension
);
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
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
);
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
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
);
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
548 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */