LCOV - code coverage report
Current view: top level - l10ntools/source/help - HelpCompiler.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 73 80 91.2 %
Date: 2012-08-25 Functions: 19 22 86.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36 66 54.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef HELPCOMPILER_HXX
      30                 :            : #define HELPCOMPILER_HXX
      31                 :            : 
      32                 :            : #include <string>
      33                 :            : #include <boost/unordered_map.hpp>
      34                 :            : #include <vector>
      35                 :            : #include <list>
      36                 :            : #include <fstream>
      37                 :            : #include <sstream>
      38                 :            : #include <algorithm>
      39                 :            : #include <ctype.h>
      40                 :            : #ifdef SYSTEM_DB_HEADER
      41                 :            : #include SYSTEM_DB_HEADER
      42                 :            : #else
      43                 :            : #include <berkeleydb/db.h>
      44                 :            : #endif
      45                 :            : 
      46                 :            : #include <boost/shared_ptr.hpp>
      47                 :            : 
      48                 :            : #include <libxml/xmlmemory.h>
      49                 :            : #include <libxml/debugXML.h>
      50                 :            : #include <libxml/HTMLtree.h>
      51                 :            : #include <libxml/xmlIO.h>
      52                 :            : #include <libxml/xinclude.h>
      53                 :            : #include <libxml/catalog.h>
      54                 :            : 
      55                 :            : #include <rtl/ustring.hxx>
      56                 :            : #include <osl/thread.h>
      57                 :            : #include <osl/process.h>
      58                 :            : #include <osl/file.hxx>
      59                 :            : 
      60                 :            : #include <compilehelp.hxx>
      61                 :            : 
      62                 :            : #if OSL_DEBUG_LEVEL > 2
      63                 :            :     #include <iostream>
      64                 :            :     #define HCDBG(foo) do { if (1) foo; } while(0)
      65                 :            : #else
      66                 :            :     #define HCDBG(foo) do { } while(0)
      67                 :            : #endif
      68                 :            : 
      69                 :            : namespace fs
      70                 :            : {
      71                 :            :     rtl_TextEncoding getThreadTextEncoding( void );
      72                 :            : 
      73                 :            :     enum convert { native };
      74                 :      82379 :     class path
      75                 :            :     {
      76                 :            :     public:
      77                 :            :         ::rtl::OUString data;
      78                 :            :     public:
      79                 :       9689 :         path() {}
      80                 :      53945 :         path(const path &rOther) : data(rOther.data) {}
      81                 :       9003 :         path(const std::string &in, convert)
      82                 :       9003 :         {
      83                 :       9003 :             rtl::OUString sWorkingDir;
      84         [ +  - ]:       9003 :             osl_getProcessWorkingDir(&sWorkingDir.pData);
      85                 :            : 
      86                 :       9003 :             rtl::OString tmp(in.c_str());
      87 [ +  - ][ +  - ]:       9003 :             rtl::OUString ustrSystemPath(rtl::OStringToOUString(tmp, getThreadTextEncoding()));
      88         [ +  - ]:       9003 :             osl::File::getFileURLFromSystemPath(ustrSystemPath, data);
      89         [ +  - ]:       9003 :             osl::File::getAbsoluteFileURL(sWorkingDir, data, data);
      90                 :       9003 :         }
      91                 :        310 :         path(const std::string &FileURL)
      92                 :        310 :         {
      93                 :        310 :             rtl::OString tmp(FileURL.c_str());
      94 [ +  - ][ +  - ]:        310 :             data = rtl::OStringToOUString(tmp, getThreadTextEncoding());
      95                 :        310 :         }
      96                 :      26761 :         std::string native_file_string() const
      97                 :            :         {
      98                 :      26761 :             ::rtl::OUString ustrSystemPath;
      99         [ +  - ]:      26761 :             osl::File::getSystemPathFromFileURL(data, ustrSystemPath);
     100 [ +  - ][ +  - ]:      26761 :             rtl::OString tmp(rtl::OUStringToOString(ustrSystemPath, getThreadTextEncoding()));
     101                 :            :             HCDBG(std::cerr << "native_file_string is " << tmp.getStr() << std::endl);
     102         [ +  - ]:      26761 :             return std::string(tmp.getStr());
     103                 :            :         }
     104                 :            : #ifdef WNT
     105                 :            :         wchar_t const * native_file_string_w() const
     106                 :            :         {
     107                 :            :             ::rtl::OUString ustrSystemPath;
     108                 :            :             osl::File::getSystemPathFromFileURL(data, ustrSystemPath);
     109                 :            :             return (wchar_t const *) ustrSystemPath.getStr();
     110                 :            :         }
     111                 :            : #endif
     112                 :            :         std::string native_directory_string() const { return native_file_string(); }
     113                 :          8 :         std::string toUTF8() const
     114                 :            :         {
     115         [ +  - ]:          8 :             rtl::OString tmp(rtl::OUStringToOString(data, RTL_TEXTENCODING_UTF8));
     116         [ +  - ]:          8 :             return std::string(tmp.getStr());
     117                 :            :         }
     118                 :        116 :         bool empty() const { return data.isEmpty(); }
     119                 :      17802 :         path operator/(const std::string &in) const
     120                 :            :         {
     121                 :      17802 :             path ret(*this);
     122                 :            :             HCDBG(std::cerr << "orig was " <<
     123                 :            :                 rtl::OUStringToOString(ret.data, RTL_TEXTENCODING_UTF8).getStr() << std::endl);
     124                 :      17802 :             rtl::OString tmp(in.c_str());
     125 [ +  - ][ +  - ]:      17802 :             rtl::OUString ustrSystemPath(rtl::OStringToOUString(tmp, getThreadTextEncoding()));
     126                 :      17802 :             ret.data += rtl::OUString(sal_Unicode('/'));
     127                 :      17802 :             ret.data += ustrSystemPath;
     128                 :            :             HCDBG(std::cerr << "final is " <<
     129                 :            :                 rtl::OUStringToOString(ret.data, RTL_TEXTENCODING_UTF8).getStr() << std::endl);
     130                 :      17802 :             return ret;
     131                 :            :         }
     132                 :       8919 :         void append(const char *in)
     133                 :            :         {
     134                 :       8919 :             rtl::OString tmp(in);
     135 [ +  - ][ +  - ]:       8919 :             rtl::OUString ustrSystemPath(rtl::OStringToOUString(tmp, getThreadTextEncoding()));
     136                 :       8919 :             data = data + ustrSystemPath;
     137                 :       8919 :         }
     138                 :       8919 :         void append(const std::string &in) { append(in.c_str()); }
     139                 :            :     };
     140                 :            : 
     141                 :            :     void create_directory(const fs::path indexDirName);
     142                 :            :     void copy(const fs::path &src, const fs::path &dest);
     143                 :            : }
     144                 :            : 
     145                 :            : struct joaat_hash
     146                 :            : {
     147                 :      65147 :     size_t operator()(const std::string &str) const
     148                 :            :     {
     149                 :      65147 :         size_t hash = 0;
     150                 :      65147 :         const char *key = str.data();
     151         [ +  + ]:    1978126 :         for (size_t i = 0; i < str.size(); i++)
     152                 :            :         {
     153                 :    1912979 :             hash += key[i];
     154                 :    1912979 :             hash += (hash << 10);
     155                 :    1912979 :             hash ^= (hash >> 6);
     156                 :            :         }
     157                 :      65147 :         hash += (hash << 3);
     158                 :      65147 :         hash ^= (hash >> 11);
     159                 :      65147 :         hash += (hash << 15);
     160                 :      65147 :         return hash;
     161                 :            :     }
     162                 :            : };
     163                 :            : 
     164                 :            : #define get16bits(d) ((((sal_uInt32)(((const sal_uInt8 *)(d))[1])) << 8)\
     165                 :            :                        +(sal_uInt32)(((const sal_uInt8 *)(d))[0]) )
     166                 :            : 
     167                 :            : #define pref_hash joaat_hash
     168                 :            : 
     169                 :            : typedef boost::unordered_map<std::string, std::string, pref_hash> Stringtable;
     170                 :            : typedef std::list<std::string> LinkedList;
     171                 :            : typedef std::vector<std::string> HashSet;
     172                 :            : 
     173                 :            : typedef boost::unordered_map<std::string, LinkedList, pref_hash> Hashtable;
     174                 :            : 
     175                 :            : class StreamTable
     176                 :            : {
     177                 :            : public:
     178                 :            :     std::string document_id;
     179                 :            :     std::string document_path;
     180                 :            :     std::string document_module;
     181                 :            :     std::string document_title;
     182                 :            : 
     183                 :            :     HashSet *appl_hidlist;
     184                 :            :     Hashtable *appl_keywords;
     185                 :            :     Stringtable *appl_helptexts;
     186                 :            :     xmlDocPtr appl_doc;
     187                 :            : 
     188                 :            :     HashSet *default_hidlist;
     189                 :            :     Hashtable *default_keywords;
     190                 :            :     Stringtable *default_helptexts;
     191                 :            :     xmlDocPtr default_doc;
     192                 :            : 
     193                 :       8981 :     StreamTable() :
     194                 :            :         appl_hidlist(NULL), appl_keywords(NULL), appl_helptexts(NULL), appl_doc(NULL),
     195 [ +  - ][ +  - ]:       8981 :         default_hidlist(NULL), default_keywords(NULL), default_helptexts(NULL), default_doc(NULL)
                 [ +  - ]
     196                 :       8981 :     {}
     197                 :       8981 :     void dropdefault()
     198                 :            :     {
     199         [ -  + ]:       8981 :         delete default_hidlist;
     200         [ -  + ]:       8981 :         delete default_keywords;
     201         [ -  + ]:       8981 :         delete default_helptexts;
     202         [ -  + ]:       8981 :         if (default_doc) xmlFreeDoc(default_doc);
     203                 :       8981 :     }
     204                 :      17962 :     void dropappl()
     205                 :            :     {
     206         [ +  + ]:      17962 :         delete appl_hidlist;
     207         [ +  + ]:      17962 :         delete appl_keywords;
     208         [ +  + ]:      17962 :         delete appl_helptexts;
     209         [ +  + ]:      17962 :         if (appl_doc) xmlFreeDoc(appl_doc);
     210                 :      17962 :     }
     211                 :       8981 :     ~StreamTable()
     212                 :       8981 :     {
     213         [ +  - ]:       8981 :         dropappl();
     214         [ +  - ]:       8981 :         dropdefault();
     215                 :       8981 :     }
     216                 :            : };
     217                 :            : 
     218                 :          0 : struct HelpProcessingException
     219                 :            : {
     220                 :            :     HelpProcessingErrorClass        m_eErrorClass;
     221                 :            :     std::string                     m_aErrorMsg;
     222                 :            :     std::string                     m_aXMLParsingFile;
     223                 :            :     int                             m_nXMLParsingLine;
     224                 :            : 
     225                 :          0 :     HelpProcessingException( HelpProcessingErrorClass eErrorClass, const std::string& aErrorMsg )
     226                 :            :         : m_eErrorClass( eErrorClass )
     227                 :            :         , m_aErrorMsg( aErrorMsg )
     228         [ #  # ]:          0 :         , m_nXMLParsingLine( 0 )
     229                 :          0 :     {}
     230                 :          0 :     HelpProcessingException( const std::string& aErrorMsg, const std::string& aXMLParsingFile, int nXMLParsingLine )
     231                 :            :         : m_eErrorClass( HELPPROCESSING_XMLPARSING_ERROR )
     232                 :            :         , m_aErrorMsg( aErrorMsg )
     233                 :            :         , m_aXMLParsingFile( aXMLParsingFile )
     234         [ #  # ]:          0 :         , m_nXMLParsingLine( nXMLParsingLine )
     235                 :          0 :     {}
     236                 :            : };
     237                 :            : 
     238                 :       8981 : class HelpCompiler
     239                 :            : {
     240                 :            : public:
     241                 :            :     HelpCompiler(StreamTable &streamTable,
     242                 :            :                 const fs::path &in_inputFile,
     243                 :            :                 const fs::path &in_src,
     244                 :            :                 const fs::path &in_resEmbStylesheet,
     245                 :            :                 const std::string &in_module,
     246                 :            :                 const std::string &in_lang,
     247                 :            :                 bool in_bExtensionMode);
     248                 :            :     bool compile( void ) throw (HelpProcessingException);
     249                 :            :     void addEntryToJarFile(const std::string &prefix,
     250                 :            :         const std::string &entryName, const std::string &bytesToAdd);
     251                 :            :     void addEntryToJarFile(const std::string &prefix,
     252                 :            :                 const std::string &entryName, const HashSet &bytesToAdd);
     253                 :            :     void addEntryToJarFile(const std::string &prefix,
     254                 :            :                 const std::string &entryName, const Stringtable &bytesToAdd);
     255                 :            :     void addEntryToJarFile(const std::string &prefix,
     256                 :            :                 const std::string &entryName, const Hashtable &bytesToAdd);
     257                 :            : private:
     258                 :            :     xmlDocPtr getSourceDocument(const fs::path &filePath);
     259                 :            :     xmlNodePtr clone(xmlNodePtr node, const std::string& appl);
     260                 :            :     StreamTable &streamTable;
     261                 :            :     const fs::path inputFile, src;
     262                 :            :     const std::string module, lang;
     263                 :            :     const fs::path resEmbStylesheet;
     264                 :            :     bool bExtensionMode;
     265                 :            :     std::string gui;
     266                 :            : };
     267                 :            : 
     268                 :      57314 : inline char tocharlower(char c)
     269                 :            : {
     270                 :      57314 :     return static_cast<char>(tolower(c));
     271                 :            : }
     272                 :            : 
     273                 :            : #endif
     274                 :            : 
     275                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10