1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: HelpCompiler.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef HELPCOMPILER_HXX
32 #define HELPCOMPILER_HXX
46 #include <berkeleydb/db.h>
49 #include <boost/shared_ptr.hpp>
51 #include <libxml/xmlmemory.h>
52 #include <libxml/debugXML.h>
53 #include <libxml/HTMLtree.h>
54 #include <libxml/xmlIO.h>
55 #include <libxml/xinclude.h>
56 #include <libxml/catalog.h>
58 #include <rtl/ustring.hxx>
59 #include <osl/thread.h>
60 #include <osl/process.h>
61 #include <osl/file.hxx>
63 #include <xmlhelp/compilehelp.hxx>
65 #define EMULATEORIGINAL 1
68 #define HCDBG(foo) do { if (1) foo; } while(0)
70 #define HCDBG(foo) do { if (0) foo; } while(0)
75 rtl_TextEncoding
getThreadTextEncoding( void );
77 enum convert
{ native
};
84 path(const path
&rOther
) : data(rOther
.data
) {}
85 path(const std::string
&in
, convert
)
87 rtl::OUString sWorkingDir
;
88 osl_getProcessWorkingDir(&sWorkingDir
.pData
);
90 rtl::OString
tmp(in
.c_str());
91 rtl::OUString
ustrSystemPath(rtl::OStringToOUString(tmp
, getThreadTextEncoding()));
92 osl::File::getFileURLFromSystemPath(ustrSystemPath
, data
);
93 osl::File::getAbsoluteFileURL(sWorkingDir
, data
, data
);
95 path(const std::string
&FileURL
)
97 rtl::OString
tmp(FileURL
.c_str());
98 data
= rtl::OStringToOUString(tmp
, getThreadTextEncoding());
100 std::string
native_file_string() const
102 ::rtl::OUString ustrSystemPath
;
103 osl::File::getSystemPathFromFileURL(data
, ustrSystemPath
);
104 rtl::OString
tmp(rtl::OUStringToOString(ustrSystemPath
, getThreadTextEncoding()));
105 HCDBG(std::cerr
<< "native_file_string is " << tmp
.getStr() << std::endl
);
106 return std::string(tmp
.getStr());
108 std::string
native_directory_string() const { return native_file_string(); }
109 std::string
toUTF8() const
111 rtl::OString
tmp(rtl::OUStringToOString(data
, RTL_TEXTENCODING_UTF8
));
112 return std::string(tmp
.getStr());
114 bool empty() const { return data
.getLength() == 0; }
115 path
operator/(const std::string
&in
) const
118 HCDBG(std::cerr
<< "orig was " <<
119 rtl::OUStringToOString(ret
.data
, RTL_TEXTENCODING_UTF8
).getStr() << std::endl
);
120 rtl::OString
tmp(in
.c_str());
121 rtl::OUString
ustrSystemPath(rtl::OStringToOUString(tmp
, getThreadTextEncoding()));
122 ret
.data
+= rtl::OUString(sal_Unicode('/'));
123 ret
.data
+= ustrSystemPath
;
124 HCDBG(std::cerr
<< "final is " <<
125 rtl::OUStringToOString(ret
.data
, RTL_TEXTENCODING_UTF8
).getStr() << std::endl
);
128 void append(const char *in
)
130 rtl::OString
tmp(in
);
131 rtl::OUString
ustrSystemPath(rtl::OStringToOUString(tmp
, getThreadTextEncoding()));
132 data
= data
+ ustrSystemPath
;
134 void append(const std::string
&in
) { append(in
.c_str()); }
137 void create_directory(const fs::path indexDirName
);
138 void rename(const fs::path
&src
, const fs::path
&dest
);
139 void copy(const fs::path
&src
, const fs::path
&dest
);
140 bool exists(const fs::path
&in
);
141 void remove_all(const fs::path
&in
);
142 void remove(const fs::path
&in
);
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]) )
169 size_t operator()(const std::string
&str
) const
171 const char * data
= str
.data();
172 int len
= str
.size();
173 size_t hash
= len
, tmp
;
174 if (len
<= 0 || data
== NULL
) return 0;
180 for (;len
> 0; len
--)
182 hash
+= get16bits (data
);
183 tmp
= (get16bits (data
+2) << 11) ^ hash
;
184 hash
= (hash
<< 16) ^ tmp
;
185 data
+= 2*sizeof (sal_uInt16
);
189 /* Handle end cases */
192 case 3: hash
+= get16bits (data
);
194 hash
^= data
[sizeof (sal_uInt16
)] << 18;
197 case 2: hash
+= get16bits (data
);
201 case 1: hash
+= *data
;
206 /* Force "avalanching" of final 127 bits */
218 #define pref_hash joaat_hash
220 typedef std::hash_map
<std::string
, std::string
, pref_hash
> Stringtable
;
221 typedef std::list
<std::string
> LinkedList
;
222 typedef std::vector
<std::string
> HashSet
;
224 typedef std::hash_map
<std::string
, LinkedList
, pref_hash
> Hashtable
;
229 std::string document_id
;
230 std::string document_path
;
231 std::string document_module
;
232 std::string document_title
;
234 HashSet
*appl_hidlist
;
235 Hashtable
*appl_keywords
;
236 Stringtable
*appl_helptexts
;
239 HashSet
*default_hidlist
;
240 Hashtable
*default_keywords
;
241 Stringtable
*default_helptexts
;
242 xmlDocPtr default_doc
;
245 appl_hidlist(NULL
), appl_keywords(NULL
), appl_helptexts(NULL
), appl_doc(NULL
),
246 default_hidlist(NULL
), default_keywords(NULL
), default_helptexts(NULL
), default_doc(NULL
)
250 delete default_hidlist
;
251 delete default_keywords
;
252 delete default_helptexts
;
253 if (default_doc
) xmlFreeDoc(default_doc
);
258 delete appl_keywords
;
259 delete appl_helptexts
;
260 if (appl_doc
) xmlFreeDoc(appl_doc
);
269 struct HelpProcessingException
271 HelpProcessingErrorClass m_eErrorClass
;
272 std::string m_aErrorMsg
;
273 std::string m_aXMLParsingFile
;
274 int m_nXMLParsingLine
;
276 HelpProcessingException( HelpProcessingErrorClass eErrorClass
, const std::string
& aErrorMsg
)
277 : m_eErrorClass( eErrorClass
)
278 , m_aErrorMsg( aErrorMsg
)
280 HelpProcessingException( const std::string
& aErrorMsg
, const std::string
& aXMLParsingFile
, int nXMLParsingLine
)
281 : m_eErrorClass( HELPPROCESSING_XMLPARSING_ERROR
)
282 , m_aErrorMsg( aErrorMsg
)
283 , m_aXMLParsingFile( aXMLParsingFile
)
284 , m_nXMLParsingLine( nXMLParsingLine
)
291 HelpCompiler(StreamTable
&streamTable
,
292 const fs::path
&in_inputFile
,
293 const fs::path
&in_src
,
294 const fs::path
&in_resEmbStylesheet
,
295 const std::string
&in_module
,
296 const std::string
&in_lang
,
297 bool in_bExtensionMode
);
298 bool compile( void ) throw (HelpProcessingException
);
299 void addEntryToJarFile(const std::string
&prefix
,
300 const std::string
&entryName
, const std::string
&bytesToAdd
);
301 void addEntryToJarFile(const std::string
&prefix
,
302 const std::string
&entryName
, const HashSet
&bytesToAdd
);
303 void addEntryToJarFile(const std::string
&prefix
,
304 const std::string
&entryName
, const Stringtable
&bytesToAdd
);
305 void addEntryToJarFile(const std::string
&prefix
,
306 const std::string
&entryName
, const Hashtable
&bytesToAdd
);
308 xmlDocPtr
getSourceDocument(const fs::path
&filePath
);
309 HashSet
switchFind(xmlDocPtr doc
);
310 xmlNodePtr
clone(xmlNodePtr node
, const std::string
& appl
);
311 StreamTable
&streamTable
;
312 const fs::path inputFile
, src
;
313 const std::string module
, lang
;
314 const fs::path resEmbStylesheet
;
320 /* vi:set tabstop=4 shiftwidth=4 expandtab: */