Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <unicode/uscript.h>
30 : : #include <i18npool/lang.h>
31 : : #include <tools/fsys.hxx>
32 : : #include <tools/stream.hxx>
33 : : #include <tools/string.hxx>
34 : : #include <osl/mutex.hxx>
35 : : #include <ucbhelper/content.hxx>
36 : :
37 : : #include <cppuhelper/factory.hxx> // helper for factories
38 : : #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
39 : : #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
40 : : #include <com/sun/star/lang/Locale.hpp>
41 : : #include <com/sun/star/uno/Reference.h>
42 : : #include <com/sun/star/registry/XRegistryKey.hpp>
43 : :
44 : : #include "hhconvdic.hxx"
45 : : #include "linguistic/misc.hxx"
46 : : #include "defs.hxx"
47 : :
48 : : using namespace utl;
49 : : using namespace osl;
50 : : using namespace com::sun::star;
51 : : using namespace com::sun::star::lang;
52 : : using namespace com::sun::star::uno;
53 : : using namespace com::sun::star::linguistic2;
54 : : using namespace linguistic;
55 : :
56 : : using ::rtl::OUString;
57 : :
58 : : #define SN_HH_CONV_DICTIONARY "com.sun.star.linguistic2.HangulHanjaConversionDictionary"
59 : :
60 : :
61 : : #include <i18nutil/unicode.hxx>
62 : : #include <com/sun/star/i18n/UnicodeScript.hpp>
63 : :
64 : : using namespace i18n;
65 : :
66 : : #define SCRIPT_OTHERS 0
67 : : #define SCRIPT_HANJA 1
68 : : #define SCRIPT_HANGUL 2
69 : :
70 : : // from i18npool/source/textconversion/textconversion_ko.cxx
71 : 0 : sal_Int16 SAL_CALL checkScriptType(sal_Unicode c) throw (RuntimeException)
72 : : {
73 : 0 : UErrorCode status = U_ZERO_ERROR;
74 : :
75 [ # # ]: 0 : UScriptCode scriptCode = uscript_getScript(c, &status);
76 : :
77 [ # # ][ # # ]: 0 : if ( !U_SUCCESS(status) ) throw RuntimeException();
78 : :
79 : : return scriptCode == USCRIPT_HANGUL ? SCRIPT_HANGUL :
80 [ # # ][ # # ]: 0 : scriptCode == USCRIPT_HAN ? SCRIPT_HANJA : SCRIPT_OTHERS;
81 : : }
82 : :
83 : :
84 : :
85 : 0 : sal_Bool TextIsAllScriptType( const OUString &rTxt, sal_Int16 nScriptType )
86 : : {
87 : 0 : sal_Bool bIsAll = sal_True;
88 [ # # ][ # # ]: 0 : for (sal_Int32 i = 0; i < rTxt.getLength() && bIsAll; ++i)
[ # # ]
89 : : {
90 [ # # ]: 0 : if (checkScriptType( rTxt.getStr()[i]) != nScriptType)
91 : 0 : bIsAll = sal_False;
92 : : }
93 : 0 : return bIsAll;
94 : : }
95 : :
96 : :
97 : :
98 : 0 : HHConvDic::HHConvDic( const String &rName, const String &rMainURL ) :
99 : 0 : ConvDic( rName, LANGUAGE_KOREAN, ConversionDictionaryType::HANGUL_HANJA, sal_True, rMainURL )
100 : : {
101 : 0 : }
102 : :
103 : :
104 : 0 : HHConvDic::~HHConvDic()
105 : : {
106 [ # # ]: 0 : }
107 : :
108 : :
109 : 0 : void SAL_CALL HHConvDic::addEntry(
110 : : const OUString& aLeftText,
111 : : const OUString& aRightText )
112 : : throw (IllegalArgumentException, container::ElementExistException, RuntimeException)
113 : : {
114 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
115 : :
116 [ # # ][ # # ]: 0 : if ((aLeftText.getLength() != aRightText.getLength()) ||
[ # # ][ # # ]
117 [ # # ]: 0 : !TextIsAllScriptType( aLeftText, SCRIPT_HANGUL ) ||
118 [ # # ]: 0 : !TextIsAllScriptType( aRightText, SCRIPT_HANJA ))
119 [ # # ]: 0 : throw IllegalArgumentException();
120 [ # # ][ # # ]: 0 : ConvDic::addEntry( aLeftText, aRightText );
121 : 0 : }
122 : :
123 : :
124 : 0 : OUString SAL_CALL HHConvDic::getImplementationName( )
125 : : throw (RuntimeException)
126 : : {
127 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
128 [ # # ]: 0 : return getImplementationName_Static();
129 : : }
130 : :
131 : :
132 : 0 : sal_Bool SAL_CALL HHConvDic::supportsService( const OUString& rServiceName )
133 : : throw (RuntimeException)
134 : : {
135 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
136 : 0 : sal_Bool bRes = sal_False;
137 [ # # ][ # # ]: 0 : if ( rServiceName == SN_CONV_DICTIONARY || rServiceName == SN_HH_CONV_DICTIONARY )
[ # # ]
138 : 0 : bRes = sal_True;
139 [ # # ]: 0 : return bRes;
140 : : }
141 : :
142 : :
143 : 0 : uno::Sequence< OUString > SAL_CALL HHConvDic::getSupportedServiceNames( )
144 : : throw (RuntimeException)
145 : : {
146 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetLinguMutex() );
147 [ # # ]: 0 : return getSupportedServiceNames_Static();
148 : : }
149 : :
150 : :
151 : 0 : uno::Sequence< OUString > HHConvDic::getSupportedServiceNames_Static()
152 : : throw()
153 : : {
154 : 0 : uno::Sequence< OUString > aSNS( 2 );
155 [ # # ][ # # ]: 0 : aSNS.getArray()[0] = A2OU( SN_CONV_DICTIONARY );
156 [ # # ][ # # ]: 0 : aSNS.getArray()[1] = A2OU( SN_HH_CONV_DICTIONARY );
157 : 0 : return aSNS;
158 : : }
159 : :
160 : :
161 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|