1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoForbiddenCharsTable.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include "UnoForbiddenCharsTable.hxx"
34 #include "forbiddencharacterstable.hxx"
35 #include <vos/mutex.hxx>
36 #include <vcl/svapp.hxx>
37 #include "unolingu.hxx"
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::container
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::i18n
;
44 using namespace ::rtl
;
45 using namespace ::vos
;
46 using namespace ::cppu
;
48 SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(ORef
<SvxForbiddenCharactersTable
> xForbiddenChars
) :
49 mxForbiddenChars( xForbiddenChars
)
53 SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable()
57 void SvxUnoForbiddenCharsTable::onChange()
61 ForbiddenCharacters
SvxUnoForbiddenCharsTable::getForbiddenCharacters( const Locale
& rLocale
)
62 throw(NoSuchElementException
, RuntimeException
)
64 OGuard
aGuard( Application::GetSolarMutex() );
66 if(!mxForbiddenChars
.isValid())
67 throw RuntimeException();
69 const LanguageType eLang
= SvxLocaleToLanguage( rLocale
);
70 const ForbiddenCharacters
* pForbidden
= mxForbiddenChars
->GetForbiddenCharacters( eLang
, FALSE
);
72 throw NoSuchElementException();
77 sal_Bool
SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const Locale
& rLocale
)
78 throw(RuntimeException
)
80 OGuard
aGuard( Application::GetSolarMutex() );
82 if(!mxForbiddenChars
.isValid())
85 const LanguageType eLang
= SvxLocaleToLanguage( rLocale
);
86 const ForbiddenCharacters
* pForbidden
= mxForbiddenChars
->GetForbiddenCharacters( eLang
, FALSE
);
88 return NULL
!= pForbidden
;
91 void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const Locale
& rLocale
, const ForbiddenCharacters
& rForbiddenCharacters
)
92 throw(RuntimeException
)
94 OGuard
aGuard( Application::GetSolarMutex() );
96 if(!mxForbiddenChars
.isValid())
97 throw RuntimeException();
99 const LanguageType eLang
= SvxLocaleToLanguage( rLocale
);
100 mxForbiddenChars
->SetForbiddenCharacters( eLang
, rForbiddenCharacters
);
105 void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const Locale
& rLocale
)
106 throw(RuntimeException
)
108 OGuard
aGuard( Application::GetSolarMutex() );
110 if(!mxForbiddenChars
.isValid())
111 throw RuntimeException();
113 const LanguageType eLang
= SvxLocaleToLanguage( rLocale
);
114 mxForbiddenChars
->ClearForbiddenCharacters( eLang
);
120 Sequence
< Locale
> SAL_CALL
SvxUnoForbiddenCharsTable::getLocales()
121 throw(RuntimeException
)
123 OGuard
aGuard( Application::GetSolarMutex() );
125 const sal_Int32 nCount
= mxForbiddenChars
.isValid() ? mxForbiddenChars
->Count() : 0;
127 Sequence
< Locale
> aLocales( nCount
);
130 Locale
* pLocales
= aLocales
.getArray();
132 for( sal_Int32 nIndex
= 0; nIndex
< nCount
; nIndex
++ )
134 const ULONG nLanguage
= mxForbiddenChars
->GetObjectKey( nIndex
);
135 SvxLanguageToLocale ( *pLocales
++, static_cast < LanguageType
> (nLanguage
) );
142 sal_Bool SAL_CALL
SvxUnoForbiddenCharsTable::hasLocale( const Locale
& aLocale
)
143 throw(RuntimeException
)
145 OGuard
aGuard( Application::GetSolarMutex() );
147 return hasForbiddenCharacters( aLocale
);