Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <unicode/uscript.h>
21 : #include <i18nlangtag/lang.h>
22 : #include <tools/stream.hxx>
23 : #include <tools/string.hxx>
24 : #include <osl/mutex.hxx>
25 : #include <ucbhelper/content.hxx>
26 :
27 : #include <cppuhelper/factory.hxx> // helper for factories
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>
33 :
34 : #include "hhconvdic.hxx"
35 : #include "linguistic/misc.hxx"
36 : #include "defs.hxx"
37 :
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;
45 :
46 :
47 : #define SN_HH_CONV_DICTIONARY "com.sun.star.linguistic2.HangulHanjaConversionDictionary"
48 :
49 :
50 : #include <i18nutil/unicode.hxx>
51 : #include <com/sun/star/i18n/UnicodeScript.hpp>
52 :
53 : using namespace i18n;
54 :
55 : #define SCRIPT_OTHERS 0
56 : #define SCRIPT_HANJA 1
57 : #define SCRIPT_HANGUL 2
58 :
59 : // from i18npool/source/textconversion/textconversion_ko.cxx
60 0 : sal_Int16 SAL_CALL checkScriptType(sal_Unicode c) throw (RuntimeException)
61 : {
62 0 : UErrorCode status = U_ZERO_ERROR;
63 :
64 0 : UScriptCode scriptCode = uscript_getScript(c, &status);
65 :
66 0 : if ( !U_SUCCESS(status) ) throw RuntimeException();
67 :
68 : return scriptCode == USCRIPT_HANGUL ? SCRIPT_HANGUL :
69 0 : scriptCode == USCRIPT_HAN ? SCRIPT_HANJA : SCRIPT_OTHERS;
70 : }
71 :
72 :
73 :
74 0 : sal_Bool TextIsAllScriptType( const OUString &rTxt, sal_Int16 nScriptType )
75 : {
76 0 : sal_Bool bIsAll = sal_True;
77 0 : for (sal_Int32 i = 0; i < rTxt.getLength() && bIsAll; ++i)
78 : {
79 0 : if (checkScriptType( rTxt.getStr()[i]) != nScriptType)
80 0 : bIsAll = sal_False;
81 : }
82 0 : return bIsAll;
83 : }
84 :
85 :
86 :
87 0 : HHConvDic::HHConvDic( const String &rName, const String &rMainURL ) :
88 0 : ConvDic( rName, LANGUAGE_KOREAN, ConversionDictionaryType::HANGUL_HANJA, sal_True, rMainURL )
89 : {
90 0 : }
91 :
92 :
93 0 : HHConvDic::~HHConvDic()
94 : {
95 0 : }
96 :
97 :
98 0 : void SAL_CALL HHConvDic::addEntry(
99 : const OUString& aLeftText,
100 : const OUString& aRightText )
101 : throw (IllegalArgumentException, container::ElementExistException, RuntimeException)
102 : {
103 0 : MutexGuard aGuard( GetLinguMutex() );
104 :
105 0 : if ((aLeftText.getLength() != aRightText.getLength()) ||
106 0 : !TextIsAllScriptType( aLeftText, SCRIPT_HANGUL ) ||
107 0 : !TextIsAllScriptType( aRightText, SCRIPT_HANJA ))
108 0 : throw IllegalArgumentException();
109 0 : ConvDic::addEntry( aLeftText, aRightText );
110 0 : }
111 :
112 :
113 0 : OUString SAL_CALL HHConvDic::getImplementationName( )
114 : throw (RuntimeException)
115 : {
116 0 : MutexGuard aGuard( GetLinguMutex() );
117 0 : return getImplementationName_Static();
118 : }
119 :
120 :
121 0 : sal_Bool SAL_CALL HHConvDic::supportsService( const OUString& rServiceName )
122 : throw (RuntimeException)
123 : {
124 0 : MutexGuard aGuard( GetLinguMutex() );
125 0 : sal_Bool bRes = sal_False;
126 0 : if ( rServiceName == SN_CONV_DICTIONARY || rServiceName == SN_HH_CONV_DICTIONARY )
127 0 : bRes = sal_True;
128 0 : return bRes;
129 : }
130 :
131 :
132 0 : uno::Sequence< OUString > SAL_CALL HHConvDic::getSupportedServiceNames( )
133 : throw (RuntimeException)
134 : {
135 0 : MutexGuard aGuard( GetLinguMutex() );
136 0 : return getSupportedServiceNames_Static();
137 : }
138 :
139 :
140 0 : uno::Sequence< OUString > HHConvDic::getSupportedServiceNames_Static()
141 : throw()
142 : {
143 0 : uno::Sequence< OUString > aSNS( 2 );
144 0 : aSNS.getArray()[0] = SN_CONV_DICTIONARY;
145 0 : aSNS.getArray()[1] = SN_HH_CONV_DICTIONARY;
146 0 : return aSNS;
147 : }
148 :
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|