1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <boost/ptr_container/ptr_vector.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.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"
55 #include <txtparaimphint.hxx>
56 class XMLHints_Impl
: public boost::ptr_vector
<XMLHint_Impl
> {};
58 using namespace ::com::sun::star
;
59 using namespace ::com::sun::star::uno
;
60 using namespace ::com::sun::star::text
;
61 using namespace ::com::sun::star::drawing
;
62 using namespace ::com::sun::star::beans
;
63 using namespace ::xmloff::token
;
64 using ::com::sun::star::container::XEnumerationAccess
;
65 using ::com::sun::star::container::XEnumeration
;
67 TYPEINIT1( XMLCharContext
, SvXMLImportContext
);
69 XMLCharContext::XMLCharContext(
72 const OUString
& rLName
,
73 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
76 SvXMLImportContext( rImport
, nPrfx
, rLName
)
83 const SvXMLNamespaceMap
& rMap
= GetImport().GetNamespaceMap();
84 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
85 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
87 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
90 sal_uInt16 nPrefix
=rMap
.GetKeyByAttrName( rAttrName
,&aLocalName
);
91 if( XML_NAMESPACE_TEXT
== nPrefix
&&
92 IsXMLToken( aLocalName
, XML_C
) )
94 sal_Int32 nTmp
= xAttrList
->getValueByIndex(i
).toInt32();
97 if( nTmp
> USHRT_MAX
)
100 m_nCount
= (sal_uInt16
)nTmp
;
107 XMLCharContext::XMLCharContext(
110 const OUString
& rLName
,
111 const Reference
< xml::sax::XAttributeList
> &,
112 sal_Int16 nControl
) :
113 SvXMLImportContext( rImp
, nPrfx
, rLName
)
114 ,m_nControl(nControl
)
120 XMLCharContext::~XMLCharContext()
123 void XMLCharContext::EndElement()
126 InsertControlCharacter( m_nControl
);
131 OUString
sBuff( &m_c
, 1 );
136 OUStringBuffer
sBuff(static_cast<int>(m_nCount
));
138 sBuff
.append( &m_c
, 1 );
140 InsertString(sBuff
.makeStringAndClear() );
144 void XMLCharContext::InsertControlCharacter(sal_Int16 _nControl
)
146 GetImport().GetTextImport()->InsertControlCharacter( _nControl
);
148 void XMLCharContext::InsertString(const OUString
& _sString
)
150 GetImport().GetTextImport()->InsertString( _sString
);
153 /** import start of reference (<text:reference-start>) */
154 class XMLStartReferenceContext_Impl
: public SvXMLImportContext
159 // Do everything in constructor. Well ...
160 XMLStartReferenceContext_Impl (
161 SvXMLImport
& rImport
,
163 const OUString
& rLocalName
,
164 XMLHints_Impl
& rHnts
,
165 const Reference
<xml::sax::XAttributeList
> & xAttrList
);
167 static bool FindName(
168 SvXMLImport
& rImport
,
169 const Reference
<xml::sax::XAttributeList
> & xAttrList
,
173 TYPEINIT1( XMLStartReferenceContext_Impl
, SvXMLImportContext
);
175 XMLStartReferenceContext_Impl::XMLStartReferenceContext_Impl(
176 SvXMLImport
& rImport
,
178 const OUString
& rLocalName
,
179 XMLHints_Impl
& rHints
,
180 const Reference
<xml::sax::XAttributeList
> & xAttrList
) :
181 SvXMLImportContext(rImport
, nPrefix
, rLocalName
)
185 if (FindName(GetImport(), xAttrList
, sName
))
187 XMLHint_Impl
* pHint
= new XMLReferenceHint_Impl(
188 sName
, rImport
.GetTextImport()->GetCursor()->getStart() );
190 // degenerates to point reference, if no end is found!
191 pHint
->SetEnd(rImport
.GetTextImport()->GetCursor()->getStart() );
193 rHints
.push_back(pHint
);
197 bool XMLStartReferenceContext_Impl::FindName(
198 SvXMLImport
& rImport
,
199 const Reference
<xml::sax::XAttributeList
> & xAttrList
,
202 bool bNameOK( false );
204 // find name attribute first
205 const sal_Int16
nLength( xAttrList
->getLength() );
206 for (sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
209 const sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().
210 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
213 if ( (XML_NAMESPACE_TEXT
== nPrefix
) &&
214 IsXMLToken(sLocalName
, XML_NAME
) )
216 rName
= xAttrList
->getValueByIndex(nAttr
);
224 /** import end of reference (<text:reference-end>) */
225 class XMLEndReferenceContext_Impl
: public SvXMLImportContext
230 // Do everything in constructor. Well ...
231 XMLEndReferenceContext_Impl(
232 SvXMLImport
& rImport
,
234 const OUString
& rLocalName
,
235 XMLHints_Impl
& rHnts
,
236 const Reference
<xml::sax::XAttributeList
> & xAttrList
);
239 TYPEINIT1( XMLEndReferenceContext_Impl
, SvXMLImportContext
);
241 XMLEndReferenceContext_Impl::XMLEndReferenceContext_Impl(
242 SvXMLImport
& rImport
,
244 const OUString
& rLocalName
,
245 XMLHints_Impl
& rHints
,
246 const Reference
<xml::sax::XAttributeList
> & xAttrList
) :
247 SvXMLImportContext(rImport
, nPrefix
, rLocalName
)
251 // borrow from XMLStartReferenceContext_Impl
252 if (XMLStartReferenceContext_Impl::FindName(GetImport(), xAttrList
, sName
))
254 // search for reference start
255 sal_uInt16 nCount
= rHints
.size();
256 for(sal_uInt16 nPos
= 0; nPos
< nCount
; nPos
++)
258 XMLHint_Impl
*pHint
= &rHints
[nPos
];
259 if ( pHint
->IsReference() &&
260 sName
.equals( static_cast<XMLReferenceHint_Impl
*>(pHint
)->GetRefName()) )
262 // set end and stop searching
263 pHint
->SetEnd(GetImport().GetTextImport()->
264 GetCursor()->getStart() );
268 // else: no start (in this paragraph) -> ignore
272 class XMLImpSpanContext_Impl
: public SvXMLImportContext
274 XMLHints_Impl
& rHints
;
275 XMLStyleHint_Impl
*pHint
;
277 bool& rIgnoreLeadingSpace
;
279 sal_uInt8 nStarFontsConvFlags
;
285 XMLImpSpanContext_Impl(
286 SvXMLImport
& rImport
,
288 const OUString
& rLName
,
289 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
290 XMLHints_Impl
& rHnts
,
292 sal_uInt8 nSFConvFlags
295 virtual ~XMLImpSpanContext_Impl();
297 static SvXMLImportContext
*CreateChildContext(
298 SvXMLImport
& rImport
,
299 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
300 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
301 sal_uInt16 nToken
, XMLHints_Impl
& rHnts
,
303 sal_uInt8 nStarFontsConvFlags
= 0
305 virtual SvXMLImportContext
*CreateChildContext(
306 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
307 const Reference
< xml::sax::XAttributeList
> & xAttrList
) SAL_OVERRIDE
;
309 virtual void Characters( const OUString
& rChars
) SAL_OVERRIDE
;
312 class XMLImpHyperlinkContext_Impl
: public SvXMLImportContext
314 XMLHints_Impl
& mrHints
;
315 XMLHyperlinkHint_Impl
*mpHint
;
317 bool& mrbIgnoreLeadingSpace
;
323 XMLImpHyperlinkContext_Impl(
324 SvXMLImport
& rImport
,
326 const OUString
& rLName
,
327 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
328 XMLHints_Impl
& rHnts
,
329 bool& rIgnLeadSpace
);
331 virtual ~XMLImpHyperlinkContext_Impl();
333 virtual SvXMLImportContext
*CreateChildContext(
334 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
335 const Reference
< xml::sax::XAttributeList
> & xAttrList
) SAL_OVERRIDE
;
337 virtual void Characters( const OUString
& rChars
) SAL_OVERRIDE
;
340 TYPEINIT1( XMLImpHyperlinkContext_Impl
, SvXMLImportContext
);
342 XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
343 SvXMLImport
& rImport
,
345 const OUString
& rLName
,
346 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
347 XMLHints_Impl
& rHnts
,
348 bool& rIgnLeadSpace
)
349 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
351 , mpHint( new XMLHyperlinkHint_Impl( GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) )
352 , mrbIgnoreLeadingSpace( rIgnLeadSpace
)
355 const SvXMLTokenMap
& rTokenMap
= GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
357 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
358 for ( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
360 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
361 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
364 const sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
365 switch (rTokenMap
.Get( nPrefix
, aLocalName
))
367 case XML_TOK_TEXT_HYPERLINK_HREF
:
368 mpHint
->SetHRef( GetImport().GetAbsoluteReference( rValue
) );
370 case XML_TOK_TEXT_HYPERLINK_NAME
:
371 mpHint
->SetName( rValue
);
373 case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME
:
374 mpHint
->SetTargetFrameName( rValue
);
376 case XML_TOK_TEXT_HYPERLINK_SHOW
:
379 case XML_TOK_TEXT_HYPERLINK_STYLE_NAME
:
380 mpHint
->SetStyleName( rValue
);
382 case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME
:
383 mpHint
->SetVisitedStyleName( rValue
);
388 if( !sShow
.isEmpty() && mpHint
->GetTargetFrameName().isEmpty() )
390 if( IsXMLToken( sShow
, XML_NEW
) )
391 mpHint
->SetTargetFrameName(
392 OUString( "_blank" ) );
393 else if( IsXMLToken( sShow
, XML_REPLACE
) )
394 mpHint
->SetTargetFrameName(
395 OUString( "_self" ) );
398 if ( mpHint
->GetHRef().isEmpty() )
400 // hyperlink without an URL is not imported.
406 mrHints
.push_back( mpHint
);
410 XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
413 mpHint
->SetEnd( GetImport().GetTextImport()
414 ->GetCursorAsRange()->getStart() );
417 SvXMLImportContext
*XMLImpHyperlinkContext_Impl::CreateChildContext(
418 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
419 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
421 if ( (nPrefix
== XML_NAMESPACE_OFFICE
) &&
422 IsXMLToken(rLocalName
, XML_EVENT_LISTENERS
) )
424 XMLEventsImportContext
* pCtxt
= new XMLEventsImportContext(
425 GetImport(), nPrefix
, rLocalName
);
426 mpHint
->SetEventsContext(pCtxt
);
431 const SvXMLTokenMap
& rTokenMap
=
432 GetImport().GetTextImport()->GetTextPElemTokenMap();
433 sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
435 return XMLImpSpanContext_Impl::CreateChildContext(
436 GetImport(), nPrefix
, rLocalName
, xAttrList
,
437 nToken
, mrHints
, mrbIgnoreLeadingSpace
);
441 void XMLImpHyperlinkContext_Impl::Characters( const OUString
& rChars
)
443 GetImport().GetTextImport()->InsertString( rChars
, mrbIgnoreLeadingSpace
);
446 class XMLImpRubyBaseContext_Impl
: public SvXMLImportContext
448 XMLHints_Impl
& rHints
;
450 bool& rIgnoreLeadingSpace
;
456 XMLImpRubyBaseContext_Impl(
457 SvXMLImport
& rImport
,
459 const OUString
& rLName
,
460 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
461 XMLHints_Impl
& rHnts
,
462 bool& rIgnLeadSpace
);
464 virtual ~XMLImpRubyBaseContext_Impl();
466 virtual SvXMLImportContext
*CreateChildContext(
467 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
468 const Reference
< xml::sax::XAttributeList
> & xAttrList
) SAL_OVERRIDE
;
470 virtual void Characters( const OUString
& rChars
) SAL_OVERRIDE
;
473 TYPEINIT1( XMLImpRubyBaseContext_Impl
, SvXMLImportContext
);
475 XMLImpRubyBaseContext_Impl::XMLImpRubyBaseContext_Impl(
476 SvXMLImport
& rImport
,
478 const OUString
& rLName
,
479 const Reference
< xml::sax::XAttributeList
> &,
480 XMLHints_Impl
& rHnts
,
481 bool& rIgnLeadSpace
) :
482 SvXMLImportContext( rImport
, nPrfx
, rLName
),
484 rIgnoreLeadingSpace( rIgnLeadSpace
)
488 XMLImpRubyBaseContext_Impl::~XMLImpRubyBaseContext_Impl()
492 SvXMLImportContext
*XMLImpRubyBaseContext_Impl::CreateChildContext(
493 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
494 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
496 const SvXMLTokenMap
& rTokenMap
=
497 GetImport().GetTextImport()->GetTextPElemTokenMap();
498 sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
500 return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), nPrefix
,
501 rLocalName
, xAttrList
,
502 nToken
, rHints
, rIgnoreLeadingSpace
);
505 void XMLImpRubyBaseContext_Impl::Characters( const OUString
& rChars
)
507 GetImport().GetTextImport()->InsertString( rChars
, rIgnoreLeadingSpace
);
510 class XMLImpRubyContext_Impl
: public SvXMLImportContext
512 XMLHints_Impl
& rHints
;
514 bool& rIgnoreLeadingSpace
;
516 Reference
< XTextRange
> m_xStart
;
517 OUString m_sStyleName
;
518 OUString m_sTextStyleName
;
525 XMLImpRubyContext_Impl(
526 SvXMLImport
& rImport
,
528 const OUString
& rLName
,
529 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
530 XMLHints_Impl
& rHnts
,
531 bool& rIgnLeadSpace
);
533 virtual ~XMLImpRubyContext_Impl();
535 virtual SvXMLImportContext
*CreateChildContext(
536 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
537 const Reference
< xml::sax::XAttributeList
> & xAttrList
) SAL_OVERRIDE
;
539 void SetTextStyleName( const OUString
& s
) { m_sTextStyleName
= s
; }
540 void AppendText( const OUString
& s
) { m_sText
+= s
; }
543 class XMLImpRubyTextContext_Impl
: public SvXMLImportContext
545 XMLImpRubyContext_Impl
& m_rRubyContext
;
551 XMLImpRubyTextContext_Impl(
552 SvXMLImport
& rImport
,
554 const OUString
& rLName
,
555 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
556 XMLImpRubyContext_Impl
& rParent
);
558 virtual ~XMLImpRubyTextContext_Impl();
560 virtual void Characters( const OUString
& rChars
) SAL_OVERRIDE
;
563 TYPEINIT1( XMLImpRubyTextContext_Impl
, SvXMLImportContext
);
565 XMLImpRubyTextContext_Impl::XMLImpRubyTextContext_Impl(
566 SvXMLImport
& rImport
,
568 const OUString
& rLName
,
569 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
570 XMLImpRubyContext_Impl
& rParent
)
571 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
572 , m_rRubyContext( rParent
)
574 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
575 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
577 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
578 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
582 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
584 if( XML_NAMESPACE_TEXT
== nPrefix
&&
585 IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
587 m_rRubyContext
.SetTextStyleName( rValue
);
593 XMLImpRubyTextContext_Impl::~XMLImpRubyTextContext_Impl()
597 void XMLImpRubyTextContext_Impl::Characters( const OUString
& rChars
)
599 m_rRubyContext
.AppendText( rChars
);
602 TYPEINIT1( XMLImpRubyContext_Impl
, SvXMLImportContext
);
604 XMLImpRubyContext_Impl::XMLImpRubyContext_Impl(
605 SvXMLImport
& rImport
,
607 const OUString
& rLName
,
608 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
609 XMLHints_Impl
& rHnts
,
610 bool& rIgnLeadSpace
) :
611 SvXMLImportContext( rImport
, nPrfx
, rLName
),
613 rIgnoreLeadingSpace( rIgnLeadSpace
)
614 , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
616 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
617 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
619 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
620 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
624 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
626 if( XML_NAMESPACE_TEXT
== nPrefix
&&
627 IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
629 m_sStyleName
= rValue
;
635 XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl()
637 const rtl::Reference
< XMLTextImportHelper
> xTextImport(
638 GetImport().GetTextImport());
639 const Reference
< XTextCursor
> xAttrCursor(
640 xTextImport
->GetText()->createTextCursorByRange( m_xStart
));
641 xAttrCursor
->gotoRange(xTextImport
->GetCursorAsRange()->getStart(),
643 xTextImport
->SetRuby( GetImport(), xAttrCursor
,
644 m_sStyleName
, m_sTextStyleName
, m_sText
);
647 SvXMLImportContext
*XMLImpRubyContext_Impl::CreateChildContext(
648 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
649 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
651 SvXMLImportContext
*pContext
;
652 if( XML_NAMESPACE_TEXT
== nPrefix
)
654 if( IsXMLToken( rLocalName
, XML_RUBY_BASE
) )
655 pContext
= new XMLImpRubyBaseContext_Impl( GetImport(), nPrefix
,
659 rIgnoreLeadingSpace
);
660 else if( IsXMLToken( rLocalName
, XML_RUBY_TEXT
) )
661 pContext
= new XMLImpRubyTextContext_Impl( GetImport(), nPrefix
,
666 pContext
= new SvXMLImportContext(
667 GetImport(), nPrefix
, rLocalName
);
670 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
,
676 /** for text:meta and text:meta-field
678 class XMLMetaImportContextBase
: public SvXMLImportContext
680 XMLHints_Impl
& m_rHints
;
682 bool& m_rIgnoreLeadingSpace
;
685 Reference
<XTextRange
> m_xStart
;
693 XMLMetaImportContextBase(
694 SvXMLImport
& i_rImport
,
695 const sal_uInt16 i_nPrefix
,
696 const OUString
& i_rLocalName
,
697 XMLHints_Impl
& i_rHints
,
698 bool & i_rIgnoreLeadingSpace
);
700 virtual ~XMLMetaImportContextBase();
702 virtual void StartElement(
703 const Reference
<xml::sax::XAttributeList
> & i_xAttrList
) SAL_OVERRIDE
;
705 virtual void EndElement() SAL_OVERRIDE
;
707 virtual SvXMLImportContext
*CreateChildContext(
708 sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
,
709 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
) SAL_OVERRIDE
;
711 virtual void Characters( const OUString
& i_rChars
) SAL_OVERRIDE
;
713 virtual void ProcessAttribute(sal_uInt16
const i_nPrefix
,
714 OUString
const & i_rLocalName
, OUString
const & i_rValue
);
716 virtual void InsertMeta(const Reference
<XTextRange
> & i_xInsertionRange
)
720 TYPEINIT1( XMLMetaImportContextBase
, SvXMLImportContext
);
722 XMLMetaImportContextBase::XMLMetaImportContextBase(
723 SvXMLImport
& i_rImport
,
724 const sal_uInt16 i_nPrefix
,
725 const OUString
& i_rLocalName
,
726 XMLHints_Impl
& i_rHints
,
727 bool & i_rIgnoreLeadingSpace
)
728 : SvXMLImportContext( i_rImport
, i_nPrefix
, i_rLocalName
)
729 , m_rHints( i_rHints
)
730 , m_rIgnoreLeadingSpace( i_rIgnoreLeadingSpace
)
731 , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
735 XMLMetaImportContextBase::~XMLMetaImportContextBase()
739 void XMLMetaImportContextBase::StartElement(
740 const Reference
<xml::sax::XAttributeList
> & i_xAttrList
)
742 const sal_Int16
nAttrCount(i_xAttrList
.is() ? i_xAttrList
->getLength() : 0);
743 for ( sal_Int16 i
= 0; i
< nAttrCount
; ++i
)
745 const OUString
& rAttrName( i_xAttrList
->getNameByIndex( i
) );
746 const OUString
& rValue( i_xAttrList
->getValueByIndex( i
) );
749 const sal_uInt16
nPrefix(
750 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
752 ProcessAttribute(nPrefix
, sLocalName
, rValue
);
756 void XMLMetaImportContextBase::EndElement()
758 SAL_WARN_IF(!m_xStart
.is(), "xmloff.text", "no mxStart?");
759 if (!m_xStart
.is()) return;
761 const Reference
<XTextRange
> xEndRange(
762 GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
764 // create range for insertion
765 const Reference
<XTextCursor
> xInsertionCursor(
766 GetImport().GetTextImport()->GetText()->createTextCursorByRange(
768 xInsertionCursor
->gotoRange(m_xStart
, sal_True
);
770 InsertMeta(xInsertionCursor
);
773 SvXMLImportContext
* XMLMetaImportContextBase::CreateChildContext(
774 sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
,
775 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
)
777 const SvXMLTokenMap
& rTokenMap(
778 GetImport().GetTextImport()->GetTextPElemTokenMap() );
779 const sal_uInt16
nToken( rTokenMap
.Get( i_nPrefix
, i_rLocalName
) );
781 return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), i_nPrefix
,
782 i_rLocalName
, i_xAttrList
, nToken
, m_rHints
, m_rIgnoreLeadingSpace
);
785 void XMLMetaImportContextBase::Characters( const OUString
& i_rChars
)
787 GetImport().GetTextImport()->InsertString(i_rChars
, m_rIgnoreLeadingSpace
);
790 void XMLMetaImportContextBase::ProcessAttribute(sal_uInt16
const i_nPrefix
,
791 OUString
const & i_rLocalName
, OUString
const & i_rValue
)
793 if ( (XML_NAMESPACE_XML
== i_nPrefix
) && IsXMLToken(i_rLocalName
, XML_ID
) )
800 class XMLMetaImportContext
: public XMLMetaImportContextBase
805 OUString m_sProperty
;
807 OUString m_sDatatype
;
812 XMLMetaImportContext(
813 SvXMLImport
& i_rImport
,
814 const sal_uInt16 i_nPrefix
,
815 const OUString
& i_rLocalName
,
816 XMLHints_Impl
& i_rHints
,
817 bool & i_rIgnoreLeadingSpace
);
819 virtual void ProcessAttribute(sal_uInt16
const i_nPrefix
,
820 OUString
const & i_rLocalName
, OUString
const & i_rValue
) SAL_OVERRIDE
;
822 virtual void InsertMeta(const Reference
<XTextRange
> & i_xInsertionRange
) SAL_OVERRIDE
;
825 TYPEINIT1( XMLMetaImportContext
, XMLMetaImportContextBase
);
827 XMLMetaImportContext::XMLMetaImportContext(
828 SvXMLImport
& i_rImport
,
829 const sal_uInt16 i_nPrefix
,
830 const OUString
& i_rLocalName
,
831 XMLHints_Impl
& i_rHints
,
832 bool & i_rIgnoreLeadingSpace
)
833 : XMLMetaImportContextBase( i_rImport
, i_nPrefix
, i_rLocalName
,
834 i_rHints
, i_rIgnoreLeadingSpace
)
835 , m_bHaveAbout(false)
839 void XMLMetaImportContext::ProcessAttribute(sal_uInt16
const i_nPrefix
,
840 OUString
const & i_rLocalName
, OUString
const & i_rValue
)
842 if ( XML_NAMESPACE_XHTML
== i_nPrefix
)
845 if ( IsXMLToken( i_rLocalName
, XML_ABOUT
) )
850 else if ( IsXMLToken( i_rLocalName
, XML_PROPERTY
) )
852 m_sProperty
= i_rValue
;
854 else if ( IsXMLToken( i_rLocalName
, XML_CONTENT
) )
856 m_sContent
= i_rValue
;
858 else if ( IsXMLToken( i_rLocalName
, XML_DATATYPE
) )
860 m_sDatatype
= i_rValue
;
865 XMLMetaImportContextBase::ProcessAttribute(
866 i_nPrefix
, i_rLocalName
, i_rValue
);
870 void XMLMetaImportContext::InsertMeta(
871 const Reference
<XTextRange
> & i_xInsertionRange
)
873 SAL_WARN_IF(m_bHaveAbout
== m_sProperty
.isEmpty(), "xmloff.text", "XMLMetaImportContext::InsertMeta: invalid RDFa?");
874 if (!m_XmlId
.isEmpty() || (m_bHaveAbout
&& !m_sProperty
.isEmpty()))
877 const uno::Reference
<rdf::XMetadatable
> xMeta(
878 XMLTextMarkImportContext::CreateAndInsertMark(
880 OUString("com.sun.star.text.InContentMetadata"),
882 i_xInsertionRange
, m_XmlId
),
884 SAL_WARN_IF(!xMeta
.is(), "xmloff.text", "cannot insert Meta?");
886 if (xMeta
.is() && m_bHaveAbout
)
888 GetImport().AddRDFa(xMeta
,
889 m_sAbout
, m_sProperty
, m_sContent
, m_sDatatype
);
894 SAL_INFO("xmloff.text", "invalid <text:meta>: no xml:id, no valid RDFa");
898 /** text:meta-field */
899 class XMLMetaFieldImportContext
: public XMLMetaImportContextBase
901 OUString m_DataStyleName
;
906 XMLMetaFieldImportContext(
907 SvXMLImport
& i_rImport
,
908 const sal_uInt16 i_nPrefix
,
909 const OUString
& i_rLocalName
,
910 XMLHints_Impl
& i_rHints
,
911 bool & i_rIgnoreLeadingSpace
);
913 virtual void ProcessAttribute(sal_uInt16
const i_nPrefix
,
914 OUString
const & i_rLocalName
, OUString
const & i_rValue
) SAL_OVERRIDE
;
916 virtual void InsertMeta(const Reference
<XTextRange
> & i_xInsertionRange
) SAL_OVERRIDE
;
919 TYPEINIT1( XMLMetaFieldImportContext
, XMLMetaImportContextBase
);
921 XMLMetaFieldImportContext::XMLMetaFieldImportContext(
922 SvXMLImport
& i_rImport
,
923 const sal_uInt16 i_nPrefix
,
924 const OUString
& i_rLocalName
,
925 XMLHints_Impl
& i_rHints
,
926 bool & i_rIgnoreLeadingSpace
)
927 : XMLMetaImportContextBase( i_rImport
, i_nPrefix
, i_rLocalName
,
928 i_rHints
, i_rIgnoreLeadingSpace
)
932 void XMLMetaFieldImportContext::ProcessAttribute(sal_uInt16
const i_nPrefix
,
933 OUString
const & i_rLocalName
, OUString
const & i_rValue
)
935 if ( XML_NAMESPACE_STYLE
== i_nPrefix
&&
936 IsXMLToken( i_rLocalName
, XML_DATA_STYLE_NAME
) )
938 m_DataStyleName
= i_rValue
;
942 XMLMetaImportContextBase::ProcessAttribute(
943 i_nPrefix
, i_rLocalName
, i_rValue
);
947 void XMLMetaFieldImportContext::InsertMeta(
948 const Reference
<XTextRange
> & i_xInsertionRange
)
950 if (!m_XmlId
.isEmpty()) // valid?
953 const Reference
<XPropertySet
> xPropertySet(
954 XMLTextMarkImportContext::CreateAndInsertMark(
956 OUString("com.sun.star.text.textfield.MetadataField"),
958 i_xInsertionRange
, m_XmlId
),
960 SAL_WARN_IF(!xPropertySet
.is(), "xmloff.text", "cannot insert MetaField?");
961 if (!xPropertySet
.is()) return;
963 if (!m_DataStyleName
.isEmpty())
965 bool isDefaultLanguage(true);
967 const sal_Int32
nKey( GetImport().GetTextImport()->GetDataStyleKey(
968 m_DataStyleName
, & isDefaultLanguage
) );
972 static OUString
sPropertyIsFixedLanguage(
973 OUString("IsFixedLanguage") );
976 xPropertySet
->setPropertyValue(
977 OUString("NumberFormat"), any
);
978 if ( xPropertySet
->getPropertySetInfo()->
979 hasPropertyByName( sPropertyIsFixedLanguage
) )
981 any
<<= static_cast<bool>(!isDefaultLanguage
);
982 xPropertySet
->setPropertyValue( sPropertyIsFixedLanguage
,
990 SAL_INFO("xmloff.text", "invalid <text:meta-field>: no xml:id");
995 * Process index marks.
997 * All *-mark-end index marks should instantiate *this* class (because
998 * it doesn't process attributes other than ID), while the *-mark and
999 * *-mark-start classes should instantiate the apporpiate subclasses.
1001 class XMLIndexMarkImportContext_Impl
: public SvXMLImportContext
1003 const OUString sAlternativeText
;
1005 XMLHints_Impl
& rHints
;
1006 const enum XMLTextPElemTokens eToken
;
1010 TYPEINFO_OVERRIDE();
1012 XMLIndexMarkImportContext_Impl(
1013 SvXMLImport
& rImport
,
1015 const OUString
& rLocalName
,
1016 enum XMLTextPElemTokens nTok
,
1017 XMLHints_Impl
& rHnts
);
1019 void StartElement(const Reference
<xml::sax::XAttributeList
> & xAttrList
) SAL_OVERRIDE
;
1023 /// process all attributes
1024 void ProcessAttributes(const Reference
<xml::sax::XAttributeList
> & xAttrList
,
1025 Reference
<beans::XPropertySet
>& rPropSet
);
1028 * All marks can be created immediately. Since we don't care about
1029 * the element content, ProcessAttribute should set the properties
1032 * This method tolerates an empty PropertySet; subclasses however
1033 * are not expected to.
1035 virtual void ProcessAttribute(sal_uInt16 nNamespace
,
1036 const OUString
& sLocalName
,
1037 const OUString
& sValue
,
1038 Reference
<beans::XPropertySet
>& rPropSet
);
1040 static void GetServiceName(OUString
& sServiceName
,
1041 enum XMLTextPElemTokens nToken
);
1043 bool CreateMark(Reference
<beans::XPropertySet
>& rPropSet
,
1044 const OUString
& rServiceName
);
1047 TYPEINIT1( XMLIndexMarkImportContext_Impl
, SvXMLImportContext
);
1049 XMLIndexMarkImportContext_Impl::XMLIndexMarkImportContext_Impl(
1050 SvXMLImport
& rImport
,
1052 const OUString
& rLocalName
,
1053 enum XMLTextPElemTokens eTok
,
1054 XMLHints_Impl
& rHnts
) :
1055 SvXMLImportContext(rImport
, nPrefix
, rLocalName
),
1056 sAlternativeText("AlternativeText"),
1062 void XMLIndexMarkImportContext_Impl::StartElement(
1063 const Reference
<xml::sax::XAttributeList
> & xAttrList
)
1065 // get Cursor position (needed for all cases)
1066 Reference
<XTextRange
> xPos(
1067 GetImport().GetTextImport()->GetCursor()->getStart());
1068 Reference
<beans::XPropertySet
> xMark
;
1072 case XML_TOK_TEXT_TOC_MARK
:
1073 case XML_TOK_TEXT_USER_INDEX_MARK
:
1074 case XML_TOK_TEXT_ALPHA_INDEX_MARK
:
1076 // single mark: create mark and insert
1078 GetServiceName(sService
, eToken
);
1079 if (CreateMark(xMark
, sService
))
1081 ProcessAttributes(xAttrList
, xMark
);
1082 XMLHint_Impl
* pHint
= new XMLIndexMarkHint_Impl(xMark
, xPos
);
1083 rHints
.push_back(pHint
);
1085 // else: can't create mark -> ignore
1089 case XML_TOK_TEXT_TOC_MARK_START
:
1090 case XML_TOK_TEXT_USER_INDEX_MARK_START
:
1091 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START
:
1093 // start: create mark and insert (if ID is found)
1095 GetServiceName(sService
, eToken
);
1096 if (CreateMark(xMark
, sService
))
1098 ProcessAttributes(xAttrList
, xMark
);
1101 // process only if we find an ID
1102 XMLHint_Impl
* pHint
=
1103 new XMLIndexMarkHint_Impl(xMark
, xPos
, sID
);
1104 rHints
.push_back(pHint
);
1106 // else: no ID -> we'll never find the end -> ignore
1108 // else: can't create mark -> ignore
1112 case XML_TOK_TEXT_TOC_MARK_END
:
1113 case XML_TOK_TEXT_USER_INDEX_MARK_END
:
1114 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END
:
1116 // end: search for ID and set end of mark
1118 // call process attributes with empty XPropertySet:
1119 ProcessAttributes(xAttrList
, xMark
);
1122 // if we have an ID, find the hint and set the end position
1123 sal_uInt16 nCount
= rHints
.size();
1124 for(sal_uInt16 nPos
= 0; nPos
< nCount
; nPos
++)
1126 XMLHint_Impl
*pHint
= &rHints
[nPos
];
1127 if ( pHint
->IsIndexMark() &&
1129 static_cast<XMLIndexMarkHint_Impl
*>(pHint
)->GetID()) )
1131 // set end and stop searching
1132 pHint
->SetEnd(xPos
);
1137 // else: no ID -> ignore
1142 SAL_WARN("xmloff.text", "unknown index mark type!");
1147 void XMLIndexMarkImportContext_Impl::ProcessAttributes(
1148 const Reference
<xml::sax::XAttributeList
> & xAttrList
,
1149 Reference
<beans::XPropertySet
>& rPropSet
)
1151 // process attributes
1152 sal_Int16 nLength
= xAttrList
->getLength();
1153 for(sal_Int16 i
=0; i
<nLength
; i
++)
1155 OUString sLocalName
;
1156 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
1157 GetKeyByAttrName( xAttrList
->getNameByIndex(i
), &sLocalName
);
1159 ProcessAttribute(nPrefix
, sLocalName
,
1160 xAttrList
->getValueByIndex(i
),
1165 void XMLIndexMarkImportContext_Impl::ProcessAttribute(
1166 sal_uInt16 nNamespace
,
1167 const OUString
& sLocalName
,
1168 const OUString
& sValue
,
1169 Reference
<beans::XPropertySet
>& rPropSet
)
1171 // we only know ID + string-value attribute;
1172 // (former: marks, latter: -start + -end-marks)
1173 // the remainder is handled in sub-classes
1176 case XML_TOK_TEXT_TOC_MARK
:
1177 case XML_TOK_TEXT_USER_INDEX_MARK
:
1178 case XML_TOK_TEXT_ALPHA_INDEX_MARK
:
1179 if ( (XML_NAMESPACE_TEXT
== nNamespace
) &&
1180 IsXMLToken( sLocalName
, XML_STRING_VALUE
) )
1182 rPropSet
->setPropertyValue(sAlternativeText
, uno::makeAny(sValue
));
1187 case XML_TOK_TEXT_TOC_MARK_START
:
1188 case XML_TOK_TEXT_USER_INDEX_MARK_START
:
1189 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START
:
1190 case XML_TOK_TEXT_TOC_MARK_END
:
1191 case XML_TOK_TEXT_USER_INDEX_MARK_END
:
1192 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END
:
1193 if ( (XML_NAMESPACE_TEXT
== nNamespace
) &&
1194 IsXMLToken( sLocalName
, XML_ID
) )
1202 SAL_WARN("xmloff.text", "unknown index mark type!");
1207 static const sal_Char sAPI_com_sun_star_text_ContentIndexMark
[] =
1208 "com.sun.star.text.ContentIndexMark";
1209 static const sal_Char sAPI_com_sun_star_text_UserIndexMark
[] =
1210 "com.sun.star.text.UserIndexMark";
1211 static const sal_Char sAPI_com_sun_star_text_DocumentIndexMark
[] =
1212 "com.sun.star.text.DocumentIndexMark";
1214 void XMLIndexMarkImportContext_Impl::GetServiceName(
1215 OUString
& sServiceName
,
1216 enum XMLTextPElemTokens eToken
)
1220 case XML_TOK_TEXT_TOC_MARK
:
1221 case XML_TOK_TEXT_TOC_MARK_START
:
1222 case XML_TOK_TEXT_TOC_MARK_END
:
1225 sAPI_com_sun_star_text_ContentIndexMark
);
1226 sServiceName
= sTmp
;
1230 case XML_TOK_TEXT_USER_INDEX_MARK
:
1231 case XML_TOK_TEXT_USER_INDEX_MARK_START
:
1232 case XML_TOK_TEXT_USER_INDEX_MARK_END
:
1235 sAPI_com_sun_star_text_UserIndexMark
);
1236 sServiceName
= sTmp
;
1240 case XML_TOK_TEXT_ALPHA_INDEX_MARK
:
1241 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START
:
1242 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END
:
1245 sAPI_com_sun_star_text_DocumentIndexMark
);
1246 sServiceName
= sTmp
;
1252 SAL_WARN("xmloff.text", "unknown index mark type!");
1254 sServiceName
= sTmp
;
1260 bool XMLIndexMarkImportContext_Impl::CreateMark(
1261 Reference
<beans::XPropertySet
>& rPropSet
,
1262 const OUString
& rServiceName
)
1264 Reference
<lang::XMultiServiceFactory
>
1265 xFactory(GetImport().GetModel(), UNO_QUERY
);
1269 Reference
<beans::XPropertySet
> xPropSet( xFactory
->createInstance(rServiceName
), UNO_QUERY
);
1271 rPropSet
= xPropSet
;
1278 class XMLTOCMarkImportContext_Impl
: public XMLIndexMarkImportContext_Impl
1280 const OUString sLevel
;
1283 TYPEINFO_OVERRIDE();
1285 XMLTOCMarkImportContext_Impl(
1286 SvXMLImport
& rImport
,
1288 const OUString
& rLocalName
,
1289 enum XMLTextPElemTokens nTok
,
1290 XMLHints_Impl
& rHnts
);
1294 /** process outline level */
1295 virtual void ProcessAttribute(sal_uInt16 nNamespace
,
1296 const OUString
& sLocalName
,
1297 const OUString
& sValue
,
1298 Reference
<beans::XPropertySet
>& rPropSet
) SAL_OVERRIDE
;
1301 TYPEINIT1( XMLTOCMarkImportContext_Impl
, XMLIndexMarkImportContext_Impl
);
1303 XMLTOCMarkImportContext_Impl::XMLTOCMarkImportContext_Impl(
1304 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1305 enum XMLTextPElemTokens nTok
, XMLHints_Impl
& rHnts
) :
1306 XMLIndexMarkImportContext_Impl(rImport
, nPrefix
, rLocalName
,
1312 void XMLTOCMarkImportContext_Impl::ProcessAttribute(
1313 sal_uInt16 nNamespace
,
1314 const OUString
& sLocalName
,
1315 const OUString
& sValue
,
1316 Reference
<beans::XPropertySet
>& rPropSet
)
1318 SAL_WARN_IF(!rPropSet
.is(), "xmloff.text", "need PropertySet");
1320 if ((XML_NAMESPACE_TEXT
== nNamespace
) &&
1321 IsXMLToken( sLocalName
, XML_OUTLINE_LEVEL
) )
1323 // ouline level: set Level property
1325 if (::sax::Converter::convertNumber( nTmp
, sValue
)
1327 && nTmp
< GetImport().GetTextImport()->
1328 GetChapterNumbering()->getCount() )
1330 rPropSet
->setPropertyValue(sLevel
, uno::makeAny((sal_Int16
)(nTmp
- 1)));
1332 // else: value out of range -> ignore
1336 // else: delegate to superclass
1337 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1338 nNamespace
, sLocalName
, sValue
, rPropSet
);
1342 class XMLUserIndexMarkImportContext_Impl
: public XMLIndexMarkImportContext_Impl
1344 const OUString sUserIndexName
;
1345 const OUString sLevel
;
1348 TYPEINFO_OVERRIDE();
1350 XMLUserIndexMarkImportContext_Impl(
1351 SvXMLImport
& rImport
,
1353 const OUString
& rLocalName
,
1354 enum XMLTextPElemTokens nTok
,
1355 XMLHints_Impl
& rHnts
);
1359 /** process index name */
1360 virtual void ProcessAttribute(sal_uInt16 nNamespace
,
1361 const OUString
& sLocalName
,
1362 const OUString
& sValue
,
1363 Reference
<beans::XPropertySet
>& rPropSet
) SAL_OVERRIDE
;
1366 TYPEINIT1( XMLUserIndexMarkImportContext_Impl
, XMLIndexMarkImportContext_Impl
);
1368 XMLUserIndexMarkImportContext_Impl::XMLUserIndexMarkImportContext_Impl(
1369 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1370 enum XMLTextPElemTokens nTok
, XMLHints_Impl
& rHnts
) :
1371 XMLIndexMarkImportContext_Impl(rImport
, nPrefix
, rLocalName
,
1373 sUserIndexName("UserIndexName"),
1378 void XMLUserIndexMarkImportContext_Impl::ProcessAttribute(
1379 sal_uInt16 nNamespace
, const OUString
& sLocalName
, const OUString
& sValue
,
1380 Reference
<beans::XPropertySet
>& rPropSet
)
1382 if ( XML_NAMESPACE_TEXT
== nNamespace
)
1384 if ( IsXMLToken( sLocalName
, XML_INDEX_NAME
) )
1386 rPropSet
->setPropertyValue(sUserIndexName
, uno::makeAny(sValue
));
1388 else if ( IsXMLToken( sLocalName
, XML_OUTLINE_LEVEL
) )
1390 // ouline level: set Level property
1392 if (::sax::Converter::convertNumber(
1394 GetImport().GetTextImport()->GetChapterNumbering()->getCount()))
1396 rPropSet
->setPropertyValue(sLevel
, uno::makeAny(static_cast<sal_Int16
>(nTmp
- 1)));
1398 // else: value out of range -> ignore
1402 // else: unknown text property: delegate to super class
1403 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1404 nNamespace
, sLocalName
, sValue
, rPropSet
);
1409 // else: unknown namespace: delegate to super class
1410 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1411 nNamespace
, sLocalName
, sValue
, rPropSet
);
1415 class XMLAlphaIndexMarkImportContext_Impl
: public XMLIndexMarkImportContext_Impl
1417 const OUString sPrimaryKey
;
1418 const OUString sSecondaryKey
;
1419 const OUString sTextReading
;
1420 const OUString sPrimaryKeyReading
;
1421 const OUString sSecondaryKeyReading
;
1422 const OUString sMainEntry
;
1425 TYPEINFO_OVERRIDE();
1427 XMLAlphaIndexMarkImportContext_Impl(
1428 SvXMLImport
& rImport
,
1430 const OUString
& rLocalName
,
1431 enum XMLTextPElemTokens nTok
,
1432 XMLHints_Impl
& rHnts
);
1436 /** process primary + secondary keys */
1437 virtual void ProcessAttribute(sal_uInt16 nNamespace
,
1438 const OUString
& sLocalName
,
1439 const OUString
& sValue
,
1440 Reference
<beans::XPropertySet
>& rPropSet
) SAL_OVERRIDE
;
1443 TYPEINIT1( XMLAlphaIndexMarkImportContext_Impl
,
1444 XMLIndexMarkImportContext_Impl
);
1446 XMLAlphaIndexMarkImportContext_Impl::XMLAlphaIndexMarkImportContext_Impl(
1447 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1448 enum XMLTextPElemTokens nTok
, XMLHints_Impl
& rHnts
) :
1449 XMLIndexMarkImportContext_Impl(rImport
, nPrefix
, rLocalName
,
1451 sPrimaryKey("PrimaryKey"),
1452 sSecondaryKey("SecondaryKey"),
1453 sTextReading("TextReading"),
1454 sPrimaryKeyReading("PrimaryKeyReading"),
1455 sSecondaryKeyReading("SecondaryKeyReading"),
1456 sMainEntry("IsMainEntry")
1460 void XMLAlphaIndexMarkImportContext_Impl::ProcessAttribute(
1461 sal_uInt16 nNamespace
, const OUString
& sLocalName
, const OUString
& sValue
,
1462 Reference
<beans::XPropertySet
>& rPropSet
)
1464 if (XML_NAMESPACE_TEXT
== nNamespace
)
1466 if ( IsXMLToken( sLocalName
, XML_KEY1
) )
1468 rPropSet
->setPropertyValue(sPrimaryKey
, uno::makeAny(sValue
));
1470 else if ( IsXMLToken( sLocalName
, XML_KEY2
) )
1472 rPropSet
->setPropertyValue(sSecondaryKey
, uno::makeAny(sValue
));
1474 else if ( IsXMLToken( sLocalName
, XML_KEY1_PHONETIC
) )
1476 rPropSet
->setPropertyValue(sPrimaryKeyReading
, uno::makeAny(sValue
));
1478 else if ( IsXMLToken( sLocalName
, XML_KEY2_PHONETIC
) )
1480 rPropSet
->setPropertyValue(sSecondaryKeyReading
, uno::makeAny(sValue
));
1482 else if ( IsXMLToken( sLocalName
, XML_STRING_VALUE_PHONETIC
) )
1484 rPropSet
->setPropertyValue(sTextReading
, uno::makeAny(sValue
));
1486 else if ( IsXMLToken( sLocalName
, XML_MAIN_ENTRY
) )
1488 bool bMainEntry
= false;
1491 if (::sax::Converter::convertBool(bTmp
, sValue
))
1494 rPropSet
->setPropertyValue(sMainEntry
, uno::makeAny(bMainEntry
));
1498 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1499 nNamespace
, sLocalName
, sValue
, rPropSet
);
1504 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1505 nNamespace
, sLocalName
, sValue
, rPropSet
);
1509 TYPEINIT1( XMLImpSpanContext_Impl
, SvXMLImportContext
);
1511 XMLImpSpanContext_Impl::XMLImpSpanContext_Impl(
1512 SvXMLImport
& rImport
,
1514 const OUString
& rLName
,
1515 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
1516 XMLHints_Impl
& rHnts
,
1517 bool& rIgnLeadSpace
,
1518 sal_uInt8 nSFConvFlags
1520 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
1523 , rIgnoreLeadingSpace( rIgnLeadSpace
)
1524 , nStarFontsConvFlags( nSFConvFlags
& (CONV_FROM_STAR_BATS
|CONV_FROM_STAR_MATH
) )
1526 OUString aStyleName
;
1528 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1529 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
1531 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
1533 OUString aLocalName
;
1534 sal_uInt16 nPrefix
=
1535 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
1537 if( XML_NAMESPACE_TEXT
== nPrefix
&&
1538 IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
1539 aStyleName
= xAttrList
->getValueByIndex( i
);
1542 if( !aStyleName
.isEmpty() )
1544 pHint
= new XMLStyleHint_Impl( aStyleName
,
1545 GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
1546 rHints
.push_back( pHint
);
1550 XMLImpSpanContext_Impl::~XMLImpSpanContext_Impl()
1553 pHint
->SetEnd( GetImport().GetTextImport()
1554 ->GetCursorAsRange()->getStart() );
1557 SvXMLImportContext
*XMLImpSpanContext_Impl::CreateChildContext(
1558 SvXMLImport
& rImport
,
1559 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1560 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
1562 XMLHints_Impl
& rHints
,
1563 bool& rIgnoreLeadingSpace
,
1564 sal_uInt8 nStarFontsConvFlags
1567 SvXMLImportContext
*pContext
= 0;
1571 case XML_TOK_TEXT_SPAN
:
1572 pContext
= new XMLImpSpanContext_Impl( rImport
, nPrefix
,
1573 rLocalName
, xAttrList
,
1576 ,nStarFontsConvFlags
1580 case XML_TOK_TEXT_TAB_STOP
:
1581 pContext
= new XMLCharContext( rImport
, nPrefix
,
1582 rLocalName
, xAttrList
,
1584 rIgnoreLeadingSpace
= false;
1587 case XML_TOK_TEXT_LINE_BREAK
:
1588 pContext
= new XMLCharContext( rImport
, nPrefix
,
1589 rLocalName
, xAttrList
,
1590 ControlCharacter::LINE_BREAK
);
1591 rIgnoreLeadingSpace
= false;
1594 case XML_TOK_TEXT_S
:
1595 pContext
= new XMLCharContext( rImport
, nPrefix
,
1596 rLocalName
, xAttrList
,
1600 case XML_TOK_TEXT_HYPERLINK
:
1602 // test for HyperLinkURL property. If present, insert link as
1603 // text property (StarWriter), else try to insert as text
1604 // field (StarCalc, StarDraw, ...)
1605 Reference
< beans::XPropertySet
> xPropSet( rImport
.GetTextImport()->GetCursor(), UNO_QUERY
);
1607 const OUString
sHyperLinkURL("HyperLinkURL");
1609 if ( xPropSet
->getPropertySetInfo()->hasPropertyByName( sHyperLinkURL
) )
1611 pContext
= new XMLImpHyperlinkContext_Impl(
1617 rIgnoreLeadingSpace
);
1621 pContext
= new XMLUrlFieldImportContext( rImport
, *rImport
.GetTextImport().get(), nPrefix
, rLocalName
);
1622 //whitespace handling like other fields
1623 rIgnoreLeadingSpace
= false;
1629 case XML_TOK_TEXT_RUBY
:
1630 pContext
= new XMLImpRubyContext_Impl( rImport
, nPrefix
,
1631 rLocalName
, xAttrList
,
1633 rIgnoreLeadingSpace
);
1636 case XML_TOK_TEXT_NOTE
:
1637 if (rImport
.GetTextImport()->IsInFrame())
1639 // we must not insert footnotes into text frames
1640 pContext
= new SvXMLImportContext( rImport
, nPrefix
,
1645 pContext
= new XMLFootnoteImportContext( rImport
,
1646 *rImport
.GetTextImport().get(),
1647 nPrefix
, rLocalName
);
1649 rIgnoreLeadingSpace
= false;
1652 case XML_TOK_TEXT_REFERENCE
:
1653 case XML_TOK_TEXT_BOOKMARK
:
1654 case XML_TOK_TEXT_BOOKMARK_START
:
1655 case XML_TOK_TEXT_BOOKMARK_END
:
1656 pContext
= new XMLTextMarkImportContext( rImport
,
1657 *rImport
.GetTextImport().get(),
1658 nPrefix
, rLocalName
);
1661 case XML_TOK_TEXT_FIELDMARK
:
1662 case XML_TOK_TEXT_FIELDMARK_START
:
1663 case XML_TOK_TEXT_FIELDMARK_END
:
1664 pContext
= new XMLTextMarkImportContext( rImport
,
1665 *rImport
.GetTextImport().get(),
1666 nPrefix
, rLocalName
);
1669 case XML_TOK_TEXT_REFERENCE_START
:
1670 pContext
= new XMLStartReferenceContext_Impl( rImport
,
1671 nPrefix
, rLocalName
,
1672 rHints
, xAttrList
);
1675 case XML_TOK_TEXT_REFERENCE_END
:
1676 pContext
= new XMLEndReferenceContext_Impl( rImport
,
1677 nPrefix
, rLocalName
,
1678 rHints
, xAttrList
);
1681 case XML_TOK_TEXT_FRAME
:
1683 Reference
< XTextRange
> xAnchorPos
=
1684 rImport
.GetTextImport()->GetCursor()->getStart();
1685 XMLTextFrameContext
*pTextFrameContext
=
1686 new XMLTextFrameContext( rImport
, nPrefix
,
1687 rLocalName
, xAttrList
,
1688 TextContentAnchorType_AS_CHARACTER
);
1689 // Remove check for text content. (#i33242#)
1690 // Check for text content is done on the processing of the hint
1691 if( TextContentAnchorType_AT_CHARACTER
==
1692 pTextFrameContext
->GetAnchorType() )
1694 rHints
.push_back( new XMLTextFrameHint_Impl(
1695 pTextFrameContext
, xAnchorPos
) );
1697 pContext
= pTextFrameContext
;
1698 rIgnoreLeadingSpace
= false;
1701 case XML_TOK_DRAW_A
:
1703 Reference
< XTextRange
> xAnchorPos(rImport
.GetTextImport()->GetCursor()->getStart());
1705 new XMLTextFrameHyperlinkContext( rImport
, nPrefix
,
1706 rLocalName
, xAttrList
,
1707 TextContentAnchorType_AS_CHARACTER
);
1708 XMLTextFrameHint_Impl
*pHint
=
1709 new XMLTextFrameHint_Impl( pContext
, xAnchorPos
);
1710 rHints
.push_back( pHint
);
1714 case XML_TOK_TEXT_TOC_MARK
:
1715 case XML_TOK_TEXT_TOC_MARK_START
:
1716 pContext
= new XMLTOCMarkImportContext_Impl(
1717 rImport
, nPrefix
, rLocalName
,
1718 (enum XMLTextPElemTokens
)nToken
, rHints
);
1721 case XML_TOK_TEXT_USER_INDEX_MARK
:
1722 case XML_TOK_TEXT_USER_INDEX_MARK_START
:
1723 pContext
= new XMLUserIndexMarkImportContext_Impl(
1724 rImport
, nPrefix
, rLocalName
,
1725 (enum XMLTextPElemTokens
)nToken
, rHints
);
1728 case XML_TOK_TEXT_ALPHA_INDEX_MARK
:
1729 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START
:
1730 pContext
= new XMLAlphaIndexMarkImportContext_Impl(
1731 rImport
, nPrefix
, rLocalName
,
1732 (enum XMLTextPElemTokens
)nToken
, rHints
);
1735 case XML_TOK_TEXT_TOC_MARK_END
:
1736 case XML_TOK_TEXT_USER_INDEX_MARK_END
:
1737 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END
:
1738 pContext
= new XMLIndexMarkImportContext_Impl(
1739 rImport
, nPrefix
, rLocalName
, (enum XMLTextPElemTokens
)nToken
,
1743 case XML_TOK_TEXTP_CHANGE_START
:
1744 case XML_TOK_TEXTP_CHANGE_END
:
1745 case XML_TOK_TEXTP_CHANGE
:
1746 pContext
= new XMLChangeImportContext(
1747 rImport
, nPrefix
, rLocalName
,
1748 (nToken
!= XML_TOK_TEXTP_CHANGE_END
),
1749 (nToken
!= XML_TOK_TEXTP_CHANGE_START
),
1753 case XML_TOK_TEXT_META
:
1754 pContext
= new XMLMetaImportContext(rImport
, nPrefix
, rLocalName
,
1755 rHints
, rIgnoreLeadingSpace
);
1758 case XML_TOK_TEXT_META_FIELD
:
1759 pContext
= new XMLMetaFieldImportContext(rImport
, nPrefix
, rLocalName
,
1760 rHints
, rIgnoreLeadingSpace
);
1764 // none of the above? then it's probably a text field!
1766 XMLTextFieldImportContext::CreateTextFieldImportContext(
1767 rImport
, *rImport
.GetTextImport().get(), nPrefix
, rLocalName
,
1769 // #108784# import draw elements (except control shapes in headers)
1770 if( pContext
== NULL
&&
1771 !( rImport
.GetTextImport()->IsInHeaderFooter() &&
1772 nPrefix
== XML_NAMESPACE_DRAW
&&
1773 IsXMLToken( rLocalName
, XML_CONTROL
) ) )
1775 Reference
< XShapes
> xShapes
;
1776 SvXMLShapeContext
* pShapeContext
= rImport
.GetShapeImport()->CreateGroupChildContext(
1777 rImport
, nPrefix
, rLocalName
, xAttrList
, xShapes
);
1778 pContext
= pShapeContext
;
1779 // OD 2004-04-20 #i26791# - keep shape in a text frame hint to
1780 // adjust its anchor position, if its at-character anchored
1781 Reference
< XTextRange
> xAnchorPos
=
1782 rImport
.GetTextImport()->GetCursor()->getStart();
1783 rHints
.push_back( new XMLDrawHint_Impl( pShapeContext
, xAnchorPos
) );
1787 // ignore unknown content
1789 new SvXMLImportContext( rImport
, nPrefix
, rLocalName
);
1791 // Behind fields, shapes and any unknown content blanks aren't ignored
1792 rIgnoreLeadingSpace
= false;
1798 SvXMLImportContext
*XMLImpSpanContext_Impl::CreateChildContext(
1799 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1800 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
1802 const SvXMLTokenMap
& rTokenMap
=
1803 GetImport().GetTextImport()->GetTextPElemTokenMap();
1804 sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
1806 return CreateChildContext( GetImport(), nPrefix
, rLocalName
, xAttrList
,
1807 nToken
, rHints
, rIgnoreLeadingSpace
1808 ,nStarFontsConvFlags
1812 void XMLImpSpanContext_Impl::Characters( const OUString
& rChars
)
1814 OUString sStyleName
;
1816 sStyleName
= pHint
->GetStyleName();
1818 GetImport().GetTextImport()->ConvertStarFonts( rChars
, sStyleName
,
1819 nStarFontsConvFlags
,
1820 false, GetImport() );
1821 GetImport().GetTextImport()->InsertString( sChars
, rIgnoreLeadingSpace
);
1824 TYPEINIT1( XMLParaContext
, SvXMLImportContext
);
1826 XMLParaContext::XMLParaContext(
1827 SvXMLImport
& rImport
,
1829 const OUString
& rLName
,
1830 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
1832 SvXMLImportContext( rImport
, nPrfx
, rLName
),
1833 xStart( rImport
.GetTextImport()->GetCursorAsRange()->getStart() ),
1834 m_bHaveAbout(false),
1835 nOutlineLevel( IsXMLToken( rLName
, XML_H
) ? 1 : -1 ),
1837 // Lost outline numbering in master document (#i73509#)
1838 mbOutlineLevelAttrFound( false ),
1839 bIgnoreLeadingSpace( true ),
1841 bIsListHeader( false ),
1844 nStarFontsConvFlags( 0 )
1846 const SvXMLTokenMap
& rTokenMap
=
1847 GetImport().GetTextImport()->GetTextPAttrTokenMap();
1849 bool bHaveXmlId( false );
1850 OUString aCondStyleName
, sClassNames
;
1852 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1853 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
1855 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
1856 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
1858 OUString aLocalName
;
1859 sal_uInt16 nPrefix
=
1860 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
1862 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
1864 case XML_TOK_TEXT_P_XMLID
:
1868 case XML_TOK_TEXT_P_ABOUT
:
1870 m_bHaveAbout
= true;
1872 case XML_TOK_TEXT_P_PROPERTY
:
1873 m_sProperty
= rValue
;
1875 case XML_TOK_TEXT_P_CONTENT
:
1876 m_sContent
= rValue
;
1878 case XML_TOK_TEXT_P_DATATYPE
:
1879 m_sDatatype
= rValue
;
1881 case XML_TOK_TEXT_P_TEXTID
:
1882 if (!bHaveXmlId
) { m_sXmlId
= rValue
; }
1884 case XML_TOK_TEXT_P_STYLE_NAME
:
1885 sStyleName
= rValue
;
1887 case XML_TOK_TEXT_P_CLASS_NAMES
:
1888 sClassNames
= rValue
;
1890 case XML_TOK_TEXT_P_COND_STYLE_NAME
:
1891 aCondStyleName
= rValue
;
1893 case XML_TOK_TEXT_P_LEVEL
:
1895 sal_Int32 nTmp
= rValue
.toInt32();
1900 nOutlineLevel
= (sal_Int8
)nTmp
;
1902 // Lost outline numbering in master document (#i73509#)
1903 mbOutlineLevelAttrFound
= true;
1906 case XML_TOK_TEXT_P_IS_LIST_HEADER
:
1909 if( ::sax::Converter::convertBool( bBool
, rValue
) )
1911 bIsListHeader
= bBool
;
1915 case XML_TOK_TEXT_P_RESTART_NUMBERING
:
1918 if (::sax::Converter::convertBool(bBool
, rValue
))
1924 case XML_TOK_TEXT_P_START_VALUE
:
1926 nStartValue
= sal::static_int_cast
< sal_Int16
>(
1933 if( !aCondStyleName
.isEmpty() )
1934 sStyleName
= aCondStyleName
;
1935 else if( !sClassNames
.isEmpty() )
1937 sal_Int32 nDummy
= 0;
1938 sStyleName
= sClassNames
.getToken( 0, ' ', nDummy
);
1942 XMLParaContext::~XMLParaContext()
1944 rtl::Reference
< XMLTextImportHelper
> xTxtImport(
1945 GetImport().GetTextImport());
1946 Reference
< XTextRange
> xCrsrRange( xTxtImport
->GetCursorAsRange() );
1947 if( !xCrsrRange
.is() )
1948 return; // Robust (defect file)
1949 Reference
< XTextRange
> xEnd(xCrsrRange
->getStart());
1951 // if we have an id set for this paragraph, get a cursor for this
1952 // paragraph and register it with the given identifier
1953 // FIXME: this is just temporary, and should be removed when
1954 // EditEngine paragraphs implement XMetadatable!
1955 if (!m_sXmlId
.isEmpty())
1957 Reference
< XTextCursor
> xIdCursor( xTxtImport
->GetText()->createTextCursorByRange( xStart
) );
1958 if( xIdCursor
.is() )
1960 xIdCursor
->gotoRange( xEnd
, sal_True
);
1961 GetImport().getInterfaceToIdentifierMapper().registerReference(
1962 m_sXmlId
, Reference
<XInterface
>( xIdCursor
, UNO_QUERY
));
1966 // insert a paragraph break
1967 xTxtImport
->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH
);
1969 // create a cursor that select the whole last paragraph
1970 Reference
< XTextCursor
> xAttrCursor
;
1972 xAttrCursor
= xTxtImport
->GetText()->createTextCursorByRange( xStart
);
1973 if( !xAttrCursor
.is() )
1974 return; // Robust (defect file)
1975 } catch (const uno::Exception
&) {
1976 // createTextCursorByRange() likes to throw runtime exception, even
1977 // though it just means 'we were unable to create the cursor'
1980 xAttrCursor
->gotoRange( xEnd
, sal_True
);
1982 // xml:id for RDF metadata
1983 if (!m_sXmlId
.isEmpty() || m_bHaveAbout
|| !m_sProperty
.isEmpty())
1986 const uno::Reference
<container::XEnumerationAccess
> xEA
1987 (xAttrCursor
, uno::UNO_QUERY_THROW
);
1988 const uno::Reference
<container::XEnumeration
> xEnum(
1989 xEA
->createEnumeration(), uno::UNO_QUERY_THROW
);
1990 SAL_WARN_IF(!xEnum
->hasMoreElements(), "xmloff.text", "xml:id: no paragraph?");
1991 if (xEnum
->hasMoreElements()) {
1992 uno::Reference
<rdf::XMetadatable
> xMeta
;
1993 xEnum
->nextElement() >>= xMeta
;
1994 SAL_WARN_IF(!xMeta
.is(), "xmloff.text", "xml:id: not XMetadatable");
1995 GetImport().SetXmlId(xMeta
, m_sXmlId
);
1998 GetImport().AddRDFa(xMeta
,
1999 m_sAbout
, m_sProperty
, m_sContent
, m_sDatatype
);
2001 SAL_WARN_IF(xEnum
->hasMoreElements(), "xmloff.text", "xml:id: > 1 paragraph?");
2003 } catch (const uno::Exception
&) {
2004 SAL_INFO("xmloff.text", "XMLParaContext::~XMLParaContext: exception");
2008 OUString
const sCellParaStyleName(xTxtImport
->GetCellParaStyleDefault());
2009 if( !sCellParaStyleName
.isEmpty() )
2011 /* Suppress handling of outline and list attributes,
2012 because of side effects of method <SetStyleAndAttrs(..)> (#i80724#)
2014 xTxtImport
->SetStyleAndAttrs( GetImport(), xAttrCursor
,
2017 false, -1, // suppress outline handling
2018 false ); // suppress list attributes handling
2021 // #103445# for headings without style name, find the proper style
2022 if( bHeading
&& sStyleName
.isEmpty() )
2023 xTxtImport
->FindOutlineStyleName( sStyleName
, nOutlineLevel
);
2025 // set style and hard attributes at the previous paragraph
2026 // Add parameter <mbOutlineLevelAttrFound> (#i73509#)
2027 sStyleName
= xTxtImport
->SetStyleAndAttrs( GetImport(), xAttrCursor
,
2030 mbOutlineLevelAttrFound
,
2031 bHeading
? nOutlineLevel
: -1 );
2033 // handle list style header
2034 if (bHeading
&& (bIsListHeader
|| bIsRestart
))
2036 Reference
<XPropertySet
> xPropSet( xAttrCursor
, UNO_QUERY
);
2042 OUString sNumberingIsNumber
2043 ("NumberingIsNumber");
2044 if(xPropSet
->getPropertySetInfo()->
2045 hasPropertyByName(sNumberingIsNumber
))
2047 xPropSet
->setPropertyValue
2048 (sNumberingIsNumber
, makeAny( false ) );
2053 OUString sParaIsNumberingRestart
2054 ("ParaIsNumberingRestart");
2055 OUString sNumberingStartValue
2056 ("NumberingStartValue");
2057 if (xPropSet
->getPropertySetInfo()->
2058 hasPropertyByName(sParaIsNumberingRestart
))
2060 xPropSet
->setPropertyValue
2061 (sParaIsNumberingRestart
, makeAny(true));
2064 if (xPropSet
->getPropertySetInfo()->
2065 hasPropertyByName(sNumberingStartValue
))
2067 xPropSet
->setPropertyValue
2068 (sNumberingStartValue
, makeAny(nStartValue
));
2075 if( pHints
&& !pHints
->empty() )
2077 for( sal_uInt16 i
=0; i
<pHints
->size(); i
++ )
2079 XMLHint_Impl
*pHint
= &(*pHints
)[i
];
2080 xAttrCursor
->gotoRange( pHint
->GetStart(), sal_False
);
2081 xAttrCursor
->gotoRange( pHint
->GetEnd(), sal_True
);
2082 switch( pHint
->GetType() )
2084 case XML_HINT_STYLE
:
2086 const OUString
& rStyleName
=
2087 static_cast<XMLStyleHint_Impl
*>(pHint
)->GetStyleName();
2088 if( !rStyleName
.isEmpty() )
2089 xTxtImport
->SetStyleAndAttrs( GetImport(),
2090 xAttrCursor
, rStyleName
,
2094 case XML_HINT_REFERENCE
:
2096 const OUString
& rRefName
=
2097 static_cast<XMLReferenceHint_Impl
*>(pHint
)->GetRefName();
2098 if( !rRefName
.isEmpty() )
2100 if( !pHint
->GetEnd().is() )
2101 pHint
->SetEnd(xEnd
);
2103 // reference name uses rStyleName member
2104 // borrow from XMLTextMarkImportContext
2105 XMLTextMarkImportContext::CreateAndInsertMark(
2107 OUString( "com.sun.star.text.ReferenceMark"),
2113 case XML_HINT_HYPERLINK
:
2115 const XMLHyperlinkHint_Impl
*pHHint
=
2116 static_cast<const XMLHyperlinkHint_Impl
*>(pHint
);
2117 xTxtImport
->SetHyperlink( GetImport(),
2121 pHHint
->GetTargetFrameName(),
2122 pHHint
->GetStyleName(),
2123 pHHint
->GetVisitedStyleName(),
2124 pHHint
->GetEventsContext() );
2127 case XML_HINT_INDEX_MARK
:
2129 Reference
<beans::XPropertySet
> xMark(
2130 static_cast<const XMLIndexMarkHint_Impl
*>(pHint
)->GetMark());
2131 Reference
<XTextContent
> xContent(xMark
, UNO_QUERY
);
2132 xTxtImport
->GetText()->insertTextContent(
2133 xAttrCursor
, xContent
, sal_True
);
2136 case XML_HINT_TEXT_FRAME
:
2138 const XMLTextFrameHint_Impl
*pFHint
=
2139 static_cast<const XMLTextFrameHint_Impl
*>(pHint
);
2140 // Check for text content (#i33242#)
2141 Reference
< XTextContent
> xTextContent
=
2142 pFHint
->GetTextContent();
2143 if ( xTextContent
.is() )
2145 /* Core impl. of the unification of drawing objects and
2146 Writer fly frames (#i26791#)
2148 if ( pFHint
->IsBoundAtChar() )
2150 xTextContent
->attach( xAttrCursor
);
2153 /* Consider, that hint can also contain a shape -
2154 e.g. drawing object of type 'Text'. (#i33242#)
2158 Reference
< XShape
> xShape
= pFHint
->GetShape();
2161 // determine anchor type
2162 Reference
< XPropertySet
> xPropSet( xShape
, UNO_QUERY
);
2163 TextContentAnchorType eAnchorType
=
2164 TextContentAnchorType_AT_PARAGRAPH
;
2166 OUString
sAnchorType( "AnchorType" );
2167 Any aAny
= xPropSet
->getPropertyValue( sAnchorType
);
2168 aAny
>>= eAnchorType
;
2170 if ( TextContentAnchorType_AT_CHARACTER
== eAnchorType
)
2172 // set anchor position for at-character anchored objects
2173 Reference
<XTextRange
> xRange(xAttrCursor
, UNO_QUERY
);
2176 OUString
sTextRange( "TextRange" );
2177 xPropSet
->setPropertyValue(sTextRange
, aPos
);
2183 /* Core impl. of the unification of drawing objects and
2184 Writer fly frames (#i26791#)
2188 const XMLDrawHint_Impl
*pDHint
=
2189 static_cast<const XMLDrawHint_Impl
*>(pHint
);
2190 // Improvement: hint directly provides the shape. (#i33242#)
2191 Reference
< XShape
> xShape
= pDHint
->GetShape();
2194 // determine anchor type
2195 Reference
< XPropertySet
> xPropSet( xShape
, UNO_QUERY
);
2196 TextContentAnchorType eAnchorType
= TextContentAnchorType_AT_PARAGRAPH
;
2198 OUString
sAnchorType( "AnchorType" );
2199 Any aAny
= xPropSet
->getPropertyValue( sAnchorType
);
2200 aAny
>>= eAnchorType
;
2202 if ( TextContentAnchorType_AT_CHARACTER
== eAnchorType
)
2204 // set anchor position for at-character anchored objects
2205 Reference
<XTextRange
> xRange(xAttrCursor
, UNO_QUERY
);
2208 OUString
sTextRange( "TextRange" );
2209 xPropSet
->setPropertyValue(sTextRange
, aPos
);
2215 SAL_WARN( "xmloff.text", "What's this" );
2223 SvXMLImportContext
*XMLParaContext::CreateChildContext(
2224 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
2225 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
2227 const SvXMLTokenMap
& rTokenMap
=
2228 GetImport().GetTextImport()->GetTextPElemTokenMap();
2229 sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
2231 pHints
= new XMLHints_Impl
;
2232 return XMLImpSpanContext_Impl::CreateChildContext(
2233 GetImport(), nPrefix
, rLocalName
, xAttrList
,
2234 nToken
, *pHints
, bIgnoreLeadingSpace
2235 , nStarFontsConvFlags
2239 void XMLParaContext::Characters( const OUString
& rChars
)
2242 GetImport().GetTextImport()->ConvertStarFonts( rChars
, sStyleName
,
2243 nStarFontsConvFlags
,
2244 true, GetImport() );
2245 GetImport().GetTextImport()->InsertString( sChars
, bIgnoreLeadingSpace
);
2248 TYPEINIT1( XMLNumberedParaContext
, SvXMLImportContext
);
2250 XMLNumberedParaContext::XMLNumberedParaContext(
2251 SvXMLImport
& i_rImport
,
2252 sal_uInt16 i_nPrefix
,
2253 const OUString
& i_rLocalName
,
2254 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
) :
2255 SvXMLImportContext( i_rImport
, i_nPrefix
, i_rLocalName
),
2263 const SvXMLTokenMap
& rTokenMap(
2264 i_rImport
.GetTextImport()->GetTextNumberedParagraphAttrTokenMap() );
2266 const sal_Int16
nAttrCount( i_xAttrList
.is() ?
2267 i_xAttrList
->getLength() : 0 );
2268 for ( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
2270 const OUString
& rAttrName( i_xAttrList
->getNameByIndex( i
) );
2271 const OUString
& rValue ( i_xAttrList
->getValueByIndex( i
) );
2273 OUString aLocalName
;
2274 const sal_uInt16
nPrefix(
2275 GetImport().GetNamespaceMap().GetKeyByAttrName(
2276 rAttrName
, &aLocalName
) );
2277 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
2279 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_XMLID
:
2281 //FIXME: there is no UNO API for lists
2283 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LIST_ID
:
2286 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LEVEL
:
2288 sal_Int32 nTmp
= rValue
.toInt32();
2289 if ( nTmp
>= 1 && nTmp
<= SHRT_MAX
) {
2290 m_Level
= static_cast<sal_uInt16
>(nTmp
) - 1;
2294 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_STYLE_NAME
:
2297 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_CONTINUE_NUMBERING
:
2298 // this attribute is deprecated
2299 // ContinuteNumbering = IsXMLToken(rValue, XML_TRUE);
2301 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_START_VALUE
:
2303 sal_Int32 nTmp
= rValue
.toInt32();
2304 if ( nTmp
>= 0 && nTmp
<= SHRT_MAX
) {
2305 m_StartValue
= static_cast<sal_Int16
>(nTmp
);
2312 XMLTextListsHelper
& rTextListsHelper(
2313 i_rImport
.GetTextImport()->GetTextListHelper() );
2314 if (m_ListId
.isEmpty())
2316 SAL_WARN_IF( i_rImport
.GetODFVersion() == "1.2", "xmloff.text", "invalid numbered-paragraph: no list-id (1.2)" );
2317 m_ListId
= rTextListsHelper
.GetNumberedParagraphListId(m_Level
,
2319 SAL_WARN_IF(m_ListId
.isEmpty(), "xmloff.text", "numbered-paragraph: no ListId");
2320 if (m_ListId
.isEmpty()) {
2324 m_xNumRules
= rTextListsHelper
.EnsureNumberedParagraph( i_rImport
,
2325 m_ListId
, m_Level
, StyleName
);
2327 SAL_WARN_IF(!m_xNumRules
.is(), "xmloff.text", "numbered-paragraph: no NumRules");
2329 i_rImport
.GetTextImport()->GetTextListHelper().PushListContext( this );
2332 XMLNumberedParaContext::~XMLNumberedParaContext()
2336 void XMLNumberedParaContext::EndElement()
2338 if (!m_ListId
.isEmpty()) {
2339 GetImport().GetTextImport()->PopListContext();
2343 SvXMLImportContext
*XMLNumberedParaContext::CreateChildContext(
2344 sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
,
2345 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
)
2347 SvXMLImportContext
*pContext( 0 );
2349 if ( XML_NAMESPACE_TEXT
== i_nPrefix
||
2350 XML_NAMESPACE_LO_EXT
== i_nPrefix
)
2352 bool bIsHeader( IsXMLToken( i_rLocalName
, XML_H
) );
2353 if ( bIsHeader
|| IsXMLToken( i_rLocalName
, XML_P
) )
2355 pContext
= new XMLParaContext( GetImport(),
2356 i_nPrefix
, i_rLocalName
, i_xAttrList
, bIsHeader
);
2357 // ignore text:number } else if (IsXMLToken( i_rLocalName, XML_NUMBER )) {
2362 pContext
= SvXMLImportContext::CreateChildContext(
2363 i_nPrefix
, i_rLocalName
, i_xAttrList
);
2369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */