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
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
|
/*************************************************************************
*
* $RCSfile: xmlnumfe.cxx,v $
*
* $Revision: 1.2 $
*
* last change: $Author: sab $ $Date: 2000-10-24 10:41:04 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library 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 for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#define _SVSTDARR_ULONGS
#define _ZFORLIST_DECLARE_TABLE
#include <svtools/svstdarr.hxx>
#include <svtools/zforlist.hxx>
#include <svtools/zformat.hxx>
#include <svtools/numuno.hxx>
#include <tools/isolang.hxx>
#include <tools/debug.hxx>
#include <tools/solmath.hxx>
#include <unotools/charclass.hxx>
#include <com/sun/star/lang/Locale.hpp>
#include <rtl/ustrbuf.hxx>
#include <comphelper/processfactory.hxx>
#include "xmlnumfe.hxx"
#include "xmlnmspe.hxx"
#include "xmlkywd.hxx"
#include "xmluconv.hxx"
#include "attrlist.hxx"
#include "nmspmap.hxx"
#include "families.hxx"
using namespace ::rtl;
using namespace ::com::sun::star;
//-------------------------------------------------------------------------
//! enum Sc_SymbolType is in source/numbers/zforscan.hxx
#define XMLNUM_SYMBOLTYPE_STRING (-1)
#define XMLNUM_SYMBOLTYPE_DEL (-2)
#define XMLNUM_SYMBOLTYPE_BLANK (-3)
#define XMLNUM_SYMBOLTYPE_STAR (-4)
#define XMLNUM_SYMBOLTYPE_DIGIT (-5)
#define XMLNUM_SYMBOLTYPE_DECSEP (-6)
#define XMLNUM_SYMBOLTYPE_THSEP (-7)
#define XMLNUM_SYMBOLTYPE_EXP (-8)
#define XMLNUM_SYMBOLTYPE_FRAC (-9)
#define XMLNUM_SYMBOLTYPE_EMPTY (-10)
#define XMLNUM_SYMBOLTYPE_FRACBLANK (-11)
#define XMLNUM_SYMBOLTYPE_COMMENT (-12)
#define XMLNUM_SYMBOLTYPE_CURRENCY (-13)
#define XMLNUM_SYMBOLTYPE_CURRDEL (-14)
#define XMLNUM_SYMBOLTYPE_CURREXT (-15)
//-------------------------------------------------------------------------
// 4th condition for text formats doesn't work
//#define XMLNUM_MAX_PARTS 4
#define XMLNUM_MAX_PARTS 3
//-------------------------------------------------------------------------
class SvXMLNumUsedList_Impl
{
SvULongs aUsed;
SvULongs aWasUsed;
public:
SvXMLNumUsedList_Impl();
~SvXMLNumUsedList_Impl();
void SetUsed( sal_uInt32 nKey );
sal_Bool IsUsed( sal_uInt32 nKey ) const;
sal_Bool IsWasUsed( sal_uInt32 nKey ) const;
void Export();
};
//-------------------------------------------------------------------------
//
//! SvXMLNumUsedList_Impl should be optimized!
//
SvXMLNumUsedList_Impl::SvXMLNumUsedList_Impl()
{
}
SvXMLNumUsedList_Impl::~SvXMLNumUsedList_Impl()
{
}
void SvXMLNumUsedList_Impl::SetUsed( sal_uInt32 nKey )
{
if ( !IsUsed( nKey ) && !IsWasUsed(nKey) )
aUsed.Insert( nKey, aUsed.Count() );
}
sal_Bool SvXMLNumUsedList_Impl::IsUsed( sal_uInt32 nKey ) const
{
sal_uInt16 nCount = aUsed.Count();
for ( sal_uInt16 i = 0; i < nCount; i++ )
if ( aUsed[i] == nKey )
return sal_True;
return sal_False;
}
sal_Bool SvXMLNumUsedList_Impl::IsWasUsed( sal_uInt32 nKey ) const
{
sal_uInt16 nCount = aWasUsed.Count();
for ( sal_uInt16 i = 0; i < nCount; i++ )
if ( aWasUsed[i] == nKey )
return sal_True;
return sal_False;
}
void SvXMLNumUsedList_Impl::Export()
{
sal_uInt16 nCount = aUsed.Count();
for (sal_uInt16 i = 0; i < nCount; i++)
aWasUsed.Insert( aUsed[i], aWasUsed.Count());
aUsed.Remove(0, nCount);
}
//-------------------------------------------------------------------------
SvXMLNumFmtExport::SvXMLNumFmtExport(
const uno::Reference< xml::sax::XDocumentHandler >& rHdl,
const uno::Reference< util::XNumberFormatsSupplier >& rSupp ) :
xHandler( rHdl ),
pFormatter( NULL ),
pNamespaceMap( NULL ),
sCDATA( OUString::createFromAscii( sXML_CDATA ) ),
sWS( OUString::createFromAscii( sXML_WS ) )
{
// supplier must be SvNumberFormatsSupplierObj
SvNumberFormatsSupplierObj* pObj =
SvNumberFormatsSupplierObj::getImplementation( rSupp );
if (pObj)
pFormatter = pObj->GetNumberFormatter();
pAttrList = new SvXMLAttributeList;
xAttrList = pAttrList;
pUsedList = new SvXMLNumUsedList_Impl;
}
SvXMLNumFmtExport::~SvXMLNumFmtExport()
{
delete pUsedList;
}
//-------------------------------------------------------------------------
//
// helper methods
//
OUString lcl_CreateStyleName( sal_Int32 nKey, sal_Int32 nPart, sal_Bool bDefPart )
{
OUStringBuffer aFmtName( 10L );
aFmtName.append( (sal_Unicode)'N' );
aFmtName.append( nKey );
if (!bDefPart)
{
aFmtName.append( (sal_Unicode)'P' );
aFmtName.append( nPart );
}
return aFmtName.makeStringAndClear();
}
void SvXMLNumFmtExport::AddTextualAttr_Impl( sal_Bool bText )
{
if ( bText ) // non-textual
{
OUString sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_textual ) );
OUString sAttrValue = OUString::createFromAscii( sXML_true );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
}
void SvXMLNumFmtExport::AddStyleAttr_Impl( sal_Bool bLong )
{
if ( bLong ) // short is default
{
OUString sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_style ) );
OUString sAttrValue = OUString::createFromAscii( sXML_long );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
}
void SvXMLNumFmtExport::AddLanguageAttr_Impl( sal_Int32 nLang )
{
if ( nLang != LANGUAGE_SYSTEM )
{
String aLangStr, aCountryStr;
ConvertLanguageToIsoNames( nLang, aLangStr, aCountryStr );
OUString sAttrName, sAttrValue;
if (aLangStr.Len())
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER, OUString::createFromAscii(sXML_language) );
sAttrValue = aLangStr;
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
if (aCountryStr.Len())
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER, OUString::createFromAscii(sXML_country) );
sAttrValue = aCountryStr;
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
}
}
//-------------------------------------------------------------------------
//
// methods to write individual elements within a format
//
void SvXMLNumFmtExport::WriteColorElement_Impl( const Color& rColor )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_STYLE,
OUString::createFromAscii( sXML_properties ) );
OUString sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_FO,
OUString::createFromAscii(sXML_color) );
OUStringBuffer aColStr( 7 );
SvXMLUnitConverter::convertColor( aColStr, rColor );
OUString sAttrValue = aColStr.makeStringAndClear();
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteTextElement_Impl( const OUString& rString )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_text ) );
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->characters( rString );
xHandler->endElement( sElem );
}
void SvXMLNumFmtExport::WriteCurrencyElement_Impl( const OUString& rString,
const OUString& rExt )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_currency_symbol ) );
if ( rExt.getLength() )
{
sal_Int32 nLang = rExt.toInt32(16); // hex
if ( nLang < 0 ) // extension string may contain "-" separator
nLang = -nLang;
AddLanguageAttr_Impl( nLang ); // adds to pAttrList
}
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->characters( rString );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteBooleanElement_Impl()
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_boolean ) );
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
}
void SvXMLNumFmtExport::WriteTextContentElement_Impl()
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_text_content ) );
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
}
// date elements
void SvXMLNumFmtExport::WriteDayElement_Impl( sal_Bool bLong )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_day ) );
AddStyleAttr_Impl( bLong ); // adds to pAttrList
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteMonthElement_Impl( sal_Bool bLong, sal_Bool bText )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_month ) );
AddStyleAttr_Impl( bLong ); // adds to pAttrList
AddTextualAttr_Impl( bText ); // adds to pAttrList
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteYearElement_Impl( sal_Bool bLong )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_year ) );
AddStyleAttr_Impl( bLong ); // adds to pAttrList
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteDayOfWeekElement_Impl( sal_Bool bLong )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_day_of_week ) );
AddStyleAttr_Impl( bLong ); // adds to pAttrList
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteWeekElement_Impl()
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_week_of_year ) );
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
}
void SvXMLNumFmtExport::WriteQuarterElement_Impl( sal_Bool bLong )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_quarter ) );
AddStyleAttr_Impl( bLong ); // adds to pAttrList
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
// time elements
void SvXMLNumFmtExport::WriteHoursElement_Impl( sal_Bool bLong )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_hours ) );
AddStyleAttr_Impl( bLong ); // adds to pAttrList
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteMinutesElement_Impl( sal_Bool bLong )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_minutes ) );
AddStyleAttr_Impl( bLong ); // adds to pAttrList
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteSecondsElement_Impl( sal_Bool bLong, sal_uInt16 nDecimals )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_seconds ) );
AddStyleAttr_Impl( bLong ); // adds to pAttrList
if ( nDecimals > 0 )
{
OUString sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_decimal_places ) );
OUString sAttrValue = OUString::valueOf( (sal_Int32) nDecimals );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteAMPMElement_Impl()
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_am_pm ) );
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
}
// numbers
void SvXMLNumFmtExport::WriteNumberElement_Impl(
sal_Int32 nDecimals, sal_Int32 nInteger,
const OUString& rDashStr, sal_Bool bGrouping )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_number ) );
OUString sAttrName, sAttrValue;
// decimals
if ( nDecimals >= 0 ) // negative = automatic
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_decimal_places ) );
sAttrValue = OUString::valueOf( nDecimals );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// integer digits
if ( nInteger >= 0 ) // negative = automatic
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_min_integer_digits ) );
sAttrValue = OUString::valueOf( nInteger );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// decimal replacement (dashes)
if ( rDashStr.getLength() )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_decimal_replacement ) );
sAttrValue = rDashStr;
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// (automatic) grouping separator
if ( bGrouping )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_grouping ) );
sAttrValue = OUString::createFromAscii(sXML_true);
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteScientificElement_Impl(
sal_Int32 nDecimals, sal_Int32 nInteger,
sal_Bool bGrouping, sal_Int32 nExp )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_scientific_number ) );
OUString sAttrName, sAttrValue;
// decimals
if ( nDecimals >= 0 ) // negative = automatic
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_decimal_places ) );
sAttrValue = OUString::valueOf( nDecimals );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// integer digits
if ( nInteger >= 0 ) // negative = automatic
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_min_integer_digits ) );
sAttrValue = OUString::valueOf( nInteger );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// (automatic) grouping separator
if ( bGrouping )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_grouping ) );
sAttrValue = OUString::createFromAscii(sXML_true);
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// exponent digits
if ( nExp >= 0 )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_min_exponent_digits ) );
sAttrValue = OUString::valueOf( nExp );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
void SvXMLNumFmtExport::WriteFractionElement_Impl(
sal_Int32 nInteger, sal_Bool bGrouping,
sal_Int32 nNumerator, sal_Int32 nDenominator )
{
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_fraction ) );
OUString sAttrName, sAttrValue;
// integer digits
if ( nInteger >= 0 ) // negative = default (no integer part)
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_min_integer_digits ) );
sAttrValue = OUString::valueOf( nInteger );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// (automatic) grouping separator
if ( bGrouping )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_grouping ) );
sAttrValue = OUString::createFromAscii(sXML_true);
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// numerator digits
if ( nNumerator >= 0 )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_min_numerator_digits ) );
sAttrValue = OUString::valueOf( nNumerator );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// denominator digits
if ( nDenominator >= 0 )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_min_denominator_digits ) );
sAttrValue = OUString::valueOf( nDenominator );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
// mapping (condition)
void SvXMLNumFmtExport::WriteMapElement_Impl( sal_Int32 nOp, double fLimit,
sal_Int32 nKey, sal_Int32 nPart )
{
if ( nOp != NUMBERFORMAT_OP_NO )
{
// style namespace
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_STYLE,
OUString::createFromAscii( sXML_map ) );
OUString sAttrName, sAttrValue;
OUStringBuffer aCondStr( 20L );
aCondStr.appendAscii( "value()" ); //! define constant
switch ( nOp )
{
case NUMBERFORMAT_OP_EQ: aCondStr.append( (sal_Unicode) '=' ); break;
case NUMBERFORMAT_OP_NE: aCondStr.appendAscii( "<>" ); break;
case NUMBERFORMAT_OP_LT: aCondStr.append( (sal_Unicode) '<' ); break;
case NUMBERFORMAT_OP_LE: aCondStr.appendAscii( "<=" ); break;
case NUMBERFORMAT_OP_GT: aCondStr.append( (sal_Unicode) '>' ); break;
case NUMBERFORMAT_OP_GE: aCondStr.appendAscii( ">=" ); break;
default:
DBG_ERROR("unknown operator");
}
String aValStr;
SolarMath::DoubleToString( aValStr, fLimit, 'A', INT_MAX, '.', TRUE );
aCondStr.append( aValStr );
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_STYLE,
OUString::createFromAscii( sXML_condition ) );
sAttrValue = aCondStr.makeStringAndClear();
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_STYLE,
OUString::createFromAscii( sXML_apply_style_name ) );
sAttrValue = lcl_CreateStyleName( nKey, nPart, sal_False );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
xHandler->endElement( sElem );
pAttrList->Clear();
}
}
//-------------------------------------------------------------------------
// for old (automatic) currency formats: parse currency symbol from text
xub_StrLen lcl_FindSymbol( const String& sUpperStr, const String& sCurString )
{
// search for currency symbol
// Quoting as in ImpSvNumberformatScan::Symbol_Division
xub_StrLen nCPos = 0;
while (nCPos != STRING_NOTFOUND)
{
nCPos = sUpperStr.Search( sCurString, nCPos );
if (nCPos != STRING_NOTFOUND)
{
// in Quotes?
xub_StrLen nQ = SvNumberformat::GetQuoteEnd( sUpperStr, nCPos );
if ( nQ == STRING_NOTFOUND )
{
// dm can be escaped as "dm or \d
sal_Unicode c;
if ( nCPos == 0 ||
((c = sUpperStr.GetChar(xub_StrLen(nCPos-1))) != '"'
&& c != '\\') )
{
return nCPos; // found
}
else
nCPos++; // continue
}
else
nCPos = nQ + 1; // continue after quote end
}
}
return STRING_NOTFOUND; // not found
}
void SvXMLNumFmtExport::WriteTextWithCurrency_Impl( const OUString& rString,
const International& rIntl,
const CharClass& rCharClass )
{
String sCurString = rIntl.GetCurrSymbol();
String sUpperStr = rCharClass.upper(rString);
xub_StrLen nPos = lcl_FindSymbol( sUpperStr, sCurString );
if ( nPos != STRING_NOTFOUND )
{
sal_Int32 nLength = rString.getLength();
sal_Int32 nCurLen = sCurString.Len();
sal_Int32 nCont = nPos + nCurLen;
// text before currency symbol
if ( nPos > 0 )
WriteTextElement_Impl( rString.copy( 0, nPos ) );
// currency symbol (empty string -> default)
OUString sEmpty;
WriteCurrencyElement_Impl( sEmpty, sEmpty );
// text after currency symbol
if ( nCont < nLength )
WriteTextElement_Impl( rString.copy( nCont, nLength-nCont ) );
}
else
WriteTextElement_Impl( rString ); // simple text
}
//-------------------------------------------------------------------------
//
// export one part (condition)
//
void SvXMLNumFmtExport::ExportPart_Impl( SvNumberformat& rFormat, sal_uInt32 nKey,
sal_uInt16 nPart, sal_Bool bDefPart )
{
//! for the default part, pass the coditions from the other parts!
//
// element name
//
NfIndexTableOffset eBuiltIn = pFormatter->GetIndexTableOffset( nKey );
short nFmtType = rFormat.GetType() & ~NUMBERFORMAT_DEFINED;
OUString sType;
switch ( nFmtType )
{
//! case 0: // may occur in imported documents (?)
case NUMBERFORMAT_NUMBER:
case NUMBERFORMAT_SCIENTIFIC:
case NUMBERFORMAT_FRACTION:
sType = OUString::createFromAscii(sXML_number_style);
break;
case NUMBERFORMAT_PERCENT:
sType = OUString::createFromAscii(sXML_percentage_style);
break;
case NUMBERFORMAT_CURRENCY:
sType = OUString::createFromAscii(sXML_currency_style);
break;
case NUMBERFORMAT_DATE:
case NUMBERFORMAT_DATETIME:
sType = OUString::createFromAscii(sXML_date_style);
break;
case NUMBERFORMAT_TIME:
sType = OUString::createFromAscii(sXML_time_style);
break;
case NUMBERFORMAT_TEXT:
sType = OUString::createFromAscii(sXML_text_style);
break;
case NUMBERFORMAT_LOGICAL:
sType = OUString::createFromAscii(sXML_boolean_style);
break;
}
if (!sType.getLength())
{
DBG_ERROR("unknown format type");
return;
}
OUString sElem = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER, sType );
OUString sAttrName, sAttrValue;
sal_Bool bUserDef = ( ( rFormat.GetType() & NUMBERFORMAT_DEFINED ) != 0 );
//! get FormatInfo from each part separately
sal_Bool bThousand = sal_False;
sal_Bool bRed = sal_False;
sal_uInt16 nPrecision = 0;
sal_uInt16 nLeading = 0;
rFormat.GetFormatSpecialInfo( bThousand, bRed, nPrecision, nLeading);
//
// common attributes for format
//
// format name (generated from key) - style namespace
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_STYLE, OUString::createFromAscii(sXML_name) );
sAttrValue = lcl_CreateStyleName( nKey, nPart, bDefPart );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_STYLE, OUString(RTL_CONSTASCII_USTRINGPARAM(sXML_family)));
sAttrValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_DATA_STYLE_NAME));
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
// language / country
LanguageType nLang = rFormat.GetLanguage();
AddLanguageAttr_Impl( nLang ); // adds to pAttrList
// title (comment)
// titles for builtin formats are not written
sAttrValue = rFormat.GetComment();
if ( sAttrValue.getLength() && bUserDef && bDefPart )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER, OUString::createFromAscii(sXML_title) );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// automatic ordering for currency and date formats
// only used for some built-in formats
BOOL bAutoOrder = ( eBuiltIn == NF_CURRENCY_1000INT || eBuiltIn == NF_CURRENCY_1000DEC2 ||
eBuiltIn == NF_CURRENCY_1000INT_RED || eBuiltIn == NF_CURRENCY_1000DEC2_RED ||
eBuiltIn == NF_CURRENCY_1000DEC2_DASHED ||
eBuiltIn == NF_DATE_SYSTEM_SHORT || eBuiltIn == NF_DATE_SYSTEM_LONG ||
eBuiltIn == NF_DATE_SYS_MMYY || eBuiltIn == NF_DATE_SYS_DDMMM ||
eBuiltIn == NF_DATE_SYS_DDMMYYYY || eBuiltIn == NF_DATE_SYS_DDMMYY ||
eBuiltIn == NF_DATE_SYS_DMMMYY || eBuiltIn == NF_DATE_SYS_DMMMYYYY ||
eBuiltIn == NF_DATE_SYS_DMMMMYYYY || eBuiltIn == NF_DATE_SYS_NNDMMMYY ||
eBuiltIn == NF_DATE_SYS_NNDMMMMYYYY || eBuiltIn == NF_DATE_SYS_NNNNDMMMMYYYY );
if ( bAutoOrder )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_automatic_order ) );
sAttrValue = OUString::createFromAscii( sXML_true );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// format source (for date and time formats)
// only used for some built-in formats
BOOL bSystemDate = ( eBuiltIn == NF_DATE_SYSTEM_SHORT ||
eBuiltIn == NF_DATE_SYSTEM_LONG ||
eBuiltIn == NF_DATETIME_SYSTEM_SHORT_HHMM );
BOOL bLongSysDate = ( eBuiltIn == NF_DATE_SYSTEM_LONG );
if ( bSystemDate )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_format_source ) );
sAttrValue = OUString::createFromAscii( sXML_language );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
// overflow for time formats as in [hh]:mm
// controlled by bThousand from number format info
// default for truncate-on-overflow is true
if ( nFmtType == NUMBERFORMAT_TIME && bThousand )
{
sAttrName = pNamespaceMap->GetQNameByKey( XML_NAMESPACE_NUMBER,
OUString::createFromAscii( sXML_truncate_on_overflow ) );
sAttrValue = OUString::createFromAscii( sXML_false );
pAttrList->AddAttribute( sAttrName, sCDATA, sAttrValue );
}
xHandler->ignorableWhitespace( sWS );
xHandler->startElement( sElem, xAttrList );
pAttrList->Clear();
//
// color (properties element)
//
const Color* pCol = rFormat.GetColor( nPart );
if (pCol)
WriteColorElement_Impl(*pCol);
//
// format elements
//
if ( eBuiltIn == NF_NUMBER_STANDARD )
{
// default number format contains just one number element
WriteNumberElement_Impl( -1, 1, OUString(), sal_False );
}
else if ( eBuiltIn == NF_BOOLEAN )
{
// boolean format contains just one boolean element
WriteBooleanElement_Impl();
}
else
{
// first loop to collect attributes
sal_Bool bDecDashes = sal_False;
sal_Bool bExpFound = sal_False;
sal_Bool bCurrFound = sal_False;
sal_Int32 nExpDigits = 0;
OUString sCurrExt;
sal_uInt16 nPos = 0;
sal_Bool bEnd = sal_False;
while (!bEnd)
{
short nElemType = rFormat.GetNumForType( nPart, nPos, sal_False );
const XubString* pElemStr = rFormat.GetNumForString( nPart, nPos, sal_False );
switch ( nElemType )
{
case 0:
bEnd = sal_True; // end of format reached
break;
case XMLNUM_SYMBOLTYPE_DIGIT:
if ( bExpFound && pElemStr )
nExpDigits += pElemStr->Len();
else if ( !bDecDashes && pElemStr && pElemStr->GetChar(0) == '-' )
bDecDashes = TRUE;
break;
case XMLNUM_SYMBOLTYPE_EXP:
bExpFound = TRUE; // following digits are exponent digits
break;
case XMLNUM_SYMBOLTYPE_CURRENCY:
bCurrFound = TRUE;
break;
case XMLNUM_SYMBOLTYPE_CURREXT:
if (pElemStr)
sCurrExt = *pElemStr;
break;
}
++nPos;
}
// second loop to write elements
sal_Bool bNumWritten = sal_False;
short nPrevType = 0;
nPos = 0;
bEnd = sal_False;
while (!bEnd)
{
short nElemType = rFormat.GetNumForType( nPart, nPos, sal_False );
const XubString* pElemStr = rFormat.GetNumForString( nPart, nPos, sal_False );
switch ( nElemType )
{
case 0:
bEnd = sal_True; // end of format reached
break;
case XMLNUM_SYMBOLTYPE_STRING:
if (pElemStr)
{
if ( ( nPrevType == NF_KEY_S || nPrevType == NF_KEY_SS ) &&
( pElemStr->EqualsAscii( "," ) || pElemStr->EqualsAscii( "." ) ) &&
nPrecision > 0 )
{
// decimal separator after seconds is implied by
// "decimal-places" attribute and must not be written
// as text element
//! difference between '.' and ',' is lost here
}
else if ( nFmtType == NUMBERFORMAT_CURRENCY && !bCurrFound )
{
// automatic currency symbol is implemented as part of
// normal text -> search for the symbol
International aIntl( nLang );
String aLanguage, aCountry, aVariant;
ConvertLanguageToIsoNames( International::GetRealLanguage( nLang ), aLanguage, aCountry );
CharClass aChrCls( ::comphelper::getProcessServiceFactory(), lang::Locale( aLanguage, aCountry, aVariant ) );
WriteTextWithCurrency_Impl( *pElemStr, aIntl, aChrCls );
}
else
WriteTextElement_Impl( *pElemStr );
}
break;
case NF_KEY_CCC:
//! must be different from short automatic format
//! but should still be empty (meaning automatic)
// pElemStr is "CCC"
if (pElemStr)
WriteCurrencyElement_Impl( *pElemStr, OUString() );
break;
case XMLNUM_SYMBOLTYPE_CURRENCY:
if (pElemStr)
WriteCurrencyElement_Impl( *pElemStr, sCurrExt );
break;
case XMLNUM_SYMBOLTYPE_DIGIT:
if (!bNumWritten) // write number part
{
switch ( nFmtType )
{
case NUMBERFORMAT_NUMBER:
case NUMBERFORMAT_CURRENCY:
case NUMBERFORMAT_PERCENT:
{
// decimals
// only some built-in formats have automatic decimals
sal_Int32 nDecimals = nPrecision; // from GetFormatSpecialInfo
if ( eBuiltIn == NF_NUMBER_STANDARD ||
eBuiltIn == NF_CURRENCY_1000DEC2 ||
eBuiltIn == NF_CURRENCY_1000DEC2_RED ||
eBuiltIn == NF_CURRENCY_1000DEC2_CCC ||
eBuiltIn == NF_CURRENCY_1000DEC2_DASHED )
nDecimals = -1;
// integer digits
// only one built-in format has automatic integer digits
sal_Int32 nInteger = nLeading;
if ( eBuiltIn == NF_NUMBER_SYSTEM )
nInteger = -1;
// string for decimal replacement
// has to be taken from nPrecision
// (positive number even for automatic decimals)
String sDashStr;
if ( bDecDashes && nPrecision > 0 )
sDashStr.Fill( nPrecision, '-' );
WriteNumberElement_Impl( nDecimals, nInteger, sDashStr, bThousand );
}
break;
case NUMBERFORMAT_SCIENTIFIC:
WriteScientificElement_Impl( nPrecision, nLeading, bThousand, nExpDigits );
break;
case NUMBERFORMAT_FRACTION:
WriteFractionElement_Impl( nLeading, bThousand, nPrecision, nPrecision );
break;
}
bNumWritten = sal_True;
}
break;
case XMLNUM_SYMBOLTYPE_DEL:
if ( pElemStr && *pElemStr == XubString('@') )
WriteTextContentElement_Impl();
break;
// date elements:
case NF_KEY_T:
case NF_KEY_TT:
{
sal_Bool bLong = ( nElemType == NF_KEY_TT );
WriteDayElement_Impl( bSystemDate ? bLongSysDate : bLong );
}
break;
case NF_KEY_TTT:
case NF_KEY_TTTT:
case NF_KEY_NN:
case NF_KEY_NNN:
case NF_KEY_NNNN:
{
sal_Bool bLong = ( nElemType == NF_KEY_NNN || nElemType == NF_KEY_NNNN ||
nElemType == NF_KEY_TTTT );
WriteDayOfWeekElement_Impl( bSystemDate ? bLongSysDate : bLong );
if ( nElemType == NF_KEY_NNNN )
{
// write additional text element for separator
International aIntl( nLang );
WriteTextElement_Impl( aIntl.GetLongDateDayOfWeekSep() );
}
}
break;
case NF_KEY_M:
case NF_KEY_MM:
case NF_KEY_MMM:
case NF_KEY_MMMM:
{
sal_Bool bLong = ( nElemType == NF_KEY_MM || nElemType == NF_KEY_MMMM );
sal_Bool bText = ( nElemType == NF_KEY_MMM || nElemType == NF_KEY_MMMM );
WriteMonthElement_Impl( ( bSystemDate ? bLongSysDate : bLong ), bText );
}
break;
case NF_KEY_JJ:
case NF_KEY_JJJJ:
{
sal_Bool bLong = ( nElemType == NF_KEY_JJJJ );
WriteYearElement_Impl( bSystemDate ? bLongSysDate : bLong );
}
break;
case NF_KEY_Q:
case NF_KEY_QQ:
{
sal_Bool bLong = ( nElemType == NF_KEY_QQ );
WriteQuarterElement_Impl( bSystemDate ? bLongSysDate : bLong );
}
break;
case NF_KEY_WW:
WriteWeekElement_Impl();
break;
// time elements (bSystemDate is not used):
case NF_KEY_H:
case NF_KEY_HH:
WriteHoursElement_Impl( nElemType == NF_KEY_HH );
break;
case NF_KEY_MI:
case NF_KEY_MMI:
WriteMinutesElement_Impl( nElemType == NF_KEY_MMI );
break;
case NF_KEY_S:
case NF_KEY_SS:
WriteSecondsElement_Impl( ( nElemType == NF_KEY_SS ), nPrecision );
break;
case NF_KEY_AMPM:
case NF_KEY_AP:
WriteAMPMElement_Impl(); // short/long?
break;
}
nPrevType = nElemType;
++nPos;
}
}
//
// mapping (conditions) must be last elements
//
SvNumberformatLimitOps eOp1, eOp2;
double fLimit1, fLimit2;
rFormat.GetConditions( eOp1, fLimit1, eOp2, fLimit2 );
if (bDefPart)
{
WriteMapElement_Impl( eOp1, fLimit1, nKey, 0 );
WriteMapElement_Impl( eOp2, fLimit2, nKey, 1 );
}
xHandler->endElement( sElem );
}
//-------------------------------------------------------------------------
//
// export one format
//
void SvXMLNumFmtExport::ExportFormat_Impl( SvNumberformat& rFormat, sal_uInt32 nKey )
{
sal_uInt16 nUsedParts = 0;
sal_uInt16 nPart;
for (nPart=0; nPart<XMLNUM_MAX_PARTS; nPart++)
if (rFormat.GetNumForType( nPart, 0, sal_False ) != 0)
nUsedParts = nPart+1;
for (nPart=0; nPart<nUsedParts; nPart++)
{
sal_Bool bDefault = ( nPart+1 == nUsedParts ); // last = default
ExportPart_Impl( rFormat, nKey, nPart, bDefault );
}
}
//-------------------------------------------------------------------------
//
// export method called by application
//
void SvXMLNumFmtExport::Export( const SvXMLNamespaceMap& rNamespaceMap, sal_Bool bIsAutoStyle )
{
if ( !pFormatter )
return; // no formatter -> no entries
pNamespaceMap = &rNamespaceMap;
SvUShorts aLanguages;
pFormatter->GetUsedLanguages( aLanguages );
sal_uInt16 nLangCount = aLanguages.Count();
for (sal_uInt16 nLangPos=0; nLangPos<nLangCount; nLangPos++)
{
LanguageType nLang = aLanguages[nLangPos];
sal_uInt32 nStandard;
SvNumberFormatTable& rTable = pFormatter->GetEntryTable(
NUMBERFORMAT_ALL, nStandard, nLang );
SvNumberformat* pFormat = rTable.First();
while (pFormat)
{
sal_uInt32 nKey = rTable.GetCurKey();
if ( (!bIsAutoStyle &&( pFormat->GetType() & NUMBERFORMAT_DEFINED )) ||
pUsedList->IsUsed( nKey ) )
{
// user-defined and used formats are exported
ExportFormat_Impl( *pFormat, nKey );
// if it is a user-defined Format it will be added else nothing will hapen
pUsedList->SetUsed(nKey);
}
pFormat = rTable.Next();
}
}
pUsedList->Export();
pNamespaceMap = NULL;
}
OUString SvXMLNumFmtExport::GetStyleName( sal_uInt32 nKey )
{
DBG_ASSERT(pUsedList->IsUsed(nKey) || pUsedList->IsWasUsed(nKey), "There is no written Data-Style");
return lcl_CreateStyleName( nKey, 0, sal_True );
}
void SvXMLNumFmtExport::SetUsed( sal_uInt32 nKey )
{
pUsedList->SetUsed( nKey );
}
|