1*449ab281SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*449ab281SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*449ab281SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*449ab281SAndrew Rist  * distributed with this work for additional information
6*449ab281SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*449ab281SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*449ab281SAndrew Rist  * "License"); you may not use this file except in compliance
9*449ab281SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*449ab281SAndrew Rist  *
11*449ab281SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*449ab281SAndrew Rist  *
13*449ab281SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*449ab281SAndrew Rist  * software distributed under the License is distributed on an
15*449ab281SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*449ab281SAndrew Rist  * KIND, either express or implied.  See the License for the
17*449ab281SAndrew Rist  * specific language governing permissions and limitations
18*449ab281SAndrew Rist  * under the License.
19*449ab281SAndrew Rist  *
20*449ab281SAndrew Rist  *************************************************************/
21*449ab281SAndrew Rist 
22*449ab281SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_i18npool.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <assert.h>
28cdf0e10cSrcweir #include <textconversionImpl.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace com::sun::star::lang;
31cdf0e10cSrcweir using namespace com::sun::star::uno;
32cdf0e10cSrcweir using namespace rtl;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace i18n {
35cdf0e10cSrcweir 
36cdf0e10cSrcweir TextConversionResult SAL_CALL
getConversions(const OUString & aText,sal_Int32 nStartPos,sal_Int32 nLength,const Locale & rLocale,sal_Int16 nConversionType,sal_Int32 nConversionOptions)37cdf0e10cSrcweir TextConversionImpl::getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
38cdf0e10cSrcweir     const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
39cdf0e10cSrcweir     throw(  RuntimeException, IllegalArgumentException, NoSupportException )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     getLocaleSpecificTextConversion(rLocale);
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     sal_Int32 len = aText.getLength() - nStartPos;
44cdf0e10cSrcweir     if (nLength > len)
45cdf0e10cSrcweir         nLength = len > 0 ? len : 0;
46cdf0e10cSrcweir     return xTC->getConversions(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir OUString SAL_CALL
getConversion(const OUString & aText,sal_Int32 nStartPos,sal_Int32 nLength,const Locale & rLocale,sal_Int16 nConversionType,sal_Int32 nConversionOptions)50cdf0e10cSrcweir TextConversionImpl::getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
51cdf0e10cSrcweir     const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
52cdf0e10cSrcweir     throw(  RuntimeException, IllegalArgumentException, NoSupportException )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     getLocaleSpecificTextConversion(rLocale);
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     sal_Int32 len = aText.getLength() - nStartPos;
57cdf0e10cSrcweir     if (nLength > len)
58cdf0e10cSrcweir         nLength = len > 0 ? len : 0;
59cdf0e10cSrcweir     return xTC->getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir OUString SAL_CALL
getConversionWithOffset(const OUString & aText,sal_Int32 nStartPos,sal_Int32 nLength,const Locale & rLocale,sal_Int16 nConversionType,sal_Int32 nConversionOptions,Sequence<sal_Int32> & offset)63cdf0e10cSrcweir TextConversionImpl::getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
64cdf0e10cSrcweir     const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions, Sequence< sal_Int32>& offset)
65cdf0e10cSrcweir     throw(  RuntimeException, IllegalArgumentException, NoSupportException )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     getLocaleSpecificTextConversion(rLocale);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     sal_Int32 len = aText.getLength() - nStartPos;
70cdf0e10cSrcweir     if (nLength > len)
71cdf0e10cSrcweir         nLength = len > 0 ? len : 0;
72cdf0e10cSrcweir     return xTC->getConversionWithOffset(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions, offset);
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir sal_Bool SAL_CALL
interactiveConversion(const Locale & rLocale,sal_Int16 nTextConversionType,sal_Int32 nTextConversionOptions)76cdf0e10cSrcweir TextConversionImpl::interactiveConversion( const Locale& rLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions )
77cdf0e10cSrcweir     throw(  RuntimeException, IllegalArgumentException, NoSupportException )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     getLocaleSpecificTextConversion(rLocale);
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions);
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
operator !=(const Locale & l1,const Locale & l2)84cdf0e10cSrcweir static inline sal_Bool operator != (const Locale& l1, const Locale& l2) {
85cdf0e10cSrcweir 	return l1.Language != l2.Language || l1.Country != l2.Country || l1.Variant != l2.Variant;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir void SAL_CALL
getLocaleSpecificTextConversion(const Locale & rLocale)89cdf0e10cSrcweir TextConversionImpl::getLocaleSpecificTextConversion(const Locale& rLocale) throw( NoSupportException )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     if (xMSF.is() && rLocale != aLocale) {
92cdf0e10cSrcweir         aLocale = rLocale;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         Reference < XInterface > xI;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         xI = xMSF->createInstance(
97cdf0e10cSrcweir             OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale.Language);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         if ( ! xI.is() )
100cdf0e10cSrcweir             xI = xMSF->createInstance(
101cdf0e10cSrcweir                 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale.Language +
102cdf0e10cSrcweir                 OUString::createFromAscii("_") + aLocale.Country);
103cdf0e10cSrcweir         if ( ! xI.is() )
104cdf0e10cSrcweir             xI = xMSF->createInstance(
105cdf0e10cSrcweir                 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale.Language +
106cdf0e10cSrcweir                 OUString::createFromAscii("_") + aLocale.Country +
107cdf0e10cSrcweir                 OUString::createFromAscii("_") + aLocale.Variant);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         if (xI.is())
110cdf0e10cSrcweir             xI->queryInterface( getCppuType((const Reference< XTextConversion>*)0) ) >>= xTC;
111cdf0e10cSrcweir         else if (xTC.is())
112cdf0e10cSrcweir             xTC.clear();
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir     if (! xTC.is())
115cdf0e10cSrcweir         throw NoSupportException(); // aLocale is not supported
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir const sal_Char cTextConversion[] = "com.sun.star.i18n.TextConversion";
119cdf0e10cSrcweir 
120cdf0e10cSrcweir OUString SAL_CALL
getImplementationName()121cdf0e10cSrcweir TextConversionImpl::getImplementationName() throw( RuntimeException )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     return OUString::createFromAscii(cTextConversion);
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir sal_Bool SAL_CALL
supportsService(const OUString & rServiceName)127cdf0e10cSrcweir TextConversionImpl::supportsService(const OUString& rServiceName)
128cdf0e10cSrcweir                 throw( RuntimeException )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     return rServiceName.equalsAscii(cTextConversion);
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir Sequence< OUString > SAL_CALL
getSupportedServiceNames()134cdf0e10cSrcweir TextConversionImpl::getSupportedServiceNames() throw( RuntimeException )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     Sequence< OUString > aRet(1);
137cdf0e10cSrcweir     aRet[0] = OUString::createFromAscii(cTextConversion);
138cdf0e10cSrcweir     return aRet;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir } } } }
142