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