nss: upgrade to release 3.73
[LibreOffice.git] / helpcompiler / inc / HelpCompiler.hxx
blob87390aeedc7e2da35fb814f8bed46ff37c161437
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_HELPCOMPILER_INC_HELPCOMPILER_HXX
21 #define INCLUDED_HELPCOMPILER_INC_HELPCOMPILER_HXX
23 #include <sal/config.h>
25 #include <deque>
26 #include <memory>
27 #include <string>
28 #include <unordered_map>
29 #include <vector>
31 #include <libxml/parser.h>
33 #include <rtl/ustring.hxx>
34 #include <rtl/character.hxx>
35 #include <osl/process.h>
36 #include <osl/file.hxx>
37 #include <osl/thread.h>
38 #include <o3tl/char16_t2wchar_t.hxx>
40 #include <helpcompiler/compilehelp.hxx>
42 #if OSL_DEBUG_LEVEL > 2
43 #include <iostream>
44 #define HCDBG(foo) do { if (true) foo; } while(false)
45 #else
46 #define HCDBG(foo) do { } while(false)
47 #endif
49 namespace fs
51 enum convert { native };
52 class path
54 public:
55 OUString data;
56 public:
57 path() {}
58 path(const std::string &in, convert)
60 OUString sWorkingDir;
61 osl_getProcessWorkingDir(&sWorkingDir.pData);
62 OString tmp(in.c_str());
63 OUString ustrSystemPath(OStringToOUString(tmp, osl_getThreadTextEncoding()));
64 osl::File::getFileURLFromSystemPath(ustrSystemPath, data);
65 (void)osl::File::getAbsoluteFileURL(sWorkingDir, data, data);
67 path(const std::string &FileURL)
69 OString tmp(FileURL.c_str());
70 data = OStringToOUString(tmp, osl_getThreadTextEncoding());
72 std::string native_file_string() const
74 OUString ustrSystemPath;
75 osl::File::getSystemPathFromFileURL(data, ustrSystemPath);
76 OString tmp(OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding()));
77 HCDBG(std::cerr << "native_file_string is " << tmp.getStr() << std::endl);
78 return std::string(tmp.getStr());
80 #ifdef _WIN32
81 std::wstring native_file_string_w() const
83 OUString ustrSystemPath;
84 osl::File::getSystemPathFromFileURL(data, ustrSystemPath);
85 return std::wstring(o3tl::toW(ustrSystemPath.getStr()));
87 #endif
88 std::string toUTF8() const
90 OString tmp(OUStringToOString(data, RTL_TEXTENCODING_UTF8));
91 return std::string(tmp.getStr());
93 bool empty() const { return data.isEmpty(); }
94 path operator/(const std::string &in) const
96 path ret(*this);
97 HCDBG(std::cerr << "orig was " <<
98 OUStringToOString(ret.data, RTL_TEXTENCODING_UTF8).getStr() << std::endl);
99 OString tmp(in.c_str());
100 OUString ustrSystemPath(OStringToOUString(tmp, osl_getThreadTextEncoding()));
101 ret.data += "/" + ustrSystemPath;
102 HCDBG(std::cerr << "final is " <<
103 OUStringToOString(ret.data, RTL_TEXTENCODING_UTF8).getStr() << std::endl);
104 return ret;
106 void append(const char *in)
108 OString tmp(in);
109 OUString ustrSystemPath(OStringToOUString(tmp, osl_getThreadTextEncoding()));
110 data += ustrSystemPath;
112 void append(const std::string &in) { append(in.c_str()); }
115 void create_directory(const fs::path& indexDirName);
116 void copy(const fs::path &src, const fs::path &dest);
120 typedef std::unordered_map<std::string, std::string> Stringtable;
121 typedef std::deque<std::string> LinkedList;
123 typedef std::unordered_map<std::string, LinkedList> Hashtable;
125 class StreamTable
127 public:
128 std::string document_path;
129 std::string document_module;
130 std::string document_title;
132 std::unique_ptr< std::vector<std::string> > appl_hidlist;
133 std::unique_ptr<Hashtable> appl_keywords;
134 std::unique_ptr<Stringtable> appl_helptexts;
135 xmlDocPtr appl_doc;
137 StreamTable() :
138 appl_doc(nullptr)
140 void dropappl()
142 appl_hidlist.reset();
143 appl_keywords.reset();
144 appl_helptexts.reset();
145 if (appl_doc) xmlFreeDoc(appl_doc);
147 ~StreamTable()
149 dropappl();
153 struct HelpProcessingException
155 HelpProcessingErrorClass m_eErrorClass;
156 std::string m_aErrorMsg;
157 std::string m_aXMLParsingFile;
158 int m_nXMLParsingLine;
160 HelpProcessingException( HelpProcessingErrorClass eErrorClass, const std::string& aErrorMsg )
161 : m_eErrorClass( eErrorClass )
162 , m_aErrorMsg( aErrorMsg )
163 , m_nXMLParsingLine( 0 )
165 HelpProcessingException( const std::string& aErrorMsg, const std::string& aXMLParsingFile, int nXMLParsingLine )
166 : m_eErrorClass( HelpProcessingErrorClass::XmlParsing )
167 , m_aErrorMsg( aErrorMsg )
168 , m_aXMLParsingFile( aXMLParsingFile )
169 , m_nXMLParsingLine( nXMLParsingLine )
173 class HelpCompiler
175 public:
176 HelpCompiler(StreamTable &streamTable,
177 const fs::path &in_inputFile,
178 const fs::path &in_src,
179 const fs::path &in_zipdir,
180 const fs::path &in_resCompactStylesheet,
181 const fs::path &in_resEmbStylesheet,
182 const std::string &in_module,
183 const std::string &in_lang,
184 bool in_bExtensionMode);
185 /// @throws HelpProcessingException
186 /// @throws BasicCodeTagger::TaggerException
187 void compile();
188 private:
189 xmlDocPtr getSourceDocument(const fs::path &filePath);
190 static void tagBasicCodeExamples(xmlDocPtr doc);
191 xmlDocPtr compactXhpForJar(xmlDocPtr doc);
192 void saveXhpForJar(xmlDocPtr doc, const fs::path &filePath);
193 xmlNodePtr clone(xmlNodePtr node, const std::string& appl);
194 StreamTable &streamTable;
195 const fs::path inputFile, src, zipdir;
196 const std::string module, lang;
197 const fs::path resCompactStylesheet;
198 const fs::path resEmbStylesheet;
199 bool bExtensionMode;
200 std::string gui;
203 inline char tocharlower(char c)
205 return static_cast<char>(
206 rtl::toAsciiLowerCase(static_cast<unsigned char>(c)));
209 #endif
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */