update dev300-m58
[ooovba.git] / unotools / source / i18n / collatorwrapper.cxx
blobe5f19341e6cf7ccaa1158b161b8de475460787f2
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: collatorwrapper.cxx,v $
10 * $Revision: 1.8 $
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_unotools.hxx"
33 #include <unotools/collatorwrapper.hxx>
34 #include <tools/debug.hxx>
36 #ifndef _COMPHELPER_COMPONENTFACTORY_HXX_
37 #include <comphelper/componentfactory.hxx>
38 #endif
39 #include <com/sun/star/uno/XInterface.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 using namespace ::com::sun::star;
44 CollatorWrapper::CollatorWrapper (
45 const uno::Reference< lang::XMultiServiceFactory > &xServiceFactory)
46 : mxServiceFactory (xServiceFactory)
48 ::rtl::OUString aService (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.Collator"));
50 if (mxServiceFactory.is())
52 try
54 mxInternationalCollator = uno::Reference< i18n::XCollator > (
55 mxServiceFactory->createInstance(aService), uno::UNO_QUERY);
57 catch (uno::Exception& rException)
59 (void)rException;
60 DBG_ERRORFILE ("CollatorWrapper: failed to create instance");
63 else
65 ::rtl::OUString aLibrary (RTL_CONSTASCII_USTRINGPARAM(LLCF_LIBNAME("i18n")));
67 try
69 uno::Reference< uno::XInterface > xInstance =
70 ::comphelper::getComponentInstance (aLibrary, aService);
72 if (xInstance.is())
74 uno::Any xInterface = xInstance->queryInterface (
75 ::getCppuType((const uno::Reference< i18n::XCollator >*)0) );
76 xInterface >>= mxInternationalCollator;
79 catch (uno::Exception& rException)
81 (void)rException;
82 DBG_ERRORFILE ("CollatorWrapper: failed to get component instance!");
86 DBG_ASSERT (mxInternationalCollator.is(), "CollatorWrapper: no i18n collator");
89 CollatorWrapper::~CollatorWrapper()
93 sal_Int32
94 CollatorWrapper::compareSubstring (
95 const ::rtl::OUString& s1, sal_Int32 off1, sal_Int32 len1,
96 const ::rtl::OUString& s2, sal_Int32 off2, sal_Int32 len2) const
98 try
100 if (mxInternationalCollator.is())
101 return mxInternationalCollator->compareSubstring (
102 s1, off1, len1, s2, off2, len2);
104 catch (uno::RuntimeException& rRuntimeException)
106 (void)rRuntimeException;
107 DBG_ERRORFILE ("CollatorWrapper: compareSubstring failed");
110 return 0;
113 sal_Int32
114 CollatorWrapper::compareString (const ::rtl::OUString& s1, const ::rtl::OUString& s2) const
118 if (mxInternationalCollator.is())
119 return mxInternationalCollator->compareString (s1, s2);
121 catch (uno::RuntimeException& rRuntimeException)
123 (void)rRuntimeException;
124 DBG_ERRORFILE ("CollatorWrapper: compareString failed");
127 return 0;
130 uno::Sequence< ::rtl::OUString >
131 CollatorWrapper::listCollatorAlgorithms (const lang::Locale& rLocale) const
135 if (mxInternationalCollator.is())
136 return mxInternationalCollator->listCollatorAlgorithms (rLocale);
138 catch (uno::RuntimeException& rRuntimeException)
140 (void)rRuntimeException;
141 DBG_ERRORFILE ("CollatorWrapper: listCollatorAlgorithms failed");
144 return uno::Sequence< ::rtl::OUString > ();
147 uno::Sequence< sal_Int32 >
148 CollatorWrapper::listCollatorOptions (const ::rtl::OUString& rAlgorithm) const
152 if (mxInternationalCollator.is())
153 return mxInternationalCollator->listCollatorOptions (rAlgorithm);
155 catch (uno::RuntimeException& rRuntimeException)
157 (void)rRuntimeException;
158 DBG_ERRORFILE ("CollatorWrapper: listCollatorOptions failed");
161 return uno::Sequence< sal_Int32 > ();
164 sal_Int32
165 CollatorWrapper::loadDefaultCollator (const lang::Locale& rLocale, sal_Int32 nOptions)
169 if (mxInternationalCollator.is())
170 return mxInternationalCollator->loadDefaultCollator (rLocale, nOptions);
172 catch (uno::RuntimeException& rRuntimeException)
174 (void)rRuntimeException;
175 DBG_ERRORFILE ("CollatorWrapper: loadDefaultCollator failed");
178 return 0;
181 sal_Int32
182 CollatorWrapper::loadCollatorAlgorithm (const ::rtl::OUString& rAlgorithm,
183 const lang::Locale& rLocale, sal_Int32 nOptions)
187 if (mxInternationalCollator.is())
188 return mxInternationalCollator->loadCollatorAlgorithm (
189 rAlgorithm, rLocale, nOptions);
191 catch (uno::RuntimeException& rRuntimeException)
193 (void)rRuntimeException;
194 DBG_ERRORFILE ("CollatorWrapper: loadCollatorAlgorithm failed");
197 return 0;
201 void
202 CollatorWrapper::loadCollatorAlgorithmWithEndUserOption (
203 const ::rtl::OUString& rAlgorithm,
204 const lang::Locale& rLocale, const uno::Sequence< sal_Int32 >& rOption)
208 if (mxInternationalCollator.is())
209 mxInternationalCollator->loadCollatorAlgorithmWithEndUserOption (
210 rAlgorithm, rLocale, rOption);
212 catch (uno::RuntimeException& rRuntimeException)
214 (void)rRuntimeException;
215 DBG_ERRORFILE ("CollatorWrapper: loadCollatorAlgorithmWithEndUserOption failed");