xref: /trunk/main/xmloff/source/style/xmlnumfi.cxx (revision d666495c4f609ab94ddded8b0141831070b22d11) !
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_xmloff.hxx"
26 
27 #include <unotools/syslocale.hxx>
28 
29 #define _ZFORLIST_DECLARE_TABLE
30 #include <svl/zforlist.hxx>
31 
32 #include <svl/zformat.hxx>
33 #include <svl/numuno.hxx>
34 #include <rtl/math.hxx>
35 #include <i18npool/mslangid.hxx>
36 #include <tools/debug.hxx>
37 #include <rtl/ustrbuf.hxx>
38 
39 // #110680#
40 //#include <comphelper/processfactory.hxx>
41 
42 #include <xmloff/xmlnumfi.hxx>
43 #include <xmloff/xmltkmap.hxx>
44 #include "xmloff/xmlnmspe.hxx"
45 #include <xmloff/xmlictxt.hxx>
46 #include <xmloff/xmlimp.hxx>
47 #include <xmloff/xmluconv.hxx>
48 #include <xmloff/nmspmap.hxx>
49 #include <xmloff/families.hxx>
50 #include <xmloff/xmltoken.hxx>
51 
52 using ::rtl::OUString;
53 using ::rtl::OUStringBuffer;
54 
55 using namespace ::com::sun::star;
56 using namespace ::xmloff::token;
57 
58 //-------------------------------------------------------------------------
59 
60 struct SvXMLNumFmtEntry
61 {
62     rtl::OUString   aName;
63     sal_uInt32      nKey;
64     sal_Bool        bRemoveAfterUse;
65 
SvXMLNumFmtEntrySvXMLNumFmtEntry66     SvXMLNumFmtEntry( const rtl::OUString& rN, sal_uInt32 nK, sal_Bool bR ) :
67         aName(rN), nKey(nK), bRemoveAfterUse(bR) {}
68 };
69 
70 typedef SvXMLNumFmtEntry* SvXMLNumFmtEntryPtr;
71 SV_DECL_PTRARR_DEL( SvXMLNumFmtEntryArr, SvXMLNumFmtEntryPtr, 4, 4 )
72 
73 struct SvXMLEmbeddedElement
74 {
75     sal_Int32       nFormatPos;
76     rtl::OUString   aText;
77 
SvXMLEmbeddedElementSvXMLEmbeddedElement78     SvXMLEmbeddedElement( sal_Int32 nFP, const rtl::OUString& rT ) :
79         nFormatPos(nFP), aText(rT) {}
80 
81     //  comparison operators for PTRARR sorting - sorted by position
operator ==SvXMLEmbeddedElement82     sal_Bool operator ==( const SvXMLEmbeddedElement& r ) const { return nFormatPos == r.nFormatPos; }
operator <SvXMLEmbeddedElement83     sal_Bool operator < ( const SvXMLEmbeddedElement& r ) const { return nFormatPos <  r.nFormatPos; }
84 };
85 
86 typedef SvXMLEmbeddedElement* SvXMLEmbeddedElementPtr;
87 SV_DECL_PTRARR_SORT_DEL( SvXMLEmbeddedElementArr, SvXMLEmbeddedElementPtr, 0, 4 )
88 
89 //-------------------------------------------------------------------------
90 
91 class SvXMLNumImpData
92 {
93     SvNumberFormatter*  pFormatter;
94     SvXMLTokenMap*      pStylesElemTokenMap;
95     SvXMLTokenMap*      pStyleElemTokenMap;
96     SvXMLTokenMap*      pStyleAttrTokenMap;
97     SvXMLTokenMap*      pStyleElemAttrTokenMap;
98     LocaleDataWrapper*  pLocaleData;
99     SvXMLNumFmtEntryArr aNameEntries;
100 
101     // #110680#
102     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxServiceFactory;
103 
104 public:
105     // #110680#
106     // SvXMLNumImpData( SvNumberFormatter* pFmt );
107     SvXMLNumImpData(
108         SvNumberFormatter* pFmt,
109         const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory );
110     ~SvXMLNumImpData();
111 
GetNumberFormatter() const112     SvNumberFormatter*      GetNumberFormatter() const  { return pFormatter; }
113     const SvXMLTokenMap&    GetStylesElemTokenMap();
114     const SvXMLTokenMap&    GetStyleElemTokenMap();
115     const SvXMLTokenMap&    GetStyleAttrTokenMap();
116     const SvXMLTokenMap&    GetStyleElemAttrTokenMap();
117     const LocaleDataWrapper&    GetLocaleData( LanguageType nLang );
118     sal_uInt32              GetKeyForName( const rtl::OUString& rName );
119     void                    AddKey( sal_uInt32 nKey, const rtl::OUString& rName, sal_Bool bRemoveAfterUse );
120     void                    SetUsed( sal_uInt32 nKey );
121     void                    RemoveVolatileFormats();
122 };
123 
124 
125 struct SvXMLNumberInfo
126 {
127     sal_Int32   nDecimals;
128     sal_Int32   nMinDecimals;
129     sal_Int32   nInteger;
130     sal_Int32   nExpDigits;
131     sal_Int32   nNumerDigits;
132     sal_Int32   nDenomDigits;
133     sal_Bool    bGrouping;
134     sal_Bool    bDecReplace;
135     sal_Bool    bVarDecimals;
136     double      fDisplayFactor;
137     SvXMLEmbeddedElementArr aEmbeddedElements;
138 
SvXMLNumberInfoSvXMLNumberInfo139     SvXMLNumberInfo()
140     {
141         nDecimals = nMinDecimals = nInteger = nExpDigits = nNumerDigits = nDenomDigits = -1;
142         bGrouping = bDecReplace = bVarDecimals = sal_False;
143         fDisplayFactor = 1.0;
144     }
145 };
146 
147 class SvXMLNumFmtElementContext : public SvXMLImportContext
148 {
149     SvXMLNumFormatContext&  rParent;
150     sal_uInt16              nType;
151     rtl::OUStringBuffer     aContent;
152     SvXMLNumberInfo         aNumInfo;
153     LanguageType            nElementLang;
154     sal_Bool                bLong;
155     sal_Bool                bTextual;
156     rtl::OUString           sCalendar;
157 
158 public:
159                 SvXMLNumFmtElementContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
160                                     const rtl::OUString& rLName,
161                                     SvXMLNumFormatContext& rParentContext, sal_uInt16 nNewType,
162                                     const ::com::sun::star::uno::Reference<
163                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
164     virtual     ~SvXMLNumFmtElementContext();
165 
166     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
167                                     const rtl::OUString& rLocalName,
168                                     const ::com::sun::star::uno::Reference<
169                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
170     virtual void Characters( const rtl::OUString& rChars );
171     virtual void EndElement();
172 
173     void    AddEmbeddedElement( sal_Int32 nFormatPos, const rtl::OUString& rContent );
174 };
175 
176 
177 class SvXMLNumFmtEmbeddedTextContext : public SvXMLImportContext
178 {
179     SvXMLNumFmtElementContext&  rParent;
180     rtl::OUStringBuffer         aContent;
181     sal_Int32                   nTextPosition;
182 
183 public:
184                 SvXMLNumFmtEmbeddedTextContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
185                                     const rtl::OUString& rLName,
186                                     SvXMLNumFmtElementContext& rParentContext,
187                                     const ::com::sun::star::uno::Reference<
188                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
189     virtual     ~SvXMLNumFmtEmbeddedTextContext();
190 
191     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
192                                     const rtl::OUString& rLocalName,
193                                     const ::com::sun::star::uno::Reference<
194                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
195     virtual void Characters( const rtl::OUString& rChars );
196     virtual void EndElement();
197 };
198 
199 
200 class SvXMLNumFmtMapContext : public SvXMLImportContext
201 {
202     SvXMLNumFormatContext&  rParent;
203     rtl::OUString           sCondition;
204     rtl::OUString           sName;
205 
206 public:
207                 SvXMLNumFmtMapContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
208                                     const rtl::OUString& rLName,
209                                     SvXMLNumFormatContext& rParentContext,
210                                     const ::com::sun::star::uno::Reference<
211                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
212     virtual     ~SvXMLNumFmtMapContext();
213 
214     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
215                                     const rtl::OUString& rLocalName,
216                                     const ::com::sun::star::uno::Reference<
217                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
218     virtual void Characters( const rtl::OUString& rChars );
219     virtual void EndElement();
220 };
221 
222 
223 class SvXMLNumFmtPropContext : public SvXMLImportContext
224 {
225     SvXMLNumFormatContext&  rParent;
226     Color                   aColor;
227     sal_Bool                bColSet;
228 
229 public:
230                 SvXMLNumFmtPropContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
231                                     const rtl::OUString& rLName,
232                                     SvXMLNumFormatContext& rParentContext,
233                                     const ::com::sun::star::uno::Reference<
234                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
235     virtual     ~SvXMLNumFmtPropContext();
236 
237     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
238                                     const rtl::OUString& rLocalName,
239                                     const ::com::sun::star::uno::Reference<
240                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
241     virtual void Characters( const rtl::OUString& rChars );
242     virtual void EndElement();
243 };
244 
245 
246 //-------------------------------------------------------------------------
247 
248 enum SvXMLStyleTokens
249 {
250     XML_TOK_STYLE_TEXT,
251     XML_TOK_STYLE_NUMBER,
252     XML_TOK_STYLE_SCIENTIFIC_NUMBER,
253     XML_TOK_STYLE_FRACTION,
254     XML_TOK_STYLE_CURRENCY_SYMBOL,
255     XML_TOK_STYLE_DAY,
256     XML_TOK_STYLE_MONTH,
257     XML_TOK_STYLE_YEAR,
258     XML_TOK_STYLE_ERA,
259     XML_TOK_STYLE_DAY_OF_WEEK,
260     XML_TOK_STYLE_WEEK_OF_YEAR,
261     XML_TOK_STYLE_QUARTER,
262     XML_TOK_STYLE_HOURS,
263     XML_TOK_STYLE_AM_PM,
264     XML_TOK_STYLE_MINUTES,
265     XML_TOK_STYLE_SECONDS,
266     XML_TOK_STYLE_BOOLEAN,
267     XML_TOK_STYLE_TEXT_CONTENT,
268     XML_TOK_STYLE_FILL_CHARACTER,
269     XML_TOK_STYLE_PROPERTIES,
270     XML_TOK_STYLE_MAP
271 };
272 
273 enum SvXMLStyleAttrTokens
274 {
275     XML_TOK_STYLE_ATTR_NAME,
276     XML_TOK_STYLE_ATTR_LANGUAGE,
277     XML_TOK_STYLE_ATTR_COUNTRY,
278     XML_TOK_STYLE_ATTR_TITLE,
279     XML_TOK_STYLE_ATTR_AUTOMATIC_ORDER,
280     XML_TOK_STYLE_ATTR_FORMAT_SOURCE,
281     XML_TOK_STYLE_ATTR_TRUNCATE_ON_OVERFLOW,
282     XML_TOK_STYLE_ATTR_VOLATILE,
283     XML_TOK_STYLE_ATTR_TRANSL_FORMAT,
284     XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE,
285     XML_TOK_STYLE_ATTR_TRANSL_COUNTRY,
286     XML_TOK_STYLE_ATTR_TRANSL_STYLE
287 };
288 
289 enum SvXMLStyleElemAttrTokens
290 {
291     XML_TOK_ELEM_ATTR_DECIMAL_PLACES,
292     XML_TOK_ELEM_ATTR_MIN_DECIMAL_PLACES,
293     XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS,
294     XML_TOK_ELEM_ATTR_GROUPING,
295     XML_TOK_ELEM_ATTR_DISPLAY_FACTOR,
296     XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT,
297     XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS,
298     XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS,
299     XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS,
300     XML_TOK_ELEM_ATTR_LANGUAGE,
301     XML_TOK_ELEM_ATTR_COUNTRY,
302     XML_TOK_ELEM_ATTR_STYLE,
303     XML_TOK_ELEM_ATTR_TEXTUAL,
304     XML_TOK_ELEM_ATTR_CALENDAR
305 };
306 
307 //-------------------------------------------------------------------------
308 
309 //
310 //  standard colors
311 //
312 
313 #define XML_NUMF_COLORCOUNT     10
314 
315 static ColorData aNumFmtStdColors[XML_NUMF_COLORCOUNT] =
316 {
317     COL_BLACK,
318     COL_LIGHTBLUE,
319     COL_LIGHTGREEN,
320     COL_LIGHTCYAN,
321     COL_LIGHTRED,
322     COL_LIGHTMAGENTA,
323     COL_BROWN,
324     COL_GRAY,
325     COL_YELLOW,
326     COL_WHITE
327 };
328 
329 //
330 //  token maps
331 //
332 
333 // maps for SvXMLUnitConverter::convertEnum
334 
335 static __FAR_DATA SvXMLEnumMapEntry aStyleValueMap[] =
336 {
337     { XML_SHORT,            sal_False   },
338     { XML_LONG,             sal_True    },
339     { XML_TOKEN_INVALID,    0 }
340 };
341 
342 static __FAR_DATA SvXMLEnumMapEntry aFormatSourceMap[] =
343 {
344     { XML_FIXED,            sal_False },
345     { XML_LANGUAGE,         sal_True  },
346     { XML_TOKEN_INVALID,    0 }
347 };
348 
349 //-------------------------------------------------------------------------
350 
351 struct SvXMLDefaultDateFormat
352 {
353     NfIndexTableOffset          eFormat;
354     SvXMLDateElementAttributes  eDOW;
355     SvXMLDateElementAttributes  eDay;
356     SvXMLDateElementAttributes  eMonth;
357     SvXMLDateElementAttributes  eYear;
358     SvXMLDateElementAttributes  eHours;
359     SvXMLDateElementAttributes  eMins;
360     SvXMLDateElementAttributes  eSecs;
361     sal_Bool                    bSystem;
362 };
363 
364 static __FAR_DATA SvXMLDefaultDateFormat aDefaultDateFormats[] =
365 {
366     // format                           day-of-week     day             month               year            hours           minutes         seconds         format-source
367 
368     { NF_DATE_SYSTEM_SHORT,             XML_DEA_NONE,   XML_DEA_ANY,    XML_DEA_ANY,        XML_DEA_ANY,    XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_True },
369     { NF_DATE_SYSTEM_LONG,              XML_DEA_ANY,    XML_DEA_ANY,    XML_DEA_ANY,        XML_DEA_ANY,    XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_True },
370     { NF_DATE_SYS_MMYY,                 XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_LONG,       XML_DEA_SHORT,  XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
371     { NF_DATE_SYS_DDMMM,                XML_DEA_NONE,   XML_DEA_LONG,   XML_DEA_TEXTSHORT,  XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
372     { NF_DATE_SYS_DDMMYYYY,             XML_DEA_NONE,   XML_DEA_LONG,   XML_DEA_LONG,       XML_DEA_LONG,   XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
373     { NF_DATE_SYS_DDMMYY,               XML_DEA_NONE,   XML_DEA_LONG,   XML_DEA_LONG,       XML_DEA_SHORT,  XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
374     { NF_DATE_SYS_DMMMYY,               XML_DEA_NONE,   XML_DEA_SHORT,  XML_DEA_TEXTSHORT,  XML_DEA_SHORT,  XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
375     { NF_DATE_SYS_DMMMYYYY,             XML_DEA_NONE,   XML_DEA_SHORT,  XML_DEA_TEXTSHORT,  XML_DEA_LONG,   XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
376     { NF_DATE_SYS_DMMMMYYYY,            XML_DEA_NONE,   XML_DEA_SHORT,  XML_DEA_TEXTLONG,   XML_DEA_LONG,   XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
377     { NF_DATE_SYS_NNDMMMYY,             XML_DEA_SHORT,  XML_DEA_SHORT,  XML_DEA_TEXTSHORT,  XML_DEA_SHORT,  XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
378     { NF_DATE_SYS_NNDMMMMYYYY,          XML_DEA_SHORT,  XML_DEA_SHORT,  XML_DEA_TEXTLONG,   XML_DEA_LONG,   XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
379     { NF_DATE_SYS_NNNNDMMMMYYYY,        XML_DEA_LONG,   XML_DEA_SHORT,  XML_DEA_TEXTLONG,   XML_DEA_LONG,   XML_DEA_NONE,   XML_DEA_NONE,   XML_DEA_NONE,   sal_False },
380     { NF_DATETIME_SYSTEM_SHORT_HHMM,    XML_DEA_NONE,   XML_DEA_ANY,    XML_DEA_ANY,        XML_DEA_ANY,    XML_DEA_ANY,    XML_DEA_ANY,    XML_DEA_NONE,   sal_True },
381     { NF_DATETIME_SYS_DDMMYYYY_HHMMSS,  XML_DEA_NONE,   XML_DEA_ANY,    XML_DEA_ANY,        XML_DEA_ANY,    XML_DEA_ANY,    XML_DEA_ANY,    XML_DEA_ANY,    sal_False }
382 };
383 
384 //-------------------------------------------------------------------------
385 
386 SV_IMPL_PTRARR( SvXMLNumFmtEntryArr, SvXMLNumFmtEntryPtr );
387 SV_IMPL_OP_PTRARR_SORT( SvXMLEmbeddedElementArr, SvXMLEmbeddedElementPtr );
388 
389 //-------------------------------------------------------------------------
390 
391 //
392 //  SvXMLNumImpData
393 //
394 
395 // #110680#
396 // SvXMLNumImpData::SvXMLNumImpData( SvNumberFormatter* pFmt ) :
SvXMLNumImpData(SvNumberFormatter * pFmt,const uno::Reference<lang::XMultiServiceFactory> & xServiceFactory)397 SvXMLNumImpData::SvXMLNumImpData(
398     SvNumberFormatter* pFmt,
399     const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory )
400 :   pFormatter(pFmt),
401     pStylesElemTokenMap(NULL),
402     pStyleElemTokenMap(NULL),
403     pStyleAttrTokenMap(NULL),
404     pStyleElemAttrTokenMap(NULL),
405     pLocaleData(NULL),
406 
407     // #110680#
408     mxServiceFactory(xServiceFactory)
409 {
410     DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
411 }
412 
~SvXMLNumImpData()413 SvXMLNumImpData::~SvXMLNumImpData()
414 {
415     delete pStylesElemTokenMap;
416     delete pStyleElemTokenMap;
417     delete pStyleAttrTokenMap;
418     delete pStyleElemAttrTokenMap;
419     delete pLocaleData;
420 }
421 
GetKeyForName(const rtl::OUString & rName)422 sal_uInt32 SvXMLNumImpData::GetKeyForName( const rtl::OUString& rName )
423 {
424     sal_uInt16 nCount = aNameEntries.Count();
425     for (sal_uInt16 i=0; i<nCount; i++)
426     {
427         const SvXMLNumFmtEntry* pObj = aNameEntries[i];
428         if ( pObj->aName == rName )
429             return pObj->nKey;              // found
430     }
431     return NUMBERFORMAT_ENTRY_NOT_FOUND;
432 }
433 
AddKey(sal_uInt32 nKey,const rtl::OUString & rName,sal_Bool bRemoveAfterUse)434 void SvXMLNumImpData::AddKey( sal_uInt32 nKey, const rtl::OUString& rName, sal_Bool bRemoveAfterUse )
435 {
436     if ( bRemoveAfterUse )
437     {
438         //  if there is already an entry for this key without the bRemoveAfterUse flag,
439         //  clear the flag for this entry, too
440 
441         sal_uInt16 nCount = aNameEntries.Count();
442         for (sal_uInt16 i=0; i<nCount; i++)
443         {
444             SvXMLNumFmtEntry* pObj = aNameEntries[i];
445             if ( pObj->nKey == nKey && !pObj->bRemoveAfterUse )
446             {
447                 bRemoveAfterUse = sal_False;        // clear flag for new entry
448                 break;
449             }
450         }
451     }
452     else
453     {
454         //  call SetUsed to clear the bRemoveAfterUse flag for other entries for this key
455         SetUsed( nKey );
456     }
457 
458     SvXMLNumFmtEntry* pObj = new SvXMLNumFmtEntry( rName, nKey, bRemoveAfterUse );
459     aNameEntries.Insert( pObj, aNameEntries.Count() );
460 }
461 
SetUsed(sal_uInt32 nKey)462 void SvXMLNumImpData::SetUsed( sal_uInt32 nKey )
463 {
464     sal_uInt16 nCount = aNameEntries.Count();
465     for (sal_uInt16 i=0; i<nCount; i++)
466     {
467         SvXMLNumFmtEntry* pObj = aNameEntries[i];
468         if ( pObj->nKey == nKey )
469         {
470             pObj->bRemoveAfterUse = sal_False;      // used -> don't remove
471 
472             //  continue searching - there may be several entries for the same key
473             //  (with different names), the format must not be deleted if any one of
474             //  them is used
475         }
476     }
477 }
478 
RemoveVolatileFormats()479 void SvXMLNumImpData::RemoveVolatileFormats()
480 {
481     //  remove temporary (volatile) formats from NumberFormatter
482     //  called at the end of each import (styles and content), so volatile formats
483     //  from styles can't be used in content
484 
485     if ( !pFormatter )
486         return;
487 
488     sal_uInt16 nCount = aNameEntries.Count();
489     for (sal_uInt16 i=0; i<nCount; i++)
490     {
491         const SvXMLNumFmtEntry* pObj = aNameEntries[i];
492         if ( pObj->bRemoveAfterUse )
493         {
494             const SvNumberformat* pFormat = pFormatter->GetEntry(pObj->nKey);
495             if (pFormat && (pFormat->GetType() & NUMBERFORMAT_DEFINED))
496                 pFormatter->DeleteEntry( pObj->nKey );
497         }
498     }
499 }
500 
GetStylesElemTokenMap()501 const SvXMLTokenMap& SvXMLNumImpData::GetStylesElemTokenMap()
502 {
503     if( !pStylesElemTokenMap )
504     {
505         static __FAR_DATA SvXMLTokenMapEntry aStylesElemMap[] =
506         {
507             //  style elements
508             { XML_NAMESPACE_NUMBER, XML_NUMBER_STYLE,      XML_TOK_STYLES_NUMBER_STYLE      },
509             { XML_NAMESPACE_NUMBER, XML_CURRENCY_STYLE,    XML_TOK_STYLES_CURRENCY_STYLE    },
510             { XML_NAMESPACE_NUMBER, XML_PERCENTAGE_STYLE,  XML_TOK_STYLES_PERCENTAGE_STYLE  },
511             { XML_NAMESPACE_NUMBER, XML_DATE_STYLE,        XML_TOK_STYLES_DATE_STYLE        },
512             { XML_NAMESPACE_NUMBER, XML_TIME_STYLE,        XML_TOK_STYLES_TIME_STYLE        },
513             { XML_NAMESPACE_NUMBER, XML_BOOLEAN_STYLE,     XML_TOK_STYLES_BOOLEAN_STYLE     },
514             { XML_NAMESPACE_NUMBER, XML_TEXT_STYLE,        XML_TOK_STYLES_TEXT_STYLE        },
515             XML_TOKEN_MAP_END
516         };
517 
518         pStylesElemTokenMap = new SvXMLTokenMap( aStylesElemMap );
519     }
520     return *pStylesElemTokenMap;
521 }
522 
GetStyleElemTokenMap()523 const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemTokenMap()
524 {
525     if( !pStyleElemTokenMap )
526     {
527         static __FAR_DATA SvXMLTokenMapEntry aStyleElemMap[] =
528         {
529             //  elements in a style
530             { XML_NAMESPACE_NUMBER, XML_TEXT,               XML_TOK_STYLE_TEXT              },
531             { XML_NAMESPACE_NUMBER, XML_NUMBER,             XML_TOK_STYLE_NUMBER            },
532             { XML_NAMESPACE_NUMBER, XML_SCIENTIFIC_NUMBER,  XML_TOK_STYLE_SCIENTIFIC_NUMBER },
533             { XML_NAMESPACE_NUMBER, XML_FRACTION,           XML_TOK_STYLE_FRACTION          },
534             { XML_NAMESPACE_NUMBER, XML_CURRENCY_SYMBOL,    XML_TOK_STYLE_CURRENCY_SYMBOL   },
535             { XML_NAMESPACE_NUMBER, XML_DAY,                XML_TOK_STYLE_DAY               },
536             { XML_NAMESPACE_NUMBER, XML_MONTH,              XML_TOK_STYLE_MONTH             },
537             { XML_NAMESPACE_NUMBER, XML_YEAR,               XML_TOK_STYLE_YEAR              },
538             { XML_NAMESPACE_NUMBER, XML_ERA,                XML_TOK_STYLE_ERA               },
539             { XML_NAMESPACE_NUMBER, XML_DAY_OF_WEEK,        XML_TOK_STYLE_DAY_OF_WEEK       },
540             { XML_NAMESPACE_NUMBER, XML_WEEK_OF_YEAR,       XML_TOK_STYLE_WEEK_OF_YEAR      },
541             { XML_NAMESPACE_NUMBER, XML_QUARTER,            XML_TOK_STYLE_QUARTER           },
542             { XML_NAMESPACE_NUMBER, XML_HOURS,              XML_TOK_STYLE_HOURS             },
543             { XML_NAMESPACE_NUMBER, XML_AM_PM,              XML_TOK_STYLE_AM_PM             },
544             { XML_NAMESPACE_NUMBER, XML_MINUTES,            XML_TOK_STYLE_MINUTES           },
545             { XML_NAMESPACE_NUMBER, XML_SECONDS,            XML_TOK_STYLE_SECONDS           },
546             { XML_NAMESPACE_NUMBER, XML_BOOLEAN,            XML_TOK_STYLE_BOOLEAN           },
547             { XML_NAMESPACE_NUMBER, XML_TEXT_CONTENT,       XML_TOK_STYLE_TEXT_CONTENT      },
548             { XML_NAMESPACE_NUMBER, XML_FILL_CHARACTER, XML_TOK_STYLE_FILL_CHARACTER    },
549             { XML_NAMESPACE_STYLE,  XML_TEXT_PROPERTIES,    XML_TOK_STYLE_PROPERTIES        },
550             { XML_NAMESPACE_STYLE,  XML_MAP,                XML_TOK_STYLE_MAP               },
551             XML_TOKEN_MAP_END
552         };
553 
554         pStyleElemTokenMap = new SvXMLTokenMap( aStyleElemMap );
555     }
556     return *pStyleElemTokenMap;
557 }
558 
GetStyleAttrTokenMap()559 const SvXMLTokenMap& SvXMLNumImpData::GetStyleAttrTokenMap()
560 {
561     if( !pStyleAttrTokenMap )
562     {
563         static __FAR_DATA SvXMLTokenMapEntry aStyleAttrMap[] =
564         {
565             //  attributes for a style
566             { XML_NAMESPACE_STYLE,  XML_NAME,                  XML_TOK_STYLE_ATTR_NAME                  },
567             { XML_NAMESPACE_NUMBER, XML_LANGUAGE,              XML_TOK_STYLE_ATTR_LANGUAGE              },
568             { XML_NAMESPACE_NUMBER, XML_COUNTRY,               XML_TOK_STYLE_ATTR_COUNTRY               },
569             { XML_NAMESPACE_NUMBER, XML_TITLE,                 XML_TOK_STYLE_ATTR_TITLE                 },
570             { XML_NAMESPACE_NUMBER, XML_AUTOMATIC_ORDER,       XML_TOK_STYLE_ATTR_AUTOMATIC_ORDER       },
571             { XML_NAMESPACE_NUMBER, XML_FORMAT_SOURCE,         XML_TOK_STYLE_ATTR_FORMAT_SOURCE         },
572             { XML_NAMESPACE_NUMBER, XML_TRUNCATE_ON_OVERFLOW,  XML_TOK_STYLE_ATTR_TRUNCATE_ON_OVERFLOW  },
573             { XML_NAMESPACE_STYLE,  XML_VOLATILE,              XML_TOK_STYLE_ATTR_VOLATILE              },
574             { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_FORMAT,     XML_TOK_STYLE_ATTR_TRANSL_FORMAT    },
575             { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_LANGUAGE,   XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE  },
576             { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_COUNTRY,    XML_TOK_STYLE_ATTR_TRANSL_COUNTRY   },
577             { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_STYLE,      XML_TOK_STYLE_ATTR_TRANSL_STYLE     },
578             XML_TOKEN_MAP_END
579         };
580 
581         pStyleAttrTokenMap = new SvXMLTokenMap( aStyleAttrMap );
582     }
583     return *pStyleAttrTokenMap;
584 }
585 
GetStyleElemAttrTokenMap()586 const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemAttrTokenMap()
587 {
588     if( !pStyleElemAttrTokenMap )
589     {
590         static __FAR_DATA SvXMLTokenMapEntry aStyleElemAttrMap[] =
591         {
592             //  attributes for an element within a style
593             { XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES,          XML_TOK_ELEM_ATTR_DECIMAL_PLACES       },
594             { XML_NAMESPACE_NUMBER, XML_MIN_DECIMAL_PLACES,      XML_TOK_ELEM_ATTR_MIN_DECIMAL_PLACES   },
595             { XML_NAMESPACE_NUMBER, XML_MIN_INTEGER_DIGITS,      XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS   },
596             { XML_NAMESPACE_NUMBER, XML_GROUPING,                XML_TOK_ELEM_ATTR_GROUPING             },
597             { XML_NAMESPACE_NUMBER, XML_DISPLAY_FACTOR,          XML_TOK_ELEM_ATTR_DISPLAY_FACTOR       },
598             { XML_NAMESPACE_NUMBER, XML_DECIMAL_REPLACEMENT,     XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT  },
599             { XML_NAMESPACE_NUMBER, XML_MIN_EXPONENT_DIGITS,     XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS  },
600             { XML_NAMESPACE_NUMBER, XML_MIN_NUMERATOR_DIGITS,    XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS },
601             { XML_NAMESPACE_NUMBER, XML_MIN_DENOMINATOR_DIGITS,  XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS },
602             { XML_NAMESPACE_NUMBER, XML_LANGUAGE,                XML_TOK_ELEM_ATTR_LANGUAGE             },
603             { XML_NAMESPACE_NUMBER, XML_COUNTRY,                 XML_TOK_ELEM_ATTR_COUNTRY              },
604             { XML_NAMESPACE_NUMBER, XML_STYLE,                   XML_TOK_ELEM_ATTR_STYLE                },
605             { XML_NAMESPACE_NUMBER, XML_TEXTUAL,                 XML_TOK_ELEM_ATTR_TEXTUAL              },
606             { XML_NAMESPACE_NUMBER, XML_CALENDAR,                XML_TOK_ELEM_ATTR_CALENDAR             },
607             XML_TOKEN_MAP_END
608         };
609 
610         pStyleElemAttrTokenMap = new SvXMLTokenMap( aStyleElemAttrMap );
611     }
612     return *pStyleElemAttrTokenMap;
613 }
614 
GetLocaleData(LanguageType nLang)615 const LocaleDataWrapper& SvXMLNumImpData::GetLocaleData( LanguageType nLang )
616 {
617     if ( !pLocaleData )
618         // #110680#
619         //pLocaleData = new LocaleDataWrapper(
620         //  (pFormatter ? pFormatter->GetServiceManager() :
621         //  ::comphelper::getProcessServiceFactory()),
622         //  MsLangId::convertLanguageToLocale( nLang ) );
623         pLocaleData = new LocaleDataWrapper(
624             (pFormatter ? pFormatter->GetServiceManager() :
625             mxServiceFactory),
626             MsLangId::convertLanguageToLocale( nLang ) );
627     else
628         pLocaleData->setLocale( MsLangId::convertLanguageToLocale( nLang ) );
629     return *pLocaleData;
630 }
631 
632 //-------------------------------------------------------------------------
633 
634 //
635 //  SvXMLNumFmtMapContext
636 //
637 
SvXMLNumFmtMapContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumFormatContext & rParentContext,const uno::Reference<xml::sax::XAttributeList> & xAttrList)638 SvXMLNumFmtMapContext::SvXMLNumFmtMapContext( SvXMLImport& rImport,
639                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
640                                     SvXMLNumFormatContext& rParentContext,
641                                     const uno::Reference<xml::sax::XAttributeList>& xAttrList ) :
642     SvXMLImportContext( rImport, nPrfx, rLName ),
643     rParent( rParentContext )
644 {
645     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
646     for( sal_Int16 i=0; i < nAttrCount; i++ )
647     {
648         OUString sAttrName = xAttrList->getNameByIndex( i );
649         OUString sValue = xAttrList->getValueByIndex( i );
650         OUString aLocalName;
651         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
652         if ( nPrefix == XML_NAMESPACE_STYLE )
653         {
654             if ( IsXMLToken( aLocalName, XML_CONDITION) )
655                 sCondition = sValue;
656             else if ( IsXMLToken( aLocalName, XML_APPLY_STYLE_NAME) )
657                 sName = sValue;
658         }
659     }
660 }
661 
~SvXMLNumFmtMapContext()662 SvXMLNumFmtMapContext::~SvXMLNumFmtMapContext()
663 {
664 }
665 
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)666 SvXMLImportContext* SvXMLNumFmtMapContext::CreateChildContext(
667                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
668                                     const uno::Reference<xml::sax::XAttributeList>& )
669 {
670     // no elements supported - use default context
671     return new SvXMLImportContext( GetImport(), nPrfx, rLName );
672 }
673 
Characters(const rtl::OUString &)674 void SvXMLNumFmtMapContext::Characters( const rtl::OUString& )
675 {
676 }
677 
EndElement()678 void SvXMLNumFmtMapContext::EndElement()
679 {
680     rParent.AddCondition( sCondition, sName );
681 }
682 
683 //-------------------------------------------------------------------------
684 
685 //
686 //  SvXMLNumFmtPropContext
687 //
688 
SvXMLNumFmtPropContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumFormatContext & rParentContext,const uno::Reference<xml::sax::XAttributeList> & xAttrList)689 SvXMLNumFmtPropContext::SvXMLNumFmtPropContext( SvXMLImport& rImport,
690                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
691                                     SvXMLNumFormatContext& rParentContext,
692                                     const uno::Reference<xml::sax::XAttributeList>& xAttrList ) :
693     SvXMLImportContext( rImport, nPrfx, rLName ),
694     rParent( rParentContext ),
695     bColSet( sal_False )
696 {
697     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
698     for( sal_Int16 i=0; i < nAttrCount; i++ )
699     {
700         OUString sAttrName = xAttrList->getNameByIndex( i );
701         OUString sValue = xAttrList->getValueByIndex( i );
702         OUString aLocalName;
703         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
704         if ( nPrefix == XML_NAMESPACE_FO && IsXMLToken( aLocalName, XML_COLOR ) )
705             bColSet = SvXMLUnitConverter::convertColor( aColor, sValue );
706     }
707 }
708 
~SvXMLNumFmtPropContext()709 SvXMLNumFmtPropContext::~SvXMLNumFmtPropContext()
710 {
711 }
712 
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)713 SvXMLImportContext* SvXMLNumFmtPropContext::CreateChildContext(
714                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
715                                     const uno::Reference<xml::sax::XAttributeList>& )
716 {
717     // no elements supported - use default context
718     return new SvXMLImportContext( GetImport(), nPrfx, rLName );
719 }
720 
Characters(const rtl::OUString &)721 void SvXMLNumFmtPropContext::Characters( const rtl::OUString& )
722 {
723 }
724 
EndElement()725 void SvXMLNumFmtPropContext::EndElement()
726 {
727     if (bColSet)
728         rParent.AddColor( aColor );
729 }
730 
731 //-------------------------------------------------------------------------
732 
733 //
734 //  SvXMLNumFmtEmbeddedTextContext
735 //
736 
SvXMLNumFmtEmbeddedTextContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumFmtElementContext & rParentContext,const uno::Reference<xml::sax::XAttributeList> & xAttrList)737 SvXMLNumFmtEmbeddedTextContext::SvXMLNumFmtEmbeddedTextContext( SvXMLImport& rImport,
738                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
739                                     SvXMLNumFmtElementContext& rParentContext,
740                                     const uno::Reference<xml::sax::XAttributeList>& xAttrList ) :
741     SvXMLImportContext( rImport, nPrfx, rLName ),
742     rParent( rParentContext ),
743     nTextPosition( 0 )
744 {
745     sal_Int32 nAttrVal;
746 
747     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
748     for( sal_Int16 i=0; i < nAttrCount; i++ )
749     {
750         OUString sAttrName = xAttrList->getNameByIndex( i );
751         OUString sValue = xAttrList->getValueByIndex( i );
752         OUString aLocalName;
753         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
754         if ( nPrefix == XML_NAMESPACE_NUMBER && IsXMLToken( aLocalName, XML_POSITION ) )
755         {
756             if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
757                 nTextPosition = nAttrVal;
758         }
759     }
760 }
761 
~SvXMLNumFmtEmbeddedTextContext()762 SvXMLNumFmtEmbeddedTextContext::~SvXMLNumFmtEmbeddedTextContext()
763 {
764 }
765 
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)766 SvXMLImportContext* SvXMLNumFmtEmbeddedTextContext::CreateChildContext(
767                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
768                                     const uno::Reference<xml::sax::XAttributeList>& )
769 {
770     // no elements supported - use default context
771     return new SvXMLImportContext( GetImport(), nPrfx, rLName );
772 }
773 
Characters(const rtl::OUString & rChars)774 void SvXMLNumFmtEmbeddedTextContext::Characters( const rtl::OUString& rChars )
775 {
776     aContent.append( rChars );
777 }
778 
EndElement()779 void SvXMLNumFmtEmbeddedTextContext::EndElement()
780 {
781     rParent.AddEmbeddedElement( nTextPosition, aContent.makeStringAndClear() );
782 }
783 
784 //-------------------------------------------------------------------------
785 
lcl_ValidChar(sal_Unicode cChar,const SvXMLNumFormatContext & rParent)786 sal_Bool lcl_ValidChar( sal_Unicode cChar, const SvXMLNumFormatContext& rParent )
787 {
788     sal_uInt16 nFormatType = rParent.GetType();
789 
790     // Treat space equal to non-breaking space separator.
791     const sal_Unicode cNBSP = 0x00A0;
792     sal_Unicode cTS;
793     if ( ( nFormatType == XML_TOK_STYLES_NUMBER_STYLE ||
794            nFormatType == XML_TOK_STYLES_CURRENCY_STYLE ||
795            nFormatType == XML_TOK_STYLES_PERCENTAGE_STYLE ) &&
796             (cChar == (cTS = rParent.GetLocaleData().getNumThousandSep().GetChar(0)) ||
797              (cChar == ' ' && cTS == cNBSP)) )
798     {
799         //  #i22394# Extra occurrences of thousands separator must be quoted, so they
800         //  aren't mis-interpreted as display-factor.
801         //  This must be limited to the format types that can contain a number element,
802         //  because the same character can be a date separator that should not be quoted
803         //  in date formats.
804 
805         return sal_False;   // force quotes
806     }
807 
808     //  see ImpSvNumberformatScan::Next_Symbol
809     if ( cChar == ' ' ||
810          cChar == '-' ||
811          cChar == '/' ||
812          cChar == '.' ||
813          cChar == ',' ||
814          cChar == ':' ||
815          cChar == '\'' )
816         return sal_True;    // for all format types
817 
818     //  percent sign must be used without quotes for percentage styles only
819     if ( nFormatType == XML_TOK_STYLES_PERCENTAGE_STYLE && cChar == '%' )
820         return sal_True;
821 
822     //  don't put quotes around single parentheses (often used for negative numbers)
823     if ( ( nFormatType == XML_TOK_STYLES_NUMBER_STYLE ||
824            nFormatType == XML_TOK_STYLES_CURRENCY_STYLE ||
825            nFormatType == XML_TOK_STYLES_PERCENTAGE_STYLE ) &&
826          ( cChar == '(' || cChar == ')' ) )
827         return sal_True;
828 
829     return sal_False;
830 }
831 
lcl_EnquoteIfNecessary(rtl::OUStringBuffer & rContent,const SvXMLNumFormatContext & rParent)832 void lcl_EnquoteIfNecessary( rtl::OUStringBuffer& rContent, const SvXMLNumFormatContext& rParent )
833 {
834     sal_Bool bQuote = sal_True;
835     sal_Int32 nLength = rContent.getLength();
836 
837     if ( ( nLength == 1 &&
838             lcl_ValidChar( rContent.charAt(0), rParent ) ) ||
839          ( nLength == 2 &&
840             lcl_ValidChar( rContent.charAt(0), rParent ) &&
841             rContent.charAt(1) == ' ' ) )
842     {
843         //  don't quote single separator characters like space or percent,
844         //  or separator characters followed by space (used in date formats)
845         bQuote = sal_False;
846     }
847     else if ( rParent.GetType() == XML_TOK_STYLES_PERCENTAGE_STYLE && nLength > 1 )
848     {
849         //  the percent character in percentage styles must be left out of quoting
850         //  (one occurrence is enough even if there are several percent characters in the string)
851 
852         rtl::OUString aString( rContent.getStr() );
853         sal_Int32 nPos = aString.indexOf( (sal_Unicode) '%' );
854         if ( nPos >= 0 )
855         {
856             if ( nPos + 1 < nLength )
857             {
858                 if ( nPos + 2 == nLength && lcl_ValidChar( rContent.charAt(nPos + 1), rParent ) )
859                 {
860                     //  single character that doesn't need quoting
861                 }
862                 else
863                 {
864                     //  quote text behind percent character
865                     rContent.insert( nPos + 1, (sal_Unicode) '"' );
866                     rContent.append( (sal_Unicode) '"' );
867                 }
868             }
869             if ( nPos > 0 )
870             {
871                 if ( nPos == 1 && lcl_ValidChar( rContent.charAt(0), rParent ) )
872                 {
873                     //  single character that doesn't need quoting
874                 }
875                 else
876                 {
877                     //  quote text before percent character
878                     rContent.insert( nPos, (sal_Unicode) '"' );
879                     rContent.insert( 0, (sal_Unicode) '"' );
880                 }
881             }
882             bQuote = sal_False;
883         }
884         // else: normal quoting (below)
885     }
886 
887     if ( bQuote )
888     {
889         // #i55469# quotes in the string itself have to be escaped
890         rtl::OUString aString( rContent.getStr() );
891         bool bEscape = ( aString.indexOf( (sal_Unicode) '"' ) >= 0 );
892         if ( bEscape )
893         {
894             // A quote is turned into "\"" - a quote to end quoted text, an escaped quote,
895             // and a quote to resume quoting.
896             rtl::OUString aInsert( rtl::OUString::createFromAscii( "\"\\\"" ) );
897 
898             sal_Int32 nPos = 0;
899             while ( nPos < rContent.getLength() )
900             {
901                 if ( rContent.charAt( nPos ) == (sal_Unicode) '"' )
902                 {
903                     rContent.insert( nPos, aInsert );
904                     nPos += aInsert.getLength();
905                 }
906                 ++nPos;
907             }
908         }
909 
910         //  quote string literals
911         rContent.insert( 0, (sal_Unicode) '"' );
912         rContent.append( (sal_Unicode) '"' );
913 
914         // remove redundant double quotes at start or end
915         if ( bEscape )
916         {
917             if ( rContent.getLength() > 2 &&
918                  rContent.charAt(0) == (sal_Unicode) '"' &&
919                  rContent.charAt(1) == (sal_Unicode) '"' )
920             {
921                 String aTrimmed( rContent.makeStringAndClear().copy(2) );
922                 rContent = rtl::OUStringBuffer( aTrimmed );
923             }
924 
925             sal_Int32 nLen = rContent.getLength();
926             if ( nLen > 2 &&
927                  rContent.charAt(nLen-1) == (sal_Unicode) '"' &&
928                  rContent.charAt(nLen-2) == (sal_Unicode) '"' )
929             {
930                 String aTrimmed( rContent.makeStringAndClear().copy( 0, nLen - 2 ) );
931                 rContent = rtl::OUStringBuffer( aTrimmed );
932             }
933         }
934     }
935 }
936 
937 //
938 //  SvXMLNumFmtElementContext
939 //
940 
SvXMLNumFmtElementContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumFormatContext & rParentContext,sal_uInt16 nNewType,const uno::Reference<xml::sax::XAttributeList> & xAttrList)941 SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport,
942                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
943                                     SvXMLNumFormatContext& rParentContext, sal_uInt16 nNewType,
944                                     const uno::Reference<xml::sax::XAttributeList>& xAttrList ) :
945     SvXMLImportContext( rImport, nPrfx, rLName ),
946     rParent( rParentContext ),
947     nType( nNewType ),
948     nElementLang( LANGUAGE_SYSTEM ),
949     bLong( sal_False ),
950     bTextual( sal_False )
951 {
952     OUString sLanguage, sCountry;
953     sal_Int32 nAttrVal;
954     sal_Bool bAttrBool;
955     sal_uInt16 nAttrEnum;
956     double fAttrDouble;
957 
958     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
959     for( sal_Int16 i=0; i < nAttrCount; i++ )
960     {
961         OUString sAttrName = xAttrList->getNameByIndex( i );
962         OUString sValue = xAttrList->getValueByIndex( i );
963         OUString aLocalName;
964         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
965 
966         const SvXMLTokenMap& rTokenMap = rParent.GetData()->GetStyleElemAttrTokenMap();
967         sal_uInt16 nToken = rTokenMap.Get( nPrefix, aLocalName );
968 
969         switch (nToken)
970         {
971             case XML_TOK_ELEM_ATTR_DECIMAL_PLACES:
972                 if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
973                     aNumInfo.nDecimals = nAttrVal;
974                 break;
975             case XML_TOK_ELEM_ATTR_MIN_DECIMAL_PLACES:
976                 if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
977                     aNumInfo.nMinDecimals = nAttrVal;
978                 break;
979             case XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS:
980                 if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
981                     aNumInfo.nInteger = nAttrVal;
982                 break;
983             case XML_TOK_ELEM_ATTR_GROUPING:
984                 if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
985                     aNumInfo.bGrouping = bAttrBool;
986                 break;
987             case XML_TOK_ELEM_ATTR_DISPLAY_FACTOR:
988                 if ( SvXMLUnitConverter::convertDouble( fAttrDouble, sValue ) )
989                     aNumInfo.fDisplayFactor = fAttrDouble;
990                 break;
991             case XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT:
992                 if ( sValue.getLength() > 0 )
993                     aNumInfo.bDecReplace = sal_True;    // only a default string is supported
994                 else
995                     aNumInfo.bVarDecimals = sal_True;   // empty replacement string: variable decimals
996                 break;
997             case XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS:
998                 if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
999                     aNumInfo.nExpDigits = nAttrVal;
1000                 break;
1001             case XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS:
1002                 if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
1003                     aNumInfo.nNumerDigits = nAttrVal;
1004                 break;
1005             case XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS:
1006                 if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
1007                     aNumInfo.nDenomDigits = nAttrVal;
1008                 break;
1009             case XML_TOK_ELEM_ATTR_LANGUAGE:
1010                 sLanguage = sValue;
1011                 break;
1012             case XML_TOK_ELEM_ATTR_COUNTRY:
1013                 sCountry = sValue;
1014                 break;
1015             case XML_TOK_ELEM_ATTR_STYLE:
1016                 if ( SvXMLUnitConverter::convertEnum( nAttrEnum, sValue, aStyleValueMap ) )
1017                     bLong = (sal_Bool) nAttrEnum;
1018                 break;
1019             case XML_TOK_ELEM_ATTR_TEXTUAL:
1020                 if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
1021                     bTextual = bAttrBool;
1022                 break;
1023             case XML_TOK_ELEM_ATTR_CALENDAR:
1024                 sCalendar = sValue;
1025                 break;
1026         }
1027     }
1028 
1029     if ( sLanguage.getLength() || sCountry.getLength() )
1030     {
1031         nElementLang = MsLangId::convertIsoNamesToLanguage( sLanguage, sCountry );
1032         if ( nElementLang == LANGUAGE_DONTKNOW )
1033             nElementLang = LANGUAGE_SYSTEM;         //! error handling for invalid locales?
1034     }
1035 }
1036 
~SvXMLNumFmtElementContext()1037 SvXMLNumFmtElementContext::~SvXMLNumFmtElementContext()
1038 {
1039 }
1040 
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)1041 SvXMLImportContext* SvXMLNumFmtElementContext::CreateChildContext(
1042                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
1043                                     const uno::Reference<xml::sax::XAttributeList>& xAttrList )
1044 {
1045     //  only number:number supports number:embedded-text child element
1046 
1047     if ( nType == XML_TOK_STYLE_NUMBER &&
1048          nPrfx == XML_NAMESPACE_NUMBER && IsXMLToken( rLName, XML_EMBEDDED_TEXT ) )
1049     {
1050         return new SvXMLNumFmtEmbeddedTextContext( GetImport(), nPrfx, rLName, *this, xAttrList );
1051     }
1052     else
1053         return new SvXMLImportContext( GetImport(), nPrfx, rLName );
1054 }
1055 
Characters(const rtl::OUString & rChars)1056 void SvXMLNumFmtElementContext::Characters( const rtl::OUString& rChars )
1057 {
1058     aContent.append( rChars );
1059 }
1060 
AddEmbeddedElement(sal_Int32 nFormatPos,const rtl::OUString & rContent)1061 void SvXMLNumFmtElementContext::AddEmbeddedElement( sal_Int32 nFormatPos, const rtl::OUString& rContent )
1062 {
1063     if ( rContent.getLength() )
1064     {
1065         SvXMLEmbeddedElement* pObj = new SvXMLEmbeddedElement( nFormatPos, rContent );
1066         if ( !aNumInfo.aEmbeddedElements.Insert( pObj ) )
1067         {
1068             //  there's already an element at this position - append text to existing element
1069 
1070             delete pObj;
1071             sal_uInt16 nElementCount = aNumInfo.aEmbeddedElements.Count();
1072             for (sal_uInt16 i=0; i<nElementCount; i++)
1073             {
1074                 pObj = aNumInfo.aEmbeddedElements[i];
1075                 if ( pObj->nFormatPos == nFormatPos )
1076                 {
1077                     pObj->aText += rContent;
1078                     break;
1079                 }
1080             }
1081         }
1082     }
1083 }
1084 
EndElement()1085 void SvXMLNumFmtElementContext::EndElement()
1086 {
1087     sal_Bool bEffLong = bLong;
1088     switch (nType)
1089     {
1090         case XML_TOK_STYLE_TEXT:
1091             if ( rParent.HasLongDoW() &&
1092                     rParent.GetLocaleData().getLongDateDayOfWeekSep() ==
1093                         String( aContent.getStr() ) )
1094             {
1095                 //  skip separator constant after long day of week
1096                 //  (NF_KEY_NNNN contains the separator)
1097 
1098                 if ( rParent.ReplaceNfKeyword( NF_KEY_NNN, NF_KEY_NNNN ) )
1099                 {
1100                     //!aContent.setLength(0);       //! doesn't work, #76293#
1101                     aContent = OUStringBuffer();
1102                 }
1103 
1104                 rParent.SetHasLongDoW( sal_False );     // only once
1105             }
1106             if ( aContent.getLength() )
1107             {
1108                 lcl_EnquoteIfNecessary( aContent, rParent );
1109                 rParent.AddToCode( aContent.makeStringAndClear() );
1110             }
1111             break;
1112 
1113         case XML_TOK_STYLE_NUMBER:
1114             rParent.AddNumber( aNumInfo );
1115             break;
1116 
1117         case XML_TOK_STYLE_CURRENCY_SYMBOL:
1118             rParent.AddCurrency( aContent.makeStringAndClear(), nElementLang );
1119             break;
1120 
1121         case XML_TOK_STYLE_TEXT_CONTENT:
1122             rParent.AddToCode( OUString::valueOf((sal_Unicode)'@') );
1123             break;
1124         case XML_TOK_STYLE_FILL_CHARACTER:
1125             // the formatter accepts one '*' per format, and only a BMP character
1126             if ( aContent.getLength() == 1 && !rParent.HasFillChar() )
1127             {
1128                 rParent.SetHasFillChar();
1129                 rParent.AddToCode( OUString::valueOf((sal_Unicode)'*') + aContent.makeStringAndClear() );
1130             }
1131             break;
1132         case XML_TOK_STYLE_BOOLEAN:
1133             // ignored - only default boolean format is supported
1134             break;
1135 
1136         case XML_TOK_STYLE_DAY:
1137             rParent.UpdateCalendar( sCalendar );
1138 #if 0
1139 //! I18N doesn't provide SYSTEM or extended date information yet
1140             if ( rParent.IsFromSystem() )
1141                 bEffLong = SvXMLNumFmtDefaults::IsSystemLongDay( rParent.GetInternational(), bLong );
1142 #endif
1143             rParent.AddNfKeyword(
1144                 sal::static_int_cast< sal_uInt16 >(
1145                     bEffLong ? NF_KEY_DD : NF_KEY_D ) );
1146             break;
1147         case XML_TOK_STYLE_MONTH:
1148             rParent.UpdateCalendar( sCalendar );
1149 #if 0
1150 //! I18N doesn't provide SYSTEM or extended date information yet
1151             if ( rParent.IsFromSystem() )
1152             {
1153                 bEffLong = SvXMLNumFmtDefaults::IsSystemLongMonth( rParent.GetInternational(), bLong );
1154                 bTextual = SvXMLNumFmtDefaults::IsSystemTextualMonth( rParent.GetInternational(), bLong );
1155             }
1156 #endif
1157             rParent.AddNfKeyword(
1158                 sal::static_int_cast< sal_uInt16 >(
1159                     bTextual
1160                     ? ( bEffLong ? NF_KEY_MMMM : NF_KEY_MMM )
1161                     : ( bEffLong ? NF_KEY_MM : NF_KEY_M ) ) );
1162             break;
1163         case XML_TOK_STYLE_YEAR:
1164             rParent.UpdateCalendar( sCalendar );
1165 #if 0
1166 //! I18N doesn't provide SYSTEM or extended date information yet
1167             if ( rParent.IsFromSystem() )
1168                 bEffLong = SvXMLNumFmtDefaults::IsSystemLongYear( rParent.GetInternational(), bLong );
1169 #endif
1170             // Y after G (era) is replaced by E
1171             if ( rParent.HasEra() )
1172                 rParent.AddNfKeyword(
1173                     sal::static_int_cast< sal_uInt16 >(
1174                         bEffLong ? NF_KEY_EEC : NF_KEY_EC ) );
1175             else
1176                 rParent.AddNfKeyword(
1177                     sal::static_int_cast< sal_uInt16 >(
1178                         bEffLong ? NF_KEY_YYYY : NF_KEY_YY ) );
1179             break;
1180         case XML_TOK_STYLE_ERA:
1181             rParent.UpdateCalendar( sCalendar );
1182 #if 0
1183 //! I18N doesn't provide SYSTEM or extended date information yet
1184             if ( rParent.IsFromSystem() )
1185                 bEffLong = SvXMLNumFmtDefaults::IsSystemLongEra( rParent.GetInternational(), bLong );
1186 #endif
1187             rParent.AddNfKeyword(
1188                 sal::static_int_cast< sal_uInt16 >(
1189                     bEffLong ? NF_KEY_GGG : NF_KEY_G ) );
1190             //  HasEra flag is set
1191             break;
1192         case XML_TOK_STYLE_DAY_OF_WEEK:
1193             rParent.UpdateCalendar( sCalendar );
1194 #if 0
1195 //! I18N doesn't provide SYSTEM or extended date information yet
1196             if ( rParent.IsFromSystem() )
1197                 bEffLong = SvXMLNumFmtDefaults::IsSystemLongDayOfWeek( rParent.GetInternational(), bLong );
1198 #endif
1199             rParent.AddNfKeyword(
1200                 sal::static_int_cast< sal_uInt16 >(
1201                     bEffLong ? NF_KEY_NNNN : NF_KEY_NN ) );
1202             break;
1203         case XML_TOK_STYLE_WEEK_OF_YEAR:
1204             rParent.UpdateCalendar( sCalendar );
1205             rParent.AddNfKeyword( NF_KEY_WW );
1206             break;
1207         case XML_TOK_STYLE_QUARTER:
1208             rParent.UpdateCalendar( sCalendar );
1209             rParent.AddNfKeyword(
1210                 sal::static_int_cast< sal_uInt16 >(
1211                     bEffLong ? NF_KEY_QQ : NF_KEY_Q ) );
1212             break;
1213         case XML_TOK_STYLE_HOURS:
1214             rParent.AddNfKeyword(
1215                 sal::static_int_cast< sal_uInt16 >(
1216                     bEffLong ? NF_KEY_HH : NF_KEY_H ) );
1217             break;
1218         case XML_TOK_STYLE_AM_PM:
1219             //! short/long?
1220             rParent.AddNfKeyword( NF_KEY_AMPM );
1221             break;
1222         case XML_TOK_STYLE_MINUTES:
1223             rParent.AddNfKeyword(
1224                 sal::static_int_cast< sal_uInt16 >(
1225                     bEffLong ? NF_KEY_MMI : NF_KEY_MI ) );
1226             break;
1227         case XML_TOK_STYLE_SECONDS:
1228             rParent.AddNfKeyword(
1229                 sal::static_int_cast< sal_uInt16 >(
1230                     bEffLong ? NF_KEY_SS : NF_KEY_S ) );
1231             if ( aNumInfo.nDecimals > 0 )
1232             {
1233                 //  manually add the decimal places
1234                 const String& rSep = rParent.GetLocaleData().getNumDecimalSep();
1235                 for ( xub_StrLen j=0; j<rSep.Len(); j++ )
1236                 {
1237                     rParent.AddToCode( OUString::valueOf( rSep.GetChar(j) ) );
1238                 }
1239                 for (sal_Int32 i=0; i<aNumInfo.nDecimals; i++)
1240                     rParent.AddToCode( OUString::valueOf((sal_Unicode)'0') );
1241             }
1242             break;
1243 
1244         case XML_TOK_STYLE_FRACTION:
1245             {
1246                 if ( aNumInfo.nInteger >= 0 )
1247                 {
1248                     // add integer part only if min-integer-digits attribute is there
1249                     aNumInfo.nDecimals = 0;
1250                     rParent.AddNumber( aNumInfo );      // number without decimals
1251                     rParent.AddToCode( OUString::valueOf((sal_Unicode)' ') );
1252                 }
1253 
1254                 //! build string and add at once
1255 
1256                 sal_Int32 i;
1257                 for (i=0; i<aNumInfo.nNumerDigits; i++)
1258                     rParent.AddToCode( OUString::valueOf((sal_Unicode)'?') );
1259                 rParent.AddToCode( OUString::valueOf((sal_Unicode)'/') );
1260                 for (i=0; i<aNumInfo.nDenomDigits; i++)
1261                     rParent.AddToCode( OUString::valueOf((sal_Unicode)'?') );
1262             }
1263             break;
1264 
1265         case XML_TOK_STYLE_SCIENTIFIC_NUMBER:
1266             {
1267                 rParent.AddNumber( aNumInfo );      // simple number
1268 
1269                 rParent.AddToCode( OUString::createFromAscii( "E+" ) );
1270                 for (sal_Int32 i=0; i<aNumInfo.nExpDigits; i++)
1271                     rParent.AddToCode( OUString::valueOf((sal_Unicode)'0') );
1272             }
1273             break;
1274 
1275         default:
1276             DBG_ERROR("invalid element ID");
1277     }
1278 }
1279 
1280 //-------------------------------------------------------------------------
1281 
IsSystemLongDay(const SvtSysLocale &,sal_Bool bLong)1282 sal_Bool SvXMLNumFmtDefaults::IsSystemLongDay( const SvtSysLocale&, sal_Bool bLong )
1283 {
1284     // TODO: merge system information and defaults into i18n locale data
1285 #if 0
1286     return bLong ? rIntn.IsLongDateDayLeadingZero() : rIntn.IsDateDayLeadingZero();
1287 #else
1288     return !bLong;
1289 #endif
1290 }
1291 
IsSystemLongMonth(const SvtSysLocale &,sal_Bool bLong)1292 sal_Bool SvXMLNumFmtDefaults::IsSystemLongMonth( const SvtSysLocale&, sal_Bool bLong )
1293 {
1294     // TODO: merge system information and defaults into i18n locale data
1295 #if 0
1296     if (bLong)
1297     {
1298         MonthFormat eMonth = rIntn.GetLongDateMonthFormat();
1299         return ( eMonth == MONTH_ZERO || eMonth == MONTH_LONG );
1300     }
1301     else
1302         return rIntn.IsDateMonthLeadingZero();
1303 #else
1304     return !bLong;
1305 #endif
1306 }
1307 
IsSystemTextualMonth(const SvtSysLocale &,sal_Bool bLong)1308 sal_Bool SvXMLNumFmtDefaults::IsSystemTextualMonth( const SvtSysLocale&, sal_Bool bLong )
1309 {
1310     // TODO: merge system information and defaults into i18n locale data
1311 #if 0
1312     if (bLong)
1313     {
1314         MonthFormat eMonth = rIntn.GetLongDateMonthFormat();
1315         return ( eMonth == MONTH_SHORT || eMonth == MONTH_LONG );
1316     }
1317     else
1318         return sal_False;
1319 #else
1320     return bLong;
1321 #endif
1322 }
1323 
IsSystemLongYear(const SvtSysLocale &,sal_Bool bLong)1324 sal_Bool SvXMLNumFmtDefaults::IsSystemLongYear( const SvtSysLocale&, sal_Bool bLong )
1325 {
1326     // TODO: merge system information and defaults into i18n locale data
1327 #if 0
1328     return bLong ? rIntn.IsLongDateCentury() : rIntn.IsDateCentury();
1329 #else
1330     return bLong;
1331 #endif
1332 }
1333 
IsSystemLongEra(const SvtSysLocale & rSysLoc,sal_Bool bLong)1334 sal_Bool SvXMLNumFmtDefaults::IsSystemLongEra( const SvtSysLocale& rSysLoc, sal_Bool bLong )
1335 {
1336     // TODO: merge system information and defaults into i18n locale data
1337     return IsSystemLongYear( rSysLoc, bLong );      // no separate setting
1338 }
1339 
IsSystemLongDayOfWeek(const SvtSysLocale &,sal_Bool bLong)1340 sal_Bool SvXMLNumFmtDefaults::IsSystemLongDayOfWeek( const SvtSysLocale&, sal_Bool bLong )
1341 {
1342     // TODO: merge system information and defaults into i18n locale data
1343 #if 0
1344     return ( bLong && rIntn.GetLongDateDayOfWeekFormat() == DAYOFWEEK_LONG );
1345 #else
1346     return bLong && true;
1347 #endif
1348 }
1349 
GetDefaultDateFormat(SvXMLDateElementAttributes eDOW,SvXMLDateElementAttributes eDay,SvXMLDateElementAttributes eMonth,SvXMLDateElementAttributes eYear,SvXMLDateElementAttributes eHours,SvXMLDateElementAttributes eMins,SvXMLDateElementAttributes eSecs,sal_Bool bSystem)1350 sal_uInt16 SvXMLNumFmtDefaults::GetDefaultDateFormat( SvXMLDateElementAttributes eDOW,
1351                 SvXMLDateElementAttributes eDay, SvXMLDateElementAttributes eMonth,
1352                 SvXMLDateElementAttributes eYear, SvXMLDateElementAttributes eHours,
1353                 SvXMLDateElementAttributes eMins, SvXMLDateElementAttributes eSecs,
1354                 sal_Bool bSystem )
1355 {
1356     const sal_uInt16 nCount = sizeof(aDefaultDateFormats) / sizeof(SvXMLDefaultDateFormat);
1357     for (sal_uInt16 nPos=0; nPos<nCount; nPos++)
1358     {
1359         const SvXMLDefaultDateFormat& rEntry = aDefaultDateFormats[nPos];
1360         if ( bSystem == rEntry.bSystem &&
1361             ( eDOW   == rEntry.eDOW   || ( rEntry.eDOW   == XML_DEA_ANY && eDOW   != XML_DEA_NONE ) ) &&
1362             ( eDay   == rEntry.eDay   || ( rEntry.eDay   == XML_DEA_ANY && eDay   != XML_DEA_NONE ) ) &&
1363             ( eMonth == rEntry.eMonth || ( rEntry.eMonth == XML_DEA_ANY && eMonth != XML_DEA_NONE ) ) &&
1364             ( eYear  == rEntry.eYear  || ( rEntry.eYear  == XML_DEA_ANY && eYear  != XML_DEA_NONE ) ) &&
1365             ( eHours == rEntry.eHours || ( rEntry.eHours == XML_DEA_ANY && eHours != XML_DEA_NONE ) ) &&
1366             ( eMins  == rEntry.eMins  || ( rEntry.eMins  == XML_DEA_ANY && eMins  != XML_DEA_NONE ) ) &&
1367             ( eSecs  == rEntry.eSecs  || ( rEntry.eSecs  == XML_DEA_ANY && eSecs  != XML_DEA_NONE ) ) )
1368         {
1369             return sal::static_int_cast< sal_uInt16 >(rEntry.eFormat);
1370         }
1371     }
1372 
1373     return NF_INDEX_TABLE_ENTRIES;  // invalid
1374 }
1375 
1376 //-------------------------------------------------------------------------
1377 
1378 //
1379 //  SvXMLNumFormatContext
1380 //
1381 
SvXMLNumFormatContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumImpData * pNewData,sal_uInt16 nNewType,const uno::Reference<xml::sax::XAttributeList> & xAttrList,SvXMLStylesContext & rStyles)1382 SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
1383                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
1384                                     SvXMLNumImpData* pNewData, sal_uInt16 nNewType,
1385                                     const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1386                                     SvXMLStylesContext& rStyles ) :
1387     SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList ),
1388     pData( pNewData ),
1389     pStyles( &rStyles ),
1390     aMyConditions(),
1391     nType( nNewType ),
1392     nKey(-1),
1393     nFormatLang( LANGUAGE_SYSTEM ),
1394     bAutoOrder( sal_False ),
1395     bFromSystem( sal_False ),
1396     bTruncate( sal_True ),
1397     bAutoDec( sal_False ),
1398     bAutoInt( sal_False ),
1399     bHasExtraText( sal_False ),
1400     bHasLongDoW( sal_False ),
1401     bHasFillChar( sal_False ),
1402     bHasEra( sal_False ),
1403     bHasDateTime( sal_False ),
1404     bRemoveAfterUse( sal_False ),
1405     eDateDOW( XML_DEA_NONE ),
1406     eDateDay( XML_DEA_NONE ),
1407     eDateMonth( XML_DEA_NONE ),
1408     eDateYear( XML_DEA_NONE ),
1409     eDateHours( XML_DEA_NONE ),
1410     eDateMins( XML_DEA_NONE ),
1411     eDateSecs( XML_DEA_NONE ),
1412     bDateNoDefault( sal_False )
1413 {
1414     OUString sLanguage, sCountry;
1415     ::com::sun::star::i18n::NativeNumberXmlAttributes aNatNumAttr;
1416     sal_Bool bAttrBool;
1417     sal_uInt16 nAttrEnum;
1418 
1419     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1420     for( sal_Int16 i=0; i < nAttrCount; i++ )
1421     {
1422         OUString sAttrName = xAttrList->getNameByIndex( i );
1423         OUString sValue = xAttrList->getValueByIndex( i );
1424         OUString aLocalName;
1425         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1426 
1427         const SvXMLTokenMap& rTokenMap = pData->GetStyleAttrTokenMap();
1428         sal_uInt16 nToken = rTokenMap.Get( nPrefix, aLocalName );
1429         switch (nToken)
1430         {
1431             case XML_TOK_STYLE_ATTR_NAME:
1432 //              aName = sValue;
1433                 break;
1434             case XML_TOK_STYLE_ATTR_LANGUAGE:
1435                 sLanguage = sValue;
1436                 break;
1437             case XML_TOK_STYLE_ATTR_COUNTRY:
1438                 sCountry = sValue;
1439                 break;
1440             case XML_TOK_STYLE_ATTR_TITLE:
1441                 sFormatTitle = sValue;
1442                 break;
1443             case XML_TOK_STYLE_ATTR_AUTOMATIC_ORDER:
1444                 if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
1445                     bAutoOrder = bAttrBool;
1446                 break;
1447             case XML_TOK_STYLE_ATTR_FORMAT_SOURCE:
1448                 if ( SvXMLUnitConverter::convertEnum( nAttrEnum, sValue, aFormatSourceMap ) )
1449                     bFromSystem = (sal_Bool) nAttrEnum;
1450                 break;
1451             case XML_TOK_STYLE_ATTR_TRUNCATE_ON_OVERFLOW:
1452                 if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
1453                     bTruncate = bAttrBool;
1454                 break;
1455             case XML_TOK_STYLE_ATTR_VOLATILE:
1456                 //  volatile formats can be removed after importing
1457                 //  if not used in other styles
1458                 if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
1459                     bRemoveAfterUse = bAttrBool;
1460                 break;
1461             case XML_TOK_STYLE_ATTR_TRANSL_FORMAT:
1462                 aNatNumAttr.Format = sValue;
1463                 break;
1464             case XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE:
1465                 aNatNumAttr.Locale.Language = sValue;
1466                 break;
1467             case XML_TOK_STYLE_ATTR_TRANSL_COUNTRY:
1468                 aNatNumAttr.Locale.Country = sValue;
1469                 break;
1470             case XML_TOK_STYLE_ATTR_TRANSL_STYLE:
1471                 aNatNumAttr.Style = sValue;
1472                 break;
1473         }
1474     }
1475 
1476     if ( sLanguage.getLength() || sCountry.getLength() )
1477     {
1478         nFormatLang = MsLangId::convertIsoNamesToLanguage( sLanguage, sCountry );
1479         if ( nFormatLang == LANGUAGE_DONTKNOW )
1480             nFormatLang = LANGUAGE_SYSTEM;          //! error handling for invalid locales?
1481     }
1482 
1483     if ( aNatNumAttr.Format.getLength() )
1484     {
1485         SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
1486         if ( pFormatter )
1487         {
1488             // ODF 1.2 19.364: a missing style means "short"
1489             if ( !aNatNumAttr.Style.getLength() )
1490                 aNatNumAttr.Style = GetXMLToken( XML_SHORT );
1491             sal_Int32 nNatNum = pFormatter->GetNatNum()->convertFromXmlAttributes( aNatNumAttr );
1492             aFormatCode.appendAscii( RTL_CONSTASCII_STRINGPARAM( "[NatNum" ) );
1493             aFormatCode.append( nNatNum, 10 );
1494 
1495             LanguageType eLang = MsLangId::convertLocaleToLanguage( aNatNumAttr.Locale );
1496             if ( eLang == LANGUAGE_DONTKNOW )
1497                 eLang = LANGUAGE_SYSTEM;            //! error handling for invalid locales?
1498             if ( eLang != nFormatLang && eLang != LANGUAGE_SYSTEM )
1499             {
1500                 aFormatCode.appendAscii( RTL_CONSTASCII_STRINGPARAM( "][$-" ) );
1501                 // language code in upper hex:
1502                 aFormatCode.append( String::CreateFromInt32( sal_Int32( eLang ), 16 ).ToUpperAscii() );
1503             }
1504             aFormatCode.append( sal_Unicode(']') );
1505         }
1506     }
1507 }
1508 
SvXMLNumFormatContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,const sal_Int32 nTempKey,SvXMLStylesContext & rStyles)1509 SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
1510                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
1511                                     const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1512                                     const sal_Int32 nTempKey,
1513                                     SvXMLStylesContext& rStyles ) :
1514     SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_DATA_STYLE ),
1515     pData( NULL ),
1516     pStyles( &rStyles ),
1517     aMyConditions(),
1518     nType( 0 ),
1519     nKey(nTempKey),
1520     nFormatLang( LANGUAGE_SYSTEM ),
1521     bAutoOrder( sal_False ),
1522     bFromSystem( sal_False ),
1523     bTruncate( sal_True ),
1524     bAutoDec( sal_False ),
1525     bAutoInt( sal_False ),
1526     bHasExtraText( sal_False ),
1527     bHasLongDoW( sal_False ),
1528     bHasFillChar( sal_False ),
1529     bHasEra( sal_False ),
1530     bHasDateTime( sal_False ),
1531     bRemoveAfterUse( sal_False ),
1532     eDateDOW( XML_DEA_NONE ),
1533     eDateDay( XML_DEA_NONE ),
1534     eDateMonth( XML_DEA_NONE ),
1535     eDateYear( XML_DEA_NONE ),
1536     eDateHours( XML_DEA_NONE ),
1537     eDateMins( XML_DEA_NONE ),
1538     eDateSecs( XML_DEA_NONE ),
1539     bDateNoDefault( sal_False )
1540 {
1541     SetAttribute(XML_NAMESPACE_STYLE, GetXMLToken(XML_NAME), rLName);
1542 }
1543 
~SvXMLNumFormatContext()1544 SvXMLNumFormatContext::~SvXMLNumFormatContext()
1545 {
1546 }
1547 
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)1548 SvXMLImportContext* SvXMLNumFormatContext::CreateChildContext(
1549                                     sal_uInt16 nPrfx, const rtl::OUString& rLName,
1550                                     const uno::Reference<xml::sax::XAttributeList>& xAttrList )
1551 {
1552     SvXMLImportContext* pContext = NULL;
1553 
1554     const SvXMLTokenMap& rTokenMap = pData->GetStyleElemTokenMap();
1555     sal_uInt16 nToken = rTokenMap.Get( nPrfx, rLName );
1556     switch (nToken)
1557     {
1558         case XML_TOK_STYLE_TEXT:
1559         case XML_TOK_STYLE_NUMBER:
1560         case XML_TOK_STYLE_SCIENTIFIC_NUMBER:
1561         case XML_TOK_STYLE_FRACTION:
1562         case XML_TOK_STYLE_CURRENCY_SYMBOL:
1563         case XML_TOK_STYLE_DAY:
1564         case XML_TOK_STYLE_MONTH:
1565         case XML_TOK_STYLE_YEAR:
1566         case XML_TOK_STYLE_ERA:
1567         case XML_TOK_STYLE_DAY_OF_WEEK:
1568         case XML_TOK_STYLE_WEEK_OF_YEAR:
1569         case XML_TOK_STYLE_QUARTER:
1570         case XML_TOK_STYLE_HOURS:
1571         case XML_TOK_STYLE_AM_PM:
1572         case XML_TOK_STYLE_MINUTES:
1573         case XML_TOK_STYLE_SECONDS:
1574         case XML_TOK_STYLE_BOOLEAN:
1575         case XML_TOK_STYLE_TEXT_CONTENT:
1576         case XML_TOK_STYLE_FILL_CHARACTER:
1577             pContext = new SvXMLNumFmtElementContext( GetImport(), nPrfx, rLName,
1578                                                         *this, nToken, xAttrList );
1579             break;
1580 
1581         case XML_TOK_STYLE_PROPERTIES:
1582             pContext = new SvXMLNumFmtPropContext( GetImport(), nPrfx, rLName,
1583                                                         *this, xAttrList );
1584             break;
1585         case XML_TOK_STYLE_MAP:
1586             {
1587                 //  SvXMLNumFmtMapContext::EndElement adds to aMyConditions,
1588                 //  so there's no need for an extra flag
1589                 pContext = new SvXMLNumFmtMapContext( GetImport(), nPrfx, rLName,
1590                                                             *this, xAttrList );
1591             }
1592             break;
1593     }
1594 
1595     if( !pContext )
1596         pContext = new SvXMLImportContext( GetImport(), nPrfx, rLName );
1597     return pContext;
1598 }
1599 
GetKey()1600 sal_Int32 SvXMLNumFormatContext::GetKey()
1601 {
1602     if (nKey > -1)
1603     {
1604         if (bRemoveAfterUse)
1605         {
1606             //  format is used -> don't remove
1607             bRemoveAfterUse = sal_False;
1608             if (pData)
1609                 pData->SetUsed(nKey);
1610 
1611             //  Add to import's list of keys now - CreateAndInsert didn't add
1612             //  the style if bRemoveAfterUse was set.
1613             GetImport().AddNumberStyle( nKey, GetName() );
1614         }
1615         return nKey;
1616     }
1617     else
1618     {
1619         // reset bRemoveAfterUse before CreateAndInsert, so AddKey is called without bRemoveAfterUse set
1620         bRemoveAfterUse = sal_False;
1621         CreateAndInsert(sal_True);
1622         return nKey;
1623     }
1624 }
1625 
PrivateGetKey()1626 sal_Int32 SvXMLNumFormatContext::PrivateGetKey()
1627 {
1628     //  used for map elements in CreateAndInsert - don't reset bRemoveAfterUse flag
1629 
1630     if (nKey > -1)
1631         return nKey;
1632     else
1633     {
1634         CreateAndInsert(sal_True);
1635         return nKey;
1636     }
1637 }
1638 
CreateAndInsert(com::sun::star::uno::Reference<com::sun::star::util::XNumberFormatsSupplier> & xFormatsSupplier)1639 sal_Int32 SvXMLNumFormatContext::CreateAndInsert( com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatsSupplier >& xFormatsSupplier )
1640 {
1641     if (nKey <= -1)
1642     {
1643         SvNumberFormatter* pFormatter = NULL;
1644         SvNumberFormatsSupplierObj* pObj =
1645                         SvNumberFormatsSupplierObj::getImplementation( xFormatsSupplier );
1646         if (pObj)
1647             pFormatter = pObj->GetNumberFormatter();
1648 
1649         if ( pFormatter )
1650             return CreateAndInsert( pFormatter );
1651         else
1652             return -1;
1653     }
1654     else
1655         return nKey;
1656 }
1657 
CreateAndInsert(sal_Bool)1658 void SvXMLNumFormatContext::CreateAndInsert(sal_Bool /*bOverwrite*/)
1659 {
1660     if (!(nKey > -1))
1661         CreateAndInsert(pData->GetNumberFormatter());
1662 }
1663 
CreateAndInsert(SvNumberFormatter * pFormatter)1664 sal_Int32 SvXMLNumFormatContext::CreateAndInsert(SvNumberFormatter* pFormatter)
1665 {
1666     if (!pFormatter)
1667     {
1668         DBG_ERROR("no number formatter");
1669         return -1;
1670     }
1671 
1672     sal_uInt32 nIndex = NUMBERFORMAT_ENTRY_NOT_FOUND;
1673 
1674     for (sal_uInt32 i = 0; i < aMyConditions.size(); i++)
1675     {
1676         SvXMLNumFormatContext* pStyle = (SvXMLNumFormatContext *)pStyles->FindStyleChildContext(
1677             XML_STYLE_FAMILY_DATA_STYLE, aMyConditions[i].sMapName, sal_False);
1678         if (pStyle)
1679         {
1680             if ((pStyle->PrivateGetKey() > -1))     // don't reset pStyle's bRemoveAfterUse flag
1681                 AddCondition(i);
1682         }
1683     }
1684 
1685     if ( !aFormatCode.getLength() )
1686     {
1687         //  insert empty format as empty string (with quotes)
1688         //  #93901# this check has to be done before inserting the conditions
1689         aFormatCode.appendAscii("\"\"");    // ""
1690     }
1691 
1692     aFormatCode.insert( 0, aConditions.makeStringAndClear() );
1693     OUString sFormat = aFormatCode.makeStringAndClear();
1694 
1695     //  test special cases
1696 
1697     if ( bAutoDec )         // automatic decimal places
1698     {
1699         //  #99391# adjust only if the format contains no text elements, no conditions
1700         //  and no color definition (detected by the '[' at the start)
1701 
1702         if ( nType == XML_TOK_STYLES_NUMBER_STYLE && !bHasExtraText &&
1703                 aMyConditions.size() == 0 && sFormat.toChar() != (sal_Unicode)'[' )
1704             nIndex = pFormatter->GetStandardIndex( nFormatLang );
1705     }
1706     if ( bAutoInt )         // automatic integer digits
1707     {
1708         //! only if two decimal places was set?
1709 
1710         if ( nType == XML_TOK_STYLES_NUMBER_STYLE && !bHasExtraText &&
1711                 aMyConditions.size() == 0 && sFormat.toChar() != (sal_Unicode)'[' )
1712             nIndex = pFormatter->GetFormatIndex( NF_NUMBER_SYSTEM, nFormatLang );
1713     }
1714 
1715     //  boolean is always the builtin boolean format
1716     //  (no other boolean formats are implemented)
1717     if ( nType == XML_TOK_STYLES_BOOLEAN_STYLE )
1718         nIndex = pFormatter->GetFormatIndex( NF_BOOLEAN, nFormatLang );
1719 
1720     //  check for default date formats
1721     if ( nType == XML_TOK_STYLES_DATE_STYLE && bAutoOrder && !bDateNoDefault )
1722     {
1723         NfIndexTableOffset eFormat = (NfIndexTableOffset) SvXMLNumFmtDefaults::GetDefaultDateFormat(
1724             eDateDOW, eDateDay, eDateMonth, eDateYear,
1725             eDateHours, eDateMins, eDateSecs, bFromSystem );
1726         if ( eFormat < NF_INDEX_TABLE_ENTRIES )
1727         {
1728             //  #109651# if a date format has the automatic-order attribute and
1729             //  contains exactly the elements of one of the default date formats,
1730             //  use that default format, with the element order and separators
1731             //  from the current locale settings
1732 
1733             nIndex = pFormatter->GetFormatIndex( eFormat, nFormatLang );
1734         }
1735     }
1736 
1737     if ( nIndex == NUMBERFORMAT_ENTRY_NOT_FOUND && sFormat.getLength() )
1738     {
1739         //  insert by format string
1740 
1741         String aFormatStr( sFormat );
1742         nIndex = pFormatter->GetEntryKey( aFormatStr, nFormatLang );
1743         if ( nIndex == NUMBERFORMAT_ENTRY_NOT_FOUND )
1744         {
1745             xub_StrLen  nErrPos = 0;
1746             short       l_nType = 0;
1747             sal_Bool bOk = pFormatter->PutEntry( aFormatStr, nErrPos, l_nType, nIndex, nFormatLang );
1748             if ( !bOk && nErrPos == 0 && aFormatStr != String(sFormat) )
1749             {
1750                 //  if the string was modified by PutEntry, look for an existing format
1751                 //  with the modified string
1752                 nIndex = pFormatter->GetEntryKey( aFormatStr, nFormatLang );
1753                 if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND )
1754                     bOk = sal_True;
1755             }
1756             if (!bOk)
1757                 nIndex = NUMBERFORMAT_ENTRY_NOT_FOUND;
1758         }
1759     }
1760 
1761 #if 0
1762 //! I18N doesn't provide SYSTEM or extended date information yet
1763     if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND && !bFromSystem )
1764     {
1765         //  instead of automatic date format, use fixed formats if bFromSystem is not set
1766         //! prevent use of automatic formats in other cases, force user-defined format?
1767 
1768         sal_uInt32 nNewIndex = nIndex;
1769 
1770         NfIndexTableOffset eOffset = pFormatter->GetIndexTableOffset( nIndex );
1771         if ( eOffset == NF_DATE_SYSTEM_SHORT )
1772         {
1773             const International& rInt = pData->GetInternational( nFormatLang );
1774             if ( rInt.IsDateDayLeadingZero() && rInt.IsDateMonthLeadingZero() )
1775             {
1776                 if ( rInt.IsDateCentury() )
1777                     nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, nFormatLang );
1778                 else
1779                     nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYY, nFormatLang );
1780             }
1781         }
1782         else if ( eOffset == NF_DATE_SYSTEM_LONG )
1783         {
1784             const International& rInt = pData->GetInternational( nFormatLang );
1785             if ( !rInt.IsLongDateDayLeadingZero() )
1786             {
1787                 sal_Bool bCentury = rInt.IsLongDateCentury();
1788                 MonthFormat eMonth = rInt.GetLongDateMonthFormat();
1789                 if ( eMonth == MONTH_LONG && bCentury )
1790                 {
1791                     if ( rInt.GetLongDateDayOfWeekFormat() == DAYOFWEEK_LONG )
1792                         nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNNNDMMMMYYYY, nFormatLang );
1793                     else
1794                         nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNDMMMMYYYY, nFormatLang );
1795                 }
1796                 else if ( eMonth == MONTH_SHORT && !bCentury )
1797                     nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNDMMMYY, nFormatLang );
1798             }
1799         }
1800 
1801         if ( nNewIndex != nIndex )
1802         {
1803             //  verify the fixed format really matches the format string
1804             //  (not the case with some formats from locale data)
1805 
1806             const SvNumberformat* pFixedFormat = pFormatter->GetEntry( nNewIndex );
1807             if ( pFixedFormat && pFixedFormat->GetFormatstring() == String(sFormat) )
1808                 nIndex = nNewIndex;
1809         }
1810     }
1811 #endif
1812 
1813     if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND && !bAutoOrder )
1814     {
1815         //  use fixed-order formats instead of SYS... if bAutoOrder is false
1816         //  (only if the format strings are equal for the locale)
1817 
1818         NfIndexTableOffset eOffset = pFormatter->GetIndexTableOffset( nIndex );
1819         if ( eOffset == NF_DATE_SYS_DMMMYYYY )
1820         {
1821             sal_uInt32 nNewIndex = pFormatter->GetFormatIndex( NF_DATE_DIN_DMMMYYYY, nFormatLang );
1822             const SvNumberformat* pOldEntry = pFormatter->GetEntry( nIndex );
1823             const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewIndex );
1824             if ( pOldEntry && pNewEntry && pOldEntry->GetFormatstring() == pNewEntry->GetFormatstring() )
1825                 nIndex = nNewIndex;
1826         }
1827         else if ( eOffset == NF_DATE_SYS_DMMMMYYYY )
1828         {
1829             sal_uInt32 nNewIndex = pFormatter->GetFormatIndex( NF_DATE_DIN_DMMMMYYYY, nFormatLang );
1830             const SvNumberformat* pOldEntry = pFormatter->GetEntry( nIndex );
1831             const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewIndex );
1832             if ( pOldEntry && pNewEntry && pOldEntry->GetFormatstring() == pNewEntry->GetFormatstring() )
1833                 nIndex = nNewIndex;
1834         }
1835     }
1836 
1837     if ((nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND) && sFormatTitle.getLength())
1838     {
1839         SvNumberformat* pFormat = const_cast<SvNumberformat*>(pFormatter->GetEntry( nIndex ));
1840         if (pFormat)
1841         {
1842             String sTitle (sFormatTitle);
1843             pFormat->SetComment(sTitle);
1844         }
1845     }
1846 
1847     if ( nIndex == NUMBERFORMAT_ENTRY_NOT_FOUND )
1848     {
1849         DBG_ERROR("invalid number format");
1850         nIndex = pFormatter->GetStandardIndex( nFormatLang );
1851     }
1852 
1853     pData->AddKey( nIndex, GetName(), bRemoveAfterUse );
1854     nKey = nIndex;
1855 
1856     //  Add to import's list of keys (shared between styles and content import)
1857     //  only if not volatile - formats are removed from NumberFormatter at the
1858     //  end of each import (in SvXMLNumFmtHelper dtor).
1859     //  If bRemoveAfterUse is reset later in GetKey, AddNumberStyle is called there.
1860 
1861     if (!bRemoveAfterUse)
1862         GetImport().AddNumberStyle( nKey, GetName() );
1863 
1864 #if 0
1865     ByteString aByte( String(sFormatName), gsl_getSystemTextEncoding() );
1866     aByte.Append( " | " );
1867     aByte.Append(ByteString( String(sFormat), gsl_getSystemTextEncoding() ));
1868     aByte.Append( " | " );
1869     aByte.Append(ByteString::CreateFromInt32( nIndex ));
1870 
1871 //  DBG_ERROR(aByte.GetBuffer());
1872     int xxx=42;
1873 #endif
1874 
1875     return nKey;
1876 }
1877 
Finish(sal_Bool bOverwrite)1878 void SvXMLNumFormatContext::Finish( sal_Bool bOverwrite )
1879 {
1880     SvXMLStyleContext::Finish( bOverwrite );
1881 //  AddCondition();
1882 }
1883 
GetLocaleData() const1884 const LocaleDataWrapper& SvXMLNumFormatContext::GetLocaleData() const
1885 {
1886     return pData->GetLocaleData( nFormatLang );
1887 }
1888 
AddToCode(const rtl::OUString & rString)1889 void SvXMLNumFormatContext::AddToCode( const rtl::OUString& rString )
1890 {
1891     aFormatCode.append( rString );
1892     bHasExtraText = sal_True;
1893 }
1894 
AddNumber(const SvXMLNumberInfo & rInfo)1895 void SvXMLNumFormatContext::AddNumber( const SvXMLNumberInfo& rInfo )
1896 {
1897     SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
1898     if (!pFormatter)
1899         return;
1900 
1901     //  store special conditions
1902     bAutoDec = ( rInfo.nDecimals < 0 );
1903     bAutoInt = ( rInfo.nInteger < 0 );
1904 
1905     sal_uInt16 nPrec = 0;
1906     sal_uInt16 nLeading = 0;
1907     if ( rInfo.nDecimals >= 0 )                     //  < 0 : Default
1908         nPrec = (sal_uInt16) rInfo.nDecimals;
1909     if ( rInfo.nInteger >= 0 )                      //  < 0 : Default
1910         nLeading = (sal_uInt16) rInfo.nInteger;
1911 
1912     if ( bAutoDec )
1913     {
1914         if ( nType == XML_TOK_STYLES_CURRENCY_STYLE )
1915         {
1916             //  for currency formats, "automatic decimals" is used for the automatic
1917             //  currency format with (fixed) decimals from the locale settings
1918 
1919             const LocaleDataWrapper& rLoc = pData->GetLocaleData( nFormatLang );
1920             nPrec = rLoc.getCurrDigits();
1921         }
1922         else
1923         {
1924             //  for other types, "automatic decimals" means dynamic determination of
1925             //  decimals, as achieved with the "general" keyword
1926 
1927             aFormatCode.append( pFormatter->GetStandardName( nFormatLang ) );
1928             return;
1929         }
1930     }
1931     if ( bAutoInt )
1932     {
1933         //!...
1934     }
1935 
1936     // decimals beyond the minimum are optional ('#'); a replacement string wins over a minimum
1937     sal_uInt16 nMinPrec = 0;
1938     if ( !rInfo.bDecReplace )
1939     {
1940         if ( rInfo.nMinDecimals >= 0 )
1941             nMinPrec = (sal_uInt16) rInfo.nMinDecimals;
1942         else if ( !rInfo.bVarDecimals )
1943             nMinPrec = nPrec;
1944         if ( nMinPrec > nPrec )
1945             nMinPrec = nPrec;
1946     }
1947 
1948     sal_uInt16 nGenPrec = nPrec;
1949     if ( rInfo.bDecReplace )
1950         nGenPrec = 0;               // generate format without decimals...
1951     else
1952         nGenPrec = nMinPrec;
1953 
1954     sal_Bool bGrouping = rInfo.bGrouping;
1955     sal_uInt16 nEmbeddedCount = rInfo.aEmbeddedElements.Count();
1956     if ( nEmbeddedCount )
1957         bGrouping = sal_False;      // grouping and embedded characters can't be used together
1958 
1959     String aNumStr;
1960     sal_uInt32 nStdIndex = pFormatter->GetStandardIndex( nFormatLang );
1961     pFormatter->GenerateFormat( aNumStr, nStdIndex, nFormatLang,
1962                                 bGrouping, sal_False, nGenPrec, nLeading );
1963 
1964     if ( rInfo.nExpDigits >= 0 && nLeading == 0 && !bGrouping && nEmbeddedCount == 0 )
1965     {
1966         // #i43959# For scientific numbers, "#" in the integer part forces a digit,
1967         // so it has to be removed if nLeading is 0 (".00E+0", not "#.00E+0").
1968 
1969         aNumStr.EraseLeadingChars( (sal_Unicode)'#' );
1970     }
1971 
1972     if ( nEmbeddedCount )
1973     {
1974         //  insert embedded strings into number string
1975         //  only the integer part is supported
1976         //  nZeroPos is the string position where format position 0 is inserted
1977 
1978         xub_StrLen nZeroPos = aNumStr.Search( pData->GetLocaleData( nFormatLang ).getNumDecimalSep() );
1979         if ( nZeroPos == STRING_NOTFOUND )
1980             nZeroPos = aNumStr.Len();
1981 
1982         //  aEmbeddedElements is sorted - last entry has the largest position (leftmost)
1983         const SvXMLEmbeddedElement* pLastObj = rInfo.aEmbeddedElements[nEmbeddedCount - 1];
1984         sal_Int32 nLastFormatPos = pLastObj->nFormatPos;
1985         if ( nLastFormatPos >= nZeroPos )
1986         {
1987             //  add '#' characters so all embedded texts are really embedded in digits
1988             //  (there always has to be a digit before the leftmost embedded text)
1989 
1990             xub_StrLen nAddCount = (xub_StrLen)nLastFormatPos + 1 - nZeroPos;
1991             String aDigitStr;
1992             aDigitStr.Fill( nAddCount, (sal_Unicode)'#' );
1993             aNumStr.Insert( aDigitStr, 0 );
1994             nZeroPos = nZeroPos + nAddCount;
1995         }
1996 
1997         //  aEmbeddedElements is sorted with ascending positions - loop is from right to left
1998         for (sal_uInt16 nElement = 0; nElement < nEmbeddedCount; nElement++)
1999         {
2000             const SvXMLEmbeddedElement* pObj = rInfo.aEmbeddedElements[nElement];
2001             sal_Int32 nFormatPos = pObj->nFormatPos;
2002             sal_Int32 nInsertPos = nZeroPos - nFormatPos;
2003             if ( nFormatPos >= 0 && nInsertPos >= 0 )
2004             {
2005                 rtl::OUStringBuffer aContent( pObj->aText );
2006                 //  #107805# always quote embedded strings - even space would otherwise
2007                 //  be recognized as thousands separator in French.
2008                 aContent.insert( 0, (sal_Unicode) '"' );
2009                 aContent.append( (sal_Unicode) '"' );
2010 
2011                 aNumStr.Insert( String( aContent.makeStringAndClear() ), (xub_StrLen)nInsertPos );
2012             }
2013         }
2014     }
2015 
2016     aFormatCode.append( aNumStr );
2017 
2018     if ( rInfo.bDecReplace && nPrec )       // add decimal replacement (dashes)
2019     {
2020         aFormatCode.append( pData->GetLocaleData( nFormatLang ).getNumDecimalSep() );
2021         for ( sal_uInt16 i=0; i<nPrec; i++)
2022             aFormatCode.append( (sal_Unicode) '-' );
2023     }
2024     else if ( nPrec > nMinPrec )            // optional decimals
2025     {
2026         if ( nMinPrec == 0 )
2027             aFormatCode.append( pData->GetLocaleData( nFormatLang ).getNumDecimalSep() );
2028         for ( sal_uInt16 i=nMinPrec; i<nPrec; i++)
2029             aFormatCode.append( (sal_Unicode) '#' );
2030     }
2031 
2032     //  add extra thousands separators for display factor
2033 
2034     if ( rInfo.fDisplayFactor != 1.0 && rInfo.fDisplayFactor > 0.0 )
2035     {
2036         //  test for 1.0 is just for optimization - nSepCount would be 0
2037 
2038         //  one separator for each factor of 1000
2039         sal_Int32 nSepCount = (sal_Int32) ::rtl::math::round( log10(rInfo.fDisplayFactor) / 3.0 );
2040         if ( nSepCount > 0 )
2041         {
2042             OUString aSep = pData->GetLocaleData( nFormatLang ).getNumThousandSep();
2043             for ( sal_Int32 i=0; i<nSepCount; i++ )
2044                 aFormatCode.append( aSep );
2045         }
2046     }
2047 }
2048 
AddCurrency(const rtl::OUString & rContent,LanguageType nLang)2049 void SvXMLNumFormatContext::AddCurrency( const rtl::OUString& rContent, LanguageType nLang )
2050 {
2051     sal_Bool bAutomatic = sal_False;
2052     OUString aSymbol = rContent;
2053     if ( aSymbol.getLength() == 0 )
2054     {
2055         //  get currency symbol for language
2056 
2057         //aSymbol = pData->GetLocaleData( nFormatLang ).getCurrSymbol();
2058 
2059         SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2060         if ( pFormatter )
2061         {
2062             pFormatter->ChangeIntl( nFormatLang );
2063             String sCurString, sDummy;
2064             pFormatter->GetCompatibilityCurrency( sCurString, sDummy );
2065             aSymbol = sCurString;
2066 
2067             bAutomatic = sal_True;
2068         }
2069     }
2070     else if ( nLang == LANGUAGE_SYSTEM && aSymbol.compareToAscii("CCC") == 0 )
2071     {
2072         //  "CCC" is used for automatic long symbol
2073         bAutomatic = sal_True;
2074     }
2075 
2076     if ( bAutomatic )
2077     {
2078         //  remove unnecessary quotes before automatic symbol (formats like "-(0DM)")
2079         //  otherwise the currency symbol isn't recognized (#94048#)
2080 
2081         sal_Int32 nLength = aFormatCode.getLength();
2082         if ( nLength > 1 && aFormatCode.charAt( nLength-1 ) == '"' )
2083         {
2084             //  find start of quoted string
2085             //  When SvXMLNumFmtElementContext::EndElement creates escaped quotes,
2086             //  they must be handled here, too.
2087 
2088             sal_Int32 nFirst = nLength - 2;
2089             while ( nFirst >= 0 && aFormatCode.charAt( nFirst ) != '"' )
2090                 --nFirst;
2091             if ( nFirst >= 0 )
2092             {
2093                 //  remove both quotes from aFormatCode
2094                 rtl::OUString aOld = aFormatCode.makeStringAndClear();
2095                 if ( nFirst > 0 )
2096                     aFormatCode.append( aOld.copy( 0, nFirst ) );
2097                 if ( nLength > nFirst + 2 )
2098                     aFormatCode.append( aOld.copy( nFirst + 1, nLength - nFirst - 2 ) );
2099             }
2100         }
2101     }
2102 
2103     if (!bAutomatic)
2104         aFormatCode.appendAscii( "[$" );            // intro for "new" currency symbols
2105 
2106     aFormatCode.append( aSymbol );
2107 
2108     if (!bAutomatic)
2109     {
2110         if ( nLang != LANGUAGE_SYSTEM )
2111         {
2112             //  '-' sign and language code in hex:
2113             aFormatCode.append( (sal_Unicode) '-' );
2114             aFormatCode.append( String::CreateFromInt32( sal_Int32( nLang ), 16 ).ToUpperAscii() );
2115         }
2116 
2117         aFormatCode.append( (sal_Unicode) ']' );    // end of "new" currency symbol
2118     }
2119 }
2120 
AddNfKeyword(sal_uInt16 nIndex)2121 void SvXMLNumFormatContext::AddNfKeyword( sal_uInt16 nIndex )
2122 {
2123     SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2124     if (!pFormatter)
2125         return;
2126 
2127     if ( nIndex == NF_KEY_G || nIndex == NF_KEY_GG || nIndex == NF_KEY_GGG )
2128         bHasEra = sal_True;
2129 
2130     if ( nIndex == NF_KEY_NNNN )
2131     {
2132         nIndex = NF_KEY_NNN;
2133         bHasLongDoW = sal_True;         // to remove string constant with separator
2134     }
2135 
2136     String sKeyword = pFormatter->GetKeyword( nFormatLang, nIndex );
2137 
2138     if ( nIndex == NF_KEY_H  || nIndex == NF_KEY_HH  ||
2139          nIndex == NF_KEY_MI || nIndex == NF_KEY_MMI ||
2140          nIndex == NF_KEY_S  || nIndex == NF_KEY_SS )
2141     {
2142         if ( !bTruncate && !bHasDateTime )
2143         {
2144             //  with truncate-on-overflow = false, add "[]" to first time part
2145 
2146             sKeyword.Insert( (sal_Unicode) '[', 0 );
2147             sKeyword.Append( (sal_Unicode) ']' );
2148         }
2149         bHasDateTime = sal_True;
2150     }
2151 
2152     aFormatCode.append( sKeyword );
2153 
2154     //  collect the date elements that the format contains, to recognize default date formats
2155     switch ( nIndex )
2156     {
2157         case NF_KEY_NN:     eDateDOW = XML_DEA_SHORT;       break;
2158         case NF_KEY_NNN:
2159         case NF_KEY_NNNN:   eDateDOW = XML_DEA_LONG;        break;
2160         case NF_KEY_D:      eDateDay = XML_DEA_SHORT;       break;
2161         case NF_KEY_DD:     eDateDay = XML_DEA_LONG;        break;
2162         case NF_KEY_M:      eDateMonth = XML_DEA_SHORT;     break;
2163         case NF_KEY_MM:     eDateMonth = XML_DEA_LONG;      break;
2164         case NF_KEY_MMM:    eDateMonth = XML_DEA_TEXTSHORT; break;
2165         case NF_KEY_MMMM:   eDateMonth = XML_DEA_TEXTLONG;  break;
2166         case NF_KEY_YY:     eDateYear = XML_DEA_SHORT;      break;
2167         case NF_KEY_YYYY:   eDateYear = XML_DEA_LONG;       break;
2168         case NF_KEY_H:      eDateHours = XML_DEA_SHORT;     break;
2169         case NF_KEY_HH:     eDateHours = XML_DEA_LONG;      break;
2170         case NF_KEY_MI:     eDateMins = XML_DEA_SHORT;      break;
2171         case NF_KEY_MMI:    eDateMins = XML_DEA_LONG;       break;
2172         case NF_KEY_S:      eDateSecs = XML_DEA_SHORT;      break;
2173         case NF_KEY_SS:     eDateSecs = XML_DEA_LONG;       break;
2174         case NF_KEY_AP:
2175         case NF_KEY_AMPM:   break;          // AM/PM may or may not be in date/time formats -> ignore by itself
2176         default:
2177             bDateNoDefault = sal_True;      // any other element -> no default format
2178     }
2179 }
2180 
lcl_IsAtEnd(rtl::OUStringBuffer & rBuffer,const String & rToken)2181 sal_Bool lcl_IsAtEnd( rtl::OUStringBuffer& rBuffer, const String& rToken )
2182 {
2183     sal_Int32 nBufLen = rBuffer.getLength();
2184     xub_StrLen nTokLen = rToken.Len();
2185 
2186     if ( nTokLen > nBufLen )
2187         return sal_False;
2188 
2189     sal_Int32 nStartPos = nBufLen - nTokLen;
2190     for ( xub_StrLen nTokPos = 0; nTokPos < nTokLen; nTokPos++ )
2191         if ( rToken.GetChar( nTokPos ) != rBuffer.charAt( nStartPos + nTokPos ) )
2192             return sal_False;
2193 
2194     return sal_True;
2195 }
2196 
ReplaceNfKeyword(sal_uInt16 nOld,sal_uInt16 nNew)2197 sal_Bool SvXMLNumFormatContext::ReplaceNfKeyword( sal_uInt16 nOld, sal_uInt16 nNew )
2198 {
2199     //  replaces one keyword with another if it is found at the end of the code
2200 
2201     SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2202     if (!pFormatter)
2203         return sal_False;
2204 
2205     String sOldStr = pFormatter->GetKeyword( nFormatLang, nOld );
2206     if ( lcl_IsAtEnd( aFormatCode, sOldStr ) )
2207     {
2208         // remove old keyword
2209         aFormatCode.setLength( aFormatCode.getLength() - sOldStr.Len() );
2210 
2211         // add new keyword
2212         String sNewStr = pFormatter->GetKeyword( nFormatLang, nNew );
2213         aFormatCode.append( sNewStr );
2214 
2215         return sal_True;    // changed
2216     }
2217     return sal_False;       // not found
2218 }
2219 
AddCondition(const sal_Int32 nIndex)2220 void SvXMLNumFormatContext::AddCondition( const sal_Int32 nIndex )
2221 {
2222     rtl::OUString rApplyName = aMyConditions[nIndex].sMapName;
2223     rtl::OUString rCondition = aMyConditions[nIndex].sCondition;
2224     SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2225     sal_uInt32 l_nKey = pData->GetKeyForName( rApplyName );
2226     OUString sValue = OUString::createFromAscii( "value()" );       //! define constant
2227     sal_Int32 nValLen = sValue.getLength();
2228 
2229     if ( pFormatter && l_nKey != NUMBERFORMAT_ENTRY_NOT_FOUND &&
2230             rCondition.copy( 0, nValLen ) == sValue )
2231     {
2232         //! test for valid conditions
2233         //! test for default conditions
2234 
2235         OUString sRealCond = rCondition.copy( nValLen, rCondition.getLength() - nValLen );
2236         sal_Bool bDefaultCond = sal_False;
2237 
2238         //! collect all conditions first and adjust default to >=0, >0 or <0 depending on count
2239         //! allow blanks in conditions
2240         sal_Bool bFirstCond = ( aConditions.getLength() == 0 );
2241         if ( bFirstCond && aMyConditions.size() == 1 && sRealCond.compareToAscii( ">=0" ) == 0 )
2242             bDefaultCond = sal_True;
2243 
2244         if ( nType == XML_TOK_STYLES_TEXT_STYLE && nIndex == 2 )
2245         {
2246             //  The third condition in a number format with a text part can only be
2247             //  "all other numbers", the condition string must be empty.
2248             bDefaultCond = sal_True;
2249         }
2250 
2251         if (!bDefaultCond)
2252         {
2253             sal_Int32 nPos = sRealCond.indexOf( '.' );
2254             if ( nPos >= 0 )
2255             {   // #i8026# #103991# localize decimal separator
2256                 const String& rDecSep = GetLocaleData().getNumDecimalSep();
2257                 if ( rDecSep.Len() > 1 || rDecSep.GetChar(0) != '.' )
2258                     sRealCond = sRealCond.replaceAt( nPos, 1, rDecSep );
2259             }
2260             aConditions.append( (sal_Unicode) '[' );
2261             aConditions.append( sRealCond );
2262             aConditions.append( (sal_Unicode) ']' );
2263         }
2264 
2265         const SvNumberformat* pFormat = pFormatter->GetEntry(l_nKey);
2266         if ( pFormat )
2267             aConditions.append( OUString( pFormat->GetFormatstring() ) );
2268 
2269         aConditions.append( (sal_Unicode) ';' );
2270     }
2271 }
2272 
AddCondition(const sal_Int32 nIndex,const rtl::OUString & rFormat,const LocaleDataWrapper & rData)2273 void SvXMLNumFormatContext::AddCondition( const sal_Int32 nIndex, const rtl::OUString& rFormat, const LocaleDataWrapper& rData )
2274 {
2275     rtl::OUString rCondition = aMyConditions[nIndex].sCondition;
2276     OUString sValue = OUString::createFromAscii( "value()" );       //! define constant
2277     sal_Int32 nValLen = sValue.getLength();
2278 
2279     if ( rCondition.copy( 0, nValLen ) == sValue )
2280     {
2281         //! test for valid conditions
2282         //! test for default conditions
2283 
2284         OUString sRealCond = rCondition.copy( nValLen, rCondition.getLength() - nValLen );
2285         sal_Bool bDefaultCond = sal_False;
2286 
2287         //! collect all conditions first and adjust default to >=0, >0 or <0 depending on count
2288         //! allow blanks in conditions
2289         sal_Bool bFirstCond = ( aConditions.getLength() == 0 );
2290         if ( bFirstCond && aMyConditions.size() == 1 && sRealCond.compareToAscii( ">=0" ) == 0 )
2291             bDefaultCond = sal_True;
2292 
2293         if ( nType == XML_TOK_STYLES_TEXT_STYLE && nIndex == 2 )
2294         {
2295             //  The third condition in a number format with a text part can only be
2296             //  "all other numbers", the condition string must be empty.
2297             bDefaultCond = sal_True;
2298         }
2299 
2300         if (!bDefaultCond)
2301         {
2302             sal_Int32 nPos = sRealCond.indexOf( '.' );
2303             if ( nPos >= 0 )
2304             {   // #i8026# #103991# localize decimal separator
2305                 const String& rDecSep = rData.getNumDecimalSep();
2306                 if ( rDecSep.Len() > 1 || rDecSep.GetChar(0) != '.' )
2307                     sRealCond = sRealCond.replaceAt( nPos, 1, rDecSep );
2308             }
2309             aConditions.append( (sal_Unicode) '[' );
2310             aConditions.append( sRealCond );
2311             aConditions.append( (sal_Unicode) ']' );
2312         }
2313 
2314         aConditions.append( rFormat );
2315 
2316         aConditions.append( (sal_Unicode) ';' );
2317     }
2318 }
2319 
AddCondition(const rtl::OUString & rCondition,const rtl::OUString & rApplyName)2320 void SvXMLNumFormatContext::AddCondition( const rtl::OUString& rCondition, const rtl::OUString& rApplyName )
2321 {
2322     MyCondition aCondition;
2323     aCondition.sCondition = rCondition;
2324     aCondition.sMapName = rApplyName;
2325     aMyConditions.push_back(aCondition);
2326 }
2327 
AddColor(const Color & rColor)2328 void SvXMLNumFormatContext::AddColor( const Color& rColor )
2329 {
2330     SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2331     if (!pFormatter)
2332         return;
2333 
2334     OUStringBuffer aColName;
2335     for ( sal_uInt16 i=0; i<XML_NUMF_COLORCOUNT; i++ )
2336         if ( rColor == aNumFmtStdColors[i] )
2337         {
2338             aColName = OUString( pFormatter->GetKeyword( nFormatLang, sal::static_int_cast< sal_uInt16 >(NF_KEY_FIRSTCOLOR + i) ) );
2339             break;
2340         }
2341 
2342     if ( aColName.getLength() )
2343     {
2344         aColName.insert( 0, (sal_Unicode) '[' );
2345         aColName.append( (sal_Unicode) ']' );
2346         aFormatCode.insert( 0, aColName.makeStringAndClear() );
2347     }
2348 }
2349 
UpdateCalendar(const rtl::OUString & rNewCalendar)2350 void SvXMLNumFormatContext::UpdateCalendar( const rtl::OUString& rNewCalendar )
2351 {
2352     if ( rNewCalendar != sCalendar )
2353     {
2354         sCalendar = rNewCalendar;
2355         if ( sCalendar.getLength() )
2356         {
2357             aFormatCode.appendAscii( "[~" );            // intro for calendar code
2358             aFormatCode.append( sCalendar );
2359             aFormatCode.append( (sal_Unicode) ']' );    // end of "new" currency symbolcalendar code
2360         }
2361     }
2362 }
2363 
IsSystemLanguage()2364 sal_Bool SvXMLNumFormatContext::IsSystemLanguage()
2365 {
2366     return nFormatLang == LANGUAGE_SYSTEM;
2367 }
2368 
2369 //-------------------------------------------------------------------------
2370 
2371 //
2372 //  SvXMLNumFmtHelper
2373 //
2374 
2375 // #110680#
2376 //SvXMLNumFmtHelper::SvXMLNumFmtHelper(
2377 //                      const uno::Reference<util::XNumberFormatsSupplier>& rSupp )
SvXMLNumFmtHelper(const uno::Reference<util::XNumberFormatsSupplier> & rSupp,const uno::Reference<lang::XMultiServiceFactory> & xServiceFactory)2378 SvXMLNumFmtHelper::SvXMLNumFmtHelper(
2379     const uno::Reference<util::XNumberFormatsSupplier>& rSupp,
2380     const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory )
2381 :   mxServiceFactory(xServiceFactory)
2382 {
2383     DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
2384 
2385     SvNumberFormatter* pFormatter = NULL;
2386     SvNumberFormatsSupplierObj* pObj =
2387                     SvNumberFormatsSupplierObj::getImplementation( rSupp );
2388     if (pObj)
2389         pFormatter = pObj->GetNumberFormatter();
2390 
2391     // #110680#
2392     // pData = new SvXMLNumImpData( pFormatter );
2393     pData = new SvXMLNumImpData( pFormatter, mxServiceFactory );
2394 }
2395 
2396 // #110680#
2397 // SvXMLNumFmtHelper::SvXMLNumFmtHelper( SvNumberFormatter* pNumberFormatter )
SvXMLNumFmtHelper(SvNumberFormatter * pNumberFormatter,const uno::Reference<lang::XMultiServiceFactory> & xServiceFactory)2398 SvXMLNumFmtHelper::SvXMLNumFmtHelper(
2399     SvNumberFormatter* pNumberFormatter,
2400     const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory )
2401 :   mxServiceFactory(xServiceFactory)
2402 {
2403     DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
2404 
2405     // #110680#
2406     // pData = new SvXMLNumImpData( pNumberFormatter );
2407     pData = new SvXMLNumImpData( pNumberFormatter, mxServiceFactory );
2408 }
2409 
~SvXMLNumFmtHelper()2410 SvXMLNumFmtHelper::~SvXMLNumFmtHelper()
2411 {
2412     //  remove temporary (volatile) formats from NumberFormatter
2413     pData->RemoveVolatileFormats();
2414 
2415     delete pData;
2416 }
2417 
CreateChildContext(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,SvXMLStylesContext & rStyles)2418 SvXMLStyleContext*  SvXMLNumFmtHelper::CreateChildContext( SvXMLImport& rImport,
2419                 sal_uInt16 nPrefix, const OUString& rLocalName,
2420                 const uno::Reference<xml::sax::XAttributeList>& xAttrList,
2421                 SvXMLStylesContext& rStyles )
2422 {
2423     SvXMLStyleContext* pContext = NULL;
2424 
2425     const SvXMLTokenMap& rTokenMap = pData->GetStylesElemTokenMap();
2426     sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
2427     switch (nToken)
2428     {
2429         case XML_TOK_STYLES_NUMBER_STYLE:
2430         case XML_TOK_STYLES_CURRENCY_STYLE:
2431         case XML_TOK_STYLES_PERCENTAGE_STYLE:
2432         case XML_TOK_STYLES_DATE_STYLE:
2433         case XML_TOK_STYLES_TIME_STYLE:
2434         case XML_TOK_STYLES_BOOLEAN_STYLE:
2435         case XML_TOK_STYLES_TEXT_STYLE:
2436             pContext = new SvXMLNumFormatContext( rImport, nPrefix, rLocalName,
2437                                                     pData, nToken, xAttrList, rStyles );
2438             break;
2439     }
2440 
2441     // return NULL if not a data style, caller must handle other elements
2442     return pContext;
2443 }
2444 
GetStylesElemTokenMap()2445 const SvXMLTokenMap& SvXMLNumFmtHelper::GetStylesElemTokenMap()
2446 {
2447     return pData->GetStylesElemTokenMap();
2448 }
2449 
2450 /*sal_uInt32 SvXMLNumFmtHelper::GetKeyForName( const rtl::OUString& rName )
2451 {
2452     return pData->GetKeyForName( rName );
2453 }*/
2454