summaryrefslogtreecommitdiff
path: root/xmloff/source/draw/XMLNumberStyles.cxx
blob: 5e0ccb2c9e460d765a59e931f601bf670505ed37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_xmloff.hxx"
#include <tools/debug.hxx>
#include <XMLNumberStylesExport.hxx>
#include <XMLNumberStylesImport.hxx>
#include "xmlnmspe.hxx"
#include <xmloff/xmlimp.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmltoken.hxx>

#include "sdxmlexp_impl.hxx"
#include "sdxmlimp_impl.hxx"

using namespace rtl;
using namespace ::xmloff::token;

struct SdXMLDataStyleNumber
{
    enum XMLTokenEnum meNumberStyle;
    sal_Bool	mbLong;
    sal_Bool	mbTextual;
    sal_Bool	mbDecimal02;
    const char* mpText;
}
    aSdXMLDataStyleNumbers[] =
{
    { XML_DAY,			sal_False,		sal_False,		sal_False,		NULL },
    { XML_DAY,			sal_True,		sal_False,		sal_False,		NULL },
    { XML_MONTH,		sal_True,		sal_False,		sal_False,		NULL },
    { XML_MONTH,		sal_False,		sal_True,		sal_False,		NULL },
    { XML_MONTH,		sal_True,		sal_True,		sal_False,		NULL },
    { XML_YEAR,		    sal_False,		sal_False,		sal_False,		NULL },
    { XML_YEAR,		    sal_True,		sal_False,		sal_False,		NULL },
    { XML_DAY_OF_WEEK,	sal_False,		sal_False,		sal_False,		NULL },
    { XML_DAY_OF_WEEK,  sal_True,		sal_False,		sal_False,		NULL },
    { XML_TEXT,		    sal_False,		sal_False,		sal_False,		"."	 },
    { XML_TEXT,		    sal_False,		sal_False,		sal_False,		" "  },
    { XML_TEXT,		    sal_False,		sal_False,		sal_False,		", " },
    { XML_TEXT,		    sal_False,		sal_False,		sal_False,		". " },
    { XML_HOURS,		sal_False,		sal_False,		sal_False,		NULL },
    { XML_MINUTES,		sal_False,		sal_False,		sal_False,		NULL },
    { XML_TEXT,		    sal_False,		sal_False,		sal_False,		":"  },
    { XML_AM_PM,		sal_False,		sal_False,		sal_False,		NULL },
    { XML_SECONDS,		sal_False,		sal_False,		sal_False,		NULL },
    { XML_SECONDS,		sal_False,		sal_False,		sal_True,		NULL },
    { XML_TOKEN_INVALID,        0,              0,             0,       NULL  }
};

// date 

#define DATA_STYLE_NUMBER_END				0
#define DATA_STYLE_NUMBER_DAY				1	// <number:day/>
#define DATA_STYLE_NUMBER_DAY_LONG			2	// <number:day number:style="long"/>
#define DATA_STYLE_NUMBER_MONTH_LONG		3	// <number:month number:style="long"/>
#define DATA_STYLE_NUMBER_MONTH_TEXT		4	// <number:month number:textual="true"/>
#define DATA_STYLE_NUMBER_MONTH_LONG_TEXT	5	// <number:month number:style="long" number:textual="true"/>
#define DATA_STYLE_NUMBER_YEAR				6	// <number:year/>
#define DATA_STYLE_NUMBER_YEAR_LONG			7	// <number:year number:style="long"/>
#define DATA_STYLE_NUMBER_DAYOFWEEK			8	// <number:day-of-week/>
#define DATA_STYLE_NUMBER_DAYOFWEEK_LONG	9	// <number:day-of-week number:style="long"/>
#define DATA_STYLE_NUMBER_TEXT_POINT		10	// <number:text>.</number:text>
#define DATA_STYLE_NUMBER_TEXT_SPACE		11	// <number:text> </number:text>
#define DATA_STYLE_NUMBER_TEXT_COMMASPACE	12	// <number:text>, </number:text>
#define DATA_STYLE_NUMBER_TEXT_POINTSPACE	13	// <number:text>. </number:text>
#define DATA_STYLE_NUMBER_HOURS				14	// <number:hours/>
#define DATA_STYLE_NUMBER_MINUTES			15	// <number:minutes/>
#define DATA_STYLE_NUMBER_TEXT_COLON		16	// <number:text>:</number:text>
#define DATA_STYLE_NUMBER_AMPM				17	// <number:am-pm/>
#define DATA_STYLE_NUMBER_SECONDS			18	// <number:seconds/>
#define DATA_STYLE_NUMBER_SECONDS_02		19	// <number:seconds number:/>


