1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: databases.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DATABASES_HXX_
32 #define _DATABASES_HXX_
34 #ifndef INCLUDED_STL_SET
36 #define INCLUDED_STL_SET
38 #ifndef INCLUDED_STL_VECTOR
40 #define INCLUDED_STL_VECTOR
44 #include <osl/mutex.hxx>
45 #include <rtl/ustring.hxx>
46 #include <rtl/string.hxx>
47 #include <com/sun/star/uno/Sequence.hxx>
48 #include <com/sun/star/ucb/XContent.hpp>
49 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
50 #include <com/sun/star/io/XInputStream.hpp>
51 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
52 #include <com/sun/star/uno/XComponentContext.hpp>
53 #include <com/sun/star/i18n/XCollator.hpp>
54 #include <com/sun/star/deployment/XPackage.hpp>
55 #include "com/sun/star/ucb/XSimpleFileAccess.hpp"
57 // Forward declaration
60 namespace berkeleydbproxy
{
73 class StaticModuleInformation
77 rtl::OUString m_aStartId
;
78 rtl::OUString m_aProgramSwitch
;
79 rtl::OUString m_aTitle
;
80 rtl::OUString m_aHeading
;
81 rtl::OUString m_aFulltext
;
87 StaticModuleInformation( rtl::OUString aTitle
,
88 rtl::OUString aStartId
,
89 rtl::OUString aProgramSwitch
,
90 rtl::OUString aHeading
,
91 rtl::OUString aFulltext
,
92 rtl::OUString aOrder
)
93 : m_aStartId( aStartId
),
94 m_aProgramSwitch( aProgramSwitch
),
96 m_aHeading( aHeading
),
97 m_aFulltext( aFulltext
),
98 m_nOrder( aOrder
.toInt32() )
102 ~StaticModuleInformation() { }
104 rtl::OUString
get_title() { return m_aTitle
; }
105 rtl::OUString
get_id() { return m_aStartId
; }
106 rtl::OUString
get_program() { return m_aProgramSwitch
; }
107 rtl::OUString
get_heading() { return m_aHeading
; }
108 rtl::OUString
get_fulltext() { return m_aFulltext
; }
109 int get_order() { return m_nOrder
; }
110 }; // end class StaticModuleInformation
120 friend struct KeywordElementComparator
;
121 friend class KeywordInfo
;
125 KeywordElement( Databases
* pDatabases
,
126 berkeleydbproxy::Db
* pDb
,
128 rtl::OUString
& ids
);
133 com::sun::star::uno::Sequence
< rtl::OUString
> listId
;
134 com::sun::star::uno::Sequence
< rtl::OUString
> listAnchor
;
135 com::sun::star::uno::Sequence
< rtl::OUString
> listTitle
;
137 void init( Databases
*pDatabases
,berkeleydbproxy::Db
* pDb
,const rtl::OUString
& ids
);
141 KeywordInfo( const std::vector
< KeywordElement
>& aVector
);
145 com::sun::star::uno::Sequence
< rtl::OUString
>&
146 getKeywordList() { return listKey
; }
148 com::sun::star::uno::Sequence
< com::sun::star::uno::Sequence
< rtl::OUString
> >&
149 getIdList() { return listId
; }
151 com::sun::star::uno::Sequence
< com::sun::star::uno::Sequence
< rtl::OUString
> >&
152 getAnchorList() { return listAnchor
; }
154 com::sun::star::uno::Sequence
< com::sun::star::uno::Sequence
< rtl::OUString
> >&
155 getTitleList() { return listTitle
; }
159 com::sun::star::uno::Sequence
< rtl::OUString
> listKey
;
160 com::sun::star::uno::Sequence
< com::sun::star::uno::Sequence
< rtl::OUString
> > listId
,listAnchor
,listTitle
;
161 }; // end class KeywordInfo
171 bool operator()( const rtl::OUString
& rKey1
, const rtl::OUString
& rKey2
) const
173 return rKey1
.compareTo( rKey2
) == 0;
179 size_t operator()( const rtl::OUString
& rName
) const
181 return rName
.hashCode();
187 * Input is the installdirectory in system dependent notation
190 Databases( sal_Bool showBasic
,
191 const rtl::OUString
& instPath
,
192 const com::sun::star::uno::Sequence
< rtl::OUString
>& imagesZipPaths
,
193 const rtl::OUString
& productName
,
194 const rtl::OUString
& productVersion
,
195 const rtl::OUString
& vendorName
,
196 const rtl::OUString
& vendorVersion
,
197 const rtl::OUString
& vendorShort
,
198 const rtl::OUString
& styleSheet
,
199 com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> xContext
);
203 rtl::OString
getImagesZipFileURL();
205 rtl::OUString
getInstallPathAsSystemPath();
207 rtl::OUString
getInstallPathAsURL();
209 const std::vector
< rtl::OUString
>& getModuleList( const rtl::OUString
& Language
);
211 StaticModuleInformation
* getStaticInformationForModule( const rtl::OUString
& Module
,
212 const rtl::OUString
& Language
);
214 bool checkModuleMatchForExtension( const rtl::OUString
& Database
, const rtl::OUString
& doclist
);
215 KeywordInfo
* getKeyword( const rtl::OUString
& Module
,
216 const rtl::OUString
& Language
);
218 berkeleydbproxy::Db
* getBerkeley( const rtl::OUString
& Module
,
219 const rtl::OUString
& Language
, bool helpText
= false,
220 const rtl::OUString
* pExtensionPath
= NULL
);
224 * The following method returns the Collator for the given language-country combination
227 com::sun::star::uno::Reference
< com::sun::star::i18n::XCollator
>
228 getCollator( const rtl::OUString
& Language
,
229 const rtl::OUString
& System
); // System not used by current implementation
233 * Returns a copy of the popupfile
236 void popupDocument( URLParameter
* urlPar
,char **buffer
,int *byteCount
);
240 * Returns the cascading stlye sheet used to format the HTML-output.
241 * First try is language directory, second try is main installation directory.
244 void cascadingStylesheet( const rtl::OUString
& Language
,
250 * Changes the the stylesheet for further reads.
253 void changeCSS(const rtl::OUString
& newStyleSheet
);
257 * Returns the active help text for the given module, language and id.
260 void setActiveText( const rtl::OUString
& Module
,
261 const rtl::OUString
& Language
,
262 const rtl::OUString
& Id
,
267 * Has the purpose of forcing the the jarfile to stay open
270 com::sun::star::uno::Reference
< com::sun::star::container::XHierarchicalNameAccess
>
271 jarFile( const rtl::OUString
& jar
,
272 const rtl::OUString
& Language
);
274 com::sun::star::uno::Reference
< com::sun::star::container::XHierarchicalNameAccess
>
275 findJarFileForPath( const rtl::OUString
& jar
, const rtl::OUString
& Language
,
276 const rtl::OUString
& path
, rtl::OUString
* o_pExtensionPath
= NULL
);
279 * Maps a given language-locale combination to language.
282 rtl::OUString
processLang( const rtl::OUString
& Language
);
286 * Maps a given language-locale combination to locale.
287 * The returned string maybe empty
290 rtl::OUString
country( const rtl::OUString
& Language
);
293 void replaceName( rtl::OUString
& oustring
) const;
295 rtl::OUString
getProductName() const { return m_vReplacement
[0]; }
296 rtl::OUString
getProductVersion() const { return m_vReplacement
[1]; }
297 rtl::OUString
getVendorName() const { return m_vReplacement
[2]; }
298 rtl::OUString
getVendorVersion() const { return m_vReplacement
[3]; }
299 rtl::OUString
getVendorShort() const { return m_vReplacement
[4]; }
301 rtl::OUString
expandURL( const rtl::OUString
& aURL
);
303 static rtl::OUString
expandURL( const rtl::OUString
& aURL
,
304 com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> xContext
);
309 com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_xContext
;
310 com::sun::star::uno::Reference
< com::sun::star::lang::XMultiComponentFactory
> m_xSMgr
;
311 com::sun::star::uno::Reference
< com::sun::star::ucb::XSimpleFileAccess
> m_xSFA
;
313 sal_Bool m_bShowBasic
;
314 int m_nErrorDocLength
;
317 int m_nCustomCSSDocLength
;
318 char* m_pCustomCSSDoc
;
319 rtl::OUString m_aCSS
;
321 #define PRODUCTNAME 0
322 #define PRODUCTVERSION 1
324 #define VENDORVERSION 3
325 #define VENDORSHORT 4
326 #define NEWPRODUCTNAME 5
327 #define NEWPRODUCTVERSION 6
330 rtl::OUString m_vReplacement
[7];
331 rtl::OUString newProdName
,newProdVersion
,
332 prodName
,prodVersion
,vendName
,vendVersion
,vendShort
;
334 rtl::OUString m_aInstallDirectory
; // Installation directory
335 com::sun::star::uno::Sequence
< rtl::OUString
> m_aImagesZipPaths
;
336 rtl::OString m_aImagesZipFileURL
;
337 sal_Int16 m_nSymbolsStyle
;
338 rtl::OUString m_aInstallDirectoryWithoutEncoding
; // a work around for a Sablot bug.
339 rtl::OUString m_aInstallDirectoryAsSystemPath
; // Installation directory
341 std::vector
< rtl::OUString
> m_avModules
;
343 typedef std::hash_map
< rtl::OUString
,berkeleydbproxy::Db
*,ha
,eq
> DatabasesTable
;
344 DatabasesTable m_aDatabases
; // Language and module dependent databases
346 typedef std::hash_map
< rtl::OUString
,rtl::OUString
,ha
,eq
> LangSetTable
;
347 LangSetTable m_aLangSet
; // Mapping to of lang-country to lang
349 typedef std::hash_map
< rtl::OUString
,StaticModuleInformation
*,ha
,eq
> ModInfoTable
;
350 ModInfoTable m_aModInfo
; // Module information
352 typedef std::hash_map
< rtl::OUString
,KeywordInfo
*,ha
,eq
> KeywordInfoTable
;
353 KeywordInfoTable m_aKeywordInfo
; // Module information
358 ::com::sun::star::uno::Reference
< com::sun::star::container::XHierarchicalNameAccess
>,
361 ZipFileTable m_aZipFileTable
; // No closing of an once opened jarfile
366 ::com::sun::star::uno::Reference
< com::sun::star::i18n::XCollator
>,
369 CollatorTable m_aCollatorTable
;
374 bool operator()( const rtl::OString
& rKey1
, const rtl::OString
& rKey2
) const
376 return rKey1
.compareTo( rKey2
) == 0;
382 size_t operator()( const rtl::OString
& rName
) const
384 return rName
.hashCode();
392 ostring_eq
> EmptyActiveTextSet
;
393 EmptyActiveTextSet m_aEmptyActiveTextSet
;
398 void setInstallPath( const rtl::OUString
& aInstallDirectory
);
400 }; // end class Databases
403 //===================================================================
407 //SHARED_MODULE, // Later, avoids redundancies in help compiling
413 // Hashtable to cache extension help status
414 typedef std::hash_map
421 ExtensionHelpExistanceMap
;
424 class ExtensionIteratorBase
426 static ExtensionHelpExistanceMap aHelpExistanceMap
;
429 ExtensionIteratorBase( com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> xContext
,
430 Databases
& rDatabases
, const rtl::OUString
& aInitialModule
, const rtl::OUString
& aLanguage
);
431 ExtensionIteratorBase( Databases
& rDatabases
, const rtl::OUString
& aInitialModule
,
432 const rtl::OUString
& aLanguage
);
436 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> implGetHelpPackageFromPackage
437 ( const com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> xPackage
,
438 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
>& o_xParentPackageBundle
);
441 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> implGetNextUserHelpPackage
442 ( com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
>& o_xParentPackageBundle
);
443 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> implGetNextSharedHelpPackage
444 ( com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
>& o_xParentPackageBundle
);
445 rtl::OUString
implGetFileFromPackage( const rtl::OUString
& rFileExtension
,
446 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> xPackage
);
447 void implGetLanguageVectorFromPackage( ::std::vector
< ::rtl::OUString
> &rv
,
448 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> xPackage
);
450 com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_xContext
;
451 com::sun::star::uno::Reference
< com::sun::star::ucb::XSimpleFileAccess
> m_xSFA
;
452 Databases
& m_rDatabases
;
454 IteratorState m_eState
;
455 rtl::OUString m_aExtensionPath
;
457 rtl::OUString m_aInitialModule
;
458 rtl::OUString m_aLanguage
;
460 com::sun::star::uno::Sequence
< com::sun::star::uno::Reference
461 < com::sun::star::deployment::XPackage
> > m_aUserPackagesSeq
;
462 bool m_bUserPackagesLoaded
;
464 com::sun::star::uno::Sequence
< com::sun::star::uno::Reference
465 < com::sun::star::deployment::XPackage
> > m_aSharedPackagesSeq
;
466 bool m_bSharedPackagesLoaded
;
469 int m_iSharedPackage
;
471 }; // end class ExtensionIteratorBase
474 //===================================================================
475 class DataBaseIterator
: public ExtensionIteratorBase
478 DataBaseIterator( com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> xContext
,
479 Databases
& rDatabases
, const rtl::OUString
& aInitialModule
, const rtl::OUString
& aLanguage
, bool bHelpText
)
480 : ExtensionIteratorBase( xContext
, rDatabases
, aInitialModule
, aLanguage
)
481 , m_bHelpText( bHelpText
)
483 DataBaseIterator( Databases
& rDatabases
, const rtl::OUString
& aInitialModule
,
484 const rtl::OUString
& aLanguage
, bool bHelpText
)
485 : ExtensionIteratorBase( rDatabases
, aInitialModule
, aLanguage
)
486 , m_bHelpText( bHelpText
)
489 berkeleydbproxy::Db
* nextDb( rtl::OUString
* o_pExtensionPath
= NULL
);
493 berkeleydbproxy::Db
* implGetDbFromPackage(
494 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> xPackage
,
495 rtl::OUString
* o_pExtensionPath
);
499 }; // end class DataBaseIterator
501 //===================================================================
502 class KeyDataBaseFileIterator
: public ExtensionIteratorBase
505 KeyDataBaseFileIterator( com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> xContext
,
506 Databases
& rDatabases
, const rtl::OUString
& aInitialModule
, const rtl::OUString
& aLanguage
)
507 : ExtensionIteratorBase( xContext
, rDatabases
, aInitialModule
, aLanguage
)
510 rtl::OUString
nextDbFile( bool& o_rbExtension
);
513 rtl::OUString
implGetDbFileFromPackage(
514 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> xPackage
);
516 }; // end class KeyDataBaseFileIterator
518 //===================================================================
519 class JarFileIterator
: public ExtensionIteratorBase
522 JarFileIterator( com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> xContext
,
523 Databases
& rDatabases
, const rtl::OUString
& aInitialModule
, const rtl::OUString
& aLanguage
)
524 : ExtensionIteratorBase( xContext
, rDatabases
, aInitialModule
, aLanguage
)
527 com::sun::star::uno::Reference
< com::sun::star::container::XHierarchicalNameAccess
>
528 nextJarFile( com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
>& o_xParentPackageBundle
,
529 rtl::OUString
* o_pExtensionPath
= NULL
);
532 com::sun::star::uno::Reference
< com::sun::star::container::XHierarchicalNameAccess
>
533 implGetJarFromPackage(com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> xPackage
,
534 rtl::OUString
* o_pExtensionPath
= NULL
);
536 }; // end class JarFileIterator
538 //===================================================================
539 class IndexFolderIterator
: public ExtensionIteratorBase
542 IndexFolderIterator( Databases
& rDatabases
, const rtl::OUString
& aInitialModule
, const rtl::OUString
& aLanguage
)
543 : ExtensionIteratorBase( rDatabases
, aInitialModule
, aLanguage
)
546 rtl::OUString
nextIndexFolder( bool& o_rbExtension
, bool& o_rbTemporary
);
547 void deleteTempIndexFolder( const rtl::OUString
& aIndexFolder
);
550 rtl::OUString
implGetIndexFolderFromPackage( bool& o_rbTemporary
,
551 com::sun::star::uno::Reference
< com::sun::star::deployment::XPackage
> xPackage
);
553 }; // end class KeyDataBaseFileIterator
555 //===================================================================
557 } // end namespace chelp