28#include <libxslt/xsltInternals.h>
29#include <libxslt/transform.h>
30#include <rtl/character.hxx>
36 fs::path in_resEmbStylesheet, std::string in_module, std::string in_lang,
37 bool in_bExtensionMode)
38 : streamTable(in_streamTable), inputFile(
std::move(in_inputFile)),
39 src(
std::move(in_src)), zipdir(
std::move(in_zipdir)),
module(
std::move(in_module)), lang(
std::move(in_lang)), resCompactStylesheet(
std::move(in_resCompactStylesheet)),
40 resEmbStylesheet(
std::move(in_resEmbStylesheet)), bExtensionMode( in_bExtensionMode )
42 xmlKeepBlanksDefaultValue = 0;
43 char* os = getenv(
"OS");
46 gui = (strcmp(os,
"WNT") ?
"UNIX" :
"WIN");
47 gui = (strcmp(os,
"MACOSX") ?
gui :
"MAC");
67 static xsltStylesheetPtr compact =
nullptr;
68 static const char *params[2 + 1];
77 compacted = xsltApplyStylesheet(compact, doc, params);
85 std::string pathSep =
"\\";
87 std::string pathSep =
"/";
89 const std::string& sourceXhpPath =
filePath.native_file_string();
93 std::string jarXhpPath = sourceXhpPath.substr( srcdirPath.length() - 1 );
94 std::string xhpFileName = jarXhpPath.substr( jarXhpPath.rfind( pathSep ) + 1 );
95 jarXhpPath = jarXhpPath.substr( 0, jarXhpPath.rfind( pathSep ) );
96 if ( !jarXhpPath.compare( 1, 11,
"text" + pathSep +
"sbasic" ) )
100 if ( !jarXhpPath.compare( 1, 11,
"text" + pathSep +
"shared" ) )
102 const size_t pos = zipdirPath.find(
"ziptmp" );
103 if (
pos != std::string::npos )
104 zipdirPath.replace(
pos + 6,
module.length(),
"shared" );
108 if ( -1 == xmlSaveFormatFileEnc( (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str(), compacted,
"utf-8", 0 ) )
109 std::cerr <<
"Error saving file to " << (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str() << std::endl;
110 xmlFreeDoc(compacted);
120 res = xmlParseFile(
filePath.native_file_string().c_str());
126 static xsltStylesheetPtr cur =
nullptr;
127 static const char *params[2 + 1];
130 static std::string fsroot(
'\'' +
src.
toUTF8() +
'\'');
135 params[nbparams++] =
"fsroot";
136 params[nbparams++] = fsroot.c_str();
137 params[nbparams] =
nullptr;
139 xmlDocPtr doc = xmlParseFile(
filePath.native_file_string().c_str());
143 res = xsltApplyStylesheet(cur, doc, params);
153 xmlNodePtr root = xmlCopyNode(node, 2);
154 if (node->xmlChildrenNode)
156 xmlNodePtr list = node->xmlChildrenNode;
159 if (strcmp(
reinterpret_cast<const char*
>(list->name),
"switchinline") == 0 || strcmp(
reinterpret_cast<const char*
>(list->name),
"switch") == 0)
162 xmlChar * prop = xmlGetProp(list,
reinterpret_cast<xmlChar
const *
>(
"select"));
165 if (strcmp(
reinterpret_cast<char *
>(prop),
"sys") == 0)
169 else if (strcmp(
reinterpret_cast<char *
>(prop),
"appl") == 0)
175 if (tmp.compare(
"") != 0)
178 xmlNodePtr caseList=list->xmlChildrenNode;
181 xmlChar *select = xmlGetProp(caseList,
reinterpret_cast<xmlChar
const *
>(
"select"));
184 if (!strcmp(
reinterpret_cast<char*
>(select), tmp.c_str()) && !isCase)
187 xmlNodePtr clp = caseList->xmlChildrenNode;
190 xmlAddChild(root,
clone(clp, appl));
198 if ((strcmp(
reinterpret_cast<const char*
>(caseList->name),
"defaultinline") != 0) && (strcmp(
reinterpret_cast<const char*
>(caseList->name),
"default") != 0))
200 xmlAddChild(root,
clone(caseList, appl));
206 xmlNodePtr clp = caseList->xmlChildrenNode;
209 xmlAddChild(root,
clone(clp, appl));
215 caseList = caseList->next;
221 xmlAddChild(root,
clone(list, appl));
234 std::string documentId;
235 std::string fileName;
237 std::unique_ptr< std::vector<std::string> > hidlist;
238 std::unique_ptr<Hashtable> keywords;
239 std::unique_ptr<Stringtable> helptexts;
241 std::vector<std::string> extendedHelpText;
243 myparser(std::string indocumentId, std::string infileName,
244 std::string intitle) : documentId(
std::move(indocumentId)), fileName(
std::move(infileName)),
245 title(
std::move(intitle))
247 hidlist.reset(
new std::vector<std::string>);
251 void traverse( xmlNodePtr parentNode );
253 std::string
dump(xmlNodePtr node);
258std::string myparser::dump(xmlNodePtr node)
261 if (node->xmlChildrenNode)
263 xmlNodePtr list = node->xmlChildrenNode;
270 if (xmlNodeIsText(node))
272 xmlChar *pContent = xmlNodeGetContent(node);
273 app += std::string(
reinterpret_cast<char*
>(pContent));
279static void trim(std::string& str)
281 std::string::size_type
pos = str.find_last_not_of(
' ');
282 if(
pos != std::string::npos)
285 pos = str.find_first_not_of(
' ');
286 if(
pos != std::string::npos)
293void myparser::traverse( xmlNodePtr parentNode )
299 if (fileName.empty() && !strcmp(
reinterpret_cast<const char*
>(
test->name),
"filename"))
301 xmlNodePtr node =
test->xmlChildrenNode;
302 if (xmlNodeIsText(node))
304 xmlChar *pContent = xmlNodeGetContent(node);
305 fileName = std::string(
reinterpret_cast<char*
>(pContent));
309 else if (title.empty() && !strcmp(
reinterpret_cast<const char*
>(
test->name),
"title"))
315 else if (!strcmp(
reinterpret_cast<const char*
>(
test->name),
"bookmark"))
317 xmlChar *branchxml = xmlGetProp(
test,
reinterpret_cast<const xmlChar*
>(
"branch"));
318 if (branchxml ==
nullptr) {
322 std::string branch(
reinterpret_cast<char*
>(branchxml));
324 xmlChar *idxml = xmlGetProp(
test,
reinterpret_cast<const xmlChar*
>(
"id"));
325 if (idxml ==
nullptr) {
329 std::string
anchor(
reinterpret_cast<char*
>(idxml));
332 if (branch.compare(0, 3,
"hid") == 0)
334 size_t index = branch.find(
'/');
335 if (index != std::string::npos)
337 auto hid = branch.substr(1 + index);
339 if (documentId.empty())
341 extendedHelpText.push_back(hid);
342 HCDBG(std::cerr <<
"hid pushback" << (
anchor.empty() ? hid : hid +
"#" +
anchor) << std::endl);
343 hidlist->push_back(
anchor.empty() ? hid : hid +
"#" +
anchor);
348 else if (branch.compare(
"index") == 0)
352 for (xmlNodePtr nd =
test->xmlChildrenNode; nd; nd = nd->next)
354 if (strcmp(
reinterpret_cast<const char*
>(nd->name),
"bookmark_value"))
357 std::string embedded;
358 xmlChar *embeddedxml = xmlGetProp(nd,
reinterpret_cast<const xmlChar*
>(
"embedded"));
361 embedded = std::string(
reinterpret_cast<char*
>(embeddedxml));
362 xmlFree (embeddedxml);
363 std::transform (embedded.begin(), embedded.end(),
367 bool isEmbedded = !embedded.empty() && embedded.compare(
"true") == 0;
371 std::string keyword =
dump(nd);
372 size_t keywordSem = keyword.find(
';');
373 if (keywordSem != std::string::npos)
376 keyword.substr(0,keywordSem);
379 keyword.substr(1+keywordSem);
381 keyword = tmppre +
";" + tmppos;
383 ll.push_back(keyword);
388 else if (branch.compare(
"contents") == 0)
393 else if (!strcmp(
reinterpret_cast<const char*
>(
test->name),
"ahelp"))
397 std::replace(
text.begin(),
text.end(),
'\n',
' ');
401 std::string hidstr(
".");
402 xmlChar *hid = xmlGetProp(
test,
reinterpret_cast<const xmlChar*
>(
"hid"));
405 hidstr = std::string(
reinterpret_cast<char*
>(hid));
409 if (hidstr !=
"." && !hidstr.empty())
411 assert(!hidstr.empty());
412 (*helptexts)[hidstr] =
text;
417 SAL_WARN_IF(hidstr.empty(),
"helpcompiler",
"hid='' for text:" << text);
418 SAL_WARN_IF(!hidstr.empty() && extendedHelpText.empty(),
"helpcompiler",
"hid='.' with no hid bookmark branches in file: " << fileName +
" for text: " << text);
419 for (
const std::string& name : extendedHelpText)
424 extendedHelpText.clear();
443 std::stringstream aStrStream;
448 std::string documentId;
449 std::string fileName;
452 std::string appl =
module.substr(1);
453 for (
char &
i : appl)
455 i=rtl::toAsciiUpperCase(
static_cast<unsigned char>(
i));
457 xmlNodePtr docResolved =
clone(xmlDocGetRootElement(docResolvedOrg), appl);
458 myparser aparser(documentId, fileName, title);
459 aparser.traverse(docResolved);
460 documentId = aparser.documentId;
461 fileName = aparser.fileName;
462 title = aparser.title;
464 HCDBG(std::cerr << documentId <<
" : " << fileName <<
" : " << title << std::endl);
466 xmlDocPtr docResolvedDoc = xmlCopyDoc(docResolvedOrg,
false);
467 xmlDocSetRootElement(docResolvedDoc, docResolved);
477 std::string actMod =
module;
481 if (fileName.compare(0, 6,
"/text/") == 0)
483 actMod = fileName.substr(strlen(
"/text/"));
484 actMod = actMod.substr(0, actMod.find(
'/'));
488 xmlFreeDoc(docResolvedOrg);
496 std::cerr <<
"creating " <<
500 osl::Directory::createPath(indexDirName.
data);
505 osl::File::copy(src.
data, dest.
data);
static void trim(std::string &str)
std::unordered_map< std::string, LinkedList > Hashtable
std::unordered_map< std::string, std::string > Stringtable
std::deque< std::string > LinkedList
void tagBasicCodes()
Manages tagging process.
const fs::path resEmbStylesheet
xmlNodePtr clone(xmlNodePtr node, const std::string &appl)
xmlDocPtr compactXhpForJar(xmlDocPtr doc)
void saveXhpForJar(xmlDocPtr doc, const fs::path &filePath)
static void tagBasicCodeExamples(xmlDocPtr doc)
xmlDocPtr getSourceDocument(const fs::path &filePath)
const fs::path resCompactStylesheet
HelpCompiler(StreamTable &streamTable, fs::path in_inputFile, fs::path in_src, fs::path in_zipdir, fs::path in_resCompactStylesheet, fs::path in_resEmbStylesheet, std::string in_module, std::string in_lang, bool in_bExtensionMode)
StreamTable & streamTable
std::string document_module
std::unique_ptr< Hashtable > appl_keywords
std::string document_path
std::unique_ptr< Stringtable > appl_helptexts
std::unique_ptr< std::vector< std::string > > appl_hidlist
std::string document_title
std::string native_file_string() const
std::string toUTF8() const
#define SAL_WARN_IF(condition, area, stream)
VCL_DLLPUBLIC void dump(const SkBitmap &bitmap, const char *file)
void copy(const fs::path &src, const fs::path &dest)
void create_directory(const fs::path &indexDirName)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)