diff options
author | Andras Timar <atimar@suse.com> | 2013-02-13 16:28:16 +0100 |
---|---|---|
committer | Andras Timar <atimar@suse.com> | 2013-02-13 16:37:35 +0100 |
commit | a775aa57f7b1d5f0f69b8faa5277d1914455ba38 (patch) | |
tree | 5aa3130772eba2cc2285cdff43b3947451449e84 /helpcompiler | |
parent | 4552bd5a7c61c4f9428ad73e19bbee5b78e510ab (diff) |
compact help xml files with xslt which removes the cruft
Change-Id: Iee923174169d6ba9961a9cee14115c9a4bf7ba09
Diffstat (limited to 'helpcompiler')
-rw-r--r-- | helpcompiler/inc/HelpCompiler.hxx | 3 | ||||
-rw-r--r-- | helpcompiler/inc/HelpLinker.hxx | 1 | ||||
-rw-r--r-- | helpcompiler/source/HelpCompiler.cxx | 29 | ||||
-rw-r--r-- | helpcompiler/source/HelpLinker.cxx | 14 |
4 files changed, 41 insertions, 6 deletions
diff --git a/helpcompiler/inc/HelpCompiler.hxx b/helpcompiler/inc/HelpCompiler.hxx index 8a5dda170747..0ee28019e2dd 100644 --- a/helpcompiler/inc/HelpCompiler.hxx +++ b/helpcompiler/inc/HelpCompiler.hxx @@ -230,6 +230,7 @@ public: const fs::path &in_inputFile, const fs::path &in_src, const fs::path &in_zipdir, + const fs::path &in_resCompactStylesheet, const fs::path &in_resEmbStylesheet, const std::string &in_module, const std::string &in_lang, @@ -246,11 +247,13 @@ public: private: xmlDocPtr getSourceDocument(const fs::path &filePath); void tagBasicCodeExamples(xmlDocPtr doc); + xmlDocPtr compactXhpForJar(xmlDocPtr doc); void saveXhpForJar(xmlDocPtr doc, const fs::path &filePath); xmlNodePtr clone(xmlNodePtr node, const std::string& appl); StreamTable &streamTable; const fs::path inputFile, src, zipdir; const std::string module, lang; + const fs::path resCompactStylesheet; const fs::path resEmbStylesheet; bool bExtensionMode; std::string gui; diff --git a/helpcompiler/inc/HelpLinker.hxx b/helpcompiler/inc/HelpLinker.hxx index 57e21a5424d1..5e2e88dc70f8 100644 --- a/helpcompiler/inc/HelpLinker.hxx +++ b/helpcompiler/inc/HelpLinker.hxx @@ -66,6 +66,7 @@ private: Stringtable additionalFiles; HashSet helpFiles; fs::path sourceRoot; + fs::path compactStylesheet; fs::path embeddStylesheet; fs::path idxCaptionStylesheet; fs::path idxContentStylesheet; diff --git a/helpcompiler/source/HelpCompiler.cxx b/helpcompiler/source/HelpCompiler.cxx index 3983f169603d..eedc7fd660b5 100644 --- a/helpcompiler/source/HelpCompiler.cxx +++ b/helpcompiler/source/HelpCompiler.cxx @@ -38,11 +38,12 @@ static void impl_sleep( sal_uInt32 nSec ) osl::Thread::wait( aTime ); } HelpCompiler::HelpCompiler(StreamTable &in_streamTable, const fs::path &in_inputFile, - const fs::path &in_src, const fs::path &in_zipdir, const fs::path &in_resEmbStylesheet, - const std::string &in_module, const std::string &in_lang, bool in_bExtensionMode) + const fs::path &in_src, const fs::path &in_zipdir, const fs::path &in_resCompactStylesheet, + const fs::path &in_resEmbStylesheet, const std::string &in_module, const std::string &in_lang, + bool in_bExtensionMode) : streamTable(in_streamTable), inputFile(in_inputFile), - src(in_src), zipdir(in_zipdir), module(in_module), lang(in_lang), resEmbStylesheet(in_resEmbStylesheet), - bExtensionMode( in_bExtensionMode ) + src(in_src), zipdir(in_zipdir), module(in_module), lang(in_lang), resCompactStylesheet(in_resCompactStylesheet), + resEmbStylesheet(in_resEmbStylesheet), bExtensionMode( in_bExtensionMode ) { xmlKeepBlanksDefaultValue = 0; char* guitmp = getenv("GUI"); @@ -68,6 +69,22 @@ void HelpCompiler::tagBasicCodeExamples( xmlDocPtr doc ) } } +xmlDocPtr HelpCompiler::compactXhpForJar( xmlDocPtr doc ) +{ + static xsltStylesheetPtr compact = NULL; + static const char *params[2 + 1]; + params[0] = NULL; + xmlDocPtr compacted; + + if (!compact) + { + compact = xsltParseStylesheetFile((const xmlChar *)resCompactStylesheet.native_file_string().c_str()); + } + + compacted = xsltApplyStylesheet(compact, doc, params); + return compacted; +} + void HelpCompiler::saveXhpForJar( xmlDocPtr doc, const fs::path &filePath ) { //save processed xhp document in ziptmp<module>_<lang>/text directory @@ -90,9 +107,11 @@ void HelpCompiler::saveXhpForJar( xmlDocPtr doc, const fs::path &filePath ) size_t pos = zipdirPath.find( "ziptmp" ) + 6; zipdirPath.replace( pos, module.length(), "shared" ); } + xmlDocPtr compacted = compactXhpForJar( doc ); fs::create_directory( fs::path( zipdirPath + jarXhpPath, fs::native ) ); - if ( -1 == xmlSaveFormatFileEnc( (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str(), doc, "utf-8", 0 ) ) + if ( -1 == xmlSaveFormatFileEnc( (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str(), compacted, "utf-8", 0 ) ) std::cerr << "Error saving file to " << (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str() << std::endl; + xmlFreeDoc(compacted); } diff --git a/helpcompiler/source/HelpLinker.cxx b/helpcompiler/source/HelpLinker.cxx index 4bbe2b6bd23e..6d00f67742e3 100644 --- a/helpcompiler/source/HelpLinker.cxx +++ b/helpcompiler/source/HelpLinker.cxx @@ -378,7 +378,7 @@ void HelpLinker::link() throw( HelpProcessingException ) } HelpCompiler hc( streamTable, xhpFile, langsourceRoot, zipdir, - embeddStylesheet, module, lang, bExtensionMode ); + compactStylesheet, embeddStylesheet, module, lang, bExtensionMode ); HCDBG(std::cerr << "before compile of " << xhpFileName << std::endl); bool success = hc.compile(); @@ -608,6 +608,18 @@ void HelpLinker::main( std::vector<std::string> &args, bSrcOption = true; sourceRoot = fs::path(args[i], fs::native); } + else if (args[i].compare("-compact") == 0) + { + ++i; + if (i >= args.size()) + { + std::stringstream aStrStream; + aStrStream << "compactStylesheet missing" << std::endl; + throw HelpProcessingException( HELPPROCESSING_GENERAL_ERROR, aStrStream.str() ); + } + + compactStylesheet = fs::path(args[i], fs::native); + } else if (args[i].compare("-sty") == 0) { ++i; |