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