LibreOffice Module xmloff (master)  1
txtparai.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
21 
22 #include <memory>
23 #include <string_view>
24 #include <vector>
25 
26 #include <rtl/ustring.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <sal/log.hxx>
29 #include <tools/diagnose_ex.h>
30 #include <com/sun/star/frame/XModel.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/text/XTextFrame.hpp>
33 #include <com/sun/star/text/XTextCursor.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/beans/XPropertySetInfo.hpp>
36 #include <com/sun/star/text/ControlCharacter.hpp>
37 #include <com/sun/star/container/XIndexReplace.hpp>
38 #include <com/sun/star/drawing/XShapes.hpp>
39 #include <com/sun/star/container/XEnumerationAccess.hpp>
40 #include <com/sun/star/rdf/XMetadatable.hpp>
41 
42 #include <sax/tools/converter.hxx>
43 
44 #include <xmloff/xmlictxt.hxx>
45 #include <xmloff/xmlimp.hxx>
46 #include <xmloff/xmltoken.hxx>
47 #include <xmloff/namespacemap.hxx>
48 #include <xmloff/xmlnamespace.hxx>
49 #include <xmloff/txtimp.hxx>
50 #include "txtparai.hxx"
51 #include <txtfldi.hxx>
54 #include "XMLTextFrameContext.hxx"
59 #include <txtlists.hxx>
60 
61 #include "txtparaimphint.hxx"
62 
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::text;
66 using namespace ::com::sun::star::drawing;
67 using namespace ::com::sun::star::beans;
68 using namespace ::xmloff::token;
69 using ::com::sun::star::container::XEnumerationAccess;
70 using ::com::sun::star::container::XEnumeration;
71 
73 {
74 private:
75 
76  std::vector<std::unique_ptr<XMLHint_Impl>> m_Hints;
77  std::unordered_map<OUString, XMLIndexMarkHint_Impl*> m_IndexHintsById;
78  uno::Reference<uno::XInterface> m_xCrossRefHeadingBookmark;
79 
80 public:
81  void push_back(std::unique_ptr<XMLHint_Impl> pHint)
82  {
83  m_Hints.push_back(std::move(pHint));
84  }
85 
86  void push_back(std::unique_ptr<XMLIndexMarkHint_Impl> pHint)
87  {
88  m_IndexHintsById.emplace(pHint->GetID(), pHint.get());
89  m_Hints.push_back(std::move(pHint));
90  }
91 
92  std::vector<std::unique_ptr<XMLHint_Impl>> const& GetHints() const
93  {
94  return m_Hints;
95  }
96 
98  {
99  auto it = m_IndexHintsById.find(sID);
100  return it == m_IndexHintsById.end() ? nullptr : it->second;
101  }
102 
103  uno::Reference<uno::XInterface> & GetCrossRefHeadingBookmark()
104  {
106  }
107 };
108 
109 
111  SvXMLImport& rImport,
112  const Reference< xml::sax::XFastAttributeList > & xAttrList,
113  sal_Unicode c,
114  bool bCount ) :
115  SvXMLImportContext( rImport )
116  ,m_nControl(0)
117  ,m_nCount(1)
118  ,m_c(c)
119 {
120  if( !bCount )
121  return;
122 
123  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
124  {
125  if( aIter.getToken() == XML_ELEMENT(TEXT, XML_C) )
126  {
127  sal_Int32 nTmp = aIter.toInt32();
128  if( nTmp > 0 )
129  {
130  if( nTmp > SAL_MAX_UINT16 )
132  else
133  m_nCount = static_cast<sal_uInt16>(nTmp);
134  }
135  }
136  else
137  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
138  }
139 }
140 
142  SvXMLImport& rImp,
143  sal_Int16 nControl ) :
144  SvXMLImportContext( rImp )
145  ,m_nControl(nControl)
146  ,m_nCount(0)
147  ,m_c(0)
148 {
149 }
150 
152 {
153 }
155 {
156  if ( !m_nCount )
158  else
159  {
160  if( 1U == m_nCount )
161  {
162  OUString sBuff( &m_c, 1 );
163  InsertString(sBuff);
164  }
165  else
166  {
167  OUStringBuffer sBuff(static_cast<int>(m_nCount));
168  while( m_nCount-- )
169  sBuff.append( &m_c, 1 );
170 
171  InsertString(sBuff.makeStringAndClear() );
172  }
173  }
174 }
175 void XMLCharContext::InsertControlCharacter(sal_Int16 _nControl)
176 {
177  GetImport().GetTextImport()->InsertControlCharacter( _nControl );
178 }
179 void XMLCharContext::InsertString(const OUString& _sString)
180 {
181  GetImport().GetTextImport()->InsertString( _sString );
182 }
183 
184 namespace {
185 
187 class XMLStartReferenceContext_Impl : public SvXMLImportContext
188 {
189 public:
190 
191  // Do everything in constructor. Well ...
192  XMLStartReferenceContext_Impl (
193  SvXMLImport& rImport,
194  XMLHints_Impl& rHints,
195  const Reference<xml::sax::XFastAttributeList> & xAttrList);
196 
197  static bool FindName(
198  const Reference<xml::sax::XFastAttributeList> & xAttrList,
199  OUString& rName);
200 };
201 
202 }
203 
204 XMLStartReferenceContext_Impl::XMLStartReferenceContext_Impl(
205  SvXMLImport& rImport,
206  XMLHints_Impl& rHints,
207  const Reference<xml::sax::XFastAttributeList> & xAttrList) :
208  SvXMLImportContext(rImport)
209 {
210  OUString sName;
211 
212  if (FindName(xAttrList, sName))
213  {
214  std::unique_ptr<XMLHint_Impl> pHint(new XMLReferenceHint_Impl(
215  sName, rImport.GetTextImport()->GetCursor()->getStart()));
216 
217  // degenerates to point reference, if no end is found!
218  pHint->SetEnd(rImport.GetTextImport()->GetCursor()->getStart() );
219 
220  rHints.push_back(std::move(pHint));
221  }
222 }
223 
224 bool XMLStartReferenceContext_Impl::FindName(
225  const Reference<xml::sax::XFastAttributeList> & xAttrList,
226  OUString& rName)
227 {
228  bool bNameOK( false );
229 
230  // find name attribute first
231  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
232  {
233  if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_NAME) )
234  {
235  rName = aIter.toString();
236  bNameOK = true;
237  break;
238  }
239  }
240 
241  return bNameOK;
242 }
243 
244 namespace {
245 
247 class XMLEndReferenceContext_Impl : public SvXMLImportContext
248 {
249 public:
250 
251  // Do everything in constructor. Well ...
252  XMLEndReferenceContext_Impl(
253  SvXMLImport& rImport,
254  const XMLHints_Impl& rHints,
255  const Reference<xml::sax::XFastAttributeList> & xAttrList);
256 };
257 
258 }
259 
260 XMLEndReferenceContext_Impl::XMLEndReferenceContext_Impl(
261  SvXMLImport& rImport,
262  const XMLHints_Impl& rHints,
263  const Reference<xml::sax::XFastAttributeList> & xAttrList) :
264  SvXMLImportContext(rImport)
265 {
266  OUString sName;
267 
268  // borrow from XMLStartReferenceContext_Impl
269  if (!XMLStartReferenceContext_Impl::FindName(xAttrList, sName))
270  return;
271 
272  // search for reference start
273  for (const auto& rHintPtr : rHints.GetHints())
274  {
275  XMLHint_Impl *const pHint = rHintPtr.get();
276  if ( pHint->IsReference() &&
277  sName == static_cast<XMLReferenceHint_Impl *>(pHint)->GetRefName() )
278  {
279  // set end and stop searching
280  pHint->SetEnd(GetImport().GetTextImport()->
281  GetCursor()->getStart() );
282  break;
283  }
284  }
285  // else: no start (in this paragraph) -> ignore
286 }
287 
288 namespace {
289 
290 class XMLImpSpanContext_Impl : public SvXMLImportContext
291 {
292  XMLHints_Impl& m_rHints;
293  XMLStyleHint_Impl *pHint;
294 
295  bool& rIgnoreLeadingSpace;
296 
297  sal_uInt8 nStarFontsConvFlags;
298 
299 public:
300 
301 
302  XMLImpSpanContext_Impl(
303  SvXMLImport& rImport,
304  sal_Int32 nElement,
305  const Reference< xml::sax::XFastAttributeList > & xAttrList,
306  XMLHints_Impl& rHints,
307  bool& rIgnLeadSpace,
308  sal_uInt8 nSFConvFlags
309  );
310 
311  static css::uno::Reference< css::xml::sax::XFastContextHandler > CreateSpanContext(
312  SvXMLImport& rImport,
313  sal_Int32 nElement,
314  const Reference< xml::sax::XFastAttributeList > & xAttrList,
315  XMLHints_Impl& rHints,
316  bool& rIgnLeadSpace,
317  sal_uInt8 nStarFontsConvFlags = 0
318  );
319 
320  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
321  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
322 
323  virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
324  virtual void SAL_CALL characters( const OUString& rChars ) override;
325 };
326 
327 class XMLImpHyperlinkContext_Impl : public SvXMLImportContext
328 {
329  XMLHints_Impl& m_rHints;
330  XMLHyperlinkHint_Impl *mpHint;
331 
332  bool& mrbIgnoreLeadingSpace;
333 
334 public:
335 
336 
337  XMLImpHyperlinkContext_Impl(
338  SvXMLImport& rImport,
339  sal_Int32 nElement,
340  const Reference< xml::sax::XFastAttributeList > & xAttrList,
341  XMLHints_Impl& rHints,
342  bool& rIgnLeadSpace );
343 
344  virtual ~XMLImpHyperlinkContext_Impl() override;
345 
346  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
347  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
348 
349  virtual void SAL_CALL characters( const OUString& rChars ) override;
350 };
351 
352 }
353 
354 XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
355  SvXMLImport& rImport,
356  sal_Int32 /*nElement*/,
357  const Reference< xml::sax::XFastAttributeList > & xAttrList,
358  XMLHints_Impl& rHints,
359  bool& rIgnLeadSpace )
360  : SvXMLImportContext( rImport )
361  , m_rHints( rHints )
362  , mpHint( new XMLHyperlinkHint_Impl( GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) )
363  , mrbIgnoreLeadingSpace( rIgnLeadSpace )
364 {
365  OUString sShow;
366 
367  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
368  {
369  OUString sValue = aIter.toString();
370  switch (aIter.getToken())
371  {
372  case XML_ELEMENT(XLINK, XML_HREF):
373  mpHint->SetHRef( GetImport().GetAbsoluteReference( sValue ) );
374  break;
375  case XML_ELEMENT(OFFICE, XML_NAME):
376  mpHint->SetName( sValue );
377  break;
378  case XML_ELEMENT(OFFICE, XML_TARGET_FRAME_NAME):
379  mpHint->SetTargetFrameName( sValue );
380  break;
381  case XML_ELEMENT(XLINK, XML_SHOW):
382  sShow = sValue;
383  break;
384  case XML_ELEMENT(TEXT, XML_STYLE_NAME):
385  mpHint->SetStyleName( sValue );
386  break;
388  mpHint->SetVisitedStyleName( sValue );
389  break;
390  default:
391  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
392  }
393  }
394 
395  if( !sShow.isEmpty() && mpHint->GetTargetFrameName().isEmpty() )
396  {
397  if( IsXMLToken( sShow, XML_NEW ) )
398  mpHint->SetTargetFrameName(
399  "_blank" );
400  else if( IsXMLToken( sShow, XML_REPLACE ) )
401  mpHint->SetTargetFrameName(
402  "_self" );
403  }
404 
405  if ( mpHint->GetHRef().isEmpty() )
406  {
407  // hyperlink without a URL is not imported.
408  delete mpHint;
409  mpHint = nullptr;
410  }
411  else
412  {
413  m_rHints.push_back(std::unique_ptr<XMLHyperlinkHint_Impl>(mpHint));
414  }
415 }
416 
417 XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
418 {
419  if (mpHint)
420  mpHint->SetEnd( GetImport().GetTextImport()
421  ->GetCursorAsRange()->getStart() );
422 }
423 
424 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLImpHyperlinkContext_Impl::createFastChildContext(
425  sal_Int32 nElement,
426  const uno::Reference< xml::sax::XFastAttributeList>& xAttrList )
427 {
428  if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
429  {
430  XMLEventsImportContext* pCtxt = new XMLEventsImportContext(GetImport());
431  if (mpHint)
432  mpHint->SetEventsContext(pCtxt);
433  return pCtxt;
434  }
435  else
436  {
437  return XMLImpSpanContext_Impl::CreateSpanContext(
438  GetImport(), nElement, xAttrList,
439  m_rHints, mrbIgnoreLeadingSpace );
440  }
441 }
442 
443 void XMLImpHyperlinkContext_Impl::characters( const OUString& rChars )
444 {
445  GetImport().GetTextImport()->InsertString( rChars, mrbIgnoreLeadingSpace );
446 }
447 
448 namespace {
449 
450 class XMLImpRubyBaseContext_Impl : public SvXMLImportContext
451 {
452  XMLHints_Impl& m_rHints;
453 
454  bool& rIgnoreLeadingSpace;
455 
456 public:
457 
458 
459  XMLImpRubyBaseContext_Impl(
460  SvXMLImport& rImport,
461  sal_Int32 nElement,
462  const Reference< xml::sax::XFastAttributeList > & xAttrList,
463  XMLHints_Impl& rHints,
464  bool& rIgnLeadSpace );
465 
466  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
467  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
468 
469  virtual void SAL_CALL characters( const OUString& rChars ) override;
470 };
471 
472 }
473 
474 XMLImpRubyBaseContext_Impl::XMLImpRubyBaseContext_Impl(
475  SvXMLImport& rImport,
476  sal_Int32 /*nElement*/,
477  const Reference< xml::sax::XFastAttributeList > &,
478  XMLHints_Impl& rHints,
479  bool& rIgnLeadSpace )
480  : SvXMLImportContext( rImport )
481  , m_rHints( rHints )
482  , rIgnoreLeadingSpace( rIgnLeadSpace )
483 {
484 }
485 
486 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLImpRubyBaseContext_Impl::createFastChildContext(
487  sal_Int32 nElement,
488  const uno::Reference< xml::sax::XFastAttributeList>& xAttrList )
489 {
490  return XMLImpSpanContext_Impl::CreateSpanContext( GetImport(), nElement, xAttrList,
491  m_rHints, rIgnoreLeadingSpace );
492 }
493 
494 void XMLImpRubyBaseContext_Impl::characters( const OUString& rChars )
495 {
496  GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
497 }
498 
499 namespace {
500 
501 class XMLImpRubyContext_Impl : public SvXMLImportContext
502 {
503  XMLHints_Impl& m_rHints;
504 
505  bool& rIgnoreLeadingSpace;
506 
507  Reference < XTextRange > m_xStart;
508  OUString m_sStyleName;
509  OUString m_sTextStyleName;
510  OUString m_sText;
511 
512 public:
513 
514 
515  XMLImpRubyContext_Impl(
516  SvXMLImport& rImport,
517  sal_Int32 nElement,
518  const Reference< xml::sax::XFastAttributeList > & xAttrList,
519  XMLHints_Impl& rHints,
520  bool& rIgnLeadSpace );
521 
522  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
523 
524  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
525  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
526 
527  void SetTextStyleName( const OUString& s ) { m_sTextStyleName = s; }
528  void AppendText( std::u16string_view s ) { m_sText += s; }
529 };
530 
531 class XMLImpRubyTextContext_Impl : public SvXMLImportContext
532 {
533  XMLImpRubyContext_Impl & m_rRubyContext;
534 
535 public:
536 
537 
538  XMLImpRubyTextContext_Impl(
539  SvXMLImport& rImport,
540  sal_Int32 nElement,
541  const Reference< xml::sax::XFastAttributeList > & xAttrList,
542  XMLImpRubyContext_Impl & rParent );
543 
544  virtual void SAL_CALL characters( const OUString& rChars ) override;
545 };
546 
547 }
548 
549 XMLImpRubyTextContext_Impl::XMLImpRubyTextContext_Impl(
550  SvXMLImport& rImport,
551  sal_Int32 /*nElement*/,
552  const Reference< xml::sax::XFastAttributeList > & xAttrList,
553  XMLImpRubyContext_Impl & rParent )
554  : SvXMLImportContext( rImport )
555  , m_rRubyContext( rParent )
556 {
557  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
558  {
559  if( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) )
560  {
561  m_rRubyContext.SetTextStyleName( aIter.toString() );
562  break;
563  }
564  }
565 }
566 
567 void XMLImpRubyTextContext_Impl::characters( const OUString& rChars )
568 {
569  m_rRubyContext.AppendText( rChars );
570 }
571 
572 
573 XMLImpRubyContext_Impl::XMLImpRubyContext_Impl(
574  SvXMLImport& rImport,
575  sal_Int32 /*nElement*/,
576  const Reference< xml::sax::XFastAttributeList > & xAttrList,
577  XMLHints_Impl& rHints,
578  bool& rIgnLeadSpace )
579  : SvXMLImportContext( rImport )
580  , m_rHints( rHints )
581  , rIgnoreLeadingSpace( rIgnLeadSpace )
582  , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
583 {
584  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
585  {
586  if( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) )
587  {
588  m_sStyleName = aIter.toString();
589  break;
590  }
591  }
592 }
593 
594 void XMLImpRubyContext_Impl::endFastElement(sal_Int32 )
595 {
596  const rtl::Reference < XMLTextImportHelper > xTextImport(
597  GetImport().GetTextImport());
598  const Reference < XTextCursor > xAttrCursor(
599  xTextImport->GetText()->createTextCursorByRange( m_xStart ));
600  if (!xAttrCursor.is())
601  {
602  SAL_WARN("xmloff.text", "cannot insert ruby");
603  return;
604  }
605  xAttrCursor->gotoRange(xTextImport->GetCursorAsRange()->getStart(),
606  true);
607  xTextImport->SetRuby( GetImport(), xAttrCursor,
608  m_sStyleName, m_sTextStyleName, m_sText );
609 }
610 
611 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLImpRubyContext_Impl::createFastChildContext(
612  sal_Int32 nElement,
613  const uno::Reference< xml::sax::XFastAttributeList>& xAttrList )
614 {
615  if( nElement == XML_ELEMENT(TEXT, XML_RUBY_BASE) )
616  return new XMLImpRubyBaseContext_Impl( GetImport(), nElement,
617  xAttrList,
618  m_rHints,
619  rIgnoreLeadingSpace );
620  else if( nElement == XML_ELEMENT(TEXT, XML_RUBY_TEXT) )
621  return new XMLImpRubyTextContext_Impl( GetImport(), nElement,
622  xAttrList,
623  *this );
624  else
625  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
626 
627  return nullptr;
628 }
629 
630 namespace {
631 
634 class XMLMetaImportContextBase : public SvXMLImportContext
635 {
636  XMLHints_Impl& m_rHints;
637 
638  bool& m_rIgnoreLeadingSpace;
639 
641  Reference<XTextRange> m_xStart;
642 
643 protected:
644  OUString m_XmlId;
645 
646 public:
647 
648  XMLMetaImportContextBase(
649  SvXMLImport& i_rImport,
650  const sal_Int32 nElement,
651  XMLHints_Impl& i_rHints,
652  bool & i_rIgnoreLeadingSpace );
653 
654  virtual void SAL_CALL startFastElement(
655  sal_Int32 nElement,
656  const Reference<xml::sax::XFastAttributeList> & i_xAttrList) override;
657 
658  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
659 
660  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
661  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
662 
663  virtual void SAL_CALL characters( const OUString& i_rChars ) override;
664 
665  virtual void ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter);
666 
667  virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange)
668  = 0;
669 };
670 
671 }
672 
673 XMLMetaImportContextBase::XMLMetaImportContextBase(
674  SvXMLImport& i_rImport,
675  const sal_Int32 /*i_nElement*/,
676  XMLHints_Impl& i_rHints,
677  bool & i_rIgnoreLeadingSpace )
678  : SvXMLImportContext( i_rImport )
679  , m_rHints( i_rHints )
680  , m_rIgnoreLeadingSpace( i_rIgnoreLeadingSpace )
681  , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
682 {
683 }
684 
685 void XMLMetaImportContextBase::startFastElement(
686  sal_Int32 /*nElement*/,
687  const Reference<xml::sax::XFastAttributeList> & xAttrList)
688 {
689  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
690  ProcessAttribute(aIter);
691 }
692 
693 void XMLMetaImportContextBase::endFastElement(sal_Int32 )
694 {
695  SAL_WARN_IF(!m_xStart.is(), "xmloff.text", "no mxStart?");
696  if (!m_xStart.is()) return;
697 
698  const Reference<XTextRange> xEndRange(
699  GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
700 
701  // create range for insertion
702  const Reference<XTextCursor> xInsertionCursor(
703  GetImport().GetTextImport()->GetText()->createTextCursorByRange(
704  xEndRange) );
705  xInsertionCursor->gotoRange(m_xStart, true);
706 
707  InsertMeta(xInsertionCursor);
708 }
709 
710 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLMetaImportContextBase::createFastChildContext(
711  sal_Int32 nElement,
712  const uno::Reference< xml::sax::XFastAttributeList>& xAttrList )
713 {
714  return XMLImpSpanContext_Impl::CreateSpanContext( GetImport(), nElement,
715  xAttrList, m_rHints, m_rIgnoreLeadingSpace );
716 }
717 
718 void XMLMetaImportContextBase::characters( const OUString& i_rChars )
719 {
720  GetImport().GetTextImport()->InsertString(i_rChars, m_rIgnoreLeadingSpace);
721 }
722 
723 void XMLMetaImportContextBase::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter)
724 {
725  if ( aIter.getToken() == XML_ELEMENT(XML, XML_ID) )
726  m_XmlId = aIter.toString();
727  else
728  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
729 }
730 
731 namespace {
732 
734 class XMLMetaImportContext : public XMLMetaImportContextBase
735 {
736  // RDFa
737  bool m_bHaveAbout;
738  OUString m_sAbout;
739  OUString m_sProperty;
740  OUString m_sContent;
741  OUString m_sDatatype;
742 
743 public:
744 
745  XMLMetaImportContext(
746  SvXMLImport& i_rImport,
747  sal_Int32 nElement,
748  XMLHints_Impl& i_rHints,
749  bool & i_rIgnoreLeadingSpace );
750 
751  virtual void ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter) override;
752 
753  virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange) override;
754 };
755 
756 }
757 
758 XMLMetaImportContext::XMLMetaImportContext(
759  SvXMLImport& i_rImport,
760  sal_Int32 nElement,
761  XMLHints_Impl& i_rHints,
762  bool & i_rIgnoreLeadingSpace )
763  : XMLMetaImportContextBase( i_rImport, nElement,
764  i_rHints, i_rIgnoreLeadingSpace )
765  , m_bHaveAbout(false)
766 {
767 }
768 
769 void XMLMetaImportContext::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter)
770 {
771  switch (aIter.getToken())
772  {
773  // RDFa
774  case XML_ELEMENT(XHTML, XML_ABOUT):
775  m_sAbout = aIter.toString();
776  m_bHaveAbout = true;
777  break;
778  case XML_ELEMENT(XHTML, XML_PROPERTY):
779  m_sProperty = aIter.toString();
780  break;
781  case XML_ELEMENT(XHTML, XML_CONTENT):
782  m_sContent = aIter.toString();
783  break;
784  case XML_ELEMENT(XHTML, XML_DATATYPE):
785  m_sDatatype = aIter.toString();
786  break;
787  default:
788  XMLMetaImportContextBase::ProcessAttribute(aIter);
789  }
790 }
791 
792 void XMLMetaImportContext::InsertMeta(
793  const Reference<XTextRange> & i_xInsertionRange)
794 {
795  SAL_WARN_IF(m_bHaveAbout == m_sProperty.isEmpty(), "xmloff.text", "XMLMetaImportContext::InsertMeta: invalid RDFa?");
796  if (!m_XmlId.isEmpty() || (m_bHaveAbout && !m_sProperty.isEmpty()))
797  {
798  // insert mark
799  const uno::Reference<rdf::XMetadatable> xMeta(
801  GetImport(),
802  "com.sun.star.text.InContentMetadata",
803  OUString(),
804  i_xInsertionRange, m_XmlId),
805  uno::UNO_QUERY);
806  SAL_WARN_IF(!xMeta.is(), "xmloff.text", "cannot insert Meta?");
807 
808  if (xMeta.is() && m_bHaveAbout)
809  {
810  GetImport().AddRDFa(xMeta,
811  m_sAbout, m_sProperty, m_sContent, m_sDatatype);
812  }
813  }
814  else
815  {
816  SAL_INFO("xmloff.text", "invalid <text:meta>: no xml:id, no valid RDFa");
817  }
818 }
819 
820 namespace {
821 
823 class XMLMetaFieldImportContext : public XMLMetaImportContextBase
824 {
825  OUString m_DataStyleName;
826 
827 public:
828 
829  XMLMetaFieldImportContext(
830  SvXMLImport& i_rImport,
831  sal_Int32 nElement,
832  XMLHints_Impl& i_rHints,
833  bool & i_rIgnoreLeadingSpace );
834 
835  virtual void ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter) override;
836 
837  virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange) override;
838 };
839 
840 }
841 
842 XMLMetaFieldImportContext::XMLMetaFieldImportContext(
843  SvXMLImport& i_rImport,
844  sal_Int32 nElement,
845  XMLHints_Impl& i_rHints,
846  bool & i_rIgnoreLeadingSpace )
847  : XMLMetaImportContextBase( i_rImport, nElement,
848  i_rHints, i_rIgnoreLeadingSpace )
849 {
850 }
851 
852 void XMLMetaFieldImportContext::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter)
853 {
854  switch (aIter.getToken())
855  {
856  case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME):
857  m_DataStyleName = aIter.toString();
858  break;
859  default:
860  XMLMetaImportContextBase::ProcessAttribute(aIter);
861  }
862 }
863 
864 void XMLMetaFieldImportContext::InsertMeta(
865  const Reference<XTextRange> & i_xInsertionRange)
866 {
867  if (!m_XmlId.isEmpty()) // valid?
868  {
869  // insert mark
870  const Reference<XPropertySet> xPropertySet(
872  GetImport(),
873  "com.sun.star.text.textfield.MetadataField",
874  OUString(),
875  i_xInsertionRange, m_XmlId),
876  UNO_QUERY);
877  SAL_WARN_IF(!xPropertySet.is(), "xmloff.text", "cannot insert MetaField?");
878  if (!xPropertySet.is()) return;
879 
880  if (!m_DataStyleName.isEmpty())
881  {
882  bool isDefaultLanguage(true);
883 
884  const sal_Int32 nKey( GetImport().GetTextImport()->GetDataStyleKey(
885  m_DataStyleName, & isDefaultLanguage) );
886 
887  if (-1 != nKey)
888  {
889  OUString sPropertyIsFixedLanguage("IsFixedLanguage");
890  xPropertySet->setPropertyValue("NumberFormat", Any(nKey));
891  if ( xPropertySet->getPropertySetInfo()->
892  hasPropertyByName( sPropertyIsFixedLanguage ) )
893  {
894  xPropertySet->setPropertyValue( sPropertyIsFixedLanguage,
895  Any(!isDefaultLanguage) );
896  }
897  }
898  }
899  }
900  else
901  {
902  SAL_INFO("xmloff.text", "invalid <text:meta-field>: no xml:id");
903  }
904 }
905 
906 namespace {
907 
915 class XMLIndexMarkImportContext_Impl : public SvXMLImportContext
916 {
917  XMLHints_Impl& m_rHints;
918  OUString sID;
919 
920 public:
921 
922  XMLIndexMarkImportContext_Impl(
923  SvXMLImport& rImport,
924  XMLHints_Impl& rHints);
925 
926  void SAL_CALL startFastElement(sal_Int32 nElement, const Reference<xml::sax::XFastAttributeList> & xAttrList) override;
927 
928 protected:
929 
931  void ProcessAttributes(sal_Int32 nElement, const Reference<xml::sax::XFastAttributeList> & xAttrList,
933 
942  virtual void ProcessAttribute(sal_Int32 nElement,
945 
946  static void GetServiceName(OUString& sServiceName,
947  sal_Int32 nElement);
948 
949  bool CreateMark(Reference<beans::XPropertySet>& rPropSet,
950  const OUString& rServiceName);
951 };
952 
953 }
954 
955 XMLIndexMarkImportContext_Impl::XMLIndexMarkImportContext_Impl(
956  SvXMLImport& rImport,
957  XMLHints_Impl& rHints)
958  : SvXMLImportContext(rImport)
959  , m_rHints(rHints)
960 {
961 }
962 
963 void XMLIndexMarkImportContext_Impl::startFastElement(
964  sal_Int32 nElement,
965  const Reference<xml::sax::XFastAttributeList> & xAttrList)
966 {
967  // get Cursor position (needed for all cases)
968  Reference<XTextRange> xPos(
969  GetImport().GetTextImport()->GetCursor()->getStart());
971 
972  switch (nElement)
973  {
974  case XML_ELEMENT(TEXT, XML_TOC_MARK):
977  {
978  // single mark: create mark and insert
979  OUString sService;
980  GetServiceName(sService, nElement);
981  if (CreateMark(xMark, sService))
982  {
983  ProcessAttributes(nElement, xAttrList, xMark);
984  m_rHints.push_back(
985  std::make_unique<XMLIndexMarkHint_Impl>(xMark, xPos));
986  }
987  // else: can't create mark -> ignore
988  break;
989  }
990 
991  case XML_ELEMENT(TEXT, XML_TOC_MARK_START):
994  {
995  // start: create mark and insert (if ID is found)
996  OUString sService;
997  GetServiceName(sService, nElement);
998  if (CreateMark(xMark, sService))
999  {
1000  ProcessAttributes(nElement, xAttrList, xMark);
1001  if (!sID.isEmpty())
1002  {
1003  // process only if we find an ID
1004  m_rHints.push_back(
1005  std::make_unique<XMLIndexMarkHint_Impl>(xMark, xPos, sID));
1006  }
1007  // else: no ID -> we'll never find the end -> ignore
1008  }
1009  // else: can't create mark -> ignore
1010  break;
1011  }
1012 
1013  case XML_ELEMENT(TEXT, XML_TOC_MARK_END):
1016  {
1017  // end: search for ID and set end of mark
1018 
1019  // call process attributes with empty XPropertySet:
1020  ProcessAttributes(nElement, xAttrList, xMark);
1021  if (!sID.isEmpty())
1022  {
1023  // if we have an ID, find the hint and set the end position
1024  XMLIndexMarkHint_Impl *const pHint = m_rHints.GetIndexHintById(sID);
1025  if (pHint)
1026  // set end and stop searching
1027  pHint->SetEnd(xPos);
1028  }
1029  // else: no ID -> ignore
1030  break;
1031  }
1032 
1033  default:
1034  SAL_WARN("xmloff.text", "unknown index mark type!");
1035  break;
1036  }
1037 }
1038 
1039 void XMLIndexMarkImportContext_Impl::ProcessAttributes(
1040  sal_Int32 nElement,
1041  const Reference<xml::sax::XFastAttributeList> & xAttrList,
1043 {
1044  // process attributes
1045  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1046  {
1047  ProcessAttribute(nElement, aIter, rPropSet);
1048  }
1049 }
1050 
1051 void XMLIndexMarkImportContext_Impl::ProcessAttribute(
1052  sal_Int32 nElement,
1055 {
1056  // we only know ID + string-value attribute;
1057  // (former: marks, latter: -start + -end-marks)
1058  // the remainder is handled in sub-classes
1059  switch (nElement)
1060  {
1061  case XML_ELEMENT(TEXT, XML_TOC_MARK):
1064  if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STRING_VALUE) )
1065  {
1066  rPropSet->setPropertyValue("AlternativeText", uno::makeAny(aIter.toString()));
1067  }
1068  // else: ignore!
1069  break;
1070 
1071  case XML_ELEMENT(TEXT, XML_TOC_MARK_START):
1077  if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_ID) )
1078  {
1079  sID = aIter.toString();
1080  }
1081  // else: ignore
1082  break;
1083 
1084  default:
1085  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
1086  break;
1087  }
1088 }
1089 
1090 
1091 void XMLIndexMarkImportContext_Impl::GetServiceName(
1092  OUString& sServiceName,
1093  sal_Int32 nElement)
1094 {
1095  switch (nElement)
1096  {
1097  case XML_ELEMENT(TEXT, XML_TOC_MARK):
1100  {
1101  sServiceName = "com.sun.star.text.ContentIndexMark";
1102  break;
1103  }
1104 
1105  case XML_ELEMENT(TEXT, XML_USER_INDEX_MARK):
1108  {
1109  sServiceName = "com.sun.star.text.UserIndexMark";
1110  break;
1111  }
1112 
1116  {
1117  sServiceName = "com.sun.star.text.DocumentIndexMark";
1118  break;
1119  }
1120 
1121  default:
1122  {
1123  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
1124  sServiceName.clear();
1125  break;
1126  }
1127  }
1128 }
1129 
1130 bool XMLIndexMarkImportContext_Impl::CreateMark(
1132  const OUString& rServiceName)
1133 {
1134  Reference<lang::XMultiServiceFactory>
1135  xFactory(GetImport().GetModel(), UNO_QUERY);
1136 
1137  if( xFactory.is() )
1138  {
1139  Reference<beans::XPropertySet> xPropSet( xFactory->createInstance(rServiceName), UNO_QUERY );
1140  if (xPropSet.is())
1141  rPropSet = xPropSet;
1142  return true;
1143  }
1144 
1145  return false;
1146 }
1147 
1148 namespace {
1149 
1150 class XMLTOCMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1151 {
1152 public:
1153 
1154  XMLTOCMarkImportContext_Impl(
1155  SvXMLImport& rImport,
1156  XMLHints_Impl& rHints);
1157 
1158 protected:
1159 
1161  virtual void ProcessAttribute(sal_Int32 nElement,
1163  Reference<beans::XPropertySet>& rPropSet) override;
1164 };
1165 
1166 }
1167 
1168 XMLTOCMarkImportContext_Impl::XMLTOCMarkImportContext_Impl(
1169  SvXMLImport& rImport, XMLHints_Impl& rHints) :
1170  XMLIndexMarkImportContext_Impl(rImport, rHints)
1171 {
1172 }
1173 
1174 void XMLTOCMarkImportContext_Impl::ProcessAttribute(
1175  sal_Int32 nElement,
1178 {
1179  SAL_WARN_IF(!rPropSet.is(), "xmloff.text", "need PropertySet");
1180 
1181  switch (aIter.getToken())
1182  {
1183  case XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL):
1184  {
1185  // ouline level: set Level property
1186  sal_Int32 nTmp;
1187  if (::sax::Converter::convertNumber( nTmp, aIter.toView() )
1188  && nTmp >= 1
1189  && nTmp < GetImport().GetTextImport()->
1190  GetChapterNumbering()->getCount() )
1191  {
1192  rPropSet->setPropertyValue("Level", uno::makeAny(static_cast<sal_Int16>(nTmp - 1)));
1193  }
1194  // else: value out of range -> ignore
1195  break;
1196  }
1197  default:
1198  // else: delegate to superclass
1199  XMLIndexMarkImportContext_Impl::ProcessAttribute(
1200  nElement, aIter, rPropSet);
1201  }
1202 }
1203 
1204 namespace {
1205 
1206 class XMLUserIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1207 {
1208 public:
1209 
1210  XMLUserIndexMarkImportContext_Impl(
1211  SvXMLImport& rImport,
1212  XMLHints_Impl& rHints);
1213 
1214 protected:
1215 
1217  virtual void ProcessAttribute(sal_Int32 nElement,
1219  Reference<beans::XPropertySet>& rPropSet) override;
1220 };
1221 
1222 }
1223 
1224 XMLUserIndexMarkImportContext_Impl::XMLUserIndexMarkImportContext_Impl(
1225  SvXMLImport& rImport, XMLHints_Impl& rHints) :
1226  XMLIndexMarkImportContext_Impl(rImport, rHints)
1227 {
1228 }
1229 
1230 void XMLUserIndexMarkImportContext_Impl::ProcessAttribute(
1231  sal_Int32 nElement,
1234 {
1235  switch (aIter.getToken())
1236  {
1237  case XML_ELEMENT(TEXT, XML_INDEX_NAME):
1238  rPropSet->setPropertyValue("UserIndexName", uno::makeAny(aIter.toString()));
1239  break;
1240  case XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL):
1241  {
1242  // ouline level: set Level property
1243  sal_Int32 nTmp;
1245  nTmp, aIter.toView(), 0,
1246  GetImport().GetTextImport()->GetChapterNumbering()->getCount()))
1247  {
1248  rPropSet->setPropertyValue("Level", uno::makeAny(static_cast<sal_Int16>(nTmp - 1)));
1249  }
1250  // else: value out of range -> ignore
1251  break;
1252  }
1253  default:
1254  // else: unknown text property: delegate to super class
1255  XMLIndexMarkImportContext_Impl::ProcessAttribute(
1256  nElement, aIter, rPropSet);
1257  }
1258 }
1259 
1260 namespace {
1261 
1262 class XMLAlphaIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1263 {
1264 public:
1265 
1266  XMLAlphaIndexMarkImportContext_Impl(
1267  SvXMLImport& rImport,
1268  XMLHints_Impl& rHints);
1269 
1270 protected:
1271 
1273  virtual void ProcessAttribute(sal_Int32 nElement,
1275  Reference<beans::XPropertySet>& rPropSet) override;
1276 };
1277 
1278 }
1279 
1280 XMLAlphaIndexMarkImportContext_Impl::XMLAlphaIndexMarkImportContext_Impl(
1281  SvXMLImport& rImport, XMLHints_Impl& rHints) :
1282  XMLIndexMarkImportContext_Impl(rImport, rHints)
1283 {
1284 }
1285 
1286 void XMLAlphaIndexMarkImportContext_Impl::ProcessAttribute(
1287  sal_Int32 nElement,
1290 {
1291  switch (aIter.getToken())
1292  {
1293  case XML_ELEMENT(TEXT, XML_KEY1):
1294  rPropSet->setPropertyValue("PrimaryKey", uno::makeAny(aIter.toString()));
1295  break;
1296  case XML_ELEMENT(TEXT, XML_KEY2):
1297  rPropSet->setPropertyValue("SecondaryKey", uno::makeAny(aIter.toString()));
1298  break;
1299  case XML_ELEMENT(TEXT, XML_KEY1_PHONETIC):
1300  rPropSet->setPropertyValue("PrimaryKeyReading", uno::makeAny(aIter.toString()));
1301  break;
1302  case XML_ELEMENT(TEXT, XML_KEY2_PHONETIC):
1303  rPropSet->setPropertyValue("SecondaryKeyReading", uno::makeAny(aIter.toString()));
1304  break;
1306  rPropSet->setPropertyValue("TextReading", uno::makeAny(aIter.toString()));
1307  break;
1308  case XML_ELEMENT(TEXT, XML_MAIN_ENTRY):
1309  {
1310  bool bMainEntry = false;
1311  bool bTmp(false);
1312 
1313  if (::sax::Converter::convertBool(bTmp, aIter.toView()))
1314  bMainEntry = bTmp;
1315 
1316  rPropSet->setPropertyValue("IsMainEntry", uno::makeAny(bMainEntry));
1317  break;
1318  }
1319  default:
1320  XMLIndexMarkImportContext_Impl::ProcessAttribute(
1321  nElement, aIter, rPropSet);
1322  }
1323 }
1324 
1325 
1326 XMLImpSpanContext_Impl::XMLImpSpanContext_Impl(
1327  SvXMLImport& rImport,
1328  sal_Int32 /*nElement*/,
1329  const Reference< xml::sax::XFastAttributeList > & xAttrList,
1330  XMLHints_Impl& rHints,
1331  bool& rIgnLeadSpace,
1332  sal_uInt8 nSFConvFlags)
1333 : SvXMLImportContext( rImport )
1334 , m_rHints( rHints )
1335 , pHint( nullptr )
1336 , rIgnoreLeadingSpace( rIgnLeadSpace )
1337 , nStarFontsConvFlags( nSFConvFlags & (CONV_FROM_STAR_BATS|CONV_FROM_STAR_MATH) )
1338 {
1339  OUString aStyleName;
1340 
1341  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
1342  {
1343  if( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) )
1344  {
1345  aStyleName = aIter.toString();
1346  break;
1347  }
1348  }
1349 
1350  if( !aStyleName.isEmpty() )
1351  {
1352  pHint = new XMLStyleHint_Impl( aStyleName,
1353  GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
1354  m_rHints.push_back(std::unique_ptr<XMLStyleHint_Impl>(pHint));
1355  }
1356 }
1357 
1358 void XMLImpSpanContext_Impl::endFastElement(sal_Int32 )
1359 {
1360  if (!pHint)
1361  return;
1362 
1363  Reference<XTextRange> xCrsrRange(GetImport().GetTextImport()->GetCursorAsRange());
1364  if (!xCrsrRange.is())
1365  return; // Robust (defective file)
1366 
1367  pHint->SetEnd(xCrsrRange->getStart());
1368 }
1369 
1370 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLImpSpanContext_Impl::CreateSpanContext(
1371  SvXMLImport& rImport,
1372  sal_Int32 nElement,
1373  const Reference< xml::sax::XFastAttributeList > & xAttrList,
1374  XMLHints_Impl& rHints,
1375  bool& rIgnoreLeadingSpace,
1376  sal_uInt8 nStarFontsConvFlags
1377  )
1378 {
1379  SvXMLImportContext *pContext = nullptr;
1380 
1381  switch( nElement )
1382  {
1383  case XML_ELEMENT(TEXT, XML_SPAN):
1384  pContext = new XMLImpSpanContext_Impl( rImport, nElement,
1385  xAttrList,
1386  rHints,
1387  rIgnoreLeadingSpace
1388  ,nStarFontsConvFlags
1389  );
1390  break;
1391 
1392  case XML_ELEMENT(TEXT, XML_TAB):
1393  pContext = new XMLCharContext( rImport, xAttrList,
1394  0x0009, false );
1395  rIgnoreLeadingSpace = false;
1396  break;
1397 
1398  case XML_ELEMENT(TEXT, XML_LINE_BREAK):
1399  pContext = new XMLCharContext( rImport, ControlCharacter::LINE_BREAK );
1400  rIgnoreLeadingSpace = false;
1401  break;
1402 
1403  case XML_ELEMENT(TEXT, XML_S):
1404  pContext = new XMLCharContext( rImport, xAttrList, 0x0020, true );
1405  rIgnoreLeadingSpace = false;
1406  break;
1407 
1408  case XML_ELEMENT(TEXT, XML_A):
1409  {
1410  // test for HyperLinkURL property. If present, insert link as
1411  // text property (StarWriter), else try to insert as text
1412  // field (StarCalc, StarDraw, ...)
1413  Reference< beans::XPropertySet > xPropSet( rImport.GetTextImport()->GetCursor(), UNO_QUERY );
1414 
1415  if ( xPropSet->getPropertySetInfo()->hasPropertyByName( "HyperLinkURL" ) )
1416  {
1417  pContext = new XMLImpHyperlinkContext_Impl(
1418  rImport,
1419  nElement,
1420  xAttrList,
1421  rHints,
1422  rIgnoreLeadingSpace );
1423  }
1424  else
1425  {
1426  pContext = new XMLUrlFieldImportContext(rImport, *rImport.GetTextImport());
1427  //whitespace handling like other fields
1428  rIgnoreLeadingSpace = false;
1429 
1430  }
1431  break;
1432  }
1433 
1434  case XML_ELEMENT(TEXT, XML_RUBY):
1435  pContext = new XMLImpRubyContext_Impl( rImport, nElement,
1436  xAttrList,
1437  rHints,
1438  rIgnoreLeadingSpace );
1439  break;
1440 
1441  case XML_ELEMENT(TEXT, XML_NOTE):
1442  if (rImport.GetTextImport()->IsInFrame())
1443  {
1444  // we must not insert footnotes into text frames
1445  pContext = new SvXMLImportContext( rImport );
1446  }
1447  else
1448  {
1449  pContext = new XMLFootnoteImportContext(rImport, *rImport.GetTextImport());
1450  }
1451  rIgnoreLeadingSpace = false;
1452  break;
1453 
1454  case XML_ELEMENT(TEXT, XML_REFERENCE_MARK):
1455  case XML_ELEMENT(TEXT, XML_BOOKMARK):
1458  pContext = new XMLTextMarkImportContext(rImport, *rImport.GetTextImport(),
1459  rHints.GetCrossRefHeadingBookmark());
1460  break;
1461 
1462  case XML_ELEMENT(FIELD, XML_FIELDMARK):
1465  pContext = new XMLTextMarkImportContext(rImport, *rImport.GetTextImport(),
1466  rHints.GetCrossRefHeadingBookmark());
1467  break;
1468 
1470  pContext = new XMLStartReferenceContext_Impl( rImport,
1471  rHints, xAttrList );
1472  break;
1473 
1474  case XML_ELEMENT(TEXT, XML_REFERENCE_MARK_END):
1475  pContext = new XMLEndReferenceContext_Impl( rImport,
1476  rHints, xAttrList );
1477  break;
1478 
1479  case XML_ELEMENT(DRAW, XML_FRAME):
1480  {
1481  Reference < XTextRange > xAnchorPos =
1482  rImport.GetTextImport()->GetCursor()->getStart();
1483  XMLTextFrameContext *pTextFrameContext =
1484  new XMLTextFrameContext(rImport,
1485  xAttrList,
1486  TextContentAnchorType_AS_CHARACTER );
1487  // Remove check for text content. (#i33242#)
1488  // Check for text content is done on the processing of the hint
1489  if( TextContentAnchorType_AT_CHARACTER ==
1490  pTextFrameContext->GetAnchorType() )
1491  {
1492  rHints.push_back(std::make_unique<XMLTextFrameHint_Impl>(
1493  pTextFrameContext, xAnchorPos));
1494  }
1495  pContext = pTextFrameContext;
1496  rIgnoreLeadingSpace = false;
1497  }
1498  break;
1499  case XML_ELEMENT(DRAW, XML_A):
1500  {
1501  Reference < XTextRange > xAnchorPos(rImport.GetTextImport()->GetCursor()->getStart());
1502  pContext =
1503  new XMLTextFrameHyperlinkContext( rImport, nElement,
1504  xAttrList,
1505  TextContentAnchorType_AS_CHARACTER );
1506  rHints.push_back(
1507  std::make_unique<XMLTextFrameHint_Impl>(pContext, xAnchorPos));
1508  }
1509  break;
1510 
1511  case XML_ELEMENT(TEXT, XML_TOC_MARK):
1513  pContext = new XMLTOCMarkImportContext_Impl(
1514  rImport, rHints);
1515  break;
1516 
1517  case XML_ELEMENT(TEXT, XML_USER_INDEX_MARK):
1519  pContext = new XMLUserIndexMarkImportContext_Impl(
1520  rImport, rHints);
1521  break;
1522 
1525  pContext = new XMLAlphaIndexMarkImportContext_Impl(
1526  rImport, rHints);
1527  break;
1528 
1529  case XML_ELEMENT(TEXT, XML_TOC_MARK_END):
1532  pContext = new XMLIndexMarkImportContext_Impl(
1533  rImport, rHints);
1534  break;
1535 
1536  case XML_ELEMENT(TEXT, XML_CHANGE_START):
1538  case XML_ELEMENT(TEXT, XML_CHANGE):
1539  pContext = new XMLChangeImportContext(
1540  rImport,
1541  ((nElement == XML_ELEMENT(TEXT, XML_CHANGE_END))
1542  ? XMLChangeImportContext::Element::END
1543  : (nElement == XML_ELEMENT(TEXT, XML_CHANGE_START))
1544  ? XMLChangeImportContext::Element::START
1545  : XMLChangeImportContext::Element::POINT),
1546  false);
1547  break;
1548 
1549  case XML_ELEMENT(TEXT, XML_META):
1550  pContext = new XMLMetaImportContext(rImport, nElement,
1551  rHints, rIgnoreLeadingSpace );
1552  break;
1553 
1554  case XML_ELEMENT(TEXT, XML_META_FIELD):
1555  pContext = new XMLMetaFieldImportContext(rImport, nElement,
1556  rHints, rIgnoreLeadingSpace );
1557  break;
1558 
1559  default:
1560  // none of the above? then it's probably a text field!
1562  rImport, *rImport.GetTextImport(), nElement);
1563  // #108784# import draw elements (except control shapes in headers)
1564  if( pContext == nullptr &&
1565  !( rImport.GetTextImport()->IsInHeaderFooter() &&
1566  nElement == XML_ELEMENT(DRAW, XML_CONTROL ) ) )
1567  {
1568  Reference < XShapes > xShapes;
1570  rImport, nElement, xAttrList, xShapes );
1571  pContext = pShapeContext;
1572  // OD 2004-04-20 #i26791# - keep shape in a text frame hint to
1573  // adjust its anchor position, if its at-character anchored
1574  Reference < XTextRange > xAnchorPos =
1575  rImport.GetTextImport()->GetCursor()->getStart();
1576  rHints.push_back(
1577  std::make_unique<XMLDrawHint_Impl>(pShapeContext, xAnchorPos));
1578  }
1579  // Behind fields, shapes and any unknown content blanks aren't ignored
1580  rIgnoreLeadingSpace = false;
1581  }
1582 
1583  if (!pContext)
1584  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
1585  return pContext;
1586 }
1587 
1588 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLImpSpanContext_Impl::createFastChildContext(
1589  sal_Int32 nElement,
1590  const uno::Reference< xml::sax::XFastAttributeList>& xAttrList )
1591 {
1592  return CreateSpanContext( GetImport(), nElement, xAttrList,
1593  m_rHints, rIgnoreLeadingSpace
1594  ,nStarFontsConvFlags
1595  );
1596 }
1597 
1598 void XMLImpSpanContext_Impl::characters( const OUString& rChars )
1599 {
1600  OUString sStyleName;
1601  if( pHint )
1602  sStyleName = pHint->GetStyleName();
1603  OUString sChars =
1604  GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
1605  nStarFontsConvFlags,
1606  false, GetImport() );
1607  GetImport().GetTextImport()->InsertString( sChars, rIgnoreLeadingSpace );
1608 }
1609 
1610 
1612  SvXMLImport& rImport,
1613  sal_Int32 nElement,
1614  const Reference< xml::sax::XFastAttributeList > & xAttrList ) :
1615  SvXMLImportContext( rImport ),
1616  xStart( rImport.GetTextImport()->GetCursorAsRange()->getStart() ),
1617  m_bHaveAbout(false),
1618  nOutlineLevel( (nElement & TOKEN_MASK) == XML_H ? 1 : -1 ),
1619  // Lost outline numbering in master document (#i73509#)
1620  mbOutlineLevelAttrFound( false ),
1621  mbOutlineContentVisible(true),
1622  bIgnoreLeadingSpace( true ),
1623  bHeading( (nElement & TOKEN_MASK) == XML_H ),
1624  bIsListHeader( false ),
1625  bIsRestart (false),
1626  nStartValue(0),
1627  nStarFontsConvFlags( 0 )
1628 {
1629  bool bHaveXmlId( false );
1630  OUString aCondStyleName;
1631 
1632  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
1633  {
1634  switch( aIter.getToken() )
1635  {
1636  case XML_ELEMENT(XML, XML_ID):
1637  m_sXmlId = aIter.toString();
1638  bHaveXmlId = true;
1639  break;
1640  case XML_ELEMENT(XHTML, XML_ABOUT):
1641  m_sAbout = aIter.toString();
1642  m_bHaveAbout = true;
1643  break;
1644  case XML_ELEMENT(XHTML, XML_PROPERTY):
1645  m_sProperty = aIter.toString();
1646  break;
1647  case XML_ELEMENT(XHTML, XML_CONTENT):
1648  m_sContent = aIter.toString();
1649  break;
1650  case XML_ELEMENT(XHTML, XML_DATATYPE):
1651  m_sDatatype = aIter.toString();
1652  break;
1653  case XML_ELEMENT(TEXT, XML_ID):
1654  if (!bHaveXmlId) { m_sXmlId = aIter.toString(); }
1655  break;
1656  case XML_ELEMENT(TEXT, XML_STYLE_NAME):
1657  sStyleName = aIter.toString();
1658  break;
1659  case XML_ELEMENT(TEXT, XML_COND_STYLE_NAME):
1660  aCondStyleName = aIter.toString();
1661  break;
1662  case XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL):
1663  {
1664  sal_Int32 nTmp = aIter.toInt32();
1665  if( nTmp > 0 )
1666  {
1667  if( nTmp > 127 )
1668  nTmp = 127;
1669  nOutlineLevel = static_cast<sal_Int8>(nTmp);
1670  }
1671  // Lost outline numbering in master document (#i73509#)
1672  mbOutlineLevelAttrFound = true;
1673  }
1674  break;
1676  {
1677  bool bBool(false);
1678  if (::sax::Converter::convertBool(bBool, aIter.toView()))
1679  mbOutlineContentVisible = bBool;
1680  }
1681  break;
1682  case XML_ELEMENT(TEXT, XML_IS_LIST_HEADER):
1683  {
1684  bool bBool(false);
1685  if (::sax::Converter::convertBool(bBool, aIter.toView()))
1686  bIsListHeader = bBool;
1687  }
1688  break;
1689  case XML_ELEMENT(TEXT, XML_RESTART_NUMBERING):
1690  {
1691  bool bBool(false);
1692  if (::sax::Converter::convertBool(bBool, aIter.toView()))
1693  bIsRestart = bBool;
1694  }
1695  break;
1696  case XML_ELEMENT(TEXT, XML_START_VALUE):
1697  {
1698  nStartValue = sal::static_int_cast< sal_Int16 >(aIter.toInt32());
1699  }
1700  break;
1701  default:
1702  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
1703  }
1704  }
1705 
1706  if( !aCondStyleName.isEmpty() )
1707  sStyleName = aCondStyleName;
1708 }
1709 
1711 {
1713  GetImport().GetTextImport());
1714  Reference < XTextRange > xCrsrRange( xTxtImport->GetCursorAsRange() );
1715  if( !xCrsrRange.is() )
1716  return; // Robust (defective file)
1717  Reference < XTextRange > xEnd(xCrsrRange->getStart());
1718 
1719  // if we have an id set for this paragraph, get a cursor for this
1720  // paragraph and register it with the given identifier
1721  // FIXME: this is just temporary, and should be removed when
1722  // EditEngine paragraphs implement XMetadatable!
1723  if (!m_sXmlId.isEmpty())
1724  {
1725  Reference < XTextCursor > xIdCursor( xTxtImport->GetText()->createTextCursorByRange( xStart ) );
1726  if( xIdCursor.is() )
1727  {
1728  xIdCursor->gotoRange( xEnd, true );
1730  m_sXmlId, Reference<XInterface>( xIdCursor, UNO_QUERY ));
1731  }
1732  }
1733 
1734  // insert a paragraph break
1735  xTxtImport->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH );
1736 
1737  // create a cursor that select the whole last paragraph
1738  Reference < XTextCursor > xAttrCursor;
1739  try {
1740  xAttrCursor = xTxtImport->GetText()->createTextCursorByRange( xStart );
1741  if( !xAttrCursor.is() )
1742  return; // Robust (defective file)
1743  } catch (const uno::Exception &) {
1744  // createTextCursorByRange() likes to throw runtime exception, even
1745  // though it just means 'we were unable to create the cursor'
1746  return;
1747  }
1748  xAttrCursor->gotoRange( xEnd, true );
1749 
1750  // xml:id for RDF metadata
1751  if (!m_sXmlId.isEmpty() || m_bHaveAbout || !m_sProperty.isEmpty())
1752  {
1753  try {
1754  const uno::Reference<container::XEnumerationAccess> xEA
1755  (xAttrCursor, uno::UNO_QUERY_THROW);
1756  const uno::Reference<container::XEnumeration> xEnum(
1757  xEA->createEnumeration(), uno::UNO_SET_THROW);
1758  SAL_WARN_IF(!xEnum->hasMoreElements(), "xmloff.text", "xml:id: no paragraph?");
1759  if (xEnum->hasMoreElements()) {
1760  uno::Reference<rdf::XMetadatable> xMeta;
1761  xEnum->nextElement() >>= xMeta;
1762  SAL_WARN_IF(!xMeta.is(), "xmloff.text", "xml:id: not XMetadatable");
1763  GetImport().SetXmlId(xMeta, m_sXmlId);
1764  if (m_bHaveAbout)
1765  {
1766  GetImport().AddRDFa(xMeta,
1768  }
1769  SAL_WARN_IF(xEnum->hasMoreElements(), "xmloff.text", "xml:id: > 1 paragraph?");
1770  }
1771  } catch (const uno::Exception &) {
1772  SAL_INFO("xmloff.text", "XMLParaContext::~XMLParaContext: exception");
1773  }
1774  }
1775 
1776  OUString const sCellParaStyleName(xTxtImport->GetCellParaStyleDefault());
1777  if( !sCellParaStyleName.isEmpty() )
1778  {
1779  /* Suppress handling of outline and list attributes,
1780  because of side effects of method <SetStyleAndAttrs(..)> (#i80724#)
1781  */
1782  xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
1783  sCellParaStyleName,
1784  true,
1785  false, -1, // suppress outline handling
1786  false ); // suppress list attributes handling
1787  }
1788 
1789  // #103445# for headings without style name, find the proper style
1790  if( bHeading && sStyleName.isEmpty() )
1791  xTxtImport->FindOutlineStyleName( sStyleName, nOutlineLevel );
1792 
1793  // set style and hard attributes at the previous paragraph
1794  // Add parameter <mbOutlineLevelAttrFound> (#i73509#)
1795  sStyleName = xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
1796  sStyleName,
1797  true,
1799  bHeading ? nOutlineLevel : -1,
1800  true,
1802 
1803  // handle list style header
1804  if (bHeading && (bIsListHeader || bIsRestart))
1805  {
1806  Reference<XPropertySet> xPropSet( xAttrCursor, UNO_QUERY );
1807 
1808  if (xPropSet.is())
1809  {
1810  if (bIsListHeader)
1811  {
1812  OUString sNumberingIsNumber
1813  ("NumberingIsNumber");
1814  if(xPropSet->getPropertySetInfo()->
1815  hasPropertyByName(sNumberingIsNumber))
1816  {
1817  xPropSet->setPropertyValue
1818  (sNumberingIsNumber, makeAny( false ) );
1819  }
1820  }
1821  if (bIsRestart)
1822  {
1823  OUString sParaIsNumberingRestart
1824  ("ParaIsNumberingRestart");
1825  OUString sNumberingStartValue
1826  ("NumberingStartValue");
1827  if (xPropSet->getPropertySetInfo()->
1828  hasPropertyByName(sParaIsNumberingRestart))
1829  {
1830  xPropSet->setPropertyValue
1831  (sParaIsNumberingRestart, makeAny(true));
1832  }
1833 
1834  if (xPropSet->getPropertySetInfo()->
1835  hasPropertyByName(sNumberingStartValue))
1836  {
1837  xPropSet->setPropertyValue
1838  (sNumberingStartValue, makeAny(nStartValue));
1839  }
1840  }
1841 
1842  }
1843  }
1844 
1845  if (m_xHints)
1846  {
1847  for (const auto & i : m_xHints->GetHints())
1848  {
1849  XMLHint_Impl *const pHint = i.get();
1850  xAttrCursor->gotoRange( pHint->GetStart(), false );
1851  xAttrCursor->gotoRange( pHint->GetEnd(), true );
1852  switch( pHint->GetType() )
1853  {
1854  case XML_HINT_STYLE:
1855  {
1856  const OUString& rStyleName =
1857  static_cast<XMLStyleHint_Impl *>(pHint)->GetStyleName();
1858  if( !rStyleName.isEmpty() )
1859  xTxtImport->SetStyleAndAttrs( GetImport(),
1860  xAttrCursor, rStyleName,
1861  false );
1862  }
1863  break;
1864  case XML_HINT_REFERENCE:
1865  {
1866  const OUString& rRefName =
1867  static_cast<XMLReferenceHint_Impl *>(pHint)->GetRefName();
1868  if( !rRefName.isEmpty() )
1869  {
1870  if( !pHint->GetEnd().is() )
1871  pHint->SetEnd(xEnd);
1872 
1873  // reference name uses rStyleName member
1874  // borrow from XMLTextMarkImportContext
1876  GetImport(),
1877  "com.sun.star.text.ReferenceMark",
1878  rRefName,
1879  xAttrCursor);
1880  }
1881  }
1882  break;
1883  case XML_HINT_HYPERLINK:
1884  {
1885  const XMLHyperlinkHint_Impl *pHHint =
1886  static_cast<const XMLHyperlinkHint_Impl *>(pHint);
1887  xTxtImport->SetHyperlink( GetImport(),
1888  xAttrCursor,
1889  pHHint->GetHRef(),
1890  pHHint->GetName(),
1891  pHHint->GetTargetFrameName(),
1892  pHHint->GetStyleName(),
1893  pHHint->GetVisitedStyleName(),
1894  pHHint->GetEventsContext() );
1895  }
1896  break;
1897  case XML_HINT_INDEX_MARK:
1898  {
1900  static_cast<const XMLIndexMarkHint_Impl *>(pHint)->GetMark());
1901  Reference<XTextContent> xContent(xMark, UNO_QUERY);
1902  try
1903  {
1904  xTxtImport->GetText()->insertTextContent(
1905  xAttrCursor, xContent, true );
1906  }
1907  catch (uno::RuntimeException const&)
1908  {
1909  TOOLS_INFO_EXCEPTION("xmloff.text", "could not insert index mark, presumably in editengine text");
1910  }
1911  }
1912  break;
1913  case XML_HINT_TEXT_FRAME:
1914  {
1915  const XMLTextFrameHint_Impl *pFHint =
1916  static_cast<const XMLTextFrameHint_Impl *>(pHint);
1917  // Check for text content (#i33242#)
1918  Reference < XTextContent > xTextContent =
1919  pFHint->GetTextContent();
1920  if ( xTextContent.is() )
1921  {
1922  /* Core impl. of the unification of drawing objects and
1923  Writer fly frames (#i26791#)
1924  */
1925  if ( pFHint->IsBoundAtChar() )
1926  {
1927  xTextContent->attach( xAttrCursor );
1928  }
1929  }
1930  /* Consider, that hint can also contain a shape -
1931  e.g. drawing object of type 'Text'. (#i33242#)
1932  */
1933  else
1934  {
1935  Reference < XShape > xShape = pFHint->GetShape();
1936  if ( xShape.is() )
1937  {
1938  // determine anchor type
1939  Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
1940  TextContentAnchorType eAnchorType =
1941  TextContentAnchorType_AT_PARAGRAPH;
1942  {
1943  Any aAny = xPropSet->getPropertyValue( "AnchorType" );
1944  aAny >>= eAnchorType;
1945  }
1946  if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
1947  {
1948  // set anchor position for at-character anchored objects
1949  xPropSet->setPropertyValue("TextRange", Any(xAttrCursor));
1950  }
1951  }
1952  }
1953  }
1954  break;
1955  /* Core impl. of the unification of drawing objects and
1956  Writer fly frames (#i26791#)
1957  */
1958  case XML_HINT_DRAW:
1959  {
1960  const XMLDrawHint_Impl *pDHint =
1961  static_cast<const XMLDrawHint_Impl*>(pHint);
1962  // Improvement: hint directly provides the shape. (#i33242#)
1963  const Reference < XShape >& xShape = pDHint->GetShape();
1964  if ( xShape.is() )
1965  {
1966  // determine anchor type
1967  Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
1968  TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
1969  {
1970  Any aAny = xPropSet->getPropertyValue( "AnchorType" );
1971  aAny >>= eAnchorType;
1972  }
1973  if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
1974  {
1975  // set anchor position for at-character anchored objects
1976  xPropSet->setPropertyValue("TextRange", Any(xAttrCursor));
1977  }
1978  }
1979  }
1980  break;
1981  default:
1982  SAL_WARN( "xmloff.text", "What's this" );
1983  break;
1984  }
1985  }
1986  }
1987  m_xHints.reset();
1988 }
1989 
1990 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLParaContext::createFastChildContext(
1991  sal_Int32 nElement,
1992  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1993 {
1994  if (!m_xHints)
1995  m_xHints.reset(new XMLHints_Impl);
1996  return XMLImpSpanContext_Impl::CreateSpanContext(
1997  GetImport(), nElement, xAttrList,
1999  nStarFontsConvFlags);
2000 }
2001 
2002 void XMLParaContext::characters( const OUString& rChars )
2003 {
2004  OUString sChars =
2005  GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
2006  nStarFontsConvFlags,
2007  true, GetImport() );
2008  GetImport().GetTextImport()->InsertString( sChars, bIgnoreLeadingSpace );
2009 }
2010 
2011 
2013  SvXMLImport& i_rImport,
2014  sal_Int32 /*nElement*/,
2015  const Reference< xml::sax::XFastAttributeList > & xAttrList ) :
2016  SvXMLImportContext( i_rImport ),
2017  m_Level(0),
2018  m_StartValue(-1)
2019 {
2020  OUString StyleName;
2021 
2022  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
2023  {
2024  switch( aIter.getToken() )
2025  {
2026  case XML_ELEMENT(XML, XML_ID):
2027 //FIXME: there is no UNO API for lists
2028  break;
2029  case XML_ELEMENT(TEXT, XML_LIST_ID):
2030  m_ListId = aIter.toString();
2031  break;
2032  case XML_ELEMENT(TEXT, XML_LEVEL):
2033  {
2034  sal_Int32 nTmp = aIter.toInt32();
2035  if ( nTmp >= 1 && nTmp <= SHRT_MAX ) {
2036  m_Level = static_cast<sal_uInt16>(nTmp) - 1;
2037  }
2038  }
2039  break;
2041  StyleName = aIter.toString();
2042  break;
2044  // this attribute is deprecated
2045 // ContinueNumbering = IsXMLToken(sValue, XML_TRUE);
2046  break;
2048  {
2049  sal_Int32 nTmp = aIter.toInt32();
2050  if ( nTmp >= 0 && nTmp <= SHRT_MAX ) {
2051  m_StartValue = static_cast<sal_Int16>(nTmp);
2052  }
2053  }
2054  break;
2055  default:
2056  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
2057  }
2058  }
2059 
2060  XMLTextListsHelper& rTextListsHelper(
2061  i_rImport.GetTextImport()->GetTextListHelper() );
2062  if (m_ListId.isEmpty())
2063  {
2064  SAL_WARN_IF(0 <= i_rImport.GetODFVersion().compareTo(u"1.2"), "xmloff.text", "invalid numbered-paragraph: no list-id (1.2)");
2065  m_ListId = rTextListsHelper.GetNumberedParagraphListId(m_Level,
2066  StyleName);
2067  SAL_WARN_IF(m_ListId.isEmpty(), "xmloff.text", "numbered-paragraph: no ListId");
2068  if (m_ListId.isEmpty()) {
2069  return;
2070  }
2071  }
2072  m_xNumRules = rTextListsHelper.EnsureNumberedParagraph( i_rImport,
2073  m_ListId, m_Level, StyleName);
2074 
2075  SAL_WARN_IF(!m_xNumRules.is(), "xmloff.text", "numbered-paragraph: no NumRules");
2076 
2077  i_rImport.GetTextImport()->GetTextListHelper().PushListContext( this );
2078 }
2079 
2081 {
2082  if (!m_ListId.isEmpty()) {
2083  GetImport().GetTextImport()->PopListContext();
2084  }
2085 }
2086 
2087 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLNumberedParaContext::createFastChildContext(
2088  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
2089 {
2090  switch (nElement)
2091  {
2092  case XML_ELEMENT(TEXT, XML_H):
2093  case XML_ELEMENT(LO_EXT, XML_H):
2094  case XML_ELEMENT(TEXT, XML_P):
2095  case XML_ELEMENT(LO_EXT, XML_P):
2096  return new XMLParaContext( GetImport(), nElement, xAttrList );
2097  default:
2098  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
2099  }
2100 
2101  return nullptr;
2102 }
2103 
2104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
Definition: txtparai.cxx:2080
OUString m_XmlId
css::uno::Reference< css::container::XIndexReplace > m_xNumRules
text:style-name
Definition: txtparai.hxx:83
css::uno::Reference< css::drawing::XShape > const & GetShape() const
bool IsReference() const
void push_back(std::unique_ptr< XMLIndexMarkHint_Impl > pHint)
Definition: txtparai.cxx:86
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
Definition: txtparai.cxx:1710
virtual void InsertString(const OUString &_sString)
Definition: txtparai.cxx:179
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
Definition: txtparai.cxx:154
signed char sal_Int8
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: txtparai.cxx:1990
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:45
std::vector< std::unique_ptr< XMLHint_Impl > > m_Hints
Definition: txtparai.cxx:76
bool mbOutlineContentVisible
Definition: txtparai.hxx:50
uno::Reference< uno::XInterface > m_xCrossRefHeadingBookmark
Definition: txtparai.cxx:78
sal_Int16 m_StartValue
text:start-value
Definition: txtparai.hxx:79
const css::uno::Reference< css::text::XTextRange > & GetEnd() const
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
#define CONV_FROM_STAR_MATH
Definition: txtparai.hxx:33
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3501
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString m_sAbout
Definition: txtparai.hxx:41
sal_Int8 nOutlineLevel
Definition: txtparai.hxx:46
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:600
XMLParaContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
#define CONV_FROM_STAR_BATS
Definition: txtparai.hxx:32
virtual void InsertControlCharacter(sal_Int16 _nControl)
Definition: txtparai.cxx:175
bool bIgnoreLeadingSpace
Definition: txtparai.hxx:51
const css::uno::Reference< css::text::XTextRange > & GetStart() const
sal_uInt16 sal_Unicode
static css::uno::Reference< css::text::XTextContent > CreateAndInsertMark(SvXMLImport &rImport, const OUString &sServiceName, const OUString &sMarkName, const css::uno::Reference< css::text::XTextRange > &rRange, const OUString &i_rXmlId=OUString())
#define SAL_MAX_UINT16
OUString m_sProperty
Definition: txtparai.hxx:42
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
void SetEnd(const css::uno::Reference< css::text::XTextRange > &rPos)
OUString m_sContent
Definition: txtparai.hxx:43
::comphelper::UnoInterfaceToUniqueIdentifierMapper & getInterfaceToIdentifierMapper()
Definition: xmlimp.cxx:1781
css::text::TextContentAnchorType GetAnchorType() const
const char * sName
START
import hyperlinks as URL fields (Calc, Impress, Draw) ()
Definition: txtfldi.hxx:910
void AddRDFa(const css::uno::Reference< css::rdf::XMetadatable > &i_xObject, OUString const &i_rAbout, OUString const &i_rProperty, OUString const &i_rContent, OUString const &i_rDatatype)
Add a RDFa statement; parameters are XML attribute values.
Definition: xmlimp.cxx:1903
const OUString & GetStyleName() const
sal_uInt8 GetType() const
END
#define XML_HINT_HYPERLINK
int i
std::unique_ptr< XMLHints_Impl > m_xHints
Definition: txtparai.hxx:47
bool mbOutlineLevelAttrFound
Definition: txtparai.hxx:49
#define XML_HINT_INDEX_MARK
XMLCharContext(const XMLCharContext &)=delete
virtual void SAL_CALL characters(const OUString &rChars) override
This method is called for all characters that are contained in the current element.
Definition: txtparai.cxx:2002
static XMLTextFieldImportContext * CreateTextFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp, sal_Int32 nElement)
create the appropriate field context from (for use in paragraph import)
Definition: txtfldi.cxx:219
float u
XMLIndexMarkHint_Impl * GetIndexHintById(const OUString &sID)
Definition: txtparai.cxx:97
virtual ~XMLCharContext() override
Definition: txtparai.cxx:151
const OUString & GetTargetFrameName() const
void push_back(std::unique_ptr< XMLHint_Impl > pHint)
Definition: txtparai.cxx:81
uno::Reference< uno::XInterface > & GetCrossRefHeadingBookmark()
Definition: txtparai.cxx:103
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: txtparai.cxx:2087
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
std::unordered_map< OUString, XMLIndexMarkHint_Impl * > m_IndexHintsById
Definition: txtparai.cxx:77
Used for hyperlinks attached to objects (drawing objects, text boxes, Writer frames) ...
bool IsBoundAtChar() const
bool bIsListHeader
Definition: txtparai.hxx:53
sal_Int16 m_Level
text:list-level MINUS 1
Definition: txtparai.hxx:77
static bool convertBool(bool &rBool, std::u16string_view rString)
void SetXmlId(css::uno::Reference< css::uno::XInterface > const &i_xIfc, OUString const &i_rXmlId)
set the XmlId attribute of given UNO object (for RDF metadata)
Definition: xmlimp.cxx:1868
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
OUString m_sDatatype
Definition: txtparai.hxx:44
#define TOOLS_INFO_EXCEPTION(area, stream)
sal_Int16 m_nCount
XMLEventsImportContext * GetEventsContext() const
OUString m_ListId
text:list-id
Definition: txtparai.hxx:81
OUString GetODFVersion() const
Definition: xmlimp.cxx:1857
#define SAL_WARN_IF(condition, area, stream)
unsigned char sal_uInt8
css::uno::Reference< css::drawing::XShape > GetShape() const
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
Definition: xmlictxt.cxx:40
import bookmarks and reference marks ( , , , , , )
Handling of tokens in XML:
#define SAL_INFO(area, stream)
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:59
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
sal_Int16 nStartValue
Definition: txtparai.hxx:55
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
const OUString & GetHRef() const
sal_Int16 m_nControl
sal_Int32 getToken(const Context &rContext, const char *pToken)
const OUString & GetName() const
sal_uInt16 m_nCount
import footnote elements ()
bool m_bHaveAbout
Definition: txtparai.hxx:45
#define SAL_WARN(area, stream)
Reference< XSingleServiceFactory > xFactory
OUString m_sXmlId
Definition: txtparai.hxx:40
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:119
std::vector< std::unique_ptr< XMLHint_Impl > > const & GetHints() const
Definition: txtparai.cxx:92
static SvXMLShapeContext * CreateGroupChildContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes, bool bTemporaryShape=false)
const OUString & registerReference(const css::uno::Reference< css::uno::XInterface > &rInterface)
returns a unique identifier for the given uno object.
uno::Reference< ucb::XContent > xContent
const OUString & GetVisitedStyleName() const
import change tracking/redlining markers , , ...
virtual void SAL_CALL characters(const OUString &aChars) override
This method is called for all characters that are contained in the current element.
Definition: xmlictxt.cxx:70
#define XML_HINT_STYLE
TEXT
css::uno::Reference< css::text::XTextRange > xStart
Definition: txtparai.hxx:38
XMLNumberedParaContext(SvXMLImport &i_rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &i_xAttrList)
Definition: txtparai.cxx:2012
css::uno::Reference< css::text::XTextContent > GetTextContent() const
#define XML_HINT_TEXT_FRAME
OUString toString(OptionInfo const *info)
#define XML_HINT_DRAW
#define XML_HINT_REFERENCE
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
sal_Unicode m_c
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)