bump product version to 5.0.4.1
[LibreOffice.git] / linguistic / source / hhconvdic.cxx
blob75125c9b48be272b244f7b5ca0d3ecbde195e798
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <unicode/uscript.h>
21 #include <i18nlangtag/lang.h>
22 #include <tools/stream.hxx>
23 #include <osl/mutex.hxx>
24 #include <ucbhelper/content.hxx>
26 #include <cppuhelper/factory.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
29 #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
30 #include <com/sun/star/lang/Locale.hpp>
31 #include <com/sun/star/uno/Reference.h>
32 #include <com/sun/star/registry/XRegistryKey.hpp>
34 #include "hhconvdic.hxx"
35 #include "linguistic/misc.hxx"
36 #include "defs.hxx"
38 using namespace utl;
39 using namespace osl;
40 using namespace com::sun::star;
41 using namespace com::sun::star::lang;
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::linguistic2;
44 using namespace linguistic;
47 #define SN_HH_CONV_DICTIONARY "com.sun.star.linguistic2.HangulHanjaConversionDictionary"
50 #include <i18nutil/unicode.hxx>
51 #include <com/sun/star/i18n/UnicodeScript.hpp>
53 using namespace i18n;
55 #define SCRIPT_OTHERS 0
56 #define SCRIPT_HANJA 1
57 #define SCRIPT_HANGUL 2
59 // from i18npool/source/textconversion/textconversion_ko.cxx
60 sal_Int16 SAL_CALL checkScriptType(sal_Unicode c) throw (RuntimeException)
62 UErrorCode status = U_ZERO_ERROR;
64 UScriptCode scriptCode = uscript_getScript(c, &status);
66 if ( !U_SUCCESS(status) ) throw RuntimeException();
68 return scriptCode == USCRIPT_HANGUL ? SCRIPT_HANGUL :
69 scriptCode == USCRIPT_HAN ? SCRIPT_HANJA : SCRIPT_OTHERS;
74 bool TextIsAllScriptType( const OUString &rTxt, sal_Int16 nScriptType )
76 bool bIsAll = true;
77 for (sal_Int32 i = 0; i < rTxt.getLength() && bIsAll; ++i)
79 if (checkScriptType( rTxt[i]) != nScriptType)
80 bIsAll = false;
82 return bIsAll;
87 HHConvDic::HHConvDic( const OUString &rName, const OUString &rMainURL ) :
88 ConvDic( rName, LANGUAGE_KOREAN, ConversionDictionaryType::HANGUL_HANJA, true, rMainURL )
93 HHConvDic::~HHConvDic()
98 void SAL_CALL HHConvDic::addEntry(
99 const OUString& aLeftText,
100 const OUString& aRightText )
101 throw (IllegalArgumentException, container::ElementExistException, RuntimeException, std::exception)
103 MutexGuard aGuard( GetLinguMutex() );
105 if ((aLeftText.getLength() != aRightText.getLength()) ||
106 !TextIsAllScriptType( aLeftText, SCRIPT_HANGUL ) ||
107 !TextIsAllScriptType( aRightText, SCRIPT_HANJA ))
108 throw IllegalArgumentException();
109 ConvDic::addEntry( aLeftText, aRightText );
113 OUString SAL_CALL HHConvDic::getImplementationName( )
114 throw (RuntimeException, std::exception)
116 MutexGuard aGuard( GetLinguMutex() );
117 return getImplementationName_Static();
121 sal_Bool SAL_CALL HHConvDic::supportsService( const OUString& rServiceName )
122 throw (RuntimeException, std::exception)
124 return cppu::supportsService(this, rServiceName);
128 uno::Sequence< OUString > SAL_CALL HHConvDic::getSupportedServiceNames( )
129 throw (RuntimeException, std::exception)
131 MutexGuard aGuard( GetLinguMutex() );
132 return getSupportedServiceNames_Static();
136 uno::Sequence< OUString > HHConvDic::getSupportedServiceNames_Static()
137 throw()
139 uno::Sequence< OUString > aSNS( 2 );
140 aSNS.getArray()[0] = SN_CONV_DICTIONARY;
141 aSNS.getArray()[1] = SN_HH_CONV_DICTIONARY;
142 return aSNS;
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */