Update ooo320-m1
[ooovba.git] / xmloff / source / text / txtparai.cxx
blobe308f803cb9b6363343ea88dddd6ea695b27c86d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtparai.cxx,v $
10 * $Revision: 1.68.2.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "unointerfacetouniqueidentifiermapper.hxx"
34 #include <rtl/ustring.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <tools/debug.hxx>
38 #include <tools/string.hxx>
39 #include <svtools/svarray.hxx>
40 #include <com/sun/star/text/XTextFrame.hpp>
41 #include <com/sun/star/text/XTextCursor.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/beans/XPropertySetInfo.hpp>
44 #include <com/sun/star/text/ControlCharacter.hpp>
45 #include <com/sun/star/container/XIndexReplace.hpp>
46 #include <com/sun/star/drawing/XShapes.hpp>
47 #include <com/sun/star/container/XEnumerationAccess.hpp>
48 #include <com/sun/star/rdf/XMetadatable.hpp>
51 #include <xmloff/xmlictxt.hxx>
52 #include <xmloff/xmlimp.hxx>
53 #include <xmloff/xmltoken.hxx>
54 #include <xmloff/nmspmap.hxx>
55 #include "xmlnmspe.hxx"
56 #include <xmloff/txtimp.hxx>
57 #include "txtparai.hxx"
58 #include "txtfldi.hxx"
59 #include <xmloff/xmluconv.hxx>
60 #include "XMLFootnoteImportContext.hxx"
61 #include "XMLTextMarkImportContext.hxx"
62 #include "XMLTextFrameContext.hxx"
63 #include <xmloff/XMLCharContext.hxx>
64 #include "XMLTextFrameHyperlinkContext.hxx"
65 #include <xmloff/XMLEventsImportContext.hxx>
66 #include "XMLChangeImportContext.hxx"
67 #include "txtlists.hxx"
70 // OD 2004-04-21 #i26791#
71 #include <txtparaimphint.hxx>
72 typedef XMLHint_Impl *XMLHint_ImplPtr;
73 SV_DECL_PTRARR_DEL( XMLHints_Impl, XMLHint_ImplPtr, 5, 5 )
74 SV_IMPL_PTRARR( XMLHints_Impl, XMLHint_ImplPtr )
75 // OD 2004-04-21 #i26791#
76 #include <com/sun/star/beans/XPropertySet.hpp>
78 using ::rtl::OUString;
79 using ::rtl::OUStringBuffer;
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::uno;
83 using namespace ::com::sun::star::text;
84 using namespace ::com::sun::star::drawing;
85 using namespace ::com::sun::star::beans;
86 using namespace ::xmloff::token;
87 using ::com::sun::star::container::XEnumerationAccess;
88 using ::com::sun::star::container::XEnumeration;
91 TYPEINIT1( XMLCharContext, SvXMLImportContext );
93 XMLCharContext::XMLCharContext(
94 SvXMLImport& rImport,
95 sal_uInt16 nPrfx,
96 const OUString& rLName,
97 const Reference< xml::sax::XAttributeList > & xAttrList,
98 sal_Unicode c,
99 sal_Bool bCount ) :
100 SvXMLImportContext( rImport, nPrfx, rLName )
101 ,m_nControl(0)
102 ,m_nCount(1)
103 ,m_c(c)
105 if( bCount )
107 const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
108 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
109 for( sal_Int16 i=0; i < nAttrCount; i++ )
111 const OUString& rAttrName = xAttrList->getNameByIndex( i );
113 OUString aLocalName;
114 sal_uInt16 nPrefix =rMap.GetKeyByAttrName( rAttrName,&aLocalName );
115 if( XML_NAMESPACE_TEXT == nPrefix &&
116 IsXMLToken( aLocalName, XML_C ) )
118 sal_Int32 nTmp = xAttrList->getValueByIndex(i).toInt32();
119 if( nTmp > 0L )
121 if( nTmp > USHRT_MAX )
122 m_nCount = USHRT_MAX;
123 else
124 m_nCount = (sal_uInt16)nTmp;
131 XMLCharContext::XMLCharContext(
132 SvXMLImport& rImp,
133 sal_uInt16 nPrfx,
134 const OUString& rLName,
135 const Reference< xml::sax::XAttributeList > &,
136 sal_Int16 nControl ) :
137 SvXMLImportContext( rImp, nPrfx, rLName )
138 ,m_nControl(nControl)
139 ,m_nCount(0)
143 XMLCharContext::~XMLCharContext()
146 // -----------------------------------------------------------------------------
147 void XMLCharContext::EndElement()
149 if ( !m_nCount )
150 InsertControlCharacter( m_nControl );
151 else
153 if( 1U == m_nCount )
155 OUString sBuff( &m_c, 1 );
156 InsertString(sBuff);
158 else
160 OUStringBuffer sBuff( m_nCount );
161 while( m_nCount-- )
162 sBuff.append( &m_c, 1 );
164 InsertString(sBuff.makeStringAndClear() );
168 // -----------------------------------------------------------------------------
169 void XMLCharContext::InsertControlCharacter(sal_Int16 _nControl)
171 GetImport().GetTextImport()->InsertControlCharacter( _nControl );
173 void XMLCharContext::InsertString(const ::rtl::OUString& _sString)
175 GetImport().GetTextImport()->InsertString( _sString );
178 // ---------------------------------------------------------------------
180 /** import start of reference (<text:reference-start>) */
181 class XMLStartReferenceContext_Impl : public SvXMLImportContext
183 public:
184 TYPEINFO();
186 // Do everything in constructor. Well ...
187 XMLStartReferenceContext_Impl (
188 SvXMLImport& rImport,
189 sal_uInt16 nPrefix,
190 const OUString& rLocalName,
191 XMLHints_Impl& rHnts,
192 const Reference<xml::sax::XAttributeList> & xAttrList);
194 static sal_Bool FindName(
195 SvXMLImport& rImport,
196 const Reference<xml::sax::XAttributeList> & xAttrList,
197 OUString& rName);
200 TYPEINIT1( XMLStartReferenceContext_Impl, SvXMLImportContext );
202 XMLStartReferenceContext_Impl::XMLStartReferenceContext_Impl(
203 SvXMLImport& rImport,
204 sal_uInt16 nPrefix,
205 const OUString& rLocalName,
206 XMLHints_Impl& rHints,
207 const Reference<xml::sax::XAttributeList> & xAttrList) :
208 SvXMLImportContext(rImport, nPrefix, rLocalName)
210 OUString sName;
212 if (FindName(GetImport(), xAttrList, sName))
214 XMLHint_Impl* pHint = new XMLReferenceHint_Impl(
215 sName, rImport.GetTextImport()->GetCursor()->getStart() );
217 // degenerates to point reference, if no end is found!
218 pHint->SetEnd(rImport.GetTextImport()->GetCursor()->getStart() );
220 rHints.Insert(pHint, rHints.Count());
224 sal_Bool XMLStartReferenceContext_Impl::FindName(
225 SvXMLImport& rImport,
226 const Reference<xml::sax::XAttributeList> & xAttrList,
227 OUString& rName)
229 sal_Bool bNameOK( sal_False );
231 // find name attribute first
232 const sal_Int16 nLength( xAttrList->getLength() );
233 for (sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
235 OUString sLocalName;
236 const sal_uInt16 nPrefix = rImport.GetNamespaceMap().
237 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
238 &sLocalName );
240 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
241 IsXMLToken(sLocalName, XML_NAME) )
243 rName = xAttrList->getValueByIndex(nAttr);
244 bNameOK = sal_True;
248 return bNameOK;
251 // ---------------------------------------------------------------------
253 /** import end of reference (<text:reference-end>) */
254 class XMLEndReferenceContext_Impl : public SvXMLImportContext
256 public:
257 TYPEINFO();
259 // Do everything in constructor. Well ...
260 XMLEndReferenceContext_Impl(
261 SvXMLImport& rImport,
262 sal_uInt16 nPrefix,
263 const OUString& rLocalName,
264 XMLHints_Impl& rHnts,
265 const Reference<xml::sax::XAttributeList> & xAttrList);
268 TYPEINIT1( XMLEndReferenceContext_Impl, SvXMLImportContext );
270 XMLEndReferenceContext_Impl::XMLEndReferenceContext_Impl(
271 SvXMLImport& rImport,
272 sal_uInt16 nPrefix,
273 const OUString& rLocalName,
274 XMLHints_Impl& rHints,
275 const Reference<xml::sax::XAttributeList> & xAttrList) :
276 SvXMLImportContext(rImport, nPrefix, rLocalName)
278 OUString sName;
280 // borrow from XMLStartReferenceContext_Impl
281 if (XMLStartReferenceContext_Impl::FindName(GetImport(), xAttrList, sName))
283 // search for reference start
284 sal_uInt16 nCount = rHints.Count();
285 for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
287 XMLHint_Impl *pHint = rHints[nPos];
288 if ( pHint->IsReference() &&
289 sName.equals( ((XMLReferenceHint_Impl *)pHint)->GetRefName()) )
291 // set end and stop searching
292 pHint->SetEnd(GetImport().GetTextImport()->
293 GetCursor()->getStart() );
294 break;
297 // else: no start (in this paragraph) -> ignore
301 // ---------------------------------------------------------------------
303 class XMLImpSpanContext_Impl : public SvXMLImportContext
305 const OUString sTextFrame;
307 XMLHints_Impl& rHints;
308 XMLStyleHint_Impl *pHint;
310 sal_Bool& rIgnoreLeadingSpace;
312 sal_uInt8 nStarFontsConvFlags;
314 public:
316 TYPEINFO();
318 XMLImpSpanContext_Impl(
319 SvXMLImport& rImport,
320 sal_uInt16 nPrfx,
321 const OUString& rLName,
322 const Reference< xml::sax::XAttributeList > & xAttrList,
323 XMLHints_Impl& rHnts,
324 sal_Bool& rIgnLeadSpace
325 ,sal_uInt8 nSFConvFlags
328 virtual ~XMLImpSpanContext_Impl();
330 static SvXMLImportContext *CreateChildContext(
331 SvXMLImport& rImport,
332 sal_uInt16 nPrefix, const OUString& rLocalName,
333 const Reference< xml::sax::XAttributeList > & xAttrList,
334 sal_uInt16 nToken, XMLHints_Impl& rHnts,
335 sal_Bool& rIgnLeadSpace
336 ,sal_uInt8 nStarFontsConvFlags = 0
338 virtual SvXMLImportContext *CreateChildContext(
339 sal_uInt16 nPrefix, const OUString& rLocalName,
340 const Reference< xml::sax::XAttributeList > & xAttrList );
342 virtual void Characters( const OUString& rChars );
344 // ---------------------------------------------------------------------
346 class XMLImpHyperlinkContext_Impl : public SvXMLImportContext
348 XMLHints_Impl& rHints;
349 XMLHyperlinkHint_Impl *pHint;
351 sal_Bool& rIgnoreLeadingSpace;
353 public:
355 TYPEINFO();
357 XMLImpHyperlinkContext_Impl(
358 SvXMLImport& rImport,
359 sal_uInt16 nPrfx,
360 const OUString& rLName,
361 const Reference< xml::sax::XAttributeList > & xAttrList,
362 XMLHints_Impl& rHnts,
363 sal_Bool& rIgnLeadSpace );
365 virtual ~XMLImpHyperlinkContext_Impl();
367 virtual SvXMLImportContext *CreateChildContext(
368 sal_uInt16 nPrefix, const OUString& rLocalName,
369 const Reference< xml::sax::XAttributeList > & xAttrList );
371 virtual void Characters( const OUString& rChars );
374 TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext );
376 XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
377 SvXMLImport& rImport,
378 sal_uInt16 nPrfx,
379 const OUString& rLName,
380 const Reference< xml::sax::XAttributeList > & xAttrList,
381 XMLHints_Impl& rHnts,
382 sal_Bool& rIgnLeadSpace ) :
383 SvXMLImportContext( rImport, nPrfx, rLName ),
384 rHints( rHnts ),
385 pHint( new XMLHyperlinkHint_Impl(
386 GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) ),
387 rIgnoreLeadingSpace( rIgnLeadSpace )
389 OUString sShow;
390 const SvXMLTokenMap& rTokenMap =
391 GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
393 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
394 for( sal_Int16 i=0; i < nAttrCount; i++ )
396 const OUString& rAttrName = xAttrList->getNameByIndex( i );
397 const OUString& rValue = xAttrList->getValueByIndex( i );
399 OUString aLocalName;
400 sal_uInt16 nPrefix =
401 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
402 &aLocalName );
403 switch( rTokenMap.Get( nPrefix, aLocalName ) )
405 case XML_TOK_TEXT_HYPERLINK_HREF:
406 pHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
407 break;
408 case XML_TOK_TEXT_HYPERLINK_NAME:
409 pHint->SetName( rValue );
410 break;
411 case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
412 pHint->SetTargetFrameName( rValue );
413 break;
414 case XML_TOK_TEXT_HYPERLINK_SHOW:
415 sShow = rValue;
416 break;
417 case XML_TOK_TEXT_HYPERLINK_STYLE_NAME:
418 pHint->SetStyleName( rValue );
419 break;
420 case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME:
421 pHint->SetVisitedStyleName( rValue );
422 break;
426 if( sShow.getLength() && !pHint->GetTargetFrameName().getLength() )
428 if( IsXMLToken( sShow, XML_NEW ) )
429 pHint->SetTargetFrameName(
430 OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ) );
431 else if( IsXMLToken( sShow, XML_REPLACE ) )
432 pHint->SetTargetFrameName(
433 OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ) );
435 rHints.Insert( pHint, rHints.Count() );
438 XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
440 if( pHint )
441 pHint->SetEnd( GetImport().GetTextImport()
442 ->GetCursorAsRange()->getStart() );
445 SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
446 sal_uInt16 nPrefix, const OUString& rLocalName,
447 const Reference< xml::sax::XAttributeList > & xAttrList )
449 if ( (nPrefix == XML_NAMESPACE_OFFICE) &&
450 IsXMLToken(rLocalName, XML_EVENT_LISTENERS) )
452 XMLEventsImportContext* pCtxt = new XMLEventsImportContext(
453 GetImport(), nPrefix, rLocalName);
454 pHint->SetEventsContext(pCtxt);
455 return pCtxt;
457 else
459 const SvXMLTokenMap& rTokenMap =
460 GetImport().GetTextImport()->GetTextPElemTokenMap();
461 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
463 return XMLImpSpanContext_Impl::CreateChildContext(
464 GetImport(), nPrefix, rLocalName, xAttrList,
465 nToken, rHints, rIgnoreLeadingSpace );
469 void XMLImpHyperlinkContext_Impl::Characters( const OUString& rChars )
471 GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
474 // ---------------------------------------------------------------------
476 class XMLImpRubyBaseContext_Impl : public SvXMLImportContext
478 XMLHints_Impl& rHints;
480 sal_Bool& rIgnoreLeadingSpace;
482 public:
484 TYPEINFO();
486 XMLImpRubyBaseContext_Impl(
487 SvXMLImport& rImport,
488 sal_uInt16 nPrfx,
489 const OUString& rLName,
490 const Reference< xml::sax::XAttributeList > & xAttrList,
491 XMLHints_Impl& rHnts,
492 sal_Bool& rIgnLeadSpace );
494 virtual ~XMLImpRubyBaseContext_Impl();
496 virtual SvXMLImportContext *CreateChildContext(
497 sal_uInt16 nPrefix, const OUString& rLocalName,
498 const Reference< xml::sax::XAttributeList > & xAttrList );
500 virtual void Characters( const OUString& rChars );
503 TYPEINIT1( XMLImpRubyBaseContext_Impl, SvXMLImportContext );
505 XMLImpRubyBaseContext_Impl::XMLImpRubyBaseContext_Impl(
506 SvXMLImport& rImport,
507 sal_uInt16 nPrfx,
508 const OUString& rLName,
509 const Reference< xml::sax::XAttributeList > &,
510 XMLHints_Impl& rHnts,
511 sal_Bool& rIgnLeadSpace ) :
512 SvXMLImportContext( rImport, nPrfx, rLName ),
513 rHints( rHnts ),
514 rIgnoreLeadingSpace( rIgnLeadSpace )
518 XMLImpRubyBaseContext_Impl::~XMLImpRubyBaseContext_Impl()
522 SvXMLImportContext *XMLImpRubyBaseContext_Impl::CreateChildContext(
523 sal_uInt16 nPrefix, const OUString& rLocalName,
524 const Reference< xml::sax::XAttributeList > & xAttrList )
526 const SvXMLTokenMap& rTokenMap =
527 GetImport().GetTextImport()->GetTextPElemTokenMap();
528 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
530 return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), nPrefix,
531 rLocalName, xAttrList,
532 nToken, rHints, rIgnoreLeadingSpace );
535 void XMLImpRubyBaseContext_Impl::Characters( const OUString& rChars )
537 GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
540 // ---------------------------------------------------------------------
542 class XMLImpRubyContext_Impl : public SvXMLImportContext
544 XMLHints_Impl& rHints;
546 sal_Bool& rIgnoreLeadingSpace;
548 Reference < XTextRange > m_xStart;
549 OUString m_sStyleName;
550 OUString m_sTextStyleName;
551 OUString m_sText;
553 public:
555 TYPEINFO();
557 XMLImpRubyContext_Impl(
558 SvXMLImport& rImport,
559 sal_uInt16 nPrfx,
560 const OUString& rLName,
561 const Reference< xml::sax::XAttributeList > & xAttrList,
562 XMLHints_Impl& rHnts,
563 sal_Bool& rIgnLeadSpace );
565 virtual ~XMLImpRubyContext_Impl();
567 virtual SvXMLImportContext *CreateChildContext(
568 sal_uInt16 nPrefix, const OUString& rLocalName,
569 const Reference< xml::sax::XAttributeList > & xAttrList );
571 void SetTextStyleName( const OUString& s ) { m_sTextStyleName = s; }
572 void AppendText( const OUString& s ) { m_sText += s; }
575 // ---------------------------------------------------------------------
577 class XMLImpRubyTextContext_Impl : public SvXMLImportContext
579 XMLImpRubyContext_Impl & m_rRubyContext;
581 public:
583 TYPEINFO();
585 XMLImpRubyTextContext_Impl(
586 SvXMLImport& rImport,
587 sal_uInt16 nPrfx,
588 const OUString& rLName,
589 const Reference< xml::sax::XAttributeList > & xAttrList,
590 XMLImpRubyContext_Impl & rParent );
592 virtual ~XMLImpRubyTextContext_Impl();
594 virtual void Characters( const OUString& rChars );
597 TYPEINIT1( XMLImpRubyTextContext_Impl, SvXMLImportContext );
599 XMLImpRubyTextContext_Impl::XMLImpRubyTextContext_Impl(
600 SvXMLImport& rImport,
601 sal_uInt16 nPrfx,
602 const OUString& rLName,
603 const Reference< xml::sax::XAttributeList > & xAttrList,
604 XMLImpRubyContext_Impl & rParent )
605 : SvXMLImportContext( rImport, nPrfx, rLName )
606 , m_rRubyContext( rParent )
608 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
609 for( sal_Int16 i=0; i < nAttrCount; i++ )
611 const OUString& rAttrName = xAttrList->getNameByIndex( i );
612 const OUString& rValue = xAttrList->getValueByIndex( i );
614 OUString aLocalName;
615 sal_uInt16 nPrefix =
616 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
617 &aLocalName );
618 if( XML_NAMESPACE_TEXT == nPrefix &&
619 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
621 m_rRubyContext.SetTextStyleName( rValue );
622 break;
627 XMLImpRubyTextContext_Impl::~XMLImpRubyTextContext_Impl()
631 void XMLImpRubyTextContext_Impl::Characters( const OUString& rChars )
633 m_rRubyContext.AppendText( rChars );
636 // ---------------------------------------------------------------------
638 TYPEINIT1( XMLImpRubyContext_Impl, SvXMLImportContext );
640 XMLImpRubyContext_Impl::XMLImpRubyContext_Impl(
641 SvXMLImport& rImport,
642 sal_uInt16 nPrfx,
643 const OUString& rLName,
644 const Reference< xml::sax::XAttributeList > & xAttrList,
645 XMLHints_Impl& rHnts,
646 sal_Bool& rIgnLeadSpace ) :
647 SvXMLImportContext( rImport, nPrfx, rLName ),
648 rHints( rHnts ),
649 rIgnoreLeadingSpace( rIgnLeadSpace )
650 , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
652 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
653 for( sal_Int16 i=0; i < nAttrCount; i++ )
655 const OUString& rAttrName = xAttrList->getNameByIndex( i );
656 const OUString& rValue = xAttrList->getValueByIndex( i );
658 OUString aLocalName;
659 sal_uInt16 nPrefix =
660 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
661 &aLocalName );
662 if( XML_NAMESPACE_TEXT == nPrefix &&
663 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
665 m_sStyleName = rValue;
666 break;
671 XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl()
673 const UniReference < XMLTextImportHelper > xTextImport(
674 GetImport().GetTextImport());
675 const Reference < XTextCursor > xAttrCursor(
676 xTextImport->GetText()->createTextCursorByRange( m_xStart ));
677 xAttrCursor->gotoRange(xTextImport->GetCursorAsRange()->getStart(),
678 sal_True);
679 xTextImport->SetRuby( GetImport(), xAttrCursor,
680 m_sStyleName, m_sTextStyleName, m_sText );
683 SvXMLImportContext *XMLImpRubyContext_Impl::CreateChildContext(
684 sal_uInt16 nPrefix, const OUString& rLocalName,
685 const Reference< xml::sax::XAttributeList > & xAttrList )
687 SvXMLImportContext *pContext;
688 if( XML_NAMESPACE_TEXT == nPrefix )
690 if( IsXMLToken( rLocalName, XML_RUBY_BASE ) )
691 pContext = new XMLImpRubyBaseContext_Impl( GetImport(), nPrefix,
692 rLocalName,
693 xAttrList,
694 rHints,
695 rIgnoreLeadingSpace );
696 else if( IsXMLToken( rLocalName, XML_RUBY_TEXT ) )
697 pContext = new XMLImpRubyTextContext_Impl( GetImport(), nPrefix,
698 rLocalName,
699 xAttrList,
700 *this );
701 else
702 pContext = new SvXMLImportContext(
703 GetImport(), nPrefix, rLocalName );
705 else
706 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName,
707 xAttrList );
709 return pContext;
712 // ---------------------------------------------------------------------
714 /** for text:meta and text:meta-field
716 class XMLMetaImportContextBase : public SvXMLImportContext
718 XMLHints_Impl& m_rHints;
720 sal_Bool& m_rIgnoreLeadingSpace;
722 /// start position
723 Reference<XTextRange> m_xStart;
725 protected:
726 OUString m_XmlId;
728 public:
729 TYPEINFO();
731 XMLMetaImportContextBase(
732 SvXMLImport& i_rImport,
733 const sal_uInt16 i_nPrefix,
734 const OUString& i_rLocalName,
735 XMLHints_Impl& i_rHints,
736 sal_Bool & i_rIgnoreLeadingSpace );
738 virtual ~XMLMetaImportContextBase();
740 virtual void StartElement(
741 const Reference<xml::sax::XAttributeList> & i_xAttrList);
743 virtual void EndElement();
745 virtual SvXMLImportContext *CreateChildContext(
746 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
747 const Reference< xml::sax::XAttributeList > & i_xAttrList);
749 virtual void Characters( const OUString& i_rChars );
751 virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
752 OUString const & i_rLocalName, OUString const & i_rValue);
754 virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange)
755 = 0;
758 TYPEINIT1( XMLMetaImportContextBase, SvXMLImportContext );
760 XMLMetaImportContextBase::XMLMetaImportContextBase(
761 SvXMLImport& i_rImport,
762 const sal_uInt16 i_nPrefix,
763 const OUString& i_rLocalName,
764 XMLHints_Impl& i_rHints,
765 sal_Bool & i_rIgnoreLeadingSpace )
766 : SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName )
767 , m_rHints( i_rHints )
768 , m_rIgnoreLeadingSpace( i_rIgnoreLeadingSpace )
769 , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
773 XMLMetaImportContextBase::~XMLMetaImportContextBase()
777 void XMLMetaImportContextBase::StartElement(
778 const Reference<xml::sax::XAttributeList> & i_xAttrList)
780 const sal_Int16 nAttrCount(i_xAttrList.is() ? i_xAttrList->getLength() : 0);
781 for ( sal_Int16 i = 0; i < nAttrCount; ++i )
783 const OUString& rAttrName( i_xAttrList->getNameByIndex( i ) );
784 const OUString& rValue( i_xAttrList->getValueByIndex( i ) );
786 OUString sLocalName;
787 const sal_uInt16 nPrefix(
788 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
789 &sLocalName ));
790 ProcessAttribute(nPrefix, sLocalName, rValue);
794 void XMLMetaImportContextBase::EndElement()
796 OSL_ENSURE(m_xStart.is(), "no mxStart?");
797 if (!m_xStart.is()) return;
799 const Reference<XTextRange> xEndRange(
800 GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
802 // create range for insertion
803 const Reference<XTextCursor> xInsertionCursor(
804 GetImport().GetTextImport()->GetText()->createTextCursorByRange(
805 xEndRange) );
806 xInsertionCursor->gotoRange(m_xStart, sal_True);
808 const Reference<XTextRange> xInsertionRange(xInsertionCursor, UNO_QUERY);
810 InsertMeta(xInsertionRange);
813 SvXMLImportContext * XMLMetaImportContextBase::CreateChildContext(
814 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
815 const Reference< xml::sax::XAttributeList > & i_xAttrList )
817 const SvXMLTokenMap& rTokenMap(
818 GetImport().GetTextImport()->GetTextPElemTokenMap() );
819 const sal_uInt16 nToken( rTokenMap.Get( i_nPrefix, i_rLocalName ) );
821 return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), i_nPrefix,
822 i_rLocalName, i_xAttrList, nToken, m_rHints, m_rIgnoreLeadingSpace );
825 void XMLMetaImportContextBase::Characters( const OUString& i_rChars )
827 GetImport().GetTextImport()->InsertString(i_rChars, m_rIgnoreLeadingSpace);
830 void XMLMetaImportContextBase::ProcessAttribute(sal_uInt16 const i_nPrefix,
831 OUString const & i_rLocalName, OUString const & i_rValue)
833 if ( (XML_NAMESPACE_XML == i_nPrefix) && IsXMLToken(i_rLocalName, XML_ID) )
835 m_XmlId = i_rValue;
840 // ---------------------------------------------------------------------
842 /** text:meta */
843 class XMLMetaImportContext : public XMLMetaImportContextBase
845 // RDFa
846 bool m_bHaveAbout;
847 ::rtl::OUString m_sAbout;
848 ::rtl::OUString m_sProperty;
849 ::rtl::OUString m_sContent;
850 ::rtl::OUString m_sDatatype;
852 public:
853 TYPEINFO();
855 XMLMetaImportContext(
856 SvXMLImport& i_rImport,
857 const sal_uInt16 i_nPrefix,
858 const OUString& i_rLocalName,
859 XMLHints_Impl& i_rHints,
860 sal_Bool & i_rIgnoreLeadingSpace );
862 virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
863 OUString const & i_rLocalName, OUString const & i_rValue);
865 virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange);
868 TYPEINIT1( XMLMetaImportContext, XMLMetaImportContextBase );
870 XMLMetaImportContext::XMLMetaImportContext(
871 SvXMLImport& i_rImport,
872 const sal_uInt16 i_nPrefix,
873 const OUString& i_rLocalName,
874 XMLHints_Impl& i_rHints,
875 sal_Bool & i_rIgnoreLeadingSpace )
876 : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
877 i_rHints, i_rIgnoreLeadingSpace )
878 , m_bHaveAbout(false)
882 void XMLMetaImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
883 OUString const & i_rLocalName, OUString const & i_rValue)
885 if ( XML_NAMESPACE_XHTML == i_nPrefix )
887 // RDFa
888 if ( IsXMLToken( i_rLocalName, XML_ABOUT) )
890 m_sAbout = i_rValue;
891 m_bHaveAbout = true;
893 else if ( IsXMLToken( i_rLocalName, XML_PROPERTY) )
895 m_sProperty = i_rValue;
897 else if ( IsXMLToken( i_rLocalName, XML_CONTENT) )
899 m_sContent = i_rValue;
901 else if ( IsXMLToken( i_rLocalName, XML_DATATYPE) )
903 m_sDatatype = i_rValue;
906 else
908 XMLMetaImportContextBase::ProcessAttribute(
909 i_nPrefix, i_rLocalName, i_rValue);
913 void XMLMetaImportContext::InsertMeta(
914 const Reference<XTextRange> & i_xInsertionRange)
916 OSL_ENSURE(!m_bHaveAbout == !m_sProperty.getLength(),
917 "XMLMetaImportContext::InsertMeta: invalid RDFa?");
918 if (m_XmlId.getLength() || (m_bHaveAbout && m_sProperty.getLength()))
920 // insert mark
921 const uno::Reference<rdf::XMetadatable> xMeta(
922 XMLTextMarkImportContext::CreateAndInsertMark(
923 GetImport(),
924 OUString::createFromAscii(
925 "com.sun.star.text.InContentMetadata"),
926 OUString(),
927 i_xInsertionRange, m_XmlId),
928 uno::UNO_QUERY);
929 OSL_ENSURE(xMeta.is(), "cannot insert Meta?");
931 if (xMeta.is() && m_bHaveAbout)
933 GetImport().AddRDFa(xMeta,
934 m_sAbout, m_sProperty, m_sContent, m_sDatatype);
937 else
939 OSL_TRACE("invalid <text:meta>: no xml:id, no valid RDFa");
943 // ---------------------------------------------------------------------
945 /** text:meta-field */
946 class XMLMetaFieldImportContext : public XMLMetaImportContextBase
948 OUString m_DataStyleName;
950 public:
951 TYPEINFO();
953 XMLMetaFieldImportContext(
954 SvXMLImport& i_rImport,
955 const sal_uInt16 i_nPrefix,
956 const OUString& i_rLocalName,
957 XMLHints_Impl& i_rHints,
958 sal_Bool & i_rIgnoreLeadingSpace );
960 virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
961 OUString const & i_rLocalName, OUString const & i_rValue);
963 virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange);
966 TYPEINIT1( XMLMetaFieldImportContext, XMLMetaImportContextBase );
968 XMLMetaFieldImportContext::XMLMetaFieldImportContext(
969 SvXMLImport& i_rImport,
970 const sal_uInt16 i_nPrefix,
971 const OUString& i_rLocalName,
972 XMLHints_Impl& i_rHints,
973 sal_Bool & i_rIgnoreLeadingSpace )
974 : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
975 i_rHints, i_rIgnoreLeadingSpace )
979 void XMLMetaFieldImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
980 OUString const & i_rLocalName, OUString const & i_rValue)
982 if ( XML_NAMESPACE_STYLE == i_nPrefix &&
983 IsXMLToken( i_rLocalName, XML_DATA_STYLE_NAME ) )
985 m_DataStyleName = i_rValue;
987 else
989 XMLMetaImportContextBase::ProcessAttribute(
990 i_nPrefix, i_rLocalName, i_rValue);
994 void XMLMetaFieldImportContext::InsertMeta(
995 const Reference<XTextRange> & i_xInsertionRange)
997 if (m_XmlId.getLength()) // valid?
999 // insert mark
1000 const Reference<XPropertySet> xPropertySet(
1001 XMLTextMarkImportContext::CreateAndInsertMark(
1002 GetImport(),
1003 OUString::createFromAscii(
1004 "com.sun.star.text.textfield.MetadataField"),
1005 OUString(),
1006 i_xInsertionRange, m_XmlId),
1007 UNO_QUERY);
1008 OSL_ENSURE(xPropertySet.is(), "cannot insert MetaField?");
1009 if (!xPropertySet.is()) return;
1011 if (m_DataStyleName.getLength())
1013 sal_Bool isDefaultLanguage(sal_True);
1015 const sal_Int32 nKey( GetImport().GetTextImport()->GetDataStyleKey(
1016 m_DataStyleName, & isDefaultLanguage) );
1018 if (-1 != nKey)
1020 static ::rtl::OUString sPropertyIsFixedLanguage(
1021 ::rtl::OUString::createFromAscii("IsFixedLanguage") );
1022 Any any;
1023 any <<= nKey;
1024 xPropertySet->setPropertyValue(
1025 OUString::createFromAscii("NumberFormat"), any);
1026 if ( xPropertySet->getPropertySetInfo()->
1027 hasPropertyByName( sPropertyIsFixedLanguage ) )
1029 any <<= static_cast<bool>(!isDefaultLanguage);
1030 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage,
1031 any );
1036 else
1038 OSL_TRACE("invalid <text:meta-field>: no xml:id");
1043 // ---------------------------------------------------------------------
1047 * Process index marks.
1049 * All *-mark-end index marks should instantiate *this* class (because
1050 * it doesn't process attributes other than ID), while the *-mark and
1051 * *-mark-start classes should instantiate the apporpiate subclasses.
1053 class XMLIndexMarkImportContext_Impl : public SvXMLImportContext
1055 const OUString sAlternativeText;
1057 XMLHints_Impl& rHints;
1058 const enum XMLTextPElemTokens eToken;
1059 OUString sID;
1061 public:
1062 TYPEINFO();
1064 XMLIndexMarkImportContext_Impl(
1065 SvXMLImport& rImport,
1066 sal_uInt16 nPrefix,
1067 const OUString& rLocalName,
1068 enum XMLTextPElemTokens nTok,
1069 XMLHints_Impl& rHnts);
1071 void StartElement(const Reference<xml::sax::XAttributeList> & xAttrList);
1073 protected:
1075 /// process all attributes
1076 void ProcessAttributes(const Reference<xml::sax::XAttributeList> & xAttrList,
1077 Reference<beans::XPropertySet>& rPropSet);
1080 * All marks can be created immediatly. Since we don't care about
1081 * the element content, ProcessAttribute should set the properties
1082 * immediatly.
1084 * This method tolerates an empty PropertySet; subclasses however
1085 * are not expected to.
1087 virtual void ProcessAttribute(sal_uInt16 nNamespace,
1088 OUString sLocalName,
1089 OUString sValue,
1090 Reference<beans::XPropertySet>& rPropSet);
1092 static void GetServiceName(OUString& sServiceName,
1093 enum XMLTextPElemTokens nToken);
1095 sal_Bool CreateMark(Reference<beans::XPropertySet>& rPropSet,
1096 const OUString& rServiceName);
1100 TYPEINIT1( XMLIndexMarkImportContext_Impl, SvXMLImportContext );
1102 XMLIndexMarkImportContext_Impl::XMLIndexMarkImportContext_Impl(
1103 SvXMLImport& rImport,
1104 sal_uInt16 nPrefix,
1105 const OUString& rLocalName,
1106 enum XMLTextPElemTokens eTok,
1107 XMLHints_Impl& rHnts) :
1108 SvXMLImportContext(rImport, nPrefix, rLocalName),
1109 sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")),
1110 rHints(rHnts),
1111 eToken(eTok)
1115 void XMLIndexMarkImportContext_Impl::StartElement(
1116 const Reference<xml::sax::XAttributeList> & xAttrList)
1118 // get Cursor position (needed for all cases)
1119 Reference<XTextRange> xPos(
1120 GetImport().GetTextImport()->GetCursor()->getStart());
1121 Reference<beans::XPropertySet> xMark;
1123 switch (eToken)
1125 case XML_TOK_TEXT_TOC_MARK:
1126 case XML_TOK_TEXT_USER_INDEX_MARK:
1127 case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1129 // single mark: create mark and insert
1130 OUString sService;
1131 GetServiceName(sService, eToken);
1132 if (CreateMark(xMark, sService))
1134 ProcessAttributes(xAttrList, xMark);
1135 XMLHint_Impl* pHint = new XMLIndexMarkHint_Impl(xMark, xPos);
1136 rHints.Insert(pHint, rHints.Count());
1138 // else: can't create mark -> ignore
1139 break;
1142 case XML_TOK_TEXT_TOC_MARK_START:
1143 case XML_TOK_TEXT_USER_INDEX_MARK_START:
1144 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1146 // start: create mark and insert (if ID is found)
1147 OUString sService;
1148 GetServiceName(sService, eToken);
1149 if (CreateMark(xMark, sService))
1151 ProcessAttributes(xAttrList, xMark);
1152 if (sID.getLength() > 0)
1154 // process only if we find an ID
1155 XMLHint_Impl* pHint =
1156 new XMLIndexMarkHint_Impl(xMark, xPos, sID);
1157 rHints.Insert(pHint, rHints.Count());
1159 // else: no ID -> we'll never find the end -> ignore
1161 // else: can't create mark -> ignore
1162 break;
1165 case XML_TOK_TEXT_TOC_MARK_END:
1166 case XML_TOK_TEXT_USER_INDEX_MARK_END:
1167 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1169 // end: search for ID and set end of mark
1171 // call process attributes with empty XPropertySet:
1172 ProcessAttributes(xAttrList, xMark);
1173 if (sID.getLength() > 0)
1175 // if we have an ID, find the hint and set the end position
1176 sal_uInt16 nCount = rHints.Count();
1177 for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
1179 XMLHint_Impl *pHint = rHints[nPos];
1180 if ( pHint->IsIndexMark() &&
1181 sID.equals(
1182 ((XMLIndexMarkHint_Impl *)pHint)->GetID()) )
1184 // set end and stop searching
1185 pHint->SetEnd(xPos);
1186 break;
1190 // else: no ID -> ignore
1191 break;
1194 default:
1195 DBG_ERROR("unknown index mark type!");
1196 break;
1200 void XMLIndexMarkImportContext_Impl::ProcessAttributes(
1201 const Reference<xml::sax::XAttributeList> & xAttrList,
1202 Reference<beans::XPropertySet>& rPropSet)
1204 // process attributes
1205 sal_Int16 nLength = xAttrList->getLength();
1206 for(sal_Int16 i=0; i<nLength; i++)
1208 OUString sLocalName;
1209 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1210 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
1212 ProcessAttribute(nPrefix, sLocalName,
1213 xAttrList->getValueByIndex(i),
1214 rPropSet);
1218 void XMLIndexMarkImportContext_Impl::ProcessAttribute(
1219 sal_uInt16 nNamespace,
1220 OUString sLocalName,
1221 OUString sValue,
1222 Reference<beans::XPropertySet>& rPropSet)
1224 // we only know ID + string-value attribute;
1225 // (former: marks, latter: -start + -end-marks)
1226 // the remainder is handled in sub-classes
1227 switch (eToken)
1229 case XML_TOK_TEXT_TOC_MARK:
1230 case XML_TOK_TEXT_USER_INDEX_MARK:
1231 case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1232 if ( (XML_NAMESPACE_TEXT == nNamespace) &&
1233 IsXMLToken( sLocalName, XML_STRING_VALUE ) )
1235 rPropSet->setPropertyValue(sAlternativeText, uno::makeAny(sValue));
1237 // else: ignore!
1238 break;
1240 case XML_TOK_TEXT_TOC_MARK_START:
1241 case XML_TOK_TEXT_USER_INDEX_MARK_START:
1242 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1243 case XML_TOK_TEXT_TOC_MARK_END:
1244 case XML_TOK_TEXT_USER_INDEX_MARK_END:
1245 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1246 if ( (XML_NAMESPACE_TEXT == nNamespace) &&
1247 IsXMLToken( sLocalName, XML_ID ) )
1249 sID = sValue;
1251 // else: ignore
1252 break;
1254 default:
1255 DBG_ERROR("unknown index mark type!");
1256 break;
1260 static const sal_Char sAPI_com_sun_star_text_ContentIndexMark[] =
1261 "com.sun.star.text.ContentIndexMark";
1262 static const sal_Char sAPI_com_sun_star_text_UserIndexMark[] =
1263 "com.sun.star.text.UserIndexMark";
1264 static const sal_Char sAPI_com_sun_star_text_DocumentIndexMark[] =
1265 "com.sun.star.text.DocumentIndexMark";
1268 void XMLIndexMarkImportContext_Impl::GetServiceName(
1269 OUString& sServiceName,
1270 enum XMLTextPElemTokens eToken)
1272 switch (eToken)
1274 case XML_TOK_TEXT_TOC_MARK:
1275 case XML_TOK_TEXT_TOC_MARK_START:
1276 case XML_TOK_TEXT_TOC_MARK_END:
1278 OUString sTmp(RTL_CONSTASCII_USTRINGPARAM(
1279 sAPI_com_sun_star_text_ContentIndexMark));
1280 sServiceName = sTmp;
1281 break;
1284 case XML_TOK_TEXT_USER_INDEX_MARK:
1285 case XML_TOK_TEXT_USER_INDEX_MARK_START:
1286 case XML_TOK_TEXT_USER_INDEX_MARK_END:
1288 OUString sTmp(RTL_CONSTASCII_USTRINGPARAM(
1289 sAPI_com_sun_star_text_UserIndexMark));
1290 sServiceName = sTmp;
1291 break;
1294 case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1295 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1296 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1298 OUString sTmp(RTL_CONSTASCII_USTRINGPARAM(
1299 sAPI_com_sun_star_text_DocumentIndexMark));
1300 sServiceName = sTmp;
1301 break;
1304 default:
1306 DBG_ERROR("unknown index mark type!");
1307 OUString sTmp;
1308 sServiceName = sTmp;
1309 break;
1315 sal_Bool XMLIndexMarkImportContext_Impl::CreateMark(
1316 Reference<beans::XPropertySet>& rPropSet,
1317 const OUString& rServiceName)
1319 Reference<lang::XMultiServiceFactory>
1320 xFactory(GetImport().GetModel(), UNO_QUERY);
1322 if( xFactory.is() )
1324 Reference<beans::XPropertySet> xPropSet( xFactory->createInstance(rServiceName), UNO_QUERY );
1325 if (xPropSet.is())
1326 rPropSet = xPropSet;
1327 return sal_True;
1330 return sal_False;
1334 class XMLTOCMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1336 const OUString sLevel;
1338 public:
1339 TYPEINFO();
1341 XMLTOCMarkImportContext_Impl(
1342 SvXMLImport& rImport,
1343 sal_uInt16 nPrefix,
1344 const OUString& rLocalName,
1345 enum XMLTextPElemTokens nTok,
1346 XMLHints_Impl& rHnts);
1348 protected:
1350 /** process outline level */
1351 virtual void ProcessAttribute(sal_uInt16 nNamespace,
1352 OUString sLocalName,
1353 OUString sValue,
1354 Reference<beans::XPropertySet>& rPropSet);
1357 TYPEINIT1( XMLTOCMarkImportContext_Impl, XMLIndexMarkImportContext_Impl );
1360 XMLTOCMarkImportContext_Impl::XMLTOCMarkImportContext_Impl(
1361 SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1362 enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1363 XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1364 nTok, rHnts),
1365 sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
1369 void XMLTOCMarkImportContext_Impl::ProcessAttribute(
1370 sal_uInt16 nNamespace,
1371 OUString sLocalName,
1372 OUString sValue,
1373 Reference<beans::XPropertySet>& rPropSet)
1375 DBG_ASSERT(rPropSet.is(), "need PropertySet");
1377 if ((XML_NAMESPACE_TEXT == nNamespace) &&
1378 IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
1380 // ouline level: set Level property
1381 sal_Int32 nTmp;
1382 if ( SvXMLUnitConverter::convertNumber( nTmp, sValue )
1383 && nTmp >= 1
1384 && nTmp < GetImport().GetTextImport()->
1385 GetChapterNumbering()->getCount() )
1387 rPropSet->setPropertyValue(sLevel, uno::makeAny((sal_Int16)(nTmp - 1)));
1389 // else: value out of range -> ignore
1391 else
1393 // else: delegate to superclass
1394 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1395 nNamespace, sLocalName, sValue, rPropSet);
1399 class XMLUserIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1401 const OUString sUserIndexName;
1402 const OUString sLevel;
1404 public:
1405 TYPEINFO();
1407 XMLUserIndexMarkImportContext_Impl(
1408 SvXMLImport& rImport,
1409 sal_uInt16 nPrefix,
1410 const OUString& rLocalName,
1411 enum XMLTextPElemTokens nTok,
1412 XMLHints_Impl& rHnts);
1414 protected:
1416 /** process index name */
1417 virtual void ProcessAttribute(sal_uInt16 nNamespace,
1418 OUString sLocalName,
1419 OUString sValue,
1420 Reference<beans::XPropertySet>& rPropSet);
1423 TYPEINIT1( XMLUserIndexMarkImportContext_Impl, XMLIndexMarkImportContext_Impl);
1425 XMLUserIndexMarkImportContext_Impl::XMLUserIndexMarkImportContext_Impl(
1426 SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1427 enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1428 XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1429 nTok, rHnts),
1430 sUserIndexName(RTL_CONSTASCII_USTRINGPARAM("UserIndexName")),
1431 sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
1435 void XMLUserIndexMarkImportContext_Impl::ProcessAttribute(
1436 sal_uInt16 nNamespace, OUString sLocalName, OUString sValue,
1437 Reference<beans::XPropertySet>& rPropSet)
1439 if ( XML_NAMESPACE_TEXT == nNamespace )
1441 if ( IsXMLToken( sLocalName, XML_INDEX_NAME ) )
1443 rPropSet->setPropertyValue(sUserIndexName, uno::makeAny(sValue));
1445 else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
1447 // ouline level: set Level property
1448 sal_Int32 nTmp;
1449 if (SvXMLUnitConverter::convertNumber(
1450 nTmp, sValue, 0,
1451 GetImport().GetTextImport()->GetChapterNumbering()->getCount()))
1453 rPropSet->setPropertyValue(sLevel, uno::makeAny(static_cast<sal_Int16>(nTmp - 1)));
1455 // else: value out of range -> ignore
1457 else
1459 // else: unknown text property: delegate to super class
1460 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1461 nNamespace, sLocalName, sValue, rPropSet);
1464 else
1466 // else: unknown namespace: delegate to super class
1467 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1468 nNamespace, sLocalName, sValue, rPropSet);
1473 class XMLAlphaIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1475 const OUString sPrimaryKey;
1476 const OUString sSecondaryKey;
1477 const OUString sTextReading;
1478 const OUString sPrimaryKeyReading;
1479 const OUString sSecondaryKeyReading;
1480 const OUString sMainEntry;
1482 public:
1483 TYPEINFO();
1485 XMLAlphaIndexMarkImportContext_Impl(
1486 SvXMLImport& rImport,
1487 sal_uInt16 nPrefix,
1488 const OUString& rLocalName,
1489 enum XMLTextPElemTokens nTok,
1490 XMLHints_Impl& rHnts);
1492 protected:
1494 /** process primary + secondary keys */
1495 virtual void ProcessAttribute(sal_uInt16 nNamespace,
1496 OUString sLocalName,
1497 OUString sValue,
1498 Reference<beans::XPropertySet>& rPropSet);
1501 TYPEINIT1( XMLAlphaIndexMarkImportContext_Impl,
1502 XMLIndexMarkImportContext_Impl );
1504 XMLAlphaIndexMarkImportContext_Impl::XMLAlphaIndexMarkImportContext_Impl(
1505 SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1506 enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1507 XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1508 nTok, rHnts),
1509 sPrimaryKey(RTL_CONSTASCII_USTRINGPARAM("PrimaryKey")),
1510 sSecondaryKey(RTL_CONSTASCII_USTRINGPARAM("SecondaryKey")),
1511 sTextReading(RTL_CONSTASCII_USTRINGPARAM("TextReading")),
1512 sPrimaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("PrimaryKeyReading")),
1513 sSecondaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("SecondaryKeyReading")),
1514 sMainEntry(RTL_CONSTASCII_USTRINGPARAM("IsMainEntry"))
1518 void XMLAlphaIndexMarkImportContext_Impl::ProcessAttribute(
1519 sal_uInt16 nNamespace, OUString sLocalName, OUString sValue,
1520 Reference<beans::XPropertySet>& rPropSet)
1522 if (XML_NAMESPACE_TEXT == nNamespace)
1524 if ( IsXMLToken( sLocalName, XML_KEY1 ) )
1526 rPropSet->setPropertyValue(sPrimaryKey, uno::makeAny(sValue));
1528 else if ( IsXMLToken( sLocalName, XML_KEY2 ) )
1530 rPropSet->setPropertyValue(sSecondaryKey, uno::makeAny(sValue));
1532 else if ( IsXMLToken( sLocalName, XML_KEY1_PHONETIC ) )
1534 rPropSet->setPropertyValue(sPrimaryKeyReading, uno::makeAny(sValue));
1536 else if ( IsXMLToken( sLocalName, XML_KEY2_PHONETIC ) )
1538 rPropSet->setPropertyValue(sSecondaryKeyReading, uno::makeAny(sValue));
1540 else if ( IsXMLToken( sLocalName, XML_STRING_VALUE_PHONETIC ) )
1542 rPropSet->setPropertyValue(sTextReading, uno::makeAny(sValue));
1544 else if ( IsXMLToken( sLocalName, XML_MAIN_ENTRY ) )
1546 sal_Bool bMainEntry = sal_False, bTmp;
1548 if (SvXMLUnitConverter::convertBool(bTmp, sValue))
1549 bMainEntry = bTmp;
1551 rPropSet->setPropertyValue(sMainEntry, uno::makeAny(bMainEntry));
1553 else
1555 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1556 nNamespace, sLocalName, sValue, rPropSet);
1559 else
1561 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1562 nNamespace, sLocalName, sValue, rPropSet);
1567 // ---------------------------------------------------------------------
1569 TYPEINIT1( XMLImpSpanContext_Impl, SvXMLImportContext );
1571 XMLImpSpanContext_Impl::XMLImpSpanContext_Impl(
1572 SvXMLImport& rImport,
1573 sal_uInt16 nPrfx,
1574 const OUString& rLName,
1575 const Reference< xml::sax::XAttributeList > & xAttrList,
1576 XMLHints_Impl& rHnts,
1577 sal_Bool& rIgnLeadSpace
1578 ,sal_uInt8 nSFConvFlags
1580 : SvXMLImportContext( rImport, nPrfx, rLName )
1581 , sTextFrame(RTL_CONSTASCII_USTRINGPARAM("TextFrame"))
1582 , rHints( rHnts )
1583 , pHint( 0 )
1584 , rIgnoreLeadingSpace( rIgnLeadSpace )
1585 , nStarFontsConvFlags( nSFConvFlags & (CONV_FROM_STAR_BATS|CONV_FROM_STAR_MATH) )
1587 OUString aStyleName;
1589 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1590 for( sal_Int16 i=0; i < nAttrCount; i++ )
1592 const OUString& rAttrName = xAttrList->getNameByIndex( i );
1594 OUString aLocalName;
1595 sal_uInt16 nPrefix =
1596 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
1597 &aLocalName );
1598 if( XML_NAMESPACE_TEXT == nPrefix &&
1599 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1600 aStyleName = xAttrList->getValueByIndex( i );
1603 if( aStyleName.getLength() )
1605 pHint = new XMLStyleHint_Impl( aStyleName,
1606 GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
1607 rHints.Insert( pHint, rHints.Count() );
1611 XMLImpSpanContext_Impl::~XMLImpSpanContext_Impl()
1613 if( pHint )
1614 pHint->SetEnd( GetImport().GetTextImport()
1615 ->GetCursorAsRange()->getStart() );
1618 SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
1619 SvXMLImport& rImport,
1620 sal_uInt16 nPrefix, const OUString& rLocalName,
1621 const Reference< xml::sax::XAttributeList > & xAttrList,
1622 sal_uInt16 nToken,
1623 XMLHints_Impl& rHints,
1624 sal_Bool& rIgnoreLeadingSpace
1625 ,sal_uInt8 nStarFontsConvFlags
1628 SvXMLImportContext *pContext = 0;
1630 switch( nToken )
1632 case XML_TOK_TEXT_SPAN:
1633 pContext = new XMLImpSpanContext_Impl( rImport, nPrefix,
1634 rLocalName, xAttrList,
1635 rHints,
1636 rIgnoreLeadingSpace
1637 ,nStarFontsConvFlags
1639 break;
1641 case XML_TOK_TEXT_TAB_STOP:
1642 pContext = new XMLCharContext( rImport, nPrefix,
1643 rLocalName, xAttrList,
1644 0x0009, sal_False );
1645 rIgnoreLeadingSpace = sal_False;
1646 break;
1648 case XML_TOK_TEXT_LINE_BREAK:
1649 pContext = new XMLCharContext( rImport, nPrefix,
1650 rLocalName, xAttrList,
1651 ControlCharacter::LINE_BREAK );
1652 rIgnoreLeadingSpace = sal_False;
1653 break;
1655 case XML_TOK_TEXT_S:
1656 pContext = new XMLCharContext( rImport, nPrefix,
1657 rLocalName, xAttrList,
1658 0x0020, sal_True );
1659 break;
1661 case XML_TOK_TEXT_HYPERLINK:
1663 // test for HyperLinkURL property. If present, insert link as
1664 // text property (StarWriter), else try to insert as text
1665 // field (StarCalc, StarDraw, ...)
1666 Reference<beans::XPropertySet> xPropSet(
1667 rImport.GetTextImport()->GetCursor(),
1668 UNO_QUERY );
1670 const OUString sHyperLinkURL(
1671 RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL"));
1673 if (xPropSet->getPropertySetInfo()->hasPropertyByName(sHyperLinkURL))
1675 pContext = new XMLImpHyperlinkContext_Impl( rImport, nPrefix,
1676 rLocalName, xAttrList,
1677 rHints,
1678 rIgnoreLeadingSpace );
1680 else
1682 pContext = new XMLUrlFieldImportContext( rImport,
1683 *rImport.GetTextImport().get(),
1684 nPrefix, rLocalName);
1685 //whitespace handling like other fields
1686 rIgnoreLeadingSpace = sal_False;
1689 break;
1692 case XML_TOK_TEXT_RUBY:
1693 pContext = new XMLImpRubyContext_Impl( rImport, nPrefix,
1694 rLocalName, xAttrList,
1695 rHints,
1696 rIgnoreLeadingSpace );
1697 break;
1699 case XML_TOK_TEXT_NOTE:
1700 #ifndef SVX_LIGHT
1701 if (rImport.GetTextImport()->IsInFrame())
1703 // we must not insert footnotes into text frames
1704 pContext = new SvXMLImportContext( rImport, nPrefix,
1705 rLocalName );
1707 else
1709 pContext = new XMLFootnoteImportContext( rImport,
1710 *rImport.GetTextImport().get(),
1711 nPrefix, rLocalName );
1713 #else
1714 // create default context to skip content
1715 pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName );
1716 #endif // #ifndef SVX_LIGHT
1717 rIgnoreLeadingSpace = sal_False;
1718 break;
1720 case XML_TOK_TEXT_REFERENCE:
1721 case XML_TOK_TEXT_BOOKMARK:
1722 case XML_TOK_TEXT_BOOKMARK_START:
1723 case XML_TOK_TEXT_BOOKMARK_END:
1724 pContext = new XMLTextMarkImportContext( rImport,
1725 *rImport.GetTextImport().get(),
1726 nPrefix, rLocalName );
1727 break;
1729 case XML_TOK_TEXT_FIELDMARK:
1730 case XML_TOK_TEXT_FIELDMARK_START:
1731 case XML_TOK_TEXT_FIELDMARK_END:
1732 pContext = new XMLTextMarkImportContext( rImport,
1733 *rImport.GetTextImport().get(),
1734 nPrefix, rLocalName );
1735 break;
1737 case XML_TOK_TEXT_REFERENCE_START:
1738 pContext = new XMLStartReferenceContext_Impl( rImport,
1739 nPrefix, rLocalName,
1740 rHints, xAttrList );
1741 break;
1743 case XML_TOK_TEXT_REFERENCE_END:
1744 pContext = new XMLEndReferenceContext_Impl( rImport,
1745 nPrefix, rLocalName,
1746 rHints, xAttrList );
1747 break;
1749 case XML_TOK_TEXT_FRAME:
1751 Reference < XTextRange > xAnchorPos =
1752 rImport.GetTextImport()->GetCursor()->getStart();
1753 XMLTextFrameContext *pTextFrameContext =
1754 new XMLTextFrameContext( rImport, nPrefix,
1755 rLocalName, xAttrList,
1756 TextContentAnchorType_AS_CHARACTER );
1757 // --> OD 2004-08-24 #i33242# - remove check for text content.
1758 // Check for text content is done on the processing of the hint
1759 if( TextContentAnchorType_AT_CHARACTER ==
1760 pTextFrameContext->GetAnchorType() )
1761 // <--
1763 rHints.Insert( new XMLTextFrameHint_Impl(
1764 pTextFrameContext, xAnchorPos ),
1765 rHints.Count() );
1767 pContext = pTextFrameContext;
1768 rIgnoreLeadingSpace = sal_False;
1770 break;
1771 case XML_TOK_DRAW_A:
1773 Reference < XTextRange > xAnchorPos(rImport.GetTextImport()->GetCursor()->getStart());
1774 pContext =
1775 new XMLTextFrameHyperlinkContext( rImport, nPrefix,
1776 rLocalName, xAttrList,
1777 TextContentAnchorType_AS_CHARACTER );
1778 XMLTextFrameHint_Impl *pHint =
1779 new XMLTextFrameHint_Impl( pContext, xAnchorPos);
1780 rHints.Insert( pHint, rHints.Count() );
1782 break;
1784 case XML_TOK_TEXT_TOC_MARK:
1785 case XML_TOK_TEXT_TOC_MARK_START:
1786 pContext = new XMLTOCMarkImportContext_Impl(
1787 rImport, nPrefix, rLocalName,
1788 (enum XMLTextPElemTokens)nToken, rHints);
1789 break;
1791 case XML_TOK_TEXT_USER_INDEX_MARK:
1792 case XML_TOK_TEXT_USER_INDEX_MARK_START:
1793 pContext = new XMLUserIndexMarkImportContext_Impl(
1794 rImport, nPrefix, rLocalName,
1795 (enum XMLTextPElemTokens)nToken, rHints);
1796 break;
1798 case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1799 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1800 pContext = new XMLAlphaIndexMarkImportContext_Impl(
1801 rImport, nPrefix, rLocalName,
1802 (enum XMLTextPElemTokens)nToken, rHints);
1803 break;
1805 case XML_TOK_TEXT_TOC_MARK_END:
1806 case XML_TOK_TEXT_USER_INDEX_MARK_END:
1807 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1808 pContext = new XMLIndexMarkImportContext_Impl(
1809 rImport, nPrefix, rLocalName, (enum XMLTextPElemTokens)nToken,
1810 rHints);
1811 break;
1813 case XML_TOK_TEXTP_CHANGE_START:
1814 case XML_TOK_TEXTP_CHANGE_END:
1815 case XML_TOK_TEXTP_CHANGE:
1816 pContext = new XMLChangeImportContext(
1817 rImport, nPrefix, rLocalName,
1818 (nToken != XML_TOK_TEXTP_CHANGE_END),
1819 (nToken != XML_TOK_TEXTP_CHANGE_START),
1820 sal_False);
1821 break;
1823 case XML_TOK_TEXT_META:
1824 pContext = new XMLMetaImportContext(rImport, nPrefix, rLocalName,
1825 rHints, rIgnoreLeadingSpace );
1826 break;
1828 case XML_TOK_TEXT_META_FIELD:
1829 pContext = new XMLMetaFieldImportContext(rImport, nPrefix, rLocalName,
1830 rHints, rIgnoreLeadingSpace );
1831 break;
1833 default:
1834 // none of the above? then it's probably a text field!
1835 pContext =
1836 XMLTextFieldImportContext::CreateTextFieldImportContext(
1837 rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName,
1838 nToken);
1839 // #108784# import draw elements (except control shapes in headers)
1840 if( pContext == NULL &&
1841 !( rImport.GetTextImport()->IsInHeaderFooter() &&
1842 nPrefix == XML_NAMESPACE_DRAW &&
1843 IsXMLToken( rLocalName, XML_CONTROL ) ) )
1845 Reference < XShapes > xShapes;
1846 SvXMLShapeContext* pShapeContext = rImport.GetShapeImport()->CreateGroupChildContext(
1847 rImport, nPrefix, rLocalName, xAttrList, xShapes );
1848 pContext = pShapeContext;
1849 if (pContext) {
1850 // OD 2004-04-20 #i26791# - keep shape in a text frame hint to
1851 // adjust its anchor position, if its at-character anchored
1852 Reference < XTextRange > xAnchorPos =
1853 rImport.GetTextImport()->GetCursor()->getStart();
1854 rHints.Insert( new XMLDrawHint_Impl( pShapeContext, xAnchorPos ),
1855 rHints.Count() );
1858 if( !pContext )
1860 pContext=rImport.createUnknownContext(nPrefix, rLocalName, xAttrList);
1862 // Behind fields, shapes and any unknown content blanks aren't ignored
1863 rIgnoreLeadingSpace = sal_False;
1865 return pContext;
1868 SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
1869 sal_uInt16 nPrefix, const OUString& rLocalName,
1870 const Reference< xml::sax::XAttributeList > & xAttrList )
1872 const SvXMLTokenMap& rTokenMap =
1873 GetImport().GetTextImport()->GetTextPElemTokenMap();
1874 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
1876 return CreateChildContext( GetImport(), nPrefix, rLocalName, xAttrList,
1877 nToken, rHints, rIgnoreLeadingSpace
1878 ,nStarFontsConvFlags
1882 void XMLImpSpanContext_Impl::Characters( const OUString& rChars )
1884 OUString sStyleName;
1885 if( pHint )
1886 sStyleName = pHint->GetStyleName();
1887 OUString sChars =
1888 GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
1889 nStarFontsConvFlags,
1890 sal_False, GetImport() );
1891 GetImport().GetTextImport()->InsertString( sChars, rIgnoreLeadingSpace );
1894 // ---------------------------------------------------------------------
1896 TYPEINIT1( XMLParaContext, SvXMLImportContext );
1898 XMLParaContext::XMLParaContext(
1899 SvXMLImport& rImport,
1900 sal_uInt16 nPrfx,
1901 const OUString& rLName,
1902 const Reference< xml::sax::XAttributeList > & xAttrList,
1903 sal_Bool bHead ) :
1904 SvXMLImportContext( rImport, nPrfx, rLName ),
1905 xStart( rImport.GetTextImport()->GetCursorAsRange()->getStart() ),
1906 m_bHaveAbout(false),
1907 nOutlineLevel( IsXMLToken( rLName, XML_H ) ? 1 : -1 ),
1908 pHints( 0 ),
1909 // --> OD 2007-07-25 #i73509#
1910 mbOutlineLevelAttrFound( sal_False ),
1911 // <--
1912 bIgnoreLeadingSpace( sal_True ),
1913 bHeading( bHead ),
1914 bIsListHeader( false ),
1915 bIsRestart (false),
1916 nStartValue(0)
1917 ,nStarFontsConvFlags( 0 )
1919 const SvXMLTokenMap& rTokenMap =
1920 GetImport().GetTextImport()->GetTextPAttrTokenMap();
1922 OUString sStyleName, aCondStyleName, sClassNames;
1924 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1925 for( sal_Int16 i=0; i < nAttrCount; i++ )
1927 const OUString& rAttrName = xAttrList->getNameByIndex( i );
1928 const OUString& rValue = xAttrList->getValueByIndex( i );
1930 OUString aLocalName;
1931 sal_uInt16 nPrefix =
1932 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
1933 &aLocalName );
1934 switch( rTokenMap.Get( nPrefix, aLocalName ) )
1936 case XML_TOK_TEXT_P_XMLID:
1937 m_sXmlId = rValue;
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_STYLE_NAME:
1953 sStyleName = rValue;
1954 break;
1955 case XML_TOK_TEXT_P_CLASS_NAMES:
1956 sClassNames = rValue;
1957 break;
1958 case XML_TOK_TEXT_P_COND_STYLE_NAME:
1959 aCondStyleName = rValue;
1960 break;
1961 case XML_TOK_TEXT_P_LEVEL:
1963 sal_Int32 nTmp = rValue.toInt32();
1964 if( nTmp > 0L )
1966 if( nTmp > 127 )
1967 nTmp = 127;
1968 nOutlineLevel = (sal_Int8)nTmp;
1970 // --> OD 2007-07-25 #i73509#
1971 mbOutlineLevelAttrFound = sal_True;
1972 // <--
1974 break;
1975 case XML_TOK_TEXT_P_IS_LIST_HEADER:
1977 sal_Bool bBool;
1978 if( SvXMLUnitConverter::convertBool( bBool, rValue ) )
1980 bIsListHeader = bBool;
1983 break;
1984 case XML_TOK_TEXT_P_ID:
1985 sId = rValue;
1986 break;
1987 case XML_TOK_TEXT_P_RESTART_NUMBERING:
1989 sal_Bool bBool;
1990 if (SvXMLUnitConverter::convertBool(bBool, rValue))
1992 bIsRestart = bBool;
1995 break;
1996 case XML_TOK_TEXT_P_START_VALUE:
1998 nStartValue = sal::static_int_cast< sal_Int16 >(
1999 rValue.toInt32());
2001 break;
2004 m_sClassNames = sClassNames;
2005 if( aCondStyleName.getLength() )
2006 m_sStyleName = aCondStyleName;
2007 else {
2008 m_sStyleName = sStyleName;
2010 if (m_sStyleName.getLength()==0 && sClassNames.getLength()>0) {
2011 // so when we only have class names make sure the first styles
2012 // of the class names is the style name
2013 sal_Int32 nDummy = 0;
2014 m_sStyleName = m_sClassNames.getToken( 0, ' ', nDummy );
2015 m_sClassNames = m_sClassNames.copy(m_sStyleName.getLength()+1);
2019 XMLParaContext::~XMLParaContext()
2021 rtl::OUString sStyleName = m_sStyleName;
2022 UniReference < XMLTextImportHelper > xTxtImport(
2023 GetImport().GetTextImport());
2024 Reference < XTextRange > xCrsrRange( xTxtImport->GetCursorAsRange() );
2025 if( !xCrsrRange.is() )
2026 return; // Robust (defect file)
2027 Reference < XTextRange > xEnd(xCrsrRange->getStart());
2029 // if we have an id set for this paragraph, get a cursor for this
2030 // paragraph and register it with the given identifier
2031 if( sId.getLength() )
2033 Reference < XTextCursor > xIdCursor( xTxtImport->GetText()->createTextCursorByRange( xStart ) );
2034 if( xIdCursor.is() )
2036 xIdCursor->gotoRange( xEnd, sal_True );
2037 Reference< XInterface > xRef( xIdCursor, UNO_QUERY );
2038 GetImport().getInterfaceToIdentifierMapper().registerReference( sId, xRef );
2042 // insert a paragraph break
2043 xTxtImport->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH );
2045 // create a cursor that select the whole last paragraph
2046 Reference < XTextCursor > xAttrCursor(
2047 xTxtImport->GetText()->createTextCursorByRange( xStart ));
2048 if( !xAttrCursor.is() )
2049 return; // Robust (defect file)
2050 xAttrCursor->gotoRange( xEnd, sal_True );
2052 // xml:id for RDF metadata
2053 if (m_sXmlId.getLength() || m_bHaveAbout || m_sProperty.getLength())
2055 try {
2056 const uno::Reference<container::XEnumerationAccess> xEA
2057 (xAttrCursor, uno::UNO_QUERY_THROW);
2058 const uno::Reference<container::XEnumeration> xEnum(
2059 xEA->createEnumeration(), uno::UNO_QUERY_THROW);
2060 OSL_ENSURE(xEnum->hasMoreElements(), "xml:id: no paragraph?");
2061 if (xEnum->hasMoreElements()) {
2062 uno::Reference<rdf::XMetadatable> xMeta;
2063 xEnum->nextElement() >>= xMeta;
2064 OSL_ENSURE(xMeta.is(), "xml:id: not XMetadatable");
2065 GetImport().SetXmlId(xMeta, m_sXmlId);
2066 if (m_bHaveAbout)
2068 GetImport().AddRDFa(xMeta,
2069 m_sAbout, m_sProperty, m_sContent, m_sDatatype);
2071 OSL_ENSURE(!xEnum->hasMoreElements(), "xml:id: > 1 paragraph?");
2073 } catch (uno::Exception &) {
2074 OSL_TRACE("XMLParaContext::~XMLParaContext: exception");
2078 OUString sCellParaStyleName = xTxtImport->sCellParaStyleDefault;
2079 if( sCellParaStyleName.getLength() > 0 )
2081 // --> OD 2007-08-16 #i80724#
2082 // suppress handling of outline and list attributes,
2083 // because of side effects of method <SetStyleAndAttrs(..)>
2084 xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
2085 sCellParaStyleName,
2086 OUString(),
2087 sal_True,
2088 sal_False, -1, // suppress outline handling
2089 sal_False ); // suppress list attributes handling
2090 // <--
2093 // #103445# for headings without style name, find the proper style
2094 if( bHeading && (sStyleName.getLength() == 0) )
2095 xTxtImport->FindOutlineStyleName( sStyleName, nOutlineLevel );
2097 // set style and hard attributes at the previous paragraph
2098 // --> OD 2007-07-25 #i73509# - add paramter <mbOutlineLevelAttrFound>
2099 sStyleName = xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
2100 sStyleName,
2101 m_sClassNames,
2102 sal_True,
2103 mbOutlineLevelAttrFound,
2104 bHeading ? nOutlineLevel : -1 );
2105 // <--
2107 // handle list style header
2108 if (bHeading && (bIsListHeader || bIsRestart))
2110 Reference<XPropertySet> xPropSet( xAttrCursor, UNO_QUERY );
2112 if (xPropSet.is())
2114 if (bIsListHeader)
2116 OUString sNumberingIsNumber
2117 (RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber"));
2118 if(xPropSet->getPropertySetInfo()->
2119 hasPropertyByName(sNumberingIsNumber))
2121 xPropSet->setPropertyValue
2122 (sNumberingIsNumber, makeAny( false ) );
2125 if (bIsRestart)
2127 OUString sParaIsNumberingRestart
2128 (RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart"));
2129 OUString sNumberingStartValue
2130 (RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue"));
2131 if (xPropSet->getPropertySetInfo()->
2132 hasPropertyByName(sParaIsNumberingRestart))
2134 xPropSet->setPropertyValue
2135 (sParaIsNumberingRestart, makeAny(true));
2138 if (xPropSet->getPropertySetInfo()->
2139 hasPropertyByName(sNumberingStartValue))
2141 xPropSet->setPropertyValue
2142 (sNumberingStartValue, makeAny(nStartValue));
2149 if( pHints && pHints->Count() )
2151 for( sal_uInt16 i=0; i<pHints->Count(); i++ )
2153 XMLHint_Impl *pHint = (*pHints)[i];
2154 xAttrCursor->gotoRange( pHint->GetStart(), sal_False );
2155 xAttrCursor->gotoRange( pHint->GetEnd(), sal_True );
2156 switch( pHint->GetType() )
2158 case XML_HINT_STYLE:
2160 const OUString& rStyleName =
2161 ((XMLStyleHint_Impl *)pHint)->GetStyleName();
2162 if( rStyleName.getLength() )
2163 xTxtImport->SetStyleAndAttrs( GetImport(),
2164 xAttrCursor, rStyleName, OUString(),
2165 sal_False );
2167 break;
2168 case XML_HINT_REFERENCE:
2170 const OUString& rRefName =
2171 ((XMLReferenceHint_Impl *)pHint)->GetRefName();
2172 if( rRefName.getLength() )
2174 if( !pHint->GetEnd().is() )
2175 pHint->SetEnd(xEnd);
2177 // convert XCursor to XTextRange
2178 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2180 // reference name uses rStyleName member
2181 // borrow from XMLTextMarkImportContext
2182 XMLTextMarkImportContext::CreateAndInsertMark(
2183 GetImport(),
2184 OUString(
2185 RTL_CONSTASCII_USTRINGPARAM(
2186 "com.sun.star.text.ReferenceMark")),
2187 rRefName,
2188 xRange);
2191 break;
2192 case XML_HINT_HYPERLINK:
2194 const XMLHyperlinkHint_Impl *pHHint =
2195 (const XMLHyperlinkHint_Impl *)pHint;
2196 xTxtImport->SetHyperlink( GetImport(),
2197 xAttrCursor,
2198 pHHint->GetHRef(),
2199 pHHint->GetName(),
2200 pHHint->GetTargetFrameName(),
2201 pHHint->GetStyleName(),
2202 pHHint->GetVisitedStyleName(),
2203 pHHint->GetEventsContext() );
2205 break;
2206 case XML_HINT_INDEX_MARK:
2208 Reference<beans::XPropertySet> xMark(
2209 ((const XMLIndexMarkHint_Impl *)pHint)->GetMark());
2210 Reference<XTextContent> xContent(xMark, UNO_QUERY);
2211 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2212 xTxtImport->GetText()->insertTextContent(
2213 xRange, xContent, sal_True );
2215 break;
2216 case XML_HINT_TEXT_FRAME:
2218 const XMLTextFrameHint_Impl *pFHint =
2219 (const XMLTextFrameHint_Impl *)pHint;
2220 // --> OD 2004-08-24 #i33242# - check for text content
2221 Reference < XTextContent > xTextContent =
2222 pFHint->GetTextContent();
2223 if ( xTextContent.is() )
2225 // OD 2004-04-20 #i26791#
2226 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2227 if ( pFHint->IsBoundAtChar() )
2229 xTextContent->attach( xRange );
2232 // <--
2233 // --> OD 2004-08-24 #i33242# - consider, that hint can
2234 // also contain a shape - e.g. drawing object of type 'Text'.
2235 else
2237 Reference < XShape > xShape = pFHint->GetShape();
2238 if ( xShape.is() )
2240 // determine anchor type
2241 Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
2242 TextContentAnchorType eAnchorType =
2243 TextContentAnchorType_AT_PARAGRAPH;
2245 OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2246 Any aAny = xPropSet->getPropertyValue( sAnchorType );
2247 aAny >>= eAnchorType;
2249 if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
2251 // set anchor position for at-character anchored objects
2252 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2253 Any aPos;
2254 aPos <<= xRange;
2255 OUString sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) );
2256 xPropSet->setPropertyValue(sTextRange, aPos);
2260 // <--
2262 break;
2263 // --> DVO, OD 2004-07-14 #i26791#
2264 case XML_HINT_DRAW:
2266 const XMLDrawHint_Impl *pDHint =
2267 static_cast<const XMLDrawHint_Impl*>(pHint);
2268 // --> OD 2004-08-24 #i33242# - improvement: hint directly
2269 // provides the shape.
2270 Reference < XShape > xShape = pDHint->GetShape();
2271 if ( xShape.is() )
2273 // determine anchor type
2274 Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
2275 TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
2277 OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2278 Any aAny = xPropSet->getPropertyValue( sAnchorType );
2279 aAny >>= eAnchorType;
2281 if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
2283 // set anchor position for at-character anchored objects
2284 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2285 Any aPos;
2286 aPos <<= xRange;
2287 OUString sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) );
2288 xPropSet->setPropertyValue(sTextRange, aPos);
2291 // <--
2293 break;
2294 // <--
2296 default:
2297 DBG_ASSERT( !this, "What's this" );
2298 break;
2302 delete pHints;
2305 SvXMLImportContext *XMLParaContext::CreateChildContext(
2306 sal_uInt16 nPrefix, const OUString& rLocalName,
2307 const Reference< xml::sax::XAttributeList > & xAttrList )
2309 const SvXMLTokenMap& rTokenMap =
2310 GetImport().GetTextImport()->GetTextPElemTokenMap();
2311 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
2312 if( !pHints )
2313 pHints = new XMLHints_Impl;
2314 return XMLImpSpanContext_Impl::CreateChildContext(
2315 GetImport(), nPrefix, rLocalName, xAttrList,
2316 nToken, *pHints, bIgnoreLeadingSpace
2317 , nStarFontsConvFlags
2321 void XMLParaContext::Characters( const OUString& rChars )
2323 OUString sChars =
2324 GetImport().GetTextImport()->ConvertStarFonts( rChars, m_sStyleName,
2325 nStarFontsConvFlags,
2326 sal_True, GetImport() );
2327 GetImport().GetTextImport()->InsertString( sChars, bIgnoreLeadingSpace );
2332 TYPEINIT1( XMLNumberedParaContext, SvXMLImportContext );
2334 XMLNumberedParaContext::XMLNumberedParaContext(
2335 SvXMLImport& i_rImport,
2336 sal_uInt16 i_nPrefix,
2337 const OUString& i_rLocalName,
2338 const Reference< xml::sax::XAttributeList > & i_xAttrList ) :
2339 SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName ),
2340 m_Level(0),
2341 m_StartValue(-1),
2342 m_ListId(),
2343 m_xNumRules()
2345 ::rtl::OUString StyleName;
2347 const SvXMLTokenMap& rTokenMap(
2348 i_rImport.GetTextImport()->GetTextNumberedParagraphAttrTokenMap() );
2350 const sal_Int16 nAttrCount( i_xAttrList.is() ?
2351 i_xAttrList->getLength() : 0 );
2352 for ( sal_Int16 i=0; i < nAttrCount; i++ )
2354 const ::rtl::OUString& rAttrName( i_xAttrList->getNameByIndex( i ) );
2355 const ::rtl::OUString& rValue ( i_xAttrList->getValueByIndex( i ) );
2357 ::rtl::OUString aLocalName;
2358 const sal_uInt16 nPrefix(
2359 GetImport().GetNamespaceMap().GetKeyByAttrName(
2360 rAttrName, &aLocalName ) );
2361 switch( rTokenMap.Get( nPrefix, aLocalName ) )
2363 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_XMLID:
2364 m_XmlId = rValue;
2365 //FIXME: there is no UNO API for lists
2366 break;
2367 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LIST_ID:
2368 m_ListId = rValue;
2369 break;
2370 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LEVEL:
2372 sal_Int32 nTmp = rValue.toInt32();
2373 if ( nTmp >= 1 && nTmp <= SHRT_MAX ) {
2374 m_Level = static_cast<sal_uInt16>(nTmp) - 1;
2377 break;
2378 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_STYLE_NAME:
2379 StyleName = rValue;
2380 break;
2381 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_CONTINUE_NUMBERING:
2382 // this attribute is deprecated
2383 // ContinuteNumbering = IsXMLToken(rValue, XML_TRUE);
2384 break;
2385 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_START_VALUE:
2387 sal_Int32 nTmp = rValue.toInt32();
2388 if ( nTmp >= 0 && nTmp <= SHRT_MAX ) {
2389 m_StartValue = static_cast<sal_Int16>(nTmp);
2392 break;
2396 XMLTextListsHelper& rTextListsHelper(
2397 i_rImport.GetTextImport()->GetTextListHelper() );
2398 if (!m_ListId.getLength()) {
2399 OSL_ENSURE( ! i_rImport.GetODFVersion().equalsAsciiL(
2400 RTL_CONSTASCII_STRINGPARAM("1.2") ),
2401 "invalid numbered-paragraph: no list-id (1.2)");
2402 m_ListId = rTextListsHelper.GetNumberedParagraphListId(m_Level,
2403 StyleName);
2404 OSL_ENSURE(m_ListId.getLength(), "numbered-paragraph: no ListId");
2405 if (!m_ListId.getLength()) {
2406 return;
2409 m_xNumRules = rTextListsHelper.EnsureNumberedParagraph( i_rImport,
2410 m_ListId, m_Level, StyleName);
2412 OSL_ENSURE(m_xNumRules.is(), "numbered-paragraph: no NumRules");
2414 i_rImport.GetTextImport()->GetTextListHelper().PushListContext( this );
2417 XMLNumberedParaContext::~XMLNumberedParaContext()
2421 void XMLNumberedParaContext::EndElement()
2423 if (m_ListId.getLength()) {
2424 GetImport().GetTextImport()->PopListContext();
2428 SvXMLImportContext *XMLNumberedParaContext::CreateChildContext(
2429 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
2430 const Reference< xml::sax::XAttributeList > & i_xAttrList )
2432 SvXMLImportContext *pContext( 0 );
2434 if ( XML_NAMESPACE_TEXT == i_nPrefix )
2436 bool bIsHeader( IsXMLToken( i_rLocalName, XML_H ) );
2437 if ( bIsHeader || IsXMLToken( i_rLocalName, XML_P ) )
2439 pContext = new XMLParaContext( GetImport(),
2440 i_nPrefix, i_rLocalName, i_xAttrList, bIsHeader );
2441 // ignore text:number } else if (IsXMLToken( i_rLocalName, XML_NUMBER )) {
2445 if (!pContext) {
2446 pContext = SvXMLImportContext::CreateChildContext(
2447 i_nPrefix, i_rLocalName, i_xAttrList );
2450 return pContext;