1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <sal/config.h>
26 #include <unordered_map>
30 #include <libxml/parser.h>
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>
37 #include <o3tl/char16_t2wchar_t.hxx>
39 #include <helpcompiler/compilehelp.hxx>
41 #if OSL_DEBUG_LEVEL > 2
43 #define HCDBG(foo) do { if (true) foo; } while(false)
45 #define HCDBG(foo) do { } while(false)
50 enum convert
{ native
};
57 path(const std::string
&in
, convert
)
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
);
65 path(const std::string
&FileURL
)
67 data
= OStringToOUString(FileURL
, FileNameEnc());
69 std::string
native_file_string() const
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
);
78 std::wstring
native_file_string_w() const
80 OUString ustrSystemPath
;
81 osl::File::getSystemPathFromFileURL(data
, ustrSystemPath
);
82 return std::wstring(o3tl::toW(ustrSystemPath
.getStr()));
85 std::string
toUTF8() const
87 OString
tmp(OUStringToOString(data
, RTL_TEXTENCODING_UTF8
));
88 return std::string(tmp
);
90 bool empty() const { return data
.isEmpty(); }
91 path
operator/(const std::string
&in
) const
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
);
102 void append(const char *in
)
104 OUString
ustrSystemPath(OStringToOUString(in
, FileNameEnc()));
105 data
+= ustrSystemPath
;
107 void append(const std::string
&in
) { append(in
.c_str()); }
111 // On Windows, libxslt and libxml use UTF-8 path strings
112 static constexpr rtl_TextEncoding
FileNameEnc() { return RTL_TEXTENCODING_UTF8
; }
114 static rtl_TextEncoding
FileNameEnc() { return osl_getThreadTextEncoding(); }
119 void create_directory(const fs::path
& indexDirName
);
120 void copy(const fs::path
&src
, const fs::path
&dest
);
124 typedef std::unordered_map
<std::string
, std::string
> Stringtable
;
125 typedef std::deque
<std::string
> LinkedList
;
127 typedef std::unordered_map
<std::string
, LinkedList
> Hashtable
;
132 std::string document_path
;
133 std::string document_module
;
134 std::string document_title
;
136 std::unique_ptr
< std::vector
<std::string
> > appl_hidlist
;
137 std::unique_ptr
<Hashtable
> appl_keywords
;
138 std::unique_ptr
<Stringtable
> appl_helptexts
;
146 appl_hidlist
.reset();
147 appl_keywords
.reset();
148 appl_helptexts
.reset();
149 if (appl_doc
) xmlFreeDoc(appl_doc
);
157 struct HelpProcessingException
159 HelpProcessingErrorClass m_eErrorClass
;
160 std::string m_aErrorMsg
;
161 std::string m_aXMLParsingFile
;
162 int m_nXMLParsingLine
;
164 HelpProcessingException( HelpProcessingErrorClass eErrorClass
, std::string aErrorMsg
)
165 : m_eErrorClass( eErrorClass
)
166 , m_aErrorMsg(std::move( aErrorMsg
))
167 , m_nXMLParsingLine( 0 )
169 HelpProcessingException( std::string aErrorMsg
, std::string aXMLParsingFile
, int nXMLParsingLine
)
170 : m_eErrorClass( HelpProcessingErrorClass::XmlParsing
)
171 , m_aErrorMsg(std::move( aErrorMsg
))
172 , m_aXMLParsingFile(std::move( aXMLParsingFile
))
173 , m_nXMLParsingLine( nXMLParsingLine
)
180 HelpCompiler(StreamTable
&streamTable
,
181 fs::path in_inputFile
,
184 fs::path in_resCompactStylesheet
,
185 fs::path in_resEmbStylesheet
,
186 std::string in_module
,
188 bool in_bExtensionMode
);
189 /// @throws HelpProcessingException
190 /// @throws BasicCodeTagger::TaggerException
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
);
198 StreamTable
&streamTable
;
199 const fs::path inputFile
, src
, zipdir
;
200 const std::string module
, lang
;
201 const fs::path resCompactStylesheet
;
202 const fs::path resEmbStylesheet
;
207 inline char tocharlower(char c
)
209 return static_cast<char>(
210 rtl::toAsciiLowerCase(static_cast<unsigned char>(c
)));
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */