summaryrefslogtreecommitdiff
path: root/sw/source/filter/xml/xmltext.cxx
blob: 5dce75c62c77d1fadc91f755ed6c016358538e51 (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
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
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
/*************************************************************************
 *
 *  $RCSfile: xmltext.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: mib $ $Date: 2000-10-18 11:20:44 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PRECOMPILED
#include "filt_pch.hxx"
#endif

#pragma hdrstop

#include "hintids.hxx"

#ifndef _RTL_STRBUF_HXX_
#include <rtl/strbuf.hxx>
#endif
#ifndef _RTL_USTRBUF_HXX_
#include <rtl/ustrbuf.hxx>
#endif

#ifndef _RSCSFX_HXX
#include <rsc/rscsfx.hxx>
#endif

#ifndef _XMLOFF_NMSPMAP_HXX
#include <xmloff/nmspmap.hxx>
#endif

#ifndef _XMLOFF_XMLNMSPE_HXX
#include <xmloff/xmlnmspe.hxx>
#endif

#ifndef _XMLOFF_I18NMAP_HXX
#include <xmloff/i18nmap.hxx>
#endif

#ifndef _XMLOFF_XMLITEM_HXX
#include <xmloff/xmlitem.hxx>
#endif

#ifndef _XMLOFF_XMLIMPIT_HXX
#include <xmloff/xmlimpit.hxx>
#endif

#ifndef _XMLOFF_XMLITMPR_HXX
#include <xmloff/xmlexpit.hxx>
#endif

#ifndef _XMLOFF_XMLKYWD_HXX
#include <xmloff/xmlkywd.hxx>
#endif

#ifndef _XMLOFF_XMLASTPL_HXX
#include <xmloff/xmlastpl.hxx>
#endif
#ifndef _XMLOFF_TXTIMP_HXX
#include <xmloff/txtimp.hxx>
#endif

#ifndef _XMLOFF_TXTFLDE_HXX
#include <xmloff/txtflde.hxx>
#endif

#ifndef _XMLOFF_TXTVFLDI_HXX
//#include <xmloff/txtvfldi.hxx>
#endif

#ifndef _UNOFIELD_HXX
#include <unofield.hxx>
#endif

#ifndef _SVX_FONTITEM_HXX //autogen wg. SvxFontItem
#include <svx/fontitem.hxx>
#endif

#ifndef _NDTXT_HXX //autogen wg. SwTxtNode
#include <ndtxt.hxx>
#endif
#ifndef _SECTION_HXX //autogen wg. SwSection
#include <section.hxx>
#endif
#ifndef _DOC_HXX //autogen wg. SwDoc
#include <doc.hxx>
#endif
#ifndef _PAM_HXX //autogen wg. SwPaM
#include <pam.hxx>
#endif
#ifndef _TXATBASE_HXX
#include <txatbase.hxx>
#endif
#ifndef _CHARATR_HXX
#include <charatr.hxx>
#endif
#ifndef _CHARFMT_HXX
#include <charfmt.hxx>
#endif
#ifndef _PARATR_HXX
#include <paratr.hxx>
#endif
#ifndef _FLDBAS_HXX
#include <fldbas.hxx>
#endif
#ifndef _FMTFLD_HXX
#include <fmtfld.hxx>
#endif
#ifndef _FCHRFMT_HXX
#include <fchrfmt.hxx>
#endif
#ifndef _UNOSTYLE_HXX
#include "unostyle.hxx"
#endif

#ifndef _XMLECTXT_HXX
#include "xmlectxt.hxx"
#endif
#ifndef _HINTLIST_HXX
#include "hintlist.hxx"
#endif
#ifndef _XMLIMP_HXX
#include "xmlimp.hxx"
#endif
#ifndef _XMLEXP_HXX
#include "xmlexp.hxx"
#endif
#ifndef _XMLNUM_HXX
#include "xmlnum.hxx"
#endif
#ifndef _XMLTBLI_HXX
#include "xmltbli.hxx"
#endif
#ifndef _XMLFMTE_HXX
#include "xmlfmte.hxx"
#endif
#ifndef _XMLTEXTI_HXX
#include "xmltexti.hxx"
#endif

using namespace ::rtl;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::text;

#ifdef XML_CORE_API
enum SwXMLTextPElemTokens
{
    XML_TOK_SW_SPAN,
    XML_TOK_SW_TAB_STOP,
    XML_TOK_SW_LINE_BREAK,
    XML_TOK_SW_S,
    XML_TOK_SW_P_ELEM_END=XML_TOK_UNKNOWN
};

static __FAR_DATA SvXMLTokenMapEntry aTextPElemTokenMap[] =
{
    { XML_NAMESPACE_TEXT, sXML_span, XML_TOK_SW_SPAN },
    { XML_NAMESPACE_TEXT, sXML_tab_stop, XML_TOK_SW_TAB_STOP },
    { XML_NAMESPACE_TEXT, sXML_line_break, XML_TOK_SW_LINE_BREAK },
    { XML_NAMESPACE_TEXT, sXML_s, XML_TOK_SW_S },
    XML_TOKEN_MAP_END
};

const SvXMLTokenMap& SwXMLImport::GetTextPElemTokenMap()
{
    if( !pTextPElemTokenMap )
        pTextPElemTokenMap = new SvXMLTokenMap( aTextPElemTokenMap );

    return *pTextPElemTokenMap;
}

// ---------------------------------------------------------------------

class SwXMLHint_Impl
{
    SfxItemSet aItemSet;
    xub_StrLen nStart;
    xub_StrLen nEnd;

public:

    SwXMLHint_Impl( SfxItemPool& rPool, xub_StrLen nPos ) :
        aItemSet( rPool, RES_CHRATR_BEGIN,      RES_CHRATR_END - 1,
                            RES_TXTATR_BEGIN,       RES_TXTATR_END - 1,
                         RES_UNKNOWNATR_BEGIN,  RES_UNKNOWNATR_END - 1,  0 ),
        nStart( nPos ),
        nEnd( nPos )
    {}

    SfxItemSet& GetItemSet() { return aItemSet; }
    xub_StrLen GetStart() const { return nStart; }
    xub_StrLen GetEnd() const { return nEnd; }
    void SetEnd( xub_StrLen nPos ) { nEnd = nPos; }
};

typedef SwXMLHint_Impl *SwXMLHint_ImplPtr;
SV_DECL_PTRARR_DEL( SwXMLHints_Impl, SwXMLHint_ImplPtr, 5, 5 )
SV_IMPL_PTRARR( SwXMLHints_Impl, SwXMLHint_ImplPtr )

// ---------------------------------------------------------------------

class SwXMLImpCharContext_Impl : public SvXMLImportContext
{
public:

    SwXMLImpCharContext_Impl(
            SwXMLImport& rImport, sal_uInt16 nPrfx,
            const OUString& rLName,
            const Reference< xml::sax::XAttributeList > & xAttrList,
            sal_Unicode c,
            sal_Bool bCount );

    virtual ~SwXMLImpCharContext_Impl();

    SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
};

SwXMLImpCharContext_Impl::SwXMLImpCharContext_Impl(
        SwXMLImport& rImport,
        sal_uInt16 nPrfx,
        const OUString& rLName,
        const Reference< xml::sax::XAttributeList > & xAttrList,
        sal_Unicode c,
        sal_Bool bCount ) :
    SvXMLImportContext( rImport, nPrfx, rLName )
{
    sal_uInt16 nCount = 1;

    if( bCount )
    {
        sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
        for( sal_Int16 i=0; i < nAttrCount; i++ )
        {
            const OUString& rAttrName = xAttrList->getNameByIndex( i );

            OUString aLocalName;
            sal_uInt16 nPrefix =
                GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
                                                                &aLocalName );
            if( XML_NAMESPACE_TEXT == nPrefix &&
                aLocalName.compareToAscii( sXML_c ) == 0 )
            {
                sal_Int32 nTmp = xAttrList->getValueByIndex(i).toInt32();
                if( nTmp > 0L )
                {
                    if( nTmp > USHRT_MAX )
                        nCount = USHRT_MAX;
                    else
                        nCount = (sal_uInt16)nTmp;
                }
            }
        }
    }

    if( 1U == nCount )
    {
        GetSwImport().GetDoc().Insert( GetSwImport().GetPaM(), c );
    }
    else
    {
        OUStringBuffer sBuff( nCount );
        while( nCount-- )
            sBuff.append( c );

        GetSwImport().GetDoc().Insert( GetSwImport().GetPaM(),
                                       sBuff.makeStringAndClear() );
    }
}

SwXMLImpCharContext_Impl::~SwXMLImpCharContext_Impl()
{
}

// ---------------------------------------------------------------------

class SwXMLImpSpanContext_Impl : public SvXMLImportContext
{
    SwXMLHints_Impl&    rHints;
    SwXMLHint_Impl      *pHint;

    sal_Bool&           rIgnoreLeadingSpace;

public:

    SwXMLImpSpanContext_Impl(
            SwXMLImport& rImport, sal_uInt16 nPrfx,
            const OUString& rLName,
            const Reference< xml::sax::XAttributeList > & xAttrList,
            SwXMLHints_Impl& rHnts,
            sal_Bool& rIgnLeadSpace );

    virtual ~SwXMLImpSpanContext_Impl();

    virtual SvXMLImportContext *CreateChildContext(
            sal_uInt16 nPrefix, const OUString& rLocalName,
            const Reference< xml::sax::XAttributeList > & xAttrList );

    virtual void Characters( const OUString& rChars );

    SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
};

SwXMLImpSpanContext_Impl::SwXMLImpSpanContext_Impl(
        SwXMLImport& rImport,
        sal_uInt16 nPrfx,
        const OUString& rLName,
        const Reference< xml::sax::XAttributeList > & xAttrList,
        SwXMLHints_Impl& rHnts,
        sal_Bool& rIgnLeadSpace ) :
    SvXMLImportContext( rImport, nPrfx, rLName ),
    rHints( rHnts ),
    rIgnoreLeadingSpace( rIgnLeadSpace ),
    pHint( 0  )
{
    OUString aStyleName;

    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
    for( sal_Int16 i=0; i < nAttrCount; i++ )
    {
        const OUString& rAttrName = xAttrList->getNameByIndex( i );

        OUString aLocalName;
        sal_uInt16 nPrefix =
            GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
                                                            &aLocalName );
        if( XML_NAMESPACE_TEXT == nPrefix &&
            aLocalName.compareToAscii( sXML_style_name ) == 0 )
            aStyleName = xAttrList->getValueByIndex( i );
    }

    if( aStyleName.getLength() )
    {
        SwDoc& rDoc = GetSwImport().GetDoc();

        // try to find a matching automatic style
        const SfxItemSet *pAutoItemSet = 0;
        OUString sParentStyle;
        if( GetSwImport().FindAutomaticStyle( SFX_STYLE_FAMILY_CHAR,
                                              aStyleName, &pAutoItemSet,
                                              &sParentStyle ) )
        {
            aStyleName = sParentStyle;
        }

        // if an automatic style has not been found or has been found and
        // has a parent style, try to find this one.
        SwCharFmt *pCharFmt = 0;
        if( aStyleName.getLength() )
        {
            const SvI18NMap& rI18NMap = GetSwImport().GetI18NMap();
            String sName( rI18NMap.Get( SFX_STYLE_FAMILY_CHAR,
                                             aStyleName) );
            pCharFmt = rDoc.FindCharFmtByName( sName );
        }

        if( pAutoItemSet || pCharFmt )
        {
            xub_StrLen nPos =
                GetSwImport().GetPaM().GetPoint()->nContent.GetIndex();
            pHint = new SwXMLHint_Impl( rDoc.GetAttrPool(), nPos );
            rHints.Insert( pHint, rHints.Count() );
            if( pAutoItemSet )
                pHint->GetItemSet().Put( *pAutoItemSet );
            if( pCharFmt )
            {
                SwFmtCharFmt aCharFmt( pCharFmt );
                pHint->GetItemSet().Put( aCharFmt );
            }
        }
    }
}

SwXMLImpSpanContext_Impl::~SwXMLImpSpanContext_Impl()
{
    if( pHint )
    {
        xub_StrLen nPos =
            GetSwImport().GetPaM().GetPoint()->nContent.GetIndex();
        pHint->SetEnd( nPos );
    }
}

SvXMLImportContext *SwXMLImpSpanContext_Impl::CreateChildContext(
        sal_uInt16 nPrefix, const OUString& rLocalName,
        const Reference< xml::sax::XAttributeList > & xAttrList )
{
    SvXMLImportContext *pContext = 0;

    const SvXMLTokenMap& rTokenMap = GetSwImport().GetTextPElemTokenMap();
    switch( rTokenMap.Get( nPrefix, rLocalName ) )
    {
    case XML_TOK_SW_SPAN:
        pContext = new SwXMLImpSpanContext_Impl( GetSwImport(), nPrefix,
                                                 rLocalName, xAttrList,
                                                 rHints,
                                                 rIgnoreLeadingSpace );
        break;

    case XML_TOK_SW_TAB_STOP:
        pContext = new SwXMLImpCharContext_Impl( GetSwImport(), nPrefix,
                                                 rLocalName, xAttrList,
                                                 0x0009, sal_False );
        rIgnoreLeadingSpace = sal_False;
        break;

    case XML_TOK_SW_LINE_BREAK:
        pContext = new SwXMLImpCharContext_Impl( GetSwImport(), nPrefix,
                                                 rLocalName, xAttrList,
                                                 0x000A, sal_False );
        rIgnoreLeadingSpace = sal_False;
        break;

    case XML_TOK_SW_S:
        pContext = new SwXMLImpCharContext_Impl( GetSwImport(), nPrefix,
                                                 rLocalName, xAttrList,
                                                 0x0020, sal_True );
        break;

    default:
        // ignore unknown content
        pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
        break;
    }

    return pContext;
}

void SwXMLImpSpanContext_Impl::Characters( const OUString& rChars )
{
    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;
        }
    }

    GetSwImport().GetDoc().Insert( GetSwImport().GetPaM(),
                                   sChars.makeStringAndClear() );
}

// ---------------------------------------------------------------------

enum SwXMLTextPAttrTokens
{
    XML_TOK_SW_P_STYLE_NAME,
    XML_TOK_SW_P_COND_STYLE_NAME,
    XML_TOK_SW_P_LEVEL,
    XML_TOK_SW_P_END=XML_TOK_UNKNOWN
};

static __FAR_DATA SvXMLTokenMapEntry aTextPAttrTokenMap[] =
{
    { XML_NAMESPACE_TEXT, sXML_style_name,  XML_TOK_SW_P_STYLE_NAME },
    { XML_NAMESPACE_TEXT, sXML_cond_style_name,
                                            XML_TOK_SW_P_COND_STYLE_NAME },
    { XML_NAMESPACE_TEXT, sXML_level,       XML_TOK_SW_P_LEVEL },
    XML_TOKEN_MAP_END
};

SwXMLParaContext::SwXMLParaContext(
        SwXMLImport& rImport,
        sal_uInt16 nPrfx,
        const OUString& rLName,
        const Reference< xml::sax::XAttributeList > & xAttrList,
        sal_Bool bHead ) :
    SvXMLImportContext( rImport, nPrfx, rLName ),
    pItemSet( 0 ),
    pHints( 0 ),
    bIgnoreLeadingSpace( sal_True ),
    bHeading( bHead )
{
    const SvXMLTokenMap& rTokenMap = GetSwImport().GetTextPAttrTokenMap();

    OUString aStyleName, aCondStyleName;
    sal_uInt8 nOutlineLevel = NO_NUMBERING;

    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
    for( sal_Int16 i=0; i < nAttrCount; i++ )
    {
        const OUString& rAttrName = xAttrList->getNameByIndex( i );
        const OUString& rValue = xAttrList->getValueByIndex( i );

        OUString aLocalName;
        sal_uInt16 nPrefix =
            GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
                                                            &aLocalName );
        switch( rTokenMap.Get( nPrefix, aLocalName ) )
        {
        case XML_TOK_SW_P_STYLE_NAME:
            aStyleName = rValue;
            break;
        case XML_TOK_SW_P_COND_STYLE_NAME:
            aCondStyleName = rValue;
            break;
        case XML_TOK_SW_P_LEVEL:
            {
                sal_Int32 nTmp = rValue.toInt32() - 1L;
                if( nTmp >= 0L )
                {
                    if( nTmp > MAXLEVEL )
                        nTmp = MAXLEVEL;
                    nOutlineLevel = (sal_uInt8)nTmp;
                }
            }

        }
    }

    if( aCondStyleName.getLength() )
    {
        OUString sTmp( aStyleName );
        aStyleName = aCondStyleName;
        aCondStyleName = sTmp;
    }

    if( aStyleName.getLength() )
    {
        const SfxItemSet *pAutoItemSet = 0;
        OUString sParentStyle;
        if( GetSwImport().FindAutomaticStyle( SFX_STYLE_FAMILY_PARA,
                                              aStyleName, &pAutoItemSet,
                                                 &sParentStyle ) )
        {
            aStyleName = sParentStyle;
        }

        if( pAutoItemSet )
        {
            if( !pItemSet )
                pItemSet = new SfxItemSet( GetSwImport().GetDoc().GetAttrPool(),
                                           aTxtNodeSetRange );
            pItemSet->Put( *pAutoItemSet );
        }

        if( aStyleName.getLength() )
        {
            const SvI18NMap& rI18NMap = GetSwImport().GetI18NMap();
            String sName( rI18NMap.Get( SFX_STYLE_FAMILY_PARA, aStyleName ) );
            SwDoc& rDoc = GetSwImport().GetDoc();
            SwTxtFmtColl *pColl = rDoc.FindTxtFmtCollByName( sName );
            if( pColl )
            {
                sal_uInt8 nCollOutlineLevel = pColl->GetOutlineLevel();
                if( bHeading && !( GetSwImport().IsInsertMode() ||
                                      GetSwImport().IsStylesOnlyMode() ) &&
                    NO_NUMBERING != nOutlineLevel &&
                    ( NO_NUMBERING == nCollOutlineLevel ||
                      GetRealLevel(nCollOutlineLevel) != nOutlineLevel ) )
                {
                    sal_uInt16 nArrLen = rDoc.GetTxtFmtColls()->Count();
                    for( sal_uInt16 i=0; i<nArrLen; i++ )
                    {
                        SwTxtFmtColl* pCur = (*rDoc.GetTxtFmtColls())[i];
                        sal_uInt8 nCurLevel = pCur->GetOutlineLevel();
                        if( nCurLevel != NO_NUMBERING &&
                            GetRealLevel(nCurLevel) == nOutlineLevel )
                        {
                            if( pColl != pCur )
                                pCur->SetOutlineLevel( NO_NUMBERING );
                            break;
                        }
                    }
                    pColl->SetOutlineLevel( nOutlineLevel );
                }
                rDoc.SetTxtFmtColl( GetSwImport().GetPaM(), pColl );
            }
        }
    }
}

SwXMLParaContext::~SwXMLParaContext()
{
#ifndef PRODUCT
    SwCntntNode *pTTTNd = GetSwImport().GetPaM().GetNode()->GetCntntNode();
#endif

    // Start a new node.
    SwDoc& rDoc = GetSwImport().GetDoc();
    rDoc.AppendTxtNode( *GetSwImport().GetPaM().GetPoint() );

    // Create a "attribute" PaM and move it to the previous node.
    SwPaM aPaM( GetSwImport().GetPaM() );
    aPaM.Move( fnMoveBackward, fnGoCntnt );
    aPaM.SetMark();
    SwCntntNode *pCNd = aPaM.GetNode()->GetCntntNode();
    ASSERT( pCNd,
       "SwXMLParaContext::~SwXMLParaContext: no content node" );
#ifndef PRODUCT
    ASSERT( pTTTNd == pCNd,
       "SwXMLParaContext::~SwXMLParaContext: wrong content node" );
    ASSERT( (const SwIndexReg*)pTTTNd == aPaM.GetPoint()->nContent.GetIdxReg(),
       "SwXMLParaContext::~SwXMLParaContext: wrong content node" );
#endif

    aPaM.GetPoint()->nContent.Assign( pCNd, 0 );

    // Set paragraph attributes.
    if( pItemSet )
        rDoc.Insert( aPaM, *pItemSet );
    delete pItemSet;

    // Set numbering rules
    SwTxtNode *pTxtNd = pCNd->GetTxtNode();
    const SwNumRule *pNumRule = pTxtNd->GetNumRule();
    if( GetSwImport().IsInList() )
    {
        SwXMLListBlockContext *pListBlock = GetSwImport().GetListBlock();
        String sStyleName( GetSwImport().GetI18NMap().Get(
                        SFX_STYLE_FAMILY_PSEUDO,pListBlock->GetStyleName()) );
        if( !pNumRule ||
            ( !pListBlock->HasGeneratedStyle() &&
              pNumRule->GetName() != sStyleName ) )
        {
            rDoc.Insert( aPaM, SwNumRuleItem( sStyleName ) );
            pNumRule = pTxtNd->GetNumRule();
        }

        ASSERT( pNumRule, "SwXMLParaContext::~SwXMLParaContext: no num rule" );
        GetSwImport().SetUsed( *pNumRule );

        SwXMLListItemContext *pListItem = GetSwImport().GetListItem();

        sal_uInt8 nLevel = pListBlock->GetLevel() > MAXLEVEL
                            ? MAXLEVEL
                            : (sal_uInt8)pListBlock->GetLevel();
        if( !pListItem )
            nLevel |= NO_NUMLEVEL;

        SwNodeNum aNodeNum( nLevel );
        if( pListBlock->IsRestartNumbering() )
        {
            aNodeNum.SetStart();
            pListBlock->ResetRestartNumbering();
        }
        if( pListItem && pListItem->HasStartValue() )
        {
            aNodeNum.SetSetValue( pListItem->GetStartValue() );
        }

        pTxtNd->UpdateNum( aNodeNum );

        GetSwImport().SetListItem( 0 );
    }
    else
    {
        // If the paragraph is not in a list but its style, remove it from
        // the list.
        if( pNumRule )
            rDoc.Insert( aPaM, SwNumRuleItem() );
    }

    if( pHints && pHints->Count() )
    {
        for( sal_uInt16 i=0; i<pHints->Count(); i++ )
        {
            SwXMLHint_Impl *pHint = (*pHints)[i];
            xub_StrLen nStt = pHint->GetStart();
            xub_StrLen nEnd = pHint->GetEnd();
            if( nStt != nEnd )
            {
                aPaM.GetPoint()->nContent.Assign( pCNd, nEnd );
                aPaM.SetMark();
                aPaM.GetPoint()->nContent.Assign( pCNd, nStt );
                rDoc.Insert( aPaM, pHint->GetItemSet() );
            }
        }
    }
    delete pHints;
}

SvXMLImportContext *SwXMLParaContext::CreateChildContext(
        sal_uInt16 nPrefix, const OUString& rLocalName,
        const Reference< xml::sax::XAttributeList > & xAttrList )
{
    SvXMLImportContext *pContext = 0;

    const SvXMLTokenMap& rTokenMap = GetSwImport().GetTextPElemTokenMap();
    switch( rTokenMap.Get( nPrefix, rLocalName ) )
    {
    case XML_TOK_SW_SPAN:
        if( !pHints )
            pHints = new SwXMLHints_Impl;
        pContext = new SwXMLImpSpanContext_Impl( GetSwImport(), nPrefix,
                                                 rLocalName, xAttrList,
                                                 *pHints, bIgnoreLeadingSpace );
        break;

    case XML_TOK_SW_TAB_STOP:
        pContext = new SwXMLImpCharContext_Impl( GetSwImport(), nPrefix,
                                                 rLocalName, xAttrList,
                                                 0x0009, sal_False );
        bIgnoreLeadingSpace = sal_False;
        break;

    case XML_TOK_SW_LINE_BREAK:
        pContext = new SwXMLImpCharContext_Impl( GetSwImport(), nPrefix,
                                                 rLocalName, xAttrList,
                                                 0x000A, sal_False );
        bIgnoreLeadingSpace = sal_False;
        break;

    case XML_TOK_SW_S:
        pContext = new SwXMLImpCharContext_Impl( GetSwImport(), nPrefix,
                                                 rLocalName, xAttrList,
                                                 0x0020, sal_True );
        break;

    default:
        // ignore unknown content
        pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
        break;
    }

    return pContext;
}

void SwXMLParaContext::Characters( const OUString& rChars )
{
    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( !bIgnoreLeadingSpace )
                    sChars.append( (sal_Unicode)0x20 );
                bIgnoreLeadingSpace = sal_True;
                break;
            default:
                bIgnoreLeadingSpace = sal_False;
                sChars.append( c );
                break;
        }
    }

    GetSwImport().GetDoc().Insert( GetSwImport().GetPaM(),
                                   sChars.makeStringAndClear() );
}

const SvXMLTokenMap& SwXMLImport::GetTextPAttrTokenMap()
{
    if( !pTextPAttrTokenMap )
        pTextPAttrTokenMap = new SvXMLTokenMap( aTextPAttrTokenMap );

    return *pTextPAttrTokenMap;
}
#endif

// ---------------------------------------------------------------------

#ifdef XML_CORE_API
static __FAR_DATA SvXMLTokenMapEntry aBodyElemTokenMap[] =
{
    { XML_NAMESPACE_TEXT, sXML_p,               XML_TOK_SW_P                },
    { XML_NAMESPACE_TEXT, sXML_h,               XML_TOK_SW_H                },
    { XML_NAMESPACE_TEXT, sXML_ordered_list,    XML_TOK_SW_ORDERED_LIST },
    { XML_NAMESPACE_TEXT, sXML_unordered_list,  XML_TOK_SW_UNORDERED_LIST },
    { XML_NAMESPACE_TABLE,sXML_table,           XML_TOK_TABLE_TABLE         },
    { XML_NAMESPACE_TABLE,sXML_sub_table,       XML_TOK_TABLE_SUBTABLE      },
    XML_TOKEN_MAP_END
};
#endif

class SwXMLBodyContext_Impl : public SvXMLImportContext
{
#ifdef XML_CORE_API
    const SwXMLImport& GetSwImport() const
            { return (const SwXMLImport&)GetImport(); }
#endif
    SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }

public:

    SwXMLBodyContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
                             const OUString& rLName );
    virtual ~SwXMLBodyContext_Impl();

    virtual SvXMLImportContext *CreateChildContext(
            sal_uInt16 nPrefix, const OUString& rLocalName,
            const Reference< xml::sax::XAttributeList > & xAttrList );

    virtual void EndElement();
};

SwXMLBodyContext_Impl::SwXMLBodyContext_Impl( SwXMLImport& rImport,
                                              sal_uInt16 nPrfx,
                                                   const OUString& rLName ) :
    SvXMLImportContext( rImport, nPrfx, rLName )
{
}

SwXMLBodyContext_Impl::~SwXMLBodyContext_Impl()
{
}

SvXMLImportContext *SwXMLBodyContext_Impl::CreateChildContext(
        sal_uInt16 nPrefix, const OUString& rLocalName,
        const Reference< xml::sax::XAttributeList > & xAttrList )
{
    SvXMLImportContext *pContext = 0;

#ifndef XML_CORE_API
    pContext = GetSwImport().GetTextImport()->CreateTextChildContext(
            GetImport(), nPrefix, rLocalName, xAttrList,
               XML_TEXT_TYPE_BODY );
#else
    const SvXMLTokenMap& rTokenMap = GetSwImport().GetBodyElemTokenMap();
    sal_Bool bOrdered = sal_False;
    sal_Bool bHeading = sal_False;

    switch( rTokenMap.Get( nPrefix, rLocalName ) )
    {
    case XML_TOK_SW_H:
        bHeading = sal_True;
    case XML_TOK_SW_P:
        pContext = new SwXMLParaContext( GetSwImport(),nPrefix, rLocalName,
                                         xAttrList, bHeading );
        break;
    case XML_TOK_SW_ORDERED_LIST:
        bOrdered = sal_True;
    case XML_TOK_SW_UNORDERED_LIST:
        pContext = new SwXMLListBlockContext( GetSwImport(),nPrefix, rLocalName,
                                              xAttrList, bOrdered );
        break;
    case XML_TOK_TABLE_TABLE:
        if( !GetSwImport().GetPaM().GetNode()->FindTableNode() )
            pContext = new SwXMLTableContext( GetSwImport(),nPrefix, rLocalName,
                                              xAttrList );
        break;
    }
#endif

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

    return pContext;
}

void SwXMLBodyContext_Impl::EndElement()
{
    GetImport().GetTextImport()->SetOutlineStyles();
}

#ifdef XML_CORE_API
const SvXMLTokenMap& SwXMLImport::GetBodyElemTokenMap()
{
    if( !pBodyElemTokenMap )
        pBodyElemTokenMap = new SvXMLTokenMap( aBodyElemTokenMap );

    return *pBodyElemTokenMap;
}
#endif

SvXMLImportContext *SwXMLImport::CreateBodyContext(
                                       const OUString& rLocalName )
{
    SvXMLImportContext *pContext = 0;

    if( !IsStylesOnlyMode() )
         pContext = new SwXMLBodyContext_Impl( *this, XML_NAMESPACE_OFFICE,
                                              rLocalName );
    else
        pContext = new SvXMLImportContext( *this, XML_NAMESPACE_OFFICE,
                                           rLocalName );

    return pContext;
}

// ---------------------------------------------------------------------

#ifdef XML_CORE_API
class SwXMLHintEndPosList : public SwHintEndPosList
{
    OUString sQSpan;
    SwXMLExport& rExport;

public:

    SwXMLHintEndPosList( SwXMLExport& rExp );
    ~SwXMLHintEndPosList();

    void Insert( const SfxPoolItem& rItem, xub_StrLen nStart, xub_StrLen nEnd );

    sal_Bool HasStartingOrEndingHints( xub_StrLen nPos );

    sal_Bool ExportStartingHints( xub_StrLen nPos );
    sal_Bool ExportEndingHints( xub_StrLen nPos );
};

SwXMLHintEndPosList::SwXMLHintEndPosList( SwXMLExport& rExp ) :
    rExport( rExp )
{
    OUString sLName( OUString::createFromAscii( sXML_span ) );
    sQSpan = rExp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TEXT, sLName );
}

SwXMLHintEndPosList::~SwXMLHintEndPosList()
{
}

void SwXMLHintEndPosList::Insert( const SfxPoolItem& rItem,
                                  xub_StrLen nStart, xub_StrLen nEnd )
{
    // empty hints will be ignored
    if( nStart != nEnd )
    {
        InsertHint( rItem, nStart, nEnd );
    }
}

sal_Bool SwXMLHintEndPosList::ExportStartingHints( xub_StrLen nPos )
{
    sal_Bool bRet = sal_False;

    // Hints in the start list are sorted ascending.

    sal_uInt16 nCount = GetStartingCount();
    for( sal_uInt16 i=0; i< nCount; i++ )
    {
        SwHintSttEndPos *pPos = GetStartingHint( i );
        xub_StrLen nStart = pPos->GetStart();
        if( nStart > nPos )
        {
            // This and all following hint will be started later
            break;
        }
        else if( nStart == nPos )
        {
            // export hint's start
//          if( bIWSOutside )
//              rExport.GetDocHandler()->ignorableWhitespace( rExport.sWS );
            const SfxPoolItem& rItem = pPos->GetItem();
            if( (rItem.Which() >= RES_CHRATR_BEGIN &&
                                        rItem.Which() < RES_CHRATR_END) ||
                (rItem.Which() >= RES_UNKNOWNATR_BEGIN &&
                                        rItem.Which() < RES_UNKNOWNATR_END) )
            {
                SfxItemSet aItemSet( rExport.GetDoc().GetAttrPool(),
                                 RES_CHRATR_BEGIN,      RES_CHRATR_END - 1,
                                 RES_UNKNOWNATR_BEGIN,  RES_UNKNOWNATR_END - 1,
                                 0 );
                aItemSet.Put( rItem );
                OUString sName( rExport.GetItemSetAutoStylePool().Find(
                                    SFX_STYLE_FAMILY_CHAR, aItemSet ) );
                ASSERT( sName.getLength(), "no automatic style found" );
                if( sName.getLength() )
                    rExport.AddAttribute( XML_NAMESPACE_TEXT, sXML_style_name,
                                          sName );
            }
            else
            {
                rExport.GetParaItemMapper().exportXML(
                            rExport.GetAttrList(), rItem,
                            rExport.GetTwipUnitConverter(),
                            rExport.GetNamespaceMap() );
            }

            rExport.GetDocHandler()->startElement( sQSpan,
                                                   rExport.GetXAttrList() );
            rExport.ClearAttrList();

            bRet = sal_True;
        }
    }

    return bRet;
}

sal_Bool SwXMLHintEndPosList::ExportEndingHints( xub_StrLen nPos )
{
    sal_Bool bRet = sal_False;

    // Hints in the end list are sorted ascending
    sal_uInt16 i=0;
    while( i < GetEndingCount() )
    {
        SwHintSttEndPos *pPos = GetEndingHint( i );
        xub_StrLen nEnd = pPos->GetEnd();

        if( STRING_LEN==nPos || nEnd == nPos )
        {
//          if( bIgnWS )
//              rExport.GetDocHandler()->ignorableWhitespace( rExport.sWS );
            rExport.GetDocHandler()->endElement( sQSpan );
            _RemoveHint( i );

            bRet = sal_True;
        }
        else if( nEnd > nPos )
        {
            // This and all hints that are following will be closed later
            break;
        }
        else
        {
            // This hint should have been exported already!
            ASSERT( nEnd >= nPos,
                    "SwXMLHintEndPosLst::OutEndAttrs: hint overseen" );
            i++;
        }
    }

    return bRet;
}

sal_Bool SwXMLHintEndPosList::HasStartingOrEndingHints( xub_StrLen nPos )
{
    sal_Bool bRet = sal_False;

    // Hints in the start list are sorted ascending.

    sal_uInt16 nCount = GetStartingCount();
    for( sal_uInt16 i=0; i< nCount; i++ )
    {
        SwHintSttEndPos *pPos = GetStartingHint( i );
        xub_StrLen nStart = pPos->GetStart();
        if( nStart == nPos )
        {
            bRet = sal_True;
            break;
        }
        else if( nStart > nPos )
        {
            // This and all following hint will be started later
            break;
        }
    }

    if( !bRet )
    {
        nCount = GetEndingCount();
        for( i=0; i < nCount; i++ )
        {
            SwHintSttEndPos *pPos = GetEndingHint( i );
            xub_StrLen nEnd = pPos->GetEnd();

            if( nEnd == nPos )
            {
                bRet = sal_True;
                break;
            }
            else if( nEnd > nPos )
            {
                // This and all hints that are following will be closed later
                break;
            }
        }
    }

    return bRet;
}

void SwXMLExport::ExportTxtNode( const SwTxtNode& rTxtNd, xub_StrLen nStart,
                                 xub_StrLen nEnd, sal_Bool bExportWholeNode )
{
    // <text:p ...>
    CheckAttrList();

    const SfxItemSet *pItemSet = rTxtNd.GetpSwAttrSet();

    // text:style-name="..."
    // If the text collection is a conditional style, the current style
    // is written as style-name rather than the master style.
    const SwFmtColl& rColl = rTxtNd.GetAnyFmtColl();
    OUString sStyleName( rColl.GetName() );
    if( pItemSet )
        sStyleName = FindParaAutoStyle( sStyleName, *pItemSet );
    else
        sStyleName = SwXStyleFamilies::GetProgrammaticName( sStyleName,
                                                    SFX_STYLE_FAMILY_PARA );
    ASSERT( sStyleName.getLength(), "auto para style not found" );
    AddAttribute( XML_NAMESPACE_TEXT, sXML_style_name, sStyleName );

    sal_uInt8 nOutlineLevel = ((const SwTxtFmtColl&)rColl).GetOutlineLevel();

    // text:cond-style-name="..."
    if( rTxtNd.GetCondFmtColl() )
    {
        // master style
        const SwFmtColl *pColl = rTxtNd.GetFmtColl();
        OUString sCondStyleName;
        if( &rColl == pColl )
        {
            sCondStyleName = sStyleName;
        }
        else
        {
            sCondStyleName = pColl->GetName();
            if( pItemSet )
                sCondStyleName = FindParaAutoStyle( sCondStyleName, *pItemSet );
            else
                sCondStyleName = SwXStyleFamilies::GetProgrammaticName(
                                                    sCondStyleName,
                                                    SFX_STYLE_FAMILY_PARA );
            ASSERT( sCondStyleName.getLength(), "auto para style not found" );
            nOutlineLevel = ((const SwTxtFmtColl *)pColl)->GetOutlineLevel();
        }
        AddAttribute( XML_NAMESPACE_TEXT, sXML_cond_style_name,
                      sCondStyleName );
    }

    if( NO_NUMBERING != nOutlineLevel )
    {
        OUStringBuffer sTmp;
        sTmp.append( GetRealLevel(nOutlineLevel)+1L );
        AddAttribute( XML_NAMESPACE_TEXT, sXML_level,
                      sTmp.makeStringAndClear() );
    }

    {
        const sal_Char *pElem =
            NO_NUMBERING == nOutlineLevel ? sXML_p : sXML_h;
        SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT, pElem, sal_True,
                                  sal_False );
        xub_StrLen nOffset = 0;

        const String& rText = rTxtNd.GetTxt();
        xub_StrLen nPos = pCurPaM->GetPoint()->nContent.GetIndex();
        xub_StrLen nEndPos = rText.Len();
        if( pCurPaM->GetPoint()->nNode == pCurPaM->GetMark()->nNode )
            nEndPos = pCurPaM->GetMark()->nContent.GetIndex();

        const SwpHints *pHints = rTxtNd.GetpSwpHints();
        sal_uInt16 nHintCount = pHints ? pHints->Count() : 0;
        sal_uInt16 nHintPos = 0;
        SwXMLHintEndPosList aHintLst( *this );

        // export all hints before the current text position
        const SwTxtAttr * pTxtAttr = 0;
        if( nHintCount && nPos > *( pTxtAttr = (*pHints)[0] )->GetStart() )
        {
            do
            {
                nHintPos++;

                if( pTxtAttr->GetEnd() )
                {
                    DBG_ASSERT( RES_TXTATR_FIELD == pTxtAttr->Which(),
                                "ignore fields" );
                    xub_StrLen nHtEnd = *pTxtAttr->GetEnd(),
                           nHtStt = *pTxtAttr->GetStart();
                    if( (!bExportWholeNode && nHtEnd <= nPos) ||
                         nHtEnd == nHtStt )
                        continue;

                    // add hint to hint list
                    if( bExportWholeNode )
                    {
                        aHintLst.Insert( pTxtAttr->GetAttr(), nHtStt + nOffset,
                                         nHtEnd + nOffset );
                    }
                    else
                    {
                        xub_StrLen nTmpStt = nHtStt < nPos ? nPos : nHtStt;
                        xub_StrLen nTmpEnd = nHtEnd < nEndPos ? nHtEnd : nEndPos;
                        aHintLst.Insert( pTxtAttr->GetAttr(), nTmpStt + nOffset,
                                            nTmpEnd + nOffset );
                    }
                }

            }
            while( nHintPos < nHintCount &&
                   nPos > *( pTxtAttr = (*pHints)[nHintPos ] )->GetStart() );
        }

        xub_StrLen nExpStartPos = nPos;
        sal_Bool bCurrCharIsSpace = sal_False;
        xub_StrLen nSpaceChars = 0;
        for( ; nPos < nEndPos; nPos++ )
        {
            sal_Bool bExpCharAsText = sal_True;
            const SwTxtAttr * pTxtAttrWOEnd = 0;
            if( nHintPos < nHintCount && *pTxtAttr->GetStart() == nPos
                && nPos != nEndPos )
            {
                do
                {
                    if( pTxtAttr->GetEnd() )
                    {
                        if( *pTxtAttr->GetEnd() != nPos )
                        {
                            // insert hint into the hint list if its not
                            // empty
                            aHintLst.Insert( pTxtAttr->GetAttr(),
                                             nPos + nOffset,
                                                *pTxtAttr->GetEnd() + nOffset );
                        }
                    }
                    else
                    {
                        // hints without end must be exported after all
                        // other hints that start at this position
                        ASSERT( !pTxtAttrWOEnd,
                        "SwXMLExport::ExportTxtNode: There is a hint already" );
                        pTxtAttrWOEnd = pTxtAttr;
                        bExpCharAsText = sal_False;     // ignore 0xff
                    }
                }
                while( ++nHintPos < nHintCount &&
                      nPos == *( pTxtAttr = (*pHints)[nHintPos] )->GetStart() );
            }

            // Some characters require some extra work ...
            sal_Bool bExpCharAsElement = sal_False;
            sal_Bool bPrevCharIsSpace = bCurrCharIsSpace;
            bCurrCharIsSpace = sal_False;
            if( bExpCharAsText )
            {
                switch( rText.GetChar(nPos) )
                {
                case 0x0009:    // Tab
                case 0x000A:    // LF
                    // These characters are exported as text.
                    bExpCharAsElement = sal_True;
                    bExpCharAsText = sal_False;
                    break;
                case 0x0020:    // Blank
                    if( bPrevCharIsSpace )
                    {
                        // If the previous character is a space character,
                        // too, export a special space element.
                        bExpCharAsText = sal_False;
                    }
                    bCurrCharIsSpace = sal_True;
                    break;
                }
            }

            // If the current character is not exported as text or if there
            // are hints starting or ending before the current position,
            // the text that has not been exported by now has to be exported
            // now.
            if( nPos > nExpStartPos &&
                ( !bExpCharAsText ||
                  aHintLst.HasStartingOrEndingHints( nPos+nOffset ) ) )
            {
                ASSERT( 0==nSpaceChars,
                        "SwXMLExport::ExportTxtNode: pending spaces" );
                String sExp( rText.Copy( nExpStartPos,
                                         nPos - nExpStartPos ) );
                GetDocHandler()->characters( sExp );
                nExpStartPos = nPos;
            }

            // If there are spaces left that have not been exported and the
            // current chracter is either not a space or there are some
            // hints starting or ending, the pending spaces have to be
            // exported now.
            if( nSpaceChars > 0 &&
                ( !bCurrCharIsSpace ||
                  aHintLst.HasStartingOrEndingHints( nPos+nOffset ) ) )
            {
                ASSERT( nExpStartPos == nPos,
                        "SwXMLExport::ExportTxtNode: pending characters" );

                if( nSpaceChars > 1 )
                {
                    OUStringBuffer sTmp;
                    sTmp.append( (sal_Int32)nSpaceChars );
                    AddAttribute( XML_NAMESPACE_TEXT, sXML_c,
                                  sTmp.makeStringAndClear() );
                }

                SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT,
                                        sXML_s, sal_False, sal_False );

                nSpaceChars = 0;
            }

            // Before the text or tag of the current element, ending and
            // starting hints have to be exported.
            aHintLst.ExportEndingHints( nPos + nOffset );
            aHintLst.ExportStartingHints( nPos + nOffset );

            // If the current character has to be exported as a special
            // element, the elemnt will be exported now.
            if( bExpCharAsElement )
            {
                switch( rText.GetChar(nPos) )
                {
                case 0x0009:    // Tab
                    {
                        SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT,
                                                  sXML_tab_stop, sal_False,
                                                  sal_False );
                    }
                    break;
                case 0x000A:    // LF
                    {
                        SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT,
                                                  sXML_line_break, sal_False,
                                                  sal_False );
                    }
                    break;
                }
            }
            if( pTxtAttrWOEnd  )
            {
                // TODO: This is a hack as long as if there is no field
                // export.
                if( RES_TXTATR_FIELD == pTxtAttrWOEnd->Which() )
                {
                    const SwField *pFld =
                        ((const SwFmtFld&)pTxtAttrWOEnd->GetAttr()).GetFld();
                    if( pFld )
                    {
                        GetDocHandler()->characters( pFld->Expand() );
                    }
#ifdef XML_CORE_API
//                  Reference < XTextField > xFld = new SwXTextField(
//                      ((const SwFmtFld&)pTxtAttrWOEnd->GetAttr()),
//                      &GetDoc() );
//
//                  GetTextFieldExport().ExportField( xFld );
#endif
                }
            }

            // If the current character is a space, and the previous one
            // is a space, too, the number of pending spaces is incremented
            // only.
            if( bCurrCharIsSpace && bPrevCharIsSpace )
                nSpaceChars++;

            // If the currect character is not exported as text, the start
            // position for text is the position behind the current position.
            if( !bExpCharAsText )
            {
                ASSERT( nExpStartPos == nPos, "wrong export start pos" );
                nExpStartPos = nPos+1;
            }
        }

        // If there is some text left, it has to be exported now.
        if( nExpStartPos < nEndPos )
        {
            ASSERT( 0==nSpaceChars,
                    "SwXMLExport::ExportTxtNode: pending spaces " );
            String sExp( rText.Copy( nExpStartPos, nEndPos - nExpStartPos ) );
            GetDocHandler()->characters( sExp );
        }

        // If there are some spaces left, they have to be exported now.
        if( nSpaceChars > 0 )
        {
            if( nSpaceChars > 1 )
            {
                OUStringBuffer sTmp;
                sTmp.append( (sal_Int32)nSpaceChars );
                AddAttribute( XML_NAMESPACE_TEXT, sXML_c,
                              sTmp.makeStringAndClear() );
            }

            SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT, sXML_s,
                                      sal_False, sal_False );
        }

        // The same applies to all hints that are currently open.
        aHintLst.ExportEndingHints( STRING_LEN );
    }
}

void SwXMLExport::ExportSection( const SwSectionNode& rSectNd )
{
#if 0
    const SwSection& rSection = rSectNd.GetSection();
    const SwSectionFmt *pSectFmt = rSection.GetFmt();
    ASSERT( pSectFmt, "SwXMLExport::ExportSection: section without a format?" );

    // <text:section-desc ...>
    CheckAttrList();

    // text:name="..."
    AddAttribute( XML_NAMESPACE_TEXT, sXML_name, S2WS(rSection.GetName()) );

    // text:hidden="..."
    if( rSection.IsHidden() )
    {
        AddAttributeASCII( XML_NAMESPACE_TEXT, sXML_hidden, sXML_true );

        // text:condition="..."
        if( rSection.IsCondHidden() )
        {
            AddAttribute( XML_NAMESPACE_TEXT, sXML_condition,
                          S2WS(rSection.GetCondition()) );
        }
    }

    {
        SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT, sXML_section_desc,
                                sal_True, sal_True );
//      TODO
//      pSectionItemExport->Export( pSectFmt->GetAttrSet(), XML_ITEM_IGN_WS );
    }

    // <text:section ...>
    CheckAttrList();

    // text:name="..."
    AddAttribute( XML_NAMESPACE_TEXT, sXML_section_name,
                  S2WS(rSection.GetName()) );
#endif

    SwNode *pStartNd = pDoc->GetNodes()[rSectNd.GetIndex() + 1];
    SwNode *pEndNd = pDoc->GetNodes()[rSectNd.EndOfSectionIndex() - 1];

    {
#if 0
        SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT, sXML_section,
                                sal_True, sal_True );
#endif
        SwXMLExpContext aContext( *this, *pStartNd, *pEndNd, 0, STRING_LEN );
        ExportCurPaM();
    }

    pCurPaM->GetPoint()->nNode = *rSectNd.EndOfSectionNode();
}
#endif

/*************************************************************************

      Source Code Control System - Header

      $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/sw/source/filter/xml/xmltext.cxx,v 1.3 2000-10-18 11:20:44 mib Exp $

      Source Code Control System - Update

      $Log: not supported by cvs2svn $
      Revision 1.2  2000/09/27 06:15:11  mib
      Setting outline styles at end of body

      Revision 1.1.1.1  2000/09/18 17:15:00  hr
      initial import

      Revision 1.48  2000/09/18 16:05:08  willem.vandorp
      OpenOffice header added.

      Revision 1.47  2000/09/18 11:58:03  mib
      text frames/graphics import and export continued

      Revision 1.46  2000/08/24 11:16:42  mib
      text import continued

      Revision 1.45  2000/08/10 10:22:16  mib
      #74404#: Adeptions to new XSL/XLink working draft

      Revision 1.44  2000/08/04 11:39:54  dvo
      - field declarations import removed from CORE API import

      Revision 1.43  2000/08/03 18:03:58  dvo
      - variable field declarations import added

      Revision 1.42  2000/07/31 09:42:35  mib
      text export continued

      Revision 1.41  2000/07/24 10:19:02  dvo
      - textfield export for XML_CORE_API

      Revision 1.40  2000/07/21 12:55:15  mib
      text import/export using StarOffice API

      Revision 1.39  2000/07/11 11:17:59  dvo
      text field export added

      Revision 1.38  2000/06/08 09:45:55  aw
      changed to use functionality from xmloff project now

      Revision 1.37  2000/05/24 12:08:11  mib
      unicode bug fix

      Revision 1.36  2000/05/03 12:08:05  mib
      unicode

      Revision 1.35  2000/03/13 14:33:45  mib
      UNO3

      Revision 1.34  2000/03/06 10:46:11  mib
      #72585#: toInt32

      Revision 1.33  2000/02/21 12:51:07  mib
      #70271#: Export of section element removed

      Revision 1.32  2000/02/17 14:40:30  mib
      #70271#: XML table import

      Revision 1.30  2000/01/27 08:59:02  mib
      #70271#: outline numbering

      Revision 1.29  2000/01/20 10:03:16  mib
      #70271#: Lists reworked

      Revision 1.28  2000/01/12 15:00:23  mib
      #70271#: lists

      Revision 1.27  2000/01/06 15:08:28  mib
      #70271#:separation of text/layout, cond. styles, adaptions to wd-xlink-19991229

      Revision 1.26  1999/12/14 09:47:51  mib
      #70271#: Export field content as text

      Revision 1.25  1999/12/13 08:29:07  mib
      #70271#: Support for element items added, background and brush item

      Revision 1.24  1999/12/08 10:44:21  cl
      #70271# added first support for importing tab-stops

      Revision 1.23  1999/12/06 11:41:33  mib
      #70258#: Container item for unkown attributes

      Revision 1.22  1999/11/26 11:11:49  mib
      export-flags, loading of styles only

      Revision 1.21  1999/11/19 15:27:59  mib
      Opt: using C++ arrays instead of string buffers

      Revision 1.20  1999/11/12 11:43:03  mib
      using item mapper, part iii

      Revision 1.19  1999/11/10 15:08:09  mib
      Import now uses XMLItemMapper

      Revision 1.18  1999/11/09 15:40:08  mib
      Using XMLItemMapper for export

      Revision 1.17  1999/11/03 11:13:50  mib
      list style import continued

      Revision 1.16  1999/11/01 11:38:50  mib
      List style import

      Revision 1.15  1999/10/26 13:33:50  mib
      list styles continued

      Revision 1.14  1999/10/25 10:41:48  mib
      Using new OUString ASCII methods

      Revision 1.13  1999/10/15 12:38:01  mib
      XML_TOK_SW_LINE_FEED -> XML_TOK_SW_LINE_BREAK

      Revision 1.12  1999/10/08 11:47:56  mib
      moved some file to SVTOOLS/SVX

      Revision 1.11  1999/10/06 06:48:06  mib
      WS stripping

      Revision 1.10  1999/10/01 14:12:02  mib
      tab, line break and space

      Revision 1.9  1999/09/28 10:47:05  mib
      memory leak

      Revision 1.8  1999/09/28 08:31:47  mib
      char fmts, hints

      Revision 1.7  1999/09/23 11:54:28  mib
      i18n, token maps and hard paragraph attributes

      Revision 1.6  1999/09/22 11:57:46  mib
      string -> wstring

      Revision 1.5  1999/08/18 15:03:38  MIB
      Style import


      Rev 1.4   18 Aug 1999 17:03:38   MIB
   Style import

      Rev 1.3   17 Aug 1999 16:29:24   MIB
   import of text nodes started

      Rev 1.2   13 Aug 1999 16:19:42   MIB
   styles and sections

      Rev 1.1   12 Aug 1999 18:06:22   MIB
   Export ofSvxFontItem, SvxFontHeightItem and SvxLRSpaceItem

      Rev 1.0   12 Aug 1999 12:29:28   MIB
   Initial revision.

*************************************************************************/