LibreOffice Module helpcompiler (master) 1
HelpCompiler.hxx
Go to the documentation of this file.
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#pragma once
20
21#include <sal/config.h>
22
23#include <deque>
24#include <memory>
25#include <string>
26#include <unordered_map>
27#include <utility>
28#include <vector>
29
30#include <libxml/parser.h>
31
32#include <rtl/ustring.hxx>
33#include <rtl/character.hxx>
34#include <osl/process.h>
35#include <osl/file.hxx>
36#include <osl/thread.h>
38
40
41#if OSL_DEBUG_LEVEL > 2
42 #include <iostream>
43 #define HCDBG(foo) do { if (true) foo; } while(false)
44#else
45 #define HCDBG(foo) do { } while(false)
46#endif
47
48namespace fs
49{
50 enum convert { native };
51 class path
52 {
53 public:
54 OUString data;
55 public:
56 path() {}
57 path(const std::string &in, convert)
58 {
59 OUString sWorkingDir;
60 osl_getProcessWorkingDir(&sWorkingDir.pData);
61 OUString ustrSystemPath(OStringToOUString(in, FileNameEnc()));
62 osl::File::getFileURLFromSystemPath(ustrSystemPath, data);
63 (void)osl::File::getAbsoluteFileURL(sWorkingDir, data, data);
64 }
65 path(const std::string &FileURL)
66 {
67 data = OStringToOUString(FileURL, FileNameEnc());
68 }
69 std::string native_file_string() const
70 {
71 OUString ustrSystemPath;
72 osl::File::getSystemPathFromFileURL(data, ustrSystemPath);
73 OString tmp(OUStringToOString(ustrSystemPath, FileNameEnc()));
74 HCDBG(std::cerr << "native_file_string is " << tmp.getStr() << std::endl);
75 return std::string(tmp);
76 }
77#ifdef _WIN32
78 std::wstring native_file_string_w() const
79 {
80 OUString ustrSystemPath;
81 osl::File::getSystemPathFromFileURL(data, ustrSystemPath);
82 return std::wstring(o3tl::toW(ustrSystemPath.getStr()));
83 }
84#endif
85 std::string toUTF8() const
86 {
87 OString tmp(OUStringToOString(data, RTL_TEXTENCODING_UTF8));
88 return std::string(tmp);
89 }
90 bool empty() const { return data.isEmpty(); }
91 path operator/(const std::string &in) const
92 {
93 path ret(*this);
94 HCDBG(std::cerr << "orig was " <<
95 OUStringToOString(ret.data, RTL_TEXTENCODING_UTF8).getStr() << std::endl);
96 OUString ustrSystemPath(OStringToOUString(in, FileNameEnc()));
97 ret.data += "/" + ustrSystemPath;
98 HCDBG(std::cerr << "final is " <<
99 OUStringToOString(ret.data, RTL_TEXTENCODING_UTF8).getStr() << std::endl);
100 return ret;
101 }
102 void append(const char *in)
103 {
104 OUString ustrSystemPath(OStringToOUString(in, FileNameEnc()));
105 data += ustrSystemPath;
106 }
107 void append(const std::string &in) { append(in.c_str()); }
108
109 private:
110#ifdef _WIN32
111 // On Windows, libxslt and libxml use UTF-8 path strings
112 static constexpr rtl_TextEncoding FileNameEnc() { return RTL_TEXTENCODING_UTF8; }
113#else
114 static rtl_TextEncoding FileNameEnc() { return osl_getThreadTextEncoding(); }
115#endif
116
117 };
118
119 void create_directory(const fs::path& indexDirName);
120 void copy(const fs::path &src, const fs::path &dest);
121}
122
123
124typedef std::unordered_map<std::string, std::string> Stringtable;
125typedef std::deque<std::string> LinkedList;
126
127typedef std::unordered_map<std::string, LinkedList> Hashtable;
128
130{
131public:
132 std::string document_path;
133 std::string document_module;
134 std::string document_title;
135
136 std::unique_ptr< std::vector<std::string> > appl_hidlist;
137 std::unique_ptr<Hashtable> appl_keywords;
138 std::unique_ptr<Stringtable> appl_helptexts;
139 xmlDocPtr appl_doc;
140
142 appl_doc(nullptr)
143 {}
144 void dropappl()
145 {
146 appl_hidlist.reset();
147 appl_keywords.reset();
148 appl_helptexts.reset();
149 if (appl_doc) xmlFreeDoc(appl_doc);
150 }
152 {
153 dropappl();
154 }
155};
156
158{
160 std::string m_aErrorMsg;
161 std::string m_aXMLParsingFile;
163
164 HelpProcessingException( HelpProcessingErrorClass eErrorClass, std::string aErrorMsg )
165 : m_eErrorClass( eErrorClass )
166 , m_aErrorMsg(std::move( aErrorMsg ))
167 , m_nXMLParsingLine( 0 )
168 {}
169 HelpProcessingException( std::string aErrorMsg, std::string aXMLParsingFile, int nXMLParsingLine )
171 , m_aErrorMsg(std::move( aErrorMsg ))
172 , m_aXMLParsingFile(std::move( aXMLParsingFile ))
173 , m_nXMLParsingLine( nXMLParsingLine )
174 {}
175};
176
178{
179public:
181 fs::path in_inputFile,
182 fs::path in_src,
183 fs::path in_zipdir,
184 fs::path in_resCompactStylesheet,
185 fs::path in_resEmbStylesheet,
186 std::string in_module,
187 std::string in_lang,
188 bool in_bExtensionMode);
191 void compile();
192private:
193 xmlDocPtr getSourceDocument(const fs::path &filePath);
194 static void tagBasicCodeExamples(xmlDocPtr doc);
195 xmlDocPtr compactXhpForJar(xmlDocPtr doc);
196 void saveXhpForJar(xmlDocPtr doc, const fs::path &filePath);
197 xmlNodePtr clone(xmlNodePtr node, const std::string& appl);
200 const std::string module, lang;
204 std::string gui;
205};
206
207inline char tocharlower(char c)
208{
209 return static_cast<char>(
210 rtl::toAsciiLowerCase(static_cast<unsigned char>(c)));
211}
212
213/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< std::string, LinkedList > Hashtable
std::unordered_map< std::string, std::string > Stringtable
std::deque< std::string > LinkedList
char tocharlower(char c)
#define HCDBG(foo)
std::string gui
const fs::path resEmbStylesheet
xmlNodePtr clone(xmlNodePtr node, const std::string &appl)
xmlDocPtr compactXhpForJar(xmlDocPtr doc)
void saveXhpForJar(xmlDocPtr doc, const fs::path &filePath)
static void tagBasicCodeExamples(xmlDocPtr doc)
const fs::path inputFile
const fs::path zipdir
xmlDocPtr getSourceDocument(const fs::path &filePath)
const fs::path resCompactStylesheet
const std::string module
const std::string lang
HelpCompiler(StreamTable &streamTable, fs::path in_inputFile, fs::path in_src, fs::path in_zipdir, fs::path in_resCompactStylesheet, fs::path in_resEmbStylesheet, std::string in_module, std::string in_lang, bool in_bExtensionMode)
StreamTable & streamTable
const fs::path src
std::string document_module
std::unique_ptr< Hashtable > appl_keywords
std::string document_path
std::unique_ptr< Stringtable > appl_helptexts
std::unique_ptr< std::vector< std::string > > appl_hidlist
std::string document_title
xmlDocPtr appl_doc
static rtl_TextEncoding FileNameEnc()
void append(const char *in)
path operator/(const std::string &in) const
std::string native_file_string() const
std::string toUTF8() const
bool empty() const
OUString data
path(const std::string &FileURL)
void append(const std::string &in)
path(const std::string &in, convert)
HelpProcessingErrorClass
Definition: compilehelp.hxx:39
filePath
@ native
void copy(const fs::path &src, const fs::path &dest)
void create_directory(const fs::path &indexDirName)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
HelpProcessingException(HelpProcessingErrorClass eErrorClass, std::string aErrorMsg)
HelpProcessingException(std::string aErrorMsg, std::string aXMLParsingFile, int nXMLParsingLine)
HelpProcessingErrorClass m_eErrorClass