struct SdXMLFixedDataStyle
{
    const char*	mpName;
    sal_Bool	mbAutomatic;
    sal_Bool	mbDateStyle;
    sal_uInt8	mpFormat[8];
};

const SdXMLFixedDataStyle aSdXML_Standard_Short =
{
    "D1", sal_True, sal_True,
    {
        DATA_STYLE_NUMBER_DAY_LONG,
        DATA_STYLE_NUMBER_TEXT_POINT,
        DATA_STYLE_NUMBER_MONTH_LONG,
        DATA_STYLE_NUMBER_TEXT_POINT,
        DATA_STYLE_NUMBER_YEAR_LONG,
        0, 0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_Standard_Long =
{
    "D2", sal_True, sal_True,
    {
        DATA_STYLE_NUMBER_DAYOFWEEK_LONG,
        DATA_STYLE_NUMBER_TEXT_COMMASPACE,
        DATA_STYLE_NUMBER_DAY,
        DATA_STYLE_NUMBER_TEXT_POINTSPACE,
        DATA_STYLE_NUMBER_MONTH_LONG_TEXT,
        DATA_STYLE_NUMBER_TEXT_SPACE,
        DATA_STYLE_NUMBER_YEAR_LONG,
        0
    }
};

const SdXMLFixedDataStyle aSdXML_DateStyle_1 =
{
    "D3", sal_False, sal_True,
    {
        DATA_STYLE_NUMBER_DAY_LONG,
        DATA_STYLE_NUMBER_TEXT_POINT,
        DATA_STYLE_NUMBER_MONTH_LONG,
        DATA_STYLE_NUMBER_TEXT_POINT,
        DATA_STYLE_NUMBER_YEAR,
        0, 0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_DateStyle_2 =
{
    "D4", sal_False, sal_True,
    { 
        DATA_STYLE_NUMBER_DAY_LONG,
        DATA_STYLE_NUMBER_TEXT_POINT,
        DATA_STYLE_NUMBER_MONTH_LONG,
        DATA_STYLE_NUMBER_TEXT_POINT,
        DATA_STYLE_NUMBER_YEAR_LONG,
        0, 0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_DateStyle_3 =
{
    "D5", sal_False, sal_True,
    {
        DATA_STYLE_NUMBER_DAY,
        DATA_STYLE_NUMBER_TEXT_POINTSPACE,
        DATA_STYLE_NUMBER_MONTH_TEXT,
        DATA_STYLE_NUMBER_TEXT_SPACE,
        DATA_STYLE_NUMBER_YEAR_LONG,
        0, 0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_DateStyle_4 =
{
    "D6", sal_False, sal_True,
    {
        DATA_STYLE_NUMBER_DAY,
        DATA_STYLE_NUMBER_TEXT_POINTSPACE,
        DATA_STYLE_NUMBER_MONTH_LONG_TEXT,
        DATA_STYLE_NUMBER_TEXT_SPACE,
        DATA_STYLE_NUMBER_YEAR_LONG,
        0, 0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_DateStyle_5 =
{
    "D7", sal_False, sal_True,
    {
        DATA_STYLE_NUMBER_DAYOFWEEK,
        DATA_STYLE_NUMBER_TEXT_COMMASPACE,
        DATA_STYLE_NUMBER_DAY,
        DATA_STYLE_NUMBER_TEXT_POINTSPACE,
        DATA_STYLE_NUMBER_MONTH_LONG_TEXT,
        DATA_STYLE_NUMBER_TEXT_SPACE,
        DATA_STYLE_NUMBER_YEAR_LONG,
        0
    }
};

const SdXMLFixedDataStyle aSdXML_DateStyle_6 =
{
    "D8", sal_False, sal_True,
    {
        DATA_STYLE_NUMBER_DAYOFWEEK_LONG,
        DATA_STYLE_NUMBER_TEXT_COMMASPACE,
        DATA_STYLE_NUMBER_DAY,
        DATA_STYLE_NUMBER_TEXT_POINTSPACE,
        DATA_STYLE_NUMBER_MONTH_LONG_TEXT,
        DATA_STYLE_NUMBER_TEXT_SPACE,
        DATA_STYLE_NUMBER_YEAR_LONG,
        0
    }
};

const SdXMLFixedDataStyle aSdXML_TimeStyle_1 =
{	"T1", sal_True, sal_False,
    {
        DATA_STYLE_NUMBER_HOURS,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_MINUTES,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_SECONDS,
        DATA_STYLE_NUMBER_AMPM,
        0, 0,
    }
};

const SdXMLFixedDataStyle aSdXML_TimeStyle_2 =
{	"T2", sal_False, sal_False,
    {
        DATA_STYLE_NUMBER_HOURS,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_MINUTES,
        0, 0, 0, 0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_TimeStyle_3 =
{	"T3", sal_False, sal_False,
    {
        DATA_STYLE_NUMBER_HOURS,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_MINUTES,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_SECONDS,
        0, 0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_TimeStyle_4 =
{	"T4", sal_False, sal_False,
    {
        DATA_STYLE_NUMBER_HOURS,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_MINUTES,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_SECONDS_02,
        0, 0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_TimeStyle_5 =
{	"T5", sal_False, sal_False,
    {
        DATA_STYLE_NUMBER_HOURS,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_MINUTES,
        DATA_STYLE_NUMBER_AMPM,
        0, 0, 0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_TimeStyle_6 =
{	"T6", sal_False, sal_False,
    {
        DATA_STYLE_NUMBER_HOURS,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_MINUTES,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_SECONDS,
        DATA_STYLE_NUMBER_AMPM,
        0, 0
    }
};

const SdXMLFixedDataStyle aSdXML_TimeStyle_7 =
{	"T7", sal_False, sal_False,
    {
        DATA_STYLE_NUMBER_HOURS,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_MINUTES,
        DATA_STYLE_NUMBER_TEXT_COLON,
        DATA_STYLE_NUMBER_SECONDS_02,
        DATA_STYLE_NUMBER_AMPM,
        0, 0
    }
};

const SdXMLFixedDataStyle* aSdXMLFixedDateFormats[SdXMLDateFormatCount] =
{
    &aSdXML_Standard_Short,
    &aSdXML_Standard_Long,
    &aSdXML_DateStyle_1,
    &aSdXML_DateStyle_2,
    &aSdXML_DateStyle_3,
    &aSdXML_DateStyle_4,
    &aSdXML_DateStyle_5,
    &aSdXML_DateStyle_6,
};

const SdXMLFixedDataStyle* aSdXMLFixedTimeFormats[SdXMLTimeFormatCount] =
{
    &aSdXML_TimeStyle_1,
    &aSdXML_TimeStyle_2,
    &aSdXML_TimeStyle_3,
    &aSdXML_TimeStyle_4,
    &aSdXML_TimeStyle_5,
    &aSdXML_TimeStyle_6,
    &aSdXML_TimeStyle_7
};


///////////////////////////////////////////////////////////////////////
// export

#ifndef SVX_LIGHT

static void SdXMLExportDataStyleNumber( SdXMLExport& rExport, SdXMLDataStyleNumber& rElement )
{
    if( rElement.mbDecimal02 )
    {
        rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES, XML_2 );
    }

    if( rElement.mbLong )
    {
        rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_STYLE, XML_LONG );
    }

    if( rElement.mbTextual )
    {
        rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TEXTUAL, XML_TRUE );
    }

    SvXMLElementExport aNumberStyle( rExport, XML_NAMESPACE_NUMBER, rElement.meNumberStyle, sal_True, sal_False );
    if( rElement.mpText )
    {
        OUString sAttrValue( OUString::createFromAscii( rElement.mpText ) );
        rExport.GetDocHandler()->characters( sAttrValue );
    }
}

static void SdXMLExportStyle( SdXMLExport& rExport, const SdXMLFixedDataStyle* pStyle, const SdXMLFixedDataStyle* pStyle2 = NULL )
{
    OUString sAttrValue;

    // name
    sAttrValue = OUString::createFromAscii( pStyle->mpName );
    if( pStyle2 )
        sAttrValue += OUString::createFromAscii( pStyle2->mpName );

    rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, sAttrValue );

    if( pStyle->mbAutomatic )
    {
        rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_AUTOMATIC_ORDER, XML_TRUE );
    }

    SvXMLElementExport aElement( rExport, XML_NAMESPACE_NUMBER, pStyle->mbDateStyle ? XML_DATE_STYLE : XML_TIME_STYLE, sal_True, sal_True );

    do
    {

        const sal_uInt8* pElements = (const sal_uInt8*)&pStyle->mpFormat[0];

        while( *pElements )
        {
            SdXMLDataStyleNumber& rElement = aSdXMLDataStyleNumbers[ (*pElements++) - 1 ];
            SdXMLExportDataStyleNumber( rExport, rElement );
        }

        if( pStyle2 )
        {
            SdXMLDataStyleNumber& rElement = aSdXMLDataStyleNumbers[ DATA_STYLE_NUMBER_TEXT_SPACE - 1 ];
            SdXMLExportDataStyleNumber( rExport, rElement );
        }

        pStyle = pStyle2;
        pStyle2 = NULL;
    }
    while( pStyle );
}

void SdXMLNumberStylesExporter::exportTimeStyle( SdXMLExport& rExport, sal_Int32 nStyle )
{
    DBG_ASSERT( (nStyle >= 0) && (nStyle < SdXMLTimeFormatCount), "Unknown time style!" );
    if( (nStyle >= 0) && (nStyle < SdXMLTimeFormatCount) )
        SdXMLExportStyle( rExport, aSdXMLFixedTimeFormats[ nStyle ] );
}

void SdXMLNumberStylesExporter::exportDateStyle( SdXMLExport& rExport, sal_Int32 nStyle )
{
    if( nStyle > 0x0f )
    {
        int nDateStyle = nStyle & 0x0f;
        bool bHasDate = nDateStyle != 0;

        if( nDateStyle > 1 )
            nDateStyle -= 2;

        DBG_ASSERT( (nDateStyle >= 0) && (nDateStyle < SdXMLDateFormatCount), "unknown date style!" );

        int nTimeStyle = (nStyle >> 4) & 0x0f;
        bool bHasTime = nTimeStyle != 0;

        if( nTimeStyle > 1 )
            nTimeStyle -= 2;

        DBG_ASSERT( (nTimeStyle >= 0) && (nTimeStyle < SdXMLTimeFormatCount), "Unknown time style!" );

        if( (nDateStyle >= 0) && (nDateStyle < SdXMLDateFormatCount) && (nTimeStyle >= 0) && (nTimeStyle < SdXMLTimeFormatCount) )
        {
            if( bHasDate )
            {
                if( bHasTime )
                {
                    SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nDateStyle ], aSdXMLFixedTimeFormats[ nTimeStyle ] );
                }
                else
                {
                    SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nDateStyle ] );
                }
            }
            else if( bHasTime )
            {
                SdXMLExportStyle( rExport, aSdXMLFixedTimeFormats[ nTimeStyle ] );
            }
        }
    }
    else
    {
        DBG_ASSERT( (nStyle >= 0) && (nStyle < SdXMLDateFormatCount), "unknown date style!" );
        if( (nStyle >= 0) && (nStyle < SdXMLDateFormatCount) )
            SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nStyle ] );
    }
}

OUString SdXMLNumberStylesExporter::getTimeStyleName(const sal_Int32 nTimeFormat )
{
    sal_Int32 nFormat = nTimeFormat;
    if( nFormat > 1 )
        nFormat -= 2;

    if( (nFormat >= 0) && (nFormat < SdXMLTimeFormatCount) )
    {
        return OUString::createFromAscii(aSdXMLFixedTimeFormats[nFormat]->mpName );
    }
    else
    {
        return OUString();
    }
}

OUString SdXMLNumberStylesExporter::getDateStyleName(const sal_Int32 nDateFormat )
{
    sal_Int32 nFormat = nDateFormat;

    if( nFormat > 0x0f )
    {
        OUString aStr;
        if( nFormat & 0x0f )
            aStr = getDateStyleName( nFormat & 0x0f );
        aStr += getTimeStyleName( (nFormat >> 4) & 0x0f );
        return aStr;
    }

    if( nFormat > 1 )
        nFormat -= 2;

    if( (nFormat >= 0) && (nFormat < SdXMLDateFormatCount) )
    {
        return OUString::createFromAscii(aSdXMLFixedDateFormats[nFormat]->mpName );
    }
    else
    {
        return OUString();
    }
}

#endif // #ifndef SVX_LIGHT


///////////////////////////////////////////////////////////////////////
// import

class SdXMLNumberFormatMemberImportContext : public SvXMLImportContext
{
private:
    SdXMLNumberFormatImportContext* mpParent;

    OUString maNumberStyle;
    sal_Bool mbLong;
    sal_Bool mbTextual;
    sal_Bool mbDecimal02;
    OUString maText;
    SvXMLImportContext* mpSlaveContext;

public:
    TYPEINFO();

    SdXMLNumberFormatMemberImportContext( SvXMLImport& rImport, 
        sal_uInt16 nPrfx,
        const rtl::OUString& rLocalName, 
        const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
        SdXMLNumberFormatImportContext* pParent,
        SvXMLImportContext* pSlaveContext );
    virtual ~SdXMLNumberFormatMemberImportContext();

    virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
                                   const ::rtl::OUString& rLocalName,
                                   const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );

    virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );

    virtual void EndElement();

    virtual void Characters( const ::rtl::OUString& rChars );
};

TYPEINIT1( SdXMLNumberFormatMemberImportContext, SvXMLImportContext );

SdXMLNumberFormatMemberImportContext::SdXMLNumberFormatMemberImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, SdXMLNumberFormatImportContext* pParent, SvXMLImportContext* pSlaveContext )
:	SvXMLImportContext(rImport, nPrfx, rLocalName),
    mpParent( pParent ),
    maNumberStyle( rLocalName ),
    mpSlaveContext( pSlaveContext )
{
    mbLong = sal_False;
    mbTextual = sal_False;
    mbDecimal02 = sal_False;
    
    const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
    for(sal_Int16 i=0; i < nAttrCount; i++)
    {
        OUString sAttrName = xAttrList->getNameByIndex( i );
        OUString aLocalName;
        sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
        OUString sValue = xAttrList->getValueByIndex( i );

        if( nPrefix == XML_NAMESPACE_NUMBER )
        {
            if( IsXMLToken( aLocalName, XML_DECIMAL_PLACES ) )
            {
                mbDecimal02 =  IsXMLToken( sValue, XML_2 );
            }
            else if( IsXMLToken( aLocalName, XML_STYLE ) )
            {
                mbLong = IsXMLToken( sValue, XML_LONG );
            }
            else if( IsXMLToken( aLocalName, XML_TEXTUAL ) )
            {
                mbTextual = IsXMLToken( sValue, XML_TRUE );
            }
        }
    }

}

SdXMLNumberFormatMemberImportContext::~SdXMLNumberFormatMemberImportContext()
{
}

SvXMLImportContext *SdXMLNumberFormatMemberImportContext::CreateChildContext( USHORT nPrefix,
                           const ::rtl::OUString& rLocalName,
                           const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
{
    return mpSlaveContext->CreateChildContext( nPrefix, rLocalName, xAttrList );
}

void SdXMLNumberFormatMemberImportContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
{
    mpSlaveContext->StartElement( xAttrList );
}

void SdXMLNumberFormatMemberImportContext::EndElement()
{
    mpSlaveContext->EndElement();

    if( mpParent )
        mpParent->add( maNumberStyle, mbLong, mbTextual, mbDecimal02, maText );
}

void SdXMLNumberFormatMemberImportContext::Characters( const ::rtl::OUString& rChars )
{
    mpSlaveContext->Characters( rChars );
    maText += rChars;
}

TYPEINIT1( SdXMLNumberFormatImportContext, SvXMLImportContext );


SdXMLNumberFormatImportContext::SdXMLNumberFormatImportContext( SdXMLImport& rImport, sal_uInt16 nPrfx,	const rtl::OUString& rLocalName, SvXMLNumImpData* pNewData, sal_uInt16 nNewType, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, SvXMLStylesContext& rStyles)
:	SvXMLNumFormatContext(rImport, nPrfx, rLocalName, pNewData, nNewType, xAttrList, rStyles),
    mrImport( rImport ),
    mbAutomatic( sal_False ),
    mnIndex(0),
    mnKey( -1 )
{
    mbTimeStyle = IsXMLToken( rLocalName, XML_TIME_STYLE );

    const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
    for(sal_Int16 i=0; i < nAttrCount; i++)
    {
        OUString sAttrName = xAttrList->getNameByIndex( i );
        OUString aLocalName;
        sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
        OUString sValue = xAttrList->getValueByIndex( i );

        if( nPrefix == XML_NAMESPACE_NUMBER )
        {
            if( IsXMLToken( aLocalName, XML_AUTOMATIC_ORDER ) )
            {
                mbAutomatic = IsXMLToken( sValue, XML_TRUE );
            }
        }
    }
}

SdXMLNumberFormatImportContext::~SdXMLNumberFormatImportContext()
{
}

void SdXMLNumberFormatImportContext::add( OUString& rNumberStyle, sal_Bool bLong, sal_Bool bTextual, sal_Bool	bDecimal02, OUString& rText )
{
    if( mnIndex == -1 || mnIndex == 16 )
    {
        mnIndex = -1;
        return;
    }
    
    const SdXMLDataStyleNumber* pStyleMember = aSdXMLDataStyleNumbers;
    for( sal_uInt8 nIndex = 0; pStyleMember->meNumberStyle != XML_TOKEN_INVALID; nIndex++, pStyleMember++ )
    {
        if( (IsXMLToken(rNumberStyle, pStyleMember->meNumberStyle) &&
            (pStyleMember->mbLong == bLong) &&
            (pStyleMember->mbTextual == bTextual) &&
            (pStyleMember->mbDecimal02 == bDecimal02) &&
            ( ( (pStyleMember->mpText == NULL) && (rText.getLength() == 0) ) ||
              ( pStyleMember->mpText && (rText.compareToAscii( pStyleMember->mpText )  == 0 )) ) ) )
        {
            mnElements[mnIndex++] = nIndex + 1;
            return;
        }
    }
}

bool SdXMLNumberFormatImportContext::compareStyle( const SdXMLFixedDataStyle* pStyle, sal_Int16& nIndex ) const
{
    if( (pStyle->mbAutomatic != mbAutomatic) && (nIndex == 0))
        return sal_False;

    sal_Int16 nCompareIndex;
    for( nCompareIndex = 0; nCompareIndex < 8; nIndex++, nCompareIndex++ )
    {
        if( pStyle->mpFormat[nCompareIndex] != mnElements[nIndex] )
            return sal_False;
    }

    return sal_True;
}

void SdXMLNumberFormatImportContext::EndElement()
{
    SvXMLNumFormatContext::EndElement();

    for( ; mnIndex < 16; mnIndex++ )
    {
        mnElements[mnIndex] = 0;
    }

    if( mbTimeStyle )
    {
        // compare import with all time styles
        for( sal_Int16 nFormat = 0; nFormat < SdXMLTimeFormatCount; nFormat++ )
        {
            sal_Int16 nIndex = 0;
            if( compareStyle( aSdXMLFixedTimeFormats[nFormat], nIndex ) )
            {
                mnKey = nFormat + 2;
                break;
            }
        }
    }
    else
    {
        // compare import with all date styles
        for( sal_Int16 nFormat = 0; nFormat < SdXMLDateFormatCount; nFormat++ )
        {
            sal_Int16 nIndex = 0;
            if( compareStyle( aSdXMLFixedDateFormats[nFormat], nIndex ) )
            {
                mnKey = nFormat + 2;
                break;
            }
            else if( mnElements[nIndex] == DATA_STYLE_NUMBER_TEXT_SPACE )
            {
                // if its a valid date ending with a space, see if a time style follows
                for( sal_Int16 nTimeFormat = 0; nTimeFormat < SdXMLTimeFormatCount; nTimeFormat++ )
                {
                    sal_Int16 nIndex2 = nIndex + 1;
                    if( compareStyle( aSdXMLFixedTimeFormats[nTimeFormat], nIndex2 ) )
                    {
                        mnKey = (nFormat + 2) | ((nTimeFormat + 2) << 4);
                        break;
                    }
                }
            }
        }

        // no date style found? maybe its an extended time style
        if( mnKey == -1 )
        {
            // compare import with all time styles
            for( sal_Int16 nFormat = 0; nFormat < SdXMLTimeFormatCount; nFormat++ )
            {
                sal_Int16 nIndex = 0;
                if( compareStyle( aSdXMLFixedTimeFormats[nFormat], nIndex ) )
                {
                    mnKey = (nFormat + 2) << 4;
                    break;
                }
            }
        }
    }
}

SvXMLImportContext * SdXMLNumberFormatImportContext::CreateChildContext( USHORT nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
{
    return new SdXMLNumberFormatMemberImportContext( GetImport(), nPrefix, rLocalName, xAttrList, this, SvXMLNumFormatContext::CreateChildContext( nPrefix, rLocalName, xAttrList ) );
}