diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-07-09 13:41:34 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-07-09 13:41:34 +0100 |
commit | 4c912d3d8bd1ae01131e90fb4a2d8371a53ee888 (patch) | |
tree | 9fb299b160ec45e8faf4c5f641297f3097c22fa4 /l10ntools | |
parent | 4fc8af89257436b9cad70de574a166aa11ec42f1 (diff) |
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
Diffstat (limited to 'l10ntools')
-rw-r--r-- | l10ntools/source/help/HelpIndexer.cxx | 77 | ||||
-rw-r--r-- | l10ntools/source/help/HelpIndexer_main.cxx | 12 |
2 files changed, 44 insertions, 45 deletions
diff --git a/l10ntools/source/help/HelpIndexer.cxx b/l10ntools/source/help/HelpIndexer.cxx index 3c595b4b3bd6..72a0d045229e 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 bf42a4cdd84d..48e0f3eecdda 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; |