fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / text / txtparai.cxx
bloba50aee001901970c444f642047a4e78bf7ea8add
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
21 #include <rtl/ustring.hxx>
22 #include <rtl/ustrbuf.hxx>
23 #include <tools/debug.hxx>
24 #include <boost/ptr_container/ptr_vector.hpp>
26 #include <com/sun/star/text/XTextFrame.hpp>
27 #include <com/sun/star/text/XTextCursor.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/XPropertySetInfo.hpp>
30 #include <com/sun/star/text/ControlCharacter.hpp>
31 #include <com/sun/star/container/XIndexReplace.hpp>
32 #include <com/sun/star/drawing/XShapes.hpp>
33 #include <com/sun/star/container/XEnumerationAccess.hpp>
34 #include <com/sun/star/rdf/XMetadatable.hpp>
36 #include <sax/tools/converter.hxx>
38 #include <xmloff/xmlictxt.hxx>
39 #include <xmloff/xmlimp.hxx>
40 #include <xmloff/xmltoken.hxx>
41 #include <xmloff/nmspmap.hxx>
42 #include "xmloff/xmlnmspe.hxx"
43 #include <xmloff/txtimp.hxx>
44 #include "txtparai.hxx"
45 #include "txtfldi.hxx"
46 #include "XMLFootnoteImportContext.hxx"
47 #include "XMLTextMarkImportContext.hxx"
48 #include "XMLTextFrameContext.hxx"
49 #include <xmloff/XMLCharContext.hxx>
50 #include "XMLTextFrameHyperlinkContext.hxx"
51 #include <xmloff/XMLEventsImportContext.hxx>
52 #include "XMLChangeImportContext.hxx"
53 #include "txtlists.hxx"
56 // OD 2004-04-21 #i26791#
57 #include <txtparaimphint.hxx>
58 class XMLHints_Impl : public boost::ptr_vector<XMLHint_Impl> {};
59 // OD 2004-04-21 #i26791#
62 using namespace ::com::sun::star;
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::text;
65 using namespace ::com::sun::star::drawing;
66 using namespace ::com::sun::star::beans;
67 using namespace ::xmloff::token;
68 using ::com::sun::star::container::XEnumerationAccess;
69 using ::com::sun::star::container::XEnumeration;
72 TYPEINIT1( XMLCharContext, SvXMLImportContext );
74 XMLCharContext::XMLCharContext(
75 SvXMLImport& rImport,
76 sal_uInt16 nPrfx,
77 const OUString& rLName,
78 const Reference< xml::sax::XAttributeList > & xAttrList,
79 sal_Unicode c,
80 sal_Bool bCount ) :
81 SvXMLImportContext( rImport, nPrfx, rLName )
82 ,m_nControl(0)
83 ,m_nCount(1)
84 ,m_c(c)
86 if( bCount )
88 const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
89 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
90 for( sal_Int16 i=0; i < nAttrCount; i++ )
92 const OUString& rAttrName = xAttrList->getNameByIndex( i );
94 OUString aLocalName;
95 sal_uInt16 nPrefix =rMap.GetKeyByAttrName( rAttrName,&aLocalName );
96 if( XML_NAMESPACE_TEXT == nPrefix &&
97 IsXMLToken( aLocalName, XML_C ) )
99 sal_Int32 nTmp = xAttrList->getValueByIndex(i).toInt32();
100 if( nTmp > 0L )
102 if( nTmp > USHRT_MAX )
103 m_nCount = USHRT_MAX;
104 else
105 m_nCount = (sal_uInt16)nTmp;
112 XMLCharContext::XMLCharContext(
113 SvXMLImport& rImp,
114 sal_uInt16 nPrfx,
115 const OUString& rLName,
116 const Reference< xml::sax::XAttributeList > &,
117 sal_Int16 nControl ) :
118 SvXMLImportContext( rImp, nPrfx, rLName )
119 ,m_nControl(nControl)
120 ,m_nCount(0)
124 XMLCharContext::~XMLCharContext()
127 // -----------------------------------------------------------------------------
128 void XMLCharContext::EndElement()
130 if ( !m_nCount )
131 InsertControlCharacter( m_nControl );
132 else
134 if( 1U == m_nCount )
136 OUString sBuff( &m_c, 1 );
137 InsertString(sBuff);
139 else
141 OUStringBuffer sBuff( m_nCount );
142 while( m_nCount-- )
143 sBuff.append( &m_c, 1 );
145 InsertString(sBuff.makeStringAndClear() );
149 // -----------------------------------------------------------------------------
150 void XMLCharContext::InsertControlCharacter(sal_Int16 _nControl)
152 GetImport().GetTextImport()->InsertControlCharacter( _nControl );
154 void XMLCharContext::InsertString(const OUString& _sString)
156 GetImport().GetTextImport()->InsertString( _sString );
159 // ---------------------------------------------------------------------
161 /** import start of reference (<text:reference-start>) */
162 class XMLStartReferenceContext_Impl : public SvXMLImportContext
164 public:
165 TYPEINFO();
167 // Do everything in constructor. Well ...
168 XMLStartReferenceContext_Impl (
169 SvXMLImport& rImport,
170 sal_uInt16 nPrefix,
171 const OUString& rLocalName,
172 XMLHints_Impl& rHnts,
173 const Reference<xml::sax::XAttributeList> & xAttrList);
175 static sal_Bool FindName(
176 SvXMLImport& rImport,
177 const Reference<xml::sax::XAttributeList> & xAttrList,
178 OUString& rName);
181 TYPEINIT1( XMLStartReferenceContext_Impl, SvXMLImportContext );
183 XMLStartReferenceContext_Impl::XMLStartReferenceContext_Impl(
184 SvXMLImport& rImport,
185 sal_uInt16 nPrefix,
186 const OUString& rLocalName,
187 XMLHints_Impl& rHints,
188 const Reference<xml::sax::XAttributeList> & xAttrList) :
189 SvXMLImportContext(rImport, nPrefix, rLocalName)
191 OUString sName;
193 if (FindName(GetImport(), xAttrList, sName))
195 XMLHint_Impl* pHint = new XMLReferenceHint_Impl(
196 sName, rImport.GetTextImport()->GetCursor()->getStart() );
198 // degenerates to point reference, if no end is found!
199 pHint->SetEnd(rImport.GetTextImport()->GetCursor()->getStart() );
201 rHints.push_back(pHint);
205 sal_Bool XMLStartReferenceContext_Impl::FindName(
206 SvXMLImport& rImport,
207 const Reference<xml::sax::XAttributeList> & xAttrList,
208 OUString& rName)
210 sal_Bool bNameOK( sal_False );
212 // find name attribute first
213 const sal_Int16 nLength( xAttrList->getLength() );
214 for (sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
216 OUString sLocalName;
217 const sal_uInt16 nPrefix = rImport.GetNamespaceMap().
218 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
219 &sLocalName );
221 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
222 IsXMLToken(sLocalName, XML_NAME) )
224 rName = xAttrList->getValueByIndex(nAttr);
225 bNameOK = sal_True;
229 return bNameOK;
232 // ---------------------------------------------------------------------
234 /** import end of reference (<text:reference-end>) */
235 class XMLEndReferenceContext_Impl : public SvXMLImportContext
237 public:
238 TYPEINFO();
240 // Do everything in constructor. Well ...
241 XMLEndReferenceContext_Impl(
242 SvXMLImport& rImport,
243 sal_uInt16 nPrefix,
244 const OUString& rLocalName,
245 XMLHints_Impl& rHnts,
246 const Reference<xml::sax::XAttributeList> & xAttrList);
249 TYPEINIT1( XMLEndReferenceContext_Impl, SvXMLImportContext );
251 XMLEndReferenceContext_Impl::XMLEndReferenceContext_Impl(
252 SvXMLImport& rImport,
253 sal_uInt16 nPrefix,
254 const OUString& rLocalName,
255 XMLHints_Impl& rHints,
256 const Reference<xml::sax::XAttributeList> & xAttrList) :
257 SvXMLImportContext(rImport, nPrefix, rLocalName)
259 OUString sName;
261 // borrow from XMLStartReferenceContext_Impl
262 if (XMLStartReferenceContext_Impl::FindName(GetImport(), xAttrList, sName))
264 // search for reference start
265 sal_uInt16 nCount = rHints.size();
266 for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
268 XMLHint_Impl *pHint = &rHints[nPos];
269 if ( pHint->IsReference() &&
270 sName.equals( ((XMLReferenceHint_Impl *)pHint)->GetRefName()) )
272 // set end and stop searching
273 pHint->SetEnd(GetImport().GetTextImport()->
274 GetCursor()->getStart() );
275 break;
278 // else: no start (in this paragraph) -> ignore
282 // ---------------------------------------------------------------------
284 class XMLImpSpanContext_Impl : public SvXMLImportContext
286 const OUString sTextFrame;
288 XMLHints_Impl& rHints;
289 XMLStyleHint_Impl *pHint;
291 sal_Bool& rIgnoreLeadingSpace;
293 sal_uInt8 nStarFontsConvFlags;
295 public:
297 TYPEINFO();
299 XMLImpSpanContext_Impl(
300 SvXMLImport& rImport,
301 sal_uInt16 nPrfx,
302 const OUString& rLName,
303 const Reference< xml::sax::XAttributeList > & xAttrList,
304 XMLHints_Impl& rHnts,
305 sal_Bool& rIgnLeadSpace
306 ,sal_uInt8 nSFConvFlags
309 virtual ~XMLImpSpanContext_Impl();
311 static SvXMLImportContext *CreateChildContext(
312 SvXMLImport& rImport,
313 sal_uInt16 nPrefix, const OUString& rLocalName,
314 const Reference< xml::sax::XAttributeList > & xAttrList,
315 sal_uInt16 nToken, XMLHints_Impl& rHnts,
316 sal_Bool& rIgnLeadSpace
317 ,sal_uInt8 nStarFontsConvFlags = 0
319 virtual SvXMLImportContext *CreateChildContext(
320 sal_uInt16 nPrefix, const OUString& rLocalName,
321 const Reference< xml::sax::XAttributeList > & xAttrList );
323 virtual void Characters( const OUString& rChars );
325 // ---------------------------------------------------------------------
327 class XMLImpHyperlinkContext_Impl : public SvXMLImportContext
329 XMLHints_Impl& rHints;
330 XMLHyperlinkHint_Impl *pHint;
332 sal_Bool& rIgnoreLeadingSpace;
334 public:
336 TYPEINFO();
338 XMLImpHyperlinkContext_Impl(
339 SvXMLImport& rImport,
340 sal_uInt16 nPrfx,
341 const OUString& rLName,
342 const Reference< xml::sax::XAttributeList > & xAttrList,
343 XMLHints_Impl& rHnts,
344 sal_Bool& rIgnLeadSpace );
346 virtual ~XMLImpHyperlinkContext_Impl();
348 virtual SvXMLImportContext *CreateChildContext(
349 sal_uInt16 nPrefix, const OUString& rLocalName,
350 const Reference< xml::sax::XAttributeList > & xAttrList );
352 virtual void Characters( const OUString& rChars );
355 TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext );
357 XMLImpHyperlinkContext_Impl::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 ) :
364 SvXMLImportContext( rImport, nPrfx, rLName ),
365 rHints( rHnts ),
366 pHint( new XMLHyperlinkHint_Impl(
367 GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) ),
368 rIgnoreLeadingSpace( rIgnLeadSpace )
370 OUString sShow;
371 const SvXMLTokenMap& rTokenMap =
372 GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
374 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
375 for( sal_Int16 i=0; i < nAttrCount; i++ )
377 const OUString& rAttrName = xAttrList->getNameByIndex( i );
378 const OUString& rValue = xAttrList->getValueByIndex( i );
380 OUString aLocalName;
381 sal_uInt16 nPrefix =
382 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
383 &aLocalName );
384 switch( rTokenMap.Get( nPrefix, aLocalName ) )
386 case XML_TOK_TEXT_HYPERLINK_HREF:
387 pHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
388 break;
389 case XML_TOK_TEXT_HYPERLINK_NAME:
390 pHint->SetName( rValue );
391 break;
392 case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
393 pHint->SetTargetFrameName( rValue );
394 break;
395 case XML_TOK_TEXT_HYPERLINK_SHOW:
396 sShow = rValue;
397 break;
398 case XML_TOK_TEXT_HYPERLINK_STYLE_NAME:
399 pHint->SetStyleName( rValue );
400 break;
401 case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME:
402 pHint->SetVisitedStyleName( rValue );
403 break;
407 if( !sShow.isEmpty() && pHint->GetTargetFrameName().isEmpty() )
409 if( IsXMLToken( sShow, XML_NEW ) )
410 pHint->SetTargetFrameName(
411 OUString( "_blank" ) );
412 else if( IsXMLToken( sShow, XML_REPLACE ) )
413 pHint->SetTargetFrameName(
414 OUString( "_self" ) );
416 rHints.push_back( pHint );
419 XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
421 if( pHint )
422 pHint->SetEnd( GetImport().GetTextImport()
423 ->GetCursorAsRange()->getStart() );
426 SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
427 sal_uInt16 nPrefix, const OUString& rLocalName,
428 const Reference< xml::sax::XAttributeList > & xAttrList )
430 if ( (nPrefix == XML_NAMESPACE_OFFICE) &&
431 IsXMLToken(rLocalName, XML_EVENT_LISTENERS) )
433 XMLEventsImportContext* pCtxt = new XMLEventsImportContext(
434 GetImport(), nPrefix, rLocalName);
435 pHint->SetEventsContext(pCtxt);
436 return pCtxt;
438 else
440 const SvXMLTokenMap& rTokenMap =
441 GetImport().GetTextImport()->GetTextPElemTokenMap();
442 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
444 return XMLImpSpanContext_Impl::CreateChildContext(
445 GetImport(), nPrefix, rLocalName, xAttrList,
446 nToken, rHints, rIgnoreLeadingSpace );
450 void XMLImpHyperlinkContext_Impl::Characters( const OUString& rChars )
452 GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
455 // ---------------------------------------------------------------------
457 class XMLImpRubyBaseContext_Impl : public SvXMLImportContext
459 XMLHints_Impl& rHints;
461 sal_Bool& rIgnoreLeadingSpace;
463 public:
465 TYPEINFO();
467 XMLImpRubyBaseContext_Impl(
468 SvXMLImport& rImport,
469 sal_uInt16 nPrfx,
470 const OUString& rLName,
471 const Reference< xml::sax::XAttributeList > & xAttrList,
472 XMLHints_Impl& rHnts,
473 sal_Bool& rIgnLeadSpace );
475 virtual ~XMLImpRubyBaseContext_Impl();
477 virtual SvXMLImportContext *CreateChildContext(
478 sal_uInt16 nPrefix, const OUString& rLocalName,
479 const Reference< xml::sax::XAttributeList > & xAttrList );
481 virtual void Characters( const OUString& rChars );
484 TYPEINIT1( XMLImpRubyBaseContext_Impl, SvXMLImportContext );
486 XMLImpRubyBaseContext_Impl::XMLImpRubyBaseContext_Impl(
487 SvXMLImport& rImport,
488 sal_uInt16 nPrfx,
489 const OUString& rLName,
490 const Reference< xml::sax::XAttributeList > &,
491 XMLHints_Impl& rHnts,
492 sal_Bool& rIgnLeadSpace ) :
493 SvXMLImportContext( rImport, nPrfx, rLName ),
494 rHints( rHnts ),
495 rIgnoreLeadingSpace( rIgnLeadSpace )
499 XMLImpRubyBaseContext_Impl::~XMLImpRubyBaseContext_Impl()
503 SvXMLImportContext *XMLImpRubyBaseContext_Impl::CreateChildContext(
504 sal_uInt16 nPrefix, const OUString& rLocalName,
505 const Reference< xml::sax::XAttributeList > & xAttrList )
507 const SvXMLTokenMap& rTokenMap =
508 GetImport().GetTextImport()->GetTextPElemTokenMap();
509 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
511 return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), nPrefix,
512 rLocalName, xAttrList,
513 nToken, rHints, rIgnoreLeadingSpace );
516 void XMLImpRubyBaseContext_Impl::Characters( const OUString& rChars )
518 GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
521 // ---------------------------------------------------------------------
523 class XMLImpRubyContext_Impl : public SvXMLImportContext
525 XMLHints_Impl& rHints;
527 sal_Bool& rIgnoreLeadingSpace;
529 Reference < XTextRange > m_xStart;
530 OUString m_sStyleName;
531 OUString m_sTextStyleName;
532 OUString m_sText;
534 public:
536 TYPEINFO();
538 XMLImpRubyContext_Impl(
539 SvXMLImport& rImport,
540 sal_uInt16 nPrfx,
541 const OUString& rLName,
542 const Reference< xml::sax::XAttributeList > & xAttrList,
543 XMLHints_Impl& rHnts,
544 sal_Bool& rIgnLeadSpace );
546 virtual ~XMLImpRubyContext_Impl();
548 virtual SvXMLImportContext *CreateChildContext(
549 sal_uInt16 nPrefix, const OUString& rLocalName,
550 const Reference< xml::sax::XAttributeList > & xAttrList );
552 void SetTextStyleName( const OUString& s ) { m_sTextStyleName = s; }
553 void AppendText( const OUString& s ) { m_sText += s; }
556 // ---------------------------------------------------------------------
558 class XMLImpRubyTextContext_Impl : public SvXMLImportContext
560 XMLImpRubyContext_Impl & m_rRubyContext;
562 public:
564 TYPEINFO();
566 XMLImpRubyTextContext_Impl(
567 SvXMLImport& rImport,
568 sal_uInt16 nPrfx,
569 const OUString& rLName,
570 const Reference< xml::sax::XAttributeList > & xAttrList,
571 XMLImpRubyContext_Impl & rParent );
573 virtual ~XMLImpRubyTextContext_Impl();
575 virtual void Characters( const OUString& rChars );
578 TYPEINIT1( XMLImpRubyTextContext_Impl, SvXMLImportContext );
580 XMLImpRubyTextContext_Impl::XMLImpRubyTextContext_Impl(
581 SvXMLImport& rImport,
582 sal_uInt16 nPrfx,
583 const OUString& rLName,
584 const Reference< xml::sax::XAttributeList > & xAttrList,
585 XMLImpRubyContext_Impl & rParent )
586 : SvXMLImportContext( rImport, nPrfx, rLName )
587 , m_rRubyContext( rParent )
589 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
590 for( sal_Int16 i=0; i < nAttrCount; i++ )
592 const OUString& rAttrName = xAttrList->getNameByIndex( i );
593 const OUString& rValue = xAttrList->getValueByIndex( i );
595 OUString aLocalName;
596 sal_uInt16 nPrefix =
597 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
598 &aLocalName );
599 if( XML_NAMESPACE_TEXT == nPrefix &&
600 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
602 m_rRubyContext.SetTextStyleName( rValue );
603 break;
608 XMLImpRubyTextContext_Impl::~XMLImpRubyTextContext_Impl()
612 void XMLImpRubyTextContext_Impl::Characters( const OUString& rChars )
614 m_rRubyContext.AppendText( rChars );
617 // ---------------------------------------------------------------------
619 TYPEINIT1( XMLImpRubyContext_Impl, SvXMLImportContext );
621 XMLImpRubyContext_Impl::XMLImpRubyContext_Impl(
622 SvXMLImport& rImport,
623 sal_uInt16 nPrfx,
624 const OUString& rLName,
625 const Reference< xml::sax::XAttributeList > & xAttrList,
626 XMLHints_Impl& rHnts,
627 sal_Bool& rIgnLeadSpace ) :
628 SvXMLImportContext( rImport, nPrfx, rLName ),
629 rHints( rHnts ),
630 rIgnoreLeadingSpace( rIgnLeadSpace )
631 , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
633 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
634 for( sal_Int16 i=0; i < nAttrCount; i++ )
636 const OUString& rAttrName = xAttrList->getNameByIndex( i );
637 const OUString& rValue = xAttrList->getValueByIndex( i );
639 OUString aLocalName;
640 sal_uInt16 nPrefix =
641 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
642 &aLocalName );
643 if( XML_NAMESPACE_TEXT == nPrefix &&
644 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
646 m_sStyleName = rValue;
647 break;
652 XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl()
654 const UniReference < XMLTextImportHelper > xTextImport(
655 GetImport().GetTextImport());
656 const Reference < XTextCursor > xAttrCursor(
657 xTextImport->GetText()->createTextCursorByRange( m_xStart ));
658 xAttrCursor->gotoRange(xTextImport->GetCursorAsRange()->getStart(),
659 sal_True);
660 xTextImport->SetRuby( GetImport(), xAttrCursor,
661 m_sStyleName, m_sTextStyleName, m_sText );
664 SvXMLImportContext *XMLImpRubyContext_Impl::CreateChildContext(
665 sal_uInt16 nPrefix, const OUString& rLocalName,
666 const Reference< xml::sax::XAttributeList > & xAttrList )
668 SvXMLImportContext *pContext;
669 if( XML_NAMESPACE_TEXT == nPrefix )
671 if( IsXMLToken( rLocalName, XML_RUBY_BASE ) )
672 pContext = new XMLImpRubyBaseContext_Impl( GetImport(), nPrefix,
673 rLocalName,
674 xAttrList,
675 rHints,
676 rIgnoreLeadingSpace );
677 else if( IsXMLToken( rLocalName, XML_RUBY_TEXT ) )
678 pContext = new XMLImpRubyTextContext_Impl( GetImport(), nPrefix,
679 rLocalName,
680 xAttrList,
681 *this );
682 else
683 pContext = new SvXMLImportContext(
684 GetImport(), nPrefix, rLocalName );
686 else
687 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName,
688 xAttrList );
690 return pContext;
693 // ---------------------------------------------------------------------
695 /** for text:meta and text:meta-field
697 class XMLMetaImportContextBase : public SvXMLImportContext
699 XMLHints_Impl& m_rHints;
701 sal_Bool& m_rIgnoreLeadingSpace;
703 /// start position
704 Reference<XTextRange> m_xStart;
706 protected:
707 OUString m_XmlId;
709 public:
710 TYPEINFO();
712 XMLMetaImportContextBase(
713 SvXMLImport& i_rImport,
714 const sal_uInt16 i_nPrefix,
715 const OUString& i_rLocalName,
716 XMLHints_Impl& i_rHints,
717 sal_Bool & i_rIgnoreLeadingSpace );
719 virtual ~XMLMetaImportContextBase();
721 virtual void StartElement(
722 const Reference<xml::sax::XAttributeList> & i_xAttrList);
724 virtual void EndElement();
726 virtual SvXMLImportContext *CreateChildContext(
727 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
728 const Reference< xml::sax::XAttributeList > & i_xAttrList);
730 virtual void Characters( const OUString& i_rChars );
732 virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
733 OUString const & i_rLocalName, OUString const & i_rValue);
735 virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange)
736 = 0;
739 TYPEINIT1( XMLMetaImportContextBase, SvXMLImportContext );
741 XMLMetaImportContextBase::XMLMetaImportContextBase(
742 SvXMLImport& i_rImport,
743 const sal_uInt16 i_nPrefix,
744 const OUString& i_rLocalName,
745 XMLHints_Impl& i_rHints,
746 sal_Bool & i_rIgnoreLeadingSpace )
747 : SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName )
748 , m_rHints( i_rHints )
749 , m_rIgnoreLeadingSpace( i_rIgnoreLeadingSpace )
750 , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
754 XMLMetaImportContextBase::~XMLMetaImportContextBase()
758 void XMLMetaImportContextBase::StartElement(
759 const Reference<xml::sax::XAttributeList> & i_xAttrList)
761 const sal_Int16 nAttrCount(i_xAttrList.is() ? i_xAttrList->getLength() : 0);
762 for ( sal_Int16 i = 0; i < nAttrCount; ++i )
764 const OUString& rAttrName( i_xAttrList->getNameByIndex( i ) );
765 const OUString& rValue( i_xAttrList->getValueByIndex( i ) );
767 OUString sLocalName;
768 const sal_uInt16 nPrefix(
769 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
770 &sLocalName ));
771 ProcessAttribute(nPrefix, sLocalName, rValue);
775 void XMLMetaImportContextBase::EndElement()
777 SAL_WARN_IF(!m_xStart.is(), "xmloff.text", "no mxStart?");
778 if (!m_xStart.is()) return;
780 const Reference<XTextRange> xEndRange(
781 GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
783 // create range for insertion
784 const Reference<XTextCursor> xInsertionCursor(
785 GetImport().GetTextImport()->GetText()->createTextCursorByRange(
786 xEndRange) );
787 xInsertionCursor->gotoRange(m_xStart, sal_True);
789 const Reference<XTextRange> xInsertionRange(xInsertionCursor, UNO_QUERY);
791 InsertMeta(xInsertionRange);
794 SvXMLImportContext * XMLMetaImportContextBase::CreateChildContext(
795 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
796 const Reference< xml::sax::XAttributeList > & i_xAttrList )
798 const SvXMLTokenMap& rTokenMap(
799 GetImport().GetTextImport()->GetTextPElemTokenMap() );
800 const sal_uInt16 nToken( rTokenMap.Get( i_nPrefix, i_rLocalName ) );
802 return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), i_nPrefix,
803 i_rLocalName, i_xAttrList, nToken, m_rHints, m_rIgnoreLeadingSpace );
806 void XMLMetaImportContextBase::Characters( const OUString& i_rChars )
808 GetImport().GetTextImport()->InsertString(i_rChars, m_rIgnoreLeadingSpace);
811 void XMLMetaImportContextBase::ProcessAttribute(sal_uInt16 const i_nPrefix,
812 OUString const & i_rLocalName, OUString const & i_rValue)
814 if ( (XML_NAMESPACE_XML == i_nPrefix) && IsXMLToken(i_rLocalName, XML_ID) )
816 m_XmlId = i_rValue;
821 // ---------------------------------------------------------------------
823 /** text:meta */
824 class XMLMetaImportContext : public XMLMetaImportContextBase
826 // RDFa
827 bool m_bHaveAbout;
828 OUString m_sAbout;
829 OUString m_sProperty;
830 OUString m_sContent;
831 OUString m_sDatatype;
833 public:
834 TYPEINFO();
836 XMLMetaImportContext(
837 SvXMLImport& i_rImport,
838 const sal_uInt16 i_nPrefix,
839 const OUString& i_rLocalName,
840 XMLHints_Impl& i_rHints,
841 sal_Bool & i_rIgnoreLeadingSpace );
843 virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
844 OUString const & i_rLocalName, OUString const & i_rValue);
846 virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange);
849 TYPEINIT1( XMLMetaImportContext, XMLMetaImportContextBase );
851 XMLMetaImportContext::XMLMetaImportContext(
852 SvXMLImport& i_rImport,
853 const sal_uInt16 i_nPrefix,
854 const OUString& i_rLocalName,
855 XMLHints_Impl& i_rHints,
856 sal_Bool & i_rIgnoreLeadingSpace )
857 : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
858 i_rHints, i_rIgnoreLeadingSpace )
859 , m_bHaveAbout(false)
863 void XMLMetaImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
864 OUString const & i_rLocalName, OUString const & i_rValue)
866 if ( XML_NAMESPACE_XHTML == i_nPrefix )
868 // RDFa
869 if ( IsXMLToken( i_rLocalName, XML_ABOUT) )
871 m_sAbout = i_rValue;
872 m_bHaveAbout = true;
874 else if ( IsXMLToken( i_rLocalName, XML_PROPERTY) )
876 m_sProperty = i_rValue;
878 else if ( IsXMLToken( i_rLocalName, XML_CONTENT) )
880 m_sContent = i_rValue;
882 else if ( IsXMLToken( i_rLocalName, XML_DATATYPE) )
884 m_sDatatype = i_rValue;
887 else
889 XMLMetaImportContextBase::ProcessAttribute(
890 i_nPrefix, i_rLocalName, i_rValue);
894 void XMLMetaImportContext::InsertMeta(
895 const Reference<XTextRange> & i_xInsertionRange)
897 SAL_WARN_IF(m_bHaveAbout == m_sProperty.isEmpty(), "xmloff.text", "XMLMetaImportContext::InsertMeta: invalid RDFa?");
898 if (!m_XmlId.isEmpty() || (m_bHaveAbout && !m_sProperty.isEmpty()))
900 // insert mark
901 const uno::Reference<rdf::XMetadatable> xMeta(
902 XMLTextMarkImportContext::CreateAndInsertMark(
903 GetImport(),
904 OUString(
905 "com.sun.star.text.InContentMetadata"),
906 OUString(),
907 i_xInsertionRange, m_XmlId),
908 uno::UNO_QUERY);
909 SAL_WARN_IF(!xMeta.is(), "xmloff.text", "cannot insert Meta?");
911 if (xMeta.is() && m_bHaveAbout)
913 GetImport().AddRDFa(xMeta,
914 m_sAbout, m_sProperty, m_sContent, m_sDatatype);
917 else
919 SAL_INFO("xmloff.text", "invalid <text:meta>: no xml:id, no valid RDFa");
923 // ---------------------------------------------------------------------
925 /** text:meta-field */
926 class XMLMetaFieldImportContext : public XMLMetaImportContextBase
928 OUString m_DataStyleName;
930 public:
931 TYPEINFO();
933 XMLMetaFieldImportContext(
934 SvXMLImport& i_rImport,
935 const sal_uInt16 i_nPrefix,
936 const OUString& i_rLocalName,
937 XMLHints_Impl& i_rHints,
938 sal_Bool & i_rIgnoreLeadingSpace );
940 virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
941 OUString const & i_rLocalName, OUString const & i_rValue);
943 virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange);
946 TYPEINIT1( XMLMetaFieldImportContext, XMLMetaImportContextBase );
948 XMLMetaFieldImportContext::XMLMetaFieldImportContext(
949 SvXMLImport& i_rImport,
950 const sal_uInt16 i_nPrefix,
951 const OUString& i_rLocalName,
952 XMLHints_Impl& i_rHints,
953 sal_Bool & i_rIgnoreLeadingSpace )
954 : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
955 i_rHints, i_rIgnoreLeadingSpace )
959 void XMLMetaFieldImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
960 OUString const & i_rLocalName, OUString const & i_rValue)
962 if ( XML_NAMESPACE_STYLE == i_nPrefix &&
963 IsXMLToken( i_rLocalName, XML_DATA_STYLE_NAME ) )
965 m_DataStyleName = i_rValue;
967 else
969 XMLMetaImportContextBase::ProcessAttribute(
970 i_nPrefix, i_rLocalName, i_rValue);
974 void XMLMetaFieldImportContext::InsertMeta(
975 const Reference<XTextRange> & i_xInsertionRange)
977 if (!m_XmlId.isEmpty()) // valid?
979 // insert mark
980 const Reference<XPropertySet> xPropertySet(
981 XMLTextMarkImportContext::CreateAndInsertMark(
982 GetImport(),
983 OUString(
984 "com.sun.star.text.textfield.MetadataField"),
985 OUString(),
986 i_xInsertionRange, m_XmlId),
987 UNO_QUERY);
988 SAL_WARN_IF(!xPropertySet.is(), "xmloff.text", "cannot insert MetaField?");
989 if (!xPropertySet.is()) return;
991 if (!m_DataStyleName.isEmpty())
993 sal_Bool isDefaultLanguage(sal_True);
995 const sal_Int32 nKey( GetImport().GetTextImport()->GetDataStyleKey(
996 m_DataStyleName, & isDefaultLanguage) );
998 if (-1 != nKey)
1000 static OUString sPropertyIsFixedLanguage(
1001 OUString("IsFixedLanguage") );
1002 Any any;
1003 any <<= nKey;
1004 xPropertySet->setPropertyValue(
1005 OUString("NumberFormat"), any);
1006 if ( xPropertySet->getPropertySetInfo()->
1007 hasPropertyByName( sPropertyIsFixedLanguage ) )
1009 any <<= static_cast<bool>(!isDefaultLanguage);
1010 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage,
1011 any );
1016 else
1018 SAL_INFO("xmloff.text", "invalid <text:meta-field>: no xml:id");
1023 // ---------------------------------------------------------------------
1027 * Process index marks.
1029 * All *-mark-end index marks should instantiate *this* class (because
1030 * it doesn't process attributes other than ID), while the *-mark and
1031 * *-mark-start classes should instantiate the apporpiate subclasses.
1033 class XMLIndexMarkImportContext_Impl : public SvXMLImportContext
1035 const OUString sAlternativeText;
1037 XMLHints_Impl& rHints;
1038 const enum XMLTextPElemTokens eToken;
1039 OUString sID;
1041 public:
1042 TYPEINFO();
1044 XMLIndexMarkImportContext_Impl(
1045 SvXMLImport& rImport,
1046 sal_uInt16 nPrefix,
1047 const OUString& rLocalName,
1048 enum XMLTextPElemTokens nTok,
1049 XMLHints_Impl& rHnts);
1051 void StartElement(const Reference<xml::sax::XAttributeList> & xAttrList);
1053 protected:
1055 /// process all attributes
1056 void ProcessAttributes(const Reference<xml::sax::XAttributeList> & xAttrList,
1057 Reference<beans::XPropertySet>& rPropSet);
1060 * All marks can be created immediately. Since we don't care about
1061 * the element content, ProcessAttribute should set the properties
1062 * immediately.
1064 * This method tolerates an empty PropertySet; subclasses however
1065 * are not expected to.
1067 virtual void ProcessAttribute(sal_uInt16 nNamespace,
1068 OUString sLocalName,
1069 OUString sValue,
1070 Reference<beans::XPropertySet>& rPropSet);
1072 static void GetServiceName(OUString& sServiceName,
1073 enum XMLTextPElemTokens nToken);
1075 sal_Bool CreateMark(Reference<beans::XPropertySet>& rPropSet,
1076 const OUString& rServiceName);
1080 TYPEINIT1( XMLIndexMarkImportContext_Impl, SvXMLImportContext );
1082 XMLIndexMarkImportContext_Impl::XMLIndexMarkImportContext_Impl(
1083 SvXMLImport& rImport,
1084 sal_uInt16 nPrefix,
1085 const OUString& rLocalName,
1086 enum XMLTextPElemTokens eTok,
1087 XMLHints_Impl& rHnts) :
1088 SvXMLImportContext(rImport, nPrefix, rLocalName),
1089 sAlternativeText("AlternativeText"),
1090 rHints(rHnts),
1091 eToken(eTok)
1095 void XMLIndexMarkImportContext_Impl::StartElement(
1096 const Reference<xml::sax::XAttributeList> & xAttrList)
1098 // get Cursor position (needed for all cases)
1099 Reference<XTextRange> xPos(
1100 GetImport().GetTextImport()->GetCursor()->getStart());
1101 Reference<beans::XPropertySet> xMark;
1103 switch (eToken)
1105 case XML_TOK_TEXT_TOC_MARK:
1106 case XML_TOK_TEXT_USER_INDEX_MARK:
1107 case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1109 // single mark: create mark and insert
1110 OUString sService;
1111 GetServiceName(sService, eToken);
1112 if (CreateMark(xMark, sService))
1114 ProcessAttributes(xAttrList, xMark);
1115 XMLHint_Impl* pHint = new XMLIndexMarkHint_Impl(xMark, xPos);
1116 rHints.push_back(pHint);
1118 // else: can't create mark -> ignore
1119 break;
1122 case XML_TOK_TEXT_TOC_MARK_START:
1123 case XML_TOK_TEXT_USER_INDEX_MARK_START:
1124 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1126 // start: create mark and insert (if ID is found)
1127 OUString sService;
1128 GetServiceName(sService, eToken);
1129 if (CreateMark(xMark, sService))
1131 ProcessAttributes(xAttrList, xMark);
1132 if (!sID.isEmpty())
1134 // process only if we find an ID
1135 XMLHint_Impl* pHint =
1136 new XMLIndexMarkHint_Impl(xMark, xPos, sID);
1137 rHints.push_back(pHint);
1139 // else: no ID -> we'll never find the end -> ignore
1141 // else: can't create mark -> ignore
1142 break;
1145 case XML_TOK_TEXT_TOC_MARK_END:
1146 case XML_TOK_TEXT_USER_INDEX_MARK_END:
1147 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1149 // end: search for ID and set end of mark
1151 // call process attributes with empty XPropertySet:
1152 ProcessAttributes(xAttrList, xMark);
1153 if (!sID.isEmpty())
1155 // if we have an ID, find the hint and set the end position
1156 sal_uInt16 nCount = rHints.size();
1157 for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
1159 XMLHint_Impl *pHint = &rHints[nPos];
1160 if ( pHint->IsIndexMark() &&
1161 sID.equals(
1162 ((XMLIndexMarkHint_Impl *)pHint)->GetID()) )
1164 // set end and stop searching
1165 pHint->SetEnd(xPos);
1166 break;
1170 // else: no ID -> ignore
1171 break;
1174 default:
1175 SAL_WARN("xmloff.text", "unknown index mark type!");
1176 break;
1180 void XMLIndexMarkImportContext_Impl::ProcessAttributes(
1181 const Reference<xml::sax::XAttributeList> & xAttrList,
1182 Reference<beans::XPropertySet>& rPropSet)
1184 // process attributes
1185 sal_Int16 nLength = xAttrList->getLength();
1186 for(sal_Int16 i=0; i<nLength; i++)
1188 OUString sLocalName;
1189 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1190 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
1192 ProcessAttribute(nPrefix, sLocalName,
1193 xAttrList->getValueByIndex(i),
1194 rPropSet);
1198 void XMLIndexMarkImportContext_Impl::ProcessAttribute(
1199 sal_uInt16 nNamespace,
1200 OUString sLocalName,
1201 OUString sValue,
1202 Reference<beans::XPropertySet>& rPropSet)
1204 // we only know ID + string-value attribute;
1205 // (former: marks, latter: -start + -end-marks)
1206 // the remainder is handled in sub-classes
1207 switch (eToken)
1209 case XML_TOK_TEXT_TOC_MARK:
1210 case XML_TOK_TEXT_USER_INDEX_MARK:
1211 case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1212 if ( (XML_NAMESPACE_TEXT == nNamespace) &&
1213 IsXMLToken( sLocalName, XML_STRING_VALUE ) )
1215 rPropSet->setPropertyValue(sAlternativeText, uno::makeAny(sValue));
1217 // else: ignore!
1218 break;
1220 case XML_TOK_TEXT_TOC_MARK_START:
1221 case XML_TOK_TEXT_USER_INDEX_MARK_START:
1222 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1223 case XML_TOK_TEXT_TOC_MARK_END:
1224 case XML_TOK_TEXT_USER_INDEX_MARK_END:
1225 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1226 if ( (XML_NAMESPACE_TEXT == nNamespace) &&
1227 IsXMLToken( sLocalName, XML_ID ) )
1229 sID = sValue;
1231 // else: ignore
1232 break;
1234 default:
1235 SAL_WARN("xmloff.text", "unknown index mark type!");
1236 break;
1240 static const sal_Char sAPI_com_sun_star_text_ContentIndexMark[] =
1241 "com.sun.star.text.ContentIndexMark";
1242 static const sal_Char sAPI_com_sun_star_text_UserIndexMark[] =
1243 "com.sun.star.text.UserIndexMark";
1244 static const sal_Char sAPI_com_sun_star_text_DocumentIndexMark[] =
1245 "com.sun.star.text.DocumentIndexMark";
1248 void XMLIndexMarkImportContext_Impl::GetServiceName(
1249 OUString& sServiceName,
1250 enum XMLTextPElemTokens eToken)
1252 switch (eToken)
1254 case XML_TOK_TEXT_TOC_MARK:
1255 case XML_TOK_TEXT_TOC_MARK_START:
1256 case XML_TOK_TEXT_TOC_MARK_END:
1258 OUString sTmp(
1259 sAPI_com_sun_star_text_ContentIndexMark);
1260 sServiceName = sTmp;
1261 break;
1264 case XML_TOK_TEXT_USER_INDEX_MARK:
1265 case XML_TOK_TEXT_USER_INDEX_MARK_START:
1266 case XML_TOK_TEXT_USER_INDEX_MARK_END:
1268 OUString sTmp(
1269 sAPI_com_sun_star_text_UserIndexMark);
1270 sServiceName = sTmp;
1271 break;
1274 case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1275 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1276 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1278 OUString sTmp(
1279 sAPI_com_sun_star_text_DocumentIndexMark);
1280 sServiceName = sTmp;
1281 break;
1284 default:
1286 SAL_WARN("xmloff.text", "unknown index mark type!");
1287 OUString sTmp;
1288 sServiceName = sTmp;
1289 break;
1295 sal_Bool XMLIndexMarkImportContext_Impl::CreateMark(
1296 Reference<beans::XPropertySet>& rPropSet,
1297 const OUString& rServiceName)
1299 Reference<lang::XMultiServiceFactory>
1300 xFactory(GetImport().GetModel(), UNO_QUERY);
1302 if( xFactory.is() )
1304 Reference<beans::XPropertySet> xPropSet( xFactory->createInstance(rServiceName), UNO_QUERY );
1305 if (xPropSet.is())
1306 rPropSet = xPropSet;
1307 return sal_True;
1310 return sal_False;
1314 class XMLTOCMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1316 const OUString sLevel;
1318 public:
1319 TYPEINFO();
1321 XMLTOCMarkImportContext_Impl(
1322 SvXMLImport& rImport,
1323 sal_uInt16 nPrefix,
1324 const OUString& rLocalName,
1325 enum XMLTextPElemTokens nTok,
1326 XMLHints_Impl& rHnts);
1328 protected:
1330 /** process outline level */
1331 virtual void ProcessAttribute(sal_uInt16 nNamespace,
1332 OUString sLocalName,
1333 OUString sValue,
1334 Reference<beans::XPropertySet>& rPropSet);
1337 TYPEINIT1( XMLTOCMarkImportContext_Impl, XMLIndexMarkImportContext_Impl );
1340 XMLTOCMarkImportContext_Impl::XMLTOCMarkImportContext_Impl(
1341 SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1342 enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1343 XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1344 nTok, rHnts),
1345 sLevel("Level")
1349 void XMLTOCMarkImportContext_Impl::ProcessAttribute(
1350 sal_uInt16 nNamespace,
1351 OUString sLocalName,
1352 OUString sValue,
1353 Reference<beans::XPropertySet>& rPropSet)
1355 SAL_WARN_IF(!rPropSet.is(), "xmloff.text", "need PropertySet");
1357 if ((XML_NAMESPACE_TEXT == nNamespace) &&
1358 IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
1360 // ouline level: set Level property
1361 sal_Int32 nTmp;
1362 if (::sax::Converter::convertNumber( nTmp, sValue )
1363 && nTmp >= 1
1364 && nTmp < GetImport().GetTextImport()->
1365 GetChapterNumbering()->getCount() )
1367 rPropSet->setPropertyValue(sLevel, uno::makeAny((sal_Int16)(nTmp - 1)));
1369 // else: value out of range -> ignore
1371 else
1373 // else: delegate to superclass
1374 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1375 nNamespace, sLocalName, sValue, rPropSet);
1379 class XMLUserIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1381 const OUString sUserIndexName;
1382 const OUString sLevel;
1384 public:
1385 TYPEINFO();
1387 XMLUserIndexMarkImportContext_Impl(
1388 SvXMLImport& rImport,
1389 sal_uInt16 nPrefix,
1390 const OUString& rLocalName,
1391 enum XMLTextPElemTokens nTok,
1392 XMLHints_Impl& rHnts);
1394 protected:
1396 /** process index name */
1397 virtual void ProcessAttribute(sal_uInt16 nNamespace,
1398 OUString sLocalName,
1399 OUString sValue,
1400 Reference<beans::XPropertySet>& rPropSet);
1403 TYPEINIT1( XMLUserIndexMarkImportContext_Impl, XMLIndexMarkImportContext_Impl);
1405 XMLUserIndexMarkImportContext_Impl::XMLUserIndexMarkImportContext_Impl(
1406 SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1407 enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1408 XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1409 nTok, rHnts),
1410 sUserIndexName("UserIndexName"),
1411 sLevel("Level")
1415 void XMLUserIndexMarkImportContext_Impl::ProcessAttribute(
1416 sal_uInt16 nNamespace, OUString sLocalName, OUString sValue,
1417 Reference<beans::XPropertySet>& rPropSet)
1419 if ( XML_NAMESPACE_TEXT == nNamespace )
1421 if ( IsXMLToken( sLocalName, XML_INDEX_NAME ) )
1423 rPropSet->setPropertyValue(sUserIndexName, uno::makeAny(sValue));
1425 else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
1427 // ouline level: set Level property
1428 sal_Int32 nTmp;
1429 if (::sax::Converter::convertNumber(
1430 nTmp, sValue, 0,
1431 GetImport().GetTextImport()->GetChapterNumbering()->getCount()))
1433 rPropSet->setPropertyValue(sLevel, uno::makeAny(static_cast<sal_Int16>(nTmp - 1)));
1435 // else: value out of range -> ignore
1437 else
1439 // else: unknown text property: delegate to super class
1440 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1441 nNamespace, sLocalName, sValue, rPropSet);
1444 else
1446 // else: unknown namespace: delegate to super class
1447 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1448 nNamespace, sLocalName, sValue, rPropSet);
1453 class XMLAlphaIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1455 const OUString sPrimaryKey;
1456 const OUString sSecondaryKey;
1457 const OUString sTextReading;
1458 const OUString sPrimaryKeyReading;
1459 const OUString sSecondaryKeyReading;
1460 const OUString sMainEntry;
1462 public:
1463 TYPEINFO();
1465 XMLAlphaIndexMarkImportContext_Impl(
1466 SvXMLImport& rImport,
1467 sal_uInt16 nPrefix,
1468 const OUString& rLocalName,
1469 enum XMLTextPElemTokens nTok,
1470 XMLHints_Impl& rHnts);
1472 protected:
1474 /** process primary + secondary keys */
1475 virtual void ProcessAttribute(sal_uInt16 nNamespace,
1476 OUString sLocalName,
1477 OUString sValue,
1478 Reference<beans::XPropertySet>& rPropSet);
1481 TYPEINIT1( XMLAlphaIndexMarkImportContext_Impl,
1482 XMLIndexMarkImportContext_Impl );
1484 XMLAlphaIndexMarkImportContext_Impl::XMLAlphaIndexMarkImportContext_Impl(
1485 SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1486 enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1487 XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1488 nTok, rHnts),
1489 sPrimaryKey("PrimaryKey"),
1490 sSecondaryKey("SecondaryKey"),
1491 sTextReading("TextReading"),
1492 sPrimaryKeyReading("PrimaryKeyReading"),
1493 sSecondaryKeyReading("SecondaryKeyReading"),
1494 sMainEntry("IsMainEntry")
1498 void XMLAlphaIndexMarkImportContext_Impl::ProcessAttribute(
1499 sal_uInt16 nNamespace, OUString sLocalName, OUString sValue,
1500 Reference<beans::XPropertySet>& rPropSet)
1502 if (XML_NAMESPACE_TEXT == nNamespace)
1504 if ( IsXMLToken( sLocalName, XML_KEY1 ) )
1506 rPropSet->setPropertyValue(sPrimaryKey, uno::makeAny(sValue));
1508 else if ( IsXMLToken( sLocalName, XML_KEY2 ) )
1510 rPropSet->setPropertyValue(sSecondaryKey, uno::makeAny(sValue));
1512 else if ( IsXMLToken( sLocalName, XML_KEY1_PHONETIC ) )
1514 rPropSet->setPropertyValue(sPrimaryKeyReading, uno::makeAny(sValue));
1516 else if ( IsXMLToken( sLocalName, XML_KEY2_PHONETIC ) )
1518 rPropSet->setPropertyValue(sSecondaryKeyReading, uno::makeAny(sValue));
1520 else if ( IsXMLToken( sLocalName, XML_STRING_VALUE_PHONETIC ) )
1522 rPropSet->setPropertyValue(sTextReading, uno::makeAny(sValue));
1524 else if ( IsXMLToken( sLocalName, XML_MAIN_ENTRY ) )
1526 sal_Bool bMainEntry = sal_False;
1527 bool bTmp(false);
1529 if (::sax::Converter::convertBool(bTmp, sValue))
1530 bMainEntry = bTmp;
1532 rPropSet->setPropertyValue(sMainEntry, uno::makeAny(bMainEntry));
1534 else
1536 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1537 nNamespace, sLocalName, sValue, rPropSet);
1540 else
1542 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1543 nNamespace, sLocalName, sValue, rPropSet);
1548 // ---------------------------------------------------------------------
1550 TYPEINIT1( XMLImpSpanContext_Impl, SvXMLImportContext );
1552 XMLImpSpanContext_Impl::XMLImpSpanContext_Impl(
1553 SvXMLImport& rImport,
1554 sal_uInt16 nPrfx,
1555 const OUString& rLName,
1556 const Reference< xml::sax::XAttributeList > & xAttrList,
1557 XMLHints_Impl& rHnts,
1558 sal_Bool& rIgnLeadSpace
1559 ,sal_uInt8 nSFConvFlags
1561 : SvXMLImportContext( rImport, nPrfx, rLName )
1562 , sTextFrame("TextFrame")
1563 , rHints( rHnts )
1564 , pHint( 0 )
1565 , rIgnoreLeadingSpace( rIgnLeadSpace )
1566 , nStarFontsConvFlags( nSFConvFlags & (CONV_FROM_STAR_BATS|CONV_FROM_STAR_MATH) )
1568 OUString aStyleName;
1570 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1571 for( sal_Int16 i=0; i < nAttrCount; i++ )
1573 const OUString& rAttrName = xAttrList->getNameByIndex( i );
1575 OUString aLocalName;
1576 sal_uInt16 nPrefix =
1577 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
1578 &aLocalName );
1579 if( XML_NAMESPACE_TEXT == nPrefix &&
1580 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1581 aStyleName = xAttrList->getValueByIndex( i );
1584 if( !aStyleName.isEmpty() )
1586 pHint = new XMLStyleHint_Impl( aStyleName,
1587 GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
1588 rHints.push_back( pHint );
1592 XMLImpSpanContext_Impl::~XMLImpSpanContext_Impl()
1594 if( pHint )
1595 pHint->SetEnd( GetImport().GetTextImport()
1596 ->GetCursorAsRange()->getStart() );
1599 SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
1600 SvXMLImport& rImport,
1601 sal_uInt16 nPrefix, const OUString& rLocalName,
1602 const Reference< xml::sax::XAttributeList > & xAttrList,
1603 sal_uInt16 nToken,
1604 XMLHints_Impl& rHints,
1605 sal_Bool& rIgnoreLeadingSpace
1606 ,sal_uInt8 nStarFontsConvFlags
1609 SvXMLImportContext *pContext = 0;
1611 switch( nToken )
1613 case XML_TOK_TEXT_SPAN:
1614 pContext = new XMLImpSpanContext_Impl( rImport, nPrefix,
1615 rLocalName, xAttrList,
1616 rHints,
1617 rIgnoreLeadingSpace
1618 ,nStarFontsConvFlags
1620 break;
1622 case XML_TOK_TEXT_TAB_STOP:
1623 pContext = new XMLCharContext( rImport, nPrefix,
1624 rLocalName, xAttrList,
1625 0x0009, sal_False );
1626 rIgnoreLeadingSpace = sal_False;
1627 break;
1629 case XML_TOK_TEXT_LINE_BREAK:
1630 pContext = new XMLCharContext( rImport, nPrefix,
1631 rLocalName, xAttrList,
1632 ControlCharacter::LINE_BREAK );
1633 rIgnoreLeadingSpace = sal_False;
1634 break;
1636 case XML_TOK_TEXT_S:
1637 pContext = new XMLCharContext( rImport, nPrefix,
1638 rLocalName, xAttrList,
1639 0x0020, sal_True );
1640 break;
1642 case XML_TOK_TEXT_HYPERLINK:
1644 // test for HyperLinkURL property. If present, insert link as
1645 // text property (StarWriter), else try to insert as text
1646 // field (StarCalc, StarDraw, ...)
1647 Reference<beans::XPropertySet> xPropSet(
1648 rImport.GetTextImport()->GetCursor(),
1649 UNO_QUERY );
1651 const OUString sHyperLinkURL(
1652 "HyperLinkURL");
1654 if (xPropSet->getPropertySetInfo()->hasPropertyByName(sHyperLinkURL))
1656 pContext = new XMLImpHyperlinkContext_Impl( rImport, nPrefix,
1657 rLocalName, xAttrList,
1658 rHints,
1659 rIgnoreLeadingSpace );
1661 else
1663 pContext = new XMLUrlFieldImportContext( rImport,
1664 *rImport.GetTextImport().get(),
1665 nPrefix, rLocalName);
1666 //whitespace handling like other fields
1667 rIgnoreLeadingSpace = sal_False;
1670 break;
1673 case XML_TOK_TEXT_RUBY:
1674 pContext = new XMLImpRubyContext_Impl( rImport, nPrefix,
1675 rLocalName, xAttrList,
1676 rHints,
1677 rIgnoreLeadingSpace );
1678 break;
1680 case XML_TOK_TEXT_NOTE:
1681 if (rImport.GetTextImport()->IsInFrame())
1683 // we must not insert footnotes into text frames
1684 pContext = new SvXMLImportContext( rImport, nPrefix,
1685 rLocalName );
1687 else
1689 pContext = new XMLFootnoteImportContext( rImport,
1690 *rImport.GetTextImport().get(),
1691 nPrefix, rLocalName );
1693 rIgnoreLeadingSpace = sal_False;
1694 break;
1696 case XML_TOK_TEXT_REFERENCE:
1697 case XML_TOK_TEXT_BOOKMARK:
1698 case XML_TOK_TEXT_BOOKMARK_START:
1699 case XML_TOK_TEXT_BOOKMARK_END:
1700 pContext = new XMLTextMarkImportContext( rImport,
1701 *rImport.GetTextImport().get(),
1702 nPrefix, rLocalName );
1703 break;
1705 case XML_TOK_TEXT_FIELDMARK:
1706 case XML_TOK_TEXT_FIELDMARK_START:
1707 case XML_TOK_TEXT_FIELDMARK_END:
1708 pContext = new XMLTextMarkImportContext( rImport,
1709 *rImport.GetTextImport().get(),
1710 nPrefix, rLocalName );
1711 break;
1713 case XML_TOK_TEXT_REFERENCE_START:
1714 pContext = new XMLStartReferenceContext_Impl( rImport,
1715 nPrefix, rLocalName,
1716 rHints, xAttrList );
1717 break;
1719 case XML_TOK_TEXT_REFERENCE_END:
1720 pContext = new XMLEndReferenceContext_Impl( rImport,
1721 nPrefix, rLocalName,
1722 rHints, xAttrList );
1723 break;
1725 case XML_TOK_TEXT_FRAME:
1727 Reference < XTextRange > xAnchorPos =
1728 rImport.GetTextImport()->GetCursor()->getStart();
1729 XMLTextFrameContext *pTextFrameContext =
1730 new XMLTextFrameContext( rImport, nPrefix,
1731 rLocalName, xAttrList,
1732 TextContentAnchorType_AS_CHARACTER );
1733 // Remove check for text content. (#i33242#)
1734 // Check for text content is done on the processing of the hint
1735 if( TextContentAnchorType_AT_CHARACTER ==
1736 pTextFrameContext->GetAnchorType() )
1738 rHints.push_back( new XMLTextFrameHint_Impl(
1739 pTextFrameContext, xAnchorPos ) );
1741 pContext = pTextFrameContext;
1742 rIgnoreLeadingSpace = sal_False;
1744 break;
1745 case XML_TOK_DRAW_A:
1747 Reference < XTextRange > xAnchorPos(rImport.GetTextImport()->GetCursor()->getStart());
1748 pContext =
1749 new XMLTextFrameHyperlinkContext( rImport, nPrefix,
1750 rLocalName, xAttrList,
1751 TextContentAnchorType_AS_CHARACTER );
1752 XMLTextFrameHint_Impl *pHint =
1753 new XMLTextFrameHint_Impl( pContext, xAnchorPos);
1754 rHints.push_back( pHint );
1756 break;
1758 case XML_TOK_TEXT_TOC_MARK:
1759 case XML_TOK_TEXT_TOC_MARK_START:
1760 pContext = new XMLTOCMarkImportContext_Impl(
1761 rImport, nPrefix, rLocalName,
1762 (enum XMLTextPElemTokens)nToken, rHints);
1763 break;
1765 case XML_TOK_TEXT_USER_INDEX_MARK:
1766 case XML_TOK_TEXT_USER_INDEX_MARK_START:
1767 pContext = new XMLUserIndexMarkImportContext_Impl(
1768 rImport, nPrefix, rLocalName,
1769 (enum XMLTextPElemTokens)nToken, rHints);
1770 break;
1772 case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1773 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1774 pContext = new XMLAlphaIndexMarkImportContext_Impl(
1775 rImport, nPrefix, rLocalName,
1776 (enum XMLTextPElemTokens)nToken, rHints);
1777 break;
1779 case XML_TOK_TEXT_TOC_MARK_END:
1780 case XML_TOK_TEXT_USER_INDEX_MARK_END:
1781 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1782 pContext = new XMLIndexMarkImportContext_Impl(
1783 rImport, nPrefix, rLocalName, (enum XMLTextPElemTokens)nToken,
1784 rHints);
1785 break;
1787 case XML_TOK_TEXTP_CHANGE_START:
1788 case XML_TOK_TEXTP_CHANGE_END:
1789 case XML_TOK_TEXTP_CHANGE:
1790 pContext = new XMLChangeImportContext(
1791 rImport, nPrefix, rLocalName,
1792 (nToken != XML_TOK_TEXTP_CHANGE_END),
1793 (nToken != XML_TOK_TEXTP_CHANGE_START),
1794 sal_False);
1795 break;
1797 case XML_TOK_TEXT_META:
1798 pContext = new XMLMetaImportContext(rImport, nPrefix, rLocalName,
1799 rHints, rIgnoreLeadingSpace );
1800 break;
1802 case XML_TOK_TEXT_META_FIELD:
1803 pContext = new XMLMetaFieldImportContext(rImport, nPrefix, rLocalName,
1804 rHints, rIgnoreLeadingSpace );
1805 break;
1807 default:
1808 // none of the above? then it's probably a text field!
1809 pContext =
1810 XMLTextFieldImportContext::CreateTextFieldImportContext(
1811 rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName,
1812 nToken);
1813 // #108784# import draw elements (except control shapes in headers)
1814 if( pContext == NULL &&
1815 !( rImport.GetTextImport()->IsInHeaderFooter() &&
1816 nPrefix == XML_NAMESPACE_DRAW &&
1817 IsXMLToken( rLocalName, XML_CONTROL ) ) )
1819 Reference < XShapes > xShapes;
1820 SvXMLShapeContext* pShapeContext = rImport.GetShapeImport()->CreateGroupChildContext(
1821 rImport, nPrefix, rLocalName, xAttrList, xShapes );
1822 pContext = pShapeContext;
1823 // OD 2004-04-20 #i26791# - keep shape in a text frame hint to
1824 // adjust its anchor position, if its at-character anchored
1825 Reference < XTextRange > xAnchorPos =
1826 rImport.GetTextImport()->GetCursor()->getStart();
1827 rHints.push_back( new XMLDrawHint_Impl( pShapeContext, xAnchorPos ) );
1829 if( !pContext )
1831 // ignore unknown content
1832 pContext =
1833 new SvXMLImportContext( rImport, nPrefix, rLocalName );
1835 // Behind fields, shapes and any unknown content blanks aren't ignored
1836 rIgnoreLeadingSpace = sal_False;
1839 return pContext;
1842 SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
1843 sal_uInt16 nPrefix, const OUString& rLocalName,
1844 const Reference< xml::sax::XAttributeList > & xAttrList )
1846 const SvXMLTokenMap& rTokenMap =
1847 GetImport().GetTextImport()->GetTextPElemTokenMap();
1848 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
1850 return CreateChildContext( GetImport(), nPrefix, rLocalName, xAttrList,
1851 nToken, rHints, rIgnoreLeadingSpace
1852 ,nStarFontsConvFlags
1856 void XMLImpSpanContext_Impl::Characters( const OUString& rChars )
1858 OUString sStyleName;
1859 if( pHint )
1860 sStyleName = pHint->GetStyleName();
1861 OUString sChars =
1862 GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
1863 nStarFontsConvFlags,
1864 sal_False, GetImport() );
1865 GetImport().GetTextImport()->InsertString( sChars, rIgnoreLeadingSpace );
1868 // ---------------------------------------------------------------------
1870 TYPEINIT1( XMLParaContext, SvXMLImportContext );
1872 XMLParaContext::XMLParaContext(
1873 SvXMLImport& rImport,
1874 sal_uInt16 nPrfx,
1875 const OUString& rLName,
1876 const Reference< xml::sax::XAttributeList > & xAttrList,
1877 sal_Bool bHead ) :
1878 SvXMLImportContext( rImport, nPrfx, rLName ),
1879 xStart( rImport.GetTextImport()->GetCursorAsRange()->getStart() ),
1880 m_bHaveAbout(false),
1881 nOutlineLevel( IsXMLToken( rLName, XML_H ) ? 1 : -1 ),
1882 pHints( 0 ),
1883 // Lost outline numbering in master document (#i73509#)
1884 mbOutlineLevelAttrFound( sal_False ),
1885 bIgnoreLeadingSpace( sal_True ),
1886 bHeading( bHead ),
1887 bIsListHeader( false ),
1888 bIsRestart (false),
1889 nStartValue(0),
1890 nStarFontsConvFlags( 0 )
1892 const SvXMLTokenMap& rTokenMap =
1893 GetImport().GetTextImport()->GetTextPAttrTokenMap();
1895 bool bHaveXmlId( false );
1896 OUString aCondStyleName, sClassNames;
1898 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1899 for( sal_Int16 i=0; i < nAttrCount; i++ )
1901 const OUString& rAttrName = xAttrList->getNameByIndex( i );
1902 const OUString& rValue = xAttrList->getValueByIndex( i );
1904 OUString aLocalName;
1905 sal_uInt16 nPrefix =
1906 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
1907 &aLocalName );
1908 switch( rTokenMap.Get( nPrefix, aLocalName ) )
1910 case XML_TOK_TEXT_P_XMLID:
1911 m_sXmlId = rValue;
1912 bHaveXmlId = true;
1913 break;
1914 case XML_TOK_TEXT_P_ABOUT:
1915 m_sAbout = rValue;
1916 m_bHaveAbout = true;
1917 break;
1918 case XML_TOK_TEXT_P_PROPERTY:
1919 m_sProperty = rValue;
1920 break;
1921 case XML_TOK_TEXT_P_CONTENT:
1922 m_sContent = rValue;
1923 break;
1924 case XML_TOK_TEXT_P_DATATYPE:
1925 m_sDatatype = rValue;
1926 break;
1927 case XML_TOK_TEXT_P_TEXTID:
1928 if (!bHaveXmlId) { m_sXmlId = rValue; }
1929 break;
1930 case XML_TOK_TEXT_P_STYLE_NAME:
1931 sStyleName = rValue;
1932 break;
1933 case XML_TOK_TEXT_P_CLASS_NAMES:
1934 sClassNames = rValue;
1935 break;
1936 case XML_TOK_TEXT_P_COND_STYLE_NAME:
1937 aCondStyleName = rValue;
1938 break;
1939 case XML_TOK_TEXT_P_LEVEL:
1941 sal_Int32 nTmp = rValue.toInt32();
1942 if( nTmp > 0L )
1944 if( nTmp > 127 )
1945 nTmp = 127;
1946 nOutlineLevel = (sal_Int8)nTmp;
1948 // Lost outline numbering in master document (#i73509#)
1949 mbOutlineLevelAttrFound = sal_True;
1951 break;
1952 case XML_TOK_TEXT_P_IS_LIST_HEADER:
1954 bool bBool(false);
1955 if( ::sax::Converter::convertBool( bBool, rValue ) )
1957 bIsListHeader = bBool;
1960 break;
1961 case XML_TOK_TEXT_P_RESTART_NUMBERING:
1963 bool bBool(false);
1964 if (::sax::Converter::convertBool(bBool, rValue))
1966 bIsRestart = bBool;
1969 break;
1970 case XML_TOK_TEXT_P_START_VALUE:
1972 nStartValue = sal::static_int_cast< sal_Int16 >(
1973 rValue.toInt32());
1975 break;
1979 if( !aCondStyleName.isEmpty() )
1980 sStyleName = aCondStyleName;
1981 else if( !sClassNames.isEmpty() )
1983 sal_Int32 nDummy = 0;
1984 sStyleName = sClassNames.getToken( 0, ' ', nDummy );
1988 XMLParaContext::~XMLParaContext()
1990 UniReference < XMLTextImportHelper > xTxtImport(
1991 GetImport().GetTextImport());
1992 Reference < XTextRange > xCrsrRange( xTxtImport->GetCursorAsRange() );
1993 if( !xCrsrRange.is() )
1994 return; // Robust (defect file)
1995 Reference < XTextRange > xEnd(xCrsrRange->getStart());
1997 // if we have an id set for this paragraph, get a cursor for this
1998 // paragraph and register it with the given identifier
1999 // FIXME: this is just temporary, and should be removed when
2000 // EditEngine paragraphs implement XMetadatable!
2001 if (!m_sXmlId.isEmpty())
2003 Reference < XTextCursor > xIdCursor( xTxtImport->GetText()->createTextCursorByRange( xStart ) );
2004 if( xIdCursor.is() )
2006 xIdCursor->gotoRange( xEnd, sal_True );
2007 Reference< XInterface > xRef( xIdCursor, UNO_QUERY );
2008 GetImport().getInterfaceToIdentifierMapper().registerReference(
2009 m_sXmlId, xRef);
2013 // insert a paragraph break
2014 xTxtImport->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH );
2016 // create a cursor that select the whole last paragraph
2017 Reference < XTextCursor > xAttrCursor;
2018 try {
2019 xAttrCursor = xTxtImport->GetText()->createTextCursorByRange( xStart );
2020 if( !xAttrCursor.is() )
2021 return; // Robust (defect file)
2022 } catch (const uno::Exception &) {
2023 // createTextCursorByRange() likes to throw runtime exception, even
2024 // though it just means 'we were unable to create the cursor'
2025 return;
2027 xAttrCursor->gotoRange( xEnd, sal_True );
2029 // xml:id for RDF metadata
2030 if (!m_sXmlId.isEmpty() || m_bHaveAbout || !m_sProperty.isEmpty())
2032 try {
2033 const uno::Reference<container::XEnumerationAccess> xEA
2034 (xAttrCursor, uno::UNO_QUERY_THROW);
2035 const uno::Reference<container::XEnumeration> xEnum(
2036 xEA->createEnumeration(), uno::UNO_QUERY_THROW);
2037 SAL_WARN_IF(!xEnum->hasMoreElements(), "xmloff.text", "xml:id: no paragraph?");
2038 if (xEnum->hasMoreElements()) {
2039 uno::Reference<rdf::XMetadatable> xMeta;
2040 xEnum->nextElement() >>= xMeta;
2041 SAL_WARN_IF(!xMeta.is(), "xmloff.text", "xml:id: not XMetadatable");
2042 GetImport().SetXmlId(xMeta, m_sXmlId);
2043 if (m_bHaveAbout)
2045 GetImport().AddRDFa(xMeta,
2046 m_sAbout, m_sProperty, m_sContent, m_sDatatype);
2048 SAL_WARN_IF(xEnum->hasMoreElements(), "xmloff.text", "xml:id: > 1 paragraph?");
2050 } catch (const uno::Exception &) {
2051 SAL_INFO("xmloff.text", "XMLParaContext::~XMLParaContext: exception");
2055 OUString const sCellParaStyleName(xTxtImport->GetCellParaStyleDefault());
2056 if( !sCellParaStyleName.isEmpty() )
2058 /* Suppress handling of outline and list attributes,
2059 because of side effects of method <SetStyleAndAttrs(..)> (#i80724#)
2061 xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
2062 sCellParaStyleName,
2063 sal_True,
2064 sal_False, -1, // suppress outline handling
2065 sal_False ); // suppress list attributes handling
2068 // #103445# for headings without style name, find the proper style
2069 if( bHeading && sStyleName.isEmpty() )
2070 xTxtImport->FindOutlineStyleName( sStyleName, nOutlineLevel );
2072 // set style and hard attributes at the previous paragraph
2073 // Add paramter <mbOutlineLevelAttrFound> (#i73509#)
2074 sStyleName = xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
2075 sStyleName,
2076 sal_True,
2077 mbOutlineLevelAttrFound,
2078 bHeading ? nOutlineLevel : -1 );
2080 // handle list style header
2081 if (bHeading && (bIsListHeader || bIsRestart))
2083 Reference<XPropertySet> xPropSet( xAttrCursor, UNO_QUERY );
2085 if (xPropSet.is())
2087 if (bIsListHeader)
2089 OUString sNumberingIsNumber
2090 ("NumberingIsNumber");
2091 if(xPropSet->getPropertySetInfo()->
2092 hasPropertyByName(sNumberingIsNumber))
2094 xPropSet->setPropertyValue
2095 (sNumberingIsNumber, makeAny( false ) );
2098 if (bIsRestart)
2100 OUString sParaIsNumberingRestart
2101 ("ParaIsNumberingRestart");
2102 OUString sNumberingStartValue
2103 ("NumberingStartValue");
2104 if (xPropSet->getPropertySetInfo()->
2105 hasPropertyByName(sParaIsNumberingRestart))
2107 xPropSet->setPropertyValue
2108 (sParaIsNumberingRestart, makeAny(true));
2111 if (xPropSet->getPropertySetInfo()->
2112 hasPropertyByName(sNumberingStartValue))
2114 xPropSet->setPropertyValue
2115 (sNumberingStartValue, makeAny(nStartValue));
2122 if( pHints && !pHints->empty() )
2124 for( sal_uInt16 i=0; i<pHints->size(); i++ )
2126 XMLHint_Impl *pHint = &(*pHints)[i];
2127 xAttrCursor->gotoRange( pHint->GetStart(), sal_False );
2128 xAttrCursor->gotoRange( pHint->GetEnd(), sal_True );
2129 switch( pHint->GetType() )
2131 case XML_HINT_STYLE:
2133 const OUString& rStyleName =
2134 ((XMLStyleHint_Impl *)pHint)->GetStyleName();
2135 if( !rStyleName.isEmpty() )
2136 xTxtImport->SetStyleAndAttrs( GetImport(),
2137 xAttrCursor, rStyleName,
2138 sal_False );
2140 break;
2141 case XML_HINT_REFERENCE:
2143 const OUString& rRefName =
2144 ((XMLReferenceHint_Impl *)pHint)->GetRefName();
2145 if( !rRefName.isEmpty() )
2147 if( !pHint->GetEnd().is() )
2148 pHint->SetEnd(xEnd);
2150 // convert XCursor to XTextRange
2151 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2153 // reference name uses rStyleName member
2154 // borrow from XMLTextMarkImportContext
2155 XMLTextMarkImportContext::CreateAndInsertMark(
2156 GetImport(),
2157 OUString( "com.sun.star.text.ReferenceMark"),
2158 rRefName,
2159 xRange);
2162 break;
2163 case XML_HINT_HYPERLINK:
2165 const XMLHyperlinkHint_Impl *pHHint =
2166 (const XMLHyperlinkHint_Impl *)pHint;
2167 xTxtImport->SetHyperlink( GetImport(),
2168 xAttrCursor,
2169 pHHint->GetHRef(),
2170 pHHint->GetName(),
2171 pHHint->GetTargetFrameName(),
2172 pHHint->GetStyleName(),
2173 pHHint->GetVisitedStyleName(),
2174 pHHint->GetEventsContext() );
2176 break;
2177 case XML_HINT_INDEX_MARK:
2179 Reference<beans::XPropertySet> xMark(
2180 ((const XMLIndexMarkHint_Impl *)pHint)->GetMark());
2181 Reference<XTextContent> xContent(xMark, UNO_QUERY);
2182 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2183 xTxtImport->GetText()->insertTextContent(
2184 xRange, xContent, sal_True );
2186 break;
2187 case XML_HINT_TEXT_FRAME:
2189 const XMLTextFrameHint_Impl *pFHint =
2190 (const XMLTextFrameHint_Impl *)pHint;
2191 // Check for text content (#i33242#)
2192 Reference < XTextContent > xTextContent =
2193 pFHint->GetTextContent();
2194 if ( xTextContent.is() )
2196 /* Core impl. of the unification of drawing objects and
2197 Writer fly frames (#i26791#)
2199 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2200 if ( pFHint->IsBoundAtChar() )
2202 xTextContent->attach( xRange );
2205 /* Consider, that hint can also contain a shape -
2206 e.g. drawing object of type 'Text'. (#i33242#)
2208 else
2210 Reference < XShape > xShape = pFHint->GetShape();
2211 if ( xShape.is() )
2213 // determine anchor type
2214 Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
2215 TextContentAnchorType eAnchorType =
2216 TextContentAnchorType_AT_PARAGRAPH;
2218 OUString sAnchorType( "AnchorType" );
2219 Any aAny = xPropSet->getPropertyValue( sAnchorType );
2220 aAny >>= eAnchorType;
2222 if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
2224 // set anchor position for at-character anchored objects
2225 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2226 Any aPos;
2227 aPos <<= xRange;
2228 OUString sTextRange( "TextRange" );
2229 xPropSet->setPropertyValue(sTextRange, aPos);
2234 break;
2235 /* Core impl. of the unification of drawing objects and
2236 Writer fly frames (#i26791#)
2238 case XML_HINT_DRAW:
2240 const XMLDrawHint_Impl *pDHint =
2241 static_cast<const XMLDrawHint_Impl*>(pHint);
2242 // Improvement: hint directly provides the shape. (#i33242#)
2243 Reference < XShape > xShape = pDHint->GetShape();
2244 if ( xShape.is() )
2246 // determine anchor type
2247 Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
2248 TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
2250 OUString sAnchorType( "AnchorType" );
2251 Any aAny = xPropSet->getPropertyValue( sAnchorType );
2252 aAny >>= eAnchorType;
2254 if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
2256 // set anchor position for at-character anchored objects
2257 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2258 Any aPos;
2259 aPos <<= xRange;
2260 OUString sTextRange( "TextRange" );
2261 xPropSet->setPropertyValue(sTextRange, aPos);
2265 break;
2266 default:
2267 SAL_WARN( "xmloff.text", "What's this" );
2268 break;
2272 delete pHints;
2275 SvXMLImportContext *XMLParaContext::CreateChildContext(
2276 sal_uInt16 nPrefix, const OUString& rLocalName,
2277 const Reference< xml::sax::XAttributeList > & xAttrList )
2279 const SvXMLTokenMap& rTokenMap =
2280 GetImport().GetTextImport()->GetTextPElemTokenMap();
2281 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
2282 if( !pHints )
2283 pHints = new XMLHints_Impl;
2284 return XMLImpSpanContext_Impl::CreateChildContext(
2285 GetImport(), nPrefix, rLocalName, xAttrList,
2286 nToken, *pHints, bIgnoreLeadingSpace
2287 , nStarFontsConvFlags
2291 void XMLParaContext::Characters( const OUString& rChars )
2293 OUString sChars =
2294 GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
2295 nStarFontsConvFlags,
2296 sal_True, GetImport() );
2297 GetImport().GetTextImport()->InsertString( sChars, bIgnoreLeadingSpace );
2302 TYPEINIT1( XMLNumberedParaContext, SvXMLImportContext );
2304 XMLNumberedParaContext::XMLNumberedParaContext(
2305 SvXMLImport& i_rImport,
2306 sal_uInt16 i_nPrefix,
2307 const OUString& i_rLocalName,
2308 const Reference< xml::sax::XAttributeList > & i_xAttrList ) :
2309 SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName ),
2310 m_Level(0),
2311 m_StartValue(-1),
2312 m_ListId(),
2313 m_xNumRules()
2315 OUString StyleName;
2317 const SvXMLTokenMap& rTokenMap(
2318 i_rImport.GetTextImport()->GetTextNumberedParagraphAttrTokenMap() );
2320 const sal_Int16 nAttrCount( i_xAttrList.is() ?
2321 i_xAttrList->getLength() : 0 );
2322 for ( sal_Int16 i=0; i < nAttrCount; i++ )
2324 const OUString& rAttrName( i_xAttrList->getNameByIndex( i ) );
2325 const OUString& rValue ( i_xAttrList->getValueByIndex( i ) );
2327 OUString aLocalName;
2328 const sal_uInt16 nPrefix(
2329 GetImport().GetNamespaceMap().GetKeyByAttrName(
2330 rAttrName, &aLocalName ) );
2331 switch( rTokenMap.Get( nPrefix, aLocalName ) )
2333 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_XMLID:
2334 m_XmlId = rValue;
2335 //FIXME: there is no UNO API for lists
2336 break;
2337 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LIST_ID:
2338 m_ListId = rValue;
2339 break;
2340 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LEVEL:
2342 sal_Int32 nTmp = rValue.toInt32();
2343 if ( nTmp >= 1 && nTmp <= SHRT_MAX ) {
2344 m_Level = static_cast<sal_uInt16>(nTmp) - 1;
2347 break;
2348 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_STYLE_NAME:
2349 StyleName = rValue;
2350 break;
2351 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_CONTINUE_NUMBERING:
2352 // this attribute is deprecated
2353 // ContinuteNumbering = IsXMLToken(rValue, XML_TRUE);
2354 break;
2355 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_START_VALUE:
2357 sal_Int32 nTmp = rValue.toInt32();
2358 if ( nTmp >= 0 && nTmp <= SHRT_MAX ) {
2359 m_StartValue = static_cast<sal_Int16>(nTmp);
2362 break;
2366 XMLTextListsHelper& rTextListsHelper(
2367 i_rImport.GetTextImport()->GetTextListHelper() );
2368 if (m_ListId.isEmpty())
2370 SAL_WARN_IF( i_rImport.GetODFVersion() == "1.2", "xmloff.text", "invalid numbered-paragraph: no list-id (1.2)" );
2371 m_ListId = rTextListsHelper.GetNumberedParagraphListId(m_Level,
2372 StyleName);
2373 SAL_WARN_IF(m_ListId.isEmpty(), "xmloff.text", "numbered-paragraph: no ListId");
2374 if (m_ListId.isEmpty()) {
2375 return;
2378 m_xNumRules = rTextListsHelper.EnsureNumberedParagraph( i_rImport,
2379 m_ListId, m_Level, StyleName);
2381 SAL_WARN_IF(!m_xNumRules.is(), "xmloff.text", "numbered-paragraph: no NumRules");
2383 i_rImport.GetTextImport()->GetTextListHelper().PushListContext( this );
2386 XMLNumberedParaContext::~XMLNumberedParaContext()
2390 void XMLNumberedParaContext::EndElement()
2392 if (!m_ListId.isEmpty()) {
2393 GetImport().GetTextImport()->PopListContext();
2397 SvXMLImportContext *XMLNumberedParaContext::CreateChildContext(
2398 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
2399 const Reference< xml::sax::XAttributeList > & i_xAttrList )
2401 SvXMLImportContext *pContext( 0 );
2403 if ( XML_NAMESPACE_TEXT == i_nPrefix )
2405 bool bIsHeader( IsXMLToken( i_rLocalName, XML_H ) );
2406 if ( bIsHeader || IsXMLToken( i_rLocalName, XML_P ) )
2408 pContext = new XMLParaContext( GetImport(),
2409 i_nPrefix, i_rLocalName, i_xAttrList, bIsHeader );
2410 // ignore text:number } else if (IsXMLToken( i_rLocalName, XML_NUMBER )) {
2414 if (!pContext) {
2415 pContext = SvXMLImportContext::CreateChildContext(
2416 i_nPrefix, i_rLocalName, i_xAttrList );
2419 return pContext;
2422 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */