1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef HELPCOMPILER_HXX
30 #define HELPCOMPILER_HXX
33 #include <boost/unordered_map.hpp>
40 #ifdef SYSTEM_DB_HEADER
41 #include SYSTEM_DB_HEADER
43 #include <berkeleydb/db.h>
46 #include <boost/shared_ptr.hpp>
48 #include <libxml/xmlmemory.h>
49 #include <libxml/debugXML.h>
50 #include <libxml/HTMLtree.h>
51 #include <libxml/xmlIO.h>
52 #include <libxml/xinclude.h>
53 #include <libxml/catalog.h>
55 #include <rtl/ustring.hxx>
56 #include <osl/thread.h>
57 #include <osl/process.h>
58 #include <osl/file.hxx>
60 #include <compilehelp.hxx>
62 #if OSL_DEBUG_LEVEL > 2
64 #define HCDBG(foo) do { if (1) foo; } while(0)
66 #define HCDBG(foo) do { } while(0)
71 rtl_TextEncoding
getThreadTextEncoding( void );
73 enum convert
{ native
};
80 path(const path
&rOther
) : data(rOther
.data
) {}
81 path(const std::string
&in
, convert
)
83 rtl::OUString sWorkingDir
;
84 osl_getProcessWorkingDir(&sWorkingDir
.pData
);
86 rtl::OString
tmp(in
.c_str());
87 rtl::OUString
ustrSystemPath(rtl::OStringToOUString(tmp
, getThreadTextEncoding()));
88 osl::File::getFileURLFromSystemPath(ustrSystemPath
, data
);
89 osl::File::getAbsoluteFileURL(sWorkingDir
, data
, data
);
91 path(const std::string
&FileURL
)
93 rtl::OString
tmp(FileURL
.c_str());
94 data
= rtl::OStringToOUString(tmp
, getThreadTextEncoding());
96 std::string
native_file_string() const
98 ::rtl::OUString ustrSystemPath
;
99 osl::File::getSystemPathFromFileURL(data
, ustrSystemPath
);
100 rtl::OString
tmp(rtl::OUStringToOString(ustrSystemPath
, getThreadTextEncoding()));
101 HCDBG(std::cerr
<< "native_file_string is " << tmp
.getStr() << std::endl
);
102 return std::string(tmp
.getStr());
105 wchar_t const * native_file_string_w() const
107 ::rtl::OUString ustrSystemPath
;
108 osl::File::getSystemPathFromFileURL(data
, ustrSystemPath
);
109 return (wchar_t const *) ustrSystemPath
.getStr();
112 std::string
native_directory_string() const { return native_file_string(); }
113 std::string
toUTF8() const
115 rtl::OString
tmp(rtl::OUStringToOString(data
, RTL_TEXTENCODING_UTF8
));
116 return std::string(tmp
.getStr());
118 bool empty() const { return data
.isEmpty(); }
119 path
operator/(const std::string
&in
) const
122 HCDBG(std::cerr
<< "orig was " <<
123 rtl::OUStringToOString(ret
.data
, RTL_TEXTENCODING_UTF8
).getStr() << std::endl
);
124 rtl::OString
tmp(in
.c_str());
125 rtl::OUString
ustrSystemPath(rtl::OStringToOUString(tmp
, getThreadTextEncoding()));
126 ret
.data
+= rtl::OUString(sal_Unicode('/'));
127 ret
.data
+= ustrSystemPath
;
128 HCDBG(std::cerr
<< "final is " <<
129 rtl::OUStringToOString(ret
.data
, RTL_TEXTENCODING_UTF8
).getStr() << std::endl
);
132 void append(const char *in
)
134 rtl::OString
tmp(in
);
135 rtl::OUString
ustrSystemPath(rtl::OStringToOUString(tmp
, getThreadTextEncoding()));
136 data
= data
+ ustrSystemPath
;
138 void append(const std::string
&in
) { append(in
.c_str()); }
141 void create_directory(const fs::path indexDirName
);
142 void copy(const fs::path
&src
, const fs::path
&dest
);
147 size_t operator()(const std::string
&str
) const
150 const char *key
= str
.data();
151 for (size_t i
= 0; i
< str
.size(); i
++)
154 hash
+= (hash
<< 10);
158 hash
^= (hash
>> 11);
159 hash
+= (hash
<< 15);
164 #define get16bits(d) ((((sal_uInt32)(((const sal_uInt8 *)(d))[1])) << 8)\
165 +(sal_uInt32)(((const sal_uInt8 *)(d))[0]) )
167 #define pref_hash joaat_hash
169 typedef boost::unordered_map
<std::string
, std::string
, pref_hash
> Stringtable
;
170 typedef std::list
<std::string
> LinkedList
;
171 typedef std::vector
<std::string
> HashSet
;
173 typedef boost::unordered_map
<std::string
, LinkedList
, pref_hash
> Hashtable
;
178 std::string document_id
;
179 std::string document_path
;
180 std::string document_module
;
181 std::string document_title
;
183 HashSet
*appl_hidlist
;
184 Hashtable
*appl_keywords
;
185 Stringtable
*appl_helptexts
;
188 HashSet
*default_hidlist
;
189 Hashtable
*default_keywords
;
190 Stringtable
*default_helptexts
;
191 xmlDocPtr default_doc
;
194 appl_hidlist(NULL
), appl_keywords(NULL
), appl_helptexts(NULL
), appl_doc(NULL
),
195 default_hidlist(NULL
), default_keywords(NULL
), default_helptexts(NULL
), default_doc(NULL
)
199 delete default_hidlist
;
200 delete default_keywords
;
201 delete default_helptexts
;
202 if (default_doc
) xmlFreeDoc(default_doc
);
207 delete appl_keywords
;
208 delete appl_helptexts
;
209 if (appl_doc
) xmlFreeDoc(appl_doc
);
218 struct HelpProcessingException
220 HelpProcessingErrorClass m_eErrorClass
;
221 std::string m_aErrorMsg
;
222 std::string m_aXMLParsingFile
;
223 int m_nXMLParsingLine
;
225 HelpProcessingException( HelpProcessingErrorClass eErrorClass
, const std::string
& aErrorMsg
)
226 : m_eErrorClass( eErrorClass
)
227 , m_aErrorMsg( aErrorMsg
)
228 , m_nXMLParsingLine( 0 )
230 HelpProcessingException( const std::string
& aErrorMsg
, const std::string
& aXMLParsingFile
, int nXMLParsingLine
)
231 : m_eErrorClass( HELPPROCESSING_XMLPARSING_ERROR
)
232 , m_aErrorMsg( aErrorMsg
)
233 , m_aXMLParsingFile( aXMLParsingFile
)
234 , m_nXMLParsingLine( nXMLParsingLine
)
241 HelpCompiler(StreamTable
&streamTable
,
242 const fs::path
&in_inputFile
,
243 const fs::path
&in_src
,
244 const fs::path
&in_resEmbStylesheet
,
245 const std::string
&in_module
,
246 const std::string
&in_lang
,
247 bool in_bExtensionMode
);
248 bool compile( void ) throw (HelpProcessingException
);
249 void addEntryToJarFile(const std::string
&prefix
,
250 const std::string
&entryName
, const std::string
&bytesToAdd
);
251 void addEntryToJarFile(const std::string
&prefix
,
252 const std::string
&entryName
, const HashSet
&bytesToAdd
);
253 void addEntryToJarFile(const std::string
&prefix
,
254 const std::string
&entryName
, const Stringtable
&bytesToAdd
);
255 void addEntryToJarFile(const std::string
&prefix
,
256 const std::string
&entryName
, const Hashtable
&bytesToAdd
);
258 xmlDocPtr
getSourceDocument(const fs::path
&filePath
);
259 HashSet
switchFind(xmlDocPtr doc
);
260 xmlNodePtr
clone(xmlNodePtr node
, const std::string
& appl
);
261 StreamTable
&streamTable
;
262 const fs::path inputFile
, src
;
263 const std::string module
, lang
;
264 const fs::path resEmbStylesheet
;
268 inline char tocharlower(char c
)
270 return static_cast<char>(tolower(c
));
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */