1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _I18N_CHARACTERCLASSIFICATIONIMPL_HXX_
28 #define _I18N_CHARACTERCLASSIFICATIONIMPL_HXX_
29 
30 #include <com/sun/star/i18n/XCharacterClassification.hpp>
31 #include <cppuhelper/implbase2.hxx> // helper for implementations
32 #include <vector>
33 #include <com/sun/star/i18n/KCharacterType.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 
36 namespace com { namespace sun { namespace star { namespace i18n {
37 
38 class CharacterClassificationImpl : public cppu::WeakImplHelper2
39 <
40 	XCharacterClassification,
41 	com::sun::star::lang::XServiceInfo
42 >
43 {
44 public:
45 
46 	CharacterClassificationImpl( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF );
47 	virtual ~CharacterClassificationImpl();
48 
49 	virtual rtl::OUString SAL_CALL toUpper( const rtl::OUString& Text,
50 		sal_Int32 nPos, sal_Int32 nCount, const com::sun::star::lang::Locale& rLocale )
51 		throw(com::sun::star::uno::RuntimeException);
52 	virtual rtl::OUString SAL_CALL toLower( const rtl::OUString& Text,
53 		sal_Int32 nPos, sal_Int32 nCount, const com::sun::star::lang::Locale& rLocale )
54 		throw(com::sun::star::uno::RuntimeException);
55 	virtual rtl::OUString SAL_CALL toTitle( const rtl::OUString& Text, sal_Int32 nPos,
56 		sal_Int32 nCount, const com::sun::star::lang::Locale& rLocale )
57 		throw(com::sun::star::uno::RuntimeException);
58 	virtual sal_Int16 SAL_CALL getType( const rtl::OUString& Text, sal_Int32 nPos )
59 		throw(com::sun::star::uno::RuntimeException);
60 	virtual sal_Int16 SAL_CALL getCharacterDirection( const rtl::OUString& Text, sal_Int32 nPos )
61 		throw(com::sun::star::uno::RuntimeException);
62 	virtual sal_Int16 SAL_CALL getScript( const rtl::OUString& Text, sal_Int32 nPos )
63 		throw(com::sun::star::uno::RuntimeException);
64 	virtual sal_Int32 SAL_CALL getCharacterType( const rtl::OUString& text, sal_Int32 nPos,
65 		const com::sun::star::lang::Locale& rLocale )
66 		throw(com::sun::star::uno::RuntimeException);
67 	virtual sal_Int32 SAL_CALL getStringType( const rtl::OUString& text, sal_Int32 nPos,
68 		sal_Int32 nCount, const com::sun::star::lang::Locale& rLocale )
69 		throw(com::sun::star::uno::RuntimeException);
70 	virtual ParseResult SAL_CALL parseAnyToken( const rtl::OUString& Text, sal_Int32 nPos,
71 		const com::sun::star::lang::Locale& rLocale, sal_Int32 nStartCharFlags,
72 		const rtl::OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags,
73 		const rtl::OUString& userDefinedCharactersCont )
74 		throw(com::sun::star::uno::RuntimeException);
75 	virtual ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType,
76 		const rtl::OUString& Text, sal_Int32 nPos, const com::sun::star::lang::Locale& rLocale,
77 		sal_Int32 nStartCharFlags, const rtl::OUString& userDefinedCharactersStart,
78 		sal_Int32 nContCharFlags, const rtl::OUString& userDefinedCharactersCont )
79 		throw(com::sun::star::uno::RuntimeException);
80 
81 	//XServiceInfo
82 	virtual rtl::OUString SAL_CALL getImplementationName(void)
83                 throw( com::sun::star::uno::RuntimeException );
84 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName)
85 		throw( com::sun::star::uno::RuntimeException );
86 	virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void)
87 		throw( com::sun::star::uno::RuntimeException );
88 
89 private:
90 	struct lookupTableItem {
91 	    lookupTableItem(const com::sun::star::lang::Locale& rLocale, const rtl::OUString& rName,
92 		com::sun::star::uno::Reference < XCharacterClassification >& rxCI) :
93 		aLocale(rLocale), aName(rName), xCI(rxCI) {};
94 	    com::sun::star::lang::Locale aLocale;
95 	    rtl::OUString aName;
96 	    com::sun::star::uno::Reference < XCharacterClassification > xCI;
97 	    sal_Bool SAL_CALL equals(const com::sun::star::lang::Locale& rLocale) {
98 		return aLocale.Language == rLocale.Language &&
99 			aLocale.Country == rLocale.Country &&
100 			aLocale.Variant == rLocale.Variant;
101 	    };
102 	};
103 	std::vector<lookupTableItem*> lookupTable;
104 	lookupTableItem *cachedItem;
105 
106 	com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF;
107 	com::sun::star::uno::Reference < XCharacterClassification > xUCI;
108 
109 	com::sun::star::uno::Reference < XCharacterClassification > SAL_CALL
110 	getLocaleSpecificCharacterClassification(const com::sun::star::lang::Locale& rLocale) throw(com::sun::star::uno::RuntimeException);
111 	sal_Bool SAL_CALL
112 	createLocaleSpecificCharacterClassification(const rtl::OUString& serviceName, const com::sun::star::lang::Locale& rLocale);
113 
114 };
115 
116 } } } }
117 
118 #endif
119