1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _LINGUISTIC_DICIMP_HXX_ 25 #define _LINGUISTIC_DICIMP_HXX_ 26 27 #include <com/sun/star/linguistic2/XDictionary.hpp> 28 #include <com/sun/star/frame/XStorable.hpp> 29 #include <com/sun/star/lang/XServiceInfo.hpp> 30 31 #include <uno/lbnames.h> // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type 32 #include <cppuhelper/implbase2.hxx> // helper for implementations 33 #include <cppuhelper/implbase1.hxx> // helper for implementations 34 #include <cppuhelper/interfacecontainer.h> 35 #include <tools/string.hxx> 36 #include <tools/stream.hxx> 37 38 #include "defs.hxx" 39 #include "linguistic/misc.hxx" 40 41 42 /////////////////////////////////////////////////////////////////////////// 43 44 #define DIC_MAX_ENTRIES 30000 45 46 sal_Int16 ReadDicVersion( SvStreamPtr &rpStream, sal_uInt16 &nLng, sal_Bool &bNeg ); 47 const String GetDicExtension(); 48 49 /////////////////////////////////////////////////////////////////////////// 50 51 class DictionaryNeo : 52 public ::cppu::WeakImplHelper2 53 < 54 ::com::sun::star::linguistic2::XDictionary, 55 ::com::sun::star::frame::XStorable 56 > 57 { 58 59 ::cppu::OInterfaceContainerHelper aDicEvtListeners; 60 ::com::sun::star::uno::Sequence< 61 ::com::sun::star::uno::Reference< 62 ::com::sun::star::linguistic2::XDictionaryEntry > > aEntries; 63 ::rtl::OUString aDicName; 64 ::rtl::OUString aMainURL; 65 ::com::sun::star::linguistic2::DictionaryType eDicType; 66 sal_Int16 nCount; 67 sal_Int16 nLanguage; 68 sal_Int16 nDicVersion; 69 sal_Bool bNeedEntries; 70 sal_Bool bIsModified; 71 sal_Bool bIsActive; 72 sal_Bool bIsReadonly; 73 74 // disallow copy-constructor and assignment-operator for now 75 DictionaryNeo(const DictionaryNeo &); 76 DictionaryNeo & operator = (const DictionaryNeo &); 77 78 void launchEvent(sal_Int16 nEvent, 79 ::com::sun::star::uno::Reference< 80 ::com::sun::star::linguistic2::XDictionaryEntry > xEntry); 81 82 sal_uLong loadEntries(const ::rtl::OUString &rMainURL); 83 sal_uLong saveEntries(const ::rtl::OUString &rMainURL); 84 int cmpDicEntry(const ::rtl::OUString &rWord1, 85 const ::rtl::OUString &rWord2, 86 sal_Bool bSimilarOnly = sal_False); 87 sal_Bool seekEntry(const ::rtl::OUString &rWord, sal_Int32 *pPos, 88 sal_Bool bSimilarOnly = sal_False); 89 sal_Bool isSorted(); 90 91 sal_Bool addEntry_Impl(const ::com::sun::star::uno::Reference< 92 ::com::sun::star::linguistic2::XDictionaryEntry > xDicEntry, 93 sal_Bool bIsLoadEntries = sal_False); 94 95 public: 96 DictionaryNeo(); 97 DictionaryNeo(const ::rtl::OUString &rName, sal_Int16 nLang, 98 ::com::sun::star::linguistic2::DictionaryType eType, 99 const ::rtl::OUString &rMainURL, 100 sal_Bool bWriteable ); 101 virtual ~DictionaryNeo(); 102 103 // XNamed 104 virtual ::rtl::OUString SAL_CALL 105 getName() 106 throw(::com::sun::star::uno::RuntimeException); 107 virtual void SAL_CALL 108 setName( const ::rtl::OUString& aName ) 109 throw(::com::sun::star::uno::RuntimeException); 110 111 // XDictionary 112 virtual ::com::sun::star::linguistic2::DictionaryType SAL_CALL 113 getDictionaryType() 114 throw(::com::sun::star::uno::RuntimeException); 115 virtual void SAL_CALL 116 setActive( sal_Bool bActivate ) 117 throw(::com::sun::star::uno::RuntimeException); 118 virtual sal_Bool SAL_CALL 119 isActive() 120 throw(::com::sun::star::uno::RuntimeException); 121 virtual sal_Int32 SAL_CALL 122 getCount() 123 throw(::com::sun::star::uno::RuntimeException); 124 virtual ::com::sun::star::lang::Locale SAL_CALL 125 getLocale() 126 throw(::com::sun::star::uno::RuntimeException); 127 virtual void SAL_CALL 128 setLocale( const ::com::sun::star::lang::Locale& aLocale ) 129 throw(::com::sun::star::uno::RuntimeException); 130 virtual ::com::sun::star::uno::Reference< 131 ::com::sun::star::linguistic2::XDictionaryEntry > SAL_CALL 132 getEntry( const ::rtl::OUString& aWord ) 133 throw(::com::sun::star::uno::RuntimeException); 134 virtual sal_Bool SAL_CALL 135 addEntry( const ::com::sun::star::uno::Reference< 136 ::com::sun::star::linguistic2::XDictionaryEntry >& xDicEntry ) 137 throw(::com::sun::star::uno::RuntimeException); 138 virtual sal_Bool SAL_CALL 139 add( const ::rtl::OUString& aWord, sal_Bool bIsNegative, 140 const ::rtl::OUString& aRplcText ) 141 throw(::com::sun::star::uno::RuntimeException); 142 virtual sal_Bool SAL_CALL 143 remove( const ::rtl::OUString& aWord ) 144 throw(::com::sun::star::uno::RuntimeException); 145 virtual sal_Bool SAL_CALL 146 isFull() 147 throw(::com::sun::star::uno::RuntimeException); 148 virtual ::com::sun::star::uno::Sequence< 149 ::com::sun::star::uno::Reference< 150 ::com::sun::star::linguistic2::XDictionaryEntry > > SAL_CALL 151 getEntries() 152 throw(::com::sun::star::uno::RuntimeException); 153 virtual void SAL_CALL 154 clear() 155 throw(::com::sun::star::uno::RuntimeException); 156 virtual sal_Bool SAL_CALL 157 addDictionaryEventListener( const ::com::sun::star::uno::Reference< 158 ::com::sun::star::linguistic2::XDictionaryEventListener >& xListener ) 159 throw(::com::sun::star::uno::RuntimeException); 160 virtual sal_Bool SAL_CALL 161 removeDictionaryEventListener( const ::com::sun::star::uno::Reference< 162 ::com::sun::star::linguistic2::XDictionaryEventListener >& xListener ) 163 throw(::com::sun::star::uno::RuntimeException); 164 165 // XStorable 166 virtual sal_Bool SAL_CALL 167 hasLocation() 168 throw(::com::sun::star::uno::RuntimeException); 169 virtual ::rtl::OUString SAL_CALL 170 getLocation() 171 throw(::com::sun::star::uno::RuntimeException); 172 virtual sal_Bool SAL_CALL 173 isReadonly() 174 throw(::com::sun::star::uno::RuntimeException); 175 virtual void SAL_CALL 176 store() 177 throw(::com::sun::star::io::IOException, 178 ::com::sun::star::uno::RuntimeException); 179 virtual void SAL_CALL 180 storeAsURL( const ::rtl::OUString& aURL, 181 const ::com::sun::star::uno::Sequence< 182 ::com::sun::star::beans::PropertyValue >& aArgs ) 183 throw(::com::sun::star::io::IOException, 184 ::com::sun::star::uno::RuntimeException); 185 virtual void SAL_CALL 186 storeToURL( const ::rtl::OUString& aURL, 187 const ::com::sun::star::uno::Sequence< 188 ::com::sun::star::beans::PropertyValue >& aArgs ) 189 throw(::com::sun::star::io::IOException, 190 ::com::sun::star::uno::RuntimeException); 191 }; 192 193 194 /////////////////////////////////////////////////////////////////////////// 195 196 class DicEntry : 197 public cppu::WeakImplHelper1 198 < 199 ::com::sun::star::linguistic2::XDictionaryEntry 200 > 201 { 202 ::rtl::OUString aDicWord, // including hyphen positions represented by "=" 203 aReplacement; // including hyphen positions represented by "=" 204 sal_Bool bIsNegativ; 205 206 // disallow copy-constructor and assignment-operator for now 207 DicEntry(const DicEntry &); 208 DicEntry & operator = (const DicEntry &); 209 210 void splitDicFileWord(const ::rtl::OUString &rDicFileWord, 211 ::rtl::OUString &rDicWord, 212 ::rtl::OUString &rReplacement); 213 214 public: 215 DicEntry(); 216 DicEntry(const ::rtl::OUString &rDicFileWord, sal_Bool bIsNegativ); 217 DicEntry(const ::rtl::OUString &rDicWord, sal_Bool bIsNegativ, 218 const ::rtl::OUString &rRplcText); 219 virtual ~DicEntry(); 220 221 // XDictionaryEntry 222 virtual ::rtl::OUString SAL_CALL 223 getDictionaryWord() throw(::com::sun::star::uno::RuntimeException); 224 virtual sal_Bool SAL_CALL 225 isNegative() throw(::com::sun::star::uno::RuntimeException); 226 virtual ::rtl::OUString SAL_CALL 227 getReplacementText() throw(::com::sun::star::uno::RuntimeException); 228 }; 229 230 231 /////////////////////////////////////////////////////////////////////////// 232 233 #endif 234 235