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 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_i18npool.hxx" 30 31 #include <assert.h> 32 #include <textconversionImpl.hxx> 33 34 using namespace com::sun::star::lang; 35 using namespace com::sun::star::uno; 36 using namespace rtl; 37 38 namespace com { namespace sun { namespace star { namespace i18n { 39 40 TextConversionResult SAL_CALL 41 TextConversionImpl::getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, 42 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions) 43 throw( RuntimeException, IllegalArgumentException, NoSupportException ) 44 { 45 getLocaleSpecificTextConversion(rLocale); 46 47 sal_Int32 len = aText.getLength() - nStartPos; 48 if (nLength > len) 49 nLength = len > 0 ? len : 0; 50 return xTC->getConversions(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions); 51 } 52 53 OUString SAL_CALL 54 TextConversionImpl::getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, 55 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions) 56 throw( RuntimeException, IllegalArgumentException, NoSupportException ) 57 { 58 getLocaleSpecificTextConversion(rLocale); 59 60 sal_Int32 len = aText.getLength() - nStartPos; 61 if (nLength > len) 62 nLength = len > 0 ? len : 0; 63 return xTC->getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions); 64 } 65 66 OUString SAL_CALL 67 TextConversionImpl::getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, 68 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions, Sequence< sal_Int32>& offset) 69 throw( RuntimeException, IllegalArgumentException, NoSupportException ) 70 { 71 getLocaleSpecificTextConversion(rLocale); 72 73 sal_Int32 len = aText.getLength() - nStartPos; 74 if (nLength > len) 75 nLength = len > 0 ? len : 0; 76 return xTC->getConversionWithOffset(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions, offset); 77 } 78 79 sal_Bool SAL_CALL 80 TextConversionImpl::interactiveConversion( const Locale& rLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions ) 81 throw( RuntimeException, IllegalArgumentException, NoSupportException ) 82 { 83 getLocaleSpecificTextConversion(rLocale); 84 85 return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions); 86 } 87 88 static inline sal_Bool operator != (const Locale& l1, const Locale& l2) { 89 return l1.Language != l2.Language || l1.Country != l2.Country || l1.Variant != l2.Variant; 90 } 91 92 void SAL_CALL 93 TextConversionImpl::getLocaleSpecificTextConversion(const Locale& rLocale) throw( NoSupportException ) 94 { 95 if (xMSF.is() && rLocale != aLocale) { 96 aLocale = rLocale; 97 98 Reference < XInterface > xI; 99 100 xI = xMSF->createInstance( 101 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale.Language); 102 103 if ( ! xI.is() ) 104 xI = xMSF->createInstance( 105 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale.Language + 106 OUString::createFromAscii("_") + aLocale.Country); 107 if ( ! xI.is() ) 108 xI = xMSF->createInstance( 109 OUString::createFromAscii("com.sun.star.i18n.TextConversion_") + aLocale.Language + 110 OUString::createFromAscii("_") + aLocale.Country + 111 OUString::createFromAscii("_") + aLocale.Variant); 112 113 if (xI.is()) 114 xI->queryInterface( getCppuType((const Reference< XTextConversion>*)0) ) >>= xTC; 115 else if (xTC.is()) 116 xTC.clear(); 117 } 118 if (! xTC.is()) 119 throw NoSupportException(); // aLocale is not supported 120 } 121 122 const sal_Char cTextConversion[] = "com.sun.star.i18n.TextConversion"; 123 124 OUString SAL_CALL 125 TextConversionImpl::getImplementationName() throw( RuntimeException ) 126 { 127 return OUString::createFromAscii(cTextConversion); 128 } 129 130 sal_Bool SAL_CALL 131 TextConversionImpl::supportsService(const OUString& rServiceName) 132 throw( RuntimeException ) 133 { 134 return rServiceName.equalsAscii(cTextConversion); 135 } 136 137 Sequence< OUString > SAL_CALL 138 TextConversionImpl::getSupportedServiceNames() throw( RuntimeException ) 139 { 140 Sequence< OUString > aRet(1); 141 aRet[0] = OUString::createFromAscii(cTextConversion); 142 return aRet; 143 } 144 145 } } } } 146