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: textconversionImpl.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_i18npool.hxx"
35 #include <textconversionImpl.hxx>
37 using namespace com::sun::star::lang
;
38 using namespace com::sun::star::uno
;
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
;
52 nLength
= len
> 0 ? len
: 0;
53 return xTC
->getConversions(aText
, nStartPos
, nLength
, rLocale
, nConversionType
, nConversionOptions
);
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
;
65 nLength
= len
> 0 ? len
: 0;
66 return xTC
->getConversion(aText
, nStartPos
, nLength
, rLocale
, nConversionType
, nConversionOptions
);
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
;
78 nLength
= len
> 0 ? len
: 0;
79 return xTC
->getConversionWithOffset(aText
, nStartPos
, nLength
, rLocale
, nConversionType
, nConversionOptions
, offset
);
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
;
96 TextConversionImpl::getLocaleSpecificTextConversion(const Locale
& rLocale
) throw( NoSupportException
)
98 if (xMSF
.is() && rLocale
!= aLocale
) {
101 Reference
< XInterface
> xI
;
103 xI
= xMSF
->createInstance(
104 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale
.Language
);
107 xI
= xMSF
->createInstance(
108 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale
.Language
+
109 OUString::createFromAscii("_") + aLocale
.Country
);
111 xI
= xMSF
->createInstance(
112 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale
.Language
+
113 OUString::createFromAscii("_") + aLocale
.Country
+
114 OUString::createFromAscii("_") + aLocale
.Variant
);
117 xI
->queryInterface( getCppuType((const Reference
< XTextConversion
>*)0) ) >>= xTC
;
122 throw NoSupportException(); // aLocale is not supported
125 const sal_Char cTextConversion
[] = "com.sun.star.i18n.TextConversion";
128 TextConversionImpl::getImplementationName() throw( RuntimeException
)
130 return OUString::createFromAscii(cTextConversion
);
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
);