xref: /aoo41x/main/linguistic/source/hhconvdic.cxx (revision 3b8558fd)
1*3b8558fdSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3b8558fdSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3b8558fdSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3b8558fdSAndrew Rist  * distributed with this work for additional information
6*3b8558fdSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3b8558fdSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3b8558fdSAndrew Rist  * "License"); you may not use this file except in compliance
9*3b8558fdSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3b8558fdSAndrew Rist  *
11*3b8558fdSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3b8558fdSAndrew Rist  *
13*3b8558fdSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3b8558fdSAndrew Rist  * software distributed under the License is distributed on an
15*3b8558fdSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3b8558fdSAndrew Rist  * KIND, either express or implied.  See the License for the
17*3b8558fdSAndrew Rist  * specific language governing permissions and limitations
18*3b8558fdSAndrew Rist  * under the License.
19*3b8558fdSAndrew Rist  *
20*3b8558fdSAndrew Rist  *************************************************************/
21*3b8558fdSAndrew Rist 
22*3b8558fdSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_linguistic.hxx"
26cdf0e10cSrcweir #include <unicode/uscript.h>
27cdf0e10cSrcweir #include <i18npool/lang.h>
28cdf0e10cSrcweir #include <tools/urlobj.hxx>
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir #include <tools/fsys.hxx>
31cdf0e10cSrcweir #include <tools/stream.hxx>
32cdf0e10cSrcweir #include <tools/string.hxx>
33cdf0e10cSrcweir #include <osl/mutex.hxx>
34cdf0e10cSrcweir #include <unotools/processfactory.hxx>
35cdf0e10cSrcweir #include <ucbhelper/content.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <cppuhelper/factory.hxx>   // helper for factories
38cdf0e10cSrcweir #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
39cdf0e10cSrcweir #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
40cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
41cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
42cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include "hhconvdic.hxx"
47cdf0e10cSrcweir #include "linguistic/misc.hxx"
48cdf0e10cSrcweir #include "defs.hxx"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using namespace utl;
51cdf0e10cSrcweir using namespace osl;
52cdf0e10cSrcweir using namespace rtl;
53cdf0e10cSrcweir using namespace com::sun::star;
54cdf0e10cSrcweir using namespace com::sun::star::lang;
55cdf0e10cSrcweir using namespace com::sun::star::uno;
56cdf0e10cSrcweir using namespace com::sun::star::linguistic2;
57cdf0e10cSrcweir using namespace linguistic;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #define SN_HH_CONV_DICTIONARY   "com.sun.star.linguistic2.HangulHanjaConversionDictionary"
60cdf0e10cSrcweir 
61cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #include <i18nutil/unicode.hxx>
64cdf0e10cSrcweir #include <com/sun/star/i18n/UnicodeScript.hpp>
65cdf0e10cSrcweir 
66cdf0e10cSrcweir using namespace i18n;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #define SCRIPT_OTHERS   0
69cdf0e10cSrcweir #define SCRIPT_HANJA    1
70cdf0e10cSrcweir #define SCRIPT_HANGUL   2
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // from i18npool/source/textconversion/textconversion_ko.cxx
checkScriptType(sal_Unicode c)73cdf0e10cSrcweir sal_Int16 SAL_CALL checkScriptType(sal_Unicode c) throw (RuntimeException)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir   UErrorCode status = U_ZERO_ERROR;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir   UScriptCode scriptCode = uscript_getScript(c, &status);
78cdf0e10cSrcweir 
79cdf0e10cSrcweir   if ( !U_SUCCESS(status) ) throw RuntimeException();
80cdf0e10cSrcweir 
81cdf0e10cSrcweir   return scriptCode == USCRIPT_HANGUL ? SCRIPT_HANGUL :
82cdf0e10cSrcweir             scriptCode == USCRIPT_HAN ? SCRIPT_HANJA : SCRIPT_OTHERS;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 
TextIsAllScriptType(const OUString & rTxt,sal_Int16 nScriptType)87cdf0e10cSrcweir sal_Bool TextIsAllScriptType( const OUString &rTxt, sal_Int16 nScriptType )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     sal_Bool bIsAll = sal_True;
90cdf0e10cSrcweir     for (sal_Int32 i = 0;  i < rTxt.getLength() && bIsAll;  ++i)
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         if (checkScriptType( rTxt.getStr()[i]) != nScriptType)
93cdf0e10cSrcweir             bIsAll = sal_False;
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir     return bIsAll;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
99cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
100cdf0e10cSrcweir 
HHConvDic(const String & rName,const String & rMainURL)101cdf0e10cSrcweir HHConvDic::HHConvDic( const String &rName, const String &rMainURL ) :
102cdf0e10cSrcweir     ConvDic( rName, LANGUAGE_KOREAN, ConversionDictionaryType::HANGUL_HANJA, sal_True, rMainURL )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
~HHConvDic()107cdf0e10cSrcweir HHConvDic::~HHConvDic()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
addEntry(const OUString & aLeftText,const OUString & aRightText)112cdf0e10cSrcweir void SAL_CALL HHConvDic::addEntry(
113cdf0e10cSrcweir         const OUString& aLeftText,
114cdf0e10cSrcweir         const OUString& aRightText )
115cdf0e10cSrcweir     throw (IllegalArgumentException, container::ElementExistException, RuntimeException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     if ((aLeftText.getLength() != aRightText.getLength()) ||
120cdf0e10cSrcweir         !TextIsAllScriptType( aLeftText,  SCRIPT_HANGUL ) ||
121cdf0e10cSrcweir         !TextIsAllScriptType( aRightText, SCRIPT_HANJA ))
122cdf0e10cSrcweir         throw IllegalArgumentException();
123cdf0e10cSrcweir     ConvDic::addEntry( aLeftText, aRightText );
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
getImplementationName()127cdf0e10cSrcweir OUString SAL_CALL HHConvDic::getImplementationName(  )
128cdf0e10cSrcweir     throw (RuntimeException)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
131cdf0e10cSrcweir     return getImplementationName_Static();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
supportsService(const OUString & rServiceName)135cdf0e10cSrcweir sal_Bool SAL_CALL HHConvDic::supportsService( const OUString& rServiceName )
136cdf0e10cSrcweir     throw (RuntimeException)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
139cdf0e10cSrcweir     sal_Bool bRes = sal_False;
140cdf0e10cSrcweir     if (rServiceName.equalsAscii( SN_CONV_DICTIONARY )||
141cdf0e10cSrcweir         rServiceName.equalsAscii( SN_HH_CONV_DICTIONARY ))
142cdf0e10cSrcweir         bRes = sal_True;
143cdf0e10cSrcweir     return bRes;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
getSupportedServiceNames()147cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL HHConvDic::getSupportedServiceNames(  )
148cdf0e10cSrcweir     throw (RuntimeException)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
151cdf0e10cSrcweir     return getSupportedServiceNames_Static();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 
getSupportedServiceNames_Static()155cdf0e10cSrcweir uno::Sequence< OUString > HHConvDic::getSupportedServiceNames_Static()
156cdf0e10cSrcweir     throw()
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     uno::Sequence< OUString > aSNS( 2 );
159cdf0e10cSrcweir     aSNS.getArray()[0] = A2OU( SN_CONV_DICTIONARY );
160cdf0e10cSrcweir     aSNS.getArray()[1] = A2OU( SN_HH_CONV_DICTIONARY );
161cdf0e10cSrcweir     return aSNS;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
165cdf0e10cSrcweir 
166