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 <localedata.hxx>
28 #include <i18npool/mslangid.hxx>
29 #include <rtl/ustrbuf.hxx>
30 #include <string.h>
31 #include <stdio.h>
32 #include "rtl/instance.hxx"
33 
34 using namespace com::sun::star::i18n;
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star::lang;
37 using namespace com::sun::star;
38 using namespace rtl;
39 
40 static const sal_Char clocaledata[] = "com.sun.star.i18n.LocaleData";
41 
42 typedef sal_Unicode**   (SAL_CALL * MyFunc_Type)( sal_Int16&);
43 typedef sal_Unicode***  (SAL_CALL * MyFunc_Type2)( sal_Int16&, sal_Int16& );
44 typedef sal_Unicode**** (SAL_CALL * MyFunc_Type3)( sal_Int16&, sal_Int16&, sal_Int16& );
45 typedef sal_Unicode const * const * (SAL_CALL * MyFunc_FormatCode)( sal_Int16&, sal_Unicode const *&, sal_Unicode const *& );
46 
47 #ifdef OS2 // YD 8.3!!
48 static const char *lcl_DATA_EN = "ld_en";
49 static const char *lcl_DATA_ES = "ld_es";
50 static const char *lcl_DATA_EURO = "ld_eur";
51 static const char *lcl_DATA_OTHERS = "ld_oth";
52 #else
53 static const char *lcl_DATA_EN = "localedata_en";
54 static const char *lcl_DATA_ES = "localedata_es";
55 static const char *lcl_DATA_EURO = "localedata_euro";
56 static const char *lcl_DATA_OTHERS = "localedata_others";
57 #endif
58 
59 static const struct {
60     const char* pLocale;
61     const char* pLib;
62 } aLibTable[] = {
63     { "en_US",  lcl_DATA_EN },
64     { "en_AU",  lcl_DATA_EN },
65     { "en_BZ",  lcl_DATA_EN },
66     { "en_CA",  lcl_DATA_EN },
67     { "en_GB",  lcl_DATA_EN },
68     { "en_IE",  lcl_DATA_EN },
69     { "en_JM",  lcl_DATA_EN },
70     { "en_NZ",  lcl_DATA_EN },
71     { "en_PH",  lcl_DATA_EN },
72     { "en_TT",  lcl_DATA_EN },
73     { "en_ZA",  lcl_DATA_EN },
74     { "en_ZW",  lcl_DATA_EN },
75     { "en_NA",  lcl_DATA_EN },
76     { "en_GH",  lcl_DATA_EN },
77 
78     { "es_ES",  lcl_DATA_ES },
79     { "es_AR",  lcl_DATA_ES },
80     { "es_BO",  lcl_DATA_ES },
81     { "es_CL",  lcl_DATA_ES },
82     { "es_CO",  lcl_DATA_ES },
83     { "es_CR",  lcl_DATA_ES },
84     { "es_DO",  lcl_DATA_ES },
85     { "es_EC",  lcl_DATA_ES },
86     { "es_GT",  lcl_DATA_ES },
87     { "es_HN",  lcl_DATA_ES },
88     { "es_MX",  lcl_DATA_ES },
89     { "es_NI",  lcl_DATA_ES },
90     { "es_PA",  lcl_DATA_ES },
91     { "es_PE",  lcl_DATA_ES },
92     { "es_PR",  lcl_DATA_ES },
93     { "es_PY",  lcl_DATA_ES },
94     { "es_SV",  lcl_DATA_ES },
95     { "es_UY",  lcl_DATA_ES },
96     { "es_VE",  lcl_DATA_ES },
97     { "gl_ES",  lcl_DATA_ES },
98 
99     { "de_DE",  lcl_DATA_EURO },
100     { "de_AT",  lcl_DATA_EURO },
101     { "de_CH",  lcl_DATA_EURO },
102     { "de_LI",  lcl_DATA_EURO },
103     { "de_LU",  lcl_DATA_EURO },
104     { "fr_FR",  lcl_DATA_EURO },
105     { "fr_BE",  lcl_DATA_EURO },
106     { "fr_CA",  lcl_DATA_EURO },
107     { "fr_CH",  lcl_DATA_EURO },
108     { "fr_LU",  lcl_DATA_EURO },
109     { "fr_MC",  lcl_DATA_EURO },
110     { "it_IT",  lcl_DATA_EURO },
111     { "it_CH",  lcl_DATA_EURO },
112     { "sl_SI",  lcl_DATA_EURO },
113     { "sv_SE",  lcl_DATA_EURO },
114     { "sv_FI",  lcl_DATA_EURO },
115     { "ca_ES",  lcl_DATA_EURO },
116     { "cs_CZ",  lcl_DATA_EURO },
117     { "sk_SK",  lcl_DATA_EURO },
118     { "da_DK",  lcl_DATA_EURO },
119     { "el_GR",  lcl_DATA_EURO },
120     { "fi_FI",  lcl_DATA_EURO },
121     { "is_IS",  lcl_DATA_EURO },
122     { "nl_BE",  lcl_DATA_EURO },
123     { "nl_NL",  lcl_DATA_EURO },
124     { "no_NO",  lcl_DATA_EURO },
125     { "nn_NO",  lcl_DATA_EURO },
126     { "nb_NO",  lcl_DATA_EURO },
127     { "pl_PL",  lcl_DATA_EURO },
128     { "pt_BR",  lcl_DATA_EURO },
129     { "pt_PT",  lcl_DATA_EURO },
130     { "ru_RU",  lcl_DATA_EURO },
131     { "tr_TR",  lcl_DATA_EURO },
132     { "et_EE",  lcl_DATA_EURO },
133     { "lb_LU",  lcl_DATA_EURO },
134     { "lt_LT",  lcl_DATA_EURO },
135     { "lv_LV",  lcl_DATA_EURO },
136     { "uk_UA",  lcl_DATA_EURO },
137     { "ro_RO",  lcl_DATA_EURO },
138     { "cy_GB",  lcl_DATA_EURO },
139     { "bg_BG",  lcl_DATA_EURO },
140     { "sh_ME",  lcl_DATA_EURO },
141     { "sh_RS",  lcl_DATA_EURO },
142     { "sh_YU",  lcl_DATA_EURO },
143     { "sr_ME",  lcl_DATA_EURO },
144     { "sr_RS",  lcl_DATA_EURO },
145     { "sr_YU",  lcl_DATA_EURO },
146     { "hr_HR",  lcl_DATA_EURO },
147     { "bs_BA",  lcl_DATA_EURO },
148     { "eu",     lcl_DATA_EURO },
149     { "fo_FO",  lcl_DATA_EURO },
150     { "ga_IE",  lcl_DATA_EURO },
151     { "gd_GB",  lcl_DATA_EURO },
152     { "ka_GE",  lcl_DATA_EURO },
153     { "be_BY",  lcl_DATA_EURO },
154     { "kl_GL",  lcl_DATA_EURO },
155     { "mk_MK",  lcl_DATA_EURO },
156     { "br_FR",  lcl_DATA_EURO },
157     { "la_VA",  lcl_DATA_EURO },
158     { "cv_RU",  lcl_DATA_EURO },
159     { "wa_BE",  lcl_DATA_EURO },
160     { "fur_IT", lcl_DATA_EURO },
161     { "gsc_FR", lcl_DATA_EURO },
162     { "fy_NL",  lcl_DATA_EURO },
163     { "oc_FR",  lcl_DATA_EURO },
164     { "mt_MT",  lcl_DATA_EURO },
165     { "sc_IT",  lcl_DATA_EURO },
166     { "ast_ES", lcl_DATA_EURO },
167     { "ltg_LV", lcl_DATA_EURO },
168     { "hsb_DE", lcl_DATA_EURO },
169     { "dsb_DE", lcl_DATA_EURO },
170     { "rue_SK", lcl_DATA_EURO },
171 
172     { "ja_JP",  lcl_DATA_OTHERS },
173     { "ko_KR",  lcl_DATA_OTHERS },
174     { "zh_CN",  lcl_DATA_OTHERS },
175     { "zh_HK",  lcl_DATA_OTHERS },
176     { "zh_SG",  lcl_DATA_OTHERS },
177     { "zh_TW",  lcl_DATA_OTHERS },
178     { "zh_MO",  lcl_DATA_OTHERS },
179 
180     { "ar_EG",  lcl_DATA_OTHERS },
181     { "ar_DZ",  lcl_DATA_OTHERS },
182     { "ar_LB",  lcl_DATA_OTHERS },
183     { "ar_SA",  lcl_DATA_OTHERS },
184     { "ar_TN",  lcl_DATA_OTHERS },
185     { "he_IL",  lcl_DATA_OTHERS },
186     { "hi_IN",  lcl_DATA_OTHERS },
187     { "kn_IN",  lcl_DATA_OTHERS },
188     { "ta_IN",  lcl_DATA_OTHERS },
189     { "te_IN",  lcl_DATA_OTHERS },
190     { "gu_IN",  lcl_DATA_OTHERS },
191     { "mr_IN",  lcl_DATA_OTHERS },
192     { "pa_IN",  lcl_DATA_OTHERS },
193     { "bn_IN",  lcl_DATA_OTHERS },
194     { "or_IN",  lcl_DATA_OTHERS },
195     { "en_IN",  lcl_DATA_OTHERS },
196     { "ml_IN",  lcl_DATA_OTHERS },
197     { "bn_BD",  lcl_DATA_OTHERS },
198     { "th_TH",  lcl_DATA_OTHERS },
199 
200     { "af_ZA",  lcl_DATA_OTHERS },
201     { "hu_HU",  lcl_DATA_OTHERS },
202     { "id_ID",  lcl_DATA_OTHERS },
203     { "ms_MY",  lcl_DATA_OTHERS },
204     { "ia",     lcl_DATA_OTHERS },
205     { "mn_MN",  lcl_DATA_OTHERS },
206     { "az_AZ",  lcl_DATA_OTHERS },
207     { "sw_TZ",  lcl_DATA_OTHERS },
208     { "km_KH",  lcl_DATA_OTHERS },
209     { "lo_LA",  lcl_DATA_OTHERS },
210     { "rw_RW",  lcl_DATA_OTHERS },
211     { "eo",     lcl_DATA_OTHERS },
212     { "dz_BT",  lcl_DATA_OTHERS },
213     { "ne_NP",  lcl_DATA_OTHERS },
214     { "zu_ZA",  lcl_DATA_OTHERS },
215     { "nso_ZA", lcl_DATA_OTHERS },
216     { "vi_VN",  lcl_DATA_OTHERS },
217     { "tn_ZA",  lcl_DATA_OTHERS },
218     { "xh_ZA",  lcl_DATA_OTHERS },
219     { "st_ZA",  lcl_DATA_OTHERS },
220     { "ss_ZA",  lcl_DATA_OTHERS },
221     { "ve_ZA",  lcl_DATA_OTHERS },
222     { "nr_ZA",  lcl_DATA_OTHERS },
223     { "ts_ZA",  lcl_DATA_OTHERS },
224     { "ku_TR",  lcl_DATA_OTHERS },
225     { "ak_GH",  lcl_DATA_OTHERS },
226     { "af_NA",  lcl_DATA_OTHERS },
227     { "am_ET",  lcl_DATA_OTHERS },
228     { "ti_ER",  lcl_DATA_OTHERS },
229     { "tg_TJ",  lcl_DATA_OTHERS },
230     { "ky_KG",  lcl_DATA_OTHERS },
231     { "kk_KZ",  lcl_DATA_OTHERS },
232     { "fa_IR",  lcl_DATA_OTHERS },
233     { "ha_GH",  lcl_DATA_OTHERS },
234     { "ee_GH",  lcl_DATA_OTHERS },
235     { "sg_CF",  lcl_DATA_OTHERS },
236     { "lg_UG",  lcl_DATA_OTHERS },
237     { "uz_UZ",  lcl_DATA_OTHERS },
238     { "ln_CD",  lcl_DATA_OTHERS },
239     { "hy_AM",  lcl_DATA_OTHERS },
240     { "hil_PH", lcl_DATA_OTHERS },
241     { "so_SO",  lcl_DATA_OTHERS },
242     { "gug_PY", lcl_DATA_OTHERS },
243     { "tk_TM",  lcl_DATA_OTHERS },
244     { "my_MM",  lcl_DATA_OTHERS },
245     { "shs_CA", lcl_DATA_OTHERS },
246     { "tpi_PG", lcl_DATA_OTHERS },
247     { "ar_OM",  lcl_DATA_OTHERS },
248     { "ug_CN",  lcl_DATA_OTHERS },
249     { "om_ET",  lcl_DATA_OTHERS },
250     { "plt_MG", lcl_DATA_OTHERS },
251     { "mai_IN", lcl_DATA_OTHERS },
252     { "yi_US",  lcl_DATA_OTHERS },
253     { "haw_US", lcl_DATA_OTHERS },
254     { "lif_NP", lcl_DATA_OTHERS },
255     { "ur_PK",  lcl_DATA_OTHERS },
256     { "ht_HT",  lcl_DATA_OTHERS },
257     { "jbo",    lcl_DATA_OTHERS }
258 };
259 
260 static const sal_Unicode under = sal_Unicode('_');
261 
262 static const sal_Int16 nbOfLocales = sizeof(aLibTable) / sizeof(aLibTable[0]);
263 
264 struct LocaleDataLookupTableItem
265 {
266         LocaleDataLookupTableItem(const sal_Char *name, osl::Module* m, const sal_Char* lname) : dllName(name), module(m), localeName(lname)
267         {
268         }
269         const sal_Char* dllName;
270         osl::Module *module;
271         const sal_Char* localeName;
272 
273         com::sun::star::lang::Locale aLocale;
274         sal_Bool equals(const com::sun::star::lang::Locale& rLocale)
275         {
276             return (rLocale == aLocale);
277         }
278 };
279 
280 LocaleData::LocaleData()
281 {
282 }
283 LocaleData::~LocaleData()
284 {
285 }
286 
287 
288 LocaleDataItem SAL_CALL
289 LocaleData::getLocaleItem( const Locale& rLocale ) throw(RuntimeException)
290 {
291         sal_Int16 dataItemCount = 0;
292         sal_Unicode **dataItem = NULL;
293 
294         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getLocaleItem" );
295 
296         if ( func ) {
297             dataItem = func(dataItemCount);
298 
299             LocaleDataItem item(
300                     dataItem[0],
301                     dataItem[1],
302                     dataItem[2],
303                     dataItem[3],
304                     dataItem[4],
305                     dataItem[5],
306                     dataItem[6],
307                     dataItem[7],
308                     dataItem[8],
309                     dataItem[9],
310                     dataItem[10],
311                     dataItem[11],
312                     dataItem[12],
313                     dataItem[13],
314                     dataItem[14],
315                     dataItem[15],
316                     dataItem[16],
317                     dataItem[17]
318                     );
319             return item;
320         }
321         else {
322             LocaleDataItem item1;
323             return item1;
324         }
325 }
326 
327 extern "C" { static void SAL_CALL thisModule() {} }
328 
329 namespace
330 {
331 
332 // implement the lookup table as a safe static object
333 class lcl_LookupTableHelper
334 {
335 public:
336     lcl_LookupTableHelper();
337     ~lcl_LookupTableHelper();
338 
339     oslGenericFunction SAL_CALL getFunctionSymbolByName(
340         const OUString& localeName, const sal_Char* pFunction,
341         LocaleDataLookupTableItem** pOutCachedItem );
342 
343 private:
344     ::osl::Mutex maMutex;
345     ::std::vector< LocaleDataLookupTableItem* >  maLookupTable;
346 };
347 
348 // from instance.hxx: Helper base class for a late-initialized
349 // (default-constructed) static variable, implementing the double-checked
350 // locking pattern correctly.
351 // usage:  lcl_LookupTableHelper & rLookupTable = lcl_LookupTableStatic::get();
352 // retrieves the singleton lookup table instance
353 struct lcl_LookupTableStatic : public ::rtl::Static< lcl_LookupTableHelper, lcl_LookupTableStatic >
354 {};
355 
356 lcl_LookupTableHelper::lcl_LookupTableHelper()
357 {
358 }
359 
360 lcl_LookupTableHelper::~lcl_LookupTableHelper()
361 {
362     LocaleDataLookupTableItem* pItem = 0;
363 
364     std::vector<LocaleDataLookupTableItem*>::const_iterator aEnd(maLookupTable.end());
365     std::vector<LocaleDataLookupTableItem*>::iterator aIter(maLookupTable.begin());
366 
367     for ( ; aIter != aEnd; ++aIter ) {
368         pItem = *aIter;
369         delete pItem->module;
370         delete pItem;
371     }
372     maLookupTable.clear();
373 }
374 
375 oslGenericFunction SAL_CALL lcl_LookupTableHelper::getFunctionSymbolByName(
376     const OUString& localeName, const sal_Char* pFunction,
377     LocaleDataLookupTableItem** pOutCachedItem )
378 {
379     OUString aFallback;
380     bool bFallback = (localeName.indexOf( under) < 0);
381     if (bFallback)
382     {
383         Locale aLocale;
384         aLocale.Language = localeName;
385         Locale aFbLocale = MsLangId::getFallbackLocale( aLocale);
386         if (aFbLocale == aLocale)
387             bFallback = false;  // may be a "language-only-locale" like Interlingua (ia)
388         else if (aFbLocale.Country.getLength()) {
389             OUStringBuffer aBuf(5);
390             aFallback = aBuf.append(aFbLocale.Language).append( under).append(aFbLocale.Country).makeStringAndClear();
391         }
392         else
393             aFallback = aFbLocale.Language;
394     }
395 
396     for ( sal_Int16 i = 0; i < nbOfLocales; i++)
397     {
398         if (localeName.equalsAscii(aLibTable[i].pLocale) ||
399                 (bFallback && localeName == aFallback))
400         {
401             LocaleDataLookupTableItem* pCurrent = 0;
402             OUStringBuffer aBuf(strlen(aLibTable[i].pLocale) + 1 + strlen(pFunction));
403             {
404                 ::osl::MutexGuard aGuard( maMutex );
405                 for (size_t l = 0; l < maLookupTable.size(); l++)
406                 {
407                     pCurrent = maLookupTable[l];
408                     if (pCurrent->dllName == aLibTable[i].pLib)
409                     {
410                         OSL_ASSERT( pOutCachedItem );
411                         if( pOutCachedItem )
412                         {
413                             (*pOutCachedItem) = new LocaleDataLookupTableItem( *pCurrent );
414                             (*pOutCachedItem)->localeName = aLibTable[i].pLocale;
415                             return (*pOutCachedItem)->module->getFunctionSymbol(
416                                 aBuf.appendAscii( pFunction).append( under).
417                                 appendAscii( (*pOutCachedItem)->localeName).makeStringAndClear());
418                         }
419                         else
420                             return NULL;
421                     }
422                 }
423             }
424             // Library not loaded, load it and add it to the list.
425 #ifdef SAL_DLLPREFIX
426             aBuf.ensureCapacity(strlen(aLibTable[i].pLib) + 6);    // mostly "lib*.so"
427             aBuf.appendAscii( SAL_DLLPREFIX ).appendAscii(aLibTable[i].pLib).appendAscii( SAL_DLLEXTENSION );
428 #else
429             aBuf.ensureCapacity(strlen(aLibTable[i].pLib) + 4);    // mostly "*.dll"
430             aBuf.appendAscii(aLibTable[i].pLib).appendAscii( SAL_DLLEXTENSION );
431 #endif
432             osl::Module *module = new osl::Module();
433             if ( module->loadRelative(&thisModule, aBuf.makeStringAndClear()) )
434             {
435                 ::osl::MutexGuard aGuard( maMutex );
436                 LocaleDataLookupTableItem* pNewItem = 0;
437                 maLookupTable.push_back(pNewItem = new LocaleDataLookupTableItem(aLibTable[i].pLib, module, aLibTable[i].pLocale ));
438                 OSL_ASSERT( pOutCachedItem );
439                 if( pOutCachedItem )
440                 {
441                     (*pOutCachedItem) = new LocaleDataLookupTableItem( *pNewItem );
442                     return module->getFunctionSymbol(
443                         aBuf.appendAscii(pFunction).append(under).
444                         appendAscii((*pOutCachedItem)->localeName).makeStringAndClear());
445                 }
446                 else
447                     return NULL;
448             }
449             else
450                 delete module;
451         }
452     }
453     return NULL;
454 }
455 
456 } // anonymous namespace
457 
458 #define REF_DAYS 0
459 #define REF_MONTHS 1
460 #define REF_ERAS 2
461 
462 Sequence< CalendarItem > &LocaleData::getCalendarItemByName(const OUString& name,
463         const Locale& rLocale, const Sequence< Calendar >& calendarsSeq, sal_Int16 len, sal_Int16 item)
464         throw(RuntimeException)
465 {
466         if (!ref_name.equals(name)) {
467             sal_Int32 index = 0;
468             OUString language = name.getToken(0, under, index);
469             OUString country = name.getToken(0, under, index);
470             Locale loc(language, country, OUString());
471             Sequence < Calendar > cals;
472             if (loc == rLocale) {
473                 cals = calendarsSeq;
474             } else {
475                 cals = getAllCalendars(loc);
476                 len = sal::static_int_cast<sal_Int16>( cals.getLength() );
477             }
478             const OUString& id = name.getToken(0, under, index);
479             for (index = 0; index < cals.getLength(); index++) {
480                 if (id.equals(cals[index].Name)) {
481                     ref_cal = cals[index];
482                     break;
483                 }
484             }
485             // Refered locale does not found, return name for en_US locale.
486             if (index == cals.getLength()) {
487                 cals = getAllCalendars(
488                         Locale(OUString::createFromAscii("en"), OUString::createFromAscii("US"), OUString()));
489                 if (cals.getLength() > 0)
490                     ref_cal = cals[0];
491                 else
492                     throw RuntimeException();
493             }
494             ref_name = name;
495         }
496         return item == REF_DAYS ? ref_cal.Days : item == REF_MONTHS ? ref_cal.Months : ref_cal.Eras;
497 }
498 
499 
500 Sequence< Calendar > SAL_CALL
501 LocaleData::getAllCalendars( const Locale& rLocale ) throw(RuntimeException)
502 {
503 
504         sal_Int16 calendarsCount = 0;
505         sal_Unicode **allCalendars = NULL;
506 
507         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getAllCalendars" );
508 
509         if ( func ) {
510             allCalendars = func(calendarsCount);
511 
512             Sequence< Calendar > calendarsSeq(calendarsCount);
513             sal_Int16 offset = 3;
514             sal_Int16 i, j;
515             for(i = 0; i < calendarsCount; i++) {
516                 Sequence< CalendarItem > days(allCalendars[0][i]);
517                 Sequence< CalendarItem > months(allCalendars[1][i]);
518                 Sequence< CalendarItem > eras(allCalendars[2][i]);
519                 OUString calendarID(allCalendars[offset]);
520                 offset++;
521                 sal_Bool defaultCalendar = sal::static_int_cast<sal_Bool>( allCalendars[offset][0] );
522                 offset++;
523                 if (OUString(allCalendars[offset]).equalsAscii("ref")) {
524                     days = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, i, REF_DAYS);
525                     offset += 2;
526                 } else {
527                     for(j = 0; j < allCalendars[0][i]; j++) {
528                         CalendarItem day(allCalendars[offset],
529                             allCalendars[offset+1], allCalendars[offset+2]);
530                         days[j] = day;
531                         offset += 3;
532                     }
533                 }
534                 if (OUString(allCalendars[offset]).equalsAscii("ref")) {
535                     months = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, i, REF_MONTHS);
536                     offset += 2;
537                 } else {
538                     for(j = 0; j < allCalendars[1][i]; j++) {
539                         CalendarItem month(allCalendars[offset],
540                             allCalendars[offset+1], allCalendars[offset+2]);
541                         months[j] = month;
542                         offset += 3;
543                     }
544                 }
545                 if (OUString(allCalendars[offset]).equalsAscii("ref")) {
546                     eras = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, i, REF_ERAS);
547                     offset += 2;
548                 } else {
549                     for(j = 0; j < allCalendars[2][i]; j++) {
550                         CalendarItem era(allCalendars[offset],
551                             allCalendars[offset+1], allCalendars[offset+2]);
552                         eras[j] = era;
553                         offset += 3;
554                     }
555                 }
556                 OUString startOfWeekDay(allCalendars[offset]);
557                 offset++;
558                 sal_Int16 minimalDaysInFirstWeek = allCalendars[offset][0];
559                 offset++;
560                 Calendar aCalendar(days, months, eras, startOfWeekDay,
561                         minimalDaysInFirstWeek, defaultCalendar, calendarID);
562                 calendarsSeq[i] = aCalendar;
563             }
564             return calendarsSeq;
565         }
566         else {
567             Sequence< Calendar > seq1(0);
568             return seq1;
569         }
570 }
571 
572 
573 Sequence< Currency2 > SAL_CALL
574 LocaleData::getAllCurrencies2( const Locale& rLocale ) throw(RuntimeException)
575 {
576 
577         sal_Int16 currencyCount = 0;
578         sal_Unicode **allCurrencies = NULL;
579 
580         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getAllCurrencies" );
581 
582         if ( func ) {
583             allCurrencies = func(currencyCount);
584 
585             Sequence< Currency2 > seq(currencyCount);
586             for(int i = 0, nOff = 0; i < currencyCount; i++, nOff += 8 ) {
587                 Currency2 cur(
588                     allCurrencies[nOff],        // string ID
589                     allCurrencies[nOff+1],      // string Symbol
590                     allCurrencies[nOff+2],      // string BankSymbol
591                     allCurrencies[nOff+3],      // string Name
592                     allCurrencies[nOff+4][0] != 0, // boolean Default
593                     allCurrencies[nOff+5][0] != 0, // boolean UsedInCompatibleFormatCodes
594                     allCurrencies[nOff+6][0],   // short DecimalPlaces
595                     allCurrencies[nOff+7][0] != 0 // boolean LegacyOnly
596                     );
597                     seq[i] = cur;
598             }
599             return seq;
600         }
601         else {
602             Sequence< Currency2 > seq1(0);
603             return seq1;
604         }
605 }
606 
607 
608 Sequence< Currency > SAL_CALL
609 LocaleData::getAllCurrencies( const Locale& rLocale ) throw(RuntimeException)
610 {
611     Sequence< Currency2 > aCur2( getAllCurrencies2( rLocale));
612     sal_Int32 nLen = aCur2.getLength();
613     Sequence< Currency > aCur1( nLen);
614     const Currency2* p2 = aCur2.getArray();
615     Currency* p1 = aCur1.getArray();
616     for (sal_Int32 i=0; i < nLen; ++i, ++p1, ++p2)
617     {
618         *p1 = *p2;
619     }
620     return aCur1;
621 }
622 
623 
624 // return a static (!) string resulting from replacing all occurrences of
625 // 'oldStr' string in 'formatCode' string with 'newStr' string
626 static const sal_Unicode * replace( sal_Unicode const * const formatCode, sal_Unicode const * const oldStr, sal_Unicode const * const newStr)
627 {
628 // make reasonable assumption of maximum length of formatCode.
629 #define MAX_FORMATCODE_LENTH 512
630     static sal_Unicode str[MAX_FORMATCODE_LENTH];
631 
632     if (oldStr[0] == 0) // no replacement requires
633         return formatCode;
634 
635     sal_Int32 i = 0, k = 0;
636     while (formatCode[i] > 0 && k < MAX_FORMATCODE_LENTH) {
637         sal_Int32 j = 0, last = k;
638         // search oldStr in formatCode
639         while (formatCode[i] > 0 && oldStr[j] > 0 && k < MAX_FORMATCODE_LENTH) {
640             str[k++] = formatCode[i];
641             if (formatCode[i++] != oldStr[j++])
642                 break;
643         }
644         if (oldStr[j] == 0) {
645             // matched string found, do replacement
646             k = last; j = 0;
647             while (newStr[j] > 0 && k < MAX_FORMATCODE_LENTH)
648                 str[k++] = newStr[j++];
649         }
650     }
651     if (k >= MAX_FORMATCODE_LENTH) // could not complete replacement, return original formatCode
652         return formatCode;
653 
654     str[k] = 0;
655     return str;
656 }
657 
658 Sequence< FormatElement > SAL_CALL
659 LocaleData::getAllFormats( const Locale& rLocale ) throw(RuntimeException)
660 {
661     const int SECTIONS = 2;
662     struct FormatSection
663     {
664         MyFunc_FormatCode         func;
665         sal_Unicode const        *from;
666         sal_Unicode const        *to;
667         sal_Unicode const *const *formatArray;
668         sal_Int16                 formatCount;
669 
670         FormatSection() : func(0), from(0), to(0), formatArray(0), formatCount(0) {}
671         sal_Int16 getFunc( LocaleData& rLocaleData, const Locale& rL, const char* pName )
672         {
673             func = reinterpret_cast<MyFunc_FormatCode>( rLocaleData.getFunctionSymbol( rL, pName));
674             if (func)
675                 formatArray = func( formatCount, from, to);
676             return formatCount;
677         }
678     } section[SECTIONS];
679 
680 #if 0
681 // #i79398# wntmsci10 MSVC doesn't get this right with optimization.
682     const sal_Int32 formatCount = section[0].getFunc( *this, rLocale, "getAllFormats0")
683                                 + section[1].getFunc( *this, rLocale, "getAllFormats1");
684 #else
685     sal_Int32 formatCount  = section[0].getFunc( *this, rLocale, "getAllFormats0");
686               formatCount += section[1].getFunc( *this, rLocale, "getAllFormats1");
687 #endif
688     Sequence< FormatElement > seq(formatCount);
689     sal_Int32 f = 0;
690     for (int s = 0; s < SECTIONS; ++s)
691     {
692         sal_Unicode const * const * const formatArray = section[s].formatArray;
693         if ( formatArray )
694         {
695             for (int i = 0, nOff = 0; i < section[s].formatCount; ++i, nOff += 7, ++f)
696             {
697                 FormatElement elem(
698                         replace( formatArray[nOff], section[s].from, section[s].to),
699                         formatArray[nOff + 1],
700                         formatArray[nOff + 2],
701                         formatArray[nOff + 3],
702                         formatArray[nOff + 4],
703                         formatArray[nOff + 5][0],
704                         sal::static_int_cast<sal_Bool>(formatArray[nOff + 6][0]));
705                 seq[f] = elem;
706             }
707         }
708     }
709     return seq;
710 }
711 
712 #define COLLATOR_OFFSET_ALGO    0
713 #define COLLATOR_OFFSET_DEFAULT 1
714 #define COLLATOR_OFFSET_RULE    2
715 #define COLLATOR_ELEMENTS       3
716 
717 OUString SAL_CALL
718 LocaleData::getCollatorRuleByAlgorithm( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
719 {
720         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollatorImplementation" );
721         if ( func ) {
722             sal_Int16 collatorCount = 0;
723             sal_Unicode **collatorArray = func(collatorCount);
724             for(sal_Int16 i = 0; i < collatorCount; i++)
725                 if (algorithm.equals(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO]))
726                     return OUString(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_RULE]);
727         }
728         return OUString();
729 }
730 
731 
732 Sequence< Implementation > SAL_CALL
733 LocaleData::getCollatorImplementations( const Locale& rLocale ) throw(RuntimeException)
734 {
735         sal_Int16 collatorCount = 0;
736         sal_Unicode **collatorArray = NULL;
737 
738         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollatorImplementation" );
739 
740         if ( func ) {
741             collatorArray = func(collatorCount);
742             Sequence< Implementation > seq(collatorCount);
743             for(sal_Int16 i = 0; i < collatorCount; i++) {
744               Implementation impl(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO],
745                       sal::static_int_cast<sal_Bool>(
746                           collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_DEFAULT][0]));
747               seq[i] = impl;
748             }
749             return seq;
750         }
751         else {
752             Sequence< Implementation > seq1(0);
753             return seq1;
754         }
755 }
756 
757 Sequence< OUString > SAL_CALL
758 LocaleData::getCollationOptions( const Locale& rLocale ) throw(RuntimeException)
759 {
760         sal_Int16 optionsCount = 0;
761         sal_Unicode **optionsArray = NULL;
762 
763         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollationOptions" );
764 
765         if ( func ) {
766             optionsArray = func(optionsCount);
767             Sequence< OUString > seq(optionsCount);
768             for(sal_Int16 i = 0; i < optionsCount; i++) {
769                     seq[i] = OUString( optionsArray[i] );
770             }
771             return seq;
772         }
773         else {
774             Sequence< OUString > seq1(0);
775             return seq1;
776         }
777 }
778 
779 Sequence< OUString > SAL_CALL
780 LocaleData::getSearchOptions( const Locale& rLocale ) throw(RuntimeException)
781 {
782         sal_Int16 optionsCount = 0;
783         sal_Unicode **optionsArray = NULL;
784 
785         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getSearchOptions" );
786 
787         if ( func ) {
788             optionsArray = func(optionsCount);
789             Sequence< OUString > seq(optionsCount);
790             for(sal_Int16 i = 0; i < optionsCount; i++) {
791                     seq[i] = OUString( optionsArray[i] );
792             }
793             return seq;
794         }
795         else {
796             Sequence< OUString > seq1(0);
797             return seq1;
798         }
799 }
800 
801 sal_Unicode ** SAL_CALL
802 LocaleData::getIndexArray(const Locale& rLocale, sal_Int16& indexCount)
803 {
804         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getIndexAlgorithm" );
805 
806         if (func)
807             return func(indexCount);
808         return NULL;
809 }
810 
811 Sequence< OUString > SAL_CALL
812 LocaleData::getIndexAlgorithm( const Locale& rLocale ) throw(RuntimeException)
813 {
814         sal_Int16 indexCount = 0;
815         sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
816 
817         if ( indexArray ) {
818             Sequence< OUString > seq(indexCount);
819             for(sal_Int16 i = 0; i < indexCount; i++) {
820               seq[i] = indexArray[i*5];
821             }
822             return seq;
823         }
824         else {
825             Sequence< OUString > seq1(0);
826             return seq1;
827         }
828 }
829 
830 OUString SAL_CALL
831 LocaleData::getDefaultIndexAlgorithm( const Locale& rLocale ) throw(RuntimeException)
832 {
833         sal_Int16 indexCount = 0;
834         sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
835 
836         if ( indexArray ) {
837             for(sal_Int16 i = 0; i < indexCount; i++) {
838               if (indexArray[i*5 + 3][0])
839                   return OUString(indexArray[i*5]);
840             }
841         }
842         return OUString();
843 }
844 
845 sal_Bool SAL_CALL
846 LocaleData::hasPhonetic( const Locale& rLocale ) throw(RuntimeException)
847 {
848         sal_Int16 indexCount = 0;
849         sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
850 
851         if ( indexArray ) {
852             for(sal_Int16 i = 0; i < indexCount; i++) {
853               if (indexArray[i*5 + 4][0])
854                   return sal_True;
855             }
856         }
857         return sal_False;
858 }
859 
860 sal_Unicode ** SAL_CALL
861 LocaleData::getIndexArrayForAlgorithm(const Locale& rLocale, const OUString& algorithm)
862 {
863         sal_Int16 indexCount = 0;
864         sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
865         if ( indexArray ) {
866             for(sal_Int16 i = 0; i < indexCount; i++) {
867               if (algorithm.equals(indexArray[i*5]))
868                   return indexArray+i*5;
869             }
870         }
871         return NULL;
872 }
873 
874 sal_Bool SAL_CALL
875 LocaleData::isPhonetic( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
876 {
877         sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
878         return (indexArray && indexArray[4][0]) ? sal_True : sal_False;
879 }
880 
881 OUString SAL_CALL
882 LocaleData::getIndexKeysByAlgorithm( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
883 {
884         sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
885         return indexArray ? OUString::createFromAscii("0-9")+OUString(indexArray[2]) : OUString();
886 }
887 
888 OUString SAL_CALL
889 LocaleData::getIndexModuleByAlgorithm( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
890 {
891         sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
892         return indexArray ? OUString(indexArray[1]) : OUString();
893 }
894 
895 Sequence< UnicodeScript > SAL_CALL
896 LocaleData::getUnicodeScripts( const Locale& rLocale ) throw(RuntimeException)
897 {
898         sal_Int16 scriptCount = 0;
899         sal_Unicode **scriptArray = NULL;
900 
901         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getUnicodeScripts" );
902 
903         if ( func ) {
904             scriptArray = func(scriptCount);
905             Sequence< UnicodeScript > seq(scriptCount);
906             for(sal_Int16 i = 0; i < scriptCount; i++) {
907                     seq[i] = UnicodeScript( OUString(scriptArray[i]).toInt32() );
908             }
909             return seq;
910         }
911         else {
912             Sequence< UnicodeScript > seq1(0);
913             return seq1;
914         }
915 }
916 
917 Sequence< OUString > SAL_CALL
918 LocaleData::getFollowPageWords( const Locale& rLocale ) throw(RuntimeException)
919 {
920         sal_Int16 wordCount = 0;
921         sal_Unicode **wordArray = NULL;
922 
923         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getFollowPageWords" );
924 
925         if ( func ) {
926             wordArray = func(wordCount);
927             Sequence< OUString > seq(wordCount);
928             for(sal_Int16 i = 0; i < wordCount; i++) {
929                     seq[i] = OUString(wordArray[i]);
930             }
931             return seq;
932         }
933         else {
934             Sequence< OUString > seq1(0);
935             return seq1;
936         }
937 }
938 
939 Sequence< OUString > SAL_CALL
940 LocaleData::getTransliterations( const Locale& rLocale ) throw(RuntimeException)
941 {
942 
943         sal_Int16 transliterationsCount = 0;
944         sal_Unicode **transliterationsArray = NULL;
945 
946         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getTransliterations" );
947 
948         if ( func ) {
949             transliterationsArray = func(transliterationsCount);
950 
951             Sequence< OUString > seq(transliterationsCount);
952             for(int i = 0; i < transliterationsCount; i++) {
953                     OUString  elem(transliterationsArray[i]);
954                     seq[i] = elem;
955             }
956             return seq;
957         }
958         else {
959             Sequence< OUString > seq1(0);
960             return seq1;
961         }
962 
963 
964 }
965 
966 
967 LanguageCountryInfo SAL_CALL
968 LocaleData::getLanguageCountryInfo( const Locale& rLocale ) throw(RuntimeException)
969 {
970         sal_Int16 LCInfoCount = 0;
971         sal_Unicode **LCInfoArray = NULL;
972 
973         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getLCInfo" );
974 
975         if ( func ) {
976             LCInfoArray = func(LCInfoCount);
977             LanguageCountryInfo info(LCInfoArray[0],
978                                     LCInfoArray[1],
979                                     LCInfoArray[2],
980                                     LCInfoArray[3],
981                                     LCInfoArray[4]);
982             return info;
983         }
984         else {
985             LanguageCountryInfo info1;
986             return info1;
987         }
988 
989 }
990 
991 
992 ForbiddenCharacters SAL_CALL
993 LocaleData::getForbiddenCharacters( const Locale& rLocale ) throw(RuntimeException)
994 {
995         sal_Int16 LCForbiddenCharactersCount = 0;
996         sal_Unicode **LCForbiddenCharactersArray = NULL;
997 
998         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getForbiddenCharacters" );
999 
1000         if ( func ) {
1001             LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
1002             ForbiddenCharacters chars(LCForbiddenCharactersArray[0], LCForbiddenCharactersArray[1]);
1003             return chars;
1004         }
1005         else {
1006             ForbiddenCharacters chars1;
1007             return chars1;
1008         }
1009 }
1010 
1011 OUString SAL_CALL
1012 LocaleData::getHangingCharacters( const Locale& rLocale ) throw(RuntimeException)
1013 {
1014         sal_Int16 LCForbiddenCharactersCount = 0;
1015         sal_Unicode **LCForbiddenCharactersArray = NULL;
1016 
1017         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getForbiddenCharacters" );
1018 
1019         if ( func ) {
1020             LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
1021             return OUString(LCForbiddenCharactersArray[2]);
1022         }
1023 
1024         return OUString();
1025 }
1026 
1027 Sequence< OUString > SAL_CALL
1028 LocaleData::getBreakIteratorRules( const Locale& rLocale  ) throw(RuntimeException)
1029 {
1030         sal_Int16 LCBreakIteratorRuleCount = 0;
1031         sal_Unicode **LCBreakIteratorRulesArray = NULL;
1032 
1033         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getBreakIteratorRules" );
1034 
1035         if ( func ) {
1036             LCBreakIteratorRulesArray = func(LCBreakIteratorRuleCount);
1037             Sequence< OUString > seq(LCBreakIteratorRuleCount);
1038             for(int i = 0; i < (LCBreakIteratorRuleCount); i++) {
1039                 OUString  elem(LCBreakIteratorRulesArray[i]);
1040                 seq[i] = elem;
1041             }
1042             return seq;
1043         }
1044         else {
1045             Sequence< OUString > seq1(0);
1046             return seq1;
1047         }
1048 }
1049 
1050 
1051 Sequence< OUString > SAL_CALL
1052 LocaleData::getReservedWord( const Locale& rLocale  ) throw(RuntimeException)
1053 {
1054         sal_Int16 LCReservedWordsCount = 0;
1055         sal_Unicode **LCReservedWordsArray = NULL;
1056 
1057         MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getReservedWords" );
1058 
1059         if ( func ) {
1060             LCReservedWordsArray = func(LCReservedWordsCount);
1061             Sequence< OUString > seq(LCReservedWordsCount);
1062             for(int i = 0; i < (LCReservedWordsCount); i++) {
1063                 OUString  elem(LCReservedWordsArray[i]);
1064                 seq[i] = elem;
1065             }
1066             return seq;
1067         }
1068         else {
1069             Sequence< OUString > seq1(0);
1070             return seq1;
1071         }
1072 }
1073 
1074 
1075 inline
1076 OUString C2U( const char* s )
1077 {
1078         return OUString::createFromAscii( s );
1079 }
1080 
1081 Sequence< Sequence<beans::PropertyValue> > SAL_CALL
1082 LocaleData::getContinuousNumberingLevels( const lang::Locale& rLocale ) throw(RuntimeException)
1083 {
1084          int i;
1085 
1086          // load symbol
1087          MyFunc_Type2 func = (MyFunc_Type2) getFunctionSymbol( rLocale, "getContinuousNumberingLevels" );
1088 
1089          if ( func )
1090          {
1091               // invoke function
1092               sal_Int16 nStyles;
1093               sal_Int16 nAttributes;
1094               sal_Unicode*** p0 = func( nStyles, nAttributes );
1095 
1096               // allocate memory for nAttributes attributes for each of the nStyles styles.
1097               Sequence< Sequence<beans::PropertyValue> > pv( nStyles );
1098               for( i=0; i<pv.getLength(); i++ ) {
1099                    pv[i] = Sequence<beans::PropertyValue>( nAttributes );
1100               }
1101 
1102               sal_Unicode*** pStyle = p0;
1103               for( i=0;  i<nStyles;  i++ ) {
1104                    sal_Unicode** pAttribute = pStyle[i];
1105                    for( int j=0;  j<nAttributes;  j++ ) { // prefix, numberingtype, ...
1106                         sal_Unicode* pString = pAttribute[j];
1107                         beans::PropertyValue& rVal = pv[i][j];
1108                         OUString sVal;
1109                         if( pString ) {
1110                             if( 0 != j && 2 != j )
1111                                 sVal = pString;
1112                             else if( *pString )
1113                                 sVal = OUString( pString, 1 );
1114                         }
1115 
1116                         switch( j )
1117                         {
1118                         case 0:
1119                              rVal.Name = C2U("Prefix");
1120                              rVal.Value <<= sVal;
1121                              break;
1122                         case 1:
1123                              rVal.Name = C2U("NumberingType");
1124                              rVal.Value <<= (sal_Int16) sVal.toInt32();
1125                              break;
1126                         case 2:
1127                              rVal.Name = C2U("Suffix");
1128                              rVal.Value <<= sVal;
1129                              break;
1130                         case 3:
1131                              rVal.Name = C2U("Transliteration");
1132                              rVal.Value <<= sVal;
1133                              break;
1134                         case 4:
1135                              rVal.Name = C2U("NatNum");
1136                              rVal.Value <<= (sal_Int16) sVal.toInt32();
1137                              break;
1138                         default:
1139                              OSL_ASSERT(0);
1140                         }
1141                    }
1142               }
1143               return pv;
1144          }
1145 
1146          Sequence< Sequence<beans::PropertyValue> > seq1(0);
1147          return seq1;
1148 }
1149 
1150 // ============================================================================
1151 // \/ OutlineNumbering helper class \/
1152 //
1153 #include <com/sun/star/container/XIndexAccess.hpp>
1154 #include <cppuhelper/implbase1.hxx>
1155 
1156 namespace com{ namespace sun{ namespace star{ namespace lang {
1157         struct  Locale;
1158 }}}}
1159 //-----------------------------------------------------------------------------
1160 struct OutlineNumberingLevel_Impl
1161 {
1162         OUString        sPrefix;
1163         sal_Int16               nNumType; //com::sun::star::style::NumberingType
1164         OUString        sSuffix;
1165         sal_Unicode     cBulletChar;
1166         const sal_Char* sBulletFontName;
1167         sal_Int16               nParentNumbering;
1168         sal_Int32               nLeftMargin;
1169         sal_Int32               nSymbolTextDistance;
1170         sal_Int32               nFirstLineOffset;
1171         OUString        sTransliteration;
1172         sal_Int32               nNatNum;
1173 };
1174 //-----------------------------------------------------------------------------
1175 class OutlineNumbering : public cppu::WeakImplHelper1 < container::XIndexAccess >
1176 {
1177         const OutlineNumberingLevel_Impl* m_pOutlineLevels;
1178         sal_Int16                         m_nCount;
1179 public:
1180 //      OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlineLevels);
1181         OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlineLevels, int nLevels);
1182         ~OutlineNumbering();
1183 
1184         //XIndexAccess
1185         virtual sal_Int32 SAL_CALL getCount(  ) throw(RuntimeException);
1186         virtual Any SAL_CALL getByIndex( sal_Int32 Index )
1187             throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
1188 
1189         //XElementAccess
1190         virtual Type SAL_CALL getElementType(  ) throw(RuntimeException);
1191         virtual sal_Bool SAL_CALL hasElements(  ) throw(RuntimeException);
1192 };
1193 
1194 //
1195 //     OutlineNumbering helper class
1196 // ============================================================================
1197 
1198 static
1199 sal_Char* U2C( OUString str )
1200 {
1201 	 sal_Char* s = new sal_Char[ str.getLength()+1 ];
1202 	 int i;
1203 	 for( i = 0; i < str.getLength(); i++)
1204 		 s[i] = sal::static_int_cast<sal_Char>( str[i] );
1205 	 s[i]='\0';
1206 	 return s;
1207 }
1208 
1209 
1210 Sequence< Reference<container::XIndexAccess> > SAL_CALL
1211 LocaleData::getOutlineNumberingLevels( const lang::Locale& rLocale ) throw(RuntimeException)
1212 {
1213     int i;
1214 
1215     // load symbol
1216     MyFunc_Type3 func = (MyFunc_Type3) getFunctionSymbol( rLocale, "getOutlineNumberingLevels" );
1217 
1218     if ( func )
1219     {
1220         // invoke function
1221         sal_Int16 nStyles;
1222         sal_Int16 nLevels;
1223         sal_Int16 nAttributes;
1224         sal_Unicode**** p0 = func( nStyles, nLevels, nAttributes );
1225 
1226         Sequence< Reference<container::XIndexAccess> > aRet( nStyles );
1227 
1228         OUString aEmptyStr;
1229 
1230         sal_Unicode**** pStyle = p0;
1231         for( i=0;  i<nStyles;  i++ )
1232         {
1233             int j;
1234 
1235             OutlineNumberingLevel_Impl* level = new OutlineNumberingLevel_Impl[ nLevels+1 ];
1236             sal_Unicode*** pLevel = pStyle[i];
1237             for( j = 0;  j < nLevels;  j++ )
1238             {
1239                 sal_Unicode** pAttribute = pLevel[j];
1240                 for( int k=0; k<nAttributes; k++ )
1241                 {
1242                     OUString tmp( pAttribute[k] );
1243                     switch( k )
1244                     {
1245                         case 0: level[j].sPrefix             = tmp;             break;
1246                         case 1: level[j].nNumType            = sal::static_int_cast<sal_Int16>(tmp.toInt32()); break;
1247                         case 2: level[j].sSuffix             = tmp;             break;
1248                         //case 3: level[j].cBulletChar         = tmp.toChar();    break;
1249                         case 3: level[j].cBulletChar         = sal::static_int_cast<sal_Unicode>(tmp.toInt32(16)); break; // base 16
1250                         case 4: level[j].sBulletFontName     = U2C( tmp );      break;
1251                         case 5: level[j].nParentNumbering    = sal::static_int_cast<sal_Int16>(tmp.toInt32()); break;
1252                         case 6: level[j].nLeftMargin         = tmp.toInt32();   break;
1253                         case 7: level[j].nSymbolTextDistance = tmp.toInt32();   break;
1254                         case 8: level[j].nFirstLineOffset    = tmp.toInt32();   break;
1255                         case 9: // Adjust
1256                         // these values seem to be hard-coded elsewhere:
1257                         // level[j].Value <<= (sal_Int16) text::HoriOrientation::LEFT;
1258                         // level[j].Value <<= (sal_Int16) style::HorizontalAlignment::LEFT;
1259                             break;
1260                         case 10: level[j].sTransliteration = tmp; break;
1261                         case 11: level[j].nNatNum    = tmp.toInt32();   break;
1262                         default:
1263                             OSL_ASSERT(0);
1264                     }
1265                 }
1266             }
1267             level[j].sPrefix             = aEmptyStr;
1268             level[j].nNumType            = 0;
1269             level[j].sSuffix             = aEmptyStr;
1270             level[j].cBulletChar         = 0;
1271             level[j].sBulletFontName     = 0;
1272             level[j].nParentNumbering    = 0;
1273             level[j].nLeftMargin         = 0;
1274             level[j].nSymbolTextDistance = 0;
1275             level[j].nFirstLineOffset    = 0;
1276             level[j].sTransliteration    = aEmptyStr;
1277             level[j].nNatNum             = 0;
1278             aRet[i] = new OutlineNumbering( level, nLevels );
1279         }
1280         return aRet;
1281     }
1282     else {
1283         Sequence< Reference<container::XIndexAccess> > seq1(0);
1284         return seq1;
1285     }
1286 }
1287 
1288 /////////////////////////////////////////////////////////////////////////////////////////////
1289 //////////////////////////////////helper functions///////////////////////////////////////////
1290 /////////////////////////////////////////////////////////////////////////////////////////////
1291 
1292 oslGenericFunction SAL_CALL LocaleData::getFunctionSymbol( const Locale& rLocale, const sal_Char* pFunction )
1293         throw(RuntimeException)
1294 {
1295         lcl_LookupTableHelper & rLookupTable = lcl_LookupTableStatic::get();
1296 
1297         OUStringBuffer aBuf(1);
1298         if (cachedItem.get() && cachedItem->equals(rLocale)) {
1299             aBuf.ensureCapacity(strlen(pFunction) + 1 + strlen(cachedItem->localeName));
1300             return cachedItem->module->getFunctionSymbol(aBuf.appendAscii(pFunction).append(under).
1301                                         appendAscii(cachedItem->localeName).makeStringAndClear());
1302         }
1303 
1304         oslGenericFunction pSymbol = 0;
1305         static OUString tw(OUString::createFromAscii("TW"));
1306         static OUString en_US(OUString::createFromAscii("en_US"));
1307 
1308         sal_Int32 l = rLocale.Language.getLength();
1309         sal_Int32 c = rLocale.Country.getLength();
1310         sal_Int32 v = rLocale.Variant.getLength();
1311         aBuf.ensureCapacity(l+c+v+3);
1312 
1313         LocaleDataLookupTableItem *pCachedItem = 0;
1314 
1315         if ((l > 0 && c > 0 && v > 0 &&
1316                 // load function with name <func>_<lang>_<country>_<varian>
1317                 (pSymbol = rLookupTable.getFunctionSymbolByName(aBuf.append(rLocale.Language).append(under).append(
1318                         rLocale.Country).append(under).append(rLocale.Variant).makeStringAndClear(), pFunction, &pCachedItem)) != 0) ||
1319             (l > 0 && c > 0 &&
1320                 // load function with name <ase>_<lang>_<country>
1321                 (pSymbol = rLookupTable.getFunctionSymbolByName(aBuf.append(rLocale.Language).append(under).append(
1322                         rLocale.Country).makeStringAndClear(), pFunction, &pCachedItem)) != 0) ||
1323             (l > 0 && c > 0 && rLocale.Language.equalsAscii("zh") &&
1324                                 (rLocale.Country.equalsAscii("HK") ||
1325                                 rLocale.Country.equalsAscii("MO")) &&
1326                 // if the country code is HK or MO, one more step to try TW.
1327                 (pSymbol = rLookupTable.getFunctionSymbolByName(aBuf.append(rLocale.Language).append(under).append(tw).makeStringAndClear(),
1328                         pFunction, &pCachedItem)) != 0) ||
1329             (l > 0 &&
1330                 // load function with name <func>_<lang>
1331                 (pSymbol = rLookupTable.getFunctionSymbolByName(rLocale.Language, pFunction, &pCachedItem)) != 0) ||
1332                 // load default function with name <func>_en_US
1333                 (pSymbol = rLookupTable.getFunctionSymbolByName(en_US, pFunction, &pCachedItem)) != 0)
1334         {
1335             if( pCachedItem )
1336                 cachedItem.reset( pCachedItem );
1337             if( cachedItem.get())
1338                 cachedItem->aLocale = rLocale;
1339             return pSymbol;
1340         }
1341         throw RuntimeException();
1342 }
1343 
1344 Sequence< Locale > SAL_CALL
1345 LocaleData::getAllInstalledLocaleNames() throw(RuntimeException)
1346 {
1347         Sequence< lang::Locale > seq( nbOfLocales );
1348         OUString empStr;
1349         sal_Int16 nInstalled = 0;
1350 
1351         for( sal_Int16 i=0; i<nbOfLocales; i++ ) {
1352             OUString name = OUString::createFromAscii( aLibTable[i].pLocale );
1353 
1354             // Check if the locale is really available and not just in the table,
1355             // don't allow fall backs.
1356             LocaleDataLookupTableItem *pCachedItem = 0;
1357             if (lcl_LookupTableStatic::get().getFunctionSymbolByName( name, "getLocaleItem", &pCachedItem )) {
1358                 if( pCachedItem )
1359                     cachedItem.reset( pCachedItem );
1360                 sal_Int32 index = 0;
1361                 lang::Locale tmpLocale(name.getToken(0, under, index), empStr, empStr);
1362                 if (index >= 0) {
1363                     tmpLocale.Country = name.getToken(0, under, index);
1364                     if (index >= 0)
1365                         tmpLocale.Variant = name.getToken(0, under, index);
1366                 }
1367                 seq[nInstalled++] = tmpLocale;
1368             }
1369         }
1370         if ( nInstalled < nbOfLocales )
1371             seq.realloc( nInstalled );          // reflect reality
1372 
1373         return seq;
1374 }
1375 
1376 // ============================================================================
1377 
1378 using namespace ::com::sun::star::container;
1379 using namespace ::com::sun::star::beans;
1380 using namespace ::com::sun::star::style;
1381 using namespace ::com::sun::star::text;
1382 
1383 // // bad: can't have empty prefix ...
1384 // OutlineNumbering::OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlnLevels) :
1385 //         m_pOutlineLevels(pOutlnLevels),
1386 //         m_nCount(0)
1387 // {
1388 //         const OutlineNumberingLevel_Impl* pTemp = m_pOutlineLevels;
1389 //         while((pTemp++)->sPrefix)
1390 //                 m_nCount++;
1391 // }
1392 
1393 OutlineNumbering::OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlnLevels, int nLevels) :
1394         m_pOutlineLevels(pOutlnLevels),
1395         m_nCount(sal::static_int_cast<sal_Int16>(nLevels))
1396 {
1397 }
1398 
1399 OutlineNumbering::~OutlineNumbering()
1400 {
1401         delete [] m_pOutlineLevels;
1402 }
1403 
1404 sal_Int32 OutlineNumbering::getCount(  ) throw(RuntimeException)
1405 {
1406         return m_nCount;
1407 }
1408 
1409 Any OutlineNumbering::getByIndex( sal_Int32 nIndex )
1410         throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
1411 {
1412         if(nIndex < 0 || nIndex >= m_nCount)
1413                 throw IndexOutOfBoundsException();
1414         const OutlineNumberingLevel_Impl* pTemp = m_pOutlineLevels;
1415         pTemp += nIndex;
1416         Any aRet;
1417 
1418         Sequence<PropertyValue> aOutlineNumbering(12);
1419         PropertyValue* pValues = aOutlineNumbering.getArray();
1420         pValues[0].Name = C2U( "Prefix");
1421         pValues[0].Value <<= pTemp->sPrefix;
1422         pValues[1].Name = C2U("NumberingType");
1423         pValues[1].Value <<= pTemp->nNumType;
1424         pValues[2].Name = C2U("Suffix");
1425         pValues[2].Value <<= pTemp->sSuffix;
1426         pValues[3].Name = C2U("BulletChar");
1427         pValues[3].Value <<= OUString(&pTemp->cBulletChar, 1);
1428         pValues[4].Name = C2U("BulletFontName");
1429         pValues[4].Value <<= C2U(pTemp->sBulletFontName);
1430         pValues[5].Name = C2U("ParentNumbering");
1431         pValues[5].Value <<= pTemp->nParentNumbering;
1432         pValues[6].Name = C2U("LeftMargin");
1433         pValues[6].Value <<= pTemp->nLeftMargin;
1434         pValues[7].Name = C2U("SymbolTextDistance");
1435         pValues[7].Value <<= pTemp->nSymbolTextDistance;
1436         pValues[8].Name = C2U("FirstLineOffset");
1437         pValues[8].Value <<= pTemp->nFirstLineOffset;
1438         pValues[9].Name = C2U("Adjust");
1439         pValues[9].Value <<= (sal_Int16)HoriOrientation::LEFT;
1440         pValues[10].Name = C2U("Transliteration");
1441         pValues[10].Value <<= pTemp->sTransliteration;
1442         pValues[11].Name = C2U("NatNum");
1443         pValues[11].Value <<= pTemp->nNatNum;
1444         aRet <<= aOutlineNumbering;
1445         return aRet;
1446 }
1447 
1448 Type OutlineNumbering::getElementType(  ) throw(RuntimeException)
1449 {
1450         return ::getCppuType((Sequence<PropertyValue>*)0);
1451 }
1452 
1453 sal_Bool OutlineNumbering::hasElements(  ) throw(RuntimeException)
1454 {
1455         return m_nCount > 0;
1456 }
1457 
1458 OUString SAL_CALL
1459 LocaleData::getImplementationName() throw( RuntimeException )
1460 {
1461         return OUString::createFromAscii(clocaledata);
1462 }
1463 
1464 sal_Bool SAL_CALL
1465 LocaleData::supportsService(const OUString& rServiceName)
1466                 throw( RuntimeException )
1467 {
1468         return !rServiceName.compareToAscii(clocaledata);
1469 }
1470 
1471 Sequence< OUString > SAL_CALL
1472 LocaleData::getSupportedServiceNames() throw( RuntimeException )
1473 {
1474         Sequence< OUString > aRet(1);
1475         aRet[0] = OUString::createFromAscii(clocaledata);
1476         return aRet;
1477 }
1478