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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_linguistic.hxx" 30 #include <unicode/uscript.h> 31 #include <i18npool/lang.h> 32 #include <tools/urlobj.hxx> 33 #include <tools/debug.hxx> 34 #include <tools/fsys.hxx> 35 #include <tools/stream.hxx> 36 #include <tools/string.hxx> 37 #include <osl/mutex.hxx> 38 #include <unotools/processfactory.hxx> 39 #include <ucbhelper/content.hxx> 40 41 #include <cppuhelper/factory.hxx> // helper for factories 42 #include <com/sun/star/linguistic2/XConversionDictionary.hpp> 43 #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp> 44 #include <com/sun/star/lang/Locale.hpp> 45 #ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_ 46 #include <com/sun/star/uno/Reference.h> 47 #endif 48 #include <com/sun/star/registry/XRegistryKey.hpp> 49 50 #include "hhconvdic.hxx" 51 #include "linguistic/misc.hxx" 52 #include "defs.hxx" 53 54 using namespace utl; 55 using namespace osl; 56 using namespace rtl; 57 using namespace com::sun::star; 58 using namespace com::sun::star::lang; 59 using namespace com::sun::star::uno; 60 using namespace com::sun::star::linguistic2; 61 using namespace linguistic; 62 63 #define SN_HH_CONV_DICTIONARY "com.sun.star.linguistic2.HangulHanjaConversionDictionary" 64 65 /////////////////////////////////////////////////////////////////////////// 66 67 #include <i18nutil/unicode.hxx> 68 #include <com/sun/star/i18n/UnicodeScript.hpp> 69 70 using namespace i18n; 71 72 #define SCRIPT_OTHERS 0 73 #define SCRIPT_HANJA 1 74 #define SCRIPT_HANGUL 2 75 76 // from i18npool/source/textconversion/textconversion_ko.cxx 77 sal_Int16 SAL_CALL checkScriptType(sal_Unicode c) throw (RuntimeException) 78 { 79 UErrorCode status = U_ZERO_ERROR; 80 81 UScriptCode scriptCode = uscript_getScript(c, &status); 82 83 if ( !U_SUCCESS(status) ) throw RuntimeException(); 84 85 return scriptCode == USCRIPT_HANGUL ? SCRIPT_HANGUL : 86 scriptCode == USCRIPT_HAN ? SCRIPT_HANJA : SCRIPT_OTHERS; 87 } 88 89 90 91 sal_Bool TextIsAllScriptType( const OUString &rTxt, sal_Int16 nScriptType ) 92 { 93 sal_Bool bIsAll = sal_True; 94 for (sal_Int32 i = 0; i < rTxt.getLength() && bIsAll; ++i) 95 { 96 if (checkScriptType( rTxt.getStr()[i]) != nScriptType) 97 bIsAll = sal_False; 98 } 99 return bIsAll; 100 } 101 102 103 /////////////////////////////////////////////////////////////////////////// 104 105 HHConvDic::HHConvDic( const String &rName, const String &rMainURL ) : 106 ConvDic( rName, LANGUAGE_KOREAN, ConversionDictionaryType::HANGUL_HANJA, sal_True, rMainURL ) 107 { 108 } 109 110 111 HHConvDic::~HHConvDic() 112 { 113 } 114 115 116 void SAL_CALL HHConvDic::addEntry( 117 const OUString& aLeftText, 118 const OUString& aRightText ) 119 throw (IllegalArgumentException, container::ElementExistException, RuntimeException) 120 { 121 MutexGuard aGuard( GetLinguMutex() ); 122 123 if ((aLeftText.getLength() != aRightText.getLength()) || 124 !TextIsAllScriptType( aLeftText, SCRIPT_HANGUL ) || 125 !TextIsAllScriptType( aRightText, SCRIPT_HANJA )) 126 throw IllegalArgumentException(); 127 ConvDic::addEntry( aLeftText, aRightText ); 128 } 129 130 131 OUString SAL_CALL HHConvDic::getImplementationName( ) 132 throw (RuntimeException) 133 { 134 MutexGuard aGuard( GetLinguMutex() ); 135 return getImplementationName_Static(); 136 } 137 138 139 sal_Bool SAL_CALL HHConvDic::supportsService( const OUString& rServiceName ) 140 throw (RuntimeException) 141 { 142 MutexGuard aGuard( GetLinguMutex() ); 143 sal_Bool bRes = sal_False; 144 if (rServiceName.equalsAscii( SN_CONV_DICTIONARY )|| 145 rServiceName.equalsAscii( SN_HH_CONV_DICTIONARY )) 146 bRes = sal_True; 147 return bRes; 148 } 149 150 151 uno::Sequence< OUString > SAL_CALL HHConvDic::getSupportedServiceNames( ) 152 throw (RuntimeException) 153 { 154 MutexGuard aGuard( GetLinguMutex() ); 155 return getSupportedServiceNames_Static(); 156 } 157 158 159 uno::Sequence< OUString > HHConvDic::getSupportedServiceNames_Static() 160 throw() 161 { 162 uno::Sequence< OUString > aSNS( 2 ); 163 aSNS.getArray()[0] = A2OU( SN_CONV_DICTIONARY ); 164 aSNS.getArray()[1] = A2OU( SN_HH_CONV_DICTIONARY ); 165 return aSNS; 166 } 167 168 /////////////////////////////////////////////////////////////////////////// 169 170