1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <i18npool/lang.h>
22 #include <tools/fsys.hxx>
23 #include <tools/stream.hxx>
24 #include <tools/string.hxx>
25 #include <osl/mutex.hxx>
26 #include <ucbhelper/content.hxx>
28 #include <cppuhelper/factory.hxx> // helper for factories
29 #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
30 #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
31 #include <com/sun/star/lang/Locale.hpp>
32 #include <com/sun/star/uno/Reference.h>
33 #include <com/sun/star/registry/XRegistryKey.hpp>
35 #include "hhconvdic.hxx"
36 #include "linguistic/misc.hxx"
41 using namespace com::sun::star
;
42 using namespace com::sun::star::lang
;
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::linguistic2
;
45 using namespace linguistic
;
47 using ::rtl::OUString
;
49 #define SN_HH_CONV_DICTIONARY "com.sun.star.linguistic2.HangulHanjaConversionDictionary"
52 #include <i18nutil/unicode.hxx>
53 #include <com/sun/star/i18n/UnicodeScript.hpp>
57 #define SCRIPT_OTHERS 0
58 #define SCRIPT_HANJA 1
59 #define SCRIPT_HANGUL 2
61 // from i18npool/source/textconversion/textconversion_ko.cxx
62 sal_Int16 SAL_CALL
checkScriptType(sal_Unicode c
) throw (RuntimeException
)
64 UErrorCode status
= U_ZERO_ERROR
;
66 UScriptCode scriptCode
= uscript_getScript(c
, &status
);
68 if ( !U_SUCCESS(status
) ) throw RuntimeException();
70 return scriptCode
== USCRIPT_HANGUL
? SCRIPT_HANGUL
:
71 scriptCode
== USCRIPT_HAN
? SCRIPT_HANJA
: SCRIPT_OTHERS
;
76 sal_Bool
TextIsAllScriptType( const OUString
&rTxt
, sal_Int16 nScriptType
)
78 sal_Bool bIsAll
= sal_True
;
79 for (sal_Int32 i
= 0; i
< rTxt
.getLength() && bIsAll
; ++i
)
81 if (checkScriptType( rTxt
.getStr()[i
]) != nScriptType
)
89 HHConvDic::HHConvDic( const String
&rName
, const String
&rMainURL
) :
90 ConvDic( rName
, LANGUAGE_KOREAN
, ConversionDictionaryType::HANGUL_HANJA
, sal_True
, rMainURL
)
95 HHConvDic::~HHConvDic()
100 void SAL_CALL
HHConvDic::addEntry(
101 const OUString
& aLeftText
,
102 const OUString
& aRightText
)
103 throw (IllegalArgumentException
, container::ElementExistException
, RuntimeException
)
105 MutexGuard
aGuard( GetLinguMutex() );
107 if ((aLeftText
.getLength() != aRightText
.getLength()) ||
108 !TextIsAllScriptType( aLeftText
, SCRIPT_HANGUL
) ||
109 !TextIsAllScriptType( aRightText
, SCRIPT_HANJA
))
110 throw IllegalArgumentException();
111 ConvDic::addEntry( aLeftText
, aRightText
);
115 OUString SAL_CALL
HHConvDic::getImplementationName( )
116 throw (RuntimeException
)
118 MutexGuard
aGuard( GetLinguMutex() );
119 return getImplementationName_Static();
123 sal_Bool SAL_CALL
HHConvDic::supportsService( const OUString
& rServiceName
)
124 throw (RuntimeException
)
126 MutexGuard
aGuard( GetLinguMutex() );
127 sal_Bool bRes
= sal_False
;
128 if ( rServiceName
== SN_CONV_DICTIONARY
|| rServiceName
== SN_HH_CONV_DICTIONARY
)
134 uno::Sequence
< OUString
> SAL_CALL
HHConvDic::getSupportedServiceNames( )
135 throw (RuntimeException
)
137 MutexGuard
aGuard( GetLinguMutex() );
138 return getSupportedServiceNames_Static();
142 uno::Sequence
< OUString
> HHConvDic::getSupportedServiceNames_Static()
145 uno::Sequence
< OUString
> aSNS( 2 );
146 aSNS
.getArray()[0] = A2OU( SN_CONV_DICTIONARY
);
147 aSNS
.getArray()[1] = A2OU( SN_HH_CONV_DICTIONARY
);
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */