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>
26 #include <unordered_map>
34 #include <boost/shared_ptr.hpp>
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>
43 #include <rtl/ustring.hxx>
44 #include <osl/thread.h>
45 #include <osl/process.h>
46 #include <osl/file.hxx>
48 #include <BasCodeTagger.hxx>
49 #include <helpcompiler/compilehelp.hxx>
51 #if OSL_DEBUG_LEVEL > 2
53 #define HCDBG(foo) do { if (true) foo; } while(false)
55 #define HCDBG(foo) do { } while(false)
60 rtl_TextEncoding
getThreadTextEncoding();
62 enum convert
{ native
};
69 path(const path
&rOther
) : data(rOther
.data
) {}
70 path(const std::string
&in
, convert
)
73 osl_getProcessWorkingDir(&sWorkingDir
.pData
);
74 OString
tmp(in
.c_str());
75 OUString
ustrSystemPath(OStringToOUString(tmp
, getThreadTextEncoding()));
76 osl::File::getFileURLFromSystemPath(ustrSystemPath
, data
);
77 osl::File::getAbsoluteFileURL(sWorkingDir
, data
, data
);
79 path(const std::string
&FileURL
)
81 OString
tmp(FileURL
.c_str());
82 data
= OStringToOUString(tmp
, getThreadTextEncoding());
84 std::string
native_file_string() const
86 OUString ustrSystemPath
;
87 osl::File::getSystemPathFromFileURL(data
, ustrSystemPath
);
88 OString
tmp(OUStringToOString(ustrSystemPath
, getThreadTextEncoding()));
89 HCDBG(std::cerr
<< "native_file_string is " << tmp
.getStr() << std::endl
);
90 return std::string(tmp
.getStr());
93 wchar_t const * native_file_string_w() const
95 OUString ustrSystemPath
;
96 osl::File::getSystemPathFromFileURL(data
, ustrSystemPath
);
97 return (wchar_t const *) ustrSystemPath
.getStr();
100 std::string
native_directory_string() const { return native_file_string(); }
101 std::string
toUTF8() const
103 OString
tmp(OUStringToOString(data
, RTL_TEXTENCODING_UTF8
));
104 return std::string(tmp
.getStr());
106 bool empty() const { return data
.isEmpty(); }
107 path
operator/(const std::string
&in
) const
110 HCDBG(std::cerr
<< "orig was " <<
111 OUStringToOString(ret
.data
, RTL_TEXTENCODING_UTF8
).getStr() << std::endl
);
112 OString
tmp(in
.c_str());
113 OUString
ustrSystemPath(OStringToOUString(tmp
, getThreadTextEncoding()));
114 ret
.data
+= OUString(sal_Unicode('/'));
115 ret
.data
+= ustrSystemPath
;
116 HCDBG(std::cerr
<< "final is " <<
117 OUStringToOString(ret
.data
, RTL_TEXTENCODING_UTF8
).getStr() << std::endl
);
120 void append(const char *in
)
123 OUString
ustrSystemPath(OStringToOUString(tmp
, getThreadTextEncoding()));
124 data
= data
+ ustrSystemPath
;
126 void append(const std::string
&in
) { append(in
.c_str()); }
129 void create_directory(const fs::path
& indexDirName
);
130 void copy(const fs::path
&src
, const fs::path
&dest
);
135 size_t operator()(const std::string
&str
) const
138 const char *key
= str
.data();
139 for (size_t i
= 0; i
< str
.size(); i
++)
142 hash
+= (hash
<< 10);
146 hash
^= (hash
>> 11);
147 hash
+= (hash
<< 15);
152 #define get16bits(d) ((((sal_uInt32)(((const sal_uInt8 *)(d))[1])) << 8)\
153 +(sal_uInt32)(((const sal_uInt8 *)(d))[0]) )
155 #define pref_hash joaat_hash
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
;
161 typedef std::unordered_map
<std::string
, LinkedList
, pref_hash
> Hashtable
;
166 std::string document_id
;
167 std::string document_path
;
168 std::string document_module
;
169 std::string document_title
;
171 HashSet
*appl_hidlist
;
172 Hashtable
*appl_keywords
;
173 Stringtable
*appl_helptexts
;
176 HashSet
*default_hidlist
;
177 Hashtable
*default_keywords
;
178 Stringtable
*default_helptexts
;
179 xmlDocPtr default_doc
;
182 appl_hidlist(NULL
), appl_keywords(NULL
), appl_helptexts(NULL
), appl_doc(NULL
),
183 default_hidlist(NULL
), default_keywords(NULL
), default_helptexts(NULL
), default_doc(NULL
)
187 delete default_hidlist
;
188 delete default_keywords
;
189 delete default_helptexts
;
190 if (default_doc
) xmlFreeDoc(default_doc
);
195 delete appl_keywords
;
196 delete appl_helptexts
;
197 if (appl_doc
) xmlFreeDoc(appl_doc
);
206 struct HelpProcessingException
208 HelpProcessingErrorClass m_eErrorClass
;
209 std::string m_aErrorMsg
;
210 std::string m_aXMLParsingFile
;
211 int m_nXMLParsingLine
;
213 HelpProcessingException( HelpProcessingErrorClass eErrorClass
, const std::string
& aErrorMsg
)
214 : m_eErrorClass( eErrorClass
)
215 , m_aErrorMsg( aErrorMsg
)
216 , m_nXMLParsingLine( 0 )
218 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 , m_nXMLParsingLine( nXMLParsingLine
)
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
);
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
;
262 inline char tocharlower(char c
)
264 return static_cast<char>(tolower(c
));
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */