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 .
20 #ifndef INCLUDED_HELPCOMPILER_INC_HELPCOMPILER_HXX
21 #define INCLUDED_HELPCOMPILER_INC_HELPCOMPILER_HXX
23 #include <sal/config.h>
28 #include <unordered_map>
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 <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 rtl_TextEncoding
getThreadTextEncoding();
52 enum convert
{ native
};
59 path(const std::string
&in
, convert
)
62 osl_getProcessWorkingDir(&sWorkingDir
.pData
);
63 OString
tmp(in
.c_str());
64 OUString
ustrSystemPath(OStringToOUString(tmp
, getThreadTextEncoding()));
65 osl::File::getFileURLFromSystemPath(ustrSystemPath
, data
);
66 (void)osl::File::getAbsoluteFileURL(sWorkingDir
, data
, data
);
68 path(const std::string
&FileURL
)
70 OString
tmp(FileURL
.c_str());
71 data
= OStringToOUString(tmp
, getThreadTextEncoding());
73 std::string
native_file_string() const
75 OUString ustrSystemPath
;
76 osl::File::getSystemPathFromFileURL(data
, ustrSystemPath
);
77 OString
tmp(OUStringToOString(ustrSystemPath
, getThreadTextEncoding()));
78 HCDBG(std::cerr
<< "native_file_string is " << tmp
.getStr() << std::endl
);
79 return std::string(tmp
.getStr());
82 std::wstring
native_file_string_w() const
84 OUString ustrSystemPath
;
85 osl::File::getSystemPathFromFileURL(data
, ustrSystemPath
);
86 return std::wstring(o3tl::toW(ustrSystemPath
.getStr()));
89 std::string
toUTF8() const
91 OString
tmp(OUStringToOString(data
, RTL_TEXTENCODING_UTF8
));
92 return std::string(tmp
.getStr());
94 bool empty() const { return data
.isEmpty(); }
95 path
operator/(const std::string
&in
) const
98 HCDBG(std::cerr
<< "orig was " <<
99 OUStringToOString(ret
.data
, RTL_TEXTENCODING_UTF8
).getStr() << std::endl
);
100 OString
tmp(in
.c_str());
101 OUString
ustrSystemPath(OStringToOUString(tmp
, getThreadTextEncoding()));
102 ret
.data
+= "/" + ustrSystemPath
;
103 HCDBG(std::cerr
<< "final is " <<
104 OUStringToOString(ret
.data
, RTL_TEXTENCODING_UTF8
).getStr() << std::endl
);
107 void append(const char *in
)
110 OUString
ustrSystemPath(OStringToOUString(tmp
, getThreadTextEncoding()));
111 data
+= ustrSystemPath
;
113 void append(const std::string
&in
) { append(in
.c_str()); }
116 void create_directory(const fs::path
& indexDirName
);
117 void copy(const fs::path
&src
, const fs::path
&dest
);
121 typedef std::unordered_map
<std::string
, std::string
> Stringtable
;
122 typedef std::deque
<std::string
> LinkedList
;
124 typedef std::unordered_map
<std::string
, LinkedList
> Hashtable
;
129 std::string document_path
;
130 std::string document_module
;
131 std::string document_title
;
133 std::unique_ptr
< std::vector
<std::string
> > appl_hidlist
;
134 std::unique_ptr
<Hashtable
> appl_keywords
;
135 std::unique_ptr
<Stringtable
> appl_helptexts
;
143 appl_hidlist
.reset();
144 appl_keywords
.reset();
145 appl_helptexts
.reset();
146 if (appl_doc
) xmlFreeDoc(appl_doc
);
154 struct HelpProcessingException
156 HelpProcessingErrorClass m_eErrorClass
;
157 std::string m_aErrorMsg
;
158 std::string m_aXMLParsingFile
;
159 int m_nXMLParsingLine
;
161 HelpProcessingException( HelpProcessingErrorClass eErrorClass
, const std::string
& aErrorMsg
)
162 : m_eErrorClass( eErrorClass
)
163 , m_aErrorMsg( aErrorMsg
)
164 , m_nXMLParsingLine( 0 )
166 HelpProcessingException( const std::string
& aErrorMsg
, const std::string
& aXMLParsingFile
, int nXMLParsingLine
)
167 : m_eErrorClass( HelpProcessingErrorClass::XmlParsing
)
168 , m_aErrorMsg( aErrorMsg
)
169 , m_aXMLParsingFile( aXMLParsingFile
)
170 , m_nXMLParsingLine( nXMLParsingLine
)
177 HelpCompiler(StreamTable
&streamTable
,
178 const fs::path
&in_inputFile
,
179 const fs::path
&in_src
,
180 const fs::path
&in_zipdir
,
181 const fs::path
&in_resCompactStylesheet
,
182 const fs::path
&in_resEmbStylesheet
,
183 const std::string
&in_module
,
184 const std::string
&in_lang
,
185 bool in_bExtensionMode
);
186 /// @throws HelpProcessingException
187 /// @throws BasicCodeTagger::TaggerException
190 xmlDocPtr
getSourceDocument(const fs::path
&filePath
);
191 static void tagBasicCodeExamples(xmlDocPtr doc
);
192 xmlDocPtr
compactXhpForJar(xmlDocPtr doc
);
193 void saveXhpForJar(xmlDocPtr doc
, const fs::path
&filePath
);
194 xmlNodePtr
clone(xmlNodePtr node
, const std::string
& appl
);
195 StreamTable
&streamTable
;
196 const fs::path inputFile
, src
, zipdir
;
197 const std::string module
, lang
;
198 const fs::path resCompactStylesheet
;
199 const fs::path resEmbStylesheet
;
204 inline char tocharlower(char c
)
206 return static_cast<char>(
207 rtl::toAsciiLowerCase(static_cast<unsigned char>(c
)));
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */