bump product version to 5.0.4.1
[LibreOffice.git] / editeng / source / uno / UnoForbiddenCharsTable.cxx
blobb0f3904351314894e6bf1af90fc8ab599cb01bc4
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 <editeng/UnoForbiddenCharsTable.hxx>
21 #include <editeng/forbiddencharacterstable.hxx>
22 #include <osl/mutex.hxx>
23 #include <vcl/svapp.hxx>
24 #include <editeng/unolingu.hxx>
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::container;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::i18n;
31 using namespace ::cppu;
33 SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(::rtl::Reference<SvxForbiddenCharactersTable> xForbiddenChars) :
34 mxForbiddenChars( xForbiddenChars )
38 SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable()
42 void SvxUnoForbiddenCharsTable::onChange()
46 ForbiddenCharacters SvxUnoForbiddenCharsTable::getForbiddenCharacters( const lang::Locale& rLocale )
47 throw(NoSuchElementException, RuntimeException, std::exception)
49 SolarMutexGuard aGuard;
51 if(!mxForbiddenChars.is())
52 throw RuntimeException();
54 const LanguageType eLang = LanguageTag::convertToLanguageType( rLocale );
55 const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, false );
56 if(!pForbidden)
57 throw NoSuchElementException();
59 return *pForbidden;
62 sal_Bool SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const lang::Locale& rLocale )
63 throw(RuntimeException, std::exception)
65 SolarMutexGuard aGuard;
67 if(!mxForbiddenChars.is())
68 return sal_False;
70 const LanguageType eLang = LanguageTag::convertToLanguageType( rLocale );
71 const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, false );
73 return NULL != pForbidden;
76 void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const lang::Locale& rLocale, const ForbiddenCharacters& rForbiddenCharacters )
77 throw(RuntimeException, std::exception)
79 SolarMutexGuard aGuard;
81 if(!mxForbiddenChars.is())
82 throw RuntimeException();
84 const LanguageType eLang = LanguageTag::convertToLanguageType( rLocale );
85 mxForbiddenChars->SetForbiddenCharacters( eLang, rForbiddenCharacters );
87 onChange();
90 void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const lang::Locale& rLocale )
91 throw(RuntimeException, std::exception)
93 SolarMutexGuard aGuard;
95 if(!mxForbiddenChars.is())
96 throw RuntimeException();
98 const LanguageType eLang = LanguageTag::convertToLanguageType( rLocale );
99 mxForbiddenChars->ClearForbiddenCharacters( eLang );
101 onChange();
104 // XSupportedLocales
105 Sequence< lang::Locale > SAL_CALL SvxUnoForbiddenCharsTable::getLocales()
106 throw(RuntimeException, std::exception)
108 SolarMutexGuard aGuard;
110 const sal_Int32 nCount = mxForbiddenChars.is() ? mxForbiddenChars->GetMap().size() : 0;
112 Sequence< lang::Locale > aLocales( nCount );
113 if( nCount )
115 lang::Locale* pLocales = aLocales.getArray();
117 for( SvxForbiddenCharactersTable::Map::iterator it = mxForbiddenChars->GetMap().begin();
118 it != mxForbiddenChars->GetMap().end(); ++it )
120 const sal_uLong nLanguage = it->first;
121 *pLocales++ = LanguageTag( static_cast < LanguageType > (nLanguage) ).getLocale();
125 return aLocales;
128 sal_Bool SAL_CALL SvxUnoForbiddenCharsTable::hasLocale( const lang::Locale& aLocale )
129 throw(RuntimeException, std::exception)
131 SolarMutexGuard aGuard;
133 return hasForbiddenCharacters( aLocale );
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */