diff options
-rw-r--r-- | l10ntools/source/help/HelpIndexer.cxx | 59 | ||||
-rw-r--r-- | l10ntools/source/help/HelpIndexer.hxx | 32 | ||||
-rw-r--r-- | l10ntools/source/help/HelpIndexer_main.cxx | 9 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/databases.cxx | 102 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/makefile.mk | 5 |
5 files changed, 105 insertions, 102 deletions
diff --git a/l10ntools/source/help/HelpIndexer.cxx b/l10ntools/source/help/HelpIndexer.cxx index ed0ce39a523a..f86d265d33be 100644 --- a/l10ntools/source/help/HelpIndexer.cxx +++ b/l10ntools/source/help/HelpIndexer.cxx @@ -6,6 +6,8 @@ #include <CLucene/analysis/LanguageBasedAnalyzer.h> #endif +#include <rtl/string.hxx> + #include <unistd.h> #include <sys/stat.h> #include <dirent.h> @@ -16,9 +18,10 @@ using namespace lucene::document; -HelpIndexer::HelpIndexer(std::string const &lang, std::string const &module, - std::string const &captionDir, std::string const &contentDir, std::string const &indexDir) : -d_lang(lang), d_module(module), d_captionDir(captionDir), d_contentDir(contentDir), d_indexDir(indexDir), d_error(""), d_files() {} +HelpIndexer::HelpIndexer(rtl::OUString const &lang, rtl::OUString const &module, + rtl::OUString const &captionDir, rtl::OUString const &contentDir, rtl::OUString const &indexDir) : +d_lang(lang), d_module(module), d_captionDir(captionDir), d_contentDir(contentDir), d_indexDir(indexDir), +d_error(), d_files() {} bool HelpIndexer::indexDocuments() { if (!scanForFiles()) { @@ -28,7 +31,7 @@ bool HelpIndexer::indexDocuments() { #ifdef TODO // Construct the analyzer appropriate for the given language lucene::analysis::Analyzer *analyzer = ( - d_lang.compare("ja") == 0 ? + d_lang.compareToAscii("ja") == 0 ? (lucene::analysis::Analyzer*)new lucene::analysis::LanguageBasedAnalyzer(L"cjk") : (lucene::analysis::Analyzer*)new lucene::analysis::standard::StandardAnalyzer()); #else @@ -36,11 +39,13 @@ bool HelpIndexer::indexDocuments() { (lucene::analysis::Analyzer*)new lucene::analysis::standard::StandardAnalyzer()); #endif - lucene::index::IndexWriter writer(d_indexDir.c_str(), analyzer, true); + rtl::OString indexDirStr; + d_indexDir.convertToString(&indexDirStr, RTL_TEXTENCODING_ASCII_US, 0); + lucene::index::IndexWriter writer(indexDirStr.getStr(), analyzer, true); // Index the identified help files Document doc; - for (std::set<std::string>::iterator i = d_files.begin(); i != d_files.end(); ++i) { + for (std::set<rtl::OUString>::iterator i = d_files.begin(); i != d_files.end(); ++i) { doc.clear(); if (!helpDocument(*i, &doc)) { delete analyzer; @@ -56,7 +61,7 @@ bool HelpIndexer::indexDocuments() { return true; } -std::string const & HelpIndexer::getErrorMessage() { +rtl::OUString const & HelpIndexer::getErrorMessage() { return d_error; } @@ -70,18 +75,23 @@ bool HelpIndexer::scanForFiles() { return true; } -bool HelpIndexer::scanForFiles(std::string const & path) { - DIR *dir = opendir(path.c_str()); +bool HelpIndexer::scanForFiles(rtl::OUString const & path) { + rtl::OString pathStr; + path.convertToString(&pathStr, RTL_TEXTENCODING_ASCII_US, 0); + DIR *dir = opendir(pathStr.getStr()); if (dir == 0) { - d_error = "Error reading directory " + path + strerror(errno); + d_error = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Error reading directory ")) + path + + rtl::OUString::createFromAscii(strerror(errno)); return true; } struct dirent *ent; struct stat info; while ((ent = readdir(dir)) != 0) { - if (stat((path + "/" + ent->d_name).c_str(), &info) == 0 && S_ISREG(info.st_mode)) { - d_files.insert(ent->d_name); + rtl::OString entPath(pathStr); + entPath += rtl::OString(RTL_CONSTASCII_STRINGPARAM("/")) + rtl::OString(ent->d_name); + if (stat(entPath.getStr(), &info) == 0 && S_ISREG(info.st_mode)) { + d_files.insert(rtl::OUString::createFromAscii(ent->d_name)); } } @@ -90,34 +100,31 @@ bool HelpIndexer::scanForFiles(std::string const & path) { return true; } -bool HelpIndexer::helpDocument(std::string const & fileName, Document *doc) { +bool HelpIndexer::helpDocument(rtl::OUString const & fileName, Document *doc) { // Add the help path as an indexed, untokenized field. - std::wstring path(L"#HLP#" + string2wstring(d_module) + L"/" + string2wstring(fileName)); - doc->add(*new Field(_T("path"), path.c_str(), Field::STORE_YES | Field::INDEX_UNTOKENIZED)); + rtl::OUString path = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#HLP#")) + d_module + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + fileName; + // FIXME: the (TCHAR*) cast is a problem, because TCHAR does not match sal_Unicode + doc->add(*new Field(_T("path"), (TCHAR*)path.getStr(), Field::STORE_YES | Field::INDEX_UNTOKENIZED)); // Add the caption as a field. - std::string captionPath = d_captionDir + "/" + fileName; + rtl::OUString captionPath = d_captionDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + fileName; doc->add(*new Field(_T("caption"), helpFileReader(captionPath), Field::STORE_NO | Field::INDEX_TOKENIZED)); // FIXME: does the Document take responsibility for the FileReader or should I free it somewhere? // Add the content as a field. - std::string contentPath = d_contentDir + "/" + fileName; + rtl::OUString contentPath = d_contentDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + fileName; doc->add(*new Field(_T("content"), helpFileReader(contentPath), Field::STORE_NO | Field::INDEX_TOKENIZED)); // FIXME: does the Document take responsibility for the FileReader or should I free it somewhere? return true; } -lucene::util::Reader *HelpIndexer::helpFileReader(std::string const & path) { - if (access(path.c_str(), R_OK) == 0) { - return new lucene::util::FileReader(path.c_str(), "UTF-8"); +lucene::util::Reader *HelpIndexer::helpFileReader(rtl::OUString const & path) { + rtl::OString pathStr; + path.convertToString(&pathStr, RTL_TEXTENCODING_ASCII_US, 0); + if (access(pathStr.getStr(), R_OK) == 0) { + return new lucene::util::FileReader(pathStr.getStr(), "UTF-8"); } else { return new lucene::util::StringReader(L""); } } - -std::wstring HelpIndexer::string2wstring(std::string const &source) { - std::wstring target(source.length(), L' '); - std::copy(source.begin(), source.end(), target.begin()); - return target; -} diff --git a/l10ntools/source/help/HelpIndexer.hxx b/l10ntools/source/help/HelpIndexer.hxx index 56122e770e95..833e5e74bba3 100644 --- a/l10ntools/source/help/HelpIndexer.hxx +++ b/l10ntools/source/help/HelpIndexer.hxx @@ -4,20 +4,20 @@ #include <CLucene/StdHeader.h> #include <CLucene.h> -#include <string> +#include <rtl/ustring.hxx> #include <set> // I assume that TCHAR is defined as wchar_t throughout class HelpIndexer { private: - std::string d_lang; - std::string d_module; - std::string d_captionDir; - std::string d_contentDir; - std::string d_indexDir; - std::string d_error; - std::set<std::string> d_files; + rtl::OUString d_lang; + rtl::OUString d_module; + rtl::OUString d_captionDir; + rtl::OUString d_contentDir; + rtl::OUString d_indexDir; + rtl::OUString d_error; + std::set<rtl::OUString> d_files; public: @@ -28,9 +28,9 @@ class HelpIndexer { * @param contentDir The directory to scan for content files. * @param indexDir The directory to write the index to. */ - HelpIndexer(std::string const &lang, std::string const &module, - std::string const &captionDir, std::string const &contentDir, - std::string const &indexDir); + HelpIndexer(rtl::OUString const &lang, rtl::OUString const &module, + rtl::OUString const &captionDir, rtl::OUString const &contentDir, + rtl::OUString const &indexDir); /** * Run the indexer. @@ -41,7 +41,7 @@ class HelpIndexer { /** * Get the error string (empty if no error occurred). */ - std::string const & getErrorMessage(); + rtl::OUString const & getErrorMessage(); private: @@ -53,19 +53,17 @@ class HelpIndexer { /** * Scan for files in the given directory. */ - bool scanForFiles(std::string const &path); + bool scanForFiles(rtl::OUString const &path); /** * Fill the Document with information on the given help file. */ - bool helpDocument(std::string const & fileName, lucene::document::Document *doc); + bool helpDocument(rtl::OUString const & fileName, lucene::document::Document *doc); /** * Create a reader for the given file, and create an "empty" reader in case the file doesn't exist. */ - lucene::util::Reader *helpFileReader(std::string const & path); - - std::wstring string2wstring(std::string const &source); + lucene::util::Reader *helpFileReader(rtl::OUString const & path); }; #endif diff --git a/l10ntools/source/help/HelpIndexer_main.cxx b/l10ntools/source/help/HelpIndexer_main.cxx index a1dd50bac789..3d6963081e0a 100644 --- a/l10ntools/source/help/HelpIndexer_main.cxx +++ b/l10ntools/source/help/HelpIndexer_main.cxx @@ -57,9 +57,14 @@ int main(int argc, char **argv) { std::string captionDir(srcDir + "/caption"); std::string contentDir(srcDir + "/content"); std::string indexDir(outDir + "/" + module + ".idxl"); - HelpIndexer indexer(lang, module, captionDir, contentDir, indexDir); + HelpIndexer indexer( + rtl::OUString::createFromAscii(lang.c_str()), + rtl::OUString::createFromAscii(module.c_str()), + rtl::OUString::createFromAscii(captionDir.c_str()), + rtl::OUString::createFromAscii(contentDir.c_str()), + rtl::OUString::createFromAscii(indexDir.c_str())); if (!indexer.indexDocuments()) { - std::cerr << indexer.getErrorMessage() << std::endl; + std::wcerr << indexer.getErrorMessage().getStr() << std::endl; return 2; } return 0; diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx index 7ee812e94837..ccc74daa5084 100644 --- a/xmlhelp/source/cxxhelp/provider/databases.cxx +++ b/xmlhelp/source/cxxhelp/provider/databases.cxx @@ -39,6 +39,12 @@ #include <algorithm> #include <string.h> +// EDIT FROM HERE + +#include <HelpIndexer.hxx> + +// EDIT ENDS HERE + // Extensible help #include "com/sun/star/deployment/ExtensionManager.hpp" #include "com/sun/star/deployment/thePackageManagerFactory.hpp" @@ -2115,78 +2121,60 @@ rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemp // TEST //bIsWriteAccess = false; - Reference< script::XInvocation > xInvocation; - Reference< XMultiComponentFactory >xSMgr( m_xContext->getServiceManager(), UNO_QUERY ); +// EDIT FROM HERE try { - xInvocation = Reference< script::XInvocation >( - m_xContext->getServiceManager()->createInstanceWithContext( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.help.HelpIndexer" )), m_xContext ) , UNO_QUERY ); - - if( xInvocation.is() ) - { - Sequence<uno::Any> aParamsSeq( bIsWriteAccess ? 6 : 8 ); - - aParamsSeq[0] = uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "-lang" )) ); - - rtl::OUString aLang; - sal_Int32 nLastSlash = aLangURL.lastIndexOf( '/' ); - if( nLastSlash != -1 ) - aLang = aLangURL.copy( nLastSlash + 1 ); - else - aLang = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "en" )); - aParamsSeq[1] = uno::makeAny( aLang ); + rtl::OUString aLang; + sal_Int32 nLastSlash = aLangURL.lastIndexOf( '/' ); + if( nLastSlash != -1 ) + aLang = aLangURL.copy( nLastSlash + 1 ); + else + aLang = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "en" )); - aParamsSeq[2] = uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "-mod" )) ); - aParamsSeq[3] = uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "help" )) ); + rtl::OUString aMod(RTL_CONSTASCII_USTRINGPARAM("help")); - rtl::OUString aZipDir = aLangURL; - if( !bIsWriteAccess ) + rtl::OUString aZipDir = aLangURL; + if( !bIsWriteAccess ) + { + rtl::OUString aTempFileURL; + ::osl::FileBase::RC eErr = ::osl::File::createTempFile( 0, 0, &aTempFileURL ); + if( eErr == ::osl::FileBase::E_None ) { - rtl::OUString aTempFileURL; - ::osl::FileBase::RC eErr = ::osl::File::createTempFile( 0, 0, &aTempFileURL ); - if( eErr == ::osl::FileBase::E_None ) + rtl::OUString aTempDirURL = aTempFileURL; + try { - rtl::OUString aTempDirURL = aTempFileURL; - try - { - m_xSFA->kill( aTempDirURL ); - } - catch (Exception &) - {} - m_xSFA->createFolder( aTempDirURL ); - - aZipDir = aTempDirURL; - o_rbTemporary = true; + m_xSFA->kill( aTempDirURL ); } + catch (Exception &) + {} + m_xSFA->createFolder( aTempDirURL ); + + aZipDir = aTempDirURL; + o_rbTemporary = true; } + } - aParamsSeq[4] = uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "-zipdir" )) ); - rtl::OUString aSystemPath; - osl::FileBase::getSystemPathFromFileURL( aZipDir, aSystemPath ); - aParamsSeq[5] = uno::makeAny( aSystemPath ); + rtl::OUString aTargetDir; + osl::FileBase::getSystemPathFromFileURL( aZipDir, aTargetDir ); - if( !bIsWriteAccess ) - { - aParamsSeq[6] = uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "-srcdir" )) ); - rtl::OUString aSrcDirVal; - osl::FileBase::getSystemPathFromFileURL( aLangURL, aSrcDirVal ); - aParamsSeq[7] = uno::makeAny( aSrcDirVal ); - } + rtl::OUString aSourceDir; + osl::FileBase::getSystemPathFromFileURL( aLangURL, aSourceDir ); - Sequence< sal_Int16 > aOutParamIndex; - Sequence< uno::Any > aOutParam; - uno::Any aRet = xInvocation->invoke( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "createIndex" )), - aParamsSeq, aOutParamIndex, aOutParam ); + rtl::OUString aCaption(RTL_CONSTASCII_USTRINGPARAM("/caption")); + rtl::OUString aContent(RTL_CONSTASCII_USTRINGPARAM("/content")); - if( bIsWriteAccess ) - aIndexFolder = implGetFileFromPackage( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ".idxl" )), xPackage ); - else - aIndexFolder = aZipDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/help.idxl" )); - } + HelpIndexer aIndexer(aLang, aMod, aSourceDir + aCaption, aSourceDir + aContent, aTargetDir); + + if( bIsWriteAccess ) + aIndexFolder = implGetFileFromPackage( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ".idxl" )), xPackage ); + else + aIndexFolder = aZipDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/help.idxl" )); } catch (Exception &) {} + +// EDIT UNTIL HERE + } } diff --git a/xmlhelp/source/cxxhelp/provider/makefile.mk b/xmlhelp/source/cxxhelp/provider/makefile.mk index b70979741fef..05f4eada22cc 100644 --- a/xmlhelp/source/cxxhelp/provider/makefile.mk +++ b/xmlhelp/source/cxxhelp/provider/makefile.mk @@ -67,6 +67,11 @@ LIBXSLTINCDIR=external$/libxslt CFLAGS+= -I$(SOLARINCDIR)$/$(LIBXSLTINCDIR) .ENDIF +CFLAGS+= -I$(SRC_ROOT)$/l10ntools$/source$/help + +PKGCONFIG_MODULES=libclucene-core libclucene-contribs-lib +.INCLUDE : pkg_config.mk + .IF "$(GUI)"=="WNT" .IF "$(COM)"=="MSC" CFLAGS+=-GR |