20#include <com/sun/star/uno/Reference.h>
24#include <com/sun/star/linguistic2/LinguServiceManager.hpp>
25#include <com/sun/star/linguistic2/XLinguProperties.hpp>
26#include <com/sun/star/linguistic2/XSpellChecker1.hpp>
32#include <osl/mutex.hxx>
33#include <osl/thread.h>
37#include <rtl/string.hxx>
38#include <rtl/textenc.h>
40#include <svtools/strings.hrc>
65 uno::Reference< XLinguServiceManager2 > xRes = LinguServiceManager::create( xContext ) ;
70 aEvtListeners (
GetLinguMutex() ), pPropHelper(nullptr), bDisposing(false),
90 pPropHelper =
new PropertyHelper_Thesaurus(
static_cast<XThesaurus *
>(
this), xPropSet );
107 std::vector< SvtLinguConfigDictionaryEntry > aDics;
108 uno::Sequence< OUString > aFormatList;
110 "org.openoffice.lingu.new.Thesaurus", aFormatList );
111 for (
const auto& rFormat : std::as_const(aFormatList))
113 std::vector< SvtLinguConfigDictionaryEntry > aTmpDic(
115 aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() );
121 std::vector< SvtLinguConfigDictionaryEntry > aOldStyleDics(
132 std::set<OUString> aLocaleNamesSet;
133 for (
auto const& dict : aDics)
135 for (
const auto& rLocaleName : dict.aLocaleNames)
140 aLocaleNamesSet.insert( rLocaleName );
144 std::vector<Locale> aLocalesVec;
145 aLocalesVec.reserve(aLocaleNamesSet.size());
147 std::transform(aLocaleNamesSet.begin(), aLocaleNamesSet.end(), std::back_inserter(aLocalesVec),
148 [](
const OUString& localeName) ->
Locale { return LanguageTag::convertToLocale(localeName); });
157 sal_Int32 numthes = std::accumulate(aDics.begin(), aDics.end(), 0,
159 return nSum + dict.aLocaleNames.getLength(); });
165 for (
auto const& dict : aDics)
176 mvThesInfo[k].aEncoding = RTL_TEXTENCODING_DONTKNOW;
183 sal_Int32
nPos = aLocation.lastIndexOf(
'.' );
184 aLocation = aLocation.copy( 0,
nPos );
191 DBG_ASSERT( k == numthes,
"index mismatch?" );
215 const OUString& qTerm,
const Locale& rLocale,
216 const css::uno::Sequence< css::beans::PropertyValue >& rProperties)
220 uno::Sequence< Reference< XMeaning > > aMeanings( 1 );
221 uno::Sequence< Reference< XMeaning > > noMeanings( 0 );
223 uno::Reference< XSpellChecker1 > xSpell;
225 OUString aRTerm(qTerm);
226 OUString aPTerm(qTerm);
237#ifdef LINGU_EXCEPTIONS
238 throw( IllegalArgumentException() );
246 mentry * pmean =
nullptr;
250 rHelper.SetTmpPropVals( rProperties );
252 MyThes * pTH =
nullptr;
253 rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
268 osl::FileBase::getSystemPathFromFileURL(datpath,ndat);
269 osl::FileBase::getSystemPathFromFileURL(idxpath,nidx);
273 OString aTmpidx = Win_AddLongPathPrefix(
OUStringToOString(nidx, RTL_TEXTENCODING_UTF8));
274 OString aTmpdat = Win_AddLongPathPrefix(
OUStringToOString(ndat, RTL_TEXTENCODING_UTF8));
276 OString aTmpidx(
OU2ENC(nidx,osl_getThreadTextEncoding()));
277 OString aTmpdat(
OU2ENC(ndat,osl_getThreadTextEncoding()));
280 mvThesInfo[
i].aThes.reset(
new MyThes(aTmpidx.getStr(),aTmpdat.getStr()) );
296 DBG_ASSERT( eEnc != RTL_TEXTENCODING_DONTKNOW,
"failed to get text encoding! (maybe incorrect encoding string in file)" );
297 if (eEnc == RTL_TEXTENCODING_DONTKNOW)
306 OString aTmp(
OU2ENC(nTerm, eEnc) );
307 nmean = pTH->Lookup(aTmp.getStr(),aTmp.getLength(),&pmean);
310 aMeanings.realloc( nmean );
313 OUString codeTerm = qTerm;
318 xTmpRes2 = xSpell->spell(
"<?xml?><query type='analyze'><word>" +
319 aPTerm +
"</word></query>",
static_cast<sal_uInt16
>(nLanguage), rProperties );
323 if (seq.hasElements())
331 for (
int j = 0; j < nmean; j++)
333 int count = pe->count;
337 OUString *pStr =
aStr.getArray();
341 OUString sTerm(pe->psyns[
i],strlen(pe->psyns[
i]),eEnc );
342 sal_Int32 catpos = sTerm.indexOf(
'(');
347 catst = OUString::Concat(
" ") + sTerm.subView(catpos);
348 sTerm = sTerm.copy(0, catpos);
349 sTerm = sTerm.trim();
355 sTerm +
"</word>" + codeTerm +
"</query>",
static_cast<sal_uInt16
>(nLanguage), rProperties );
359 if (seq.hasElements())
365 if (CapType::MIXED == ct1)
370 case CapType::ALLCAP:
373 case CapType::INITCAP:
380 OUString aAlt( cTerm + catst);
384 OUString dTerm(pe->defn,strlen(pe->defn),eEnc );
385 pMn->SetMeaning(dTerm);
386 pMn->SetSynonyms(
aStr);
392 pTH->CleanUpAfterLookup(&pmean,nmean);
402 if (stem || !xLngSvcMgr.is())
406 xSpell.set( xLngSvcMgr->getSpellChecker(), UNO_QUERY );
407 if (!xSpell.is() || !xSpell->isValid(
SPELLML_SUPPORT,
static_cast<sal_uInt16
>(nLanguage), rProperties ))
410 aRTerm +
"</word></query>",
static_cast<sal_uInt16
>(nLanguage), rProperties );
414 if (seq.hasElements())
422 aRTerm = aRTerm.trim();
423 sal_Int32
pos = aRTerm.lastIndexOf(
' ');
426 xTmpRes = xSpell->spell( OUString::Concat(
"<?xml?><query type='stem'><word>") +
427 aRTerm.subView(
pos + 1) +
"</word></query>",
static_cast<sal_uInt16
>(nLanguage), rProperties );
431 if (seq.hasElements())
433 aPTerm = aRTerm.copy(
pos + 1);
434 aRTerm = aRTerm.subView(0,
pos + 1) + seq[0];
436 for (
int i = 0;
i < seq.getLength();
i++)
439 fprintf(stderr,
"%d: %s\n",
i + 1, o.pData->buffer);
463 sal_Int32 nLen = rArguments.getLength();
466 if (1 == nLen || 2 == nLen)
469 rArguments.getConstArray()[0] >>= xPropSet;
476 pPropHelper =
new PropertyHelper_Thesaurus(
static_cast<XThesaurus *
>(
this), xPropSet );
480 OSL_FAIL(
"wrong number of arguments in sequence" );
499 sal_Int32 tlen = aTerm.getLength();
502 OUString bTemp = aTerm.copy(0,1);
521 EventObject aEvtObj(
static_cast<XThesaurus *
>(
this) );
551 return "org.openoffice.lingu.new.Thesaurus";
564extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
566 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any>
const&)
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
OUString lowercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
std::vector< SvtLinguConfigDictionaryEntry > GetActiveDictionariesByFormat(std::u16string_view rFormatName) const
bool GetSupportedDictionaryFormatsFor(const OUString &rSetName, const OUString &rSetEntry, css::uno::Sequence< OUString > &rFormatList) const
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL dispose() override
Sequence< Reference< css::linguistic2::XMeaning > > prevMeanings
::comphelper::OInterfaceContainerHelper3< XEventListener > aEvtListeners
static OUString makeUpperCase(const OUString &, CharClass const *)
virtual OUString SAL_CALL getServiceDisplayName(const Locale &rLocale) override
virtual void SAL_CALL initialize(const Sequence< Any > &rArguments) override
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL addEventListener(const Reference< XEventListener > &rxListener) override
virtual void SAL_CALL removeEventListener(const Reference< XEventListener > &rxListener) override
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
virtual ~Thesaurus() override
virtual Sequence< Locale > SAL_CALL getLocales() override
static OUString makeLowerCase(const OUString &, CharClass const *)
linguistic::PropertyHelper_Thesaurus & GetPropHelper_Impl()
static OUString makeInitCap(const OUString &, CharClass const *)
Sequence< Locale > aSuppLocales
linguistic::PropertyHelper_Thesaurus * pPropHelper
std::vector< ThesInfo > mvThesInfo
linguistic::PropertyHelper_Thesaurus & GetPropHelper()
virtual sal_Bool SAL_CALL hasLocale(const Locale &rLocale) override
virtual Sequence< Reference< css::linguistic2::XMeaning > > SAL_CALL queryMeanings(const OUString &rTerm, const Locale &rLocale, const css::uno::Sequence< css::beans::PropertyValue > &rProperties) override
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
#define DBG_ASSERT(sCon, aError)
#define LANGUAGE_DONTKNOW
std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics(const char *pDicType)
void MergeNewStyleDicsAndOldStyleDics(std::vector< SvtLinguConfigDictionaryEntry > &rNewStyleDics, const std::vector< SvtLinguConfigDictionaryEntry > &rOldStyleDics)
rtl_TextEncoding getTextEncodingFromCharset(const char *pCharset)
#define OU2ENC(rtlOUString, rtlEncoding)
constexpr OUStringLiteral SN_THESAURUS
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
bool isAllowlistedLanguage(const OUString &lang)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Reference< XComponentContext > getProcessComponentContext()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
bool LinguIsUnspecified(LanguageType nLanguage)
uno::Reference< XLinguProperties > GetLinguProperties()
CapType capitalType(const OUString &aTerm, CharClass const *pCC)
osl::Mutex & GetLinguMutex()
LanguageType LinguLocaleToLanguage(const css::lang::Locale &rLocale)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
static uno::Reference< XLinguServiceManager2 > GetLngSvcMgr_Impl()
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * lingucomponent_Thesaurus_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral SPELLML_SUPPORT
css::uno::Sequence< OUString > aLocaleNames
css::uno::Sequence< OUString > aLocations