LCOV - code coverage report
Current view: top level - xmlhelp/source/cxxhelp/provider - databases.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 8 36 22.2 %
Date: 2015-06-13 12:38:46 Functions: 4 27 14.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_XMLHELP_SOURCE_CXXHELP_PROVIDER_DATABASES_HXX
      21             : #define INCLUDED_XMLHELP_SOURCE_CXXHELP_PROVIDER_DATABASES_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : 
      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>
      41             : 
      42             : // Forward declaration
      43             : 
      44             : namespace helpdatafileproxy {
      45             : 
      46             :     class Hdf;
      47             : 
      48             : }
      49             : 
      50             : namespace chelp {
      51             : 
      52             :     class Databases;
      53             :     class URLParameter;
      54             : 
      55             :     class StaticModuleInformation
      56             :     {
      57             :     private:
      58             : 
      59             :         OUString m_aStartId;
      60             :         OUString m_aProgramSwitch;
      61             :         OUString m_aTitle;
      62             :         OUString m_aHeading;
      63             :         OUString m_aFulltext;
      64             :         int m_nOrder;
      65             : 
      66             :     public:
      67             : 
      68           0 :         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           0 :               m_nOrder( aOrder.toInt32() )
      80             :         {
      81           0 :         }
      82             : 
      83           0 :         ~StaticModuleInformation() { }
      84             : 
      85           0 :         OUString get_title() const { return m_aTitle; }
      86           0 :         OUString get_id() const { return m_aStartId; }
      87           0 :         OUString get_program() const { return m_aProgramSwitch; }
      88             :         OUString get_heading() const { return m_aHeading; }
      89             :         OUString get_fulltext() const { return m_aFulltext; }
      90           0 :         int get_order() const { return m_nOrder; }
      91             :     };  // end class StaticModuleInformation
      92             : 
      93             :     class KeywordInfo
      94             :     {
      95             :     public:
      96             : 
      97           0 :         class KeywordElement
      98             :         {
      99             :             friend struct KeywordElementComparator;
     100             :             friend class KeywordInfo;
     101             : 
     102             :         public:
     103             : 
     104             :             KeywordElement( Databases* pDatabases,
     105             :                             helpdatafileproxy::Hdf* pHdf,
     106             :                             OUString& key,
     107             :                             OUString& ids );
     108             : 
     109             :         private:
     110             : 
     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;
     115             : 
     116             :             void init( Databases *pDatabases,helpdatafileproxy::Hdf* pHdf,const OUString& ids );
     117             :         };
     118             : 
     119             :         explicit KeywordInfo( const std::vector< KeywordElement >& aVector );
     120             : 
     121           0 :         ~KeywordInfo() { };
     122             : 
     123             :         com::sun::star::uno::Sequence< OUString >&
     124           0 :         getKeywordList() { return listKey; }
     125             : 
     126             :         com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > >&
     127           0 :         getIdList() { return listId; }
     128             : 
     129             :         com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > >&
     130           0 :         getAnchorList() { return listAnchor; }
     131             : 
     132             :         com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< OUString > >&
     133           0 :         getTitleList() { return listTitle; }
     134             : 
     135             :     private:
     136             : 
     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
     140             : 
     141             :     class Databases
     142             :     {
     143             :     public:
     144             : 
     145             :         /**
     146             :          *  Input is the installdirectory in system dependent notation
     147             :          */
     148             : 
     149             :         Databases( bool showBasic,
     150             :                  const OUString& instPath,
     151             :                  const com::sun::star::uno::Sequence< OUString >& imagesZipPaths,
     152             :                  const OUString& productName,
     153             :                  const OUString& productVersion,
     154             :                  const OUString& styleSheet,
     155             :                  com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext );
     156             : 
     157             :         ~Databases();
     158             : 
     159             :         OString getImagesZipFileURL();
     160             : 
     161             :         OUString getInstallPathAsURL();
     162             : 
     163             :         const std::vector< OUString >& getModuleList( const OUString& Language );
     164             : 
     165             :         StaticModuleInformation* getStaticInformationForModule( const OUString& Module,
     166             :                                                                 const OUString& Language );
     167             : 
     168             :         bool checkModuleMatchForExtension( const OUString& Database, const OUString& doclist );
     169             :         KeywordInfo* getKeyword( const OUString& Module,
     170             :                                  const OUString& Language );
     171             : 
     172             :         helpdatafileproxy::Hdf* getHelpDataFile( const OUString& Module,
     173             :                          const OUString& Language, bool helpText = false,
     174             :                          const OUString* pExtensionPath = NULL );
     175             : 
     176             :         /**
     177             :          *  The following method returns the Collator for the given language-country combination
     178             :          */
     179             : 
     180             :         com::sun::star::uno::Reference< com::sun::star::i18n::XCollator >
     181             :         getCollator( const OUString& Language,
     182             :                      const OUString& System );   // System not used by current implementation
     183             :         //                                            // of XCollator
     184             : 
     185             :         /**
     186             :          *  Returns the cascading style sheet used to format the HTML-output.
     187             :          *  First try is language directory, second try is main installation directory.
     188             :          */
     189             : 
     190             :         void cascadingStylesheet( const OUString& Language,
     191             :                                   char** buffer,
     192             :                                   int* byteCount );
     193             : 
     194             :         /**
     195             :          *  Changes the stylesheet for further reads.
     196             :          */
     197             : 
     198             :         void changeCSS(const OUString& newStyleSheet);
     199             : 
     200             :         /**
     201             :          *  Returns the active help text for the given module, language and id.
     202             :          */
     203             : 
     204             :         void setActiveText( const OUString& Module,
     205             :                             const OUString& Language,
     206             :                             const OUString& Id,
     207             :                             char** buffer,
     208             :                             int* byteCount );
     209             : 
     210             :         /**
     211             :          *  Has the purpose of forcing the jarfile to stay open
     212             :          */
     213             : 
     214             :         com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
     215             :         jarFile( const OUString& jar,
     216             :                  const OUString& Language );
     217             : 
     218             :         com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
     219             :         findJarFileForPath( const OUString& jar, const OUString& Language,
     220             :             const OUString& path, OUString* o_pExtensionPath = NULL,
     221             :             OUString* o_pExtensionRegistryPath = NULL );
     222             : 
     223             :         /**
     224             :          *  Maps a given language-locale combination to language.
     225             :          */
     226             : 
     227             :         OUString processLang( const OUString& Language );
     228             : 
     229             :         /**
     230             :          *  Maps a given language-locale combination to locale.
     231             :          *  The returned string maybe empty
     232             :          */
     233             : 
     234             :         static OUString country( const OUString& Language );
     235             : 
     236             :         void replaceName( OUString& oustring ) const;
     237             : 
     238           0 :         OUString getProductName() const { return m_vReplacement[0]; }
     239           0 :         OUString getProductVersion() const { return m_vReplacement[1]; }
     240             : 
     241             :         OUString expandURL( const OUString& aURL );
     242             : 
     243             :         static OUString expandURL( const OUString& aURL,
     244             :             com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext );
     245             : 
     246             :     private:
     247             : 
     248             :         osl::Mutex                                                                     m_aMutex;
     249             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >       m_xContext;
     250             :         com::sun::star::uno::Reference< com::sun::star::lang::XMultiComponentFactory > m_xSMgr;
     251             :         com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 >      m_xSFA;
     252             : 
     253             :         bool   m_bShowBasic;
     254             :         char*  m_pErrorDoc;
     255             : 
     256             :         int    m_nCustomCSSDocLength;
     257             :         char*  m_pCustomCSSDoc;
     258             :         OUString m_aCSS;
     259             : 
     260             :         enum {
     261             :             PRODUCTNAME = 0,
     262             :             PRODUCTVERSION,
     263             :             VENDORNAME,
     264             :             VENDORVERSION,
     265             :             VENDORSHORT,
     266             :             NEWPRODUCTNAME,
     267             :             NEWPRODUCTVERSION
     268             :         };
     269             : 
     270             :         int                    m_vAdd[7];
     271             :         OUString          m_vReplacement[7];
     272             :         OUString          newProdName,newProdVersion,
     273             :             prodName,prodVersion,vendName,vendVersion,vendShort;
     274             : 
     275             :         OUString          m_aInstallDirectory;                // Installation directory
     276             :         com::sun::star::uno::Sequence< OUString > m_aImagesZipPaths;
     277             :         OString           m_aImagesZipFileURL;
     278             :         OUString          m_aSymbolsStyleName;
     279             : 
     280             :         std::vector< OUString >    m_avModules;
     281             : 
     282             :         typedef std::unordered_map< OUString,helpdatafileproxy::Hdf*,OUStringHash >   DatabasesTable;
     283             :         DatabasesTable m_aDatabases;         // Language and module dependent databases
     284             : 
     285             :         typedef std::unordered_map< OUString,OUString,OUStringHash > LangSetTable;
     286             :         LangSetTable m_aLangSet;   // Mapping to of lang-country to lang
     287             : 
     288             :         typedef std::unordered_map< OUString,StaticModuleInformation*,OUStringHash > ModInfoTable;
     289             :         ModInfoTable m_aModInfo;   // Module information
     290             : 
     291             :         typedef std::unordered_map< OUString,KeywordInfo*,OUStringHash > KeywordInfoTable;
     292             :         KeywordInfoTable m_aKeywordInfo;   // Module information
     293             : 
     294             :         typedef
     295             :         std::unordered_map<
     296             :         OUString,
     297             :              ::com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >,
     298             :             OUStringHash >         ZipFileTable;
     299             :         ZipFileTable m_aZipFileTable;   // No closing of an once opened jarfile
     300             : 
     301             :         typedef
     302             :         std::unordered_map<
     303             :         OUString,
     304             :              ::com::sun::star::uno::Reference< com::sun::star::i18n::XCollator >,
     305             :             OUStringHash >      CollatorTable;
     306             :         CollatorTable    m_aCollatorTable;
     307             : 
     308             : 
     309             :         typedef
     310             :         std::unordered_set<
     311             :             OString,
     312             :             OStringHash >      EmptyActiveTextSet;
     313             :         EmptyActiveTextSet  m_aEmptyActiveTextSet;
     314             : 
     315             :         // methods
     316             : 
     317             :         void setInstallPath( const OUString& aInstallDirectory );
     318             : 
     319             :     }; // end class Databases
     320             : 
     321             :     enum IteratorState
     322             :     {
     323             :         INITIAL_MODULE,
     324             :         //SHARED_MODULE,        // Later, avoids redundancies in help compiling
     325             :         USER_EXTENSIONS,
     326             :         SHARED_EXTENSIONS,
     327             :         BUNDLED_EXTENSIONS,
     328             :         END_REACHED
     329             :     };
     330             : 
     331             :     // Hashtable to cache extension help status
     332             :     typedef std::unordered_map
     333             :     <
     334             :         OUString,
     335             :         bool,
     336             :         OUStringHash
     337             :     >
     338             :     ExtensionHelpExistanceMap;
     339             : 
     340        2900 :     class ExtensionIteratorBase
     341             :     {
     342             :         static ExtensionHelpExistanceMap    aHelpExistanceMap;
     343             : 
     344             :     public:
     345             :         ExtensionIteratorBase( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
     346             :             Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage );
     347             :         ExtensionIteratorBase( Databases& rDatabases, const OUString& aInitialModule,
     348             :             const OUString& aLanguage );
     349             :         void init();
     350             : 
     351             :     private:
     352             :         static com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetHelpPackageFromPackage
     353             :             ( const com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
     354             :               com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
     355             : 
     356             :     protected:
     357             :         com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextUserHelpPackage
     358             :             ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
     359             :         com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextSharedHelpPackage
     360             :             ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
     361             :         com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextBundledHelpPackage
     362             :         ( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
     363             :         OUString implGetFileFromPackage( const OUString& rFileExtension,
     364             :             com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
     365             :         void implGetLanguageVectorFromPackage( ::std::vector< OUString > &rv,
     366             :             com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
     367             : 
     368             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >    m_xContext;
     369             :         com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess3 >   m_xSFA;
     370             :         Databases&                                                                  m_rDatabases;
     371             : 
     372             :         IteratorState                                                               m_eState;
     373             :         OUString                                                               m_aExtensionPath;
     374             : 
     375             :         OUString                                                               m_aInitialModule;
     376             :         OUString                                                               m_aLanguage;
     377             : 
     378             :         com::sun::star::uno::Sequence< com::sun::star::uno::Reference
     379             :             < com::sun::star::deployment::XPackage > >                              m_aUserPackagesSeq;
     380             :         bool                                                                        m_bUserPackagesLoaded;
     381             : 
     382             :         com::sun::star::uno::Sequence< com::sun::star::uno::Reference
     383             :             < com::sun::star::deployment::XPackage > >                              m_aSharedPackagesSeq;
     384             :         bool                                                                        m_bSharedPackagesLoaded;
     385             : 
     386             :         com::sun::star::uno::Sequence< com::sun::star::uno::Reference
     387             :             < com::sun::star::deployment::XPackage > >                              m_aBundledPackagesSeq;
     388             :         bool                                                                        m_bBundledPackagesLoaded;
     389             : 
     390             :         int                                                                         m_iUserPackage;
     391             :         int                                                                         m_iSharedPackage;
     392             :         int                                                                         m_iBundledPackage;
     393             : 
     394             :     }; // end class ExtensionIteratorBase
     395             : 
     396        2900 :     class DataBaseIterator : public ExtensionIteratorBase
     397             :     {
     398             :     public:
     399        1550 :         DataBaseIterator( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
     400             :             Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage, bool bHelpText )
     401             :                 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
     402        1550 :                 , m_bHelpText( bHelpText )
     403        1550 :         {}
     404        1350 :         DataBaseIterator( Databases& rDatabases, const OUString& aInitialModule,
     405             :             const OUString& aLanguage, bool bHelpText )
     406             :                 : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
     407        1350 :                 , m_bHelpText( bHelpText )
     408        1350 :         {}
     409             : 
     410             :         helpdatafileproxy::Hdf* nextHdf( OUString* o_pExtensionPath = NULL, OUString* o_pExtensionRegistryPath = NULL );
     411             : 
     412             :     private:
     413             :         helpdatafileproxy::Hdf* implGetHdfFromPackage(
     414             :             com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
     415             :             OUString* o_pExtensionPath, OUString* o_pExtensionRegistryPath );
     416             : 
     417             :         bool                                                                        m_bHelpText;
     418             : 
     419             :     }; // end class DataBaseIterator
     420             : 
     421           0 :     class KeyDataBaseFileIterator : public ExtensionIteratorBase
     422             :     {
     423             :     public:
     424           0 :         KeyDataBaseFileIterator( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
     425             :             Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
     426           0 :                 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
     427           0 :         {}
     428             :         //Returns a file URL
     429             :         OUString nextDbFile( bool& o_rbExtension );
     430             : 
     431             :     private:
     432             :         OUString implGetDbFileFromPackage(
     433             :             com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
     434             : 
     435             :     }; // end class KeyDataBaseFileIterator
     436             : 
     437           0 :     class JarFileIterator : public ExtensionIteratorBase
     438             :     {
     439             :     public:
     440           0 :         JarFileIterator( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext,
     441             :             Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
     442           0 :                 : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage )
     443           0 :         {}
     444             : 
     445             :         com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
     446             :             nextJarFile( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle,
     447             :                             OUString* o_pExtensionPath = NULL, OUString* o_pExtensionRegistryPath = NULL );
     448             : 
     449             :     private:
     450             :         com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess >
     451             :             implGetJarFromPackage(com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
     452             :                 OUString* o_pExtensionPath = NULL, OUString* o_pExtensionRegistryPath = NULL );
     453             : 
     454             :     }; // end class JarFileIterator
     455             : 
     456           0 :     class IndexFolderIterator : public ExtensionIteratorBase
     457             :     {
     458             :     public:
     459           0 :         IndexFolderIterator( Databases& rDatabases, const OUString& aInitialModule, const OUString& aLanguage )
     460           0 :             : ExtensionIteratorBase( rDatabases, aInitialModule, aLanguage )
     461           0 :         {}
     462             : 
     463             :         OUString nextIndexFolder( bool& o_rbExtension, bool& o_rbTemporary );
     464             :         void deleteTempIndexFolder( const OUString& aIndexFolder );
     465             : 
     466             :     private:
     467             :         OUString implGetIndexFolderFromPackage( bool& o_rbTemporary,
     468             :             com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
     469             : 
     470             :     }; // end class KeyDataBaseFileIterator
     471             : 
     472             : }      // end namespace chelp
     473             : 
     474             : #endif
     475             : 
     476             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11