xref: /trunk/main/sw/source/core/tox/toxhlp.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_sw.hxx"
30 
31 
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <comphelper/processfactory.hxx>
34 #ifndef _COM_SUN_STAR_I18N_XINDEXENTRYSUPPLIER_HPP_
35 #include <com/sun/star/i18n/XExtendedIndexEntrySupplier.hpp>
36 #endif
37 #include <tools/string.hxx>
38 #include <tools/debug.hxx>
39 #include <toxwrap.hxx>
40 
41 using namespace ::com::sun::star;
42 
43 
44 IndexEntrySupplierWrapper::IndexEntrySupplierWrapper()
45 {
46     uno::Reference<
47             lang::XMultiServiceFactory > rxMSF =
48                                     ::comphelper::getProcessServiceFactory();
49 
50     try {
51         STAR_REFERENCE( uno::XInterface ) xI =
52             rxMSF->createInstance( ::rtl::OUString::createFromAscii(
53                                 "com.sun.star.i18n.IndexEntrySupplier" ) );
54         if( xI.is() )
55         {
56             UNO_NMSPC::Any x = xI->queryInterface( ::getCppuType(
57                     (const uno::Reference< i18n::XExtendedIndexEntrySupplier>*)0) );
58             x >>= xIES;
59         }
60     }
61     catch ( UNO_NMSPC::Exception&
62 #ifdef DBG_UTIL
63         e
64 #endif
65         )
66     {
67 #ifdef DBG_UTIL
68         ByteString aMsg( "IndexEntrySupplierWrapper: Exception caught\n" );
69         aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
70         DBG_ERRORFILE( aMsg.GetBuffer() );
71 #endif
72     }
73 }
74 
75 IndexEntrySupplierWrapper::~IndexEntrySupplierWrapper()
76 {
77 }
78 
79 String IndexEntrySupplierWrapper::GetIndexKey( const String& rTxt,
80                                                const String& rTxtReading,
81                                                const STAR_NMSPC::lang::Locale& rLocale ) const
82 {
83     String sRet;
84     try {
85         sRet = xIES->getIndexKey( rTxt, rTxtReading, rLocale );
86     }
87     catch ( UNO_NMSPC::Exception&
88 #ifdef DBG_UTIL
89         e
90 #endif
91         )
92     {
93 #ifdef DBG_UTIL
94         ByteString aMsg( "getIndexKey: Exception caught\n" );
95         aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
96         DBG_ERRORFILE( aMsg.GetBuffer() );
97 #endif
98     }
99     return sRet;
100 }
101 
102 String IndexEntrySupplierWrapper::GetFollowingText( sal_Bool bMorePages ) const
103 {
104     String sRet;
105     try {
106         sRet = xIES->getIndexFollowPageWord( bMorePages, aLcl );
107     }
108     catch ( UNO_NMSPC::Exception&
109 #ifdef DBG_UTIL
110         e
111 #endif
112         )
113     {
114 #ifdef DBG_UTIL
115         ByteString aMsg( "getIndexFollowPageWord: Exception caught\n" );
116         aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
117         DBG_ERRORFILE( aMsg.GetBuffer() );
118 #endif
119     }
120     return sRet;
121 }
122 
123 STAR_NMSPC::uno::Sequence< ::rtl::OUString >
124 IndexEntrySupplierWrapper::GetAlgorithmList( const STAR_NMSPC::lang::Locale& rLcl ) const
125 {
126     uno::Sequence< ::rtl::OUString > sRet;
127 
128     try {
129         sRet = xIES->getAlgorithmList( rLcl );
130     }
131     catch ( UNO_NMSPC::Exception&
132 #ifdef DBG_UTIL
133         e
134 #endif
135         )
136     {
137 #ifdef DBG_UTIL
138         ByteString aMsg( "getAlgorithmList: Exception caught\n" );
139         aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
140         DBG_ERRORFILE( aMsg.GetBuffer() );
141 #endif
142     }
143     return sRet;
144 }
145 
146 sal_Bool IndexEntrySupplierWrapper::LoadAlgorithm(
147         const STAR_NMSPC::lang::Locale& rLcl,
148         const String& sSortAlgorithm, long nOptions ) const
149 {
150     sal_Bool bRet = sal_False;
151     try {
152         bRet = xIES->loadAlgorithm( rLcl, sSortAlgorithm, nOptions );
153     }
154     catch ( UNO_NMSPC::Exception&
155 #ifdef DBG_UTIL
156         e
157 #endif
158         )
159     {
160 #ifdef DBG_UTIL
161         ByteString aMsg( "loadAlgorithm: Exception caught\n" );
162         aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
163         DBG_ERRORFILE( aMsg.GetBuffer() );
164 #endif
165     }
166     return bRet;
167 }
168 
169 sal_Int16 IndexEntrySupplierWrapper::CompareIndexEntry(
170             const String& rTxt1, const String& rTxtReading1,
171             const STAR_NMSPC::lang::Locale& rLocale1,
172             const String& rTxt2, const String& rTxtReading2,
173             const STAR_NMSPC::lang::Locale& rLocale2 ) const
174 {
175     sal_Int16 nRet = 0;
176     try {
177         nRet = xIES->compareIndexEntry( rTxt1, rTxtReading1, rLocale1,
178                                         rTxt2, rTxtReading2, rLocale2 );
179     }
180     catch ( UNO_NMSPC::Exception&
181 #ifdef DBG_UTIL
182         e
183 #endif
184         )
185     {
186 #ifdef DBG_UTIL
187         ByteString aMsg( "compareIndexEntry: Exception caught\n" );
188         aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 );
189         DBG_ERRORFILE( aMsg.GetBuffer() );
190 #endif
191     }
192     return nRet;
193 }
194