1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _LINGUISTIC_DICIMP_HXX_ 29*cdf0e10cSrcweir #define _LINGUISTIC_DICIMP_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/linguistic2/XDictionary.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <uno/lbnames.h> // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type 36*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> // helper for implementations 37*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> // helper for implementations 38*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h> 39*cdf0e10cSrcweir #include <tools/string.hxx> 40*cdf0e10cSrcweir #include <tools/stream.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include "defs.hxx" 43*cdf0e10cSrcweir #include "linguistic/misc.hxx" 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #define DIC_MAX_ENTRIES 30000 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir sal_Int16 ReadDicVersion( SvStreamPtr &rpStream, sal_uInt16 &nLng, sal_Bool &bNeg ); 51*cdf0e10cSrcweir const String GetDicExtension(); 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir class DictionaryNeo : 56*cdf0e10cSrcweir public ::cppu::WeakImplHelper2 57*cdf0e10cSrcweir < 58*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionary, 59*cdf0e10cSrcweir ::com::sun::star::frame::XStorable 60*cdf0e10cSrcweir > 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper aDicEvtListeners; 64*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< 65*cdf0e10cSrcweir ::com::sun::star::uno::Reference< 66*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionaryEntry > > aEntries; 67*cdf0e10cSrcweir ::rtl::OUString aDicName; 68*cdf0e10cSrcweir ::rtl::OUString aMainURL; 69*cdf0e10cSrcweir ::com::sun::star::linguistic2::DictionaryType eDicType; 70*cdf0e10cSrcweir sal_Int16 nCount; 71*cdf0e10cSrcweir sal_Int16 nLanguage; 72*cdf0e10cSrcweir sal_Int16 nDicVersion; 73*cdf0e10cSrcweir sal_Bool bNeedEntries; 74*cdf0e10cSrcweir sal_Bool bIsModified; 75*cdf0e10cSrcweir sal_Bool bIsActive; 76*cdf0e10cSrcweir sal_Bool bIsReadonly; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // disallow copy-constructor and assignment-operator for now 79*cdf0e10cSrcweir DictionaryNeo(const DictionaryNeo &); 80*cdf0e10cSrcweir DictionaryNeo & operator = (const DictionaryNeo &); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir void launchEvent(sal_Int16 nEvent, 83*cdf0e10cSrcweir ::com::sun::star::uno::Reference< 84*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionaryEntry > xEntry); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir sal_uLong loadEntries(const ::rtl::OUString &rMainURL); 87*cdf0e10cSrcweir sal_uLong saveEntries(const ::rtl::OUString &rMainURL); 88*cdf0e10cSrcweir int cmpDicEntry(const ::rtl::OUString &rWord1, 89*cdf0e10cSrcweir const ::rtl::OUString &rWord2, 90*cdf0e10cSrcweir sal_Bool bSimilarOnly = sal_False); 91*cdf0e10cSrcweir sal_Bool seekEntry(const ::rtl::OUString &rWord, sal_Int32 *pPos, 92*cdf0e10cSrcweir sal_Bool bSimilarOnly = sal_False); 93*cdf0e10cSrcweir sal_Bool isSorted(); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir sal_Bool addEntry_Impl(const ::com::sun::star::uno::Reference< 96*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionaryEntry > xDicEntry, 97*cdf0e10cSrcweir sal_Bool bIsLoadEntries = sal_False); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir public: 100*cdf0e10cSrcweir DictionaryNeo(); 101*cdf0e10cSrcweir DictionaryNeo(const ::rtl::OUString &rName, sal_Int16 nLang, 102*cdf0e10cSrcweir ::com::sun::star::linguistic2::DictionaryType eType, 103*cdf0e10cSrcweir const ::rtl::OUString &rMainURL, 104*cdf0e10cSrcweir sal_Bool bWriteable ); 105*cdf0e10cSrcweir virtual ~DictionaryNeo(); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // XNamed 108*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL 109*cdf0e10cSrcweir getName() 110*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 111*cdf0e10cSrcweir virtual void SAL_CALL 112*cdf0e10cSrcweir setName( const ::rtl::OUString& aName ) 113*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir // XDictionary 116*cdf0e10cSrcweir virtual ::com::sun::star::linguistic2::DictionaryType SAL_CALL 117*cdf0e10cSrcweir getDictionaryType() 118*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 119*cdf0e10cSrcweir virtual void SAL_CALL 120*cdf0e10cSrcweir setActive( sal_Bool bActivate ) 121*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 122*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 123*cdf0e10cSrcweir isActive() 124*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 125*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL 126*cdf0e10cSrcweir getCount() 127*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 128*cdf0e10cSrcweir virtual ::com::sun::star::lang::Locale SAL_CALL 129*cdf0e10cSrcweir getLocale() 130*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 131*cdf0e10cSrcweir virtual void SAL_CALL 132*cdf0e10cSrcweir setLocale( const ::com::sun::star::lang::Locale& aLocale ) 133*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 134*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< 135*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionaryEntry > SAL_CALL 136*cdf0e10cSrcweir getEntry( const ::rtl::OUString& aWord ) 137*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 138*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 139*cdf0e10cSrcweir addEntry( const ::com::sun::star::uno::Reference< 140*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionaryEntry >& xDicEntry ) 141*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 142*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 143*cdf0e10cSrcweir add( const ::rtl::OUString& aWord, sal_Bool bIsNegative, 144*cdf0e10cSrcweir const ::rtl::OUString& aRplcText ) 145*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 146*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 147*cdf0e10cSrcweir remove( const ::rtl::OUString& aWord ) 148*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 149*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 150*cdf0e10cSrcweir isFull() 151*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 152*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< 153*cdf0e10cSrcweir ::com::sun::star::uno::Reference< 154*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionaryEntry > > SAL_CALL 155*cdf0e10cSrcweir getEntries() 156*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 157*cdf0e10cSrcweir virtual void SAL_CALL 158*cdf0e10cSrcweir clear() 159*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 160*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 161*cdf0e10cSrcweir addDictionaryEventListener( const ::com::sun::star::uno::Reference< 162*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionaryEventListener >& xListener ) 163*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 164*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 165*cdf0e10cSrcweir removeDictionaryEventListener( const ::com::sun::star::uno::Reference< 166*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionaryEventListener >& xListener ) 167*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir // XStorable 170*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 171*cdf0e10cSrcweir hasLocation() 172*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 173*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL 174*cdf0e10cSrcweir getLocation() 175*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 176*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 177*cdf0e10cSrcweir isReadonly() 178*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 179*cdf0e10cSrcweir virtual void SAL_CALL 180*cdf0e10cSrcweir store() 181*cdf0e10cSrcweir throw(::com::sun::star::io::IOException, 182*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 183*cdf0e10cSrcweir virtual void SAL_CALL 184*cdf0e10cSrcweir storeAsURL( const ::rtl::OUString& aURL, 185*cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< 186*cdf0e10cSrcweir ::com::sun::star::beans::PropertyValue >& aArgs ) 187*cdf0e10cSrcweir throw(::com::sun::star::io::IOException, 188*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 189*cdf0e10cSrcweir virtual void SAL_CALL 190*cdf0e10cSrcweir storeToURL( const ::rtl::OUString& aURL, 191*cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< 192*cdf0e10cSrcweir ::com::sun::star::beans::PropertyValue >& aArgs ) 193*cdf0e10cSrcweir throw(::com::sun::star::io::IOException, 194*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 195*cdf0e10cSrcweir }; 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir class DicEntry : 201*cdf0e10cSrcweir public cppu::WeakImplHelper1 202*cdf0e10cSrcweir < 203*cdf0e10cSrcweir ::com::sun::star::linguistic2::XDictionaryEntry 204*cdf0e10cSrcweir > 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir ::rtl::OUString aDicWord, // including hyphen positions represented by "=" 207*cdf0e10cSrcweir aReplacement; // including hyphen positions represented by "=" 208*cdf0e10cSrcweir sal_Bool bIsNegativ; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // disallow copy-constructor and assignment-operator for now 211*cdf0e10cSrcweir DicEntry(const DicEntry &); 212*cdf0e10cSrcweir DicEntry & operator = (const DicEntry &); 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir void splitDicFileWord(const ::rtl::OUString &rDicFileWord, 215*cdf0e10cSrcweir ::rtl::OUString &rDicWord, 216*cdf0e10cSrcweir ::rtl::OUString &rReplacement); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir public: 219*cdf0e10cSrcweir DicEntry(); 220*cdf0e10cSrcweir DicEntry(const ::rtl::OUString &rDicFileWord, sal_Bool bIsNegativ); 221*cdf0e10cSrcweir DicEntry(const ::rtl::OUString &rDicWord, sal_Bool bIsNegativ, 222*cdf0e10cSrcweir const ::rtl::OUString &rRplcText); 223*cdf0e10cSrcweir virtual ~DicEntry(); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir // XDictionaryEntry 226*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL 227*cdf0e10cSrcweir getDictionaryWord() throw(::com::sun::star::uno::RuntimeException); 228*cdf0e10cSrcweir virtual sal_Bool SAL_CALL 229*cdf0e10cSrcweir isNegative() throw(::com::sun::star::uno::RuntimeException); 230*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL 231*cdf0e10cSrcweir getReplacementText() throw(::com::sun::star::uno::RuntimeException); 232*cdf0e10cSrcweir }; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////// 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir #endif 238*cdf0e10cSrcweir 239