Update ooo320-m1
[ooovba.git] / linguistic / source / hhconvdic.cxx
blobabd8879dbc62c260e48eeb2be092999dca000eb5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hhconvdic.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_linguistic.hxx"
33 #include <unicode/uscript.h>
34 #include <i18npool/lang.h>
35 #include <tools/urlobj.hxx>
36 #include <tools/debug.hxx>
37 #include <tools/fsys.hxx>
38 #include <tools/stream.hxx>
39 #include <tools/string.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <osl/mutex.hxx>
42 #include <unotools/processfactory.hxx>
43 #include <ucbhelper/content.hxx>
45 #include <cppuhelper/factory.hxx> // helper for factories
46 #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
47 #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
48 #include <com/sun/star/lang/Locale.hpp>
49 #ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
50 #include <com/sun/star/uno/Reference.h>
51 #endif
52 #include <com/sun/star/registry/XRegistryKey.hpp>
54 #include "hhconvdic.hxx"
55 #include "misc.hxx"
56 #include "defs.hxx"
58 using namespace utl;
59 using namespace osl;
60 using namespace rtl;
61 using namespace com::sun::star;
62 using namespace com::sun::star::lang;
63 using namespace com::sun::star::uno;
64 using namespace com::sun::star::linguistic2;
65 using namespace linguistic;
67 #define SN_HH_CONV_DICTIONARY "com.sun.star.linguistic2.HangulHanjaConversionDictionary"
69 ///////////////////////////////////////////////////////////////////////////
71 #include <i18nutil/unicode.hxx>
72 #include <com/sun/star/i18n/UnicodeScript.hpp>
74 using namespace i18n;
76 #define SCRIPT_OTHERS 0
77 #define SCRIPT_HANJA 1
78 #define SCRIPT_HANGUL 2
80 // from i18npool/source/textconversion/textconversion_ko.cxx
81 sal_Int16 SAL_CALL checkScriptType(sal_Unicode c) throw (RuntimeException)
83 UErrorCode status = U_ZERO_ERROR;
85 UScriptCode scriptCode = uscript_getScript(c, &status);
87 if ( !U_SUCCESS(status) ) throw RuntimeException();
89 return scriptCode == USCRIPT_HANGUL ? SCRIPT_HANGUL :
90 scriptCode == USCRIPT_HAN ? SCRIPT_HANJA : SCRIPT_OTHERS;
95 BOOL TextIsAllScriptType( const OUString &rTxt, INT16 nScriptType )
97 BOOL bIsAll = TRUE;
98 for (INT32 i = 0; i < rTxt.getLength() && bIsAll; ++i)
100 if (checkScriptType( rTxt.getStr()[i]) != nScriptType)
101 bIsAll = FALSE;
103 return bIsAll;
107 ///////////////////////////////////////////////////////////////////////////
109 HHConvDic::HHConvDic( const String &rName, const String &rMainURL ) :
110 ConvDic( rName, LANGUAGE_KOREAN, ConversionDictionaryType::HANGUL_HANJA, TRUE, rMainURL )
115 HHConvDic::~HHConvDic()
120 void SAL_CALL HHConvDic::addEntry(
121 const OUString& aLeftText,
122 const OUString& aRightText )
123 throw (IllegalArgumentException, container::ElementExistException, RuntimeException)
125 MutexGuard aGuard( GetLinguMutex() );
127 if ((aLeftText.getLength() != aRightText.getLength()) ||
128 !TextIsAllScriptType( aLeftText, SCRIPT_HANGUL ) ||
129 !TextIsAllScriptType( aRightText, SCRIPT_HANJA ))
130 throw IllegalArgumentException();
131 ConvDic::addEntry( aLeftText, aRightText );
135 OUString SAL_CALL HHConvDic::getImplementationName( )
136 throw (RuntimeException)
138 MutexGuard aGuard( GetLinguMutex() );
139 return getImplementationName_Static();
143 sal_Bool SAL_CALL HHConvDic::supportsService( const OUString& rServiceName )
144 throw (RuntimeException)
146 MutexGuard aGuard( GetLinguMutex() );
147 sal_Bool bRes = sal_False;
148 if (rServiceName.equalsAscii( SN_CONV_DICTIONARY )||
149 rServiceName.equalsAscii( SN_HH_CONV_DICTIONARY ))
150 bRes = sal_True;
151 return bRes;
155 uno::Sequence< OUString > SAL_CALL HHConvDic::getSupportedServiceNames( )
156 throw (RuntimeException)
158 MutexGuard aGuard( GetLinguMutex() );
159 return getSupportedServiceNames_Static();
163 uno::Sequence< OUString > HHConvDic::getSupportedServiceNames_Static()
164 throw()
166 uno::Sequence< OUString > aSNS( 2 );
167 aSNS.getArray()[0] = A2OU( SN_CONV_DICTIONARY );
168 aSNS.getArray()[1] = A2OU( SN_HH_CONV_DICTIONARY );
169 return aSNS;
172 ///////////////////////////////////////////////////////////////////////////