LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/linguistic/source - convdic.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 303 0.0 %
Date: 2013-07-09 Functions: 0 32 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <cppuhelper/factory.hxx>
      22             : #include <i18nlangtag/lang.h>
      23             : #include <osl/mutex.hxx>
      24             : #include <tools/debug.hxx>
      25             : #include <tools/stream.hxx>
      26             : #include <tools/string.hxx>
      27             : #include <tools/urlobj.hxx>
      28             : #include <ucbhelper/content.hxx>
      29             : #include <comphelper/processfactory.hxx>
      30             : #include <unotools/streamwrap.hxx>
      31             : #include <unotools/ucbstreamhelper.hxx>
      32             : 
      33             : #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
      34             : #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
      35             : #include <com/sun/star/linguistic2/XConversionPropertyType.hpp>
      36             : #include <com/sun/star/linguistic2/ConversionPropertyType.hpp>
      37             : #include <com/sun/star/util/XFlushable.hpp>
      38             : #include <com/sun/star/lang/Locale.hpp>
      39             : #include <com/sun/star/lang/EventObject.hpp>
      40             : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      41             : #include <com/sun/star/uno/Reference.h>
      42             : #include <com/sun/star/registry/XRegistryKey.hpp>
      43             : #include <com/sun/star/util/XFlushListener.hpp>
      44             : #include <com/sun/star/io/XActiveDataSource.hpp>
      45             : #include <com/sun/star/io/XInputStream.hpp>
      46             : #include <com/sun/star/io/XOutputStream.hpp>
      47             : #include <com/sun/star/xml/sax/Writer.hpp>
      48             : #include <com/sun/star/document/XFilter.hpp>
      49             : #include <com/sun/star/beans/PropertyValue.hpp>
      50             : #include <com/sun/star/xml/sax/InputSource.hpp>
      51             : #include <com/sun/star/xml/sax/Parser.hpp>
      52             : 
      53             : 
      54             : #include "convdic.hxx"
      55             : #include "convdicxml.hxx"
      56             : #include "linguistic/misc.hxx"
      57             : #include "defs.hxx"
      58             : 
      59             : using namespace std;
      60             : using namespace utl;
      61             : using namespace osl;
      62             : using namespace com::sun::star;
      63             : using namespace com::sun::star::lang;
      64             : using namespace com::sun::star::uno;
      65             : using namespace com::sun::star::linguistic2;
      66             : using namespace linguistic;
      67             : 
      68             : 
      69             : #define SN_CONV_DICTIONARY      "com.sun.star.linguistic2.ConversionDictionary"
      70             : 
      71           0 : void ReadThroughDic( const String &rMainURL, ConvDicXMLImport &rImport )
      72             : {
      73           0 :     if (rMainURL.Len() == 0)
      74           0 :         return;
      75             :     DBG_ASSERT(!INetURLObject( rMainURL ).HasError(), "invalid URL");
      76             : 
      77           0 :     uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
      78             : 
      79             :     // get xInputStream stream
      80           0 :     uno::Reference< io::XInputStream > xIn;
      81             :     try
      82             :     {
      83           0 :         uno::Reference< ucb::XSimpleFileAccess3 > xAccess( ucb::SimpleFileAccess::create(xContext) );
      84           0 :         xIn = xAccess->openFileRead( rMainURL );
      85             :     }
      86           0 :     catch (const uno::Exception &)
      87             :     {
      88             :         DBG_ASSERT( 0, "failed to get input stream" );
      89             :     }
      90           0 :     if (!xIn.is())
      91           0 :         return;
      92             : 
      93           0 :     SvStreamPtr pStream = SvStreamPtr( utl::UcbStreamHelper::CreateStream( xIn ) );
      94             : 
      95             :     // prepare ParserInputSource
      96           0 :     xml::sax::InputSource aParserInput;
      97           0 :     aParserInput.aInputStream = xIn;
      98             : 
      99             :     // get parser
     100           0 :     uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
     101             : 
     102             :     //!! keep a reference until everything is done to
     103             :     //!! ensure the proper lifetime of the object
     104             :     uno::Reference < xml::sax::XDocumentHandler > xFilter(
     105           0 :             (xml::sax::XExtendedDocumentHandler *) &rImport, UNO_QUERY );
     106             : 
     107             :     // connect parser and filter
     108           0 :     xParser->setDocumentHandler( xFilter );
     109             : 
     110             :     // finally, parser the stream
     111             :     try
     112             :     {
     113           0 :         xParser->parseStream( aParserInput );   // implicitly calls ConvDicXMLImport::CreateContext
     114             :     }
     115           0 :     catch( xml::sax::SAXParseException& )
     116             :     {
     117             :     }
     118           0 :     catch( xml::sax::SAXException& )
     119             :     {
     120             :     }
     121           0 :     catch( io::IOException& )
     122             :     {
     123           0 :     }
     124             : }
     125             : 
     126           0 : sal_Bool IsConvDic( const String &rFileURL, sal_Int16 &nLang, sal_Int16 &nConvType )
     127             : {
     128           0 :     sal_Bool bRes = sal_False;
     129             : 
     130           0 :     if (rFileURL.Len() == 0)
     131           0 :         return bRes;
     132             : 
     133             :     // check if file extension matches CONV_DIC_EXT
     134           0 :     String aExt;
     135           0 :     xub_StrLen nPos = rFileURL.SearchBackward( '.' );
     136           0 :     if (STRING_NOTFOUND != nPos)
     137           0 :         aExt = rFileURL.Copy( nPos + 1 );
     138           0 :     aExt.ToLowerAscii();
     139           0 :     if (!aExt.EqualsAscii( CONV_DIC_EXT ))
     140           0 :         return bRes;
     141             : 
     142             :     // first argument being 0 should stop the file from being parsed
     143             :     // up to the end (reading all entries) when the required
     144             :     // data (language, conversion type) is found.
     145           0 :     ConvDicXMLImport *pImport = new ConvDicXMLImport( 0, rFileURL );
     146             : 
     147             :     //!! keep a first reference to ensure the lifetime of the object !!
     148           0 :     uno::Reference< XInterface > xRef( (document::XFilter *) pImport, UNO_QUERY );
     149             : 
     150           0 :     ReadThroughDic( rFileURL, *pImport );    // will implicitly add the entries
     151           0 :     bRes =  !LinguIsUnspecified( pImport->GetLanguage()) &&
     152           0 :             pImport->GetConversionType() != -1;
     153             :     DBG_ASSERT( bRes, "conversion dictionary corrupted?" );
     154             : 
     155           0 :     if (bRes)
     156             :     {
     157           0 :         nLang       = pImport->GetLanguage();
     158           0 :         nConvType   = pImport->GetConversionType();
     159             :     }
     160             : 
     161           0 :     return bRes;
     162             : }
     163             : 
     164             : 
     165             : 
     166           0 : ConvDic::ConvDic(
     167             :         const String &rName,
     168             :         sal_Int16 nLang,
     169             :         sal_Int16 nConvType,
     170             :              sal_Bool bBiDirectional,
     171             :         const String &rMainURL) :
     172           0 :     aFlushListeners( GetLinguMutex() )
     173             : {
     174           0 :     aName           = rName;
     175           0 :     nLanguage       = nLang;
     176           0 :     nConversionType = nConvType;
     177           0 :     aMainURL        = rMainURL;
     178             : 
     179           0 :     if (bBiDirectional)
     180           0 :         pFromRight = std::auto_ptr< ConvMap >( new ConvMap );
     181           0 :     if (nLang == LANGUAGE_CHINESE_SIMPLIFIED || nLang == LANGUAGE_CHINESE_TRADITIONAL)
     182           0 :         pConvPropType = std::auto_ptr< PropTypeMap >( new PropTypeMap );
     183             : 
     184           0 :     nMaxLeftCharCount = nMaxRightCharCount = 0;
     185           0 :     bMaxCharCountIsValid = sal_True;
     186             : 
     187           0 :     bNeedEntries = sal_True;
     188           0 :     bIsModified  = bIsActive = sal_False;
     189           0 :     bIsReadonly = sal_False;
     190             : 
     191           0 :     if( rMainURL.Len() > 0 )
     192             :     {
     193           0 :         sal_Bool bExists = sal_False;
     194           0 :         bIsReadonly = IsReadOnly( rMainURL, &bExists );
     195             : 
     196           0 :         if( !bExists )  // new empty dictionary
     197             :         {
     198           0 :             bNeedEntries = sal_False;
     199             :             //! create physical representation of an **empty** dictionary
     200             :             //! that could be found by the dictionary-list implementation
     201             :             // (Note: empty dictionaries are not just empty files!)
     202           0 :             Save();
     203           0 :             bIsReadonly = IsReadOnly( rMainURL );   // will be sal_False if Save was successful
     204             :         }
     205             :     }
     206             :     else
     207             :     {
     208           0 :         bNeedEntries = sal_False;
     209             :     }
     210           0 : }
     211             : 
     212             : 
     213           0 : ConvDic::~ConvDic()
     214             : {
     215           0 : }
     216             : 
     217             : 
     218           0 : void ConvDic::Load()
     219             : {
     220             :     DBG_ASSERT( !bIsModified, "dictionary is modified. Really do 'Load'?" );
     221             : 
     222             :     //!! prevent function from being called recursively via HasEntry, AddEntry
     223           0 :     bNeedEntries = sal_False;
     224           0 :     ConvDicXMLImport *pImport = new ConvDicXMLImport( this, aMainURL );
     225             :     //!! keep a first reference to ensure the lifetime of the object !!
     226           0 :     uno::Reference< XInterface > xRef( (document::XFilter *) pImport, UNO_QUERY );
     227           0 :     ReadThroughDic( aMainURL, *pImport );    // will implicitly add the entries
     228           0 :     bIsModified = sal_False;
     229           0 : }
     230             : 
     231             : 
     232           0 : void ConvDic::Save()
     233             : {
     234             :     DBG_ASSERT( !bNeedEntries, "saving while entries missing" );
     235           0 :     if (aMainURL.Len() == 0 || bNeedEntries)
     236           0 :         return;
     237             :     DBG_ASSERT(!INetURLObject( aMainURL ).HasError(), "invalid URL");
     238             : 
     239           0 :     uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
     240             : 
     241             :     // get XOutputStream stream
     242           0 :     uno::Reference< io::XStream > xStream;
     243             :     try
     244             :     {
     245           0 :         uno::Reference< ucb::XSimpleFileAccess3 > xAccess( ucb::SimpleFileAccess::create(xContext) );
     246           0 :         xStream = xAccess->openFileReadWrite( aMainURL );
     247             :     }
     248           0 :     catch (const uno::Exception &)
     249             :     {
     250             :         DBG_ASSERT( 0, "failed to get input stream" );
     251             :     }
     252           0 :     if (!xStream.is())
     253           0 :         return;
     254             : 
     255           0 :     SvStreamPtr pStream = SvStreamPtr( utl::UcbStreamHelper::CreateStream( xStream ) );
     256             : 
     257             :     // get XML writer
     258           0 :     uno::Reference< xml::sax::XWriter > xSaxWriter = xml::sax::Writer::create(xContext);
     259             : 
     260           0 :     if (xStream.is())
     261             :     {
     262             :         // connect XML writer to output stream
     263           0 :         xSaxWriter->setOutputStream( xStream->getOutputStream() );
     264             : 
     265             :         // prepare arguments (prepend doc handler to given arguments)
     266           0 :         uno::Reference< xml::sax::XDocumentHandler > xDocHandler( xSaxWriter, UNO_QUERY );
     267           0 :         ConvDicXMLExport *pExport = new ConvDicXMLExport( *this, aMainURL, xDocHandler );
     268             :         //!! keep a first(!) reference until everything is done to
     269             :         //!! ensure the proper lifetime of the object
     270           0 :         uno::Reference< document::XFilter > aRef( (document::XFilter *) pExport );
     271           0 :         sal_Bool bRet = pExport->Export();     // write entries to file
     272             :         DBG_ASSERT( !pStream->GetError(), "I/O error while writing to stream" );
     273           0 :         if (bRet)
     274           0 :             bIsModified = sal_False;
     275             :     }
     276           0 :     DBG_ASSERT( !bIsModified, "dictionary still modified after save. Save failed?" );
     277             : }
     278             : 
     279             : 
     280           0 : ConvMap::iterator ConvDic::GetEntry( ConvMap &rMap, const OUString &rFirstText, const OUString &rSecondText )
     281             : {
     282             :     pair< ConvMap::iterator, ConvMap::iterator > aRange =
     283           0 :             rMap.equal_range( rFirstText );
     284           0 :     ConvMap::iterator aPos = rMap.end();
     285           0 :     for (ConvMap::iterator aIt = aRange.first;
     286           0 :          aIt != aRange.second  &&  aPos == rMap.end();
     287             :          ++aIt)
     288             :     {
     289           0 :         if ((*aIt).second == rSecondText)
     290           0 :             aPos = aIt;
     291             :     }
     292           0 :     return aPos;
     293             : }
     294             : 
     295             : 
     296           0 : sal_Bool ConvDic::HasEntry( const OUString &rLeftText, const OUString &rRightText )
     297             : {
     298           0 :     if (bNeedEntries)
     299           0 :         Load();
     300           0 :     ConvMap::iterator aIt = GetEntry( aFromLeft, rLeftText, rRightText );
     301           0 :     return aIt != aFromLeft.end();
     302             : }
     303             : 
     304             : 
     305           0 : void ConvDic::AddEntry( const OUString &rLeftText, const OUString &rRightText )
     306             : {
     307           0 :     if (bNeedEntries)
     308           0 :         Load();
     309             : 
     310             :     DBG_ASSERT(!HasEntry( rLeftText, rRightText), "entry already exists" );
     311           0 :     aFromLeft .insert( ConvMap::value_type( rLeftText, rRightText ) );
     312           0 :     if (pFromRight.get())
     313           0 :         pFromRight->insert( ConvMap::value_type( rRightText, rLeftText ) );
     314             : 
     315           0 :     if (bMaxCharCountIsValid)
     316             :     {
     317           0 :         if (rLeftText.getLength() > nMaxLeftCharCount)
     318           0 :             nMaxLeftCharCount   = (sal_Int16) rLeftText.getLength();
     319           0 :         if (pFromRight.get() && rRightText.getLength() > nMaxRightCharCount)
     320           0 :             nMaxRightCharCount  = (sal_Int16) rRightText.getLength();
     321             :     }
     322             : 
     323           0 :     bIsModified = sal_True;
     324           0 : }
     325             : 
     326             : 
     327           0 : void ConvDic::RemoveEntry( const OUString &rLeftText, const OUString &rRightText )
     328             : {
     329           0 :     if (bNeedEntries)
     330           0 :         Load();
     331             : 
     332           0 :     ConvMap::iterator aLeftIt  = GetEntry( aFromLeft,  rLeftText,  rRightText );
     333             :     DBG_ASSERT( aLeftIt  != aFromLeft.end(),  "left map entry missing" );
     334           0 :     aFromLeft .erase( aLeftIt );
     335             : 
     336           0 :     if (pFromRight.get())
     337             :     {
     338           0 :         ConvMap::iterator aRightIt = GetEntry( *pFromRight, rRightText, rLeftText );
     339             :         DBG_ASSERT( aRightIt != pFromRight->end(), "right map entry missing" );
     340           0 :         pFromRight->erase( aRightIt );
     341             :     }
     342             : 
     343           0 :     bIsModified = sal_True;
     344           0 :     bMaxCharCountIsValid = sal_False;
     345           0 : }
     346             : 
     347             : 
     348           0 : OUString SAL_CALL ConvDic::getName(  )
     349             :     throw (RuntimeException)
     350             : {
     351           0 :     MutexGuard  aGuard( GetLinguMutex() );
     352           0 :     return aName;
     353             : }
     354             : 
     355             : 
     356           0 : Locale SAL_CALL ConvDic::getLocale(  )
     357             :     throw (RuntimeException)
     358             : {
     359           0 :     MutexGuard  aGuard( GetLinguMutex() );
     360           0 :     return LanguageTag( nLanguage ).getLocale();
     361             : }
     362             : 
     363             : 
     364           0 : sal_Int16 SAL_CALL ConvDic::getConversionType(  )
     365             :     throw (RuntimeException)
     366             : {
     367           0 :     MutexGuard  aGuard( GetLinguMutex() );
     368           0 :     return nConversionType;
     369             : }
     370             : 
     371             : 
     372           0 : void SAL_CALL ConvDic::setActive( sal_Bool bActivate )
     373             :     throw (RuntimeException)
     374             : {
     375           0 :     MutexGuard  aGuard( GetLinguMutex() );
     376           0 :     bIsActive = bActivate;
     377           0 : }
     378             : 
     379             : 
     380           0 : sal_Bool SAL_CALL ConvDic::isActive(  )
     381             :     throw (RuntimeException)
     382             : {
     383           0 :     MutexGuard  aGuard( GetLinguMutex() );
     384           0 :     return bIsActive;
     385             : }
     386             : 
     387             : 
     388           0 : void SAL_CALL ConvDic::clear(  )
     389             :     throw (RuntimeException)
     390             : {
     391           0 :     MutexGuard  aGuard( GetLinguMutex() );
     392           0 :     aFromLeft .clear();
     393           0 :     if (pFromRight.get())
     394           0 :         pFromRight->clear();
     395           0 :     bNeedEntries    = sal_False;
     396           0 :     bIsModified     = sal_True;
     397           0 :     nMaxLeftCharCount       = 0;
     398           0 :     nMaxRightCharCount      = 0;
     399           0 :     bMaxCharCountIsValid    = sal_True;
     400           0 : }
     401             : 
     402             : 
     403           0 : uno::Sequence< OUString > SAL_CALL ConvDic::getConversions(
     404             :         const OUString& aText,
     405             :         sal_Int32 nStartPos,
     406             :         sal_Int32 nLength,
     407             :         ConversionDirection eDirection,
     408             :         sal_Int32 /*nTextConversionOptions*/ )
     409             :     throw (IllegalArgumentException, RuntimeException)
     410             : {
     411           0 :     MutexGuard  aGuard( GetLinguMutex() );
     412             : 
     413           0 :     if (!pFromRight.get() && eDirection == ConversionDirection_FROM_RIGHT)
     414           0 :         return uno::Sequence< OUString >();
     415             : 
     416           0 :     if (bNeedEntries)
     417           0 :         Load();
     418             : 
     419           0 :     OUString aLookUpText( aText.copy(nStartPos, nLength) );
     420             :     ConvMap &rConvMap = eDirection == ConversionDirection_FROM_LEFT ?
     421           0 :                                 aFromLeft : *pFromRight;
     422             :     pair< ConvMap::iterator, ConvMap::iterator > aRange =
     423           0 :             rConvMap.equal_range( aLookUpText );
     424             : 
     425           0 :     sal_Int32 nCount = 0;
     426           0 :     ConvMap::iterator aIt;
     427           0 :     for (aIt = aRange.first;  aIt != aRange.second;  ++aIt)
     428           0 :         ++nCount;
     429             : 
     430           0 :     uno::Sequence< OUString > aRes( nCount );
     431           0 :     OUString *pRes = aRes.getArray();
     432           0 :     sal_Int32 i = 0;
     433           0 :     for (aIt = aRange.first;  aIt != aRange.second;  ++aIt)
     434           0 :         pRes[i++] = (*aIt).second;
     435             : 
     436           0 :     return aRes;
     437             : }
     438             : 
     439             : 
     440           0 : static sal_Bool lcl_SeqHasEntry(
     441             :     const OUString *pSeqStart,  // first element to check
     442             :     sal_Int32 nToCheck,             // number of elements to check
     443             :     const OUString &rText)
     444             : {
     445           0 :     sal_Bool bRes = sal_False;
     446           0 :     if (pSeqStart && nToCheck > 0)
     447             :     {
     448           0 :         const OUString *pDone = pSeqStart + nToCheck;   // one behind last to check
     449           0 :         while (!bRes && pSeqStart != pDone)
     450             :         {
     451           0 :             if (*pSeqStart++ == rText)
     452           0 :                 bRes = sal_True;
     453             :         }
     454             :     }
     455           0 :     return bRes;
     456             : }
     457             : 
     458           0 : uno::Sequence< OUString > SAL_CALL ConvDic::getConversionEntries(
     459             :         ConversionDirection eDirection )
     460             :     throw (RuntimeException)
     461             : {
     462           0 :     MutexGuard  aGuard( GetLinguMutex() );
     463             : 
     464           0 :     if (!pFromRight.get() && eDirection == ConversionDirection_FROM_RIGHT)
     465           0 :         return uno::Sequence< OUString >();
     466             : 
     467           0 :     if (bNeedEntries)
     468           0 :         Load();
     469             : 
     470             :     ConvMap &rConvMap = eDirection == ConversionDirection_FROM_LEFT ?
     471           0 :                                 aFromLeft : *pFromRight;
     472           0 :     uno::Sequence< OUString > aRes( rConvMap.size() );
     473           0 :     OUString *pRes = aRes.getArray();
     474           0 :     ConvMap::iterator aIt = rConvMap.begin();
     475           0 :     sal_Int32 nIdx = 0;
     476           0 :     while (aIt != rConvMap.end())
     477             :     {
     478           0 :         OUString aCurEntry( (*aIt).first );
     479             :         // skip duplicate entries ( duplicate = duplicate entries
     480             :         // respective to the evaluated side (FROM_LEFT or FROM_RIGHT).
     481             :         // Thus if FROM_LEFT is evaluated for pairs (A,B) and (A,C)
     482             :         // only one entry for A will be returned in the result)
     483           0 :         if (nIdx == 0 || !lcl_SeqHasEntry( pRes, nIdx, aCurEntry ))
     484           0 :             pRes[ nIdx++ ] = aCurEntry;
     485           0 :         ++aIt;
     486           0 :     }
     487           0 :     aRes.realloc( nIdx );
     488             : 
     489           0 :     return aRes;
     490             : }
     491             : 
     492             : 
     493           0 : void SAL_CALL ConvDic::addEntry(
     494             :         const OUString& aLeftText,
     495             :         const OUString& aRightText )
     496             :     throw (IllegalArgumentException, container::ElementExistException, RuntimeException)
     497             : {
     498           0 :     MutexGuard  aGuard( GetLinguMutex() );
     499           0 :     if (bNeedEntries)
     500           0 :         Load();
     501           0 :     if (HasEntry( aLeftText, aRightText ))
     502           0 :         throw container::ElementExistException();
     503           0 :     AddEntry( aLeftText, aRightText );
     504           0 : }
     505             : 
     506             : 
     507           0 : void SAL_CALL ConvDic::removeEntry(
     508             :         const OUString& aLeftText,
     509             :         const OUString& aRightText )
     510             :     throw (container::NoSuchElementException, RuntimeException)
     511             : {
     512           0 :     MutexGuard  aGuard( GetLinguMutex() );
     513           0 :     if (bNeedEntries)
     514           0 :         Load();
     515           0 :     if (!HasEntry( aLeftText, aRightText ))
     516           0 :         throw container::NoSuchElementException();
     517           0 :     RemoveEntry( aLeftText, aRightText );
     518           0 : }
     519             : 
     520             : 
     521           0 : sal_Int16 SAL_CALL ConvDic::getMaxCharCount( ConversionDirection eDirection )
     522             :     throw (RuntimeException)
     523             : {
     524           0 :     MutexGuard  aGuard( GetLinguMutex() );
     525             : 
     526           0 :     if (!pFromRight.get() && eDirection == ConversionDirection_FROM_RIGHT)
     527             :     {
     528             :         DBG_ASSERT( nMaxRightCharCount == 0, "max right char count should be 0" );
     529           0 :         return 0;
     530             :     }
     531             : 
     532           0 :     if (bNeedEntries)
     533           0 :         Load();
     534             : 
     535           0 :     if (!bMaxCharCountIsValid)
     536             :     {
     537           0 :         nMaxLeftCharCount   = 0;
     538           0 :         ConvMap::iterator aIt = aFromLeft.begin();
     539           0 :         while (aIt != aFromLeft.end())
     540             :         {
     541           0 :             sal_Int16 nTmp = (sal_Int16) (*aIt).first.getLength();
     542           0 :             if (nTmp > nMaxLeftCharCount)
     543           0 :                 nMaxLeftCharCount = nTmp;
     544           0 :             ++aIt;
     545             :         }
     546             : 
     547           0 :         nMaxRightCharCount  = 0;
     548           0 :         if (pFromRight.get())
     549             :         {
     550           0 :             aIt = pFromRight->begin();
     551           0 :             while (aIt != pFromRight->end())
     552             :             {
     553           0 :                 sal_Int16 nTmp = (sal_Int16) (*aIt).first.getLength();
     554           0 :                 if (nTmp > nMaxRightCharCount)
     555           0 :                     nMaxRightCharCount = nTmp;
     556           0 :                 ++aIt;
     557             :             }
     558             :         }
     559             : 
     560           0 :         bMaxCharCountIsValid = sal_True;
     561             :     }
     562             :     sal_Int16 nRes = eDirection == ConversionDirection_FROM_LEFT ?
     563           0 :             nMaxLeftCharCount : nMaxRightCharCount;
     564             :     DBG_ASSERT( nRes >= 0, "invalid MaxCharCount" );
     565           0 :     return nRes;
     566             : }
     567             : 
     568             : 
     569           0 : void SAL_CALL ConvDic::setPropertyType(
     570             :         const OUString& rLeftText,
     571             :         const OUString& rRightText,
     572             :         sal_Int16 nPropertyType )
     573             :     throw (container::NoSuchElementException, IllegalArgumentException, RuntimeException)
     574             : {
     575           0 :     sal_Bool bHasElement = HasEntry( rLeftText, rRightText);
     576           0 :     if (!bHasElement)
     577           0 :         throw container::NoSuchElementException();
     578             : 
     579             :     // currently we assume that entries with the same left text have the
     580             :     // same PropertyType even if the right text is different...
     581           0 :     if (pConvPropType.get())
     582           0 :         pConvPropType->insert( PropTypeMap::value_type( rLeftText, nPropertyType ) );
     583           0 :     bIsModified = sal_True;
     584           0 : }
     585             : 
     586             : 
     587           0 : sal_Int16 SAL_CALL ConvDic::getPropertyType(
     588             :         const OUString& rLeftText,
     589             :         const OUString& rRightText )
     590             :     throw (container::NoSuchElementException, RuntimeException)
     591             : {
     592           0 :     sal_Bool bHasElement = HasEntry( rLeftText, rRightText);
     593           0 :     if (!bHasElement)
     594           0 :         throw container::NoSuchElementException();
     595             : 
     596           0 :     sal_Int16 nRes = ConversionPropertyType::NOT_DEFINED;
     597           0 :     if (pConvPropType.get())
     598             :     {
     599             :         // still assuming that entries with same left text have same PropertyType
     600             :         // even if they have different right text...
     601           0 :         PropTypeMap::iterator aIt = pConvPropType->find( rLeftText );
     602           0 :         if (aIt != pConvPropType->end())
     603           0 :             nRes = (*aIt).second;
     604             :     }
     605           0 :     return nRes;
     606             : }
     607             : 
     608             : 
     609           0 : void SAL_CALL ConvDic::flush(  )
     610             :     throw (RuntimeException)
     611             : {
     612           0 :     MutexGuard  aGuard( GetLinguMutex() );
     613             : 
     614           0 :     if (!bIsModified)
     615           0 :         return;
     616             : 
     617           0 :     Save();
     618             : 
     619             :     // notify listeners
     620           0 :     EventObject aEvtObj;
     621           0 :     aEvtObj.Source = uno::Reference< XFlushable >( this );
     622           0 :     cppu::OInterfaceIteratorHelper aIt( aFlushListeners );
     623           0 :     while (aIt.hasMoreElements())
     624             :     {
     625           0 :         uno::Reference< util::XFlushListener > xRef( aIt.next(), UNO_QUERY );
     626           0 :         if (xRef.is())
     627           0 :             xRef->flushed( aEvtObj );
     628           0 :     }
     629             : }
     630             : 
     631             : 
     632           0 : void SAL_CALL ConvDic::addFlushListener(
     633             :         const uno::Reference< util::XFlushListener >& rxListener )
     634             :     throw (RuntimeException)
     635             : {
     636           0 :     MutexGuard  aGuard( GetLinguMutex() );
     637           0 :     if (rxListener.is())
     638           0 :         aFlushListeners.addInterface( rxListener );
     639           0 : }
     640             : 
     641             : 
     642           0 : void SAL_CALL ConvDic::removeFlushListener(
     643             :         const uno::Reference< util::XFlushListener >& rxListener )
     644             :     throw (RuntimeException)
     645             : {
     646           0 :     MutexGuard  aGuard( GetLinguMutex() );
     647           0 :     if (rxListener.is())
     648           0 :         aFlushListeners.removeInterface( rxListener );
     649           0 : }
     650             : 
     651             : 
     652           0 : OUString SAL_CALL ConvDic::getImplementationName(  )
     653             :     throw (RuntimeException)
     654             : {
     655           0 :     MutexGuard  aGuard( GetLinguMutex() );
     656           0 :     return getImplementationName_Static();
     657             : }
     658             : 
     659             : 
     660           0 : sal_Bool SAL_CALL ConvDic::supportsService( const OUString& rServiceName )
     661             :     throw (RuntimeException)
     662             : {
     663           0 :     MutexGuard  aGuard( GetLinguMutex() );
     664           0 :     sal_Bool bRes = sal_False;
     665           0 :     if ( rServiceName == SN_CONV_DICTIONARY )
     666           0 :         bRes = sal_True;
     667           0 :     return bRes;
     668             : }
     669             : 
     670             : 
     671           0 : uno::Sequence< OUString > SAL_CALL ConvDic::getSupportedServiceNames(  )
     672             :     throw (RuntimeException)
     673             : {
     674           0 :     MutexGuard  aGuard( GetLinguMutex() );
     675           0 :     return getSupportedServiceNames_Static();
     676             : }
     677             : 
     678             : 
     679           0 : uno::Sequence< OUString > ConvDic::getSupportedServiceNames_Static()
     680             :     throw()
     681             : {
     682           0 :     uno::Sequence< OUString > aSNS( 1 );
     683           0 :     aSNS.getArray()[0] = SN_CONV_DICTIONARY ;
     684           0 :     return aSNS;
     685             : }
     686             : 
     687             : 
     688             : 
     689             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10