merge the formfield patch from ooo-build
[ooovba.git] / i18npool / source / textconversion / textconversionImpl.cxx
blob326f42bb4bb330926f867047f54228fea26bd562
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textconversionImpl.cxx,v $
10 * $Revision: 1.7 $
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_i18npool.hxx"
34 #include <assert.h>
35 #include <textconversionImpl.hxx>
37 using namespace com::sun::star::lang;
38 using namespace com::sun::star::uno;
39 using namespace rtl;
41 namespace com { namespace sun { namespace star { namespace i18n {
43 TextConversionResult SAL_CALL
44 TextConversionImpl::getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
45 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
46 throw( RuntimeException, IllegalArgumentException, NoSupportException )
48 getLocaleSpecificTextConversion(rLocale);
50 sal_Int32 len = aText.getLength() - nStartPos;
51 if (nLength > len)
52 nLength = len > 0 ? len : 0;
53 return xTC->getConversions(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
56 OUString SAL_CALL
57 TextConversionImpl::getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
58 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
59 throw( RuntimeException, IllegalArgumentException, NoSupportException )
61 getLocaleSpecificTextConversion(rLocale);
63 sal_Int32 len = aText.getLength() - nStartPos;
64 if (nLength > len)
65 nLength = len > 0 ? len : 0;
66 return xTC->getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
69 OUString SAL_CALL
70 TextConversionImpl::getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
71 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions, Sequence< sal_Int32>& offset)
72 throw( RuntimeException, IllegalArgumentException, NoSupportException )
74 getLocaleSpecificTextConversion(rLocale);
76 sal_Int32 len = aText.getLength() - nStartPos;
77 if (nLength > len)
78 nLength = len > 0 ? len : 0;
79 return xTC->getConversionWithOffset(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions, offset);
82 sal_Bool SAL_CALL
83 TextConversionImpl::interactiveConversion( const Locale& rLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions )
84 throw( RuntimeException, IllegalArgumentException, NoSupportException )
86 getLocaleSpecificTextConversion(rLocale);
88 return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions);
91 static inline sal_Bool operator != (const Locale& l1, const Locale& l2) {
92 return l1.Language != l2.Language || l1.Country != l2.Country || l1.Variant != l2.Variant;
95 void SAL_CALL
96 TextConversionImpl::getLocaleSpecificTextConversion(const Locale& rLocale) throw( NoSupportException )
98 if (xMSF.is() && rLocale != aLocale) {
99 aLocale = rLocale;
101 Reference < XInterface > xI;
103 xI = xMSF->createInstance(
104 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale.Language);
106 if ( ! xI.is() )
107 xI = xMSF->createInstance(
108 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale.Language +
109 OUString::createFromAscii("_") + aLocale.Country);
110 if ( ! xI.is() )
111 xI = xMSF->createInstance(
112 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale.Language +
113 OUString::createFromAscii("_") + aLocale.Country +
114 OUString::createFromAscii("_") + aLocale.Variant);
116 if (xI.is())
117 xI->queryInterface( getCppuType((const Reference< XTextConversion>*)0) ) >>= xTC;
118 else if (xTC.is())
119 xTC.clear();
121 if (! xTC.is())
122 throw NoSupportException(); // aLocale is not supported
125 const sal_Char cTextConversion[] = "com.sun.star.i18n.TextConversion";
127 OUString SAL_CALL
128 TextConversionImpl::getImplementationName() throw( RuntimeException )
130 return OUString::createFromAscii(cTextConversion);
133 sal_Bool SAL_CALL
134 TextConversionImpl::supportsService(const OUString& rServiceName)
135 throw( RuntimeException )
137 return rServiceName.equalsAscii(cTextConversion);
140 Sequence< OUString > SAL_CALL
141 TextConversionImpl::getSupportedServiceNames() throw( RuntimeException )
143 Sequence< OUString > aRet(1);
144 aRet[0] = OUString::createFromAscii(cTextConversion);
145 return aRet;
148 } } } }