2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-08 10:00:18 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-04-07 12:47:28 +00:00
|
|
|
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2009-10-06 12:34:07 +02:00
|
|
|
#include <cppuhelper/factory.hxx>
|
2000-11-17 11:37:46 +00:00
|
|
|
#include <dicimp.hxx>
|
|
|
|
#include <hyphdsp.hxx>
|
2013-04-05 18:40:39 +02:00
|
|
|
#include <i18nlangtag/lang.h>
|
|
|
|
#include <i18nlangtag/languagetag.hxx>
|
2009-10-06 12:34:07 +02:00
|
|
|
#include <osl/mutex.hxx>
|
2000-11-17 11:37:46 +00:00
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#include <tools/stream.hxx>
|
2009-10-06 12:34:07 +02:00
|
|
|
#include <tools/urlobj.hxx>
|
2011-11-14 11:49:31 +01:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2011-11-23 17:24:38 +00:00
|
|
|
#include <comphelper/string.hxx>
|
2009-10-06 12:34:07 +02:00
|
|
|
#include <unotools/ucbstreamhelper.hxx>
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2012-05-29 17:17:28 +02:00
|
|
|
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
|
2000-11-17 11:37:46 +00:00
|
|
|
#include <com/sun/star/linguistic2/DictionaryType.hpp>
|
|
|
|
#include <com/sun/star/linguistic2/DictionaryEventFlags.hpp>
|
|
|
|
#include <com/sun/star/registry/XRegistryKey.hpp>
|
2009-10-06 12:34:07 +02:00
|
|
|
#include <com/sun/star/io/XInputStream.hpp>
|
|
|
|
#include <com/sun/star/io/XOutputStream.hpp>
|
|
|
|
|
|
|
|
#include "defs.hxx"
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
using namespace utl;
|
|
|
|
using namespace osl;
|
|
|
|
using namespace com::sun::star;
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::linguistic2;
|
|
|
|
using namespace linguistic;
|
|
|
|
|
2011-02-26 15:54:59 +01:00
|
|
|
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2006-05-05 07:10:07 +00:00
|
|
|
#define BUFSIZE 4096
|
2000-11-17 11:37:46 +00:00
|
|
|
#define VERS2_NOLANGUAGE 1024
|
|
|
|
|
2006-05-05 07:10:07 +00:00
|
|
|
#define MAX_HEADER_LENGTH 16
|
|
|
|
|
2001-03-19 13:52:48 +00:00
|
|
|
static const sal_Char* pVerStr2 = "WBSWG2";
|
|
|
|
static const sal_Char* pVerStr5 = "WBSWG5";
|
|
|
|
static const sal_Char* pVerStr6 = "WBSWG6";
|
2006-05-05 07:10:07 +00:00
|
|
|
static const sal_Char* pVerOOo7 = "OOoUserDict1";
|
2001-03-19 13:52:48 +00:00
|
|
|
|
2010-11-10 13:50:33 +08:00
|
|
|
static const sal_Int16 DIC_VERSION_DONTKNOW = -1;
|
|
|
|
static const sal_Int16 DIC_VERSION_2 = 2;
|
|
|
|
static const sal_Int16 DIC_VERSION_5 = 5;
|
|
|
|
static const sal_Int16 DIC_VERSION_6 = 6;
|
|
|
|
static const sal_Int16 DIC_VERSION_7 = 7;
|
2010-04-23 08:19:46 +02:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
static bool getTag(const OString &rLine, const sal_Char *pTagName,
|
|
|
|
OString &rTagValue)
|
2001-03-19 13:52:48 +00:00
|
|
|
{
|
2012-01-22 14:34:51 +00:00
|
|
|
sal_Int32 nPos = rLine.indexOf(pTagName);
|
|
|
|
if (nPos == -1)
|
|
|
|
return false;
|
2006-05-05 07:10:07 +00:00
|
|
|
|
2012-01-22 14:34:51 +00:00
|
|
|
rTagValue = comphelper::string::strip(rLine.copy(nPos + rtl_str_getLength(pTagName)),
|
|
|
|
' ');
|
|
|
|
return true;
|
2006-05-05 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
sal_Int16 ReadDicVersion( SvStreamPtr &rpStream, sal_uInt16 &nLng, bool &bNeg )
|
2006-05-05 07:10:07 +00:00
|
|
|
{
|
|
|
|
// Sniff the header
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int16 nDicVersion = DIC_VERSION_DONTKNOW;
|
2006-05-05 07:10:07 +00:00
|
|
|
sal_Char pMagicHeader[MAX_HEADER_LENGTH];
|
|
|
|
|
|
|
|
nLng = LANGUAGE_NONE;
|
2014-04-15 08:48:53 +02:00
|
|
|
bNeg = false;
|
2006-05-05 07:10:07 +00:00
|
|
|
|
2009-10-06 12:34:07 +02:00
|
|
|
if (!rpStream.get() || rpStream->GetError())
|
2006-05-05 07:10:07 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-10-06 12:34:07 +02:00
|
|
|
sal_Size nSniffPos = rpStream->Tell();
|
2007-05-25 11:21:48 +00:00
|
|
|
static sal_Size nVerOOo7Len = sal::static_int_cast< sal_Size >(strlen( pVerOOo7 ));
|
2006-05-05 07:10:07 +00:00
|
|
|
pMagicHeader[ nVerOOo7Len ] = '\0';
|
2009-10-06 12:34:07 +02:00
|
|
|
if ((rpStream->Read((void *) pMagicHeader, nVerOOo7Len) == nVerOOo7Len) &&
|
2006-05-05 07:10:07 +00:00
|
|
|
!strcmp(pMagicHeader, pVerOOo7))
|
|
|
|
{
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bSuccess;
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aLine;
|
2006-05-05 07:10:07 +00:00
|
|
|
|
2010-04-23 08:19:46 +02:00
|
|
|
nDicVersion = DIC_VERSION_7;
|
2006-05-05 07:10:07 +00:00
|
|
|
|
|
|
|
// 1st skip magic / header line
|
2009-10-06 12:34:07 +02:00
|
|
|
rpStream->ReadLine(aLine);
|
2006-05-05 07:10:07 +00:00
|
|
|
|
|
|
|
// 2nd line: language all | en-US | pt-BR ...
|
2014-04-15 08:48:53 +02:00
|
|
|
while ((bSuccess = rpStream->ReadLine(aLine)))
|
2006-05-05 07:10:07 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aTagValue;
|
2006-05-05 07:10:07 +00:00
|
|
|
|
2012-01-22 14:34:51 +00:00
|
|
|
if (aLine[0] == '#') // skip comments
|
2006-05-05 07:10:07 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// lang: field
|
|
|
|
if (getTag(aLine, "lang: ", aTagValue))
|
|
|
|
{
|
2013-11-21 11:34:01 +02:00
|
|
|
if (aTagValue == "<none>")
|
2006-05-05 07:10:07 +00:00
|
|
|
nLng = LANGUAGE_NONE;
|
|
|
|
else
|
2013-09-03 18:56:42 +02:00
|
|
|
nLng = LanguageTag::convertToLanguageTypeWithFallback(
|
|
|
|
OStringToOUString( aTagValue, RTL_TEXTENCODING_ASCII_US));
|
2006-05-05 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// type: negative / positive
|
|
|
|
if (getTag(aLine, "type: ", aTagValue))
|
|
|
|
{
|
2013-11-21 11:34:01 +02:00
|
|
|
if (aTagValue == "negative")
|
2014-04-15 08:48:53 +02:00
|
|
|
bNeg = true;
|
2006-05-05 07:10:07 +00:00
|
|
|
else
|
2014-04-15 08:48:53 +02:00
|
|
|
bNeg = false;
|
2006-05-05 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 15:52:45 +02:00
|
|
|
if (aLine.indexOf("---") != -1) // end of header
|
2006-05-05 07:10:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!bSuccess)
|
2007-05-25 11:21:48 +00:00
|
|
|
return -2;
|
2006-05-05 07:10:07 +00:00
|
|
|
}
|
|
|
|
else
|
2001-03-19 13:52:48 +00:00
|
|
|
{
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_uInt16 nLen;
|
2006-05-05 07:10:07 +00:00
|
|
|
|
2009-10-06 12:34:07 +02:00
|
|
|
rpStream->Seek (nSniffPos );
|
2006-05-05 07:10:07 +00:00
|
|
|
|
2014-02-05 10:41:04 +02:00
|
|
|
rpStream->ReadUInt16( nLen );
|
2006-05-05 07:10:07 +00:00
|
|
|
if (nLen >= MAX_HEADER_LENGTH)
|
|
|
|
return -1;
|
|
|
|
|
2009-10-06 12:34:07 +02:00
|
|
|
rpStream->Read(pMagicHeader, nLen);
|
2006-05-05 07:10:07 +00:00
|
|
|
pMagicHeader[nLen] = '\0';
|
|
|
|
|
|
|
|
// Check version magic
|
|
|
|
if (0 == strcmp( pMagicHeader, pVerStr6 ))
|
2010-04-23 08:19:46 +02:00
|
|
|
nDicVersion = DIC_VERSION_6;
|
2006-05-05 07:10:07 +00:00
|
|
|
else if (0 == strcmp( pMagicHeader, pVerStr5 ))
|
2010-04-23 08:19:46 +02:00
|
|
|
nDicVersion = DIC_VERSION_5;
|
2006-05-05 07:10:07 +00:00
|
|
|
else if (0 == strcmp( pMagicHeader, pVerStr2 ))
|
2010-04-23 08:19:46 +02:00
|
|
|
nDicVersion = DIC_VERSION_2;
|
2006-05-05 07:10:07 +00:00
|
|
|
else
|
2010-04-23 08:19:46 +02:00
|
|
|
nDicVersion = DIC_VERSION_DONTKNOW;
|
2006-05-05 07:10:07 +00:00
|
|
|
|
2010-04-23 08:19:46 +02:00
|
|
|
if (DIC_VERSION_2 == nDicVersion ||
|
|
|
|
DIC_VERSION_5 == nDicVersion ||
|
|
|
|
DIC_VERSION_6 == nDicVersion)
|
2006-05-05 07:10:07 +00:00
|
|
|
{
|
|
|
|
// The language of the dictionary
|
2014-02-05 10:41:04 +02:00
|
|
|
rpStream->ReadUInt16( nLng );
|
2006-05-05 07:10:07 +00:00
|
|
|
|
|
|
|
if (VERS2_NOLANGUAGE == nLng)
|
|
|
|
nLng = LANGUAGE_NONE;
|
|
|
|
|
|
|
|
// Negative Flag
|
2014-04-15 08:48:53 +02:00
|
|
|
rpStream->ReadCharAsBool( bNeg );
|
2006-05-05 07:10:07 +00:00
|
|
|
}
|
2001-03-19 13:52:48 +00:00
|
|
|
}
|
2006-05-05 07:10:07 +00:00
|
|
|
|
|
|
|
return nDicVersion;
|
2001-03-19 13:52:48 +00:00
|
|
|
}
|
|
|
|
|
2000-11-17 11:37:46 +00:00
|
|
|
DictionaryNeo::DictionaryNeo(const OUString &rName,
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int16 nLang, DictionaryType eType,
|
2008-03-25 15:25:07 +00:00
|
|
|
const OUString &rMainURL,
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bWriteable) :
|
2000-11-17 11:37:46 +00:00
|
|
|
aDicEvtListeners( GetLinguMutex() ),
|
|
|
|
aDicName (rName),
|
2007-05-25 11:21:48 +00:00
|
|
|
aMainURL (rMainURL),
|
2000-11-17 11:37:46 +00:00
|
|
|
eDicType (eType),
|
2007-05-25 11:21:48 +00:00
|
|
|
nLanguage (nLang)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
nCount = 0;
|
2010-04-23 08:19:46 +02:00
|
|
|
nDicVersion = DIC_VERSION_DONTKNOW;
|
2014-04-15 08:48:53 +02:00
|
|
|
bNeedEntries = true;
|
|
|
|
bIsModified = bIsActive = false;
|
2008-03-25 15:25:07 +00:00
|
|
|
bIsReadonly = !bWriteable;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2011-12-27 11:08:04 -02:00
|
|
|
if( !rMainURL.isEmpty())
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bExists = FileExists( rMainURL );
|
2001-04-05 16:33:02 +00:00
|
|
|
if( !bExists )
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2010-04-23 08:45:27 +02:00
|
|
|
// save new dictionaries with in Format 7 (UTF8 plain text)
|
2010-04-23 08:48:44 +02:00
|
|
|
nDicVersion = DIC_VERSION_7;
|
2001-03-19 13:52:48 +00:00
|
|
|
|
2000-11-17 11:37:46 +00:00
|
|
|
//! create physical representation of an **empty** dictionary
|
2004-04-27 15:07:06 +00:00
|
|
|
//! that could be found by the dictionary-list implementation
|
2000-11-17 11:37:46 +00:00
|
|
|
// (Note: empty dictionaries are not just empty files!)
|
2008-03-25 15:25:07 +00:00
|
|
|
DBG_ASSERT( !bIsReadonly,
|
|
|
|
"DictionaryNeo: dictionaries should be writeable if they are to be saved" );
|
|
|
|
if (!bIsReadonly)
|
|
|
|
saveEntries( rMainURL );
|
2014-04-15 08:48:53 +02:00
|
|
|
bNeedEntries = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-07 12:08:36 +00:00
|
|
|
// non persistent dictionaries (like IgnoreAllList) should always be writable
|
2014-04-15 08:48:53 +02:00
|
|
|
bIsReadonly = false;
|
|
|
|
bNeedEntries = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DictionaryNeo::~DictionaryNeo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-13 11:06:43 +01:00
|
|
|
sal_uLong DictionaryNeo::loadEntries(const OUString &rMainURL)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2010-11-10 13:50:33 +08:00
|
|
|
// counter check that it is safe to set bIsModified to sal_False at
|
2000-11-17 11:37:46 +00:00
|
|
|
// the end of the function
|
|
|
|
DBG_ASSERT(!bIsModified, "lng : dictionary already modified!");
|
|
|
|
|
|
|
|
// function should only be called once in order to load entries from file
|
2014-04-15 08:48:53 +02:00
|
|
|
bNeedEntries = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2011-12-27 11:08:04 -02:00
|
|
|
if (rMainURL.isEmpty())
|
2000-11-17 11:37:46 +00:00
|
|
|
return 0;
|
|
|
|
|
2012-05-29 17:17:28 +02:00
|
|
|
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2009-10-06 12:34:07 +02:00
|
|
|
// get XInputStream stream
|
|
|
|
uno::Reference< io::XInputStream > xStream;
|
|
|
|
try
|
|
|
|
{
|
2012-11-02 17:46:30 +02:00
|
|
|
uno::Reference< ucb::XSimpleFileAccess3 > xAccess( ucb::SimpleFileAccess::create(xContext) );
|
2009-10-06 12:34:07 +02:00
|
|
|
xStream = xAccess->openFileRead( rMainURL );
|
|
|
|
}
|
2011-12-20 12:06:48 +09:00
|
|
|
catch (const uno::Exception &)
|
2009-10-06 12:34:07 +02:00
|
|
|
{
|
2014-01-28 20:01:25 +01:00
|
|
|
DBG_ASSERT( false, "failed to get input stream" );
|
2009-10-06 12:34:07 +02:00
|
|
|
}
|
|
|
|
if (!xStream.is())
|
2011-01-13 11:06:43 +01:00
|
|
|
return static_cast< sal_uLong >(-1);
|
2009-10-06 12:34:07 +02:00
|
|
|
|
|
|
|
SvStreamPtr pStream = SvStreamPtr( utl::UcbStreamHelper::CreateStream( xStream ) );
|
|
|
|
|
2011-01-13 11:06:43 +01:00
|
|
|
sal_uLong nErr = sal::static_int_cast< sal_uLong >(-1);
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2011-02-08 20:59:20 +01:00
|
|
|
// read header
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bNegativ;
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_uInt16 nLang;
|
2006-05-05 07:10:07 +00:00
|
|
|
nDicVersion = ReadDicVersion(pStream, nLang, bNegativ);
|
2007-05-25 11:21:48 +00:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
2000-11-17 11:37:46 +00:00
|
|
|
return nErr;
|
2009-10-06 12:34:07 +02:00
|
|
|
|
2006-05-05 07:10:07 +00:00
|
|
|
nLanguage = nLang;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2006-05-05 07:10:07 +00:00
|
|
|
eDicType = bNegativ ? DictionaryType_NEGATIVE : DictionaryType_POSITIVE;
|
2001-03-19 13:52:48 +00:00
|
|
|
|
2001-07-25 09:09:50 +00:00
|
|
|
rtl_TextEncoding eEnc = osl_getThreadTextEncoding();
|
2010-04-23 08:19:46 +02:00
|
|
|
if (nDicVersion >= DIC_VERSION_6)
|
2001-03-19 13:52:48 +00:00
|
|
|
eEnc = RTL_TEXTENCODING_UTF8;
|
2006-05-05 07:10:07 +00:00
|
|
|
nCount = 0;
|
2001-03-19 13:52:48 +00:00
|
|
|
|
2010-04-23 08:19:46 +02:00
|
|
|
if (DIC_VERSION_6 == nDicVersion ||
|
|
|
|
DIC_VERSION_5 == nDicVersion ||
|
|
|
|
DIC_VERSION_2 == nDicVersion)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_uInt16 nLen = 0;
|
2006-05-05 07:10:07 +00:00
|
|
|
sal_Char aWordBuf[ BUFSIZE ];
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2011-02-08 20:59:20 +01:00
|
|
|
// Read the first word
|
2000-11-17 11:37:46 +00:00
|
|
|
if (!pStream->IsEof())
|
|
|
|
{
|
2014-02-05 10:41:04 +02:00
|
|
|
pStream->ReadUInt16( nLen );
|
2007-05-25 11:21:48 +00:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
2000-11-17 11:37:46 +00:00
|
|
|
return nErr;
|
|
|
|
if ( nLen < BUFSIZE )
|
|
|
|
{
|
|
|
|
pStream->Read(aWordBuf, nLen);
|
2007-05-25 11:21:48 +00:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
2000-11-17 11:37:46 +00:00
|
|
|
return nErr;
|
|
|
|
*(aWordBuf + nLen) = 0;
|
|
|
|
}
|
2013-02-15 20:55:50 +00:00
|
|
|
else
|
|
|
|
return SVSTREAM_READ_ERROR;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
2006-05-05 07:10:07 +00:00
|
|
|
while(!pStream->IsEof())
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2011-02-08 20:59:20 +01:00
|
|
|
// Read from file
|
|
|
|
// Paste in dictionary without converting
|
2006-05-05 07:10:07 +00:00
|
|
|
if(*aWordBuf)
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aText(aWordBuf, rtl_str_getLength(aWordBuf), eEnc);
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Reference< XDictionaryEntry > xEntry =
|
2006-05-05 07:10:07 +00:00
|
|
|
new DicEntry( aText, bNegativ );
|
2014-04-15 08:48:53 +02:00
|
|
|
addEntry_Impl( xEntry, true ); //! don't launch events here
|
2006-05-05 07:10:07 +00:00
|
|
|
}
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2014-02-05 10:41:04 +02:00
|
|
|
pStream->ReadUInt16( nLen );
|
2011-02-08 20:59:20 +01:00
|
|
|
if (pStream->IsEof())
|
2006-05-05 07:10:07 +00:00
|
|
|
break;
|
2007-05-25 11:21:48 +00:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
2006-05-05 07:10:07 +00:00
|
|
|
return nErr;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2006-05-05 07:10:07 +00:00
|
|
|
if (nLen < BUFSIZE)
|
|
|
|
{
|
|
|
|
pStream->Read(aWordBuf, nLen);
|
2007-05-25 11:21:48 +00:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
2006-05-05 07:10:07 +00:00
|
|
|
return nErr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return SVSTREAM_READ_ERROR;
|
|
|
|
*(aWordBuf + nLen) = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-04-23 08:19:46 +02:00
|
|
|
else if (DIC_VERSION_7 == nDicVersion)
|
2006-05-05 07:10:07 +00:00
|
|
|
{
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bSuccess;
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aLine;
|
2006-05-05 07:10:07 +00:00
|
|
|
|
|
|
|
// remaining lines - stock strings (a [==] b)
|
2014-04-15 08:48:53 +02:00
|
|
|
while (true == (bSuccess = pStream->ReadLine(aLine)))
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2012-01-22 14:34:51 +00:00
|
|
|
if (aLine[0] == '#') // skip comments
|
2006-05-05 07:10:07 +00:00
|
|
|
continue;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aText = OStringToOUString(aLine, RTL_TEXTENCODING_UTF8);
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Reference< XDictionaryEntry > xEntry =
|
2006-05-05 07:10:07 +00:00
|
|
|
new DicEntry( aText, eDicType == DictionaryType_NEGATIVE );
|
2014-04-15 08:48:53 +02:00
|
|
|
addEntry_Impl( xEntry, true ); //! don't launch events here
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:22:29 +00:00
|
|
|
SAL_WARN_IF(!isSorted(), "linguistic", "dictionary is not sorted");
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
// since this routine should be called only initialy (prior to any
|
|
|
|
// modification to be saved) we reset the bIsModified flag here that
|
|
|
|
// was implicitly set by addEntry_Impl
|
2014-04-15 08:48:53 +02:00
|
|
|
bIsModified = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
return pStream->GetError();
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
static OString formatForSave(const uno::Reference< XDictionaryEntry > &xEntry,
|
2011-11-27 20:37:42 +00:00
|
|
|
rtl_TextEncoding eEnc )
|
2006-05-05 07:10:07 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OStringBuffer aStr(OUStringToOString(xEntry->getDictionaryWord(), eEnc));
|
2006-05-05 07:10:07 +00:00
|
|
|
|
|
|
|
if (xEntry->isNegative())
|
|
|
|
{
|
2013-11-20 10:05:20 +02:00
|
|
|
aStr.append("==");
|
2013-04-07 12:06:47 +02:00
|
|
|
aStr.append(OUStringToOString(xEntry->getReplacementText(), eEnc));
|
2006-05-05 07:10:07 +00:00
|
|
|
}
|
2011-11-27 20:37:42 +00:00
|
|
|
return aStr.makeStringAndClear();
|
2006-05-05 07:10:07 +00:00
|
|
|
}
|
|
|
|
|
2013-02-20 16:19:30 +00:00
|
|
|
struct TmpDictionary
|
|
|
|
{
|
|
|
|
OUString maURL, maTmpURL;
|
|
|
|
uno::Reference< ucb::XSimpleFileAccess3 > mxAccess;
|
|
|
|
|
|
|
|
void cleanTmpFile()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-07-05 00:07:43 +02:00
|
|
|
if (mxAccess.is())
|
|
|
|
{
|
|
|
|
mxAccess->kill(maTmpURL);
|
|
|
|
}
|
2013-02-20 16:19:30 +00:00
|
|
|
}
|
|
|
|
catch (const uno::Exception &) { }
|
|
|
|
}
|
|
|
|
TmpDictionary(const OUString &rURL)
|
|
|
|
: maURL( rURL )
|
|
|
|
{
|
|
|
|
maTmpURL = maURL + ".tmp";
|
|
|
|
}
|
|
|
|
~TmpDictionary()
|
|
|
|
{
|
|
|
|
cleanTmpFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< io::XStream > openTmpFile()
|
|
|
|
{
|
|
|
|
uno::Reference< io::XStream > xStream;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
mxAccess = ucb::SimpleFileAccess::create(
|
|
|
|
comphelper::getProcessComponentContext());
|
|
|
|
xStream = mxAccess->openFileReadWrite(maTmpURL);
|
|
|
|
} catch (const uno::Exception &) { }
|
|
|
|
|
|
|
|
return xStream;
|
|
|
|
}
|
|
|
|
|
2013-02-21 11:47:14 +01:00
|
|
|
sal_uLong renameTmpToURL()
|
2013-02-20 16:19:30 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
mxAccess->move(maTmpURL, maURL);
|
|
|
|
}
|
|
|
|
catch (const uno::Exception &)
|
|
|
|
{
|
2014-01-28 20:01:25 +01:00
|
|
|
DBG_ASSERT( false, "failed to overwrite dict" );
|
2013-02-20 16:19:30 +00:00
|
|
|
return static_cast< sal_uLong >(-1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
2006-05-05 07:10:07 +00:00
|
|
|
|
2011-01-13 11:06:43 +01:00
|
|
|
sal_uLong DictionaryNeo::saveEntries(const OUString &rURL)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2013-02-20 16:19:30 +00:00
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2011-12-27 11:08:04 -02:00
|
|
|
if (rURL.isEmpty())
|
2000-11-17 11:37:46 +00:00
|
|
|
return 0;
|
2009-10-06 12:34:07 +02:00
|
|
|
DBG_ASSERT(!INetURLObject( rURL ).HasError(), "lng : invalid URL");
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2013-02-20 16:19:30 +00:00
|
|
|
// lifecycle manage the .tmp file
|
|
|
|
TmpDictionary aTmpDictionary(rURL);
|
|
|
|
uno::Reference< io::XStream > xStream = aTmpDictionary.openTmpFile();
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2009-10-06 12:34:07 +02:00
|
|
|
if (!xStream.is())
|
2011-01-13 11:06:43 +01:00
|
|
|
return static_cast< sal_uLong >(-1);
|
2009-10-06 12:34:07 +02:00
|
|
|
|
2011-01-13 11:06:43 +01:00
|
|
|
sal_uLong nErr = sal::static_int_cast< sal_uLong >(-1);
|
2013-02-20 16:19:30 +00:00
|
|
|
SvStreamPtr pStream = SvStreamPtr( utl::UcbStreamHelper::CreateStream( xStream ) );
|
2009-10-06 12:34:07 +02:00
|
|
|
|
2014-02-25 19:17:44 +01:00
|
|
|
|
2010-07-07 08:44:22 +02:00
|
|
|
// Always write as the latest version, i.e. DIC_VERSION_7
|
2014-02-25 19:17:44 +01:00
|
|
|
|
2010-07-07 08:44:22 +02:00
|
|
|
rtl_TextEncoding eEnc = RTL_TEXTENCODING_UTF8;
|
2013-04-07 12:06:47 +02:00
|
|
|
pStream->WriteLine(OString(pVerOOo7));
|
2010-07-07 08:44:22 +02:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
|
|
|
return nErr;
|
2013-01-09 16:48:52 +01:00
|
|
|
/* XXX: the <none> case could be differentiated, is it absence or
|
|
|
|
* undetermined or multiple? Earlier versions did not know about 'und' and
|
|
|
|
* 'mul' and 'zxx' codes. Sync with ReadDicVersion() */
|
|
|
|
if (LinguIsUnspecified(nLanguage))
|
2013-11-20 10:05:20 +02:00
|
|
|
pStream->WriteLine(OString("lang: <none>"));
|
2010-07-07 08:44:22 +02:00
|
|
|
else
|
2006-05-05 07:10:07 +00:00
|
|
|
{
|
2013-11-20 10:05:20 +02:00
|
|
|
OStringBuffer aLine("lang: ");
|
2013-07-13 02:54:05 +02:00
|
|
|
aLine.append(OUStringToOString(LanguageTag::convertToBcp47(nLanguage), eEnc));
|
2011-11-27 20:37:42 +00:00
|
|
|
pStream->WriteLine(aLine.makeStringAndClear());
|
2006-05-05 07:10:07 +00:00
|
|
|
}
|
2010-07-07 08:44:22 +02:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
|
|
|
return nErr;
|
|
|
|
if (eDicType == DictionaryType_POSITIVE)
|
2013-11-20 10:05:20 +02:00
|
|
|
pStream->WriteLine(OString("type: positive"));
|
2006-05-05 07:10:07 +00:00
|
|
|
else
|
2013-11-20 10:05:20 +02:00
|
|
|
pStream->WriteLine(OString("type: negative"));
|
2010-07-07 08:44:22 +02:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
|
|
|
return nErr;
|
2013-11-20 10:05:20 +02:00
|
|
|
pStream->WriteLine(OString("---"));
|
2010-07-07 08:44:22 +02:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
|
|
|
return nErr;
|
|
|
|
const uno::Reference< XDictionaryEntry > *pEntry = aEntries.getConstArray();
|
2010-11-10 13:50:33 +08:00
|
|
|
for (sal_Int32 i = 0; i < nCount; i++)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aOutStr = formatForSave(pEntry[i], eEnc);
|
2010-07-07 08:44:22 +02:00
|
|
|
pStream->WriteLine (aOutStr);
|
2007-05-25 11:21:48 +00:00
|
|
|
if (0 != (nErr = pStream->GetError()))
|
2013-02-20 16:19:30 +00:00
|
|
|
break;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 00:07:43 +02:00
|
|
|
pStream.reset(); // fdo#66420 close streams so Win32 can move the file
|
|
|
|
xStream.clear();
|
2013-02-20 16:19:30 +00:00
|
|
|
nErr = aTmpDictionary.renameTmpToURL();
|
|
|
|
|
2010-07-07 08:44:22 +02:00
|
|
|
//If we are migrating from an older version, then on first successful
|
|
|
|
//write, we're now converted to the latest version, i.e. DIC_VERSION_7
|
|
|
|
nDicVersion = DIC_VERSION_7;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2010-07-07 08:44:22 +02:00
|
|
|
return nErr;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 13:50:33 +08:00
|
|
|
void DictionaryNeo::launchEvent(sal_Int16 nEvent,
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Reference< XDictionaryEntry > xEntry)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
DictionaryEvent aEvt;
|
2007-06-07 13:21:55 +00:00
|
|
|
aEvt.Source = uno::Reference< XDictionary >( this );
|
2000-11-17 11:37:46 +00:00
|
|
|
aEvt.nEvent = nEvent;
|
|
|
|
aEvt.xDictionaryEntry = xEntry;
|
|
|
|
|
|
|
|
cppu::OInterfaceIteratorHelper aIt( aDicEvtListeners );
|
|
|
|
while (aIt.hasMoreElements())
|
|
|
|
{
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Reference< XDictionaryEventListener > xRef( aIt.next(), UNO_QUERY );
|
2000-11-17 11:37:46 +00:00
|
|
|
if (xRef.is())
|
|
|
|
xRef->processDictionaryEvent( aEvt );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DictionaryNeo::cmpDicEntry(const OUString& rWord1,
|
|
|
|
const OUString &rWord2,
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bSimilarOnly)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
// returns 0 if rWord1 is equal to rWord2
|
|
|
|
// " a value < 0 if rWord1 is less than rWord2
|
|
|
|
// " a value > 0 if rWord1 is greater than rWord2
|
|
|
|
|
|
|
|
int nRes = 0;
|
|
|
|
|
|
|
|
OUString aWord1( rWord1 ),
|
|
|
|
aWord2( rWord2 );
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 nLen1 = aWord1.getLength(),
|
2000-11-17 11:37:46 +00:00
|
|
|
nLen2 = aWord2.getLength();
|
|
|
|
if (bSimilarOnly)
|
|
|
|
{
|
|
|
|
const sal_Unicode cChar = '.';
|
|
|
|
if (nLen1 && cChar == aWord1[ nLen1 - 1 ])
|
|
|
|
nLen1--;
|
|
|
|
if (nLen2 && cChar == aWord2[ nLen2 - 1 ])
|
|
|
|
nLen2--;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sal_Unicode cIgnChar = '=';
|
2014-01-30 14:56:30 +01:00
|
|
|
const sal_Unicode cIgnBeg = '['; // for alternative hyphenation, eg. Schif[f]fahrt, Zuc[1k]ker
|
|
|
|
const sal_Unicode cIgnEnd = ']'; // planned: gee"[1-/e]rfde or ge[-/1e]e"rfde (gee"rfde -> ge=erfde)
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 nIdx1 = 0,
|
2000-11-17 11:37:46 +00:00
|
|
|
nIdx2 = 0,
|
|
|
|
nNumIgnChar1 = 0,
|
|
|
|
nNumIgnChar2 = 0;
|
|
|
|
|
2014-01-30 14:56:30 +01:00
|
|
|
bool IgnState;
|
2000-11-17 11:37:46 +00:00
|
|
|
sal_Int32 nDiff = 0;
|
2007-05-25 11:21:48 +00:00
|
|
|
sal_Unicode cChar1 = '\0';
|
|
|
|
sal_Unicode cChar2 = '\0';
|
2000-11-17 11:37:46 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
// skip chars to be ignored
|
2014-01-30 14:56:30 +01:00
|
|
|
IgnState = false;
|
|
|
|
while (nIdx1 < nLen1 && ((cChar1 = aWord1[ nIdx1 ]) == cIgnChar || cChar1 == cIgnBeg || IgnState ))
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2014-01-30 14:56:30 +01:00
|
|
|
if ( cChar1 == cIgnBeg )
|
|
|
|
IgnState = true;
|
|
|
|
else if (cChar1 == cIgnEnd)
|
|
|
|
IgnState = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
nIdx1++;
|
|
|
|
nNumIgnChar1++;
|
|
|
|
}
|
2014-01-30 14:56:30 +01:00
|
|
|
IgnState = false;
|
|
|
|
while (nIdx2 < nLen2 && ((cChar2 = aWord2[ nIdx2 ]) == cIgnChar || cChar2 == cIgnBeg || IgnState ))
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2014-01-30 14:56:30 +01:00
|
|
|
if ( cChar2 == cIgnBeg )
|
|
|
|
IgnState = true;
|
|
|
|
else if (cChar2 == cIgnEnd)
|
|
|
|
IgnState = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
nIdx2++;
|
|
|
|
nNumIgnChar2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nIdx1 < nLen1 && nIdx2 < nLen2)
|
|
|
|
{
|
|
|
|
nDiff = cChar1 - cChar2;
|
|
|
|
if (nDiff)
|
|
|
|
break;
|
|
|
|
nIdx1++;
|
|
|
|
nIdx2++;
|
|
|
|
}
|
|
|
|
} while (nIdx1 < nLen1 && nIdx2 < nLen2);
|
|
|
|
|
|
|
|
|
|
|
|
if (nDiff)
|
|
|
|
nRes = nDiff;
|
|
|
|
else
|
|
|
|
{ // the string with the smallest count of not ignored chars is the
|
|
|
|
// shorter one
|
|
|
|
|
|
|
|
// count remaining IgnChars
|
2014-01-30 14:56:30 +01:00
|
|
|
IgnState = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
while (nIdx1 < nLen1 )
|
|
|
|
{
|
2014-01-30 14:56:30 +01:00
|
|
|
if (aWord1[ nIdx1 ] == cIgnBeg)
|
|
|
|
IgnState = true;
|
2014-01-30 15:19:56 +01:00
|
|
|
if (IgnState || aWord1[ nIdx1 ] == cIgnChar)
|
2000-11-17 11:37:46 +00:00
|
|
|
nNumIgnChar1++;
|
2014-01-30 14:56:30 +01:00
|
|
|
if (aWord1[ nIdx1] == cIgnEnd)
|
|
|
|
IgnState = false;
|
2014-01-30 15:19:56 +01:00
|
|
|
nIdx1++;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
2014-01-30 14:56:30 +01:00
|
|
|
IgnState = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
while (nIdx2 < nLen2 )
|
|
|
|
{
|
2014-01-30 15:19:56 +01:00
|
|
|
if (aWord2[ nIdx2 ] == cIgnBeg)
|
2014-01-30 14:56:30 +01:00
|
|
|
IgnState = true;
|
2014-01-30 15:19:56 +01:00
|
|
|
if (IgnState || aWord2[ nIdx2 ] == cIgnChar)
|
2000-11-17 11:37:46 +00:00
|
|
|
nNumIgnChar2++;
|
2014-01-30 15:19:56 +01:00
|
|
|
if (aWord2[ nIdx2 ] == cIgnEnd)
|
2014-01-30 14:56:30 +01:00
|
|
|
IgnState = false;
|
2014-01-30 15:19:56 +01:00
|
|
|
nIdx2++;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 13:50:33 +08:00
|
|
|
nRes = ((sal_Int32) nLen1 - nNumIgnChar1) - ((sal_Int32) nLen2 - nNumIgnChar2);
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nRes;
|
|
|
|
}
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
bool DictionaryNeo::seekEntry(const OUString &rWord,
|
|
|
|
sal_Int32 *pPos, bool bSimilarOnly)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
// look for entry with binary search.
|
2010-11-10 13:50:33 +08:00
|
|
|
// return sal_True if found sal_False else.
|
2000-11-17 11:37:46 +00:00
|
|
|
// if pPos != NULL it will become the position of the found entry, or
|
|
|
|
// if that was not found the position where it has to be inserted
|
|
|
|
// to keep the entries sorted
|
|
|
|
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2007-06-07 13:21:55 +00:00
|
|
|
const uno::Reference< XDictionaryEntry > *pEntry = aEntries.getConstArray();
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 nUpperIdx = getCount(),
|
2000-11-17 11:37:46 +00:00
|
|
|
nMidIdx,
|
|
|
|
nLowerIdx = 0;
|
|
|
|
if( nUpperIdx > 0 )
|
|
|
|
{
|
|
|
|
nUpperIdx--;
|
|
|
|
while( nLowerIdx <= nUpperIdx )
|
|
|
|
{
|
|
|
|
nMidIdx = (nLowerIdx + nUpperIdx) / 2;
|
|
|
|
DBG_ASSERT(pEntry[nMidIdx].is(), "lng : empty entry encountered");
|
|
|
|
|
|
|
|
int nCmp = - cmpDicEntry( pEntry[nMidIdx]->getDictionaryWord(),
|
|
|
|
rWord, bSimilarOnly );
|
|
|
|
if(nCmp == 0)
|
|
|
|
{
|
|
|
|
if( pPos ) *pPos = nMidIdx;
|
2014-04-15 08:48:53 +02:00
|
|
|
return true;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
else if(nCmp > 0)
|
|
|
|
nLowerIdx = nMidIdx + 1;
|
|
|
|
else if( nMidIdx == 0 )
|
|
|
|
{
|
|
|
|
if( pPos ) *pPos = nLowerIdx;
|
2014-04-15 08:48:53 +02:00
|
|
|
return false;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
nUpperIdx = nMidIdx - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( pPos ) *pPos = nLowerIdx;
|
2014-04-15 08:48:53 +02:00
|
|
|
return false;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:22:29 +00:00
|
|
|
bool DictionaryNeo::isSorted()
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2013-03-04 09:22:29 +00:00
|
|
|
bool bRes = true;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
2007-06-07 13:21:55 +00:00
|
|
|
const uno::Reference< XDictionaryEntry > *pEntry = aEntries.getConstArray();
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 nEntries = getCount();
|
|
|
|
sal_Int32 i;
|
2000-11-17 11:37:46 +00:00
|
|
|
for (i = 1; i < nEntries; i++)
|
|
|
|
{
|
|
|
|
if (cmpDicEntry( pEntry[i-1]->getDictionaryWord(),
|
|
|
|
pEntry[i]->getDictionaryWord() ) > 0)
|
|
|
|
{
|
2013-03-04 09:22:29 +00:00
|
|
|
bRes = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bRes;
|
|
|
|
}
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
bool DictionaryNeo::addEntry_Impl(const uno::Reference< XDictionaryEntry > xDicEntry,
|
|
|
|
bool bIsLoadEntries)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bRes = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
if ( bIsLoadEntries || (!bIsReadonly && xDicEntry.is()) )
|
|
|
|
{
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bIsNegEntry = xDicEntry->isNegative();
|
|
|
|
bool bAddEntry = !isFull() &&
|
2000-11-17 11:37:46 +00:00
|
|
|
( ( eDicType == DictionaryType_POSITIVE && !bIsNegEntry )
|
|
|
|
|| ( eDicType == DictionaryType_NEGATIVE && bIsNegEntry )
|
|
|
|
|| ( eDicType == DictionaryType_MIXED ) );
|
|
|
|
|
|
|
|
// look for position to insert entry at
|
|
|
|
// if there is already an entry do not insert the new one
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 nPos = 0;
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bFound = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
if (bAddEntry)
|
|
|
|
{
|
|
|
|
bFound = seekEntry( xDicEntry->getDictionaryWord(), &nPos );
|
|
|
|
if (bFound)
|
2014-04-15 08:48:53 +02:00
|
|
|
bAddEntry = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bAddEntry)
|
|
|
|
{
|
2008-11-10 15:06:12 +00:00
|
|
|
DBG_ASSERT(!bNeedEntries, "lng : entries still not loaded");
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
if (nCount >= aEntries.getLength())
|
2013-04-11 00:21:40 -03:00
|
|
|
aEntries.realloc( std::max(2 * nCount, nCount + 32) );
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Reference< XDictionaryEntry > *pEntry = aEntries.getArray();
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
// shift old entries right
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 i;
|
2000-11-17 11:37:46 +00:00
|
|
|
for (i = nCount - 1; i >= nPos; i--)
|
|
|
|
pEntry[ i+1 ] = pEntry[ i ];
|
|
|
|
// insert new entry at specified position
|
|
|
|
pEntry[ nPos ] = xDicEntry;
|
2013-03-04 09:22:29 +00:00
|
|
|
SAL_WARN_IF(!isSorted(), "linguistic", "dictionary entries unsorted");
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
nCount++;
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
bIsModified = true;
|
|
|
|
bRes = true;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
if (!bIsLoadEntries)
|
|
|
|
launchEvent( DictionaryEventFlags::ADD_ENTRY, xDicEntry );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL DictionaryNeo::getName( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
return aDicName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL DictionaryNeo::setName( const OUString& aName )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
if (aDicName != aName)
|
|
|
|
{
|
|
|
|
aDicName = aName;
|
|
|
|
launchEvent(DictionaryEventFlags::CHG_NAME, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DictionaryType SAL_CALL DictionaryNeo::getDictionaryType( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
return eDicType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL DictionaryNeo::setActive( sal_Bool bActivate )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
if ((bIsActive ? 1 : 0) != bActivate)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
bIsActive = bActivate != 0;
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int16 nEvent = bIsActive ?
|
2000-11-17 11:37:46 +00:00
|
|
|
DictionaryEventFlags::ACTIVATE_DIC : DictionaryEventFlags::DEACTIVATE_DIC;
|
|
|
|
|
|
|
|
// remove entries from memory if dictionary is deactivated
|
2014-04-15 08:48:53 +02:00
|
|
|
if (bIsActive == false)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bIsEmpty = nCount == 0;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
// save entries first if necessary
|
|
|
|
if (bIsModified && hasLocation() && !isReadonly())
|
|
|
|
{
|
|
|
|
store();
|
|
|
|
|
|
|
|
aEntries.realloc( 0 );
|
|
|
|
nCount = 0;
|
|
|
|
bNeedEntries = !bIsEmpty;
|
|
|
|
}
|
|
|
|
DBG_ASSERT( !bIsModified || !hasLocation() || isReadonly(),
|
|
|
|
"lng : dictionary is still modified" );
|
|
|
|
}
|
|
|
|
|
|
|
|
launchEvent(nEvent, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DictionaryNeo::isActive( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
return bIsActive;
|
|
|
|
}
|
|
|
|
|
2008-12-15 12:01:46 +00:00
|
|
|
sal_Int32 SAL_CALL DictionaryNeo::getCount( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
if (bNeedEntries)
|
|
|
|
loadEntries( aMainURL );
|
|
|
|
return nCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
Locale SAL_CALL DictionaryNeo::getLocale( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
2013-07-13 02:54:05 +02:00
|
|
|
return LanguageTag::convertToLocale( nLanguage );
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL DictionaryNeo::setLocale( const Locale& aLocale )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
2013-01-09 16:48:52 +01:00
|
|
|
sal_Int16 nLanguageP = LinguLocaleToLanguage( aLocale );
|
2000-11-17 11:37:46 +00:00
|
|
|
if (!bIsReadonly && nLanguage != nLanguageP)
|
|
|
|
{
|
|
|
|
nLanguage = nLanguageP;
|
2014-04-15 08:48:53 +02:00
|
|
|
bIsModified = true; // new language needs to be saved with dictionary
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
launchEvent( DictionaryEventFlags::CHG_LANGUAGE, NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Reference< XDictionaryEntry > SAL_CALL DictionaryNeo::getEntry(
|
2000-11-17 11:37:46 +00:00
|
|
|
const OUString& aWord )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
if (bNeedEntries)
|
|
|
|
loadEntries( aMainURL );
|
|
|
|
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 nPos;
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bFound = seekEntry( aWord, &nPos, true );
|
2000-11-17 11:37:46 +00:00
|
|
|
DBG_ASSERT( nCount <= aEntries.getLength(), "lng : wrong number of entries");
|
|
|
|
DBG_ASSERT(!bFound || nPos < nCount, "lng : index out of range");
|
|
|
|
|
|
|
|
return bFound ? aEntries.getConstArray()[ nPos ]
|
2007-06-07 13:21:55 +00:00
|
|
|
: uno::Reference< XDictionaryEntry >();
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DictionaryNeo::addEntry(
|
2007-06-07 13:21:55 +00:00
|
|
|
const uno::Reference< XDictionaryEntry >& xDicEntry )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bRes = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
if (!bIsReadonly)
|
|
|
|
{
|
|
|
|
if (bNeedEntries)
|
|
|
|
loadEntries( aMainURL );
|
|
|
|
bRes = addEntry_Impl( xDicEntry );
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL
|
|
|
|
DictionaryNeo::add( const OUString& rWord, sal_Bool bIsNegative,
|
|
|
|
const OUString& rRplcText )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bRes = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
if (!bIsReadonly)
|
|
|
|
{
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Reference< XDictionaryEntry > xEntry =
|
2000-11-17 11:37:46 +00:00
|
|
|
new DicEntry( rWord, bIsNegative, rRplcText );
|
|
|
|
bRes = addEntry_Impl( xEntry );
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRes;
|
|
|
|
}
|
|
|
|
|
2012-10-12 13:30:30 +02:00
|
|
|
static void lcl_SequenceRemoveElementAt(
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Sequence< uno::Reference< XDictionaryEntry > >& rEntries, int nPos )
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
//TODO: helper for SequenceRemoveElementAt available?
|
|
|
|
if(nPos >= rEntries.getLength())
|
|
|
|
return;
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Sequence< uno::Reference< XDictionaryEntry > > aTmp(rEntries.getLength() - 1);
|
|
|
|
uno::Reference< XDictionaryEntry > * pOrig = rEntries.getArray();
|
|
|
|
uno::Reference< XDictionaryEntry > * pTemp = aTmp.getArray();
|
2000-11-17 11:37:46 +00:00
|
|
|
int nOffset = 0;
|
|
|
|
for(int i = 0; i < aTmp.getLength(); i++)
|
|
|
|
{
|
|
|
|
if(nPos == i)
|
|
|
|
nOffset++;
|
|
|
|
pTemp[i] = pOrig[i + nOffset];
|
|
|
|
}
|
|
|
|
|
|
|
|
rEntries = aTmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DictionaryNeo::remove( const OUString& aWord )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bRemoved = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
if (!bIsReadonly)
|
|
|
|
{
|
|
|
|
if (bNeedEntries)
|
|
|
|
loadEntries( aMainURL );
|
|
|
|
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 nPos;
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bFound = seekEntry( aWord, &nPos );
|
2000-11-17 11:37:46 +00:00
|
|
|
DBG_ASSERT( nCount < aEntries.getLength(),
|
|
|
|
"lng : wrong number of entries");
|
|
|
|
DBG_ASSERT(!bFound || nPos < nCount, "lng : index out of range");
|
|
|
|
|
|
|
|
// remove element if found
|
|
|
|
if (bFound)
|
|
|
|
{
|
|
|
|
// entry to be removed
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Reference< XDictionaryEntry >
|
2000-11-17 11:37:46 +00:00
|
|
|
xDicEntry( aEntries.getConstArray()[ nPos ] );
|
2008-11-10 15:06:12 +00:00
|
|
|
DBG_ASSERT(xDicEntry.is(), "lng : dictionary entry is NULL");
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
nCount--;
|
|
|
|
|
|
|
|
//! the following call reduces the length of the sequence by 1 also
|
|
|
|
lcl_SequenceRemoveElementAt( aEntries, nPos );
|
2014-04-15 08:48:53 +02:00
|
|
|
bRemoved = bIsModified = true;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
launchEvent( DictionaryEventFlags::DEL_ENTRY, xDicEntry );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRemoved;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DictionaryNeo::isFull( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
if (bNeedEntries)
|
|
|
|
loadEntries( aMainURL );
|
|
|
|
return nCount >= DIC_MAX_ENTRIES;
|
|
|
|
}
|
|
|
|
|
2007-06-07 13:21:55 +00:00
|
|
|
uno::Sequence< uno::Reference< XDictionaryEntry > >
|
2000-11-17 11:37:46 +00:00
|
|
|
SAL_CALL DictionaryNeo::getEntries( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
if (bNeedEntries)
|
|
|
|
loadEntries( aMainURL );
|
|
|
|
//! return sequence with length equal to the number of dictionary entries
|
|
|
|
//! (internal used sequence may have additional unused elements.)
|
2007-06-07 13:21:55 +00:00
|
|
|
return uno::Sequence< uno::Reference< XDictionaryEntry > >
|
2000-11-17 11:37:46 +00:00
|
|
|
(aEntries.getConstArray(), nCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SAL_CALL DictionaryNeo::clear( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
if (!bIsReadonly && nCount)
|
|
|
|
{
|
|
|
|
// release all references to old entries and provide space for new ones
|
2007-06-07 13:21:55 +00:00
|
|
|
aEntries = uno::Sequence< uno::Reference< XDictionaryEntry > > ( 32 );
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
nCount = 0;
|
2014-04-15 08:48:53 +02:00
|
|
|
bNeedEntries = false;
|
|
|
|
bIsModified = true;
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
launchEvent( DictionaryEventFlags::ENTRIES_CLEARED , NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DictionaryNeo::addDictionaryEventListener(
|
2007-06-07 13:21:55 +00:00
|
|
|
const uno::Reference< XDictionaryEventListener >& xListener )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bRes = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
if (xListener.is())
|
|
|
|
{
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 nLen = aDicEvtListeners.getLength();
|
2007-05-25 11:21:48 +00:00
|
|
|
bRes = aDicEvtListeners.addInterface( xListener ) != nLen;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
return bRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DictionaryNeo::removeDictionaryEventListener(
|
2007-06-07 13:21:55 +00:00
|
|
|
const uno::Reference< XDictionaryEventListener >& xListener )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bRes = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
if (xListener.is())
|
|
|
|
{
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_Int32 nLen = aDicEvtListeners.getLength();
|
2007-05-25 11:21:48 +00:00
|
|
|
bRes = aDicEvtListeners.removeInterface( xListener ) != nLen;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
return bRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DictionaryNeo::hasLocation()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
2011-12-27 11:08:04 -02:00
|
|
|
return !aMainURL.isEmpty();
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL DictionaryNeo::getLocation()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
return aMainURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DictionaryNeo::isReadonly()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
return bIsReadonly;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL DictionaryNeo::store()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(io::IOException, RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
|
|
|
if (bIsModified && hasLocation() && !isReadonly())
|
|
|
|
{
|
2012-10-05 23:42:12 -03:00
|
|
|
if (!saveEntries( aMainURL ))
|
2014-04-15 08:48:53 +02:00
|
|
|
bIsModified = false;
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL DictionaryNeo::storeAsURL(
|
|
|
|
const OUString& aURL,
|
2007-05-25 11:21:48 +00:00
|
|
|
const uno::Sequence< beans::PropertyValue >& /*rArgs*/ )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(io::IOException, RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2012-10-05 23:42:12 -03:00
|
|
|
if (!saveEntries( aURL ))
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
aMainURL = aURL;
|
2014-04-15 08:48:53 +02:00
|
|
|
bIsModified = false;
|
2004-04-27 15:07:06 +00:00
|
|
|
bIsReadonly = IsReadOnly( getLocation() );
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL DictionaryNeo::storeToURL(
|
|
|
|
const OUString& aURL,
|
2007-05-25 11:21:48 +00:00
|
|
|
const uno::Sequence< beans::PropertyValue >& /*rArgs*/ )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(io::IOException, RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
2012-10-09 23:04:37 +01:00
|
|
|
saveEntries(aURL);
|
2000-11-17 11:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicEntry::DicEntry(const OUString &rDicFileWord,
|
2014-04-15 08:48:53 +02:00
|
|
|
bool bIsNegativWord)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
2011-12-27 11:08:04 -02:00
|
|
|
if (!rDicFileWord.isEmpty())
|
2000-11-17 11:37:46 +00:00
|
|
|
splitDicFileWord( rDicFileWord, aDicWord, aReplacement );
|
|
|
|
bIsNegativ = bIsNegativWord;
|
|
|
|
}
|
|
|
|
|
2014-04-15 08:48:53 +02:00
|
|
|
DicEntry::DicEntry(const OUString &rDicWord, bool bNegativ,
|
2000-11-17 11:37:46 +00:00
|
|
|
const OUString &rRplcText) :
|
|
|
|
aDicWord (rDicWord),
|
2007-05-25 11:21:48 +00:00
|
|
|
aReplacement (rRplcText),
|
|
|
|
bIsNegativ (bNegativ)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DicEntry::~DicEntry()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DicEntry::splitDicFileWord(const OUString &rDicFileWord,
|
|
|
|
OUString &rDicWord,
|
|
|
|
OUString &rReplacement)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
|
2013-01-30 11:44:23 +01:00
|
|
|
static const OUString aDelim( "==" );
|
2000-11-17 11:37:46 +00:00
|
|
|
|
|
|
|
sal_Int32 nDelimPos = rDicFileWord.indexOf( aDelim );
|
|
|
|
if (-1 != nDelimPos)
|
|
|
|
{
|
2007-05-25 11:21:48 +00:00
|
|
|
sal_Int32 nTriplePos = nDelimPos + 2;
|
2000-11-17 11:37:46 +00:00
|
|
|
if ( nTriplePos < rDicFileWord.getLength()
|
|
|
|
&& rDicFileWord[ nTriplePos ] == '=' )
|
|
|
|
++nDelimPos;
|
|
|
|
rDicWord = rDicFileWord.copy( 0, nDelimPos );
|
|
|
|
rReplacement = rDicFileWord.copy( nDelimPos + 2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rDicWord = rDicFileWord;
|
|
|
|
rReplacement = OUString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL DicEntry::getDictionaryWord( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
return aDicWord;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DicEntry::isNegative( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
return bIsNegativ;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL DicEntry::getReplacementText( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(RuntimeException, std::exception)
|
2000-11-17 11:37:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( GetLinguMutex() );
|
|
|
|
return aReplacement;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|