Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <assert.h>
22 : #include <textconversionImpl.hxx>
23 :
24 : using namespace com::sun::star::lang;
25 : using namespace com::sun::star::uno;
26 :
27 :
28 : namespace com { namespace sun { namespace star { namespace i18n {
29 :
30 : TextConversionResult SAL_CALL
31 0 : TextConversionImpl::getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
32 : const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
33 : throw( RuntimeException, IllegalArgumentException, NoSupportException )
34 : {
35 0 : getLocaleSpecificTextConversion(rLocale);
36 :
37 0 : sal_Int32 len = aText.getLength() - nStartPos;
38 0 : if (nLength > len)
39 0 : nLength = len > 0 ? len : 0;
40 0 : return xTC->getConversions(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
41 : }
42 :
43 : OUString SAL_CALL
44 0 : TextConversionImpl::getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
45 : const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
46 : throw( RuntimeException, IllegalArgumentException, NoSupportException )
47 : {
48 0 : getLocaleSpecificTextConversion(rLocale);
49 :
50 0 : sal_Int32 len = aText.getLength() - nStartPos;
51 0 : if (nLength > len)
52 0 : nLength = len > 0 ? len : 0;
53 0 : return xTC->getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
54 : }
55 :
56 : OUString SAL_CALL
57 0 : TextConversionImpl::getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
58 : const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions, Sequence< sal_Int32>& offset)
59 : throw( RuntimeException, IllegalArgumentException, NoSupportException )
60 : {
61 0 : getLocaleSpecificTextConversion(rLocale);
62 :
63 0 : sal_Int32 len = aText.getLength() - nStartPos;
64 0 : if (nLength > len)
65 0 : nLength = len > 0 ? len : 0;
66 0 : return xTC->getConversionWithOffset(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions, offset);
67 : }
68 :
69 : sal_Bool SAL_CALL
70 0 : TextConversionImpl::interactiveConversion( const Locale& rLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions )
71 : throw( RuntimeException, IllegalArgumentException, NoSupportException )
72 : {
73 0 : getLocaleSpecificTextConversion(rLocale);
74 :
75 0 : return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions);
76 : }
77 :
78 0 : static inline sal_Bool operator != (const Locale& l1, const Locale& l2) {
79 0 : return l1.Language != l2.Language || l1.Country != l2.Country || l1.Variant != l2.Variant;
80 : }
81 :
82 : void SAL_CALL
83 0 : TextConversionImpl::getLocaleSpecificTextConversion(const Locale& rLocale) throw( NoSupportException )
84 : {
85 0 : if (rLocale != aLocale) {
86 0 : aLocale = rLocale;
87 :
88 0 : Reference < XInterface > xI;
89 :
90 0 : xI = m_xContext->getServiceManager()->createInstanceWithContext(
91 0 : OUString("com.sun.star.i18n.TextConversion_") + aLocale.Language, m_xContext);
92 :
93 0 : if ( ! xI.is() )
94 0 : xI = m_xContext->getServiceManager()->createInstanceWithContext(
95 0 : OUString("com.sun.star.i18n.TextConversion_") + aLocale.Language +
96 0 : OUString("_") + aLocale.Country, m_xContext);
97 0 : if ( ! xI.is() )
98 0 : xI = m_xContext->getServiceManager()->createInstanceWithContext(
99 0 : OUString("com.sun.star.i18n.TextConversion_") + aLocale.Language +
100 0 : OUString("_") + aLocale.Country +
101 0 : OUString("_") + aLocale.Variant, m_xContext);
102 :
103 0 : if (xI.is())
104 0 : xTC.set( xI, UNO_QUERY );
105 0 : else if (xTC.is())
106 0 : xTC.clear();
107 : }
108 0 : if (! xTC.is())
109 0 : throw NoSupportException(); // aLocale is not supported
110 0 : }
111 :
112 : const sal_Char cTextConversion[] = "com.sun.star.i18n.TextConversion";
113 :
114 : OUString SAL_CALL
115 0 : TextConversionImpl::getImplementationName() throw( RuntimeException )
116 : {
117 0 : return OUString::createFromAscii(cTextConversion);
118 : }
119 :
120 : sal_Bool SAL_CALL
121 0 : TextConversionImpl::supportsService(const OUString& rServiceName)
122 : throw( RuntimeException )
123 : {
124 0 : return rServiceName.equalsAscii(cTextConversion);
125 : }
126 :
127 : Sequence< OUString > SAL_CALL
128 0 : TextConversionImpl::getSupportedServiceNames() throw( RuntimeException )
129 : {
130 0 : Sequence< OUString > aRet(1);
131 0 : aRet[0] = OUString::createFromAscii(cTextConversion);
132 0 : return aRet;
133 : }
134 :
135 : } } } }
136 :
137 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|