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
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* 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.
*
************************************************************************/
/** @#file
*
* export of all variable related text fields (and database display field)
*/
#include "txtvfldi.hxx"
#include <xmloff/xmltoken.hxx>
#include <xmloff/txtimp.hxx>
#include <xmloff/xmlnumi.hxx>
#include "xmloff/xmlnmspe.hxx"
#include <xmloff/nmspmap.hxx>
#include "xmloff/i18nmap.hxx"
#include <xmloff/xmlimp.hxx>
#include <xmloff/xmluconv.hxx>
#include <xmloff/xmlement.hxx>
#include <com/sun/star/text/SetVariableType.hpp>
#include <com/sun/star/text/XTextField.hpp>
#include <com/sun/star/text/XDependentTextField.hpp>
#include <com/sun/star/text/XTextFieldsSupplier.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/xml/sax/XAttributeList.hpp>
#include <sax/tools/converter.hxx>
#include <rtl/ustring.hxx>
#include <tools/debug.hxx>
// service names
static const sal_Char sAPI_textfield_prefix[] = "com.sun.star.text.TextField.";
static const sal_Char sAPI_fieldmaster_prefix[] = "com.sun.star.text.FieldMaster.";
static const sal_Char sAPI_input[] = "Input";
static const sal_Char sAPI_input_user[] = "InputUser";
static const sal_Char sAPI_get_expression[] = "GetExpression";
static const sal_Char sAPI_set_expression[] = "SetExpression";
static const sal_Char sAPI_user[] = "User";
static const sal_Char sAPI_table_formula[] = "TableFormula";
static const sal_Char sAPI_database[] = "com.sun.star.text.TextField.Database";
static const sal_Char sAPI_fieldmaster_database[] = "com.sun.star.text.FieldMaster.Database";
// property names
static const sal_Char sAPI_hint[] = "Hint";
static const sal_Char sAPI_help[] = "Help";
static const sal_Char sAPI_tooltip[] = "Tooltip";
static const sal_Char sAPI_content[] = "Content";
static const sal_Char sAPI_sub_type[] = "SubType";
static const sal_Char sAPI_is_expression[] = "IsExpression";
static const sal_Char sAPI_is_input[] = "Input";
static const sal_Char sAPI_is_show_formula[] = "IsShowFormula";
static const sal_Char sAPI_numbering_type[] = "NumberingType";
static const sal_Char sAPI_number_format[] = "NumberFormat";
static const sal_Char sAPI_name[] = "Name";
static const sal_Char sAPI_numbering_separator[] = "NumberingSeparator";
static const sal_Char sAPI_chapter_numbering_level[]= "ChapterNumberingLevel";
static const sal_Char sAPI_value[] = "Value";
static const sal_Char sAPI_is_visible[] = "IsVisible";
static const sal_Char sAPI_variable_subtype[] = "VariableSubtype";
static const sal_Char sAPI_data_column_name[] = "DataColumnName";
static const sal_Char sAPI_is_data_base_format[] = "DataBaseFormat";
static const sal_Char sAPI_current_presentation[] = "CurrentPresentation";
static const sal_Char sAPI_sequence_value[] = "SequenceValue";
static const sal_Char sAPI_is_fixed_language[] = "IsFixedLanguage";
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::style;
using namespace ::xmloff::token;
//
// XMLVarFieldImportContext: superclass for all variable related fields
//
TYPEINIT1( XMLVarFieldImportContext, XMLTextFieldImportContext );
XMLVarFieldImportContext::XMLVarFieldImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp,
const sal_Char* pServiceName, sal_uInt16 nPrfx,
const OUString& rLocalName,
sal_Bool bName, sal_Bool bFormula, sal_Bool bFormulaDefault,
sal_Bool bDescription, sal_Bool bHelp, sal_Bool bHint, sal_Bool bVisible,
sal_Bool bIsDisplayFormula,
sal_Bool bType, sal_Bool bStyle, sal_Bool bValue,
sal_Bool bPresentation) :
XMLTextFieldImportContext(rImport, rHlp, pServiceName, nPrfx, rLocalName),
sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)),
sPropertyHint(RTL_CONSTASCII_USTRINGPARAM(sAPI_hint)),
sPropertyHelp(RTL_CONSTASCII_USTRINGPARAM(sAPI_help)),
sPropertyTooltip(RTL_CONSTASCII_USTRINGPARAM(sAPI_tooltip)),
sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible)),
sPropertyIsDisplayFormula(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_show_formula)),
sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)),
aValueHelper(rImport, rHlp, bType, bStyle, bValue, sal_False),
bDisplayFormula(sal_False),
bDisplayNone(sal_False),
bNameOK(sal_False),
bFormulaOK(sal_False),
bDescriptionOK(sal_False),
bHelpOK(sal_False),
bHintOK(sal_False),
bDisplayOK(sal_False),
bSetName(bName),
bSetFormula(bFormula),
bSetFormulaDefault(bFormulaDefault),
bSetDescription(bDescription),
bSetHelp(bHelp),
bSetHint(bHint),
bSetVisible(bVisible),
bSetDisplayFormula(bIsDisplayFormula),
bSetPresentation(bPresentation)
{
}
void XMLVarFieldImportContext::ProcessAttribute(
sal_uInt16 nAttrToken,
const OUString& sAttrValue )
{
switch (nAttrToken)
{
case XML_TOK_TEXTFIELD_NAME:
sName = sAttrValue;
bNameOK = sal_True;
bValid = sal_True; // we assume: field with name is valid!
break;
case XML_TOK_TEXTFIELD_DESCRIPTION:
sDescription = sAttrValue;
bDescriptionOK = sal_True;
break;
case XML_TOK_TEXTFIELD_HELP:
sHelp = sAttrValue;
bHelpOK = true;
break;
case XML_TOK_TEXTFIELD_HINT:
sHint = sAttrValue;
bHintOK = true;
break;
case XML_TOK_TEXTFIELD_FORMULA:
{
OUString sTmp;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
_GetKeyByAttrName( sAttrValue, &sTmp, sal_False );
if( XML_NAMESPACE_OOOW == nPrefix )
{
sFormula = sTmp;
bFormulaOK = sal_True;
}
else
sFormula = sAttrValue;
}
break;
case XML_TOK_TEXTFIELD_DISPLAY:
if (IsXMLToken(sAttrValue, XML_FORMULA))
{
bDisplayFormula = sal_True;
bDisplayNone = sal_False;
bDisplayOK = sal_True;
}
else if (IsXMLToken(sAttrValue, XML_VALUE))
{
bDisplayFormula = sal_False;
bDisplayNone = sal_False;
bDisplayOK = sal_True;
}
else if (IsXMLToken(sAttrValue, XML_NONE))
{
bDisplayFormula = sal_False;
bDisplayNone = sal_True;
bDisplayOK = sal_True;
} // else: no change
DBG_ASSERT(!(bDisplayFormula && bDisplayNone),
"illegal display values");
break;
default:
// delegate all others to value helper
aValueHelper.ProcessAttribute(nAttrToken, sAttrValue);
break;
}
}
void XMLVarFieldImportContext::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
// bSetName: not implemented
if (bSetFormula)
{
if (!bFormulaOK && bSetFormulaDefault)
{
sFormula = GetContent();
bFormulaOK = sal_True;
}
if (bFormulaOK)
{
Any aAny;
aAny <<= sFormula;
xPropertySet->setPropertyValue(sPropertyContent, aAny);
}
}
if (bSetDescription && bDescriptionOK)
{
Any aAny;
aAny <<= sDescription;
xPropertySet->setPropertyValue(sPropertyHint, aAny);
}
if (bSetHelp && bHelpOK)
{
Any aAny;
aAny <<= sHelp;
xPropertySet->setPropertyValue(sPropertyHelp, aAny);
}
if (bSetHint && bHintOK)
{
Any aAny;
aAny <<= sHint;
xPropertySet->setPropertyValue(sPropertyTooltip, aAny);
}
if (bSetVisible && bDisplayOK)
{
Any aAny;
sal_Bool bTmp = ! (bDisplayNone && bDisplayOK);
aAny.setValue( &bTmp, ::getBooleanCppuType());
xPropertySet->setPropertyValue(sPropertyIsVisible, aAny);
}
// workaround for #no-bug#: display formula by default
if (xPropertySet->getPropertySetInfo()->
hasPropertyByName(sPropertyIsDisplayFormula) &&
!bSetDisplayFormula)
{
bDisplayFormula = sal_False;
bSetDisplayFormula = sal_True;
}
if (bSetDisplayFormula)
{
Any aAny;
sal_Bool bTmp = bDisplayFormula && bDisplayOK;
aAny.setValue( &bTmp, ::getBooleanCppuType());
xPropertySet->setPropertyValue(sPropertyIsDisplayFormula, aAny);
}
// delegate to value helper
aValueHelper.SetDefault(GetContent());
aValueHelper.PrepareField(xPropertySet);
// finally, set the curren presentation
if (bSetPresentation)
{
Any aAny;
aAny <<= GetContent();
xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
}
}
//
// variable set fields
//
TYPEINIT1( XMLSetVarFieldImportContext, XMLVarFieldImportContext );
XMLSetVarFieldImportContext::XMLSetVarFieldImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp,
const sal_Char* pServiceName, sal_uInt16 nPrfx,
const OUString& rLocalName, VarType eVarType,
sal_Bool bName, sal_Bool bFormula, sal_Bool bFormulaDefault,
sal_Bool bDescription, sal_Bool bHelp, sal_Bool bHint, sal_Bool bVisible, sal_Bool bIsDisplayFormula,
sal_Bool bType, sal_Bool bStyle, sal_Bool bValue, sal_Bool bPresentation) :
XMLVarFieldImportContext(rImport, rHlp, pServiceName,
nPrfx, rLocalName,
bName, bFormula, bFormulaDefault,
bDescription, bHelp, bHint, bVisible, bIsDisplayFormula,
bType, bStyle, bValue, bPresentation),
eFieldType(eVarType)
{
}
void XMLSetVarFieldImportContext::EndElement()
{
// should we call PrepareField on the field, or rather on it's master?
// currently: call on field (just like superclass)
// possible alternatives: call on master
// call field or master depending on variable
// PrepareMaster() in addition to PrepareField()
DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
if (bValid)
{
DBG_ASSERT(!GetName().isEmpty(), "variable name needed!");
// find field master
Reference<XPropertySet> xMaster;
if (FindFieldMaster(xMaster))
{
// create field/Service
Reference<XPropertySet> xPropSet;
if (CreateField(xPropSet, OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_textfield_prefix)) + GetServiceName()))
{
Reference<XDependentTextField> xDepTextField(xPropSet, UNO_QUERY);
if (xDepTextField.is())
{
// attach field to field master
xDepTextField->attachTextFieldMaster(xMaster);
// attach field to document
Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
if (xTextContent.is())
{
try {
// insert, set field properties and exit!
GetImportHelper().InsertTextContent(xTextContent);
PrepareField(xPropSet);
} catch (lang::IllegalArgumentException & /*e*/)
{
// ignore e: #i54023#
};
return;
}
}
}
}
}
// above: exit on success; so for all error cases we end up here!
// write element content
GetImportHelper().InsertString(GetContent());
}
sal_Bool XMLSetVarFieldImportContext::FindFieldMaster(
Reference<XPropertySet> & xMaster)
{
// currently: delegate to XMLVariableDeclImportContext;
// shoud eventually go here
return XMLVariableDeclImportContext::FindFieldMaster(xMaster,
GetImport(),
GetImportHelper(),
GetName(),
eFieldType);
}
//
// sequence field
//
TYPEINIT1( XMLSequenceFieldImportContext, XMLSetVarFieldImportContext );
XMLSequenceFieldImportContext::XMLSequenceFieldImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp,
sal_uInt16 nPrfx, const OUString& rLocalName) :
XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression,
nPrfx, rLocalName, VarTypeSequence,
// name, formula
sal_True, sal_True, sal_True,
sal_False, sal_False, sal_False, sal_False,
sal_False,
sal_False, sal_False, sal_False, sal_True),
sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)),
sPropertySequenceValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_sequence_value)),
sNumFormat(OUString::valueOf(sal_Unicode('1'))),
sNumFormatSync(GetXMLToken(XML_FALSE)),
bRefNameOK(sal_False)
{
}
void XMLSequenceFieldImportContext::ProcessAttribute(
sal_uInt16 nAttrToken, const OUString& sAttrValue )
{
switch (nAttrToken)
{
case XML_TOK_TEXTFIELD_NUM_FORMAT:
sNumFormat = sAttrValue;
break;
case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
sNumFormatSync = sAttrValue;
break;
case XML_TOK_TEXTFIELD_REF_NAME:
sRefName = sAttrValue;
bRefNameOK = sal_True;
break;
default:
// delegate to super class (name, formula)
XMLSetVarFieldImportContext::ProcessAttribute(nAttrToken,
sAttrValue);
break;
} // switch
}
void XMLSequenceFieldImportContext::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
// delegate to super class (formula)
XMLSetVarFieldImportContext::PrepareField(xPropertySet);
// set format
sal_Int16 nNumType = NumberingType::ARABIC;
GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, sNumFormat, sNumFormatSync );
Any aAny;
aAny <<= nNumType;
xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
// handle reference name
if (bRefNameOK)
{
aAny = xPropertySet->getPropertyValue(sPropertySequenceValue);
sal_Int16 nValue = 0;
aAny >>= nValue;
GetImportHelper().InsertSequenceID(sRefName, GetName(), nValue);
}
}
//
// variable set field
//
TYPEINIT1( XMLVariableSetFieldImportContext, XMLSetVarFieldImportContext );
XMLVariableSetFieldImportContext::XMLVariableSetFieldImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp,
sal_uInt16 nPrfx, const OUString& rLocalName) :
XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression,
nPrfx, rLocalName, VarTypeSimple,
// name, formula, value&type, style,
// display none
sal_True, sal_True, sal_True,
sal_False, sal_False, sal_False,
sal_True, sal_False,
sal_True, sal_True, sal_True,
sal_True),
sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
{
}
void XMLVariableSetFieldImportContext::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
// set type
Any aAny;
aAny <<= (IsStringValue()? SetVariableType::STRING : SetVariableType::VAR);
xPropertySet->setPropertyValue(sPropertySubType, aAny);
// the remainder is handled by super class
XMLSetVarFieldImportContext::PrepareField(xPropertySet);
}
//
// variable input field
//
TYPEINIT1( XMLVariableInputFieldImportContext, XMLSetVarFieldImportContext );
XMLVariableInputFieldImportContext::XMLVariableInputFieldImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
const OUString& rLocalName) :
XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression,
nPrfx, rLocalName, VarTypeSimple,
// name, description, display none/formula,
// value&type, style, formula
sal_True, sal_True, sal_True,
sal_True, sal_True, sal_True,
sal_True, sal_False,
sal_True, sal_True, sal_True,
sal_True),
sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)),
sPropertyIsInput(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_input))
{
}
void XMLVariableInputFieldImportContext::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
// set type (input field)
Any aAny;
sal_Bool bTrue = sal_True;
aAny.setValue( &bTrue, ::getBooleanCppuType() );
xPropertySet->setPropertyValue(sPropertyIsInput, aAny);
// set type
aAny <<= (IsStringValue()? SetVariableType::STRING : SetVariableType::VAR);
xPropertySet->setPropertyValue(sPropertySubType, aAny);
// the remainder is handled by super class
XMLSetVarFieldImportContext::PrepareField(xPropertySet);
}
//
// user field
//
TYPEINIT1( XMLUserFieldImportContext, XMLSetVarFieldImportContext );
XMLUserFieldImportContext::XMLUserFieldImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp,
sal_uInt16 nPrfx, const OUString& rLocalName) :
XMLSetVarFieldImportContext(rImport, rHlp, sAPI_user, nPrfx,
rLocalName, VarTypeUserField,
// name, display none/formula, style
sal_True, sal_False, sal_False,
sal_False, sal_False, sal_False, sal_True,
sal_True,
sal_False, sal_True, sal_False,
sal_False)
{
}
//
// user input field
//
TYPEINIT1( XMLUserFieldInputImportContext, XMLVarFieldImportContext );
// bug: doesn't work (SO API lacking)
XMLUserFieldInputImportContext::XMLUserFieldInputImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
const OUString& rLocalName) :
XMLVarFieldImportContext(rImport, rHlp, sAPI_input_user,
nPrfx, rLocalName,
// name, description, style
sal_True, sal_False, sal_False,
sal_True, sal_False, sal_False,
sal_False, sal_False,
sal_False /*???*/, sal_True, sal_False,
sal_False)
{
}
void XMLUserFieldInputImportContext::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
Any aAny;
aAny <<= GetName();
xPropertySet->setPropertyValue(sPropertyContent, aAny);
// delegate to super class
XMLVarFieldImportContext::PrepareField(xPropertySet);
}
//
// variable get field
//
TYPEINIT1( XMLVariableGetFieldImportContext, XMLVarFieldImportContext );
XMLVariableGetFieldImportContext::XMLVariableGetFieldImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp,
sal_uInt16 nPrfx, const OUString& rLocalName) :
XMLVarFieldImportContext(rImport, rHlp, sAPI_get_expression,
nPrfx, rLocalName,
// name, style, display formula
sal_True, sal_False, sal_False,
sal_False, sal_False, sal_False,
sal_False, sal_True,
sal_True, sal_True, sal_False,
sal_True),
sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
{
}
void XMLVariableGetFieldImportContext::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
// set name
Any aAny;
aAny <<= GetName();
xPropertySet->setPropertyValue(sPropertyContent, aAny);
// the remainder is handled by super class
XMLVarFieldImportContext::PrepareField(xPropertySet);
}
//
// expression field
//
TYPEINIT1( XMLExpressionFieldImportContext, XMLVarFieldImportContext );
XMLExpressionFieldImportContext::XMLExpressionFieldImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp,
sal_uInt16 nPrfx, const OUString& rLocalName) :
XMLVarFieldImportContext(rImport, rHlp, sAPI_get_expression,
nPrfx, rLocalName,
// formula, type, style, display formula
sal_False, sal_True, sal_True,
sal_False, sal_False, sal_False,
sal_False, sal_True,
sal_True, sal_True, sal_False,
sal_True),
sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
{
bValid = sal_True; // always valid
}
void XMLExpressionFieldImportContext::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
sal_Int16 nSubType = SetVariableType::FORMULA;
Any aAny;
aAny <<= nSubType;
xPropertySet->setPropertyValue(sPropertySubType, aAny);
// delegate to super class
XMLVarFieldImportContext::PrepareField(xPropertySet);
}
//
// text input field
//
TYPEINIT1( XMLTextInputFieldImportContext, XMLVarFieldImportContext );
XMLTextInputFieldImportContext::XMLTextInputFieldImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp,
sal_uInt16 nPrfx, const OUString& sLocalName) :
XMLVarFieldImportContext(rImport, rHlp, sAPI_input,
nPrfx, sLocalName,
// description
sal_False, sal_False, sal_False,
sal_True, sal_True, sal_True,
sal_False, sal_False,
sal_False, sal_False, sal_False,
sal_False),
sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content))
{
bValid = sal_True; // always valid
}
void XMLTextInputFieldImportContext::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
XMLVarFieldImportContext::PrepareField(xPropertySet);
Any aAny;
aAny <<= GetContent();
xPropertySet->setPropertyValue(sPropertyContent, aAny);
}
//
// table formula field
//
TYPEINIT1( XMLTableFormulaImportContext, XMLTextFieldImportContext );
XMLTableFormulaImportContext::XMLTableFormulaImportContext(
SvXMLImport& rImport,
XMLTextImportHelper& rHlp,
sal_uInt16 nPrfx,
const OUString& rLocalName) :
XMLTextFieldImportContext(rImport, rHlp, sAPI_table_formula,
nPrfx, rLocalName),
sPropertyIsShowFormula(RTL_CONSTASCII_USTRINGPARAM("IsShowFormula")),
sPropertyCurrentPresentation(
RTL_CONSTASCII_USTRINGPARAM("CurrentPresentation")),
aValueHelper(rImport, rHlp, sal_False, sal_True, sal_False, sal_True),
sFormula(),
bIsShowFormula(sal_False)
{
}
XMLTableFormulaImportContext::~XMLTableFormulaImportContext()
{
}
void XMLTableFormulaImportContext::ProcessAttribute(
sal_uInt16 nAttrToken,
const OUString& sAttrValue )
{
switch (nAttrToken)
{
case XML_TOK_TEXTFIELD_FORMULA:
aValueHelper.ProcessAttribute( nAttrToken, sAttrValue );
bValid = sal_True; // we need a formula!
break;
case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
aValueHelper.ProcessAttribute( nAttrToken, sAttrValue );
break;
case XML_TOK_TEXTFIELD_DISPLAY:
if ( sAttrValue.equalsAsciiL(
RTL_CONSTASCII_STRINGPARAM("formula")) )
bIsShowFormula = sal_True;
break;
default:
// unknown attribute -> ignore
break;
}
}
void XMLTableFormulaImportContext::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
// set format and formula
aValueHelper.PrepareField( xPropertySet );
Any aAny;
// set 'show formula' and presentation
aAny.setValue( &bIsShowFormula, ::getBooleanCppuType() );
xPropertySet->setPropertyValue( sPropertyIsShowFormula, aAny );
aAny <<= GetContent();
xPropertySet->setPropertyValue( sPropertyCurrentPresentation, aAny );
}
//
// variable declarations
//
// Should be adapted to XMLVarField-/XMLSetVarFieldImportContext scheme!
//
//
// declaration containter import (<variable/user-field/sequence-decls>)
//
TYPEINIT1( XMLVariableDeclsImportContext, SvXMLImportContext );
XMLVariableDeclsImportContext::XMLVariableDeclsImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
const OUString& rLocalName, enum VarType eVarType) :
SvXMLImportContext(rImport, nPrfx, rLocalName),
eVarDeclsContextType(eVarType),
rImportHelper(rHlp)
{
}
SvXMLImportContext* XMLVariableDeclsImportContext::CreateChildContext(
sal_uInt16 nPrefix, const OUString& rLocalName,
const Reference<xml::sax::XAttributeList> & xAttrList )
{
enum XMLTokenEnum eElementName;
SvXMLImportContext* pImportContext = NULL;
if( XML_NAMESPACE_TEXT == nPrefix )
{
switch (eVarDeclsContextType)
{
case VarTypeSequence:
eElementName = XML_SEQUENCE_DECL;
break;
case VarTypeSimple:
eElementName = XML_VARIABLE_DECL;
break;
case VarTypeUserField:
eElementName = XML_USER_FIELD_DECL;
break;
default:
OSL_FAIL("unknown field type!");
eElementName = XML_SEQUENCE_DECL;
break;
}
if( IsXMLToken( rLocalName, eElementName ) )
{
pImportContext = new XMLVariableDeclImportContext(
GetImport(), rImportHelper, nPrefix, rLocalName, xAttrList,
eVarDeclsContextType);
}
}
// if no context was created, use default context
if (NULL == pImportContext) {
pImportContext = SvXMLImportContext::CreateChildContext(nPrefix,
rLocalName,
xAttrList);
}
return pImportContext;
}
//
// declaration import (<variable/user-field/sequence-decl> elements)
//
TYPEINIT1( XMLVariableDeclImportContext, SvXMLImportContext );
XMLVariableDeclImportContext::XMLVariableDeclImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp,
sal_uInt16 nPrfx, const OUString& rLocalName,
const Reference<xml::sax::XAttributeList> & xAttrList,
enum VarType eVarType) :
SvXMLImportContext(rImport, nPrfx, rLocalName),
// bug?? which properties for userfield/userfieldmaster
sPropertyName(RTL_CONSTASCII_USTRINGPARAM(sAPI_name)),
sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)),
sPropertyNumberingLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_chapter_numbering_level)),
sPropertyNumberingSeparator(RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_separator)),
sPropertyIsExpression(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_expression)),
aValueHelper(rImport, rHlp, sal_True, sal_False, sal_True, sal_False),
nNumLevel(-1), cSeparationChar('.')
{
if ( (XML_NAMESPACE_TEXT == nPrfx) &&
( ( IsXMLToken( rLocalName, XML_SEQUENCE_DECL )) ||
( IsXMLToken( rLocalName, XML_VARIABLE_DECL)) ||
( IsXMLToken( rLocalName, XML_USER_FIELD_DECL)) )) {
// TODO: check validity (need name!)
// parse attributes
sal_Int16 nLength = xAttrList->getLength();
for(sal_Int16 i=0; i<nLength; i++) {
OUString sLocalName;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
sal_uInt16 nToken = rHlp.
GetTextFieldAttrTokenMap().Get(nPrefix, sLocalName);
switch (nToken)
{
case XML_TOK_TEXTFIELD_NAME:
sName = xAttrList->getValueByIndex(i);
break;
case XML_TOK_TEXTFIELD_NUMBERING_LEVEL:
{
sal_Int32 nLevel;
bool const bRet = ::sax::Converter::convertNumber(
nLevel, xAttrList->getValueByIndex(i), 0,
GetImport().GetTextImport()->GetChapterNumbering()->
getCount());
if (bRet)
{
nNumLevel = static_cast< sal_Int8 >( nLevel-1 ); // API numbers -1..9
}
break;
}
case XML_TOK_TEXTFIELD_NUMBERING_SEPARATOR:
cSeparationChar =
(sal_Char)xAttrList->getValueByIndex(i).toChar();
break;
default:
// delegate to value helper
aValueHelper.ProcessAttribute(nToken,
xAttrList->getValueByIndex(i));
break;
}
}
Reference<XPropertySet> xFieldMaster;
if (FindFieldMaster(xFieldMaster, GetImport(), rHlp,
sName, eVarType))
{
// now we have a field master: process attributes!
Any aAny;
switch (eVarType)
{
case VarTypeSequence:
aAny <<= nNumLevel;
xFieldMaster->setPropertyValue(sPropertyNumberingLevel, aAny);
if (nNumLevel >= 0)
{
OUString sStr(&cSeparationChar, 1);
aAny <<= sStr;
xFieldMaster->setPropertyValue(
sPropertyNumberingSeparator, aAny);
}
break;
case VarTypeSimple:
{
// set string or non-string SubType (#93192#)
// The SubType was already set in the FindFieldMaster
// method, but it needs to be adjusted if it's a string.
aAny <<= aValueHelper.IsStringValue()
? SetVariableType::STRING : SetVariableType::VAR;
xFieldMaster->setPropertyValue(sPropertySubType, aAny);
}
break;
case VarTypeUserField:
{
sal_Bool bTmp = !aValueHelper.IsStringValue();
aAny.setValue(&bTmp, ::getBooleanCppuType());
xFieldMaster->setPropertyValue(sPropertyIsExpression, aAny);
aValueHelper.PrepareField(xFieldMaster);
break;
}
default:
OSL_FAIL("unkown varfield type");
} // switch
} // else: no field master found/constructed
} // else: no sequence-decl
}
sal_Bool XMLVariableDeclImportContext::FindFieldMaster(
Reference<XPropertySet> & xMaster, SvXMLImport& rImport,
XMLTextImportHelper& rImportHelper,
const OUString& sVarName, enum VarType eVarType)
{
static sal_Int32 nCollisionCount = 0;
// rename field
// currently: no family in use! Use 0.
OUString sName = rImportHelper.GetRenameMap().Get(
sal::static_int_cast< sal_uInt16 >(eVarType), sVarName);
// get text fields supplier and field masters
Reference<XTextFieldsSupplier> xTextFieldsSupp(rImport.GetModel(),
UNO_QUERY);
Reference<container::XNameAccess> xFieldMasterNameAccess(
xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY);
OUStringBuffer sBuffer;
sBuffer.appendAscii(sAPI_fieldmaster_prefix);
sBuffer.appendAscii(sAPI_set_expression);
sBuffer.appendAscii(".");
sBuffer.append(sName);
OUString sVarServiceName = sBuffer.makeStringAndClear();
sBuffer.appendAscii(sAPI_fieldmaster_prefix);
sBuffer.appendAscii(sAPI_user);
sBuffer.appendAscii(".");
sBuffer.append(sName);
OUString sUserServiceName = sBuffer.makeStringAndClear();
if (xFieldMasterNameAccess->hasByName(sVarServiceName)) {
// variable field master already in document
Any aAny = xFieldMasterNameAccess->getByName(sVarServiceName);
aAny >>= xMaster;
aAny = xMaster->getPropertyValue(
// sPropertySubType
OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
);
sal_Int16 nType = 0;
aAny >>= nType;
enum VarType eFMVarType =
(SetVariableType::SEQUENCE == nType) ?
VarTypeSequence : VarTypeSimple;
if (eFMVarType != eVarType)
{
OUString sNew;
// FIXME! cant find if name is taken already!!!!
nCollisionCount++;
OUStringBuffer aBuf;
aBuf.append(sName);
aBuf.appendAscii("_renamed_");
aBuf.append(nCollisionCount);
sNew = aBuf.makeStringAndClear();
rImportHelper.GetRenameMap().Add(
sal::static_int_cast< sal_uInt16 >(eVarType), sName, sNew);
// call FindFieldMaster recursively to create new master
return FindFieldMaster(xMaster, rImport, rImportHelper,
sNew, eVarType);
}
} else if (xFieldMasterNameAccess->hasByName(sUserServiceName)) {
// user field: get field master
Any aAny = xFieldMasterNameAccess->getByName(sUserServiceName);
aAny >>= xMaster;
if (VarTypeUserField != eVarType) {
// find new name that is not taken
OUString sNew;
// FIXME! cant find if name is taken already!!!!
nCollisionCount++;
OUStringBuffer aBuf;
aBuf.append(sName);
aBuf.appendAscii("_renamed_");
aBuf.append(nCollisionCount);
sNew = aBuf.makeStringAndClear();
rImportHelper.GetRenameMap().Add(
sal::static_int_cast< sal_uInt16 >(eVarType), sName, sNew);
// call FindFieldMaster recursively to create new master
return FindFieldMaster(xMaster, rImport, rImportHelper,
sNew, eVarType);
}
} else {
// field name not used: create field master
// import -> model is MultiServiceFactory -> createInstance
Reference<lang::XMultiServiceFactory>
xFactory(rImport.GetModel(),UNO_QUERY);
if( xFactory.is() ) {
OUStringBuffer sService;
sService.appendAscii(sAPI_fieldmaster_prefix);
sService.appendAscii((eVarType==VarTypeUserField) ?
sAPI_user : sAPI_set_expression);
Reference<XInterface> xIfc =
xFactory->createInstance( sService.makeStringAndClear() );
if (xIfc.is()) {
Reference<XPropertySet> xTmp( xIfc, UNO_QUERY );
xMaster = xTmp;
// set name
Any aAny;
aAny <<= sName;
xMaster->setPropertyValue(
// sPropertyName
OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_name))
, aAny);
if (eVarType != VarTypeUserField) {
// set subtype for setexp field
aAny <<= ((eVarType == VarTypeSimple) ?
SetVariableType::VAR :
SetVariableType::SEQUENCE);
xMaster->setPropertyValue(
// sPropertySubType
OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
, aAny);
} // else : user field: no subtype
} else {
return sal_False;
}
} else {
return sal_False;
}
}
DBG_ASSERT(xMaster.is(), "no field master found!?!");
return sal_True;
}
//
// Database Display field import
//
TYPEINIT1( XMLDatabaseDisplayImportContext, XMLDatabaseFieldImportContext );
XMLDatabaseDisplayImportContext::XMLDatabaseDisplayImportContext(
SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
const OUString& rLocalName) :
XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database,
nPrfx, rLocalName, false),
sPropertyColumnName(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_column_name)),
sPropertyDatabaseFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_data_base_format)),
sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)),
sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible)),
aValueHelper(rImport, rHlp, sal_False, sal_True, sal_False, sal_False),
bColumnOK(sal_False),
bDisplay( sal_True ),
bDisplayOK( sal_False )
{
}
void XMLDatabaseDisplayImportContext::ProcessAttribute(
sal_uInt16 nAttrToken, const OUString& sAttrValue )
{
switch (nAttrToken)
{
case XML_TOK_TEXTFIELD_COLUMN_NAME:
sColumnName = sAttrValue;
bColumnOK = sal_True;
break;
case XML_TOK_TEXTFIELD_DISPLAY:
{
sal_Bool bNone = IsXMLToken( sAttrValue, XML_NONE );
sal_Bool bValue = IsXMLToken( sAttrValue, XML_VALUE );
bDisplay = bValue;
bDisplayOK = bNone || bValue;
}
break;
case XML_TOK_TEXTFIELD_DATABASE_NAME:
case XML_TOK_TEXTFIELD_TABLE_NAME:
case XML_TOK_TEXTFIELD_TABLE_TYPE:
// handled by super class
XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
sAttrValue);
break;
default:
// remainder handled by value helper
aValueHelper.ProcessAttribute(nAttrToken, sAttrValue);
break;
}
bValid = bTableOK && bDatabaseOK && bColumnOK;
}
void XMLDatabaseDisplayImportContext::EndElement()
{
// we have an EndElement of our own, because database fields need
// to be attached to a field master before they can be inserted into
// the document. Database stuff (database, table, column) all goes
// to the field master, value & style go to the field.
if (bValid)
{
// so here goes: we start with the master
Reference<XPropertySet> xMaster;
// create and prepare field master first
if (CreateField(xMaster,
OUString(RTL_CONSTASCII_USTRINGPARAM(
sAPI_fieldmaster_database))))
{
Any aAny;
aAny <<= sColumnName;
xMaster->setPropertyValue(sPropertyColumnName, aAny);
// fieldmaster takes database, table and column name
XMLDatabaseFieldImportContext::PrepareField(xMaster);
// create field
Reference<XPropertySet> xField;
if (CreateField(xField,
OUString(RTL_CONSTASCII_USTRINGPARAM(
sAPI_database))))
{
// attach field master
Reference<XDependentTextField> xDepField(xField, UNO_QUERY);
if (xDepField.is())
{
// attach field to field master
xDepField->attachTextFieldMaster(xMaster);
// attach field to document
Reference<XTextContent> xTextContent(xField, UNO_QUERY);
if (xTextContent.is())
{
// insert, set field properties and exit!
GetImportHelper().InsertTextContent(xTextContent);
// prepare field: format from database?
sal_Bool bTmp = !aValueHelper.IsFormatOK();
aAny.setValue( &bTmp, ::getBooleanCppuType() );
xField->setPropertyValue(sPropertyDatabaseFormat,aAny);
// value, value-type and format done by value helper
aValueHelper.PrepareField(xField);
// visibility
if( bDisplayOK )
{
aAny.setValue( &bDisplay, ::getBooleanCppuType() );
xField->setPropertyValue(sPropertyIsVisible, aAny);
}
// set presentation
aAny <<= GetContent();
xField->setPropertyValue(sPropertyCurrentPresentation,
aAny);
// success!
return;
}
}
}
}
}
// above: exit on success; so for all error cases we end up here!
// write element content
GetImportHelper().InsertString(GetContent());
}
//
// value import helper
//
enum ValueType
{
XML_VALUE_TYPE_STRING,
XML_VALUE_TYPE_FLOAT,
XML_VALUE_TYPE_CURRENCY,
XML_VALUE_TYPE_PERCENTAGE,
XML_VALUE_TYPE_DATE,
XML_VALUE_TYPE_TIME,
XML_VALUE_TYPE_BOOLEAN
};
static SvXMLEnumMapEntry const aValueTypeMap[] =
{
{ XML_FLOAT, XML_VALUE_TYPE_FLOAT },
{ XML_CURRENCY, XML_VALUE_TYPE_CURRENCY },
{ XML_PERCENTAGE, XML_VALUE_TYPE_PERCENTAGE },
{ XML_DATE, XML_VALUE_TYPE_DATE },
{ XML_TIME, XML_VALUE_TYPE_TIME },
{ XML_BOOLEAN, XML_VALUE_TYPE_BOOLEAN },
{ XML_STRING, XML_VALUE_TYPE_STRING },
{ XML_TOKEN_INVALID, 0 }
};
XMLValueImportHelper::XMLValueImportHelper(
SvXMLImport& rImprt,
XMLTextImportHelper& rHlp,
sal_Bool bType, sal_Bool bStyle, sal_Bool bValue, sal_Bool bFormula) :
sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)),
sPropertyValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_value)),
sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)),
sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language)),
rImport(rImprt),
rHelper(rHlp),
fValue(0.0),
nFormatKey(0),
bIsDefaultLanguage(sal_True),
bStringType(sal_False),
bFormatOK(sal_False),
bTypeOK(sal_False),
bStringValueOK(sal_False),
bFloatValueOK(sal_False),
bFormulaOK(sal_False),
bSetType(bType),
bSetValue(bValue),
bSetStyle(bStyle),
bSetFormula(bFormula),
bStringDefault(sal_True),
bFormulaDefault(sal_True)
{
}
XMLValueImportHelper::~XMLValueImportHelper()
{
}
void XMLValueImportHelper::ProcessAttribute(
sal_uInt16 nAttrToken, const OUString& sAttrValue )
{
switch (nAttrToken)
{
case XML_TOK_TEXTFIELD_VALUE_TYPE:
{
// convert enum
sal_uInt16 nTmp = 0;
sal_Bool bRet = SvXMLUnitConverter::convertEnum(
nTmp, sAttrValue, aValueTypeMap);
if (bRet) {
ValueType eValueType = (ValueType)nTmp;
bTypeOK = sal_True;
switch (eValueType)
{
case XML_VALUE_TYPE_STRING:
bStringType = sal_True;
break;
case XML_VALUE_TYPE_FLOAT:
case XML_VALUE_TYPE_CURRENCY:
case XML_VALUE_TYPE_PERCENTAGE:
case XML_VALUE_TYPE_DATE:
case XML_VALUE_TYPE_TIME:
case XML_VALUE_TYPE_BOOLEAN:
bStringType = sal_False;
break;
default:
OSL_FAIL("unknown value type");
bTypeOK = sal_False;
}
}
break;
}
case XML_TOK_TEXTFIELD_VALUE:
{
double fTmp;
bool const bRet = ::sax::Converter::convertDouble(fTmp,sAttrValue);
if (bRet) {
bFloatValueOK = sal_True;
fValue = fTmp;
}
break;
}
case XML_TOK_TEXTFIELD_TIME_VALUE:
{
double fTmp;
bool const bRet =
::sax::Converter::convertDuration(fTmp, sAttrValue);
if (bRet) {
bFloatValueOK = sal_True;
fValue = fTmp;
}
break;
}
case XML_TOK_TEXTFIELD_DATE_VALUE:
{
double fTmp;
sal_Bool bRet = rImport.GetMM100UnitConverter().
convertDateTime(fTmp,sAttrValue);
if (bRet) {
bFloatValueOK = sal_True;
fValue = fTmp;
}
break;
}
case XML_TOK_TEXTFIELD_BOOL_VALUE:
{
bool bTmp(false);
bool bRet = ::sax::Converter::convertBool(bTmp, sAttrValue);
if (bRet) {
bFloatValueOK = sal_True;
fValue = (bTmp ? 1.0 : 0.0);
}
else
{
double fTmp;
bRet = ::sax::Converter::convertDouble(fTmp, sAttrValue);
if (bRet) {
bFloatValueOK = sal_True;
fValue = fTmp;
}
}
break;
}
case XML_TOK_TEXTFIELD_STRING_VALUE:
sValue = sAttrValue;
bStringValueOK = sal_True;
break;
case XML_TOK_TEXTFIELD_FORMULA:
{
OUString sTmp;
sal_uInt16 nPrefix = rImport.GetNamespaceMap().
_GetKeyByAttrName( sAttrValue, &sTmp, sal_False );
if( XML_NAMESPACE_OOOW == nPrefix )
{
sFormula = sTmp;
bFormulaOK = sal_True;
}
else
sFormula = sAttrValue;
}
break;
case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
{
sal_Int32 nKey = rHelper.GetDataStyleKey(
sAttrValue, &bIsDefaultLanguage);
if (-1 != nKey)
{
nFormatKey = nKey;
bFormatOK = sal_True;
}
break;
}
} // switch
}
void XMLValueImportHelper::PrepareField(
const Reference<XPropertySet> & xPropertySet)
{
Any aAny;
if (bSetType)
{
// ??? how to set type?
}
if (bSetFormula)
{
aAny <<= (!bFormulaOK && bFormulaDefault) ? sDefault : sFormula;
xPropertySet->setPropertyValue(sPropertyContent, aAny);
}
// format/style
if (bSetStyle && bFormatOK)
{
aAny <<= nFormatKey;
xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
if( xPropertySet->getPropertySetInfo()->
hasPropertyByName( sPropertyIsFixedLanguage ) )
{
sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage;
aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() );
xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny );
}
}
// value: string or float
if (bSetValue)
{
if (bStringType)
{
aAny <<= (!bStringValueOK && bStringDefault) ? sDefault : sValue;
xPropertySet->setPropertyValue(sPropertyContent, aAny);
}
else
{
aAny <<= fValue;
xPropertySet->setPropertyValue(sPropertyValue, aAny);
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|