summaryrefslogtreecommitdiff
path: root/xmloff/source/text/txtimp.cxx
blob: 429b8e26fce7d9e0ffdf342ac7e9d1384fd19e30 (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
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
/*************************************************************************
 *
 *  $RCSfile: txtimp.cxx,v $
 *
 *  $Revision: 1.22 $
 *
 *  last change: $Author: dvo $ $Date: 2000-11-14 14:42:50 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _SVSTDARR_STRINGSDTOR_DECL
#define _SVSTDARR_STRINGSDTOR
#include <svtools/svstdarr.hxx>
#endif

#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
#include <com/sun/star/container/XNameContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_STYLE_XSTYLEFAMILIESSUPPLIER_HPP_
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XTEXTCURSOR_HPP_
#include <com/sun/star/text/XTextCursor.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XCHAPTERNUMBERINGSUPPLIER_HPP_
#include <com/sun/star/text/XChapterNumberingSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XTEXTFRAMESSUPPLIER_HPP_
#include <com/sun/star/text/XTextFramesSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XTEXTGRAPHICOBJECTSSUPPLIER_HPP_
#include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XTEXTEMBEDDEDOBJECTSSUPPLIER_HPP_
#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_TEXTCONTENTANCHORTYPE_HPP
#include <com/sun/star/text/TextContentAnchorType.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XTEXTFRAME_HPP_
#include <com/sun/star/text/XTextFrame.hpp>
#endif
#ifndef _COM_SUN_STAR_DRAWING_XSHAPES_HPP_
#include <com/sun/star/drawing/XShapes.hpp>
#endif


#ifndef _XMLOFF_XMLKYWD_HXX
#include "xmlkywd.hxx"
#endif
#ifndef _XMLOFF_XMLNMSPE_HXX
#include "xmlnmspe.hxx"
#endif
#ifndef _XMLOFF_TXTSTYLI_HXX_
#include "txtstyli.hxx"
#endif
#ifndef _XMLOFF_FAMILIES_HXX_
#include "families.hxx"
#endif

#ifndef _XMLOFF_XMLNUMFI_HXX
#include "xmlnumfi.hxx"
#endif
#ifndef _XMLOFF_XMLNUMI_HXX
#include "xmlnumi.hxx"
#endif

#ifndef _XMLOFF_TXTPARAI_HXX
#include "txtparai.hxx"
#endif
#ifndef _XMLOFF_TXTIMP_HXX
#include "txtimp.hxx"
#endif
#ifndef _XMLOFF_TXTPRMAP_HXX
#include "txtprmap.hxx"
#endif
#ifndef _XMLOFF_TXTIMPPR_HXX
#include "txtimppr.hxx"
#endif
#ifndef _XMLOFF_XMLIMP_HXX
#include "xmlimp.hxx"
#endif
#ifndef _XMLOFF_TXTVFLDI_HXX
#include "txtvfldi.hxx"
#endif
#ifndef _XMLOFF_I18NMAP_HXX
#include "i18nmap.hxx"
#endif
#ifndef _XMLTEXTLISTITEMCONTEXT_HXX
#include "XMLTextListItemContext.hxx"
#endif
#ifndef _XMLTEXTLISTBLOCKCONTEXT_HXX
#include "XMLTextListBlockContext.hxx"
#endif
#ifndef _XMLTEXTFRAMECONTEXT_HXX
#include "XMLTextFrameContext.hxx"
#endif
#ifndef _XMLOFF_XMLPROPERTYBACKPATCHTER_HXX
#include "XMLPropertyBackpatcher.hxx"
#endif
#ifndef _XMLTEXTFRAMEHYPERLINKCONTEXT_HXX
#include "XMLTextFrameHyperlinkContext.hxx"
#endif
#ifndef _XMLOFF_XMLSECTIONIMPORTCONTEXT_HXX_
#include "XMLSectionImportContext.hxx"
#endif
#ifndef _XMLOFF_XMLINDEXTOCCONTEXT_HXX_
#include "XMLIndexTOCContext.hxx"
#endif
#ifndef _XMLOFF_XMLFONTSTYLESCONTEXT_HXX
#include "XMLFontStylesContext.hxx"
#endif


using namespace ::rtl;
using namespace ::std;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::style;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::xml::sax;


static __FAR_DATA SvXMLTokenMapEntry aTextElemTokenMap[] =
{
    { XML_NAMESPACE_TEXT, sXML_p,               XML_TOK_TEXT_P              },
    { XML_NAMESPACE_TEXT, sXML_h,               XML_TOK_TEXT_H              },
    { XML_NAMESPACE_TEXT, sXML_ordered_list,    XML_TOK_TEXT_ORDERED_LIST   },
    { XML_NAMESPACE_TEXT, sXML_unordered_list,  XML_TOK_TEXT_UNORDERED_LIST },
    { XML_NAMESPACE_DRAW, sXML_text_box,        XML_TOK_TEXT_TEXTBOX_PAGE },
    { XML_NAMESPACE_DRAW, sXML_image,       XML_TOK_TEXT_IMAGE_PAGE },
    { XML_NAMESPACE_DRAW, sXML_a,               XML_TOK_DRAW_A_PAGE },
    { XML_NAMESPACE_TABLE,sXML_table,           XML_TOK_TABLE_TABLE         },
//  { XML_NAMESPACE_TABLE,sXML_sub_table,       XML_TOK_TABLE_SUBTABLE      },
    { XML_NAMESPACE_TEXT, sXML_variable_decls,  XML_TOK_TEXT_VARFIELD_DECLS },
    { XML_NAMESPACE_TEXT, sXML_user_field_decls,XML_TOK_TEXT_USERFIELD_DECLS },
    { XML_NAMESPACE_TEXT, sXML_sequence_decls,  XML_TOK_TEXT_SEQUENCE_DECLS },
    { XML_NAMESPACE_TEXT, sXML_dde_connection_decls, XML_TOK_TEXT_DDE_DECLS },
    { XML_NAMESPACE_TEXT, sXML_section,         XML_TOK_TEXT_SECTION },
    { XML_NAMESPACE_TEXT, sXML_table_of_content, XML_TOK_TEXT_TOC },
    { XML_NAMESPACE_TEXT, sXML_object_index,    XML_TOK_TEXT_OBJECT_INDEX },
    { XML_NAMESPACE_TEXT, sXML_table_index,     XML_TOK_TEXT_TABLE_INDEX },
    { XML_NAMESPACE_TEXT, sXML_illustration_index, XML_TOK_TEXT_ILLUSTRATION_INDEX },
    { XML_NAMESPACE_TEXT, sXML_user_index,      XML_TOK_TEXT_USER_INDEX },
    { XML_NAMESPACE_TEXT, sXML_alphabetical_index, XML_TOK_TEXT_ALPHABETICAL_INDEX },
    { XML_NAMESPACE_TEXT, sXML_bibliography,    XML_TOK_TEXT_BIBLIOGRAPHY_INDEX },

    XML_TOKEN_MAP_END
};

static __FAR_DATA SvXMLTokenMapEntry aTextPElemTokenMap[] =
{
    { XML_NAMESPACE_TEXT, sXML_span, XML_TOK_TEXT_SPAN },
    { XML_NAMESPACE_TEXT, sXML_tab_stop, XML_TOK_TEXT_TAB_STOP },
    { XML_NAMESPACE_TEXT, sXML_line_break, XML_TOK_TEXT_LINE_BREAK },
    { XML_NAMESPACE_TEXT, sXML_s, XML_TOK_TEXT_S },
    { XML_NAMESPACE_TEXT, sXML_a, XML_TOK_TEXT_HYPERLINK },

    { XML_NAMESPACE_TEXT, sXML_footnote, XML_TOK_TEXT_FOOTNOTE },
    { XML_NAMESPACE_TEXT, sXML_endnote, XML_TOK_TEXT_ENDNOTE },
    { XML_NAMESPACE_TEXT, sXML_bookmark, XML_TOK_TEXT_BOOKMARK },
    { XML_NAMESPACE_TEXT, sXML_bookmark_start, XML_TOK_TEXT_BOOKMARK_START },
    { XML_NAMESPACE_TEXT, sXML_bookmark_end, XML_TOK_TEXT_BOOKMARK_END },
    { XML_NAMESPACE_TEXT, sXML_reference_mark, XML_TOK_TEXT_REFERENCE },
    { XML_NAMESPACE_TEXT, sXML_reference_mark_start,
      XML_TOK_TEXT_REFERENCE_START },
    { XML_NAMESPACE_TEXT, sXML_reference_mark_end,
      XML_TOK_TEXT_REFERENCE_END },

    { XML_NAMESPACE_DRAW, sXML_text_box, XML_TOK_TEXT_TEXTBOX },
    { XML_NAMESPACE_DRAW, sXML_image, XML_TOK_TEXT_IMAGE },
    { XML_NAMESPACE_DRAW, sXML_a,               XML_TOK_DRAW_A },

    // sender fields
    { XML_NAMESPACE_TEXT, sXML_sender_firstname,XML_TOK_TEXT_SENDER_FIRSTNAME},
    { XML_NAMESPACE_TEXT, sXML_sender_lastname, XML_TOK_TEXT_SENDER_LASTNAME },
    { XML_NAMESPACE_TEXT, sXML_sender_initials, XML_TOK_TEXT_SENDER_INITIALS },
    { XML_NAMESPACE_TEXT, sXML_sender_title, XML_TOK_TEXT_SENDER_TITLE },
    { XML_NAMESPACE_TEXT, sXML_sender_position, XML_TOK_TEXT_SENDER_POSITION },
    { XML_NAMESPACE_TEXT, sXML_sender_email, XML_TOK_TEXT_SENDER_EMAIL },
    { XML_NAMESPACE_TEXT, sXML_sender_phone_private,
      XML_TOK_TEXT_SENDER_PHONE_PRIVATE },
    { XML_NAMESPACE_TEXT, sXML_sender_fax, XML_TOK_TEXT_SENDER_FAX },
    { XML_NAMESPACE_TEXT, sXML_sender_company, XML_TOK_TEXT_SENDER_COMPANY },
    { XML_NAMESPACE_TEXT, sXML_sender_phone_work,
      XML_TOK_TEXT_SENDER_PHONE_WORK },
    { XML_NAMESPACE_TEXT, sXML_sender_street, XML_TOK_TEXT_SENDER_STREET },
    { XML_NAMESPACE_TEXT, sXML_sender_city, XML_TOK_TEXT_SENDER_CITY },
    { XML_NAMESPACE_TEXT, sXML_sender_postal_code,
      XML_TOK_TEXT_SENDER_POSTAL_CODE },
    { XML_NAMESPACE_TEXT, sXML_sender_country, XML_TOK_TEXT_SENDER_COUNTRY },
    { XML_NAMESPACE_TEXT, sXML_sender_state_or_province,
      XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE },

    // misc. document fields
    { XML_NAMESPACE_TEXT, sXML_author_name, XML_TOK_TEXT_AUTHOR_NAME },
    { XML_NAMESPACE_TEXT, sXML_author_initials, XML_TOK_TEXT_AUTHOR_INITIALS },
    { XML_NAMESPACE_TEXT, sXML_date, XML_TOK_TEXT_DATE },
    { XML_NAMESPACE_TEXT, sXML_time, XML_TOK_TEXT_TIME },
    { XML_NAMESPACE_TEXT, sXML_page_number, XML_TOK_TEXT_PAGE_NUMBER },
    { XML_NAMESPACE_TEXT, sXML_page_continuation_string,
      XML_TOK_TEXT_PAGE_CONTINUATION_STRING },

    // variable fields
    { XML_NAMESPACE_TEXT, sXML_variable_set, XML_TOK_TEXT_VARIABLE_SET },
    { XML_NAMESPACE_TEXT, sXML_variable_get, XML_TOK_TEXT_VARIABLE_GET },
    { XML_NAMESPACE_TEXT, sXML_variable_input, XML_TOK_TEXT_VARIABLE_INPUT },
    { XML_NAMESPACE_TEXT, sXML_user_field_get, XML_TOK_TEXT_USER_FIELD_GET },
    { XML_NAMESPACE_TEXT, sXML_user_field_input,XML_TOK_TEXT_USER_FIELD_INPUT},
    { XML_NAMESPACE_TEXT, sXML_sequence, XML_TOK_TEXT_SEQUENCE },
    { XML_NAMESPACE_TEXT, sXML_expression, XML_TOK_TEXT_EXPRESSION },
    { XML_NAMESPACE_TEXT, sXML_text_input, XML_TOK_TEXT_TEXT_INPUT },

    // database fields
    { XML_NAMESPACE_TEXT, sXML_database_display,
      XML_TOK_TEXT_DATABASE_DISPLAY },
    { XML_NAMESPACE_TEXT, sXML_database_next,
      XML_TOK_TEXT_DATABASE_NEXT },
    { XML_NAMESPACE_TEXT, sXML_database_select,
      XML_TOK_TEXT_DATABASE_SELECT },
    { XML_NAMESPACE_TEXT, sXML_database_row_number,
      XML_TOK_TEXT_DATABASE_ROW_NUMBER },
    { XML_NAMESPACE_TEXT, sXML_database_name, XML_TOK_TEXT_DATABASE_NAME },

    // docinfo fields
    { XML_NAMESPACE_TEXT, sXML_initial_creator,
      XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR },
    { XML_NAMESPACE_TEXT, sXML_description, XML_TOK_TEXT_DOCUMENT_DESCRIPTION},
    { XML_NAMESPACE_TEXT, sXML_user_info_0,
      XML_TOK_TEXT_DOCUMENT_INFORMATION_0 },
    { XML_NAMESPACE_TEXT, sXML_user_info_1,
      XML_TOK_TEXT_DOCUMENT_INFORMATION_1 },
    { XML_NAMESPACE_TEXT, sXML_user_info_2,
      XML_TOK_TEXT_DOCUMENT_INFORMATION_2 },
    { XML_NAMESPACE_TEXT, sXML_user_info_3,
      XML_TOK_TEXT_DOCUMENT_INFORMATION_3 },
    { XML_NAMESPACE_TEXT, sXML_printed_by, XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR},
    { XML_NAMESPACE_TEXT, sXML_title, XML_TOK_TEXT_DOCUMENT_TITLE },
    { XML_NAMESPACE_TEXT, sXML_subject, XML_TOK_TEXT_DOCUMENT_SUBJECT },
    { XML_NAMESPACE_TEXT, sXML_keywords, XML_TOK_TEXT_DOCUMENT_KEYWORDS },
    { XML_NAMESPACE_TEXT, sXML_creator, XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR },
    { XML_NAMESPACE_TEXT, sXML_editing_cycles,
      XML_TOK_TEXT_DOCUMENT_REVISION },
    { XML_NAMESPACE_TEXT, sXML_creation_date,
      XML_TOK_TEXT_DOCUMENT_CREATION_DATE },
    { XML_NAMESPACE_TEXT, sXML_creation_time,
      XML_TOK_TEXT_DOCUMENT_CREATION_TIME },
    { XML_NAMESPACE_TEXT, sXML_print_date, XML_TOK_TEXT_DOCUMENT_PRINT_DATE },
    { XML_NAMESPACE_TEXT, sXML_print_time, XML_TOK_TEXT_DOCUMENT_PRINT_TIME },
    { XML_NAMESPACE_TEXT, sXML_modification_date,
      XML_TOK_TEXT_DOCUMENT_SAVE_DATE },
    { XML_NAMESPACE_TEXT, sXML_modification_time,
      XML_TOK_TEXT_DOCUMENT_SAVE_TIME },
    { XML_NAMESPACE_TEXT, sXML_editing_duration,
      XML_TOK_TEXT_DOCUMENT_EDIT_DURATION },
    { XML_NAMESPACE_TEXT, sXML_user_defined,
      XML_TOK_TEXT_DOCUMENT_USER_DEFINED },

    // misc fields
    { XML_NAMESPACE_TEXT, sXML_placeholder, XML_TOK_TEXT_PLACEHOLDER },
    { XML_NAMESPACE_TEXT, sXML_hidden_text, XML_TOK_TEXT_HIDDEN_TEXT },
    { XML_NAMESPACE_TEXT, sXML_hidden_paragraph,
      XML_TOK_TEXT_HIDDEN_PARAGRAPH },
    { XML_NAMESPACE_TEXT, sXML_conditional_text,
      XML_TOK_TEXT_CONDITIONAL_TEXT },
    { XML_NAMESPACE_TEXT, sXML_file_name, XML_TOK_TEXT_FILENAME },
    { XML_NAMESPACE_TEXT, sXML_chapter, XML_TOK_TEXT_CHAPTER },
    { XML_NAMESPACE_TEXT, sXML_template_name, XML_TOK_TEXT_TEMPLATENAME },
    { XML_NAMESPACE_TEXT, sXML_paragraph_count, XML_TOK_TEXT_PARAGRAPH_COUNT },
    { XML_NAMESPACE_TEXT, sXML_word_count, XML_TOK_TEXT_WORD_COUNT },
    { XML_NAMESPACE_TEXT, sXML_table_count, XML_TOK_TEXT_TABLE_COUNT },
    { XML_NAMESPACE_TEXT, sXML_character_count, XML_TOK_TEXT_CHARACTER_COUNT },
    { XML_NAMESPACE_TEXT, sXML_image_count, XML_TOK_TEXT_IMAGE_COUNT },
    { XML_NAMESPACE_TEXT, sXML_object_count, XML_TOK_TEXT_OBJECT_COUNT },
    { XML_NAMESPACE_TEXT, sXML_page_count, XML_TOK_TEXT_PAGE_COUNT },
    { XML_NAMESPACE_TEXT, sXML_page_variable_get, XML_TOK_TEXT_GET_PAGE_VAR },
    { XML_NAMESPACE_TEXT, sXML_page_variable_set, XML_TOK_TEXT_SET_PAGE_VAR },
    { XML_NAMESPACE_TEXT, sXML_execute_macro, XML_TOK_TEXT_MACRO },
    { XML_NAMESPACE_TEXT, sXML_dde_connection, XML_TOK_TEXT_DDE },
    { XML_NAMESPACE_TEXT, sXML_reference_ref, XML_TOK_TEXT_REFERENCE_REF },
    { XML_NAMESPACE_TEXT, sXML_bookmark_ref, XML_TOK_TEXT_BOOKMARK_REF },
    { XML_NAMESPACE_TEXT, sXML_sequence_ref, XML_TOK_TEXT_SEQUENCE_REF },
    { XML_NAMESPACE_TEXT, sXML_footnote_ref, XML_TOK_TEXT_FOOTNOTE_REF },
    { XML_NAMESPACE_TEXT, sXML_endnote_ref, XML_TOK_TEXT_ENDNOTE_REF },

    // Calc fields
    { XML_NAMESPACE_TEXT, sXML_sheet_name, XML_TOK_TEXT_SHEET_NAME },

    XML_TOKEN_MAP_END
};

static __FAR_DATA SvXMLTokenMapEntry aTextPAttrTokenMap[] =
{
    { XML_NAMESPACE_TEXT, sXML_style_name,  XML_TOK_TEXT_P_STYLE_NAME },
    { XML_NAMESPACE_TEXT, sXML_cond_style_name,
                                            XML_TOK_TEXT_P_COND_STYLE_NAME },
    { XML_NAMESPACE_TEXT, sXML_level,       XML_TOK_TEXT_P_LEVEL },
    XML_TOKEN_MAP_END
};

static __FAR_DATA SvXMLTokenMapEntry aTextListBlockAttrTokenMap[] =
{
    { XML_NAMESPACE_TEXT, sXML_style_name,
            XML_TOK_TEXT_LIST_BLOCK_STYLE_NAME },
    { XML_NAMESPACE_TEXT, sXML_continue_numbering,
            XML_TOK_TEXT_LIST_BLOCK_CONTINUE_NUMBERING },
    XML_TOKEN_MAP_END
};

static __FAR_DATA SvXMLTokenMapEntry aTextListBlockElemTokenMap[] =
{
    { XML_NAMESPACE_TEXT, sXML_list_header, XML_TOK_TEXT_LIST_HEADER },
    { XML_NAMESPACE_TEXT, sXML_list_item,   XML_TOK_TEXT_LIST_ITEM   },
    XML_TOKEN_MAP_END
};

static __FAR_DATA SvXMLTokenMapEntry aTextFrameAttrTokenMap[] =
{
    { XML_NAMESPACE_DRAW, sXML_style_name, XML_TOK_TEXT_FRAME_STYLE_NAME },
    { XML_NAMESPACE_DRAW, sXML_name, XML_TOK_TEXT_FRAME_NAME },
    { XML_NAMESPACE_TEXT, sXML_anchor_type, XML_TOK_TEXT_FRAME_ANCHOR_TYPE },
    { XML_NAMESPACE_TEXT, sXML_anchor_page_number, XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER },
    { XML_NAMESPACE_SVG, sXML_x, XML_TOK_TEXT_FRAME_X },
    { XML_NAMESPACE_SVG, sXML_y, XML_TOK_TEXT_FRAME_Y },
    { XML_NAMESPACE_SVG, sXML_width, XML_TOK_TEXT_FRAME_WIDTH },
//  { XML_NAMESPACE_FO, sXML_min_width, XML_TOK_TEXT_FRAME_MIN_WIDTH },
    { XML_NAMESPACE_SVG, sXML_height, XML_TOK_TEXT_FRAME_HEIGHT },
    { XML_NAMESPACE_FO, sXML_min_height, XML_TOK_TEXT_FRAME_MIN_HEIGHT },
    { XML_NAMESPACE_DRAW, sXML_chain_next_name, XML_TOK_TEXT_FRAME_NEXT_CHAIN_NAME },
    { XML_NAMESPACE_XLINK, sXML_href, XML_TOK_TEXT_FRAME_HREF },
    { XML_NAMESPACE_DRAW, sXML_name, XML_TOK_TEXT_FRAME_FILTER_NAME },
    XML_TOKEN_MAP_END
};

static __FAR_DATA SvXMLTokenMapEntry aTextHyperlinkAttrTokenMap[] =
{
    { XML_NAMESPACE_XLINK, sXML_href, XML_TOK_TEXT_HYPERLINK_HREF },
    { XML_NAMESPACE_OFFICE, sXML_name, XML_TOK_TEXT_HYPERLINK_NAME },
    { XML_NAMESPACE_XLINK, sXML_show, XML_TOK_TEXT_HYPERLINK_SHOW },
    { XML_NAMESPACE_OFFICE, sXML_target_frame_name, XML_TOK_TEXT_HYPERLINK_TARGET_FRAME },
    { XML_NAMESPACE_TEXT, sXML_style_name, XML_TOK_TEXT_HYPERLINK_STYLE_NAME },
    { XML_NAMESPACE_TEXT, sXML_visited_style_name, XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME },
    { XML_NAMESPACE_OFFICE, sXML_server_map, XML_TOK_TEXT_HYPERLINK_SERVER_MAP },
    XML_TOKEN_MAP_END
};

static __FAR_DATA SvXMLTokenMapEntry aTextMasterPageElemTokenMap[] =
{
    { XML_NAMESPACE_STYLE, sXML_header, XML_TOK_TEXT_MP_HEADER },
    { XML_NAMESPACE_STYLE, sXML_footer, XML_TOK_TEXT_MP_FOOTER },
    { XML_NAMESPACE_STYLE, sXML_header_left, XML_TOK_TEXT_MP_HEADER_LEFT },
    { XML_NAMESPACE_STYLE, sXML_footer_left, XML_TOK_TEXT_MP_FOOTER_LEFT },

    XML_TOKEN_MAP_END
};

XMLTextImportHelper::XMLTextImportHelper(
        const Reference < XModel >& rModel,
        sal_Bool bInsertM, sal_Bool bStylesOnlyM ) :
    pTextElemTokenMap( 0 ),
    pTextPElemTokenMap( 0 ),
    pTextPAttrTokenMap( 0 ),
    pTextListBlockAttrTokenMap( 0 ),
    pTextListBlockElemTokenMap( 0 ),
    pTextFieldAttrTokenMap( 0 ),
    pTextFrameAttrTokenMap( 0 ),
    pTextHyperlinkAttrTokenMap( 0 ),
    pTextMasterPageElemTokenMap( 0 ),
    pPrevFrmNames( 0 ),
    pNextFrmNames( 0 ),
    pRenameMap( 0 ),
    pOutlineStyles( 0 ),
    bInsertMode( bInsertM ),
    bStylesOnlyMode( bStylesOnlyM ),
    pFootnoteBackpatcher(NULL),
    pSequenceIdBackpatcher(NULL),
    pSequenceNameBackpatcher(NULL),
    sParaStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")),
    sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")),
    sHeadingStyleName(RTL_CONSTASCII_USTRINGPARAM("HeadingStyleName")),
    sNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("NumberingLevel")),
    sNumberingStartValue(RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue")),
    sParaIsNumberingRestart(RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart")),
    sNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules")),
    sSequenceNumber(RTL_CONSTASCII_USTRINGPARAM("SequenceNumber")),
    sSourceName(RTL_CONSTASCII_USTRINGPARAM("SourceName")),
    sCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM("CurrentPresentation")),
    sNumberingIsNumber(RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber")),
    sChainNextName(RTL_CONSTASCII_USTRINGPARAM("ChainNextName")),
    sChainPrevName(RTL_CONSTASCII_USTRINGPARAM("ChainPrevName")),
    sHyperLinkURL(RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL")),
    sHyperLinkName(RTL_CONSTASCII_USTRINGPARAM("HyperLinkName")),
    sHyperLinkTarget(RTL_CONSTASCII_USTRINGPARAM("HyperLinkTarget")),
    sUnvisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("UnvisitedCharStyleName")),
    sVisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("VisitedCharStyleName")),
    sTextFrame(RTL_CONSTASCII_USTRINGPARAM("TextFrame")),
    sPageDescName(RTL_CONSTASCII_USTRINGPARAM("PageDescName"))
{
    Reference< XChapterNumberingSupplier > xCNSupplier( rModel, UNO_QUERY );

    if( xCNSupplier.is() )
        xChapterNumbering = xCNSupplier->getChapterNumberingRules();

    Reference< XStyleFamiliesSupplier > xFamiliesSupp( rModel, UNO_QUERY );
    DBG_ASSERT( xFamiliesSupp.is(), "no chapter numbering supplier" );

    if( xFamiliesSupp.is() )
    {
        Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();

        const OUString aParaStyles(RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles"));
        if( xFamilies->hasByName( aParaStyles ) )
        {
            Any aAny( xFamilies->getByName( aParaStyles ) );
            aAny >>= xParaStyles;
        }

        const OUString aCharStyles(RTL_CONSTASCII_USTRINGPARAM("CharacterStyles"));
        if( xFamilies->hasByName( aCharStyles ) )
        {
            Any aAny( xFamilies->getByName( aCharStyles ) );
            aAny >>= xTextStyles;
        }

        const OUString aNumStyles(RTL_CONSTASCII_USTRINGPARAM("NumberingStyles"));
        if( xFamilies->hasByName( aNumStyles ) )
        {
            Any aAny( xFamilies->getByName( aNumStyles ) );
            aAny >>= xNumStyles;
        }

        const OUString aFrameStyles(RTL_CONSTASCII_USTRINGPARAM("FrameStyles"));
        if( xFamilies->hasByName( aFrameStyles ) )
        {
            Any aAny( xFamilies->getByName( aFrameStyles ) );
            aAny >>= xFrameStyles;
        }

        const OUString aPageStyles(RTL_CONSTASCII_USTRINGPARAM("PageStyles"));
        if( xFamilies->hasByName( aPageStyles ) )
        {
            Any aAny( xFamilies->getByName( aPageStyles ) );
            aAny >>= xPageStyles;
        }
    }

    Reference < XTextFramesSupplier > xTFS( rModel, UNO_QUERY );
    if( xTFS.is() )
        xTextFrames = xTFS->getTextFrames();

    Reference < XTextGraphicObjectsSupplier > xTGOS( rModel, UNO_QUERY );
    if( xTGOS.is() )
        xGraphics = xTGOS->getGraphicObjects();

    Reference < XTextEmbeddedObjectsSupplier > xTEOS( rModel, UNO_QUERY );
    if( xTEOS.is() )
        xObjects = xTEOS->getEmbeddedObjects();

    XMLPropertySetMapper *pPropMapper =
            new XMLTextPropertySetMapper( TEXT_PROP_MAP_PARA );
    xParaImpPrMap = new XMLTextImportPropertyMapper( pPropMapper );

    pPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT );
    xTextImpPrMap = new XMLTextImportPropertyMapper( pPropMapper );

    pPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_FRAME );
    xFrameImpPrMap = new XMLTextImportPropertyMapper( pPropMapper );

    pPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_SECTION );
    xSectionImpPrMap = new XMLTextImportPropertyMapper( pPropMapper );
}

XMLTextImportHelper::~XMLTextImportHelper()
{
    delete pTextElemTokenMap;
    delete pTextPElemTokenMap;
    delete pTextPAttrTokenMap;
    delete pTextListBlockAttrTokenMap;
    delete pTextListBlockElemTokenMap;
    delete pTextFieldAttrTokenMap;
    delete pTextFrameAttrTokenMap;
    delete pTextHyperlinkAttrTokenMap;
    delete pTextMasterPageElemTokenMap;

    delete pRenameMap;

    delete pPrevFrmNames;
    delete pNextFrmNames;

    _FinitBackpatcher();
}

SvXMLImportPropertyMapper *XMLTextImportHelper::CreateShapeExtPropMapper()
{
    XMLPropertySetMapper *pPropMapper =
        new XMLTextPropertySetMapper( TEXT_PROP_MAP_FRAME );
    return new XMLTextImportPropertyMapper( pPropMapper );
}

void XMLTextImportHelper::SetCursor( const Reference < XTextCursor > & rCursor )
{
    xCursor = rCursor;
    xText = rCursor->getText();
    xCursorAsRange = Reference < XTextRange >( rCursor, UNO_QUERY );
}

void XMLTextImportHelper::ResetCursor()
{
    xCursor = 0;
    xText = 0;
    xCursorAsRange = 0;
}

SvXMLTokenMap *XMLTextImportHelper::_GetTextElemTokenMap()
{
    return new SvXMLTokenMap( aTextElemTokenMap );
}

SvXMLTokenMap *XMLTextImportHelper::_GetTextPElemTokenMap()
{
    return new SvXMLTokenMap( aTextPElemTokenMap );
}

SvXMLTokenMap *XMLTextImportHelper::_GetTextPAttrTokenMap()
{
    return new SvXMLTokenMap( aTextPAttrTokenMap );
}

SvXMLTokenMap *XMLTextImportHelper::_GetTextFrameAttrTokenMap()
{
    return new SvXMLTokenMap( aTextFrameAttrTokenMap );
}

SvXMLTokenMap *XMLTextImportHelper::_GetTextHyperlinkAttrTokenMap()
{
    return new SvXMLTokenMap( aTextHyperlinkAttrTokenMap );
}

SvXMLTokenMap *XMLTextImportHelper::_GetTextMasterPageElemTokenMap()
{
    return new SvXMLTokenMap( aTextMasterPageElemTokenMap );
}

sal_Bool XMLTextImportHelper::HasFrameByName( const OUString& rName ) const
{
    return ( xTextFrames.is() && xTextFrames->hasByName( rName ) ) ||
           ( xGraphics.is() && xGraphics->hasByName( rName ) ) ||
           ( xObjects.is() && xObjects->hasByName( rName ) );
}

void XMLTextImportHelper::InsertString( const OUString& rChars )
{
    DBG_ASSERT( xText.is(), "no text" );
    DBG_ASSERT( xCursorAsRange.is(), "no range" );
    if( xText.is() )
        xText->insertString( xCursorAsRange, rChars, sal_False );
}

void XMLTextImportHelper::InsertString( const OUString& rChars,
                                         sal_Bool& rIgnoreLeadingSpace )
{
    DBG_ASSERT( xText.is(), "no text" );
    DBG_ASSERT( xCursorAsRange.is(), "no range" );
    if( xText.is() )
    {
        sal_Int32 nLen = rChars.getLength();
        OUStringBuffer sChars( nLen );

        for( sal_Int32 i=0; i < nLen; i++ )
        {
            sal_Unicode c = rChars[i];
            switch( c )
            {
                case 0x20:
                case 0x09:
                case 0x0a:
                case 0x0d:
                    if( !rIgnoreLeadingSpace )
                        sChars.append( (sal_Unicode)0x20 );
                    rIgnoreLeadingSpace = sal_True;
                    break;
                default:
                    rIgnoreLeadingSpace = sal_False;
                    sChars.append( c );
                    break;
            }
        }
        xText->insertString( xCursorAsRange, sChars.makeStringAndClear(),
                             sal_False );
    }
}
void XMLTextImportHelper::InsertControlCharacter( sal_Int16 nControl )
{
    DBG_ASSERT( xText.is(), "no text" );
    DBG_ASSERT( xCursorAsRange.is(), "no range" );
    if( xText.is() )
        xText->insertControlCharacter( xCursorAsRange, nControl, sal_False );
}

void XMLTextImportHelper::InsertTextContent(
    Reference < XTextContent > & xContent )
{
    DBG_ASSERT( xText.is(), "no text" );
    DBG_ASSERT( xCursorAsRange.is(), "no range" );
    if( xText.is() )
        xText->insertTextContent( xCursorAsRange, xContent, sal_False );
}

OUString XMLTextImportHelper::SetStyleAndAttrs(
        const Reference < XTextCursor >& rCursor,
        const OUString& rStyleName,
        sal_Bool bPara )
{
    XMLTextStyleContext *pStyle = 0;
    OUString sStyleName( rStyleName );
    if( sStyleName.getLength() && xAutoStyles.Is() )
    {
        sal_uInt32 nFamily = bPara ? XML_STYLE_FAMILY_TEXT_PARAGRAPH
                                   : XML_STYLE_FAMILY_TEXT_TEXT;
        pStyle = PTR_CAST( XMLTextStyleContext,
              ((SvXMLStylesContext *)&xAutoStyles)->
                    FindStyleChildContext( nFamily, sStyleName, sal_True ) );
    }
    if( pStyle )
        sStyleName = pStyle->GetParent();

    Reference < XPropertySet > xPropSet( rCursor, UNO_QUERY );
    Reference< XPropertySetInfo > xPropSetInfo =
        xPropSet->getPropertySetInfo();

    // style
    if( sStyleName.getLength() )
    {
        const String& rPropName = bPara ? sParaStyleName : sCharStyleName;
        const Reference < XNameContainer > & rStyles = bPara ? xParaStyles
                                                          : xTextStyles;
        if( rStyles.is() &&
            xPropSetInfo->hasPropertyByName( rPropName ) &&
            rStyles->hasByName( sStyleName ) )
        {
            Any aAny;
            aAny <<= sStyleName;
            xPropSet->setPropertyValue( rPropName, aAny );
        }
        else
            sStyleName = OUString();
    }

    // hard paragraph properties
    if( pStyle )
    {
        pStyle->FillPropertySet( xPropSet );
        if( bPara && pStyle->HasMasterPageName() &&
            xPropSetInfo->hasPropertyByName( sPageDescName ) )
        {
            const OUString& rMasterPageName = pStyle->GetMasterPageName();
            if( !rMasterPageName.getLength() ||
                (xPageStyles.is() &&
                 xPageStyles->hasByName( rMasterPageName )) )
            {
                Any aAny;
                aAny <<= rMasterPageName;
                xPropSet->setPropertyValue( sPageDescName, aAny );
            }
        }
    }

    if( bPara && xPropSetInfo->hasPropertyByName( sNumberingRules )  )
    {
        // Set numbering rules
        Reference < XIndexReplace > xNumRule;
        Any aAny = xPropSet->getPropertyValue( sNumberingRules );
        aAny >>= xNumRule;

        if( IsInList() )
        {
            XMLTextListBlockContext *pListBlock = GetListBlock();
            Reference < XIndexReplace > xNewNumRules =
                pListBlock->GetNumRules();

            if( xNewNumRules != xNumRule )
            {
                aAny <<= xNewNumRules;
                xPropSet->setPropertyValue( sNumberingRules, aAny );
            }

            XMLTextListItemContext *pListItem = GetListItem();

            sal_Int8 nLevel = pListBlock->GetLevel();
            if( !pListItem &&
                xPropSetInfo->hasPropertyByName( sNumberingIsNumber ) )
            {
                sal_Bool bTmp = sal_False;
                aAny.setValue( &bTmp, ::getBooleanCppuType() );
                xPropSet->setPropertyValue( sNumberingIsNumber, aAny );
            }

            aAny <<= nLevel;
            xPropSet->setPropertyValue( sNumberingLevel, aAny );

            if( pListBlock->IsRestartNumbering() )
            {
                // TODO: property missing
                if( xPropSetInfo->hasPropertyByName( sParaIsNumberingRestart ) )
                {
                    sal_Bool bTmp = sal_True;
                    aAny.setValue( &bTmp, ::getBooleanCppuType() );
                    xPropSet->setPropertyValue( sParaIsNumberingRestart, aAny );
                }
                pListBlock->ResetRestartNumbering();
            }
            if( pListItem && pListItem->HasStartValue() &&
                xPropSetInfo->hasPropertyByName( sNumberingStartValue ) )
            {
                aAny <<= pListItem->GetStartValue();
                xPropSet->setPropertyValue( sNumberingStartValue, aAny );
            }
            SetListItem( 0 );
        }
        else
        {
            // If the paragraph is not in a list but its style, remove it from
            // the list.
            if( xNumRule.is() )
            {
                Reference < XIndexReplace > xEmpty;
                aAny <<= xEmpty;
                xPropSet->setPropertyValue( sNumberingRules, aAny );
            }
        }
    }

    return sStyleName;
}

void XMLTextImportHelper::SetOutlineStyle(
        sal_Int8 nLevel,
        const OUString& rStyleName )
{
    if( rStyleName.getLength() &&
        xChapterNumbering.is() &&
        nLevel > 0 && nLevel <= xChapterNumbering->getCount() )
    {
        if( !pOutlineStyles )
            pOutlineStyles = new OUString[xChapterNumbering->getCount()];
        pOutlineStyles[nLevel-1] = rStyleName;
    }
}

void XMLTextImportHelper::SetOutlineStyles()
{
    if( pOutlineStyles &&
        xChapterNumbering.is() )
    {
        sal_Int32 nCount = xChapterNumbering->getCount();
        for( sal_Int32 i=0; i < nCount; i++ )
        {
            Sequence < PropertyValue > aProps( 1 );
            PropertyValue *pProps = aProps.getArray();
            pProps->Name = sHeadingStyleName;
            pProps->Value <<= pOutlineStyles[i];

            Any aAny;
            aAny <<= aProps;
            xChapterNumbering->replaceByIndex( i, aAny );
        }
    }
}

void XMLTextImportHelper::SetHyperlink(
    const Reference < XTextCursor >& rCursor,
    const OUString& rHRef,
    const OUString& rName,
    const OUString& rTargetFrameName,
    const OUString& rStyleName,
    const OUString& rVisitedStyleName )
{
    Reference < XPropertySet > xPropSet( rCursor, UNO_QUERY );
    Reference < XPropertySetInfo > xPropSetInfo =
        xPropSet->getPropertySetInfo();
    if( !xPropSetInfo.is() || !xPropSetInfo->hasPropertyByName(sHyperLinkURL) )
        return;

    Any aAny;
    aAny <<= rHRef;
    xPropSet->setPropertyValue( sHyperLinkURL, aAny );

    if( xPropSetInfo->hasPropertyByName( sHyperLinkName ) )
    {
        aAny <<= rName;
        xPropSet->setPropertyValue( sHyperLinkName, aAny );
    }

    if( xPropSetInfo->hasPropertyByName( sHyperLinkTarget ) )
    {
        aAny <<= rTargetFrameName;
        xPropSet->setPropertyValue( sHyperLinkTarget, aAny );
    }

    if( xTextStyles.is() )
    {
        if( rStyleName.getLength() &&
            xPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) &&
            xTextStyles->hasByName( rStyleName ) )
        {
            aAny <<= rStyleName;
            xPropSet->setPropertyValue( sUnvisitedCharStyleName, aAny );
        }

        if( rVisitedStyleName.getLength() &&
            xPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) &&
            xTextStyles->hasByName( rVisitedStyleName ) )
        {
            aAny <<= rVisitedStyleName;
            xPropSet->setPropertyValue( sVisitedCharStyleName, aAny );
        }
    }
}

void XMLTextImportHelper::SetAutoStyles( SvXMLStylesContext *pStyles )
{
    xAutoStyles = pStyles;
}

void XMLTextImportHelper::SetFontDecls( XMLFontStylesContext *pFontDecls )
{
    xFontDecls = pFontDecls;
    ((XMLTextImportPropertyMapper *)xParaImpPrMap.get())
        ->SetFontDecls( pFontDecls );
    ((XMLTextImportPropertyMapper *)xTextImpPrMap.get())
        ->SetFontDecls( pFontDecls );
}

const XMLFontStylesContext *XMLTextImportHelper::GetFontDecls() const
{
    return (XMLFontStylesContext *)&xFontDecls;
}

SvXMLImportContext *XMLTextImportHelper::CreateTextChildContext(
        SvXMLImport& rImport,
        sal_uInt16 nPrefix, const OUString& rLocalName,
        const Reference< XAttributeList > & xAttrList,
        XMLTextType eType )
{
    SvXMLImportContext *pContext = 0;

    const SvXMLTokenMap& rTokenMap = GetTextElemTokenMap();
    sal_Bool bOrdered = sal_False;
    sal_Bool bHeading = sal_False;
    switch( rTokenMap.Get( nPrefix, rLocalName ) )
    {
    case XML_TOK_TEXT_H:
        bHeading = sal_True;
    case XML_TOK_TEXT_P:
        pContext = new XMLParaContext( rImport,
                                       nPrefix, rLocalName,
                                       xAttrList, bHeading );
        break;
    case XML_TOK_TEXT_ORDERED_LIST:
        bOrdered = sal_True;
    case XML_TOK_TEXT_UNORDERED_LIST:
        pContext = new XMLTextListBlockContext( rImport, *this,
                                                nPrefix, rLocalName,
                                                xAttrList, bOrdered );
        break;
    case XML_TOK_TABLE_TABLE:
        if( XML_TEXT_TYPE_BODY == eType || XML_TEXT_TYPE_TEXTBOX == eType ||
             XML_TEXT_TYPE_HEADER_FOOTER == eType )
            pContext = CreateTableChildContext( rImport, nPrefix, rLocalName,
                                                xAttrList );
        break;
    case XML_TOK_TEXT_SEQUENCE_DECLS:
        if( XML_TEXT_TYPE_BODY == eType )
            pContext = new XMLVariableDeclsImportContext(
                rImport, *this, nPrefix, rLocalName, VarTypeSequence);
        break;

    case XML_TOK_TEXT_VARFIELD_DECLS:
        if( XML_TEXT_TYPE_BODY == eType )
            pContext = new XMLVariableDeclsImportContext(
                rImport, *this, nPrefix, rLocalName, VarTypeSimple);
        break;

    case XML_TOK_TEXT_USERFIELD_DECLS:
        if( XML_TEXT_TYPE_BODY == eType )
            pContext = new XMLVariableDeclsImportContext(
                rImport, *this, nPrefix, rLocalName, VarTypeUserField);
        break;

    case XML_TOK_TEXT_DDE_DECLS:
        if( XML_TEXT_TYPE_BODY == eType )
            pContext = new XMLDdeFieldDeclsImportContext(
                rImport, nPrefix, rLocalName);
        break;

    case XML_TOK_TEXT_TEXTBOX_PAGE:
        if( XML_TEXT_TYPE_BODY == eType || XML_TEXT_TYPE_TEXTBOX == eType )
        {
            TextContentAnchorType eAnchorType =
                XML_TEXT_TYPE_TEXTBOX == eType ? TextContentAnchorType_AT_FRAME
                                               : TextContentAnchorType_AT_PAGE;
            pContext = new XMLTextFrameContext( rImport, nPrefix,
                                                rLocalName, xAttrList,
                                                eAnchorType,
                                                XML_TEXT_FRAME_TEXTBOX );
        }
        break;

    case XML_TOK_TEXT_IMAGE_PAGE:
        if( XML_TEXT_TYPE_BODY == eType || XML_TEXT_TYPE_TEXTBOX == eType )
        {
            TextContentAnchorType eAnchorType =
                XML_TEXT_TYPE_TEXTBOX == eType ? TextContentAnchorType_AT_FRAME
                                               : TextContentAnchorType_AT_PAGE;
            pContext = new XMLTextFrameContext( rImport, nPrefix,
                                                rLocalName, xAttrList,
                                                eAnchorType,
                                                XML_TEXT_FRAME_GRAPHIC );
        }
        break;

    case XML_TOK_DRAW_A_PAGE:
        if( XML_TEXT_TYPE_BODY == eType || XML_TEXT_TYPE_TEXTBOX == eType )
        {
            TextContentAnchorType eAnchorType =
                XML_TEXT_TYPE_TEXTBOX == eType ? TextContentAnchorType_AT_FRAME
                                               : TextContentAnchorType_AT_PAGE;
            pContext = new XMLTextFrameHyperlinkContext( rImport, nPrefix,
                                                rLocalName, xAttrList,
                                                eAnchorType );
        }
        break;

    case XML_TOK_TEXT_SECTION:
        pContext = new XMLSectionImportContext( rImport, nPrefix, rLocalName );
        break;

    case XML_TOK_TEXT_TOC:
    case XML_TOK_TEXT_OBJECT_INDEX:
    case XML_TOK_TEXT_TABLE_INDEX:
    case XML_TOK_TEXT_ILLUSTRATION_INDEX:
    case XML_TOK_TEXT_USER_INDEX:
    case XML_TOK_TEXT_ALPHABETICAL_INDEX:
    case XML_TOK_TEXT_BIBLIOGRAPHY_INDEX:
        pContext = new XMLIndexTOCContext( rImport, nPrefix, rLocalName );
        break;

    default:
        if( XML_TEXT_TYPE_BODY == eType || XML_TEXT_TYPE_TEXTBOX == eType )
        {
            Reference < XShapes > xShapes;
            pContext = rImport.GetShapeImport()->CreateGroupChildContext(
                    rImport, nPrefix, rLocalName, xAttrList, xShapes );
        }
    }

//  if( !pContext )
//      pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );

    return pContext;
}

SvXMLImportContext *XMLTextImportHelper::CreateTableChildContext(
        SvXMLImport& rImport,
        sal_uInt16 nPrefix, const OUString& rLocalName,
        const Reference< XAttributeList > & xAttrList )
{
    return 0;
}

/// get data style key for use with NumberFormat property
sal_Int32 XMLTextImportHelper::GetDataStyleKey(const OUString& sStyleName)
{
    // get appropriate context
    SvXMLNumFormatContext* pStyle =
        PTR_CAST( SvXMLNumFormatContext,
                  ((SvXMLStylesContext *)&xAutoStyles)->
                  FindStyleChildContext( XML_STYLE_FAMILY_DATA_STYLE,
                                              sStyleName, sal_True ) );

    // return key or default (-1)
    return (0 != pStyle) ? pStyle->GetKey() : -1;
}

const SvxXMLListStyleContext *XMLTextImportHelper::FindAutoListStyle( const OUString& rName ) const
{
    const SvxXMLListStyleContext *pStyle = 0;
    if( xAutoStyles.Is() )
    {
        pStyle = PTR_CAST( SvxXMLListStyleContext ,
              ((SvXMLStylesContext *)&xAutoStyles)->
                    FindStyleChildContext( XML_STYLE_FAMILY_TEXT_LIST, rName,
                                           sal_True ) );
    }

    return pStyle;
}

XMLPropStyleContext *XMLTextImportHelper::FindAutoFrameStyle( const OUString& rName ) const
{
    XMLPropStyleContext *pStyle = 0;
    if( xAutoStyles.Is() )
    {
        pStyle = PTR_CAST( XMLPropStyleContext ,
              ((SvXMLStylesContext *)&xAutoStyles)->
                    FindStyleChildContext( XML_STYLE_FAMILY_SD_GRAPHICS_ID, rName,
                                           sal_True ) );
    }

    return pStyle;
}

XMLPropStyleContext* XMLTextImportHelper::FindSectionStyle(
    const OUString& rName ) const
{
    XMLPropStyleContext* pStyle = NULL;
    if (xAutoStyles.Is() )
    {
        pStyle = PTR_CAST( XMLPropStyleContext,
                           ((SvXMLStylesContext *)&xAutoStyles)->
                           FindStyleChildContext(
                               XML_STYLE_FAMILY_TEXT_SECTION,
                               rName, sal_True ) );
    }

    return pStyle;
}

XMLPropStyleContext* XMLTextImportHelper::FindPageMaster(
    const OUString& rName ) const
{
    XMLPropStyleContext* pStyle = NULL;
    if (xAutoStyles.Is() )
    {
        pStyle = PTR_CAST( XMLPropStyleContext,
                           ((SvXMLStylesContext *)&xAutoStyles)->
                           FindStyleChildContext(
                               XML_STYLE_FAMILY_PAGE_MASTER,
                               rName, sal_True ) );
    }

    return pStyle;
}

XMLTextListItemContext *XMLTextImportHelper::GetListItem()
{
    return (XMLTextListItemContext *)&xListItem;
}

void XMLTextImportHelper::SetListItem( XMLTextListItemContext *pListItem )
{
    xListItem = pListItem;
}

XMLTextListBlockContext *XMLTextImportHelper::GetListBlock()
{
    return (XMLTextListBlockContext *)&xListBlock;
}

void XMLTextImportHelper::SetListBlock( XMLTextListBlockContext *pListBlock )
{
    xListBlock = pListBlock;
}

const SvXMLTokenMap& XMLTextImportHelper::GetTextListBlockAttrTokenMap()
{
    if( !pTextListBlockAttrTokenMap )
        pTextListBlockAttrTokenMap =
            new SvXMLTokenMap( aTextListBlockAttrTokenMap );

    return *pTextListBlockAttrTokenMap;
}

const SvXMLTokenMap& XMLTextImportHelper::GetTextListBlockElemTokenMap()
{
    if( !pTextListBlockElemTokenMap )
        pTextListBlockElemTokenMap =
            new SvXMLTokenMap( aTextListBlockElemTokenMap );

    return *pTextListBlockElemTokenMap;
}

SvI18NMap& XMLTextImportHelper::GetRenameMap()
{
    if( 0 == pRenameMap )
        pRenameMap = new SvI18NMap();
    return *pRenameMap;
}

void XMLTextImportHelper::InsertBookmarkStartRange(
    const OUString sName,
    const Reference<XTextRange> & rRange)
{
    aBookmarkStartRanges[sName] = rRange;
}

sal_Bool XMLTextImportHelper::FindAndRemoveBookmarkStartRange(
    Reference<XTextRange> & rRange,
    const OUString sName)
{
    if (aBookmarkStartRanges.count(sName))
    {
        rRange = aBookmarkStartRanges[sName];
        aBookmarkStartRanges.erase(sName);
        return sal_True;
    }
    else
    {
        return sal_False;
    }
}


void XMLTextImportHelper::ConnectFrameChains(
        const OUString& rFrmName,
        const OUString& rNextFrmName,
        const Reference < XPropertySet >& rFrmPropSet )
{
    if( !rFrmName.getLength() )
        return;

    if( rNextFrmName.getLength() )
    {
        OUString sNextFrmName = GetRenameMap().Get( XML_TEXT_RENAME_TYPE_FRAME,
                                                    rNextFrmName );
        if( xTextFrames.is() && xTextFrames->hasByName( sNextFrmName ) )
        {
            Any aAny;
            aAny <<= sNextFrmName;
            rFrmPropSet->setPropertyValue( sChainNextName, aAny );
        }
        else
        {
            if( !pPrevFrmNames )
            {
                pPrevFrmNames = new SvStringsDtor;
                pNextFrmNames = new SvStringsDtor;
            }
            pPrevFrmNames->Insert( new String( rFrmName ),
                                   pPrevFrmNames->Count() );
            pNextFrmNames->Insert( new String( sNextFrmName ),
                                   pNextFrmNames->Count() );
        }
    }
    if( pPrevFrmNames && pPrevFrmNames->Count() )
    {
        sal_uInt16 nCount = pPrevFrmNames->Count();
        for( sal_uInt16 i=0; i<nCount; i++ )
        {
            String *pNext = (*pNextFrmNames)[i];
            if( OUString(*pNext) == rFrmName )
            {
                // The previuous frame must exist, because it existing than
                // inserting the entry
                String *pPrev = (*pPrevFrmNames)[i];

                Any aAny;
                aAny <<= OUString( *pPrev );
                rFrmPropSet->setPropertyValue( sChainPrevName, aAny );

                pPrevFrmNames->Remove( i, 1 );
                pNextFrmNames->Remove( i, 1 );
                delete pPrev;
                delete pNext;

                // There cannot be more than one previous frames
                break;
            }
        }
    }
}

sal_Bool XMLTextImportHelper::IsInFrame() const
{
    sal_Bool bIsInFrame = sal_False;

    // are we currently in a text frame? yes, if the cursor has a
    // TextFrame property and it's non-NULL
    Reference<XPropertySet> xPropSet(((XMLTextImportHelper *)this)->GetCursor(), UNO_QUERY);
    if (xPropSet.is())
    {
        if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextFrame))
        {
            Any aAny = xPropSet->getPropertyValue(sTextFrame);
            Reference<XTextFrame> xFrame;
            aAny >>= xFrame;

            if (xFrame.is())
            {
                bIsInFrame = sal_True;
            }
        }
    }

    return bIsInFrame;
}

sal_Bool XMLTextImportHelper::IsInHeaderFooter() const
{
    return sal_False;
}