l10ntools/source/help/HelpIndexer.cxx | 77 +++++++++++++++-------------- l10ntools/source/help/HelpIndexer_main.cxx | 12 ---- 2 files changed, 44 insertions(+), 45 deletions(-)
New commits: commit 4c912d3d8bd1ae01131e90fb4a2d8371a53ee888 Author: Caolán McNamara <caol...@redhat.com> Date: Mon Jul 9 13:41:34 2012 +0100 Resolves: fdo#51572 catch CLuceneError throws and extract the error message I can't reproduce fdo#51572, but catching the exception in HelpIndexer::indexDocuments should resolve it anyway and make it non-fatal. Collect the error message for retrieval via HelpIndexer::getErrorMessage Change-Id: Id557b9f5ff968c398f76969591f5ee765e56aa5a diff --git a/l10ntools/source/help/HelpIndexer.cxx b/l10ntools/source/help/HelpIndexer.cxx index 3c595b4..72a0d04 100644 --- a/l10ntools/source/help/HelpIndexer.cxx +++ b/l10ntools/source/help/HelpIndexer.cxx @@ -34,7 +34,7 @@ #include <rtl/ustrbuf.hxx> #include <osl/file.hxx> #include <osl/thread.h> - +#include <boost/scoped_ptr.hpp> #include <algorithm> #include "LuceneHelper.hxx" @@ -51,44 +51,51 @@ HelpIndexer::HelpIndexer(rtl::OUString const &lang, rtl::OUString const &module, d_contentDir = srcDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/content")); } -bool HelpIndexer::indexDocuments() { - if (!scanForFiles()) { +bool HelpIndexer::indexDocuments() +{ + if (!scanForFiles()) return false; - } - rtl::OUString sLang = d_lang.getToken(0, '-'); - bool bUseCJK = sLang == "ja" || sLang == "ko" || sLang == "zh"; - - // Construct the analyzer appropriate for the given language - lucene::analysis::Analyzer *analyzer; - if (bUseCJK) - analyzer = new lucene::analysis::LanguageBasedAnalyzer(L"cjk"); - else - analyzer = new lucene::analysis::standard::StandardAnalyzer(); - - rtl::OUString ustrSystemPath; - osl::File::getSystemPathFromFileURL(d_indexDir, ustrSystemPath); - - rtl::OString indexDirStr = rtl::OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding()); - lucene::index::IndexWriter writer(indexDirStr.getStr(), analyzer, true); - //Double limit of tokens allowed, otherwise we'll get a too-many-tokens - //exception for ja help. Could alternative ignore the exception and get - //truncated results as per java-Lucene apparently - writer.setMaxFieldLength(lucene::index::IndexWriter::DEFAULT_MAX_FIELD_LENGTH*2); - - // Index the identified help files - Document doc; - for (std::set<rtl::OUString>::iterator i = d_files.begin(); i != d_files.end(); ++i) { - helpDocument(*i, &doc); - writer.addDocument(&doc); - doc.clear(); - } - writer.optimize(); + try + { + rtl::OUString sLang = d_lang.getToken(0, '-'); + bool bUseCJK = sLang == "ja" || sLang == "ko" || sLang == "zh"; + + // Construct the analyzer appropriate for the given language + boost::scoped_ptr<lucene::analysis::Analyzer> analyzer; + if (bUseCJK) + analyzer.reset(new lucene::analysis::LanguageBasedAnalyzer(L"cjk")); + else + analyzer.reset(new lucene::analysis::standard::StandardAnalyzer()); - // Optimize the index - writer.optimize(); + rtl::OUString ustrSystemPath; + osl::File::getSystemPathFromFileURL(d_indexDir, ustrSystemPath); + + rtl::OString indexDirStr = rtl::OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding()); + lucene::index::IndexWriter writer(indexDirStr.getStr(), analyzer.get(), true); + //Double limit of tokens allowed, otherwise we'll get a too-many-tokens + //exception for ja help. Could alternative ignore the exception and get + //truncated results as per java-Lucene apparently + writer.setMaxFieldLength(lucene::index::IndexWriter::DEFAULT_MAX_FIELD_LENGTH*2); + + // Index the identified help files + Document doc; + for (std::set<rtl::OUString>::iterator i = d_files.begin(); i != d_files.end(); ++i) { + helpDocument(*i, &doc); + writer.addDocument(&doc); + doc.clear(); + } + writer.optimize(); + + // Optimize the index + writer.optimize(); + } + catch (CLuceneError &e) + { + d_error = rtl::OUString::createFromAscii(e.what()); + return false; + } - delete analyzer; return true; } diff --git a/l10ntools/source/help/HelpIndexer_main.cxx b/l10ntools/source/help/HelpIndexer_main.cxx index bf42a4c..48e0f3e 100644 --- a/l10ntools/source/help/HelpIndexer_main.cxx +++ b/l10ntools/source/help/HelpIndexer_main.cxx @@ -99,16 +99,8 @@ int main(int argc, char **argv) { rtl::OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()), sDir, sDir); - try - { - if (!indexer.indexDocuments()) { - std::cerr << rtl::OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl; - return 2; - } - } - catch (CLuceneError &e) - { - std::cerr << e.what() << std::endl; + if (!indexer.indexDocuments()) { + std::cerr << rtl::OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl; return 2; } return 0;
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits