LCOV - code coverage report
Current view: top level - helpcompiler/inc - HelpCompiler.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 80 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 22 0.0 %
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_HELPCOMPILER_INC_HELPCOMPILER_HXX
      21             : #define INCLUDED_HELPCOMPILER_INC_HELPCOMPILER_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : 
      25             : #include <string>
      26             : #include <unordered_map>
      27             : #include <vector>
      28             : #include <list>
      29             : #include <fstream>
      30             : #include <sstream>
      31             : #include <algorithm>
      32             : #include <ctype.h>
      33             : 
      34             : #include <boost/shared_ptr.hpp>
      35             : 
      36             : #include <libxml/xmlmemory.h>
      37             : #include <libxml/debugXML.h>
      38             : #include <libxml/HTMLtree.h>
      39             : #include <libxml/xmlIO.h>
      40             : #include <libxml/xinclude.h>
      41             : #include <libxml/catalog.h>
      42             : 
      43             : #include <rtl/ustring.hxx>
      44             : #include <osl/thread.h>
      45             : #include <osl/process.h>
      46             : #include <osl/file.hxx>
      47             : 
      48             : #include <BasCodeTagger.hxx>
      49             : #include <helpcompiler/compilehelp.hxx>
      50             : 
      51             : #if OSL_DEBUG_LEVEL > 2
      52             :     #include <iostream>
      53             :     #define HCDBG(foo) do { if (true) foo; } while(false)
      54             : #else
      55             :     #define HCDBG(foo) do { } while(false)
      56             : #endif
      57             : 
      58             : namespace fs
      59             : {
      60             :     rtl_TextEncoding getThreadTextEncoding();
      61             : 
      62             :     enum convert { native };
      63           0 :     class path
      64             :     {
      65             :     public:
      66             :         OUString data;
      67             :     public:
      68           0 :         path() {}
      69           0 :         path(const path &rOther) : data(rOther.data) {}
      70           0 :         path(const std::string &in, convert)
      71           0 :         {
      72           0 :             OUString sWorkingDir;
      73           0 :             osl_getProcessWorkingDir(&sWorkingDir.pData);
      74           0 :             OString tmp(in.c_str());
      75           0 :             OUString ustrSystemPath(OStringToOUString(tmp, getThreadTextEncoding()));
      76           0 :             osl::File::getFileURLFromSystemPath(ustrSystemPath, data);
      77           0 :             osl::File::getAbsoluteFileURL(sWorkingDir, data, data);
      78           0 :         }
      79           0 :         path(const std::string &FileURL)
      80           0 :         {
      81           0 :             OString tmp(FileURL.c_str());
      82           0 :             data = OStringToOUString(tmp, getThreadTextEncoding());
      83           0 :         }
      84           0 :         std::string native_file_string() const
      85             :         {
      86           0 :             OUString ustrSystemPath;
      87           0 :             osl::File::getSystemPathFromFileURL(data, ustrSystemPath);
      88           0 :             OString tmp(OUStringToOString(ustrSystemPath, getThreadTextEncoding()));
      89             :             HCDBG(std::cerr << "native_file_string is " << tmp.getStr() << std::endl);
      90           0 :             return std::string(tmp.getStr());
      91             :         }
      92             : #ifdef WNT
      93             :         wchar_t const * native_file_string_w() const
      94             :         {
      95             :             OUString ustrSystemPath;
      96             :             osl::File::getSystemPathFromFileURL(data, ustrSystemPath);
      97             :             return (wchar_t const *) ustrSystemPath.getStr();
      98             :         }
      99             : #endif
     100             :         std::string native_directory_string() const { return native_file_string(); }
     101           0 :         std::string toUTF8() const
     102             :         {
     103           0 :             OString tmp(OUStringToOString(data, RTL_TEXTENCODING_UTF8));
     104           0 :             return std::string(tmp.getStr());
     105             :         }
     106           0 :         bool empty() const { return data.isEmpty(); }
     107           0 :         path operator/(const std::string &in) const
     108             :         {
     109           0 :             path ret(*this);
     110             :             HCDBG(std::cerr << "orig was " <<
     111             :                 OUStringToOString(ret.data, RTL_TEXTENCODING_UTF8).getStr() << std::endl);
     112           0 :             OString tmp(in.c_str());
     113           0 :             OUString ustrSystemPath(OStringToOUString(tmp, getThreadTextEncoding()));
     114           0 :             ret.data += OUString(sal_Unicode('/'));
     115           0 :             ret.data += ustrSystemPath;
     116             :             HCDBG(std::cerr << "final is " <<
     117             :                 OUStringToOString(ret.data, RTL_TEXTENCODING_UTF8).getStr() << std::endl);
     118           0 :             return ret;
     119             :         }
     120           0 :         void append(const char *in)
     121             :         {
     122           0 :             OString tmp(in);
     123           0 :             OUString ustrSystemPath(OStringToOUString(tmp, getThreadTextEncoding()));
     124           0 :             data = data + ustrSystemPath;
     125           0 :         }
     126           0 :         void append(const std::string &in) { append(in.c_str()); }
     127             :     };
     128             : 
     129             :     void create_directory(const fs::path& indexDirName);
     130             :     void copy(const fs::path &src, const fs::path &dest);
     131             : }
     132             : 
     133             : struct joaat_hash
     134             : {
     135           0 :     size_t operator()(const std::string &str) const
     136             :     {
     137           0 :         size_t hash = 0;
     138           0 :         const char *key = str.data();
     139           0 :         for (size_t i = 0; i < str.size(); i++)
     140             :         {
     141           0 :             hash += key[i];
     142           0 :             hash += (hash << 10);
     143           0 :             hash ^= (hash >> 6);
     144             :         }
     145           0 :         hash += (hash << 3);
     146           0 :         hash ^= (hash >> 11);
     147           0 :         hash += (hash << 15);
     148           0 :         return hash;
     149             :     }
     150             : };
     151             : 
     152             : #define get16bits(d) ((((sal_uInt32)(((const sal_uInt8 *)(d))[1])) << 8)\
     153             :                        +(sal_uInt32)(((const sal_uInt8 *)(d))[0]) )
     154             : 
     155             : #define pref_hash joaat_hash
     156             : 
     157             : typedef std::unordered_map<std::string, std::string, pref_hash> Stringtable;
     158             : typedef std::list<std::string> LinkedList;
     159             : typedef std::vector<std::string> HashSet;
     160             : 
     161             : typedef std::unordered_map<std::string, LinkedList, pref_hash> Hashtable;
     162             : 
     163             : class StreamTable
     164             : {
     165             : public:
     166             :     std::string document_id;
     167             :     std::string document_path;
     168             :     std::string document_module;
     169             :     std::string document_title;
     170             : 
     171             :     HashSet *appl_hidlist;
     172             :     Hashtable *appl_keywords;
     173             :     Stringtable *appl_helptexts;
     174             :     xmlDocPtr appl_doc;
     175             : 
     176             :     HashSet *default_hidlist;
     177             :     Hashtable *default_keywords;
     178             :     Stringtable *default_helptexts;
     179             :     xmlDocPtr default_doc;
     180             : 
     181           0 :     StreamTable() :
     182             :         appl_hidlist(NULL), appl_keywords(NULL), appl_helptexts(NULL), appl_doc(NULL),
     183           0 :         default_hidlist(NULL), default_keywords(NULL), default_helptexts(NULL), default_doc(NULL)
     184           0 :     {}
     185           0 :     void dropdefault()
     186             :     {
     187           0 :         delete default_hidlist;
     188           0 :         delete default_keywords;
     189           0 :         delete default_helptexts;
     190           0 :         if (default_doc) xmlFreeDoc(default_doc);
     191           0 :     }
     192           0 :     void dropappl()
     193             :     {
     194           0 :         delete appl_hidlist;
     195           0 :         delete appl_keywords;
     196           0 :         delete appl_helptexts;
     197           0 :         if (appl_doc) xmlFreeDoc(appl_doc);
     198           0 :     }
     199           0 :     ~StreamTable()
     200           0 :     {
     201           0 :         dropappl();
     202           0 :         dropdefault();
     203           0 :     }
     204             : };
     205             : 
     206           0 : struct HelpProcessingException
     207             : {
     208             :     HelpProcessingErrorClass        m_eErrorClass;
     209             :     std::string                     m_aErrorMsg;
     210             :     std::string                     m_aXMLParsingFile;
     211             :     int                             m_nXMLParsingLine;
     212             : 
     213           0 :     HelpProcessingException( HelpProcessingErrorClass eErrorClass, const std::string& aErrorMsg )
     214             :         : m_eErrorClass( eErrorClass )
     215             :         , m_aErrorMsg( aErrorMsg )
     216           0 :         , m_nXMLParsingLine( 0 )
     217           0 :     {}
     218           0 :     HelpProcessingException( const std::string& aErrorMsg, const std::string& aXMLParsingFile, int nXMLParsingLine )
     219             :         : m_eErrorClass( HELPPROCESSING_XMLPARSING_ERROR )
     220             :         , m_aErrorMsg( aErrorMsg )
     221             :         , m_aXMLParsingFile( aXMLParsingFile )
     222           0 :         , m_nXMLParsingLine( nXMLParsingLine )
     223           0 :     {}
     224             : };
     225             : 
     226           0 : class HelpCompiler
     227             : {
     228             : public:
     229             :     HelpCompiler(StreamTable &streamTable,
     230             :                 const fs::path &in_inputFile,
     231             :                 const fs::path &in_src,
     232             :                 const fs::path &in_zipdir,
     233             :                 const fs::path &in_resCompactStylesheet,
     234             :                 const fs::path &in_resEmbStylesheet,
     235             :                 const std::string &in_module,
     236             :                 const std::string &in_lang,
     237             :                 bool in_bExtensionMode);
     238             :     bool compile() throw (HelpProcessingException, BasicCodeTagger::TaggerException);
     239             :     void addEntryToJarFile(const std::string &prefix,
     240             :         const std::string &entryName, const std::string &bytesToAdd);
     241             :     void addEntryToJarFile(const std::string &prefix,
     242             :                 const std::string &entryName, const HashSet &bytesToAdd);
     243             :     void addEntryToJarFile(const std::string &prefix,
     244             :                 const std::string &entryName, const Stringtable &bytesToAdd);
     245             :     void addEntryToJarFile(const std::string &prefix,
     246             :                 const std::string &entryName, const Hashtable &bytesToAdd);
     247             : private:
     248             :     xmlDocPtr getSourceDocument(const fs::path &filePath);
     249             :     static void tagBasicCodeExamples(xmlDocPtr doc);
     250             :     xmlDocPtr compactXhpForJar(xmlDocPtr doc);
     251             :     void saveXhpForJar(xmlDocPtr doc, const fs::path &filePath);
     252             :     xmlNodePtr clone(xmlNodePtr node, const std::string& appl);
     253             :     StreamTable &streamTable;
     254             :     const fs::path inputFile, src, zipdir;
     255             :     const std::string module, lang;
     256             :     const fs::path resCompactStylesheet;
     257             :     const fs::path resEmbStylesheet;
     258             :     bool bExtensionMode;
     259             :     std::string gui;
     260             : };
     261             : 
     262           0 : inline char tocharlower(char c)
     263             : {
     264           0 :     return static_cast<char>(tolower(c));
     265             : }
     266             : 
     267             : #endif
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11