13cd96b95SAndrew Rist /**************************************************************
2*facfa769Smseidel  *
33cd96b95SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
43cd96b95SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
53cd96b95SAndrew Rist  * distributed with this work for additional information
63cd96b95SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
73cd96b95SAndrew Rist  * to you under the Apache License, Version 2.0 (the
83cd96b95SAndrew Rist  * "License"); you may not use this file except in compliance
93cd96b95SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*facfa769Smseidel  *
113cd96b95SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*facfa769Smseidel  *
133cd96b95SAndrew Rist  * Unless required by applicable law or agreed to in writing,
143cd96b95SAndrew Rist  * software distributed under the License is distributed on an
153cd96b95SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
163cd96b95SAndrew Rist  * KIND, either express or implied.  See the License for the
173cd96b95SAndrew Rist  * specific language governing permissions and limitations
183cd96b95SAndrew Rist  * under the License.
19*facfa769Smseidel  *
203cd96b95SAndrew Rist  *************************************************************/
213cd96b95SAndrew Rist 
223cd96b95SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "HelpCompiler.hxx"
25cdf0e10cSrcweir #include <limits.h>
26cdf0e10cSrcweir #include <stdlib.h>
27cdf0e10cSrcweir #include <string.h>
28cdf0e10cSrcweir #include <libxslt/xslt.h>
29cdf0e10cSrcweir #include <libxslt/xsltInternals.h>
30cdf0e10cSrcweir #include <libxslt/transform.h>
31cdf0e10cSrcweir #include <libxslt/xsltutils.h>
32cdf0e10cSrcweir #ifdef __MINGW32__
33cdf0e10cSrcweir #include <tools/prewin.h>
34cdf0e10cSrcweir #include <tools/postwin.h>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <osl/thread.hxx>
37cdf0e10cSrcweir 
impl_sleep(sal_uInt32 nSec)38cdf0e10cSrcweir static void impl_sleep( sal_uInt32 nSec )
39cdf0e10cSrcweir {
40*facfa769Smseidel 	TimeValue aTime;
41*facfa769Smseidel 	aTime.Seconds = nSec;
42*facfa769Smseidel 	aTime.Nanosec = 0;
43cdf0e10cSrcweir 
44*facfa769Smseidel 	osl::Thread::wait( aTime );
45cdf0e10cSrcweir }
46cdf0e10cSrcweir 
HelpCompiler(StreamTable & in_streamTable,const fs::path & in_inputFile,const fs::path & in_src,const fs::path & in_resEmbStylesheet,const std::string & in_module,const std::string & in_lang,bool in_bExtensionMode)47*facfa769Smseidel HelpCompiler::HelpCompiler(StreamTable &in_streamTable, const fs::path &in_inputFile,
48*facfa769Smseidel 	const fs::path &in_src, const fs::path &in_resEmbStylesheet,
49*facfa769Smseidel 	const std::string &in_module, const std::string &in_lang, bool in_bExtensionMode)
50*facfa769Smseidel 	: streamTable(in_streamTable), inputFile(in_inputFile),
51*facfa769Smseidel 	src(in_src), module(in_module), lang(in_lang), resEmbStylesheet(in_resEmbStylesheet),
52cdf0e10cSrcweir 	bExtensionMode( in_bExtensionMode )
53cdf0e10cSrcweir {
54*facfa769Smseidel 	xmlKeepBlanksDefaultValue = 0;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
getSourceDocument(const fs::path & filePath)57*facfa769Smseidel xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath)
58cdf0e10cSrcweir {
59*facfa769Smseidel 	static const char *params[4 + 1];
60*facfa769Smseidel 	static xsltStylesheetPtr cur = NULL;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	xmlDocPtr res;
63cdf0e10cSrcweir 	if( bExtensionMode )
64cdf0e10cSrcweir 	{
65cdf0e10cSrcweir 		res = xmlParseFile(filePath.native_file_string().c_str());
66*facfa769Smseidel 		if( !res ){
67*facfa769Smseidel 			impl_sleep( 3 );
68*facfa769Smseidel 			res = xmlParseFile(filePath.native_file_string().c_str());
69*facfa769Smseidel 		}
70cdf0e10cSrcweir 	}
71cdf0e10cSrcweir 	else
72cdf0e10cSrcweir 	{
73cdf0e10cSrcweir 		if (!cur)
74cdf0e10cSrcweir 		{
75cdf0e10cSrcweir 			static std::string fsroot('\'' + src.toUTF8() + '\'');
76cdf0e10cSrcweir 			static std::string esclang('\'' + lang + '\'');
77*facfa769Smseidel 
78cdf0e10cSrcweir 			xmlSubstituteEntitiesDefault(1);
79cdf0e10cSrcweir 			xmlLoadExtDtdDefaultValue = 1;
80cdf0e10cSrcweir 			cur = xsltParseStylesheetFile((const xmlChar *)resEmbStylesheet.native_file_string().c_str());
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 			int nbparams = 0;
83cdf0e10cSrcweir 			params[nbparams++] = "Language";
84cdf0e10cSrcweir 			params[nbparams++] = esclang.c_str();
85cdf0e10cSrcweir 			params[nbparams++] = "fsroot";
86cdf0e10cSrcweir 			params[nbparams++] = fsroot.c_str();
87cdf0e10cSrcweir 			params[nbparams] = NULL;
88cdf0e10cSrcweir 		}
89cdf0e10cSrcweir 		xmlDocPtr doc = xmlParseFile(filePath.native_file_string().c_str());
90cdf0e10cSrcweir 		if( !doc )
91*facfa769Smseidel 		{
92*facfa769Smseidel 			impl_sleep( 3 );
93*facfa769Smseidel 			doc = xmlParseFile(filePath.native_file_string().c_str());
94*facfa769Smseidel 		}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		//???res = xmlParseFile(filePath.native_file_string().c_str());
97cdf0e10cSrcweir 
98*facfa769Smseidel 		res = xsltApplyStylesheet(cur, doc, params);
99cdf0e10cSrcweir 		xmlFreeDoc(doc);
100cdf0e10cSrcweir 	}
101*facfa769Smseidel 	return res;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
switchFind(xmlDocPtr doc)104cdf0e10cSrcweir HashSet HelpCompiler::switchFind(xmlDocPtr doc)
105cdf0e10cSrcweir {
106*facfa769Smseidel 	HashSet hs;
107*facfa769Smseidel 	xmlChar *xpath = (xmlChar*)"//switchinline";
108*facfa769Smseidel 
109*facfa769Smseidel 	xmlXPathContextPtr context = xmlXPathNewContext(doc);
110*facfa769Smseidel 	xmlXPathObjectPtr result = xmlXPathEvalExpression(xpath, context);
111*facfa769Smseidel 	xmlXPathFreeContext(context);
112*facfa769Smseidel 	if (result)
113*facfa769Smseidel 	{
114*facfa769Smseidel 		xmlNodeSetPtr nodeset = result->nodesetval;
115*facfa769Smseidel 		for (int i = 0; i < nodeset->nodeNr; i++)
116*facfa769Smseidel 		{
117*facfa769Smseidel 			xmlNodePtr el = nodeset->nodeTab[i];
118*facfa769Smseidel 			xmlChar *select = xmlGetProp(el, (xmlChar*)"select");
119*facfa769Smseidel 			if (select)
120*facfa769Smseidel 			{
121*facfa769Smseidel 				if (!strcmp((const char*)select, "appl"))
122*facfa769Smseidel 				{
123*facfa769Smseidel 					xmlNodePtr n1 = el->xmlChildrenNode;
124*facfa769Smseidel 					while (n1)
125*facfa769Smseidel 					{
126*facfa769Smseidel 						if ((!xmlStrcmp(n1->name, (const xmlChar*)"caseinline")))
127*facfa769Smseidel 						{
128*facfa769Smseidel 							xmlChar *appl = xmlGetProp(n1, (xmlChar*)"select");
129*facfa769Smseidel 							hs.push_back(std::string((const char*)appl));
130*facfa769Smseidel 							xmlFree(appl);
131*facfa769Smseidel 						}
132*facfa769Smseidel 						else if ((!xmlStrcmp(n1->name, (const xmlChar*)"defaultinline")))
133*facfa769Smseidel 							hs.push_back(std::string("DEFAULT"));
134*facfa769Smseidel 						n1 = n1->next;
135*facfa769Smseidel 					}
136*facfa769Smseidel 				}
137*facfa769Smseidel 				xmlFree(select);
138*facfa769Smseidel 			}
139*facfa769Smseidel 		}
140*facfa769Smseidel 		xmlXPathFreeObject(result);
141*facfa769Smseidel 	}
142*facfa769Smseidel 	hs.push_back(std::string("DEFAULT"));
143*facfa769Smseidel 	return hs;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir // returns a node representing the whole stuff compiled for the current
147cdf0e10cSrcweir // application.
clone(xmlNodePtr node,const std::string & appl)148cdf0e10cSrcweir xmlNodePtr HelpCompiler::clone(xmlNodePtr node, const std::string& appl)
149cdf0e10cSrcweir {
150*facfa769Smseidel 	xmlNodePtr parent = xmlCopyNode(node, 2);
151*facfa769Smseidel 	xmlNodePtr n = node->xmlChildrenNode;
152*facfa769Smseidel 	while (n != NULL)
153*facfa769Smseidel 	{
154*facfa769Smseidel 		bool isappl = false;
155*facfa769Smseidel 		if ( (!strcmp((const char*)n->name, "switchinline")) ||
156*facfa769Smseidel 			 (!strcmp((const char*)n->name, "switch")) )
157*facfa769Smseidel 		{
158*facfa769Smseidel 			xmlChar *select = xmlGetProp(n, (xmlChar*)"select");
159*facfa769Smseidel 			if (select)
160*facfa769Smseidel 			{
161*facfa769Smseidel 				if (!strcmp((const char*)select, "appl"))
162*facfa769Smseidel 					isappl = true;
163*facfa769Smseidel 				xmlFree(select);
164*facfa769Smseidel 			}
165*facfa769Smseidel 		}
166*facfa769Smseidel 		if (isappl)
167*facfa769Smseidel 		{
168*facfa769Smseidel 			xmlNodePtr caseNode = n->xmlChildrenNode;
169*facfa769Smseidel 			if (appl == "DEFAULT")
170*facfa769Smseidel 			{
171*facfa769Smseidel 				while (caseNode)
172*facfa769Smseidel 				{
173*facfa769Smseidel 					if (!strcmp((const char*)caseNode->name, "defaultinline"))
174*facfa769Smseidel 					{
175*facfa769Smseidel 						xmlNodePtr cnl = caseNode->xmlChildrenNode;
176*facfa769Smseidel 						while (cnl)
177*facfa769Smseidel 						{
178*facfa769Smseidel 							xmlAddChild(parent, clone(cnl, appl));
179*facfa769Smseidel 							cnl = cnl->next;
180*facfa769Smseidel 						}
181*facfa769Smseidel 						break;
182*facfa769Smseidel 					}
183*facfa769Smseidel 					caseNode = caseNode->next;
184*facfa769Smseidel 				}
185*facfa769Smseidel 			}
186*facfa769Smseidel 			else
187*facfa769Smseidel 			{
188*facfa769Smseidel 				while (caseNode)
189*facfa769Smseidel 				{
190*facfa769Smseidel 					isappl=false;
191*facfa769Smseidel 					if (!strcmp((const char*)caseNode->name, "caseinline"))
192*facfa769Smseidel 					{
193*facfa769Smseidel 						xmlChar *select = xmlGetProp(n, (xmlChar*)"select");
194*facfa769Smseidel 						if (select)
195*facfa769Smseidel 						{
196*facfa769Smseidel 							if (!strcmp((const char*)select, appl.c_str()))
197*facfa769Smseidel 								isappl = true;
198*facfa769Smseidel 							xmlFree(select);
199*facfa769Smseidel 						}
200*facfa769Smseidel 						if (isappl)
201*facfa769Smseidel 						{
202*facfa769Smseidel 							xmlNodePtr cnl = caseNode->xmlChildrenNode;
203*facfa769Smseidel 							while (cnl)
204*facfa769Smseidel 							{
205*facfa769Smseidel 								xmlAddChild(parent, clone(cnl, appl));
206*facfa769Smseidel 								cnl = cnl->next;
207*facfa769Smseidel 							}
208*facfa769Smseidel 							break;
209*facfa769Smseidel 						}
210*facfa769Smseidel 
211*facfa769Smseidel 					}
212*facfa769Smseidel 					caseNode = caseNode->next;
213*facfa769Smseidel 				}
214*facfa769Smseidel 			}
215*facfa769Smseidel 
216*facfa769Smseidel 		}
217*facfa769Smseidel 		else
218*facfa769Smseidel 			xmlAddChild(parent, clone(n, appl));
219*facfa769Smseidel 
220*facfa769Smseidel 		n = n->next;
221*facfa769Smseidel 	}
222*facfa769Smseidel 	return parent;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir class myparser
226cdf0e10cSrcweir {
227cdf0e10cSrcweir public:
228*facfa769Smseidel 	std::string documentId;
229*facfa769Smseidel 	std::string fileName;
230*facfa769Smseidel 	std::string title;
231*facfa769Smseidel 	HashSet *hidlist;
232*facfa769Smseidel 	Hashtable *keywords;
233*facfa769Smseidel 	Stringtable *helptexts;
234cdf0e10cSrcweir private:
235*facfa769Smseidel 	HashSet extendedHelpText;
236cdf0e10cSrcweir public:
myparser(const std::string & indocumentId,const std::string & infileName,const std::string & intitle)237*facfa769Smseidel 	myparser(const std::string &indocumentId, const std::string &infileName,
238*facfa769Smseidel 		const std::string &intitle) : documentId(indocumentId), fileName(infileName),
239*facfa769Smseidel 		title(intitle)
240*facfa769Smseidel 	{
241*facfa769Smseidel 		hidlist = new HashSet;
242*facfa769Smseidel 		keywords = new Hashtable;
243*facfa769Smseidel 		helptexts = new Stringtable;
244*facfa769Smseidel 	}
245*facfa769Smseidel 	void traverse( xmlNodePtr parentNode );
246cdf0e10cSrcweir private:
247*facfa769Smseidel 	std::string dump(xmlNodePtr node);
248cdf0e10cSrcweir };
249cdf0e10cSrcweir 
dump(xmlNodePtr node)250cdf0e10cSrcweir std::string myparser::dump(xmlNodePtr node)
251cdf0e10cSrcweir {
252*facfa769Smseidel 	std::string app;
253*facfa769Smseidel 	if (node->xmlChildrenNode)
254*facfa769Smseidel 	{
255*facfa769Smseidel 		xmlNodePtr list = node->xmlChildrenNode;
256*facfa769Smseidel 		while (list)
257*facfa769Smseidel 		{
258*facfa769Smseidel 			app += dump(list);
259*facfa769Smseidel 			list = list->next;
260*facfa769Smseidel 		}
261*facfa769Smseidel 	}
262*facfa769Smseidel 	if (xmlNodeIsText(node))
263*facfa769Smseidel 	{
264*facfa769Smseidel 		xmlChar *pContent = xmlNodeGetContent(node);
265*facfa769Smseidel 		app += std::string((const char*)pContent);
266*facfa769Smseidel 		xmlFree(pContent);
267*facfa769Smseidel 		// std::cout << app << std::endl;
268*facfa769Smseidel 	}
269*facfa769Smseidel 	return app;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
trim(std::string & str)272cdf0e10cSrcweir void trim(std::string& str)
273cdf0e10cSrcweir {
274*facfa769Smseidel 	std::string::size_type pos = str.find_last_not_of(' ');
275*facfa769Smseidel 	if(pos != std::string::npos)
276*facfa769Smseidel 	{
277*facfa769Smseidel 		str.erase(pos + 1);
278*facfa769Smseidel 		pos = str.find_first_not_of(' ');
279*facfa769Smseidel 		if(pos != std::string::npos)
280*facfa769Smseidel 			str.erase(0, pos);
281*facfa769Smseidel 	}
282*facfa769Smseidel 	else
283*facfa769Smseidel 		str.erase(str.begin(), str.end());
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
traverse(xmlNodePtr parentNode)286cdf0e10cSrcweir void myparser::traverse( xmlNodePtr parentNode )
287cdf0e10cSrcweir {
288*facfa769Smseidel 	// traverse all nodes that belong to the parent
289*facfa769Smseidel 	xmlNodePtr test ;
290*facfa769Smseidel 	for (test = parentNode->xmlChildrenNode; test; test = test->next)
291*facfa769Smseidel 	{
292*facfa769Smseidel 		if (fileName.empty() && !strcmp((const char*)test->name, "filename"))
293*facfa769Smseidel 		{
294*facfa769Smseidel 			xmlNodePtr node = test->xmlChildrenNode;
295*facfa769Smseidel 			if (xmlNodeIsText(node))
296*facfa769Smseidel 			{
297*facfa769Smseidel 				xmlChar *pContent = xmlNodeGetContent(node);
298*facfa769Smseidel 				fileName = std::string((const char*)pContent);
299*facfa769Smseidel 				xmlFree(pContent);
300*facfa769Smseidel 			}
301*facfa769Smseidel 		}
302*facfa769Smseidel 		else if (title.empty() && !strcmp((const char*)test->name, "title"))
303*facfa769Smseidel 		{
304*facfa769Smseidel 			title = dump(test);
305*facfa769Smseidel 			if (title.empty())
306*facfa769Smseidel 				title = "<notitle>";
307*facfa769Smseidel 		}
308*facfa769Smseidel 		else if (!strcmp((const char*)test->name, "bookmark"))
309*facfa769Smseidel 		{
310*facfa769Smseidel 			xmlChar *branchxml = xmlGetProp(test, (const xmlChar*)"branch");
311*facfa769Smseidel 			xmlChar *idxml = xmlGetProp(test, (const xmlChar*)"id");
312*facfa769Smseidel 			std::string branch((const char*)branchxml);
313*facfa769Smseidel 			std::string anchor((const char*)idxml);
314*facfa769Smseidel 			xmlFree (branchxml);
315*facfa769Smseidel 			xmlFree (idxml);
316*facfa769Smseidel 
317*facfa769Smseidel 			std::string hid;
318*facfa769Smseidel 
319*facfa769Smseidel 			if (branch.find("hid") == 0)
320*facfa769Smseidel 			{
321*facfa769Smseidel 				size_t index = branch.find('/');
322*facfa769Smseidel 				if (index != std::string::npos)
323*facfa769Smseidel 				{
324*facfa769Smseidel 					hid = branch.substr(1 + index);
325*facfa769Smseidel 					// one shall serve as a documentId
326*facfa769Smseidel 					if (documentId.empty())
327*facfa769Smseidel 						documentId = hid;
328*facfa769Smseidel 					extendedHelpText.push_back(hid);
329*facfa769Smseidel 					std::string foo = anchor.empty() ? hid : hid + "#" + anchor;
330*facfa769Smseidel 					HCDBG(std::cerr << "hid pushback" << foo << std::endl);
331*facfa769Smseidel 					hidlist->push_back( anchor.empty() ? hid : hid + "#" + anchor);
332*facfa769Smseidel 				}
333*facfa769Smseidel 				else
334*facfa769Smseidel 					continue;
335*facfa769Smseidel 			}
336*facfa769Smseidel 			else if (branch.compare("index") == 0)
337*facfa769Smseidel 			{
338*facfa769Smseidel 				LinkedList ll;
339*facfa769Smseidel 
340*facfa769Smseidel 				for (xmlNodePtr nd = test->xmlChildrenNode; nd; nd = nd->next)
341*facfa769Smseidel 				{
342*facfa769Smseidel 					if (strcmp((const char*)nd->name, "bookmark_value"))
343*facfa769Smseidel 						continue;
344*facfa769Smseidel 
345*facfa769Smseidel 					std::string embedded;
346*facfa769Smseidel 					xmlChar *embeddedxml = xmlGetProp(nd, (const xmlChar*)"embedded");
347*facfa769Smseidel 					if (embeddedxml)
348*facfa769Smseidel 					{
349*facfa769Smseidel 						embedded = std::string((const char*)embeddedxml);
350*facfa769Smseidel 						xmlFree (embeddedxml);
351*facfa769Smseidel 						std::transform (embedded.begin(), embedded.end(),
352*facfa769Smseidel 							embedded.begin(), tolower);
353*facfa769Smseidel 					}
354*facfa769Smseidel 
355*facfa769Smseidel 					bool isEmbedded = !embedded.empty() && embedded.compare("true") == 0;
356*facfa769Smseidel 					if (isEmbedded)
357*facfa769Smseidel 						continue;
358*facfa769Smseidel 
359*facfa769Smseidel 					std::string keyword = dump(nd);
360*facfa769Smseidel 					size_t keywordSem = keyword.find(';');
361*facfa769Smseidel 					if (keywordSem != std::string::npos)
362*facfa769Smseidel 					{
363*facfa769Smseidel 						std::string tmppre =
364*facfa769Smseidel 									keyword.substr(0,keywordSem);
365*facfa769Smseidel 						trim(tmppre);
366*facfa769Smseidel 						std::string tmppos =
367*facfa769Smseidel 									keyword.substr(1+keywordSem);
368*facfa769Smseidel 						trim(tmppos);
369*facfa769Smseidel 						keyword = tmppre + ";" + tmppos;
370*facfa769Smseidel 					}
371*facfa769Smseidel 					ll.push_back(keyword);
372*facfa769Smseidel 				}
373*facfa769Smseidel 				if (!ll.empty())
374*facfa769Smseidel 					(*keywords)[anchor] = ll;
375*facfa769Smseidel 			}
376*facfa769Smseidel 			else if (branch.compare("contents") == 0)
377*facfa769Smseidel 			{
378*facfa769Smseidel 				// currently not used
379*facfa769Smseidel 			}
380*facfa769Smseidel 		}
381*facfa769Smseidel 		else if (!strcmp((const char*)test->name, "ahelp"))
382*facfa769Smseidel 		{
383*facfa769Smseidel 			std::string text = dump(test);
384*facfa769Smseidel 			trim(text);
385*facfa769Smseidel 			std::string name;
386*facfa769Smseidel 
387*facfa769Smseidel 			HashSet::const_iterator aEnd = extendedHelpText.end();
388*facfa769Smseidel 			for (HashSet::const_iterator iter = extendedHelpText.begin(); iter != aEnd;
389*facfa769Smseidel 				++iter)
390*facfa769Smseidel 			{
391*facfa769Smseidel 				name = *iter;
392*facfa769Smseidel 				(*helptexts)[name] = text;
393*facfa769Smseidel 			}
394*facfa769Smseidel 			extendedHelpText.clear();
395*facfa769Smseidel 		}
396*facfa769Smseidel 
397*facfa769Smseidel 		// traverse children
398*facfa769Smseidel 		traverse(test);
399*facfa769Smseidel 	}
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
compile(void)402cdf0e10cSrcweir bool HelpCompiler::compile( void ) throw( HelpProcessingException )
403cdf0e10cSrcweir {
404*facfa769Smseidel 	// we now have the jaroutputstream, which will contain the document.
405*facfa769Smseidel 	// now determine the document as a dom tree in variable docResolved
406*facfa769Smseidel 
407*facfa769Smseidel 	xmlDocPtr docResolvedOrg = getSourceDocument(inputFile);
408*facfa769Smseidel 
409*facfa769Smseidel 	// now add path to the document
410*facfa769Smseidel 	// resolve the dom
411*facfa769Smseidel 	if (!docResolvedOrg)
412*facfa769Smseidel 	{
413*facfa769Smseidel 		impl_sleep( 3 );
414*facfa769Smseidel 		docResolvedOrg = getSourceDocument(inputFile);
415*facfa769Smseidel 		if( !docResolvedOrg )
416*facfa769Smseidel 		{
417cdf0e10cSrcweir 			std::stringstream aStrStream;
418*facfa769Smseidel 			aStrStream << "ERROR: file not existing: " << inputFile.native_file_string().c_str() << std::endl;
419*facfa769Smseidel 			throw HelpProcessingException( HELPPROCESSING_GENERAL_ERROR, aStrStream.str() );
420*facfa769Smseidel 		}
421*facfa769Smseidel 	}
422*facfa769Smseidel 
423*facfa769Smseidel 	// now find all applications for which one has to compile
424*facfa769Smseidel 	std::string documentId;
425*facfa769Smseidel 	std::string fileName;
426*facfa769Smseidel 	std::string title;
427*facfa769Smseidel 	// returns all applications for which one has to compile
428*facfa769Smseidel 	HashSet applications = switchFind(docResolvedOrg);
429*facfa769Smseidel 
430*facfa769Smseidel 	HashSet::const_iterator aEnd = applications.end();
431*facfa769Smseidel 	for (HashSet::const_iterator aI = applications.begin(); aI != aEnd; ++aI)
432*facfa769Smseidel 	{
433*facfa769Smseidel 		std::string appl = *aI;
434*facfa769Smseidel 		std::string modulename = appl;
435*facfa769Smseidel 		if (modulename[0] == 'S')
436*facfa769Smseidel 		{
437*facfa769Smseidel 			modulename = modulename.substr(1);
438*facfa769Smseidel 			std::transform(modulename.begin(), modulename.end(), modulename.begin(), tolower);
439*facfa769Smseidel 		}
440*facfa769Smseidel 		if (modulename != "DEFAULT" && modulename != module)
441*facfa769Smseidel 			continue;
442*facfa769Smseidel 
443*facfa769Smseidel 		// returns a clone of the document with switch-cases resolved
444*facfa769Smseidel 		xmlNodePtr docResolved = clone(xmlDocGetRootElement(docResolvedOrg), appl);
445*facfa769Smseidel 		myparser aparser(documentId, fileName, title);
446*facfa769Smseidel 		aparser.traverse(docResolved);
447*facfa769Smseidel 
448*facfa769Smseidel 		documentId = aparser.documentId;
449*facfa769Smseidel 		fileName = aparser.fileName;
450*facfa769Smseidel 		title = aparser.title;
451*facfa769Smseidel 
452*facfa769Smseidel 		HCDBG(std::cerr << documentId << " : " << fileName << " : " << title << std::endl);
453*facfa769Smseidel 
454*facfa769Smseidel 		xmlDocPtr docResolvedDoc = xmlCopyDoc(docResolvedOrg, false);
455*facfa769Smseidel 		xmlDocSetRootElement(docResolvedDoc, docResolved);
456*facfa769Smseidel 
457*facfa769Smseidel 		if (modulename == "DEFAULT")
458*facfa769Smseidel 		{
459*facfa769Smseidel 			streamTable.dropdefault();
460*facfa769Smseidel 			streamTable.default_doc = docResolvedDoc;
461*facfa769Smseidel 			streamTable.default_hidlist = aparser.hidlist;
462*facfa769Smseidel 			streamTable.default_helptexts = aparser.helptexts;
463*facfa769Smseidel 			streamTable.default_keywords = aparser.keywords;
464*facfa769Smseidel 		}
465*facfa769Smseidel 		else if (modulename == module)
466*facfa769Smseidel 		{
467*facfa769Smseidel 			streamTable.dropappl();
468*facfa769Smseidel 			streamTable.appl_doc = docResolvedDoc;
469*facfa769Smseidel 			streamTable.appl_hidlist = aparser.hidlist;
470*facfa769Smseidel 			streamTable.appl_helptexts = aparser.helptexts;
471*facfa769Smseidel 			streamTable.appl_keywords = aparser.keywords;
472*facfa769Smseidel 		}
473*facfa769Smseidel 		else
474*facfa769Smseidel 		{
475*facfa769Smseidel 			std::stringstream aStrStream;
476*facfa769Smseidel 			aStrStream << "ERROR: Found unexpected module name \"" << modulename
477cdf0e10cSrcweir 					   << "\" in file" << src.native_file_string().c_str() << std::endl;
478cdf0e10cSrcweir 			throw HelpProcessingException( HELPPROCESSING_GENERAL_ERROR, aStrStream.str() );
479*facfa769Smseidel 		}
480*facfa769Smseidel 
481*facfa769Smseidel 	} // end iteration over all applications
482*facfa769Smseidel 
483*facfa769Smseidel 	streamTable.document_id = documentId;
484*facfa769Smseidel 	streamTable.document_path = fileName;
485*facfa769Smseidel 	streamTable.document_title = title;
486*facfa769Smseidel 	std::string actMod = module;
487*facfa769Smseidel 	if ( !bExtensionMode && !fileName.empty())
488*facfa769Smseidel 	{
489*facfa769Smseidel 		if (fileName.find("/text/") == 0)
490*facfa769Smseidel 		{
491*facfa769Smseidel 			int len = strlen("/text/");
492*facfa769Smseidel 			actMod = fileName.substr(len);
493*facfa769Smseidel 			actMod = actMod.substr(0, actMod.find('/'));
494*facfa769Smseidel 		}
495*facfa769Smseidel 	}
496*facfa769Smseidel 	streamTable.document_module = actMod;
497*facfa769Smseidel 
498*facfa769Smseidel 	xmlFreeDoc(docResolvedOrg);
499*facfa769Smseidel 	return true;
500cdf0e10cSrcweir }
501cdf0e10cSrcweir 
502cdf0e10cSrcweir namespace fs
503cdf0e10cSrcweir {
getThreadTextEncoding(void)504cdf0e10cSrcweir 	rtl_TextEncoding getThreadTextEncoding( void )
505cdf0e10cSrcweir 	{
506cdf0e10cSrcweir 		static bool bNeedsInit = true;
507cdf0e10cSrcweir 		static rtl_TextEncoding nThreadTextEncoding;
508cdf0e10cSrcweir 		if( bNeedsInit )
509cdf0e10cSrcweir 		{
510cdf0e10cSrcweir 			bNeedsInit = false;
511cdf0e10cSrcweir 			nThreadTextEncoding = osl_getThreadTextEncoding();
512cdf0e10cSrcweir 		}
513cdf0e10cSrcweir 		return nThreadTextEncoding;
514cdf0e10cSrcweir 	}
515cdf0e10cSrcweir 
create_directory(const fs::path indexDirName)516*facfa769Smseidel 	void create_directory(const fs::path indexDirName)
517*facfa769Smseidel 	{
518*facfa769Smseidel 		HCDBG(
519*facfa769Smseidel 			std::cerr << "creating " <<
520*facfa769Smseidel 			rtl::OUStringToOString(indexDirName.data, RTL_TEXTENCODING_UTF8).getStr()
521*facfa769Smseidel 			<< std::endl
522*facfa769Smseidel 			 );
523*facfa769Smseidel 		osl::Directory::createPath(indexDirName.data);
524*facfa769Smseidel 	}
525*facfa769Smseidel 
rename(const fs::path & src,const fs::path & dest)526*facfa769Smseidel 	void rename(const fs::path &src, const fs::path &dest)
527*facfa769Smseidel 	{
528*facfa769Smseidel 		osl::File::move(src.data, dest.data);
529*facfa769Smseidel 	}
530*facfa769Smseidel 
copy(const fs::path & src,const fs::path & dest)531*facfa769Smseidel 	void copy(const fs::path &src, const fs::path &dest)
532*facfa769Smseidel 	{
533*facfa769Smseidel 		osl::File::copy(src.data, dest.data);
534*facfa769Smseidel 	}
535*facfa769Smseidel 
exists(const fs::path & in)536*facfa769Smseidel 	bool exists(const fs::path &in)
537*facfa769Smseidel 	{
538*facfa769Smseidel 		osl::File tmp(in.data);
539*facfa769Smseidel 		return (tmp.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None);
540*facfa769Smseidel 	}
541*facfa769Smseidel 
remove(const fs::path & in)542*facfa769Smseidel 	void remove(const fs::path &in)
543*facfa769Smseidel 	{
544*facfa769Smseidel 		osl::File::remove(in.data);
545*facfa769Smseidel 	}
546*facfa769Smseidel 
removeRecursive(rtl::OUString const & _suDirURL)547*facfa769Smseidel 	void removeRecursive(rtl::OUString const& _suDirURL)
548*facfa769Smseidel 	{
549*facfa769Smseidel 		{
550*facfa769Smseidel 			osl::Directory aDir(_suDirURL);
551*facfa769Smseidel 			aDir.open();
552*facfa769Smseidel 			if (aDir.isOpen())
553*facfa769Smseidel 			{
554*facfa769Smseidel 				osl::DirectoryItem aItem;
555*facfa769Smseidel 				osl::FileStatus aStatus(osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Attributes);
556*facfa769Smseidel 				while (aDir.getNextItem(aItem) == ::osl::FileBase::E_None)
557*facfa769Smseidel 				{
558*facfa769Smseidel 					if (osl::FileBase::E_None == aItem.getFileStatus(aStatus) &&
559*facfa769Smseidel 						aStatus.isValid(osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Attributes))
560*facfa769Smseidel 					{
561*facfa769Smseidel 						rtl::OUString suFilename = aStatus.getFileName();
562*facfa769Smseidel 						rtl::OUString suFullFileURL;
563*facfa769Smseidel 						suFullFileURL += _suDirURL;
564*facfa769Smseidel 						suFullFileURL += rtl::OUString::createFromAscii("/");
565*facfa769Smseidel 						suFullFileURL += suFilename;
566*facfa769Smseidel 
567*facfa769Smseidel 						if (aStatus.getFileType() == osl::FileStatus::Directory)
568*facfa769Smseidel 							removeRecursive(suFullFileURL);
569*facfa769Smseidel 						else
570*facfa769Smseidel 							osl::File::remove(suFullFileURL);
571*facfa769Smseidel 					}
572*facfa769Smseidel 				}
573*facfa769Smseidel 				aDir.close();
574*facfa769Smseidel 			}
575*facfa769Smseidel 		}
576*facfa769Smseidel 		osl::Directory::remove(_suDirURL);
577*facfa769Smseidel 	}
578*facfa769Smseidel 
remove_all(const fs::path & in)579*facfa769Smseidel 	void remove_all(const fs::path &in)
580*facfa769Smseidel 	{
581*facfa769Smseidel 		removeRecursive(in.data);
582*facfa769Smseidel 	}
583cdf0e10cSrcweir }
584cdf0e10cSrcweir 
585*facfa769Smseidel /* vim: set noet sw=4 ts=4: */
586