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