xref: /trunk/main/xmloff/source/text/txtparai.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "unointerfacetouniqueidentifiermapper.hxx"
31 #include <rtl/ustring.hxx>
32 #include <rtl/ustrbuf.hxx>
33 #include <tools/debug.hxx>
34 
35 #include <tools/string.hxx>
36 #include <svl/svarray.hxx>
37 #include <com/sun/star/text/XTextFrame.hpp>
38 #include <com/sun/star/text/XTextCursor.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/beans/XPropertySetInfo.hpp>
41 #include <com/sun/star/text/ControlCharacter.hpp>
42 #include <com/sun/star/container/XIndexReplace.hpp>
43 #include <com/sun/star/drawing/XShapes.hpp>
44 #include <com/sun/star/container/XEnumerationAccess.hpp>
45 #include <com/sun/star/rdf/XMetadatable.hpp>
46 
47 
48 #include <xmloff/xmlictxt.hxx>
49 #include <xmloff/xmlimp.hxx>
50 #include <xmloff/xmltoken.hxx>
51 #include <xmloff/nmspmap.hxx>
52 #include "xmloff/xmlnmspe.hxx"
53 #include <xmloff/txtimp.hxx>
54 #include "txtparai.hxx"
55 #include "txtfldi.hxx"
56 #include <xmloff/xmluconv.hxx>
57 #include "XMLFootnoteImportContext.hxx"
58 #include "XMLTextMarkImportContext.hxx"
59 #include "XMLTextFrameContext.hxx"
60 #include <xmloff/XMLCharContext.hxx>
61 #include "XMLTextFrameHyperlinkContext.hxx"
62 #include <xmloff/XMLEventsImportContext.hxx>
63 #include "XMLChangeImportContext.hxx"
64 #include "txtlists.hxx"
65 
66 
67 // OD 2004-04-21 #i26791#
68 #include <txtparaimphint.hxx>
69 typedef XMLHint_Impl *XMLHint_ImplPtr;
70 SV_DECL_PTRARR_DEL( XMLHints_Impl, XMLHint_ImplPtr, 5, 5 )
71 SV_IMPL_PTRARR( XMLHints_Impl, XMLHint_ImplPtr )
72 // OD 2004-04-21 #i26791#
73 #include <com/sun/star/beans/XPropertySet.hpp>
74 
75 using ::rtl::OUString;
76 using ::rtl::OUStringBuffer;
77 
78 using namespace ::com::sun::star;
79 using namespace ::com::sun::star::uno;
80 using namespace ::com::sun::star::text;
81 using namespace ::com::sun::star::drawing;
82 using namespace ::com::sun::star::beans;
83 using namespace ::xmloff::token;
84 using ::com::sun::star::container::XEnumerationAccess;
85 using ::com::sun::star::container::XEnumeration;
86 
87 
88 TYPEINIT1( XMLCharContext, SvXMLImportContext );
89 
90 XMLCharContext::XMLCharContext(
91         SvXMLImport& rImport,
92         sal_uInt16 nPrfx,
93         const OUString& rLName,
94         const Reference< xml::sax::XAttributeList > & xAttrList,
95         sal_Unicode c,
96         sal_Bool bCount ) :
97     SvXMLImportContext( rImport, nPrfx, rLName )
98     ,m_nControl(0)
99     ,m_nCount(1)
100     ,m_c(c)
101 {
102     if( bCount )
103     {
104         const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
105         sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
106         for( sal_Int16 i=0; i < nAttrCount; i++ )
107         {
108             const OUString& rAttrName = xAttrList->getNameByIndex( i );
109 
110             OUString aLocalName;
111             sal_uInt16 nPrefix =rMap.GetKeyByAttrName( rAttrName,&aLocalName );
112             if( XML_NAMESPACE_TEXT == nPrefix &&
113                 IsXMLToken( aLocalName, XML_C ) )
114             {
115                 sal_Int32 nTmp = xAttrList->getValueByIndex(i).toInt32();
116                 if( nTmp > 0L )
117                 {
118                     if( nTmp > USHRT_MAX )
119                         m_nCount = USHRT_MAX;
120                     else
121                         m_nCount = (sal_uInt16)nTmp;
122                 }
123             }
124         }
125     }
126 }
127 
128 XMLCharContext::XMLCharContext(
129         SvXMLImport& rImp,
130         sal_uInt16 nPrfx,
131         const OUString& rLName,
132         const Reference< xml::sax::XAttributeList > &,
133         sal_Int16 nControl ) :
134     SvXMLImportContext( rImp, nPrfx, rLName )
135     ,m_nControl(nControl)
136     ,m_nCount(0)
137 {
138 }
139 
140 XMLCharContext::~XMLCharContext()
141 {
142 }
143 // -----------------------------------------------------------------------------
144 void XMLCharContext::EndElement()
145 {
146     if ( !m_nCount )
147         InsertControlCharacter( m_nControl );
148     else
149     {
150         if( 1U == m_nCount )
151         {
152             OUString sBuff( &m_c, 1 );
153             InsertString(sBuff);
154         }
155         else
156         {
157             OUStringBuffer sBuff( m_nCount );
158             while( m_nCount-- )
159                 sBuff.append( &m_c, 1 );
160 
161             InsertString(sBuff.makeStringAndClear() );
162         }
163     }
164 }
165 // -----------------------------------------------------------------------------
166 void XMLCharContext::InsertControlCharacter(sal_Int16   _nControl)
167 {
168     GetImport().GetTextImport()->InsertControlCharacter( _nControl );
169 }
170 void XMLCharContext::InsertString(const ::rtl::OUString& _sString)
171 {
172     GetImport().GetTextImport()->InsertString( _sString );
173 }
174 
175 // ---------------------------------------------------------------------
176 
177 /** import start of reference (<text:reference-start>) */
178 class XMLStartReferenceContext_Impl : public SvXMLImportContext
179 {
180 public:
181     TYPEINFO();
182 
183     // Do everything in constructor. Well ...
184     XMLStartReferenceContext_Impl (
185         SvXMLImport& rImport,
186         sal_uInt16 nPrefix,
187         const OUString& rLocalName,
188         XMLHints_Impl& rHnts,
189         const Reference<xml::sax::XAttributeList> & xAttrList);
190 
191     static sal_Bool FindName(
192         SvXMLImport& rImport,
193         const Reference<xml::sax::XAttributeList> & xAttrList,
194         OUString& rName);
195 };
196 
197 TYPEINIT1( XMLStartReferenceContext_Impl, SvXMLImportContext );
198 
199 XMLStartReferenceContext_Impl::XMLStartReferenceContext_Impl(
200     SvXMLImport& rImport,
201     sal_uInt16 nPrefix,
202     const OUString& rLocalName,
203     XMLHints_Impl& rHints,
204     const Reference<xml::sax::XAttributeList> & xAttrList) :
205         SvXMLImportContext(rImport, nPrefix, rLocalName)
206 {
207     OUString sName;
208 
209     if (FindName(GetImport(), xAttrList, sName))
210     {
211         XMLHint_Impl* pHint = new XMLReferenceHint_Impl(
212             sName, rImport.GetTextImport()->GetCursor()->getStart() );
213 
214         // degenerates to point reference, if no end is found!
215         pHint->SetEnd(rImport.GetTextImport()->GetCursor()->getStart() );
216 
217         rHints.Insert(pHint, rHints.Count());
218     }
219 }
220 
221 sal_Bool XMLStartReferenceContext_Impl::FindName(
222     SvXMLImport& rImport,
223     const Reference<xml::sax::XAttributeList> & xAttrList,
224     OUString& rName)
225 {
226     sal_Bool bNameOK( sal_False );
227 
228     // find name attribute first
229     const sal_Int16 nLength( xAttrList->getLength() );
230     for (sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
231     {
232         OUString sLocalName;
233         const sal_uInt16 nPrefix = rImport.GetNamespaceMap().
234             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
235                               &sLocalName );
236 
237         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
238              IsXMLToken(sLocalName, XML_NAME)   )
239         {
240             rName = xAttrList->getValueByIndex(nAttr);
241             bNameOK = sal_True;
242         }
243     }
244 
245     return bNameOK;
246 }
247 
248 // ---------------------------------------------------------------------
249 
250 /** import end of reference (<text:reference-end>) */
251 class XMLEndReferenceContext_Impl : public SvXMLImportContext
252 {
253 public:
254     TYPEINFO();
255 
256     // Do everything in constructor. Well ...
257     XMLEndReferenceContext_Impl(
258         SvXMLImport& rImport,
259         sal_uInt16 nPrefix,
260         const OUString& rLocalName,
261         XMLHints_Impl& rHnts,
262         const Reference<xml::sax::XAttributeList> & xAttrList);
263 };
264 
265 TYPEINIT1( XMLEndReferenceContext_Impl, SvXMLImportContext );
266 
267 XMLEndReferenceContext_Impl::XMLEndReferenceContext_Impl(
268     SvXMLImport& rImport,
269     sal_uInt16 nPrefix,
270     const OUString& rLocalName,
271     XMLHints_Impl& rHints,
272     const Reference<xml::sax::XAttributeList> & xAttrList) :
273         SvXMLImportContext(rImport, nPrefix, rLocalName)
274 {
275     OUString sName;
276 
277     // borrow from XMLStartReferenceContext_Impl
278     if (XMLStartReferenceContext_Impl::FindName(GetImport(), xAttrList, sName))
279     {
280         // search for reference start
281         sal_uInt16 nCount = rHints.Count();
282         for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
283         {
284             XMLHint_Impl *pHint = rHints[nPos];
285             if ( pHint->IsReference() &&
286                  sName.equals( ((XMLReferenceHint_Impl *)pHint)->GetRefName()) )
287             {
288                 // set end and stop searching
289                 pHint->SetEnd(GetImport().GetTextImport()->
290                                      GetCursor()->getStart() );
291                 break;
292             }
293         }
294         // else: no start (in this paragraph) -> ignore
295     }
296 }
297 
298 // ---------------------------------------------------------------------
299 
300 class XMLImpSpanContext_Impl : public SvXMLImportContext
301 {
302     const OUString sTextFrame;
303 
304     XMLHints_Impl&  rHints;
305     XMLStyleHint_Impl   *pHint;
306 
307     sal_Bool&       rIgnoreLeadingSpace;
308 
309     sal_uInt8               nStarFontsConvFlags;
310 
311 public:
312 
313     TYPEINFO();
314 
315     XMLImpSpanContext_Impl(
316             SvXMLImport& rImport,
317             sal_uInt16 nPrfx,
318             const OUString& rLName,
319             const Reference< xml::sax::XAttributeList > & xAttrList,
320             XMLHints_Impl& rHnts,
321             sal_Bool& rIgnLeadSpace
322     ,sal_uInt8              nSFConvFlags
323                           );
324 
325     virtual ~XMLImpSpanContext_Impl();
326 
327     static SvXMLImportContext *CreateChildContext(
328             SvXMLImport& rImport,
329             sal_uInt16 nPrefix, const OUString& rLocalName,
330             const Reference< xml::sax::XAttributeList > & xAttrList,
331             sal_uInt16 nToken, XMLHints_Impl& rHnts,
332             sal_Bool& rIgnLeadSpace
333     ,sal_uInt8              nStarFontsConvFlags = 0
334              );
335     virtual SvXMLImportContext *CreateChildContext(
336             sal_uInt16 nPrefix, const OUString& rLocalName,
337             const Reference< xml::sax::XAttributeList > & xAttrList );
338 
339     virtual void Characters( const OUString& rChars );
340 };
341 // ---------------------------------------------------------------------
342 
343 class XMLImpHyperlinkContext_Impl : public SvXMLImportContext
344 {
345     XMLHints_Impl&  rHints;
346     XMLHyperlinkHint_Impl   *pHint;
347 
348     sal_Bool&       rIgnoreLeadingSpace;
349 
350 public:
351 
352     TYPEINFO();
353 
354     XMLImpHyperlinkContext_Impl(
355             SvXMLImport& rImport,
356             sal_uInt16 nPrfx,
357             const OUString& rLName,
358             const Reference< xml::sax::XAttributeList > & xAttrList,
359             XMLHints_Impl& rHnts,
360             sal_Bool& rIgnLeadSpace );
361 
362     virtual ~XMLImpHyperlinkContext_Impl();
363 
364     virtual SvXMLImportContext *CreateChildContext(
365             sal_uInt16 nPrefix, const OUString& rLocalName,
366             const Reference< xml::sax::XAttributeList > & xAttrList );
367 
368     virtual void Characters( const OUString& rChars );
369 };
370 
371 TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext );
372 
373 XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
374         SvXMLImport& rImport,
375         sal_uInt16 nPrfx,
376         const OUString& rLName,
377         const Reference< xml::sax::XAttributeList > & xAttrList,
378         XMLHints_Impl& rHnts,
379         sal_Bool& rIgnLeadSpace ) :
380     SvXMLImportContext( rImport, nPrfx, rLName ),
381     rHints( rHnts ),
382     pHint( new XMLHyperlinkHint_Impl(
383               GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) ),
384     rIgnoreLeadingSpace( rIgnLeadSpace )
385 {
386     OUString sShow;
387     const SvXMLTokenMap& rTokenMap =
388         GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
389 
390     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
391     for( sal_Int16 i=0; i < nAttrCount; i++ )
392     {
393         const OUString& rAttrName = xAttrList->getNameByIndex( i );
394         const OUString& rValue = xAttrList->getValueByIndex( i );
395 
396         OUString aLocalName;
397         sal_uInt16 nPrefix =
398             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
399                                                             &aLocalName );
400         switch( rTokenMap.Get( nPrefix, aLocalName ) )
401         {
402         case XML_TOK_TEXT_HYPERLINK_HREF:
403             pHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
404             break;
405         case XML_TOK_TEXT_HYPERLINK_NAME:
406             pHint->SetName( rValue );
407             break;
408         case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
409             pHint->SetTargetFrameName( rValue );
410             break;
411         case XML_TOK_TEXT_HYPERLINK_SHOW:
412             sShow = rValue;
413             break;
414         case XML_TOK_TEXT_HYPERLINK_STYLE_NAME:
415             pHint->SetStyleName( rValue );
416             break;
417         case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME:
418             pHint->SetVisitedStyleName( rValue );
419             break;
420         }
421     }
422 
423     if( sShow.getLength() && !pHint->GetTargetFrameName().getLength() )
424     {
425         if( IsXMLToken( sShow, XML_NEW ) )
426             pHint->SetTargetFrameName(
427                     OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ) );
428         else if( IsXMLToken( sShow, XML_REPLACE ) )
429             pHint->SetTargetFrameName(
430                     OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ) );
431     }
432     rHints.Insert( pHint, rHints.Count() );
433 }
434 
435 XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
436 {
437     if( pHint )
438         pHint->SetEnd( GetImport().GetTextImport()
439                             ->GetCursorAsRange()->getStart() );
440 }
441 
442 SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
443         sal_uInt16 nPrefix, const OUString& rLocalName,
444         const Reference< xml::sax::XAttributeList > & xAttrList )
445 {
446     if ( (nPrefix == XML_NAMESPACE_OFFICE) &&
447          IsXMLToken(rLocalName, XML_EVENT_LISTENERS) )
448     {
449         XMLEventsImportContext* pCtxt = new XMLEventsImportContext(
450             GetImport(), nPrefix, rLocalName);
451         pHint->SetEventsContext(pCtxt);
452         return pCtxt;
453     }
454     else
455     {
456         const SvXMLTokenMap& rTokenMap =
457             GetImport().GetTextImport()->GetTextPElemTokenMap();
458         sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
459 
460         return XMLImpSpanContext_Impl::CreateChildContext(
461             GetImport(), nPrefix, rLocalName, xAttrList,
462             nToken, rHints, rIgnoreLeadingSpace );
463     }
464 }
465 
466 void XMLImpHyperlinkContext_Impl::Characters( const OUString& rChars )
467 {
468     GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
469 }
470 
471 // ---------------------------------------------------------------------
472 
473 class XMLImpRubyBaseContext_Impl : public SvXMLImportContext
474 {
475     XMLHints_Impl&  rHints;
476 
477     sal_Bool&       rIgnoreLeadingSpace;
478 
479 public:
480 
481     TYPEINFO();
482 
483     XMLImpRubyBaseContext_Impl(
484             SvXMLImport& rImport,
485             sal_uInt16 nPrfx,
486             const OUString& rLName,
487             const Reference< xml::sax::XAttributeList > & xAttrList,
488             XMLHints_Impl& rHnts,
489             sal_Bool& rIgnLeadSpace );
490 
491     virtual ~XMLImpRubyBaseContext_Impl();
492 
493     virtual SvXMLImportContext *CreateChildContext(
494             sal_uInt16 nPrefix, const OUString& rLocalName,
495             const Reference< xml::sax::XAttributeList > & xAttrList );
496 
497     virtual void Characters( const OUString& rChars );
498 };
499 
500 TYPEINIT1( XMLImpRubyBaseContext_Impl, SvXMLImportContext );
501 
502 XMLImpRubyBaseContext_Impl::XMLImpRubyBaseContext_Impl(
503         SvXMLImport& rImport,
504         sal_uInt16 nPrfx,
505         const OUString& rLName,
506         const Reference< xml::sax::XAttributeList > &,
507         XMLHints_Impl& rHnts,
508         sal_Bool& rIgnLeadSpace ) :
509     SvXMLImportContext( rImport, nPrfx, rLName ),
510     rHints( rHnts ),
511     rIgnoreLeadingSpace( rIgnLeadSpace )
512 {
513 }
514 
515 XMLImpRubyBaseContext_Impl::~XMLImpRubyBaseContext_Impl()
516 {
517 }
518 
519 SvXMLImportContext *XMLImpRubyBaseContext_Impl::CreateChildContext(
520         sal_uInt16 nPrefix, const OUString& rLocalName,
521         const Reference< xml::sax::XAttributeList > & xAttrList )
522 {
523     const SvXMLTokenMap& rTokenMap =
524         GetImport().GetTextImport()->GetTextPElemTokenMap();
525     sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
526 
527     return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), nPrefix,
528                                                        rLocalName, xAttrList,
529                                nToken, rHints, rIgnoreLeadingSpace );
530 }
531 
532 void XMLImpRubyBaseContext_Impl::Characters( const OUString& rChars )
533 {
534     GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
535 }
536 
537 // ---------------------------------------------------------------------
538 
539 class XMLImpRubyContext_Impl : public SvXMLImportContext
540 {
541     XMLHints_Impl&  rHints;
542 
543     sal_Bool&       rIgnoreLeadingSpace;
544 
545     Reference < XTextRange > m_xStart;
546     OUString        m_sStyleName;
547     OUString        m_sTextStyleName;
548     OUString        m_sText;
549 
550 public:
551 
552     TYPEINFO();
553 
554     XMLImpRubyContext_Impl(
555             SvXMLImport& rImport,
556             sal_uInt16 nPrfx,
557             const OUString& rLName,
558             const Reference< xml::sax::XAttributeList > & xAttrList,
559             XMLHints_Impl& rHnts,
560             sal_Bool& rIgnLeadSpace );
561 
562     virtual ~XMLImpRubyContext_Impl();
563 
564     virtual SvXMLImportContext *CreateChildContext(
565             sal_uInt16 nPrefix, const OUString& rLocalName,
566             const Reference< xml::sax::XAttributeList > & xAttrList );
567 
568     void SetTextStyleName( const OUString& s ) { m_sTextStyleName = s; }
569     void AppendText( const OUString& s ) { m_sText += s; }
570 };
571 
572 // ---------------------------------------------------------------------
573 
574 class XMLImpRubyTextContext_Impl : public SvXMLImportContext
575 {
576     XMLImpRubyContext_Impl & m_rRubyContext;
577 
578 public:
579 
580     TYPEINFO();
581 
582     XMLImpRubyTextContext_Impl(
583             SvXMLImport& rImport,
584             sal_uInt16 nPrfx,
585             const OUString& rLName,
586             const Reference< xml::sax::XAttributeList > & xAttrList,
587             XMLImpRubyContext_Impl & rParent );
588 
589     virtual ~XMLImpRubyTextContext_Impl();
590 
591     virtual void Characters( const OUString& rChars );
592 };
593 
594 TYPEINIT1( XMLImpRubyTextContext_Impl, SvXMLImportContext );
595 
596 XMLImpRubyTextContext_Impl::XMLImpRubyTextContext_Impl(
597         SvXMLImport& rImport,
598         sal_uInt16 nPrfx,
599         const OUString& rLName,
600         const Reference< xml::sax::XAttributeList > & xAttrList,
601         XMLImpRubyContext_Impl & rParent )
602     : SvXMLImportContext( rImport, nPrfx, rLName )
603     , m_rRubyContext( rParent )
604 {
605     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
606     for( sal_Int16 i=0; i < nAttrCount; i++ )
607     {
608         const OUString& rAttrName = xAttrList->getNameByIndex( i );
609         const OUString& rValue = xAttrList->getValueByIndex( i );
610 
611         OUString aLocalName;
612         sal_uInt16 nPrefix =
613             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
614                                                             &aLocalName );
615         if( XML_NAMESPACE_TEXT == nPrefix &&
616             IsXMLToken( aLocalName, XML_STYLE_NAME ) )
617         {
618             m_rRubyContext.SetTextStyleName( rValue );
619             break;
620         }
621     }
622 }
623 
624 XMLImpRubyTextContext_Impl::~XMLImpRubyTextContext_Impl()
625 {
626 }
627 
628 void XMLImpRubyTextContext_Impl::Characters( const OUString& rChars )
629 {
630     m_rRubyContext.AppendText( rChars );
631 }
632 
633 // ---------------------------------------------------------------------
634 
635 TYPEINIT1( XMLImpRubyContext_Impl, SvXMLImportContext );
636 
637 XMLImpRubyContext_Impl::XMLImpRubyContext_Impl(
638         SvXMLImport& rImport,
639         sal_uInt16 nPrfx,
640         const OUString& rLName,
641         const Reference< xml::sax::XAttributeList > & xAttrList,
642         XMLHints_Impl& rHnts,
643         sal_Bool& rIgnLeadSpace ) :
644     SvXMLImportContext( rImport, nPrfx, rLName ),
645     rHints( rHnts ),
646     rIgnoreLeadingSpace( rIgnLeadSpace )
647     , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
648 {
649     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
650     for( sal_Int16 i=0; i < nAttrCount; i++ )
651     {
652         const OUString& rAttrName = xAttrList->getNameByIndex( i );
653         const OUString& rValue = xAttrList->getValueByIndex( i );
654 
655         OUString aLocalName;
656         sal_uInt16 nPrefix =
657             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
658                                                             &aLocalName );
659         if( XML_NAMESPACE_TEXT == nPrefix &&
660             IsXMLToken( aLocalName, XML_STYLE_NAME ) )
661         {
662             m_sStyleName = rValue;
663             break;
664         }
665     }
666 }
667 
668 XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl()
669 {
670     const UniReference < XMLTextImportHelper > xTextImport(
671         GetImport().GetTextImport());
672     const Reference < XTextCursor > xAttrCursor(
673         xTextImport->GetText()->createTextCursorByRange( m_xStart ));
674     xAttrCursor->gotoRange(xTextImport->GetCursorAsRange()->getStart(),
675             sal_True);
676     xTextImport->SetRuby( GetImport(), xAttrCursor,
677          m_sStyleName, m_sTextStyleName, m_sText );
678 }
679 
680 SvXMLImportContext *XMLImpRubyContext_Impl::CreateChildContext(
681         sal_uInt16 nPrefix, const OUString& rLocalName,
682         const Reference< xml::sax::XAttributeList > & xAttrList )
683 {
684     SvXMLImportContext *pContext;
685     if( XML_NAMESPACE_TEXT == nPrefix )
686     {
687         if( IsXMLToken( rLocalName, XML_RUBY_BASE ) )
688             pContext = new XMLImpRubyBaseContext_Impl( GetImport(), nPrefix,
689                                                        rLocalName,
690                                                        xAttrList,
691                                                        rHints,
692                                                        rIgnoreLeadingSpace );
693         else if( IsXMLToken( rLocalName, XML_RUBY_TEXT ) )
694             pContext = new XMLImpRubyTextContext_Impl( GetImport(), nPrefix,
695                                                        rLocalName,
696                                                        xAttrList,
697                                                        *this );
698         else
699             pContext = new SvXMLImportContext(
700                 GetImport(), nPrefix, rLocalName );
701     }
702     else
703         pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName,
704                                                             xAttrList );
705 
706     return pContext;
707 }
708 
709 // ---------------------------------------------------------------------
710 
711 /** for text:meta and text:meta-field
712  */
713 class XMLMetaImportContextBase : public SvXMLImportContext
714 {
715     XMLHints_Impl&    m_rHints;
716 
717     sal_Bool& m_rIgnoreLeadingSpace;
718 
719     /// start position
720     Reference<XTextRange> m_xStart;
721 
722 protected:
723     OUString m_XmlId;
724 
725 public:
726     TYPEINFO();
727 
728     XMLMetaImportContextBase(
729         SvXMLImport& i_rImport,
730         const sal_uInt16 i_nPrefix,
731         const OUString& i_rLocalName,
732         XMLHints_Impl& i_rHints,
733         sal_Bool & i_rIgnoreLeadingSpace );
734 
735     virtual ~XMLMetaImportContextBase();
736 
737     virtual void StartElement(
738             const Reference<xml::sax::XAttributeList> & i_xAttrList);
739 
740     virtual void EndElement();
741 
742     virtual SvXMLImportContext *CreateChildContext(
743             sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
744             const Reference< xml::sax::XAttributeList > & i_xAttrList);
745 
746     virtual void Characters( const OUString& i_rChars );
747 
748     virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
749         OUString const & i_rLocalName, OUString const & i_rValue);
750 
751     virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange)
752         = 0;
753 };
754 
755 TYPEINIT1( XMLMetaImportContextBase, SvXMLImportContext );
756 
757 XMLMetaImportContextBase::XMLMetaImportContextBase(
758         SvXMLImport& i_rImport,
759         const sal_uInt16 i_nPrefix,
760         const OUString& i_rLocalName,
761         XMLHints_Impl& i_rHints,
762         sal_Bool & i_rIgnoreLeadingSpace )
763     : SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName )
764     , m_rHints( i_rHints )
765     , m_rIgnoreLeadingSpace( i_rIgnoreLeadingSpace )
766     , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
767 {
768 }
769 
770 XMLMetaImportContextBase::~XMLMetaImportContextBase()
771 {
772 }
773 
774 void XMLMetaImportContextBase::StartElement(
775         const Reference<xml::sax::XAttributeList> & i_xAttrList)
776 {
777     const sal_Int16 nAttrCount(i_xAttrList.is() ? i_xAttrList->getLength() : 0);
778     for ( sal_Int16 i = 0; i < nAttrCount; ++i )
779     {
780         const OUString& rAttrName( i_xAttrList->getNameByIndex( i ) );
781         const OUString& rValue( i_xAttrList->getValueByIndex( i ) );
782 
783         OUString sLocalName;
784         const sal_uInt16 nPrefix(
785             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
786                                                             &sLocalName ));
787         ProcessAttribute(nPrefix, sLocalName, rValue);
788     }
789 }
790 
791 void XMLMetaImportContextBase::EndElement()
792 {
793     OSL_ENSURE(m_xStart.is(), "no mxStart?");
794     if (!m_xStart.is()) return;
795 
796     const Reference<XTextRange> xEndRange(
797         GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
798 
799     // create range for insertion
800     const Reference<XTextCursor> xInsertionCursor(
801         GetImport().GetTextImport()->GetText()->createTextCursorByRange(
802             xEndRange) );
803     xInsertionCursor->gotoRange(m_xStart, sal_True);
804 
805     const Reference<XTextRange> xInsertionRange(xInsertionCursor, UNO_QUERY);
806 
807     InsertMeta(xInsertionRange);
808 }
809 
810 SvXMLImportContext * XMLMetaImportContextBase::CreateChildContext(
811             sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
812             const Reference< xml::sax::XAttributeList > & i_xAttrList )
813 {
814     const SvXMLTokenMap& rTokenMap(
815         GetImport().GetTextImport()->GetTextPElemTokenMap() );
816     const sal_uInt16 nToken( rTokenMap.Get( i_nPrefix, i_rLocalName ) );
817 
818     return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), i_nPrefix,
819         i_rLocalName, i_xAttrList, nToken, m_rHints, m_rIgnoreLeadingSpace );
820 }
821 
822 void XMLMetaImportContextBase::Characters( const OUString& i_rChars )
823 {
824     GetImport().GetTextImport()->InsertString(i_rChars, m_rIgnoreLeadingSpace);
825 }
826 
827 void XMLMetaImportContextBase::ProcessAttribute(sal_uInt16 const i_nPrefix,
828     OUString const & i_rLocalName, OUString const & i_rValue)
829 {
830     if ( (XML_NAMESPACE_XML == i_nPrefix) && IsXMLToken(i_rLocalName, XML_ID) )
831     {
832         m_XmlId = i_rValue;
833     }
834 }
835 
836 
837 // ---------------------------------------------------------------------
838 
839 /** text:meta */
840 class XMLMetaImportContext : public XMLMetaImportContextBase
841 {
842     // RDFa
843     bool m_bHaveAbout;
844     ::rtl::OUString m_sAbout;
845     ::rtl::OUString m_sProperty;
846     ::rtl::OUString m_sContent;
847     ::rtl::OUString m_sDatatype;
848 
849 public:
850     TYPEINFO();
851 
852     XMLMetaImportContext(
853         SvXMLImport& i_rImport,
854         const sal_uInt16 i_nPrefix,
855         const OUString& i_rLocalName,
856         XMLHints_Impl& i_rHints,
857         sal_Bool & i_rIgnoreLeadingSpace );
858 
859     virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
860         OUString const & i_rLocalName, OUString const & i_rValue);
861 
862     virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange);
863 };
864 
865 TYPEINIT1( XMLMetaImportContext, XMLMetaImportContextBase );
866 
867 XMLMetaImportContext::XMLMetaImportContext(
868         SvXMLImport& i_rImport,
869         const sal_uInt16 i_nPrefix,
870         const OUString& i_rLocalName,
871         XMLHints_Impl& i_rHints,
872         sal_Bool & i_rIgnoreLeadingSpace )
873     : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
874             i_rHints, i_rIgnoreLeadingSpace )
875     , m_bHaveAbout(false)
876 {
877 }
878 
879 void XMLMetaImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
880     OUString const & i_rLocalName, OUString const & i_rValue)
881 {
882     if ( XML_NAMESPACE_XHTML == i_nPrefix )
883     {
884         // RDFa
885         if ( IsXMLToken( i_rLocalName, XML_ABOUT) )
886         {
887             m_sAbout = i_rValue;
888             m_bHaveAbout = true;
889         }
890         else if ( IsXMLToken( i_rLocalName, XML_PROPERTY) )
891         {
892             m_sProperty = i_rValue;
893         }
894         else if ( IsXMLToken( i_rLocalName, XML_CONTENT) )
895         {
896             m_sContent = i_rValue;
897         }
898         else if ( IsXMLToken( i_rLocalName, XML_DATATYPE) )
899         {
900             m_sDatatype = i_rValue;
901         }
902     }
903     else
904     {
905         XMLMetaImportContextBase::ProcessAttribute(
906             i_nPrefix, i_rLocalName, i_rValue);
907     }
908 }
909 
910 void XMLMetaImportContext::InsertMeta(
911     const Reference<XTextRange> & i_xInsertionRange)
912 {
913     OSL_ENSURE(!m_bHaveAbout == !m_sProperty.getLength(),
914         "XMLMetaImportContext::InsertMeta: invalid RDFa?");
915     if (m_XmlId.getLength() || (m_bHaveAbout && m_sProperty.getLength()))
916     {
917         // insert mark
918         const uno::Reference<rdf::XMetadatable> xMeta(
919             XMLTextMarkImportContext::CreateAndInsertMark(
920                 GetImport(),
921                 OUString::createFromAscii(
922                     "com.sun.star.text.InContentMetadata"),
923                 OUString(),
924                 i_xInsertionRange, m_XmlId),
925             uno::UNO_QUERY);
926         OSL_ENSURE(xMeta.is(), "cannot insert Meta?");
927 
928         if (xMeta.is() && m_bHaveAbout)
929         {
930             GetImport().AddRDFa(xMeta,
931                 m_sAbout, m_sProperty, m_sContent, m_sDatatype);
932         }
933     }
934     else
935     {
936         OSL_TRACE("invalid <text:meta>: no xml:id, no valid RDFa");
937     }
938 }
939 
940 // ---------------------------------------------------------------------
941 
942 /** text:meta-field */
943 class XMLMetaFieldImportContext : public XMLMetaImportContextBase
944 {
945     OUString m_DataStyleName;
946 
947 public:
948     TYPEINFO();
949 
950     XMLMetaFieldImportContext(
951         SvXMLImport& i_rImport,
952         const sal_uInt16 i_nPrefix,
953         const OUString& i_rLocalName,
954         XMLHints_Impl& i_rHints,
955         sal_Bool & i_rIgnoreLeadingSpace );
956 
957     virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
958         OUString const & i_rLocalName, OUString const & i_rValue);
959 
960     virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange);
961 };
962 
963 TYPEINIT1( XMLMetaFieldImportContext, XMLMetaImportContextBase );
964 
965 XMLMetaFieldImportContext::XMLMetaFieldImportContext(
966         SvXMLImport& i_rImport,
967         const sal_uInt16 i_nPrefix,
968         const OUString& i_rLocalName,
969         XMLHints_Impl& i_rHints,
970         sal_Bool & i_rIgnoreLeadingSpace )
971     : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
972             i_rHints, i_rIgnoreLeadingSpace )
973 {
974 }
975 
976 void XMLMetaFieldImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
977     OUString const & i_rLocalName, OUString const & i_rValue)
978 {
979     if ( XML_NAMESPACE_STYLE == i_nPrefix &&
980          IsXMLToken( i_rLocalName, XML_DATA_STYLE_NAME ) )
981     {
982         m_DataStyleName = i_rValue;
983     }
984     else
985     {
986         XMLMetaImportContextBase::ProcessAttribute(
987             i_nPrefix, i_rLocalName, i_rValue);
988     }
989 }
990 
991 void XMLMetaFieldImportContext::InsertMeta(
992     const Reference<XTextRange> & i_xInsertionRange)
993 {
994     if (m_XmlId.getLength()) // valid?
995     {
996         // insert mark
997         const Reference<XPropertySet> xPropertySet(
998             XMLTextMarkImportContext::CreateAndInsertMark(
999                 GetImport(),
1000                 OUString::createFromAscii(
1001                     "com.sun.star.text.textfield.MetadataField"),
1002                 OUString(),
1003                 i_xInsertionRange, m_XmlId),
1004             UNO_QUERY);
1005         OSL_ENSURE(xPropertySet.is(), "cannot insert MetaField?");
1006         if (!xPropertySet.is()) return;
1007 
1008         if (m_DataStyleName.getLength())
1009         {
1010             sal_Bool isDefaultLanguage(sal_True);
1011 
1012             const sal_Int32 nKey( GetImport().GetTextImport()->GetDataStyleKey(
1013                                    m_DataStyleName, & isDefaultLanguage) );
1014 
1015             if (-1 != nKey)
1016             {
1017                 static ::rtl::OUString sPropertyIsFixedLanguage(
1018                     ::rtl::OUString::createFromAscii("IsFixedLanguage") );
1019                 Any any;
1020                 any <<= nKey;
1021                 xPropertySet->setPropertyValue(
1022                     OUString::createFromAscii("NumberFormat"), any);
1023                 if ( xPropertySet->getPropertySetInfo()->
1024                         hasPropertyByName( sPropertyIsFixedLanguage ) )
1025                 {
1026                     any <<= static_cast<bool>(!isDefaultLanguage);
1027                     xPropertySet->setPropertyValue( sPropertyIsFixedLanguage,
1028                         any );
1029                 }
1030             }
1031         }
1032     }
1033     else
1034     {
1035         OSL_TRACE("invalid <text:meta-field>: no xml:id");
1036     }
1037 }
1038 
1039 
1040 // ---------------------------------------------------------------------
1041 
1042 
1043 /**
1044  * Process index marks.
1045  *
1046  * All *-mark-end index marks should instantiate *this* class (because
1047  * it doesn't process attributes other than ID), while the *-mark and
1048  * *-mark-start classes should instantiate the apporpiate subclasses.
1049  */
1050 class XMLIndexMarkImportContext_Impl : public SvXMLImportContext
1051 {
1052     const OUString sAlternativeText;
1053 
1054     XMLHints_Impl& rHints;
1055     const enum XMLTextPElemTokens eToken;
1056     OUString sID;
1057 
1058 public:
1059     TYPEINFO();
1060 
1061     XMLIndexMarkImportContext_Impl(
1062         SvXMLImport& rImport,
1063         sal_uInt16 nPrefix,
1064         const OUString& rLocalName,
1065         enum XMLTextPElemTokens nTok,
1066         XMLHints_Impl& rHnts);
1067 
1068     void StartElement(const Reference<xml::sax::XAttributeList> & xAttrList);
1069 
1070 protected:
1071 
1072     /// process all attributes
1073     void ProcessAttributes(const Reference<xml::sax::XAttributeList> & xAttrList,
1074                            Reference<beans::XPropertySet>& rPropSet);
1075 
1076     /**
1077      * All marks can be created immediatly. Since we don't care about
1078      * the element content, ProcessAttribute should set the properties
1079      * immediatly.
1080      *
1081      * This method tolerates an empty PropertySet; subclasses however
1082      * are not expected to.
1083      */
1084     virtual void ProcessAttribute(sal_uInt16 nNamespace,
1085                                   OUString sLocalName,
1086                                   OUString sValue,
1087                                   Reference<beans::XPropertySet>& rPropSet);
1088 
1089     static void GetServiceName(OUString& sServiceName,
1090                                enum XMLTextPElemTokens nToken);
1091 
1092     sal_Bool CreateMark(Reference<beans::XPropertySet>& rPropSet,
1093                         const OUString& rServiceName);
1094 };
1095 
1096 
1097 TYPEINIT1( XMLIndexMarkImportContext_Impl, SvXMLImportContext );
1098 
1099 XMLIndexMarkImportContext_Impl::XMLIndexMarkImportContext_Impl(
1100     SvXMLImport& rImport,
1101     sal_uInt16 nPrefix,
1102     const OUString& rLocalName,
1103     enum XMLTextPElemTokens eTok,
1104     XMLHints_Impl& rHnts) :
1105         SvXMLImportContext(rImport, nPrefix, rLocalName),
1106         sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")),
1107         rHints(rHnts),
1108         eToken(eTok)
1109 {
1110 }
1111 
1112 void XMLIndexMarkImportContext_Impl::StartElement(
1113     const Reference<xml::sax::XAttributeList> & xAttrList)
1114 {
1115     // get Cursor position (needed for all cases)
1116     Reference<XTextRange> xPos(
1117         GetImport().GetTextImport()->GetCursor()->getStart());
1118     Reference<beans::XPropertySet> xMark;
1119 
1120     switch (eToken)
1121     {
1122         case XML_TOK_TEXT_TOC_MARK:
1123         case XML_TOK_TEXT_USER_INDEX_MARK:
1124         case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1125         {
1126             // single mark: create mark and insert
1127             OUString sService;
1128             GetServiceName(sService, eToken);
1129             if (CreateMark(xMark, sService))
1130             {
1131                 ProcessAttributes(xAttrList, xMark);
1132                 XMLHint_Impl* pHint = new XMLIndexMarkHint_Impl(xMark, xPos);
1133                 rHints.Insert(pHint, rHints.Count());
1134             }
1135             // else: can't create mark -> ignore
1136             break;
1137         }
1138 
1139         case XML_TOK_TEXT_TOC_MARK_START:
1140         case XML_TOK_TEXT_USER_INDEX_MARK_START:
1141         case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1142         {
1143             // start: create mark and insert (if ID is found)
1144             OUString sService;
1145             GetServiceName(sService, eToken);
1146             if (CreateMark(xMark, sService))
1147             {
1148                 ProcessAttributes(xAttrList, xMark);
1149                 if (sID.getLength() > 0)
1150                 {
1151                     // process only if we find an ID
1152                     XMLHint_Impl* pHint =
1153                         new XMLIndexMarkHint_Impl(xMark, xPos, sID);
1154                     rHints.Insert(pHint, rHints.Count());
1155                 }
1156                 // else: no ID -> we'll never find the end -> ignore
1157             }
1158             // else: can't create mark -> ignore
1159             break;
1160         }
1161 
1162         case XML_TOK_TEXT_TOC_MARK_END:
1163         case XML_TOK_TEXT_USER_INDEX_MARK_END:
1164         case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1165         {
1166             // end: search for ID and set end of mark
1167 
1168             // call process attributes with empty XPropertySet:
1169             ProcessAttributes(xAttrList, xMark);
1170             if (sID.getLength() > 0)
1171             {
1172                 // if we have an ID, find the hint and set the end position
1173                 sal_uInt16 nCount = rHints.Count();
1174                 for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
1175                 {
1176                     XMLHint_Impl *pHint = rHints[nPos];
1177                     if ( pHint->IsIndexMark() &&
1178                          sID.equals(
1179                              ((XMLIndexMarkHint_Impl *)pHint)->GetID()) )
1180                     {
1181                         // set end and stop searching
1182                         pHint->SetEnd(xPos);
1183                         break;
1184                     }
1185                 }
1186             }
1187             // else: no ID -> ignore
1188             break;
1189         }
1190 
1191         default:
1192             DBG_ERROR("unknown index mark type!");
1193             break;
1194     }
1195 }
1196 
1197 void XMLIndexMarkImportContext_Impl::ProcessAttributes(
1198     const Reference<xml::sax::XAttributeList> & xAttrList,
1199     Reference<beans::XPropertySet>& rPropSet)
1200 {
1201     // process attributes
1202     sal_Int16 nLength = xAttrList->getLength();
1203     for(sal_Int16 i=0; i<nLength; i++)
1204     {
1205         OUString sLocalName;
1206         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1207             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
1208 
1209         ProcessAttribute(nPrefix, sLocalName,
1210                          xAttrList->getValueByIndex(i),
1211                          rPropSet);
1212     }
1213 }
1214 
1215 void XMLIndexMarkImportContext_Impl::ProcessAttribute(
1216     sal_uInt16 nNamespace,
1217     OUString sLocalName,
1218     OUString sValue,
1219     Reference<beans::XPropertySet>& rPropSet)
1220 {
1221     // we only know ID + string-value attribute;
1222     // (former: marks, latter: -start + -end-marks)
1223     // the remainder is handled in sub-classes
1224     switch (eToken)
1225     {
1226         case XML_TOK_TEXT_TOC_MARK:
1227         case XML_TOK_TEXT_USER_INDEX_MARK:
1228         case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1229             if ( (XML_NAMESPACE_TEXT == nNamespace) &&
1230                  IsXMLToken( sLocalName, XML_STRING_VALUE ) )
1231             {
1232                 rPropSet->setPropertyValue(sAlternativeText, uno::makeAny(sValue));
1233             }
1234             // else: ignore!
1235             break;
1236 
1237         case XML_TOK_TEXT_TOC_MARK_START:
1238         case XML_TOK_TEXT_USER_INDEX_MARK_START:
1239         case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1240         case XML_TOK_TEXT_TOC_MARK_END:
1241         case XML_TOK_TEXT_USER_INDEX_MARK_END:
1242         case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1243             if ( (XML_NAMESPACE_TEXT == nNamespace) &&
1244                  IsXMLToken( sLocalName, XML_ID ) )
1245             {
1246                 sID = sValue;
1247             }
1248             // else: ignore
1249             break;
1250 
1251         default:
1252             DBG_ERROR("unknown index mark type!");
1253             break;
1254     }
1255 }
1256 
1257 static const sal_Char sAPI_com_sun_star_text_ContentIndexMark[] =
1258         "com.sun.star.text.ContentIndexMark";
1259 static const sal_Char sAPI_com_sun_star_text_UserIndexMark[] =
1260         "com.sun.star.text.UserIndexMark";
1261 static const sal_Char sAPI_com_sun_star_text_DocumentIndexMark[] =
1262         "com.sun.star.text.DocumentIndexMark";
1263 
1264 
1265 void XMLIndexMarkImportContext_Impl::GetServiceName(
1266     OUString& sServiceName,
1267     enum XMLTextPElemTokens eToken)
1268 {
1269     switch (eToken)
1270     {
1271         case XML_TOK_TEXT_TOC_MARK:
1272         case XML_TOK_TEXT_TOC_MARK_START:
1273         case XML_TOK_TEXT_TOC_MARK_END:
1274         {
1275             OUString sTmp(RTL_CONSTASCII_USTRINGPARAM(
1276                 sAPI_com_sun_star_text_ContentIndexMark));
1277             sServiceName = sTmp;
1278             break;
1279         }
1280 
1281         case XML_TOK_TEXT_USER_INDEX_MARK:
1282         case XML_TOK_TEXT_USER_INDEX_MARK_START:
1283         case XML_TOK_TEXT_USER_INDEX_MARK_END:
1284         {
1285             OUString sTmp(RTL_CONSTASCII_USTRINGPARAM(
1286                 sAPI_com_sun_star_text_UserIndexMark));
1287             sServiceName = sTmp;
1288             break;
1289         }
1290 
1291         case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1292         case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1293         case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1294         {
1295             OUString sTmp(RTL_CONSTASCII_USTRINGPARAM(
1296                 sAPI_com_sun_star_text_DocumentIndexMark));
1297             sServiceName = sTmp;
1298             break;
1299         }
1300 
1301         default:
1302         {
1303             DBG_ERROR("unknown index mark type!");
1304             OUString sTmp;
1305             sServiceName = sTmp;
1306             break;
1307         }
1308     }
1309 }
1310 
1311 
1312 sal_Bool XMLIndexMarkImportContext_Impl::CreateMark(
1313     Reference<beans::XPropertySet>& rPropSet,
1314     const OUString& rServiceName)
1315 {
1316     Reference<lang::XMultiServiceFactory>
1317         xFactory(GetImport().GetModel(), UNO_QUERY);
1318 
1319     if( xFactory.is() )
1320     {
1321         Reference<beans::XPropertySet> xPropSet( xFactory->createInstance(rServiceName), UNO_QUERY );
1322         if (xPropSet.is())
1323             rPropSet = xPropSet;
1324         return sal_True;
1325     }
1326 
1327     return sal_False;
1328 }
1329 
1330 
1331 class XMLTOCMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1332 {
1333     const OUString sLevel;
1334 
1335 public:
1336     TYPEINFO();
1337 
1338     XMLTOCMarkImportContext_Impl(
1339         SvXMLImport& rImport,
1340         sal_uInt16 nPrefix,
1341         const OUString& rLocalName,
1342         enum XMLTextPElemTokens nTok,
1343         XMLHints_Impl& rHnts);
1344 
1345 protected:
1346 
1347     /** process outline level */
1348     virtual void ProcessAttribute(sal_uInt16 nNamespace,
1349                                   OUString sLocalName,
1350                                   OUString sValue,
1351                                   Reference<beans::XPropertySet>& rPropSet);
1352 };
1353 
1354 TYPEINIT1( XMLTOCMarkImportContext_Impl, XMLIndexMarkImportContext_Impl );
1355 
1356 
1357 XMLTOCMarkImportContext_Impl::XMLTOCMarkImportContext_Impl(
1358     SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1359     enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1360         XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1361                                        nTok, rHnts),
1362         sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
1363 {
1364 }
1365 
1366 void XMLTOCMarkImportContext_Impl::ProcessAttribute(
1367     sal_uInt16 nNamespace,
1368     OUString sLocalName,
1369     OUString sValue,
1370     Reference<beans::XPropertySet>& rPropSet)
1371 {
1372     DBG_ASSERT(rPropSet.is(), "need PropertySet");
1373 
1374     if ((XML_NAMESPACE_TEXT == nNamespace) &&
1375         IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
1376     {
1377         // ouline level: set Level property
1378         sal_Int32 nTmp;
1379         if ( SvXMLUnitConverter::convertNumber( nTmp, sValue )
1380              && nTmp >= 1
1381              && nTmp < GetImport().GetTextImport()->
1382                               GetChapterNumbering()->getCount() )
1383         {
1384             rPropSet->setPropertyValue(sLevel, uno::makeAny((sal_Int16)(nTmp - 1)));
1385         }
1386         // else: value out of range -> ignore
1387     }
1388     else
1389     {
1390         // else: delegate to superclass
1391         XMLIndexMarkImportContext_Impl::ProcessAttribute(
1392             nNamespace, sLocalName, sValue, rPropSet);
1393     }
1394 }
1395 
1396 class XMLUserIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1397 {
1398     const OUString sUserIndexName;
1399     const OUString sLevel;
1400 
1401 public:
1402     TYPEINFO();
1403 
1404     XMLUserIndexMarkImportContext_Impl(
1405         SvXMLImport& rImport,
1406         sal_uInt16 nPrefix,
1407         const OUString& rLocalName,
1408         enum XMLTextPElemTokens nTok,
1409         XMLHints_Impl& rHnts);
1410 
1411 protected:
1412 
1413     /** process index name */
1414     virtual void ProcessAttribute(sal_uInt16 nNamespace,
1415                                   OUString sLocalName,
1416                                   OUString sValue,
1417                                   Reference<beans::XPropertySet>& rPropSet);
1418 };
1419 
1420 TYPEINIT1( XMLUserIndexMarkImportContext_Impl, XMLIndexMarkImportContext_Impl);
1421 
1422 XMLUserIndexMarkImportContext_Impl::XMLUserIndexMarkImportContext_Impl(
1423     SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1424     enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1425         XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1426                                        nTok, rHnts),
1427         sUserIndexName(RTL_CONSTASCII_USTRINGPARAM("UserIndexName")),
1428         sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
1429 {
1430 }
1431 
1432 void XMLUserIndexMarkImportContext_Impl::ProcessAttribute(
1433     sal_uInt16 nNamespace, OUString sLocalName, OUString sValue,
1434     Reference<beans::XPropertySet>& rPropSet)
1435 {
1436     if ( XML_NAMESPACE_TEXT == nNamespace )
1437     {
1438         if ( IsXMLToken( sLocalName, XML_INDEX_NAME ) )
1439         {
1440             rPropSet->setPropertyValue(sUserIndexName, uno::makeAny(sValue));
1441         }
1442         else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
1443         {
1444             // ouline level: set Level property
1445             sal_Int32 nTmp;
1446             if (SvXMLUnitConverter::convertNumber(
1447                 nTmp, sValue, 0,
1448                GetImport().GetTextImport()->GetChapterNumbering()->getCount()))
1449             {
1450                 rPropSet->setPropertyValue(sLevel, uno::makeAny(static_cast<sal_Int16>(nTmp - 1)));
1451             }
1452             // else: value out of range -> ignore
1453         }
1454         else
1455         {
1456             // else: unknown text property: delegate to super class
1457             XMLIndexMarkImportContext_Impl::ProcessAttribute(
1458                 nNamespace, sLocalName, sValue, rPropSet);
1459         }
1460     }
1461     else
1462     {
1463         // else: unknown namespace: delegate to super class
1464         XMLIndexMarkImportContext_Impl::ProcessAttribute(
1465             nNamespace, sLocalName, sValue, rPropSet);
1466     }
1467 }
1468 
1469 
1470 class XMLAlphaIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1471 {
1472     const OUString sPrimaryKey;
1473     const OUString sSecondaryKey;
1474     const OUString sTextReading;
1475     const OUString sPrimaryKeyReading;
1476     const OUString sSecondaryKeyReading;
1477     const OUString sMainEntry;
1478 
1479 public:
1480     TYPEINFO();
1481 
1482     XMLAlphaIndexMarkImportContext_Impl(
1483         SvXMLImport& rImport,
1484         sal_uInt16 nPrefix,
1485         const OUString& rLocalName,
1486         enum XMLTextPElemTokens nTok,
1487         XMLHints_Impl& rHnts);
1488 
1489 protected:
1490 
1491     /** process primary + secondary keys */
1492     virtual void ProcessAttribute(sal_uInt16 nNamespace,
1493                                   OUString sLocalName,
1494                                   OUString sValue,
1495                                   Reference<beans::XPropertySet>& rPropSet);
1496 };
1497 
1498 TYPEINIT1( XMLAlphaIndexMarkImportContext_Impl,
1499            XMLIndexMarkImportContext_Impl );
1500 
1501 XMLAlphaIndexMarkImportContext_Impl::XMLAlphaIndexMarkImportContext_Impl(
1502     SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1503     enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1504         XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1505                                        nTok, rHnts),
1506         sPrimaryKey(RTL_CONSTASCII_USTRINGPARAM("PrimaryKey")),
1507         sSecondaryKey(RTL_CONSTASCII_USTRINGPARAM("SecondaryKey")),
1508         sTextReading(RTL_CONSTASCII_USTRINGPARAM("TextReading")),
1509         sPrimaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("PrimaryKeyReading")),
1510         sSecondaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("SecondaryKeyReading")),
1511         sMainEntry(RTL_CONSTASCII_USTRINGPARAM("IsMainEntry"))
1512 {
1513 }
1514 
1515 void XMLAlphaIndexMarkImportContext_Impl::ProcessAttribute(
1516     sal_uInt16 nNamespace, OUString sLocalName, OUString sValue,
1517     Reference<beans::XPropertySet>& rPropSet)
1518 {
1519     if (XML_NAMESPACE_TEXT == nNamespace)
1520     {
1521         if ( IsXMLToken( sLocalName, XML_KEY1 ) )
1522         {
1523             rPropSet->setPropertyValue(sPrimaryKey, uno::makeAny(sValue));
1524         }
1525         else if ( IsXMLToken( sLocalName, XML_KEY2 ) )
1526         {
1527             rPropSet->setPropertyValue(sSecondaryKey, uno::makeAny(sValue));
1528         }
1529         else if ( IsXMLToken( sLocalName, XML_KEY1_PHONETIC ) )
1530         {
1531             rPropSet->setPropertyValue(sPrimaryKeyReading, uno::makeAny(sValue));
1532         }
1533         else if ( IsXMLToken( sLocalName, XML_KEY2_PHONETIC ) )
1534         {
1535             rPropSet->setPropertyValue(sSecondaryKeyReading, uno::makeAny(sValue));
1536         }
1537         else if ( IsXMLToken( sLocalName, XML_STRING_VALUE_PHONETIC ) )
1538         {
1539             rPropSet->setPropertyValue(sTextReading, uno::makeAny(sValue));
1540         }
1541         else if ( IsXMLToken( sLocalName, XML_MAIN_ENTRY ) )
1542         {
1543             sal_Bool bMainEntry = sal_False, bTmp;
1544 
1545             if (SvXMLUnitConverter::convertBool(bTmp, sValue))
1546                 bMainEntry = bTmp;
1547 
1548             rPropSet->setPropertyValue(sMainEntry, uno::makeAny(bMainEntry));
1549         }
1550         else
1551         {
1552             XMLIndexMarkImportContext_Impl::ProcessAttribute(
1553                 nNamespace, sLocalName, sValue, rPropSet);
1554         }
1555     }
1556     else
1557     {
1558         XMLIndexMarkImportContext_Impl::ProcessAttribute(
1559             nNamespace, sLocalName, sValue, rPropSet);
1560     }
1561 }
1562 
1563 
1564 // ---------------------------------------------------------------------
1565 
1566 TYPEINIT1( XMLImpSpanContext_Impl, SvXMLImportContext );
1567 
1568 XMLImpSpanContext_Impl::XMLImpSpanContext_Impl(
1569         SvXMLImport& rImport,
1570         sal_uInt16 nPrfx,
1571         const OUString& rLName,
1572         const Reference< xml::sax::XAttributeList > & xAttrList,
1573         XMLHints_Impl& rHnts,
1574         sal_Bool& rIgnLeadSpace
1575     ,sal_uInt8              nSFConvFlags
1576                                               )
1577 :   SvXMLImportContext( rImport, nPrfx, rLName )
1578 ,   sTextFrame(RTL_CONSTASCII_USTRINGPARAM("TextFrame"))
1579 ,   rHints( rHnts )
1580 ,   pHint( 0  )
1581 ,   rIgnoreLeadingSpace( rIgnLeadSpace )
1582 ,   nStarFontsConvFlags( nSFConvFlags & (CONV_FROM_STAR_BATS|CONV_FROM_STAR_MATH) )
1583 {
1584     OUString aStyleName;
1585 
1586     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1587     for( sal_Int16 i=0; i < nAttrCount; i++ )
1588     {
1589         const OUString& rAttrName = xAttrList->getNameByIndex( i );
1590 
1591         OUString aLocalName;
1592         sal_uInt16 nPrefix =
1593             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
1594                                                             &aLocalName );
1595         if( XML_NAMESPACE_TEXT == nPrefix &&
1596             IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1597             aStyleName = xAttrList->getValueByIndex( i );
1598     }
1599 
1600     if( aStyleName.getLength() )
1601     {
1602         pHint = new XMLStyleHint_Impl( aStyleName,
1603                   GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
1604             rHints.Insert( pHint, rHints.Count() );
1605     }
1606 }
1607 
1608 XMLImpSpanContext_Impl::~XMLImpSpanContext_Impl()
1609 {
1610     if( pHint )
1611         pHint->SetEnd( GetImport().GetTextImport()
1612                             ->GetCursorAsRange()->getStart() );
1613 }
1614 
1615 SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
1616         SvXMLImport& rImport,
1617         sal_uInt16 nPrefix, const OUString& rLocalName,
1618         const Reference< xml::sax::XAttributeList > & xAttrList,
1619         sal_uInt16 nToken,
1620         XMLHints_Impl& rHints,
1621         sal_Bool& rIgnoreLeadingSpace
1622     ,sal_uInt8              nStarFontsConvFlags
1623      )
1624 {
1625     SvXMLImportContext *pContext = 0;
1626 
1627     switch( nToken )
1628     {
1629     case XML_TOK_TEXT_SPAN:
1630         pContext = new XMLImpSpanContext_Impl( rImport, nPrefix,
1631                                                rLocalName, xAttrList,
1632                                                rHints,
1633                                                rIgnoreLeadingSpace
1634                                                ,nStarFontsConvFlags
1635                                              );
1636         break;
1637 
1638     case XML_TOK_TEXT_TAB_STOP:
1639         pContext = new XMLCharContext( rImport, nPrefix,
1640                                                rLocalName, xAttrList,
1641                                                0x0009, sal_False );
1642         rIgnoreLeadingSpace = sal_False;
1643         break;
1644 
1645     case XML_TOK_TEXT_LINE_BREAK:
1646         pContext = new XMLCharContext( rImport, nPrefix,
1647                                                rLocalName, xAttrList,
1648                                                ControlCharacter::LINE_BREAK );
1649         rIgnoreLeadingSpace = sal_False;
1650         break;
1651 
1652     case XML_TOK_TEXT_S:
1653         pContext = new XMLCharContext( rImport, nPrefix,
1654                                                rLocalName, xAttrList,
1655                                                0x0020, sal_True );
1656         break;
1657 
1658     case XML_TOK_TEXT_HYPERLINK:
1659     {
1660         // test for HyperLinkURL property. If present, insert link as
1661         // text property (StarWriter), else try to insert as text
1662         // field (StarCalc, StarDraw, ...)
1663         Reference<beans::XPropertySet> xPropSet(
1664             rImport.GetTextImport()->GetCursor(),
1665             UNO_QUERY );
1666 
1667         const OUString sHyperLinkURL(
1668             RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL"));
1669 
1670         if (xPropSet->getPropertySetInfo()->hasPropertyByName(sHyperLinkURL))
1671         {
1672             pContext = new XMLImpHyperlinkContext_Impl( rImport, nPrefix,
1673                                                         rLocalName, xAttrList,
1674                                                         rHints,
1675                                                         rIgnoreLeadingSpace );
1676         }
1677         else
1678         {
1679             pContext = new XMLUrlFieldImportContext( rImport,
1680                                               *rImport.GetTextImport().get(),
1681                                                      nPrefix, rLocalName);
1682             //whitespace handling like other fields
1683             rIgnoreLeadingSpace = sal_False;
1684 
1685         }
1686         break;
1687     }
1688 
1689     case XML_TOK_TEXT_RUBY:
1690         pContext = new XMLImpRubyContext_Impl( rImport, nPrefix,
1691                                                rLocalName, xAttrList,
1692                                                rHints,
1693                                                rIgnoreLeadingSpace );
1694         break;
1695 
1696     case XML_TOK_TEXT_NOTE:
1697 #ifndef SVX_LIGHT
1698         if (rImport.GetTextImport()->IsInFrame())
1699         {
1700             // we must not insert footnotes into text frames
1701             pContext = new SvXMLImportContext( rImport, nPrefix,
1702                                                rLocalName );
1703         }
1704         else
1705         {
1706             pContext = new XMLFootnoteImportContext( rImport,
1707                                                      *rImport.GetTextImport().get(),
1708                                                      nPrefix, rLocalName );
1709         }
1710 #else
1711         // create default context to skip content
1712         pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName );
1713 #endif // #ifndef SVX_LIGHT
1714         rIgnoreLeadingSpace = sal_False;
1715         break;
1716 
1717     case XML_TOK_TEXT_REFERENCE:
1718     case XML_TOK_TEXT_BOOKMARK:
1719     case XML_TOK_TEXT_BOOKMARK_START:
1720     case XML_TOK_TEXT_BOOKMARK_END:
1721         pContext = new XMLTextMarkImportContext( rImport,
1722                                                  *rImport.GetTextImport().get(),
1723                                                  nPrefix, rLocalName );
1724         break;
1725 
1726     case XML_TOK_TEXT_FIELDMARK:
1727     case XML_TOK_TEXT_FIELDMARK_START:
1728     case XML_TOK_TEXT_FIELDMARK_END:
1729         pContext = new XMLTextMarkImportContext( rImport,
1730                                                  *rImport.GetTextImport().get(),
1731                                                  nPrefix, rLocalName );
1732         break;
1733 
1734     case XML_TOK_TEXT_REFERENCE_START:
1735         pContext = new XMLStartReferenceContext_Impl( rImport,
1736                                                       nPrefix, rLocalName,
1737                                                       rHints, xAttrList );
1738         break;
1739 
1740     case XML_TOK_TEXT_REFERENCE_END:
1741         pContext = new XMLEndReferenceContext_Impl( rImport,
1742                                                     nPrefix, rLocalName,
1743                                                     rHints, xAttrList );
1744         break;
1745 
1746     case XML_TOK_TEXT_FRAME:
1747         {
1748             Reference < XTextRange > xAnchorPos =
1749                 rImport.GetTextImport()->GetCursor()->getStart();
1750             XMLTextFrameContext *pTextFrameContext =
1751                 new XMLTextFrameContext( rImport, nPrefix,
1752                                          rLocalName, xAttrList,
1753                                          TextContentAnchorType_AS_CHARACTER );
1754             // --> OD 2004-08-24 #i33242# - remove check for text content.
1755             // Check for text content is done on the processing of the hint
1756             if( TextContentAnchorType_AT_CHARACTER ==
1757                                             pTextFrameContext->GetAnchorType() )
1758             // <--
1759             {
1760                 rHints.Insert( new XMLTextFrameHint_Impl(
1761                     pTextFrameContext, xAnchorPos ),
1762                     rHints.Count() );
1763             }
1764             pContext = pTextFrameContext;
1765             rIgnoreLeadingSpace = sal_False;
1766         }
1767         break;
1768     case XML_TOK_DRAW_A:
1769         {
1770             Reference < XTextRange > xAnchorPos(rImport.GetTextImport()->GetCursor()->getStart());
1771             pContext =
1772                 new XMLTextFrameHyperlinkContext( rImport, nPrefix,
1773                                         rLocalName, xAttrList,
1774                                         TextContentAnchorType_AS_CHARACTER );
1775             XMLTextFrameHint_Impl *pHint =
1776                 new XMLTextFrameHint_Impl( pContext, xAnchorPos);
1777             rHints.Insert( pHint, rHints.Count() );
1778         }
1779         break;
1780 
1781     case XML_TOK_TEXT_TOC_MARK:
1782     case XML_TOK_TEXT_TOC_MARK_START:
1783         pContext = new XMLTOCMarkImportContext_Impl(
1784             rImport, nPrefix, rLocalName,
1785             (enum XMLTextPElemTokens)nToken, rHints);
1786         break;
1787 
1788     case XML_TOK_TEXT_USER_INDEX_MARK:
1789     case XML_TOK_TEXT_USER_INDEX_MARK_START:
1790         pContext = new XMLUserIndexMarkImportContext_Impl(
1791             rImport, nPrefix, rLocalName,
1792             (enum XMLTextPElemTokens)nToken, rHints);
1793         break;
1794 
1795     case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1796     case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1797         pContext = new XMLAlphaIndexMarkImportContext_Impl(
1798             rImport, nPrefix, rLocalName,
1799             (enum XMLTextPElemTokens)nToken, rHints);
1800         break;
1801 
1802     case XML_TOK_TEXT_TOC_MARK_END:
1803     case XML_TOK_TEXT_USER_INDEX_MARK_END:
1804     case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1805         pContext = new XMLIndexMarkImportContext_Impl(
1806             rImport, nPrefix, rLocalName, (enum XMLTextPElemTokens)nToken,
1807             rHints);
1808         break;
1809 
1810     case XML_TOK_TEXTP_CHANGE_START:
1811     case XML_TOK_TEXTP_CHANGE_END:
1812     case XML_TOK_TEXTP_CHANGE:
1813         pContext = new XMLChangeImportContext(
1814             rImport, nPrefix, rLocalName,
1815             (nToken != XML_TOK_TEXTP_CHANGE_END),
1816             (nToken != XML_TOK_TEXTP_CHANGE_START),
1817             sal_False);
1818         break;
1819 
1820     case XML_TOK_TEXT_META:
1821         pContext = new XMLMetaImportContext(rImport, nPrefix, rLocalName,
1822             rHints, rIgnoreLeadingSpace );
1823         break;
1824 
1825     case XML_TOK_TEXT_META_FIELD:
1826         pContext = new XMLMetaFieldImportContext(rImport, nPrefix, rLocalName,
1827             rHints, rIgnoreLeadingSpace );
1828         break;
1829 
1830     default:
1831         // none of the above? then it's probably  a text field!
1832         pContext =
1833             XMLTextFieldImportContext::CreateTextFieldImportContext(
1834                 rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName,
1835                 nToken);
1836         // #108784# import draw elements (except control shapes in headers)
1837         if( pContext == NULL &&
1838             !( rImport.GetTextImport()->IsInHeaderFooter() &&
1839                nPrefix == XML_NAMESPACE_DRAW &&
1840                IsXMLToken( rLocalName, XML_CONTROL ) ) )
1841         {
1842             Reference < XShapes > xShapes;
1843             SvXMLShapeContext* pShapeContext = rImport.GetShapeImport()->CreateGroupChildContext(
1844                 rImport, nPrefix, rLocalName, xAttrList, xShapes );
1845             pContext = pShapeContext;
1846             // OD 2004-04-20 #i26791# - keep shape in a text frame hint to
1847             // adjust its anchor position, if its at-character anchored
1848             Reference < XTextRange > xAnchorPos =
1849                 rImport.GetTextImport()->GetCursor()->getStart();
1850             rHints.Insert( new XMLDrawHint_Impl( pShapeContext, xAnchorPos ),
1851                            rHints.Count() );
1852         }
1853         if( !pContext )
1854         {
1855             // ignore unknown content
1856             pContext =
1857                 new SvXMLImportContext( rImport, nPrefix, rLocalName );
1858         }
1859         // Behind fields, shapes and any unknown content blanks aren't ignored
1860         rIgnoreLeadingSpace = sal_False;
1861     }
1862 
1863     return pContext;
1864 }
1865 
1866 SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
1867         sal_uInt16 nPrefix, const OUString& rLocalName,
1868         const Reference< xml::sax::XAttributeList > & xAttrList )
1869 {
1870     const SvXMLTokenMap& rTokenMap =
1871         GetImport().GetTextImport()->GetTextPElemTokenMap();
1872     sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
1873 
1874     return CreateChildContext( GetImport(), nPrefix, rLocalName, xAttrList,
1875                                nToken, rHints, rIgnoreLeadingSpace
1876                                ,nStarFontsConvFlags
1877                              );
1878 }
1879 
1880 void XMLImpSpanContext_Impl::Characters( const OUString& rChars )
1881 {
1882     OUString sStyleName;
1883     if( pHint )
1884         sStyleName = pHint->GetStyleName();
1885     OUString sChars =
1886         GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
1887                                                        nStarFontsConvFlags,
1888                                                        sal_False, GetImport() );
1889     GetImport().GetTextImport()->InsertString( sChars, rIgnoreLeadingSpace );
1890 }
1891 
1892 // ---------------------------------------------------------------------
1893 
1894 TYPEINIT1( XMLParaContext, SvXMLImportContext );
1895 
1896 XMLParaContext::XMLParaContext(
1897         SvXMLImport& rImport,
1898         sal_uInt16 nPrfx,
1899         const OUString& rLName,
1900         const Reference< xml::sax::XAttributeList > & xAttrList,
1901         sal_Bool bHead ) :
1902     SvXMLImportContext( rImport, nPrfx, rLName ),
1903     xStart( rImport.GetTextImport()->GetCursorAsRange()->getStart() ),
1904     m_bHaveAbout(false),
1905     nOutlineLevel( IsXMLToken( rLName, XML_H ) ? 1 : -1 ),
1906     pHints( 0 ),
1907     // --> OD 2007-07-25 #i73509#
1908     mbOutlineLevelAttrFound( sal_False ),
1909     // <--
1910     bIgnoreLeadingSpace( sal_True ),
1911     bHeading( bHead ),
1912     bIsListHeader( false ),
1913     bIsRestart (false),
1914     nStartValue(0)
1915     ,nStarFontsConvFlags( 0 )
1916 {
1917     const SvXMLTokenMap& rTokenMap =
1918         GetImport().GetTextImport()->GetTextPAttrTokenMap();
1919 
1920     bool bHaveXmlId( false );
1921     OUString aCondStyleName, sClassNames;
1922 
1923     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1924     for( sal_Int16 i=0; i < nAttrCount; i++ )
1925     {
1926         const OUString& rAttrName = xAttrList->getNameByIndex( i );
1927         const OUString& rValue = xAttrList->getValueByIndex( i );
1928 
1929         OUString aLocalName;
1930         sal_uInt16 nPrefix =
1931             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
1932                                                             &aLocalName );
1933         switch( rTokenMap.Get( nPrefix, aLocalName ) )
1934         {
1935         case XML_TOK_TEXT_P_XMLID:
1936             m_sXmlId = rValue;
1937             bHaveXmlId = true;
1938             break;
1939         case XML_TOK_TEXT_P_ABOUT:
1940             m_sAbout = rValue;
1941             m_bHaveAbout = true;
1942             break;
1943         case XML_TOK_TEXT_P_PROPERTY:
1944             m_sProperty = rValue;
1945             break;
1946         case XML_TOK_TEXT_P_CONTENT:
1947             m_sContent = rValue;
1948             break;
1949         case XML_TOK_TEXT_P_DATATYPE:
1950             m_sDatatype = rValue;
1951             break;
1952         case XML_TOK_TEXT_P_TEXTID:
1953             if (!bHaveXmlId) { m_sXmlId = rValue; }
1954             break;
1955         case XML_TOK_TEXT_P_STYLE_NAME:
1956             sStyleName = rValue;
1957             break;
1958         case XML_TOK_TEXT_P_CLASS_NAMES:
1959             sClassNames = rValue;
1960             break;
1961         case XML_TOK_TEXT_P_COND_STYLE_NAME:
1962             aCondStyleName = rValue;
1963             break;
1964         case XML_TOK_TEXT_P_LEVEL:
1965             {
1966                 sal_Int32 nTmp = rValue.toInt32();
1967                 if( nTmp > 0L )
1968                 {
1969                     if( nTmp > 127 )
1970                         nTmp = 127;
1971                     nOutlineLevel = (sal_Int8)nTmp;
1972                 }
1973                 // --> OD 2007-07-25 #i73509#
1974                 mbOutlineLevelAttrFound = sal_True;
1975                 // <--
1976             }
1977             break;
1978         case XML_TOK_TEXT_P_IS_LIST_HEADER:
1979             {
1980                 sal_Bool bBool;
1981                 if( SvXMLUnitConverter::convertBool( bBool, rValue ) )
1982                 {
1983                     bIsListHeader = bBool;
1984                 }
1985             }
1986             break;
1987         case XML_TOK_TEXT_P_RESTART_NUMBERING:
1988             {
1989                 sal_Bool bBool;
1990                 if (SvXMLUnitConverter::convertBool(bBool, rValue))
1991                 {
1992                     bIsRestart = bBool;
1993                 }
1994             }
1995             break;
1996         case XML_TOK_TEXT_P_START_VALUE:
1997             {
1998                 nStartValue = sal::static_int_cast< sal_Int16 >(
1999                     rValue.toInt32());
2000             }
2001             break;
2002         }
2003     }
2004 
2005     if( aCondStyleName.getLength() )
2006         sStyleName = aCondStyleName;
2007     else if( sClassNames.getLength() )
2008     {
2009         sal_Int32 nDummy = 0;
2010         sStyleName = sClassNames.getToken( 0, ' ', nDummy );
2011     }
2012 }
2013 
2014 XMLParaContext::~XMLParaContext()
2015 {
2016     UniReference < XMLTextImportHelper > xTxtImport(
2017         GetImport().GetTextImport());
2018     Reference < XTextRange > xCrsrRange( xTxtImport->GetCursorAsRange() );
2019     if( !xCrsrRange.is() )
2020         return; // Robust (defect file)
2021     Reference < XTextRange > xEnd(xCrsrRange->getStart());
2022 
2023     // if we have an id set for this paragraph, get a cursor for this
2024     // paragraph and register it with the given identifier
2025     // FIXME: this is just temporary, and should be removed when
2026     // EditEngine paragraphs implement XMetadatable!
2027     if (m_sXmlId.getLength())
2028     {
2029         Reference < XTextCursor > xIdCursor( xTxtImport->GetText()->createTextCursorByRange( xStart ) );
2030         if( xIdCursor.is() )
2031         {
2032             xIdCursor->gotoRange( xEnd, sal_True );
2033             Reference< XInterface > xRef( xIdCursor, UNO_QUERY );
2034             GetImport().getInterfaceToIdentifierMapper().registerReference(
2035                 m_sXmlId, xRef);
2036         }
2037     }
2038 
2039     // insert a paragraph break
2040     xTxtImport->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH );
2041 
2042     // create a cursor that select the whole last paragraph
2043     Reference < XTextCursor > xAttrCursor(
2044         xTxtImport->GetText()->createTextCursorByRange( xStart ));
2045     if( !xAttrCursor.is() )
2046         return; // Robust (defect file)
2047     xAttrCursor->gotoRange( xEnd, sal_True );
2048 
2049     // xml:id for RDF metadata
2050     if (m_sXmlId.getLength() || m_bHaveAbout || m_sProperty.getLength())
2051     {
2052         try {
2053             const uno::Reference<container::XEnumerationAccess> xEA
2054                 (xAttrCursor, uno::UNO_QUERY_THROW);
2055             const uno::Reference<container::XEnumeration> xEnum(
2056                 xEA->createEnumeration(), uno::UNO_QUERY_THROW);
2057             OSL_ENSURE(xEnum->hasMoreElements(), "xml:id: no paragraph?");
2058             if (xEnum->hasMoreElements()) {
2059                 uno::Reference<rdf::XMetadatable> xMeta;
2060                 xEnum->nextElement() >>= xMeta;
2061                 OSL_ENSURE(xMeta.is(), "xml:id: not XMetadatable");
2062                 GetImport().SetXmlId(xMeta, m_sXmlId);
2063                 if (m_bHaveAbout)
2064                 {
2065                     GetImport().AddRDFa(xMeta,
2066                         m_sAbout, m_sProperty, m_sContent, m_sDatatype);
2067                 }
2068                 OSL_ENSURE(!xEnum->hasMoreElements(), "xml:id: > 1 paragraph?");
2069             }
2070         } catch (uno::Exception &) {
2071             OSL_TRACE("XMLParaContext::~XMLParaContext: exception");
2072         }
2073     }
2074 
2075     OUString const sCellParaStyleName(xTxtImport->GetCellParaStyleDefault());
2076     if( sCellParaStyleName.getLength() > 0 )
2077     {
2078         // --> OD 2007-08-16 #i80724#
2079         // suppress handling of outline and list attributes,
2080         // because of side effects of method <SetStyleAndAttrs(..)>
2081         xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
2082                                       sCellParaStyleName,
2083                                       sal_True,
2084                                       sal_False, -1, // suppress outline handling
2085                                       sal_False );   // suppress list attributes handling
2086         // <--
2087     }
2088 
2089     // #103445# for headings without style name, find the proper style
2090     if( bHeading && (sStyleName.getLength() == 0) )
2091         xTxtImport->FindOutlineStyleName( sStyleName, nOutlineLevel );
2092 
2093     // set style and hard attributes at the previous paragraph
2094     // --> OD 2007-07-25 #i73509# - add paramter <mbOutlineLevelAttrFound>
2095     sStyleName = xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
2096                                                sStyleName,
2097                                                sal_True,
2098                                                mbOutlineLevelAttrFound,
2099                                                bHeading ? nOutlineLevel : -1 );
2100     // <--
2101 
2102     // handle list style header
2103     if (bHeading && (bIsListHeader || bIsRestart))
2104     {
2105         Reference<XPropertySet> xPropSet( xAttrCursor, UNO_QUERY );
2106 
2107         if (xPropSet.is())
2108         {
2109             if (bIsListHeader)
2110             {
2111                 OUString sNumberingIsNumber
2112                     (RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber"));
2113                 if(xPropSet->getPropertySetInfo()->
2114                    hasPropertyByName(sNumberingIsNumber))
2115                 {
2116                     xPropSet->setPropertyValue
2117                         (sNumberingIsNumber, makeAny( false ) );
2118                 }
2119             }
2120             if (bIsRestart)
2121             {
2122                 OUString sParaIsNumberingRestart
2123                     (RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart"));
2124                 OUString sNumberingStartValue
2125                     (RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue"));
2126                 if (xPropSet->getPropertySetInfo()->
2127                     hasPropertyByName(sParaIsNumberingRestart))
2128                 {
2129                     xPropSet->setPropertyValue
2130                         (sParaIsNumberingRestart, makeAny(true));
2131                 }
2132 
2133                 if (xPropSet->getPropertySetInfo()->
2134                     hasPropertyByName(sNumberingStartValue))
2135                 {
2136                     xPropSet->setPropertyValue
2137                         (sNumberingStartValue, makeAny(nStartValue));
2138                 }
2139             }
2140 
2141         }
2142     }
2143 
2144     if( pHints && pHints->Count() )
2145     {
2146         for( sal_uInt16 i=0; i<pHints->Count(); i++ )
2147         {
2148             XMLHint_Impl *pHint = (*pHints)[i];
2149             xAttrCursor->gotoRange( pHint->GetStart(), sal_False );
2150             xAttrCursor->gotoRange( pHint->GetEnd(), sal_True );
2151             switch( pHint->GetType() )
2152             {
2153             case XML_HINT_STYLE:
2154                 {
2155                     const OUString& rStyleName =
2156                             ((XMLStyleHint_Impl *)pHint)->GetStyleName();
2157                     if( rStyleName.getLength() )
2158                         xTxtImport->SetStyleAndAttrs( GetImport(),
2159                                                       xAttrCursor, rStyleName,
2160                                                       sal_False );
2161                 }
2162                 break;
2163             case XML_HINT_REFERENCE:
2164                 {
2165                     const OUString& rRefName =
2166                             ((XMLReferenceHint_Impl *)pHint)->GetRefName();
2167                     if( rRefName.getLength() )
2168                     {
2169                         if( !pHint->GetEnd().is() )
2170                             pHint->SetEnd(xEnd);
2171 
2172                         // convert XCursor to XTextRange
2173                         Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2174 
2175                         // reference name uses rStyleName member
2176                         // borrow from XMLTextMarkImportContext
2177                         XMLTextMarkImportContext::CreateAndInsertMark(
2178                             GetImport(),
2179                             OUString(
2180                                 RTL_CONSTASCII_USTRINGPARAM(
2181                                     "com.sun.star.text.ReferenceMark")),
2182                             rRefName,
2183                             xRange);
2184                     }
2185                 }
2186                 break;
2187             case XML_HINT_HYPERLINK:
2188                 {
2189                     const XMLHyperlinkHint_Impl *pHHint =
2190                         (const XMLHyperlinkHint_Impl *)pHint;
2191                     xTxtImport->SetHyperlink( GetImport(),
2192                                               xAttrCursor,
2193                                               pHHint->GetHRef(),
2194                                               pHHint->GetName(),
2195                                               pHHint->GetTargetFrameName(),
2196                                               pHHint->GetStyleName(),
2197                                               pHHint->GetVisitedStyleName(),
2198                                               pHHint->GetEventsContext() );
2199                 }
2200                 break;
2201             case XML_HINT_INDEX_MARK:
2202                 {
2203                     Reference<beans::XPropertySet> xMark(
2204                         ((const XMLIndexMarkHint_Impl *)pHint)->GetMark());
2205                     Reference<XTextContent> xContent(xMark, UNO_QUERY);
2206                     Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2207                     xTxtImport->GetText()->insertTextContent(
2208                         xRange, xContent, sal_True );
2209                 }
2210                 break;
2211             case XML_HINT_TEXT_FRAME:
2212                 {
2213                     const XMLTextFrameHint_Impl *pFHint =
2214                         (const XMLTextFrameHint_Impl *)pHint;
2215                     // --> OD 2004-08-24 #i33242# - check for text content
2216                     Reference < XTextContent > xTextContent =
2217                                                     pFHint->GetTextContent();
2218                     if ( xTextContent.is() )
2219                     {
2220                         // OD 2004-04-20 #i26791#
2221                         Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2222                         if ( pFHint->IsBoundAtChar() )
2223                         {
2224                             xTextContent->attach( xRange );
2225                         }
2226                     }
2227                     // <--
2228                     // --> OD 2004-08-24 #i33242# - consider, that hint can
2229                     // also contain a shape - e.g. drawing object of type 'Text'.
2230                     else
2231                     {
2232                         Reference < XShape > xShape = pFHint->GetShape();
2233                         if ( xShape.is() )
2234                         {
2235                             // determine anchor type
2236                             Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
2237                             TextContentAnchorType eAnchorType =
2238                                             TextContentAnchorType_AT_PARAGRAPH;
2239                             {
2240                                 OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2241                                 Any aAny = xPropSet->getPropertyValue( sAnchorType );
2242                                 aAny >>= eAnchorType;
2243                             }
2244                             if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
2245                             {
2246                                 // set anchor position for at-character anchored objects
2247                                 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2248                                 Any aPos;
2249                                 aPos <<= xRange;
2250                                 OUString sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) );
2251                                 xPropSet->setPropertyValue(sTextRange, aPos);
2252                             }
2253                         }
2254                     }
2255                     // <--
2256                 }
2257                 break;
2258             // --> DVO, OD 2004-07-14 #i26791#
2259             case XML_HINT_DRAW:
2260                 {
2261                     const XMLDrawHint_Impl *pDHint =
2262                         static_cast<const XMLDrawHint_Impl*>(pHint);
2263                     // --> OD 2004-08-24 #i33242# - improvement: hint directly
2264                     // provides the shape.
2265                     Reference < XShape > xShape = pDHint->GetShape();
2266                     if ( xShape.is() )
2267                     {
2268                         // determine anchor type
2269                         Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
2270                         TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
2271                         {
2272                             OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2273                             Any aAny = xPropSet->getPropertyValue( sAnchorType );
2274                             aAny >>= eAnchorType;
2275                         }
2276                         if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
2277                         {
2278                             // set anchor position for at-character anchored objects
2279                             Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2280                             Any aPos;
2281                             aPos <<= xRange;
2282                             OUString sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) );
2283                             xPropSet->setPropertyValue(sTextRange, aPos);
2284                         }
2285                     }
2286                     // <--
2287                 }
2288                 break;
2289             // <--
2290 
2291             default:
2292                 DBG_ASSERT( !this, "What's this" );
2293                 break;
2294             }
2295         }
2296     }
2297     delete pHints;
2298 }
2299 
2300 SvXMLImportContext *XMLParaContext::CreateChildContext(
2301         sal_uInt16 nPrefix, const OUString& rLocalName,
2302         const Reference< xml::sax::XAttributeList > & xAttrList )
2303 {
2304     const SvXMLTokenMap& rTokenMap =
2305         GetImport().GetTextImport()->GetTextPElemTokenMap();
2306     sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
2307     if( !pHints )
2308         pHints = new XMLHints_Impl;
2309     return XMLImpSpanContext_Impl::CreateChildContext(
2310                                 GetImport(), nPrefix, rLocalName, xAttrList,
2311                                 nToken, *pHints, bIgnoreLeadingSpace
2312                                 , nStarFontsConvFlags
2313                                                      );
2314 }
2315 
2316 void XMLParaContext::Characters( const OUString& rChars )
2317 {
2318     OUString sChars =
2319         GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
2320                                                        nStarFontsConvFlags,
2321                                                        sal_True, GetImport() );
2322     GetImport().GetTextImport()->InsertString( sChars, bIgnoreLeadingSpace );
2323 }
2324 
2325 
2326 
2327 TYPEINIT1( XMLNumberedParaContext, SvXMLImportContext );
2328 
2329 XMLNumberedParaContext::XMLNumberedParaContext(
2330         SvXMLImport& i_rImport,
2331         sal_uInt16 i_nPrefix,
2332         const OUString& i_rLocalName,
2333         const Reference< xml::sax::XAttributeList > & i_xAttrList ) :
2334     SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName ),
2335     m_Level(0),
2336     m_StartValue(-1),
2337     m_ListId(),
2338     m_xNumRules()
2339 {
2340     ::rtl::OUString StyleName;
2341 
2342     const SvXMLTokenMap& rTokenMap(
2343         i_rImport.GetTextImport()->GetTextNumberedParagraphAttrTokenMap() );
2344 
2345     const sal_Int16 nAttrCount( i_xAttrList.is() ?
2346         i_xAttrList->getLength() : 0 );
2347     for ( sal_Int16 i=0; i < nAttrCount; i++ )
2348     {
2349         const ::rtl::OUString& rAttrName( i_xAttrList->getNameByIndex( i )  );
2350         const ::rtl::OUString& rValue   ( i_xAttrList->getValueByIndex( i ) );
2351 
2352         ::rtl::OUString aLocalName;
2353         const sal_uInt16 nPrefix(
2354             GetImport().GetNamespaceMap().GetKeyByAttrName(
2355                 rAttrName, &aLocalName ) );
2356         switch( rTokenMap.Get( nPrefix, aLocalName ) )
2357         {
2358             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_XMLID:
2359                 m_XmlId = rValue;
2360 //FIXME: there is no UNO API for lists
2361                 break;
2362             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LIST_ID:
2363                 m_ListId = rValue;
2364                 break;
2365             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LEVEL:
2366                 {
2367                     sal_Int32 nTmp = rValue.toInt32();
2368                     if ( nTmp >= 1 && nTmp <= SHRT_MAX ) {
2369                         m_Level = static_cast<sal_uInt16>(nTmp) - 1;
2370                     }
2371                 }
2372                 break;
2373             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_STYLE_NAME:
2374                 StyleName = rValue;
2375                 break;
2376             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_CONTINUE_NUMBERING:
2377                 // this attribute is deprecated
2378 //                ContinuteNumbering = IsXMLToken(rValue, XML_TRUE);
2379                 break;
2380             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_START_VALUE:
2381                 {
2382                     sal_Int32 nTmp = rValue.toInt32();
2383                     if ( nTmp >= 0 && nTmp <= SHRT_MAX ) {
2384                         m_StartValue = static_cast<sal_Int16>(nTmp);
2385                     }
2386                 }
2387                 break;
2388         }
2389     }
2390 
2391     XMLTextListsHelper& rTextListsHelper(
2392         i_rImport.GetTextImport()->GetTextListHelper() );
2393     if (!m_ListId.getLength()) {
2394         OSL_ENSURE( ! i_rImport.GetODFVersion().equalsAsciiL(
2395                         RTL_CONSTASCII_STRINGPARAM("1.2") ),
2396             "invalid numbered-paragraph: no list-id (1.2)");
2397         m_ListId = rTextListsHelper.GetNumberedParagraphListId(m_Level,
2398             StyleName);
2399         OSL_ENSURE(m_ListId.getLength(), "numbered-paragraph: no ListId");
2400         if (!m_ListId.getLength()) {
2401             return;
2402         }
2403     }
2404     m_xNumRules = rTextListsHelper.EnsureNumberedParagraph( i_rImport,
2405         m_ListId, m_Level, StyleName);
2406 
2407     OSL_ENSURE(m_xNumRules.is(), "numbered-paragraph: no NumRules");
2408 
2409     i_rImport.GetTextImport()->GetTextListHelper().PushListContext( this );
2410 }
2411 
2412 XMLNumberedParaContext::~XMLNumberedParaContext()
2413 {
2414 }
2415 
2416 void XMLNumberedParaContext::EndElement()
2417 {
2418     if (m_ListId.getLength()) {
2419         GetImport().GetTextImport()->PopListContext();
2420     }
2421 }
2422 
2423 SvXMLImportContext *XMLNumberedParaContext::CreateChildContext(
2424     sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
2425     const Reference< xml::sax::XAttributeList > & i_xAttrList )
2426 {
2427     SvXMLImportContext *pContext( 0 );
2428 
2429     if ( XML_NAMESPACE_TEXT == i_nPrefix )
2430     {
2431         bool bIsHeader( IsXMLToken( i_rLocalName, XML_H ) );
2432         if ( bIsHeader || IsXMLToken( i_rLocalName, XML_P ) )
2433         {
2434             pContext = new XMLParaContext( GetImport(),
2435                 i_nPrefix, i_rLocalName, i_xAttrList, bIsHeader );
2436 // ignore text:number       } else if (IsXMLToken( i_rLocalName, XML_NUMBER )) {
2437         }
2438     }
2439 
2440     if (!pContext) {
2441         pContext = SvXMLImportContext::CreateChildContext(
2442             i_nPrefix, i_rLocalName, i_xAttrList );
2443     }
2444 
2445     return pContext;
2446 }
2447