1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 #include <editeng/UnoForbiddenCharsTable.hxx>
27 #include <editeng/forbiddencharacterstable.hxx>
28 #include <vos/mutex.hxx>
29 #include <vcl/svapp.hxx>
30 #include <editeng/unolingu.hxx> // LocalToLanguage, LanguageToLocale
31 
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::i18n;
37 using namespace ::rtl;
38 using namespace ::vos;
39 using namespace ::cppu;
40 
SvxUnoForbiddenCharsTable(ORef<SvxForbiddenCharactersTable> xForbiddenChars)41 SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(ORef<SvxForbiddenCharactersTable> xForbiddenChars) :
42 	mxForbiddenChars( xForbiddenChars )
43 {
44 }
45 
~SvxUnoForbiddenCharsTable()46 SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable()
47 {
48 }
49 
onChange()50 void SvxUnoForbiddenCharsTable::onChange()
51 {
52 }
53 
getForbiddenCharacters(const Locale & rLocale)54 ForbiddenCharacters SvxUnoForbiddenCharsTable::getForbiddenCharacters( const Locale& rLocale )
55 	throw(NoSuchElementException, RuntimeException)
56 {
57 	OGuard aGuard( Application::GetSolarMutex() );
58 
59 	if(!mxForbiddenChars.isValid())
60 		throw RuntimeException();
61 
62 	const LanguageType eLang = SvxLocaleToLanguage( rLocale );
63 	const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False );
64 	if(!pForbidden)
65 		throw NoSuchElementException();
66 
67 	return *pForbidden;
68 }
69 
hasForbiddenCharacters(const Locale & rLocale)70 sal_Bool SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const Locale& rLocale )
71 	throw(RuntimeException)
72 {
73 	OGuard aGuard( Application::GetSolarMutex() );
74 
75 	if(!mxForbiddenChars.isValid())
76 		return sal_False;
77 
78 	const LanguageType eLang = SvxLocaleToLanguage( rLocale );
79 	const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False );
80 
81 	return NULL != pForbidden;
82 }
83 
setForbiddenCharacters(const Locale & rLocale,const ForbiddenCharacters & rForbiddenCharacters)84 void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const Locale& rLocale, const ForbiddenCharacters& rForbiddenCharacters )
85 	throw(RuntimeException)
86 {
87 	OGuard aGuard( Application::GetSolarMutex() );
88 
89 	if(!mxForbiddenChars.isValid())
90 		throw RuntimeException();
91 
92 	const LanguageType eLang = SvxLocaleToLanguage( rLocale );
93 	mxForbiddenChars->SetForbiddenCharacters( eLang, rForbiddenCharacters );
94 
95 	onChange();
96 }
97 
removeForbiddenCharacters(const Locale & rLocale)98 void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const Locale& rLocale )
99 	throw(RuntimeException)
100 {
101 	OGuard aGuard( Application::GetSolarMutex() );
102 
103 	if(!mxForbiddenChars.isValid())
104 		throw RuntimeException();
105 
106 	const LanguageType eLang = SvxLocaleToLanguage( rLocale );
107 	mxForbiddenChars->ClearForbiddenCharacters( eLang );
108 
109 	onChange();
110 }
111 
112 // XSupportedLocales
getLocales()113 Sequence< Locale > SAL_CALL SvxUnoForbiddenCharsTable::getLocales()
114 	throw(RuntimeException)
115 {
116 	OGuard aGuard( Application::GetSolarMutex() );
117 
118 	const sal_Int32 nCount = mxForbiddenChars.isValid() ? mxForbiddenChars->Count() : 0;
119 
120 	Sequence< Locale > aLocales( nCount );
121 	if( nCount )
122 	{
123 		Locale* pLocales = aLocales.getArray();
124 
125 		for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
126 		{
127 			const sal_uLong nLanguage = mxForbiddenChars->GetObjectKey( nIndex );
128 			SvxLanguageToLocale ( *pLocales++, static_cast < LanguageType > (nLanguage) );
129 		}
130 	}
131 
132 	return aLocales;
133 }
134 
hasLocale(const Locale & aLocale)135 sal_Bool SAL_CALL SvxUnoForbiddenCharsTable::hasLocale( const Locale& aLocale )
136 	throw(RuntimeException)
137 {
138 	OGuard aGuard( Application::GetSolarMutex() );
139 
140 	return hasForbiddenCharacters( aLocale );
141 }
142