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 INCLUDED_XMLHELP_SOURCE_CXXHELP_PROVIDER_DATABASES_HXX
21 #define INCLUDED_XMLHELP_SOURCE_CXXHELP_PROVIDER_DATABASES_HXX
23 #include <sal/config.h>
26 #include <unordered_map>
27 #include <unordered_set>
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
{
53 class StaticModuleInformation
58 OUString m_aProgramSwitch
;
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
),
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
87 friend struct KeywordElementComparator
;
88 friend class KeywordInfo
;
92 KeywordElement( Databases
const * pDatabases
,
93 helpdatafileproxy::Hdf
* pHdf
,
95 OUString
const & ids
);
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
; }
123 css::uno::Sequence
< OUString
> listKey
;
124 css::uno::Sequence
< css::uno::Sequence
< OUString
> > listId
,listAnchor
,listTitle
;
125 }; // end class KeywordInfo
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
);
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
,
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
);
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
;
228 std::vector
<char> m_vCustomCSSDoc
;
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
263 css::uno::Reference
< css::container::XHierarchicalNameAccess
> > ZipFileTable
;
264 ZipFileTable m_aZipFileTable
; // No closing of an once opened jarfile
269 css::uno::Reference
< css::i18n::XCollator
> > CollatorTable
;
270 CollatorTable m_aCollatorTable
;
275 OString
> EmptyActiveTextSet
;
276 EmptyActiveTextSet m_aEmptyActiveTextSet
;
280 void setInstallPath( const OUString
& aInstallDirectory
);
282 }; // end class Databases
284 enum class IteratorState
287 //SHARED_MODULE, // Later, avoids redundancies in help compiling
294 // Hashtable to cache extension help status
295 typedef std::unordered_map
300 ExtensionHelpExistenceMap
;
302 class ExtensionIteratorBase
304 static ExtensionHelpExistenceMap aHelpExistenceMap
;
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
);
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
);
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
;
352 int m_iSharedPackage
;
353 int m_iBundledPackage
;
355 }; // end class ExtensionIteratorBase
357 class DataBaseIterator
: public ExtensionIteratorBase
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 );
374 helpdatafileproxy::Hdf
* implGetHdfFromPackage(
375 const css::uno::Reference
< css::deployment::XPackage
>& xPackage
,
376 OUString
* o_pExtensionPath
, OUString
* o_pExtensionRegistryPath
);
380 }; // end class DataBaseIterator
382 class KeyDataBaseFileIterator
: public ExtensionIteratorBase
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
)
390 OUString
nextDbFile( bool& o_rbExtension
);
393 OUString
implGetDbFileFromPackage(
394 const css::uno::Reference
< css::deployment::XPackage
>& xPackage
);
396 }; // end class KeyDataBaseFileIterator
398 class JarFileIterator
: public ExtensionIteratorBase
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
);
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
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
);
428 OUString
implGetIndexFolderFromPackage( bool& o_rbTemporary
,
429 const css::uno::Reference
< css::deployment::XPackage
>& xPackage
);
431 }; // end class KeyDataBaseFileIterator
433 } // end namespace chelp
437 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */