1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtparai.cxx,v $
10 * $Revision: 1.68.2.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "unointerfacetouniqueidentifiermapper.hxx"
34 #include <rtl/ustring.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <tools/debug.hxx>
38 #include <tools/string.hxx>
39 #include <svtools/svarray.hxx>
40 #include <com/sun/star/text/XTextFrame.hpp>
41 #include <com/sun/star/text/XTextCursor.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/beans/XPropertySetInfo.hpp>
44 #include <com/sun/star/text/ControlCharacter.hpp>
45 #include <com/sun/star/container/XIndexReplace.hpp>
46 #include <com/sun/star/drawing/XShapes.hpp>
47 #include <com/sun/star/container/XEnumerationAccess.hpp>
48 #include <com/sun/star/rdf/XMetadatable.hpp>
51 #include <xmloff/xmlictxt.hxx>
52 #include <xmloff/xmlimp.hxx>
53 #include <xmloff/xmltoken.hxx>
54 #include <xmloff/nmspmap.hxx>
55 #include "xmlnmspe.hxx"
56 #include <xmloff/txtimp.hxx>
57 #include "txtparai.hxx"
58 #include "txtfldi.hxx"
59 #include <xmloff/xmluconv.hxx>
60 #include "XMLFootnoteImportContext.hxx"
61 #include "XMLTextMarkImportContext.hxx"
62 #include "XMLTextFrameContext.hxx"
63 #include <xmloff/XMLCharContext.hxx>
64 #include "XMLTextFrameHyperlinkContext.hxx"
65 #include <xmloff/XMLEventsImportContext.hxx>
66 #include "XMLChangeImportContext.hxx"
67 #include "txtlists.hxx"
70 // OD 2004-04-21 #i26791#
71 #include <txtparaimphint.hxx>
72 typedef XMLHint_Impl
*XMLHint_ImplPtr
;
73 SV_DECL_PTRARR_DEL( XMLHints_Impl
, XMLHint_ImplPtr
, 5, 5 )
74 SV_IMPL_PTRARR( XMLHints_Impl
, XMLHint_ImplPtr
)
75 // OD 2004-04-21 #i26791#
76 #include <com/sun/star/beans/XPropertySet.hpp>
78 using ::rtl::OUString
;
79 using ::rtl::OUStringBuffer
;
81 using namespace ::com::sun::star
;
82 using namespace ::com::sun::star::uno
;
83 using namespace ::com::sun::star::text
;
84 using namespace ::com::sun::star::drawing
;
85 using namespace ::com::sun::star::beans
;
86 using namespace ::xmloff::token
;
87 using ::com::sun::star::container::XEnumerationAccess
;
88 using ::com::sun::star::container::XEnumeration
;
91 TYPEINIT1( XMLCharContext
, SvXMLImportContext
);
93 XMLCharContext::XMLCharContext(
96 const OUString
& rLName
,
97 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
100 SvXMLImportContext( rImport
, nPrfx
, rLName
)
107 const SvXMLNamespaceMap
& rMap
= GetImport().GetNamespaceMap();
108 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
109 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
111 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
114 sal_uInt16 nPrefix
=rMap
.GetKeyByAttrName( rAttrName
,&aLocalName
);
115 if( XML_NAMESPACE_TEXT
== nPrefix
&&
116 IsXMLToken( aLocalName
, XML_C
) )
118 sal_Int32 nTmp
= xAttrList
->getValueByIndex(i
).toInt32();
121 if( nTmp
> USHRT_MAX
)
122 m_nCount
= USHRT_MAX
;
124 m_nCount
= (sal_uInt16
)nTmp
;
131 XMLCharContext::XMLCharContext(
134 const OUString
& rLName
,
135 const Reference
< xml::sax::XAttributeList
> &,
136 sal_Int16 nControl
) :
137 SvXMLImportContext( rImp
, nPrfx
, rLName
)
138 ,m_nControl(nControl
)
143 XMLCharContext::~XMLCharContext()
146 // -----------------------------------------------------------------------------
147 void XMLCharContext::EndElement()
150 InsertControlCharacter( m_nControl
);
155 OUString
sBuff( &m_c
, 1 );
160 OUStringBuffer
sBuff( m_nCount
);
162 sBuff
.append( &m_c
, 1 );
164 InsertString(sBuff
.makeStringAndClear() );
168 // -----------------------------------------------------------------------------
169 void XMLCharContext::InsertControlCharacter(sal_Int16 _nControl
)
171 GetImport().GetTextImport()->InsertControlCharacter( _nControl
);
173 void XMLCharContext::InsertString(const ::rtl::OUString
& _sString
)
175 GetImport().GetTextImport()->InsertString( _sString
);
178 // ---------------------------------------------------------------------
180 /** import start of reference (<text:reference-start>) */
181 class XMLStartReferenceContext_Impl
: public SvXMLImportContext
186 // Do everything in constructor. Well ...
187 XMLStartReferenceContext_Impl (
188 SvXMLImport
& rImport
,
190 const OUString
& rLocalName
,
191 XMLHints_Impl
& rHnts
,
192 const Reference
<xml::sax::XAttributeList
> & xAttrList
);
195 TYPEINIT1( XMLStartReferenceContext_Impl
, SvXMLImportContext
);
197 XMLStartReferenceContext_Impl::XMLStartReferenceContext_Impl(
198 SvXMLImport
& rImport
,
200 const OUString
& rLocalName
,
201 XMLHints_Impl
& rHints
,
202 const Reference
<xml::sax::XAttributeList
> & xAttrList
) :
203 SvXMLImportContext(rImport
, nPrefix
, rLocalName
)
208 // borrow FindName from XMLTextMarkImportContext, where bookmarks
209 // and point references are handled.
210 if (XMLTextMarkImportContext::FindName(GetImport(), xAttrList
, sName
, dummy
))
212 XMLHint_Impl
* pHint
= new XMLReferenceHint_Impl(
213 sName
, rImport
.GetTextImport()->GetCursor()->getStart() );
215 // degenerates to point reference, if no end is found!
216 pHint
->SetEnd(rImport
.GetTextImport()->GetCursor()->getStart() );
218 rHints
.Insert(pHint
, rHints
.Count());
222 // ---------------------------------------------------------------------
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
)
252 // borrow from XMLTextMarkImportContext
253 if (XMLTextMarkImportContext::FindName(GetImport(), xAttrList
, sName
, dummy
))
255 // search for reference start
256 sal_uInt16 nCount
= rHints
.Count();
257 for(sal_uInt16 nPos
= 0; nPos
< nCount
; nPos
++)
259 XMLHint_Impl
*pHint
= rHints
[nPos
];
260 if ( pHint
->IsReference() &&
261 sName
.equals( ((XMLReferenceHint_Impl
*)pHint
)->GetRefName()) )
263 // set end and stop searching
264 pHint
->SetEnd(GetImport().GetTextImport()->
265 GetCursor()->getStart() );
269 // else: no start (in this paragraph) -> ignore
273 // ---------------------------------------------------------------------
275 class XMLImpSpanContext_Impl
: public SvXMLImportContext
277 const OUString sTextFrame
;
279 XMLHints_Impl
& rHints
;
280 XMLStyleHint_Impl
*pHint
;
282 sal_Bool
& rIgnoreLeadingSpace
;
284 sal_uInt8 nStarFontsConvFlags
;
290 XMLImpSpanContext_Impl(
291 SvXMLImport
& rImport
,
293 const OUString
& rLName
,
294 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
295 XMLHints_Impl
& rHnts
,
296 sal_Bool
& rIgnLeadSpace
297 ,sal_uInt8 nSFConvFlags
300 virtual ~XMLImpSpanContext_Impl();
302 static SvXMLImportContext
*CreateChildContext(
303 SvXMLImport
& rImport
,
304 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
305 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
306 sal_uInt16 nToken
, XMLHints_Impl
& rHnts
,
307 sal_Bool
& rIgnLeadSpace
308 ,sal_uInt8 nStarFontsConvFlags
= 0
310 virtual SvXMLImportContext
*CreateChildContext(
311 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
312 const Reference
< xml::sax::XAttributeList
> & xAttrList
);
314 virtual void Characters( const OUString
& rChars
);
316 // ---------------------------------------------------------------------
318 class XMLImpHyperlinkContext_Impl
: public SvXMLImportContext
320 XMLHints_Impl
& rHints
;
321 XMLHyperlinkHint_Impl
*pHint
;
323 sal_Bool
& rIgnoreLeadingSpace
;
329 XMLImpHyperlinkContext_Impl(
330 SvXMLImport
& rImport
,
332 const OUString
& rLName
,
333 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
334 XMLHints_Impl
& rHnts
,
335 sal_Bool
& rIgnLeadSpace
);
337 virtual ~XMLImpHyperlinkContext_Impl();
339 virtual SvXMLImportContext
*CreateChildContext(
340 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
341 const Reference
< xml::sax::XAttributeList
> & xAttrList
);
343 virtual void Characters( const OUString
& rChars
);
346 TYPEINIT1( XMLImpHyperlinkContext_Impl
, SvXMLImportContext
);
348 XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
349 SvXMLImport
& rImport
,
351 const OUString
& rLName
,
352 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
353 XMLHints_Impl
& rHnts
,
354 sal_Bool
& rIgnLeadSpace
) :
355 SvXMLImportContext( rImport
, nPrfx
, rLName
),
357 pHint( new XMLHyperlinkHint_Impl(
358 GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) ),
359 rIgnoreLeadingSpace( rIgnLeadSpace
)
362 const SvXMLTokenMap
& rTokenMap
=
363 GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
365 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
366 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
368 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
369 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
373 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
375 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
377 case XML_TOK_TEXT_HYPERLINK_HREF
:
378 pHint
->SetHRef( GetImport().GetAbsoluteReference( rValue
) );
380 case XML_TOK_TEXT_HYPERLINK_NAME
:
381 pHint
->SetName( rValue
);
383 case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME
:
384 pHint
->SetTargetFrameName( rValue
);
386 case XML_TOK_TEXT_HYPERLINK_SHOW
:
389 case XML_TOK_TEXT_HYPERLINK_STYLE_NAME
:
390 pHint
->SetStyleName( rValue
);
392 case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME
:
393 pHint
->SetVisitedStyleName( rValue
);
398 if( sShow
.getLength() && !pHint
->GetTargetFrameName().getLength() )
400 if( IsXMLToken( sShow
, XML_NEW
) )
401 pHint
->SetTargetFrameName(
402 OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ) );
403 else if( IsXMLToken( sShow
, XML_REPLACE
) )
404 pHint
->SetTargetFrameName(
405 OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ) );
407 rHints
.Insert( pHint
, rHints
.Count() );
410 XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
413 pHint
->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 pHint
->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
, rHints
, rIgnoreLeadingSpace
);
441 void XMLImpHyperlinkContext_Impl::Characters( const OUString
& rChars
)
443 GetImport().GetTextImport()->InsertString( rChars
, rIgnoreLeadingSpace
);
446 // ---------------------------------------------------------------------
448 class XMLImpRubyBaseContext_Impl
: public SvXMLImportContext
450 XMLHints_Impl
& rHints
;
452 sal_Bool
& rIgnoreLeadingSpace
;
458 XMLImpRubyBaseContext_Impl(
459 SvXMLImport
& rImport
,
461 const OUString
& rLName
,
462 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
463 XMLHints_Impl
& rHnts
,
464 sal_Bool
& rIgnLeadSpace
);
466 virtual ~XMLImpRubyBaseContext_Impl();
468 virtual SvXMLImportContext
*CreateChildContext(
469 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
470 const Reference
< xml::sax::XAttributeList
> & xAttrList
);
472 virtual void Characters( const OUString
& rChars
);
475 TYPEINIT1( XMLImpRubyBaseContext_Impl
, SvXMLImportContext
);
477 XMLImpRubyBaseContext_Impl::XMLImpRubyBaseContext_Impl(
478 SvXMLImport
& rImport
,
480 const OUString
& rLName
,
481 const Reference
< xml::sax::XAttributeList
> &,
482 XMLHints_Impl
& rHnts
,
483 sal_Bool
& rIgnLeadSpace
) :
484 SvXMLImportContext( rImport
, nPrfx
, rLName
),
486 rIgnoreLeadingSpace( rIgnLeadSpace
)
490 XMLImpRubyBaseContext_Impl::~XMLImpRubyBaseContext_Impl()
494 SvXMLImportContext
*XMLImpRubyBaseContext_Impl::CreateChildContext(
495 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
496 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
498 const SvXMLTokenMap
& rTokenMap
=
499 GetImport().GetTextImport()->GetTextPElemTokenMap();
500 sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
502 return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), nPrefix
,
503 rLocalName
, xAttrList
,
504 nToken
, rHints
, rIgnoreLeadingSpace
);
507 void XMLImpRubyBaseContext_Impl::Characters( const OUString
& rChars
)
509 GetImport().GetTextImport()->InsertString( rChars
, rIgnoreLeadingSpace
);
512 // ---------------------------------------------------------------------
514 class XMLImpRubyTextContext_Impl
: public SvXMLImportContext
516 XMLRubyHint_Impl
*pHint
;
522 XMLImpRubyTextContext_Impl(
523 SvXMLImport
& rImport
,
525 const OUString
& rLName
,
526 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
527 XMLRubyHint_Impl
*pHint
);
529 virtual ~XMLImpRubyTextContext_Impl();
531 virtual void Characters( const OUString
& rChars
);
534 TYPEINIT1( XMLImpRubyTextContext_Impl
, SvXMLImportContext
);
536 XMLImpRubyTextContext_Impl::XMLImpRubyTextContext_Impl(
537 SvXMLImport
& rImport
,
539 const OUString
& rLName
,
540 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
541 XMLRubyHint_Impl
*pHt
) :
542 SvXMLImportContext( rImport
, nPrfx
, rLName
),
545 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
546 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
548 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
549 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
553 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
555 if( XML_NAMESPACE_TEXT
== nPrefix
&&
556 IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
558 pHint
->SetTextStyleName( rValue
);
564 XMLImpRubyTextContext_Impl::~XMLImpRubyTextContext_Impl()
568 void XMLImpRubyTextContext_Impl::Characters( const OUString
& rChars
)
570 pHint
->AppendText( rChars
);
573 // ---------------------------------------------------------------------
575 class XMLImpRubyContext_Impl
: public SvXMLImportContext
577 XMLHints_Impl
& rHints
;
578 XMLRubyHint_Impl
*pHint
;
580 sal_Bool
& rIgnoreLeadingSpace
;
586 XMLImpRubyContext_Impl(
587 SvXMLImport
& rImport
,
589 const OUString
& rLName
,
590 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
591 XMLHints_Impl
& rHnts
,
592 sal_Bool
& rIgnLeadSpace
);
594 virtual ~XMLImpRubyContext_Impl();
596 virtual SvXMLImportContext
*CreateChildContext(
597 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
598 const Reference
< xml::sax::XAttributeList
> & xAttrList
);
601 TYPEINIT1( XMLImpRubyContext_Impl
, SvXMLImportContext
);
603 XMLImpRubyContext_Impl::XMLImpRubyContext_Impl(
604 SvXMLImport
& rImport
,
606 const OUString
& rLName
,
607 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
608 XMLHints_Impl
& rHnts
,
609 sal_Bool
& rIgnLeadSpace
) :
610 SvXMLImportContext( rImport
, nPrfx
, rLName
),
612 pHint( new XMLRubyHint_Impl(
613 GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) ),
614 rIgnoreLeadingSpace( rIgnLeadSpace
)
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 pHint
->SetStyleName( rValue
);
633 rHints
.Insert( pHint
, rHints
.Count() );
636 XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl()
639 pHint
->SetEnd( GetImport().GetTextImport()
640 ->GetCursorAsRange()->getStart() );
643 SvXMLImportContext
*XMLImpRubyContext_Impl::CreateChildContext(
644 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
645 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
647 SvXMLImportContext
*pContext
;
648 if( XML_NAMESPACE_TEXT
== nPrefix
)
650 if( IsXMLToken( rLocalName
, XML_RUBY_BASE
) )
651 pContext
= new XMLImpRubyBaseContext_Impl( GetImport(), nPrefix
,
655 rIgnoreLeadingSpace
);
656 else if( IsXMLToken( rLocalName
, XML_RUBY_TEXT
) )
657 pContext
= new XMLImpRubyTextContext_Impl( GetImport(), nPrefix
,
662 pContext
= new SvXMLImportContext(
663 GetImport(), nPrefix
, rLocalName
);
666 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
,
672 // ---------------------------------------------------------------------
674 /** for text:meta and text:meta-field
677 class XMLMetaImportContextBase
: public SvXMLImportContext
679 XMLHints_Impl
& m_rHints
;
681 sal_Bool
& m_rIgnoreLeadingSpace
;
684 Reference
<XTextRange
> m_xStart
;
692 XMLMetaImportContextBase(
693 SvXMLImport
& i_rImport
,
694 sal_uInt16 i_nPrefix
,
695 const OUString
& i_rLocalName
,
696 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
,
697 XMLHints_Impl
& i_rHints
,
698 sal_Bool
& i_rIgnoreLeadingSpace
);
700 virtual ~XMLMetaImportContextBase();
702 virtual void EndElement();
704 virtual SvXMLImportContext
*CreateChildContext(
705 sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
,
706 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
);
708 virtual void Characters( const OUString
& i_rChars
);
710 virtual void ProcessAttribute(sal_uInt16
const i_nPrefix
,
711 OUString
const & i_rLocalName
, OUString
const & i_rValue
);
713 virtual void InsertMeta(const Reference
<XTextRange
> & i_xInsertionRange
)
717 TYPEINIT1( XMLMetaImportContextBase
, SvXMLImportContext
);
719 XMLMetaImportContextBase::XMLMetaImportContextBase(
720 SvXMLImport
& i_rImport
,
721 sal_uInt16 i_nPrefix
,
722 const OUString
& i_rLocalName
,
723 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
,
724 XMLHints_Impl
& i_rHints
,
725 sal_Bool
& i_rIgnoreLeadingSpace
)
726 : SvXMLImportContext( i_rImport
, i_nPrefix
, i_rLocalName
)
727 , m_rHints( i_rHints
)
728 , m_rIgnoreLeadingSpace( i_rIgnoreLeadingSpace
)
731 const sal_Int16
nAttrCount(i_xAttrList
.is() ? i_xAttrList
->getLength() : 0);
732 for ( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
734 const OUString
& rAttrName( i_xAttrList
->getNameByIndex( i
) );
735 const OUString
& rValue( i_xAttrList
->getValueByIndex( i
) );
739 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
741 ProcessAttribute(nPrefix
, sLocalName
, rValue
);
743 m_xStart
= GetImport().GetTextImport()->GetCursorAsRange()->getStart();
746 XMLMetaImportContextBase::~XMLMetaImportContextBase()
750 void XMLMetaImportContextBase::EndElement()
752 OSL_ENSURE(m_xStart
.is(), "no mxStart?");
753 if (!m_xStart
.is()) return;
755 const Reference
<XTextRange
> xEndRange(
756 GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
758 // create range for insertion
759 const Reference
<XTextCursor
> xInsertionCursor(
760 GetImport().GetTextImport()->GetText()->createTextCursorByRange(
762 xInsertionCursor
->gotoRange(m_xStart
, sal_True
);
764 const Reference
<XTextRange
> xInsertionRange(xInsertionCursor
, UNO_QUERY
);
766 InsertMeta(xInsertionRange
);
769 Reference
<XMultiServiceFactory
> xFactory(rImport
.GetModel(), UNO_QUERY
);
772 Reference
<XInterface
> xIfc
= xFactory
->createInstance(sServiceName
);
774 // xml:id for RDF metadata
775 rImport
.SetXmlId(xIfc
, i_rXmlId
);
777 // cast to XTextContent and attach to document
778 Reference
<XTextContent
> xTextContent(xIfc
, UNO_QUERY
);
779 if (xTextContent
.is())
783 rImport
.GetTextImport()->GetText()->insertTextContent(
784 xInsertionRange
, xTextContent
, sal_True
);
786 catch (com::sun::star::lang::IllegalArgumentException
&)
788 OSL_ENSURE(false, "XMLMetaImportContext::EndElement: iae");
795 SvXMLImportContext
* XMLMetaImportContextBase::CreateChildContext(
796 sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
,
797 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
)
799 const SvXMLTokenMap
& rTokenMap
=
800 GetImport().GetTextImport()->GetTextPElemTokenMap();
801 sal_uInt16 nToken
= rTokenMap
.Get( i_nPrefix
, i_rLocalName
);
803 return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), i_nPrefix
,
804 i_rLocalName
, i_xAttrList
, nToken
, m_rHints
, m_rIgnoreLeadingSpace
);
807 void XMLMetaImportContextBase::Characters( const OUString
& i_rChars
)
809 GetImport().GetTextImport()->InsertString(i_rChars
, m_rIgnoreLeadingSpace
);
812 void XMLMetaImportContextBase::ProcessAttribute(sal_uInt16
const i_nPrefix
,
813 OUString
const & i_rLocalName
, OUString
const & i_rValue
)
815 if ( (XML_NAMESPACE_XML
== i_nPrefix
) &&
816 IsXMLToken(i_rLocalName
, XML_ID
) )
823 // ---------------------------------------------------------------------
828 class XMLMetaImportContext
: public XMLMetaImportContextBase
832 ::rtl::OUString m_sAbout
;
833 ::rtl::OUString m_sProperty
;
834 ::rtl::OUString m_sContent
;
835 ::rtl::OUString m_sDatatype
;
840 XMLMetaImportContext(
841 SvXMLImport
& i_rImport
,
842 sal_uInt16 i_nPrefix
,
843 const OUString
& i_rLocalName
,
844 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
,
845 XMLHints_Impl
& i_rHints
,
846 sal_Bool
& i_rIgnoreLeadingSpace
);
848 virtual void ProcessAttribute(sal_uInt16
const i_nPrefix
,
849 OUString
const & i_rLocalName
, OUString
const & i_rValue
);
851 virtual void InsertMeta(const Reference
<XTextRange
> & i_xInsertionRange
);
854 TYPEINIT1( XMLMetaImportContext
, XMLMetaImportContextBase
);
856 XMLMetaImportContext::XMLMetaImportContext(
857 SvXMLImport
& i_rImport
,
858 sal_uInt16 i_nPrefix
,
859 const OUString
& i_rLocalName
,
860 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
,
861 XMLHints_Impl
& i_rHints
,
862 sal_Bool
& i_rIgnoreLeadingSpace
)
863 : XMLMetaImportContextBase( i_rImport
, i_nPrefix
, i_rLocalName
,
864 i_xAttrList
, i_rHints
, i_rIgnoreLeadingSpace
)
865 , m_bHaveAbout(false)
869 void XMLMetaImportContext::ProcessAttribute(sal_uInt16
const i_nPrefix
,
870 OUString
const & i_rLocalName
, OUString
const & i_rValue
)
872 if ( XML_NAMESPACE_XHTML
== i_nPrefix
)
875 if ( IsXMLToken( i_rLocalName
, XML_ABOUT
) )
880 else if ( IsXMLToken( i_rLocalName
, XML_PROPERTY
) )
882 m_sProperty
= i_rValue
;
884 else if ( IsXMLToken( i_rLocalName
, XML_CONTENT
) )
886 m_sContent
= i_rValue
;
888 else if ( IsXMLToken( i_rLocalName
, XML_DATATYPE
) )
890 m_sDatatype
= i_rValue
;
895 XMLMetaImportContextBase::ProcessAttribute(
896 i_nPrefix
, i_rLocalName
, i_rValue
);
900 void XMLMetaImportContext::InsertMeta(
901 const Reference
<XTextRange
> & i_xInsertionRange
)
903 OSL_ENSURE(!m_bHaveAbout
== !m_sProperty
.getLength(),
904 "XMLMetaImportContext::InsertMeta: invalid RDFa?");
905 if (m_XmlId
.getLength() || (m_bHaveAbout
&& m_sProperty
.getLength()))
908 const uno::Reference
<rdf::XMetadatable
> xMeta(
909 XMLTextMarkImportContext::CreateAndInsertMark(
911 OUString::createFromAscii(
912 "com.sun.star.text.InContentMetadata"),
914 i_xInsertionRange
, m_XmlId
),
916 OSL_ENSURE(xMeta
.is(), "cannot insert Meta?");
918 if (xMeta
.is() && m_bHaveAbout
)
920 GetImport().AddRDFa(xMeta
,
921 m_sAbout
, m_sProperty
, m_sContent
, m_sDatatype
);
926 OSL_TRACE("invalid <text:meta>: no xml:id, no valid RDFa");
930 // ---------------------------------------------------------------------
935 class XMLMetaFieldImportContext
: public XMLMetaImportContextBase
937 OUString m_DataStyleName
;
942 XMLMetaFieldImportContext(
943 SvXMLImport
& i_rImport
,
944 sal_uInt16 i_nPrefix
,
945 const OUString
& i_rLocalName
,
946 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
,
947 XMLHints_Impl
& i_rHints
,
948 sal_Bool
& i_rIgnoreLeadingSpace
);
950 virtual void ProcessAttribute(sal_uInt16
const i_nPrefix
,
951 OUString
const & i_rLocalName
, OUString
const & i_rValue
);
953 virtual void InsertMeta(const Reference
<XTextRange
> & i_xInsertionRange
);
956 TYPEINIT1( XMLMetaFieldImportContext
, XMLMetaImportContextBase
);
958 XMLMetaFieldImportContext::XMLMetaFieldImportContext(
959 SvXMLImport
& i_rImport
,
960 sal_uInt16 i_nPrefix
,
961 const OUString
& i_rLocalName
,
962 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
,
963 XMLHints_Impl
& i_rHints
,
964 sal_Bool
& i_rIgnoreLeadingSpace
)
965 : XMLMetaImportContextBase( i_rImport
, i_nPrefix
, i_rLocalName
,
966 i_xAttrList
, i_rHints
, i_rIgnoreLeadingSpace
)
970 void XMLMetaFieldImportContext::ProcessAttribute(sal_uInt16
const i_nPrefix
,
971 OUString
const & i_rLocalName
, OUString
const & i_rValue
)
973 if( XML_NAMESPACE_STYLE
== i_nPrefix
&&
974 IsXMLToken( i_rLocalName
, XML_DATA_STYLE_NAME
) )
976 m_DataStyleName
= i_rValue
;
980 XMLMetaImportContextBase::ProcessAttribute(
981 i_nPrefix
, i_rLocalName
, i_rValue
);
985 void XMLMetaFieldImportContext::InsertMeta(
986 const Reference
<XTextRange
> & i_xInsertionRange
)
988 if (m_XmlId
.getLength()) // valid?
991 const Reference
<XPropertySet
> xPropertySet(
992 XMLTextMarkImportContext::CreateAndInsertMark(
994 OUString::createFromAscii(
995 "com.sun.star.text.textfield.MetadataField"),
997 i_xInsertionRange
, m_XmlId
),
999 OSL_ENSURE(xPropertySet
.is(), "cannot insert MetaField?");
1000 if (!xPropertySet
.is()) return;
1002 if (m_DataStyleName
.getLength())
1004 sal_Bool
isDefaultLanguage(sal_True
);
1006 const sal_Int32
nKey( GetImport().GetTextImport()->GetDataStyleKey(
1007 m_DataStyleName
, & isDefaultLanguage
) );
1011 static ::rtl::OUString
sPropertyIsFixedLanguage(
1012 ::rtl::OUString::createFromAscii("IsFixedLanguage") );
1015 xPropertySet
->setPropertyValue(
1016 OUString::createFromAscii("NumberFormat"), any
);
1017 if ( xPropertySet
->getPropertySetInfo()->
1018 hasPropertyByName( sPropertyIsFixedLanguage
) )
1020 any
<<= static_cast<bool>(!isDefaultLanguage
);
1021 xPropertySet
->setPropertyValue( sPropertyIsFixedLanguage
,
1029 OSL_TRACE("invalid <text:meta-field>: no xml:id");
1034 // ---------------------------------------------------------------------
1038 * Process index marks.
1040 * All *-mark-end index marks should instantiate *this* class (because
1041 * it doesn't process attributes other than ID), while the *-mark and
1042 * *-mark-start classes should instantiate the apporpiate subclasses.
1044 class XMLIndexMarkImportContext_Impl
: public SvXMLImportContext
1046 const OUString sAlternativeText
;
1048 XMLHints_Impl
& rHints
;
1049 const enum XMLTextPElemTokens eToken
;
1055 XMLIndexMarkImportContext_Impl(
1056 SvXMLImport
& rImport
,
1058 const OUString
& rLocalName
,
1059 enum XMLTextPElemTokens nTok
,
1060 XMLHints_Impl
& rHnts
);
1062 void StartElement(const Reference
<xml::sax::XAttributeList
> & xAttrList
);
1066 /// process all attributes
1067 void ProcessAttributes(const Reference
<xml::sax::XAttributeList
> & xAttrList
,
1068 Reference
<beans::XPropertySet
>& rPropSet
);
1071 * All marks can be created immediatly. Since we don't care about
1072 * the element content, ProcessAttribute should set the properties
1075 * This method tolerates an empty PropertySet; subclasses however
1076 * are not expected to.
1078 virtual void ProcessAttribute(sal_uInt16 nNamespace
,
1079 OUString sLocalName
,
1081 Reference
<beans::XPropertySet
>& rPropSet
);
1083 static void GetServiceName(OUString
& sServiceName
,
1084 enum XMLTextPElemTokens nToken
);
1086 sal_Bool
CreateMark(Reference
<beans::XPropertySet
>& rPropSet
,
1087 const OUString
& rServiceName
);
1091 TYPEINIT1( XMLIndexMarkImportContext_Impl
, SvXMLImportContext
);
1093 XMLIndexMarkImportContext_Impl::XMLIndexMarkImportContext_Impl(
1094 SvXMLImport
& rImport
,
1096 const OUString
& rLocalName
,
1097 enum XMLTextPElemTokens eTok
,
1098 XMLHints_Impl
& rHnts
) :
1099 SvXMLImportContext(rImport
, nPrefix
, rLocalName
),
1100 sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")),
1106 void XMLIndexMarkImportContext_Impl::StartElement(
1107 const Reference
<xml::sax::XAttributeList
> & xAttrList
)
1109 // get Cursor position (needed for all cases)
1110 Reference
<XTextRange
> xPos(
1111 GetImport().GetTextImport()->GetCursor()->getStart());
1112 Reference
<beans::XPropertySet
> xMark
;
1116 case XML_TOK_TEXT_TOC_MARK
:
1117 case XML_TOK_TEXT_USER_INDEX_MARK
:
1118 case XML_TOK_TEXT_ALPHA_INDEX_MARK
:
1120 // single mark: create mark and insert
1122 GetServiceName(sService
, eToken
);
1123 if (CreateMark(xMark
, sService
))
1125 ProcessAttributes(xAttrList
, xMark
);
1126 XMLHint_Impl
* pHint
= new XMLIndexMarkHint_Impl(xMark
, xPos
);
1127 rHints
.Insert(pHint
, rHints
.Count());
1129 // else: can't create mark -> ignore
1133 case XML_TOK_TEXT_TOC_MARK_START
:
1134 case XML_TOK_TEXT_USER_INDEX_MARK_START
:
1135 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START
:
1137 // start: create mark and insert (if ID is found)
1139 GetServiceName(sService
, eToken
);
1140 if (CreateMark(xMark
, sService
))
1142 ProcessAttributes(xAttrList
, xMark
);
1143 if (sID
.getLength() > 0)
1145 // process only if we find an ID
1146 XMLHint_Impl
* pHint
=
1147 new XMLIndexMarkHint_Impl(xMark
, xPos
, sID
);
1148 rHints
.Insert(pHint
, rHints
.Count());
1150 // else: no ID -> we'll never find the end -> ignore
1152 // else: can't create mark -> ignore
1156 case XML_TOK_TEXT_TOC_MARK_END
:
1157 case XML_TOK_TEXT_USER_INDEX_MARK_END
:
1158 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END
:
1160 // end: search for ID and set end of mark
1162 // call process attributes with empty XPropertySet:
1163 ProcessAttributes(xAttrList
, xMark
);
1164 if (sID
.getLength() > 0)
1166 // if we have an ID, find the hint and set the end position
1167 sal_uInt16 nCount
= rHints
.Count();
1168 for(sal_uInt16 nPos
= 0; nPos
< nCount
; nPos
++)
1170 XMLHint_Impl
*pHint
= rHints
[nPos
];
1171 if ( pHint
->IsIndexMark() &&
1173 ((XMLIndexMarkHint_Impl
*)pHint
)->GetID()) )
1175 // set end and stop searching
1176 pHint
->SetEnd(xPos
);
1181 // else: no ID -> ignore
1186 DBG_ERROR("unknown index mark type!");
1191 void XMLIndexMarkImportContext_Impl::ProcessAttributes(
1192 const Reference
<xml::sax::XAttributeList
> & xAttrList
,
1193 Reference
<beans::XPropertySet
>& rPropSet
)
1195 // process attributes
1196 sal_Int16 nLength
= xAttrList
->getLength();
1197 for(sal_Int16 i
=0; i
<nLength
; i
++)
1199 OUString sLocalName
;
1200 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
1201 GetKeyByAttrName( xAttrList
->getNameByIndex(i
), &sLocalName
);
1203 ProcessAttribute(nPrefix
, sLocalName
,
1204 xAttrList
->getValueByIndex(i
),
1209 void XMLIndexMarkImportContext_Impl::ProcessAttribute(
1210 sal_uInt16 nNamespace
,
1211 OUString sLocalName
,
1213 Reference
<beans::XPropertySet
>& rPropSet
)
1215 // we only know ID + string-value attribute;
1216 // (former: marks, latter: -start + -end-marks)
1217 // the remainder is handled in sub-classes
1220 case XML_TOK_TEXT_TOC_MARK
:
1221 case XML_TOK_TEXT_USER_INDEX_MARK
:
1222 case XML_TOK_TEXT_ALPHA_INDEX_MARK
:
1223 if ( (XML_NAMESPACE_TEXT
== nNamespace
) &&
1224 IsXMLToken( sLocalName
, XML_STRING_VALUE
) )
1226 rPropSet
->setPropertyValue(sAlternativeText
, uno::makeAny(sValue
));
1231 case XML_TOK_TEXT_TOC_MARK_START
:
1232 case XML_TOK_TEXT_USER_INDEX_MARK_START
:
1233 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START
:
1234 case XML_TOK_TEXT_TOC_MARK_END
:
1235 case XML_TOK_TEXT_USER_INDEX_MARK_END
:
1236 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END
:
1237 if ( (XML_NAMESPACE_TEXT
== nNamespace
) &&
1238 IsXMLToken( sLocalName
, XML_ID
) )
1246 DBG_ERROR("unknown index mark type!");
1251 static const sal_Char sAPI_com_sun_star_text_ContentIndexMark
[] =
1252 "com.sun.star.text.ContentIndexMark";
1253 static const sal_Char sAPI_com_sun_star_text_UserIndexMark
[] =
1254 "com.sun.star.text.UserIndexMark";
1255 static const sal_Char sAPI_com_sun_star_text_DocumentIndexMark
[] =
1256 "com.sun.star.text.DocumentIndexMark";
1259 void XMLIndexMarkImportContext_Impl::GetServiceName(
1260 OUString
& sServiceName
,
1261 enum XMLTextPElemTokens eToken
)
1265 case XML_TOK_TEXT_TOC_MARK
:
1266 case XML_TOK_TEXT_TOC_MARK_START
:
1267 case XML_TOK_TEXT_TOC_MARK_END
:
1269 OUString
sTmp(RTL_CONSTASCII_USTRINGPARAM(
1270 sAPI_com_sun_star_text_ContentIndexMark
));
1271 sServiceName
= sTmp
;
1275 case XML_TOK_TEXT_USER_INDEX_MARK
:
1276 case XML_TOK_TEXT_USER_INDEX_MARK_START
:
1277 case XML_TOK_TEXT_USER_INDEX_MARK_END
:
1279 OUString
sTmp(RTL_CONSTASCII_USTRINGPARAM(
1280 sAPI_com_sun_star_text_UserIndexMark
));
1281 sServiceName
= sTmp
;
1285 case XML_TOK_TEXT_ALPHA_INDEX_MARK
:
1286 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START
:
1287 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END
:
1289 OUString
sTmp(RTL_CONSTASCII_USTRINGPARAM(
1290 sAPI_com_sun_star_text_DocumentIndexMark
));
1291 sServiceName
= sTmp
;
1297 DBG_ERROR("unknown index mark type!");
1299 sServiceName
= sTmp
;
1306 sal_Bool
XMLIndexMarkImportContext_Impl::CreateMark(
1307 Reference
<beans::XPropertySet
>& rPropSet
,
1308 const OUString
& rServiceName
)
1310 Reference
<lang::XMultiServiceFactory
>
1311 xFactory(GetImport().GetModel(), UNO_QUERY
);
1315 Reference
<beans::XPropertySet
> xPropSet( xFactory
->createInstance(rServiceName
), UNO_QUERY
);
1317 rPropSet
= xPropSet
;
1325 class XMLTOCMarkImportContext_Impl
: public XMLIndexMarkImportContext_Impl
1327 const OUString sLevel
;
1332 XMLTOCMarkImportContext_Impl(
1333 SvXMLImport
& rImport
,
1335 const OUString
& rLocalName
,
1336 enum XMLTextPElemTokens nTok
,
1337 XMLHints_Impl
& rHnts
);
1341 /** process outline level */
1342 virtual void ProcessAttribute(sal_uInt16 nNamespace
,
1343 OUString sLocalName
,
1345 Reference
<beans::XPropertySet
>& rPropSet
);
1348 TYPEINIT1( XMLTOCMarkImportContext_Impl
, XMLIndexMarkImportContext_Impl
);
1351 XMLTOCMarkImportContext_Impl::XMLTOCMarkImportContext_Impl(
1352 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1353 enum XMLTextPElemTokens nTok
, XMLHints_Impl
& rHnts
) :
1354 XMLIndexMarkImportContext_Impl(rImport
, nPrefix
, rLocalName
,
1356 sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
1360 void XMLTOCMarkImportContext_Impl::ProcessAttribute(
1361 sal_uInt16 nNamespace
,
1362 OUString sLocalName
,
1364 Reference
<beans::XPropertySet
>& rPropSet
)
1366 DBG_ASSERT(rPropSet
.is(), "need PropertySet");
1368 if ((XML_NAMESPACE_TEXT
== nNamespace
) &&
1369 IsXMLToken( sLocalName
, XML_OUTLINE_LEVEL
) )
1371 // ouline level: set Level property
1373 if ( SvXMLUnitConverter::convertNumber( nTmp
, sValue
)
1375 && nTmp
< GetImport().GetTextImport()->
1376 GetChapterNumbering()->getCount() )
1378 rPropSet
->setPropertyValue(sLevel
, uno::makeAny((sal_Int16
)(nTmp
- 1)));
1380 // else: value out of range -> ignore
1384 // else: delegate to superclass
1385 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1386 nNamespace
, sLocalName
, sValue
, rPropSet
);
1390 class XMLUserIndexMarkImportContext_Impl
: public XMLIndexMarkImportContext_Impl
1392 const OUString sUserIndexName
;
1393 const OUString sLevel
;
1398 XMLUserIndexMarkImportContext_Impl(
1399 SvXMLImport
& rImport
,
1401 const OUString
& rLocalName
,
1402 enum XMLTextPElemTokens nTok
,
1403 XMLHints_Impl
& rHnts
);
1407 /** process index name */
1408 virtual void ProcessAttribute(sal_uInt16 nNamespace
,
1409 OUString sLocalName
,
1411 Reference
<beans::XPropertySet
>& rPropSet
);
1414 TYPEINIT1( XMLUserIndexMarkImportContext_Impl
, XMLIndexMarkImportContext_Impl
);
1416 XMLUserIndexMarkImportContext_Impl::XMLUserIndexMarkImportContext_Impl(
1417 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1418 enum XMLTextPElemTokens nTok
, XMLHints_Impl
& rHnts
) :
1419 XMLIndexMarkImportContext_Impl(rImport
, nPrefix
, rLocalName
,
1421 sUserIndexName(RTL_CONSTASCII_USTRINGPARAM("UserIndexName")),
1422 sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
1426 void XMLUserIndexMarkImportContext_Impl::ProcessAttribute(
1427 sal_uInt16 nNamespace
, OUString sLocalName
, OUString sValue
,
1428 Reference
<beans::XPropertySet
>& rPropSet
)
1430 if ( XML_NAMESPACE_TEXT
== nNamespace
)
1432 if ( IsXMLToken( sLocalName
, XML_INDEX_NAME
) )
1434 rPropSet
->setPropertyValue(sUserIndexName
, uno::makeAny(sValue
));
1436 else if ( IsXMLToken( sLocalName
, XML_OUTLINE_LEVEL
) )
1438 // ouline level: set Level property
1440 if (SvXMLUnitConverter::convertNumber(
1442 GetImport().GetTextImport()->GetChapterNumbering()->getCount()))
1444 rPropSet
->setPropertyValue(sLevel
, uno::makeAny(static_cast<sal_Int16
>(nTmp
- 1)));
1446 // else: value out of range -> ignore
1450 // else: unknown text property: delegate to super class
1451 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1452 nNamespace
, sLocalName
, sValue
, rPropSet
);
1457 // else: unknown namespace: delegate to super class
1458 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1459 nNamespace
, sLocalName
, sValue
, rPropSet
);
1464 class XMLAlphaIndexMarkImportContext_Impl
: public XMLIndexMarkImportContext_Impl
1466 const OUString sPrimaryKey
;
1467 const OUString sSecondaryKey
;
1468 const OUString sTextReading
;
1469 const OUString sPrimaryKeyReading
;
1470 const OUString sSecondaryKeyReading
;
1471 const OUString sMainEntry
;
1476 XMLAlphaIndexMarkImportContext_Impl(
1477 SvXMLImport
& rImport
,
1479 const OUString
& rLocalName
,
1480 enum XMLTextPElemTokens nTok
,
1481 XMLHints_Impl
& rHnts
);
1485 /** process primary + secondary keys */
1486 virtual void ProcessAttribute(sal_uInt16 nNamespace
,
1487 OUString sLocalName
,
1489 Reference
<beans::XPropertySet
>& rPropSet
);
1492 TYPEINIT1( XMLAlphaIndexMarkImportContext_Impl
,
1493 XMLIndexMarkImportContext_Impl
);
1495 XMLAlphaIndexMarkImportContext_Impl::XMLAlphaIndexMarkImportContext_Impl(
1496 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1497 enum XMLTextPElemTokens nTok
, XMLHints_Impl
& rHnts
) :
1498 XMLIndexMarkImportContext_Impl(rImport
, nPrefix
, rLocalName
,
1500 sPrimaryKey(RTL_CONSTASCII_USTRINGPARAM("PrimaryKey")),
1501 sSecondaryKey(RTL_CONSTASCII_USTRINGPARAM("SecondaryKey")),
1502 sTextReading(RTL_CONSTASCII_USTRINGPARAM("TextReading")),
1503 sPrimaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("PrimaryKeyReading")),
1504 sSecondaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("SecondaryKeyReading")),
1505 sMainEntry(RTL_CONSTASCII_USTRINGPARAM("IsMainEntry"))
1509 void XMLAlphaIndexMarkImportContext_Impl::ProcessAttribute(
1510 sal_uInt16 nNamespace
, OUString sLocalName
, OUString sValue
,
1511 Reference
<beans::XPropertySet
>& rPropSet
)
1513 if (XML_NAMESPACE_TEXT
== nNamespace
)
1515 if ( IsXMLToken( sLocalName
, XML_KEY1
) )
1517 rPropSet
->setPropertyValue(sPrimaryKey
, uno::makeAny(sValue
));
1519 else if ( IsXMLToken( sLocalName
, XML_KEY2
) )
1521 rPropSet
->setPropertyValue(sSecondaryKey
, uno::makeAny(sValue
));
1523 else if ( IsXMLToken( sLocalName
, XML_KEY1_PHONETIC
) )
1525 rPropSet
->setPropertyValue(sPrimaryKeyReading
, uno::makeAny(sValue
));
1527 else if ( IsXMLToken( sLocalName
, XML_KEY2_PHONETIC
) )
1529 rPropSet
->setPropertyValue(sSecondaryKeyReading
, uno::makeAny(sValue
));
1531 else if ( IsXMLToken( sLocalName
, XML_STRING_VALUE_PHONETIC
) )
1533 rPropSet
->setPropertyValue(sTextReading
, uno::makeAny(sValue
));
1535 else if ( IsXMLToken( sLocalName
, XML_MAIN_ENTRY
) )
1537 sal_Bool bMainEntry
= sal_False
, bTmp
;
1539 if (SvXMLUnitConverter::convertBool(bTmp
, sValue
))
1542 rPropSet
->setPropertyValue(sMainEntry
, uno::makeAny(bMainEntry
));
1546 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1547 nNamespace
, sLocalName
, sValue
, rPropSet
);
1552 XMLIndexMarkImportContext_Impl::ProcessAttribute(
1553 nNamespace
, sLocalName
, sValue
, rPropSet
);
1558 // ---------------------------------------------------------------------
1560 TYPEINIT1( XMLImpSpanContext_Impl
, SvXMLImportContext
);
1562 XMLImpSpanContext_Impl::XMLImpSpanContext_Impl(
1563 SvXMLImport
& rImport
,
1565 const OUString
& rLName
,
1566 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
1567 XMLHints_Impl
& rHnts
,
1568 sal_Bool
& rIgnLeadSpace
1569 ,sal_uInt8 nSFConvFlags
1571 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
1572 , sTextFrame(RTL_CONSTASCII_USTRINGPARAM("TextFrame"))
1575 , rIgnoreLeadingSpace( rIgnLeadSpace
)
1576 , nStarFontsConvFlags( nSFConvFlags
& (CONV_FROM_STAR_BATS
|CONV_FROM_STAR_MATH
) )
1578 OUString aStyleName
;
1580 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1581 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
1583 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
1585 OUString aLocalName
;
1586 sal_uInt16 nPrefix
=
1587 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
1589 if( XML_NAMESPACE_TEXT
== nPrefix
&&
1590 IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
1591 aStyleName
= xAttrList
->getValueByIndex( i
);
1594 if( aStyleName
.getLength() )
1596 pHint
= new XMLStyleHint_Impl( aStyleName
,
1597 GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
1598 rHints
.Insert( pHint
, rHints
.Count() );
1602 XMLImpSpanContext_Impl::~XMLImpSpanContext_Impl()
1605 pHint
->SetEnd( GetImport().GetTextImport()
1606 ->GetCursorAsRange()->getStart() );
1609 SvXMLImportContext
*XMLImpSpanContext_Impl::CreateChildContext(
1610 SvXMLImport
& rImport
,
1611 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1612 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
1614 XMLHints_Impl
& rHints
,
1615 sal_Bool
& rIgnoreLeadingSpace
1616 ,sal_uInt8 nStarFontsConvFlags
1619 SvXMLImportContext
*pContext
= 0;
1623 case XML_TOK_TEXT_SPAN
:
1624 pContext
= new XMLImpSpanContext_Impl( rImport
, nPrefix
,
1625 rLocalName
, xAttrList
,
1628 ,nStarFontsConvFlags
1632 case XML_TOK_TEXT_TAB_STOP
:
1633 pContext
= new XMLCharContext( rImport
, nPrefix
,
1634 rLocalName
, xAttrList
,
1635 0x0009, sal_False
);
1636 rIgnoreLeadingSpace
= sal_False
;
1639 case XML_TOK_TEXT_LINE_BREAK
:
1640 pContext
= new XMLCharContext( rImport
, nPrefix
,
1641 rLocalName
, xAttrList
,
1642 ControlCharacter::LINE_BREAK
);
1643 rIgnoreLeadingSpace
= sal_False
;
1646 case XML_TOK_TEXT_S
:
1647 pContext
= new XMLCharContext( rImport
, nPrefix
,
1648 rLocalName
, xAttrList
,
1652 case XML_TOK_TEXT_HYPERLINK
:
1654 // test for HyperLinkURL property. If present, insert link as
1655 // text property (StarWriter), else try to insert as text
1656 // field (StarCalc, StarDraw, ...)
1657 Reference
<beans::XPropertySet
> xPropSet(
1658 rImport
.GetTextImport()->GetCursor(),
1661 const OUString
sHyperLinkURL(
1662 RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL"));
1664 if (xPropSet
->getPropertySetInfo()->hasPropertyByName(sHyperLinkURL
))
1666 pContext
= new XMLImpHyperlinkContext_Impl( rImport
, nPrefix
,
1667 rLocalName
, xAttrList
,
1669 rIgnoreLeadingSpace
);
1673 pContext
= new XMLUrlFieldImportContext( rImport
,
1674 *rImport
.GetTextImport().get(),
1675 nPrefix
, rLocalName
);
1676 //whitespace handling like other fields
1677 rIgnoreLeadingSpace
= sal_False
;
1683 case XML_TOK_TEXT_RUBY
:
1684 pContext
= new XMLImpRubyContext_Impl( rImport
, nPrefix
,
1685 rLocalName
, xAttrList
,
1687 rIgnoreLeadingSpace
);
1690 case XML_TOK_TEXT_NOTE
:
1692 if (rImport
.GetTextImport()->IsInFrame())
1694 // we must not insert footnotes into text frames
1695 pContext
= new SvXMLImportContext( rImport
, nPrefix
,
1700 pContext
= new XMLFootnoteImportContext( rImport
,
1701 *rImport
.GetTextImport().get(),
1702 nPrefix
, rLocalName
);
1705 // create default context to skip content
1706 pContext
= new SvXMLImportContext( rImport
, nPrefix
, rLocalName
);
1707 #endif // #ifndef SVX_LIGHT
1708 rIgnoreLeadingSpace
= sal_False
;
1711 case XML_TOK_TEXT_REFERENCE
:
1712 case XML_TOK_TEXT_BOOKMARK
:
1713 case XML_TOK_TEXT_BOOKMARK_START
:
1714 case XML_TOK_TEXT_BOOKMARK_END
:
1715 pContext
= new XMLTextMarkImportContext( rImport
,
1716 *rImport
.GetTextImport().get(),
1717 nPrefix
, rLocalName
);
1720 case XML_TOK_TEXT_FIELDMARK
:
1721 case XML_TOK_TEXT_FIELDMARK_START
:
1722 case XML_TOK_TEXT_FIELDMARK_END
:
1723 pContext
= new XMLTextMarkImportContext( rImport
,
1724 *rImport
.GetTextImport().get(),
1725 nPrefix
, rLocalName
);
1728 case XML_TOK_TEXT_REFERENCE_START
:
1729 pContext
= new XMLStartReferenceContext_Impl( rImport
,
1730 nPrefix
, rLocalName
,
1731 rHints
, xAttrList
);
1734 case XML_TOK_TEXT_REFERENCE_END
:
1735 pContext
= new XMLEndReferenceContext_Impl( rImport
,
1736 nPrefix
, rLocalName
,
1737 rHints
, xAttrList
);
1740 case XML_TOK_TEXT_FRAME
:
1742 Reference
< XTextRange
> xAnchorPos
=
1743 rImport
.GetTextImport()->GetCursor()->getStart();
1744 XMLTextFrameContext
*pTextFrameContext
=
1745 new XMLTextFrameContext( rImport
, nPrefix
,
1746 rLocalName
, xAttrList
,
1747 TextContentAnchorType_AS_CHARACTER
);
1748 // --> OD 2004-08-24 #i33242# - remove check for text content.
1749 // Check for text content is done on the processing of the hint
1750 if( TextContentAnchorType_AT_CHARACTER
==
1751 pTextFrameContext
->GetAnchorType() )
1754 rHints
.Insert( new XMLTextFrameHint_Impl(
1755 pTextFrameContext
, xAnchorPos
),
1758 pContext
= pTextFrameContext
;
1759 rIgnoreLeadingSpace
= sal_False
;
1762 case XML_TOK_DRAW_A
:
1764 Reference
< XTextRange
> xAnchorPos(rImport
.GetTextImport()->GetCursor()->getStart());
1766 new XMLTextFrameHyperlinkContext( rImport
, nPrefix
,
1767 rLocalName
, xAttrList
,
1768 TextContentAnchorType_AS_CHARACTER
);
1769 XMLTextFrameHint_Impl
*pHint
=
1770 new XMLTextFrameHint_Impl( pContext
, xAnchorPos
);
1771 rHints
.Insert( pHint
, rHints
.Count() );
1775 case XML_TOK_TEXT_TOC_MARK
:
1776 case XML_TOK_TEXT_TOC_MARK_START
:
1777 pContext
= new XMLTOCMarkImportContext_Impl(
1778 rImport
, nPrefix
, rLocalName
,
1779 (enum XMLTextPElemTokens
)nToken
, rHints
);
1782 case XML_TOK_TEXT_USER_INDEX_MARK
:
1783 case XML_TOK_TEXT_USER_INDEX_MARK_START
:
1784 pContext
= new XMLUserIndexMarkImportContext_Impl(
1785 rImport
, nPrefix
, rLocalName
,
1786 (enum XMLTextPElemTokens
)nToken
, rHints
);
1789 case XML_TOK_TEXT_ALPHA_INDEX_MARK
:
1790 case XML_TOK_TEXT_ALPHA_INDEX_MARK_START
:
1791 pContext
= new XMLAlphaIndexMarkImportContext_Impl(
1792 rImport
, nPrefix
, rLocalName
,
1793 (enum XMLTextPElemTokens
)nToken
, rHints
);
1796 case XML_TOK_TEXT_TOC_MARK_END
:
1797 case XML_TOK_TEXT_USER_INDEX_MARK_END
:
1798 case XML_TOK_TEXT_ALPHA_INDEX_MARK_END
:
1799 pContext
= new XMLIndexMarkImportContext_Impl(
1800 rImport
, nPrefix
, rLocalName
, (enum XMLTextPElemTokens
)nToken
,
1804 case XML_TOK_TEXTP_CHANGE_START
:
1805 case XML_TOK_TEXTP_CHANGE_END
:
1806 case XML_TOK_TEXTP_CHANGE
:
1807 pContext
= new XMLChangeImportContext(
1808 rImport
, nPrefix
, rLocalName
,
1809 (nToken
!= XML_TOK_TEXTP_CHANGE_END
),
1810 (nToken
!= XML_TOK_TEXTP_CHANGE_START
),
1814 // FIXME: should test before enabling...
1816 case XML_TOK_TEXT_META
:
1817 pContext
= new XMLMetaImportContext(rImport
, nPrefix
, rLocalName
,
1818 xAttrList
, rHints
, rIgnoreLeadingSpace
);
1821 case XML_TOK_TEXT_META_FIELD
:
1822 pContext
= new XMLMetaFieldImportContext(rImport
, nPrefix
, rLocalName
,
1823 xAttrList
, rHints
, rIgnoreLeadingSpace
);
1828 // none of the above? then it's probably a text field!
1830 XMLTextFieldImportContext::CreateTextFieldImportContext(
1831 rImport
, *rImport
.GetTextImport().get(), nPrefix
, rLocalName
,
1833 // #108784# import draw elements (except control shapes in headers)
1834 if( pContext
== NULL
&&
1835 !( rImport
.GetTextImport()->IsInHeaderFooter() &&
1836 nPrefix
== XML_NAMESPACE_DRAW
&&
1837 IsXMLToken( rLocalName
, XML_CONTROL
) ) )
1839 Reference
< XShapes
> xShapes
;
1840 SvXMLShapeContext
* pShapeContext
= rImport
.GetShapeImport()->CreateGroupChildContext(
1841 rImport
, nPrefix
, rLocalName
, xAttrList
, xShapes
);
1842 pContext
= pShapeContext
;
1844 // OD 2004-04-20 #i26791# - keep shape in a text frame hint to
1845 // adjust its anchor position, if its at-character anchored
1846 Reference
< XTextRange
> xAnchorPos
=
1847 rImport
.GetTextImport()->GetCursor()->getStart();
1848 rHints
.Insert( new XMLDrawHint_Impl( pShapeContext
, xAnchorPos
),
1854 pContext
=rImport
.createUnknownContext(nPrefix
, rLocalName
, xAttrList
);
1856 // Behind fields, shapes and any unknown content blanks aren't ignored
1857 rIgnoreLeadingSpace
= sal_False
;
1862 SvXMLImportContext
*XMLImpSpanContext_Impl::CreateChildContext(
1863 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
1864 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
1866 const SvXMLTokenMap
& rTokenMap
=
1867 GetImport().GetTextImport()->GetTextPElemTokenMap();
1868 sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
1870 return CreateChildContext( GetImport(), nPrefix
, rLocalName
, xAttrList
,
1871 nToken
, rHints
, rIgnoreLeadingSpace
1872 ,nStarFontsConvFlags
1876 void XMLImpSpanContext_Impl::Characters( const OUString
& rChars
)
1878 OUString sStyleName
;
1880 sStyleName
= pHint
->GetStyleName();
1882 GetImport().GetTextImport()->ConvertStarFonts( rChars
, sStyleName
,
1883 nStarFontsConvFlags
,
1884 sal_False
, GetImport() );
1885 GetImport().GetTextImport()->InsertString( sChars
, rIgnoreLeadingSpace
);
1888 // ---------------------------------------------------------------------
1890 TYPEINIT1( XMLParaContext
, SvXMLImportContext
);
1892 XMLParaContext::XMLParaContext(
1893 SvXMLImport
& rImport
,
1895 const OUString
& rLName
,
1896 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
1898 SvXMLImportContext( rImport
, nPrfx
, rLName
),
1899 xStart( rImport
.GetTextImport()->GetCursorAsRange()->getStart() ),
1900 m_bHaveAbout(false),
1901 nOutlineLevel( IsXMLToken( rLName
, XML_H
) ? 1 : -1 ),
1903 // --> OD 2007-07-25 #i73509#
1904 mbOutlineLevelAttrFound( sal_False
),
1906 bIgnoreLeadingSpace( sal_True
),
1908 bIsListHeader( false ),
1911 ,nStarFontsConvFlags( 0 )
1913 const SvXMLTokenMap
& rTokenMap
=
1914 GetImport().GetTextImport()->GetTextPAttrTokenMap();
1916 OUString sStyleName
, aCondStyleName
, sClassNames
;
1918 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1919 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
1921 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
1922 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
1924 OUString aLocalName
;
1925 sal_uInt16 nPrefix
=
1926 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
1928 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
1930 case XML_TOK_TEXT_P_XMLID
:
1933 case XML_TOK_TEXT_P_ABOUT
:
1935 m_bHaveAbout
= true;
1937 case XML_TOK_TEXT_P_PROPERTY
:
1938 m_sProperty
= rValue
;
1940 case XML_TOK_TEXT_P_CONTENT
:
1941 m_sContent
= rValue
;
1943 case XML_TOK_TEXT_P_DATATYPE
:
1944 m_sDatatype
= rValue
;
1946 case XML_TOK_TEXT_P_STYLE_NAME
:
1947 sStyleName
= rValue
;
1949 case XML_TOK_TEXT_P_CLASS_NAMES
:
1950 sClassNames
= rValue
;
1952 case XML_TOK_TEXT_P_COND_STYLE_NAME
:
1953 aCondStyleName
= rValue
;
1955 case XML_TOK_TEXT_P_LEVEL
:
1957 sal_Int32 nTmp
= rValue
.toInt32();
1962 nOutlineLevel
= (sal_Int8
)nTmp
;
1964 // --> OD 2007-07-25 #i73509#
1965 mbOutlineLevelAttrFound
= sal_True
;
1969 case XML_TOK_TEXT_P_IS_LIST_HEADER
:
1972 if( SvXMLUnitConverter::convertBool( bBool
, rValue
) )
1974 bIsListHeader
= bBool
;
1978 case XML_TOK_TEXT_P_ID
:
1981 case XML_TOK_TEXT_P_RESTART_NUMBERING
:
1984 if (SvXMLUnitConverter::convertBool(bBool
, rValue
))
1990 case XML_TOK_TEXT_P_START_VALUE
:
1992 nStartValue
= sal::static_int_cast
< sal_Int16
>(
1998 m_sClassNames
= sClassNames
;
1999 if( aCondStyleName
.getLength() )
2000 m_sStyleName
= aCondStyleName
;
2002 m_sStyleName
= sStyleName
;
2004 if (m_sStyleName
.getLength()==0 && sClassNames
.getLength()>0) {
2005 // so when we only have class names make sure the first styles
2006 // of the class names is the style name
2007 sal_Int32 nDummy
= 0;
2008 m_sStyleName
= m_sClassNames
.getToken( 0, ' ', nDummy
);
2009 m_sClassNames
= m_sClassNames
.copy(m_sStyleName
.getLength()+1);
2013 XMLParaContext::~XMLParaContext()
2015 rtl::OUString sStyleName
= m_sStyleName
;
2016 UniReference
< XMLTextImportHelper
> xTxtImport(
2017 GetImport().GetTextImport());
2018 Reference
< XTextRange
> xCrsrRange( xTxtImport
->GetCursorAsRange() );
2019 if( !xCrsrRange
.is() )
2020 return; // Robust (defect file)
2021 Reference
< XTextRange
> xEnd(xCrsrRange
->getStart());
2023 // if we have an id set for this paragraph, get a cursor for this
2024 // paragraph and register it with the given identifier
2025 if( sId
.getLength() )
2027 Reference
< XTextCursor
> xIdCursor( xTxtImport
->GetText()->createTextCursorByRange( xStart
) );
2028 if( xIdCursor
.is() )
2030 xIdCursor
->gotoRange( xEnd
, sal_True
);
2031 Reference
< XInterface
> xRef( xIdCursor
, UNO_QUERY
);
2032 GetImport().getInterfaceToIdentifierMapper().registerReference( sId
, xRef
);
2036 // insert a paragraph break
2037 xTxtImport
->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH
);
2039 // create a cursor that select the whole last paragraph
2040 Reference
< XTextCursor
> xAttrCursor(
2041 xTxtImport
->GetText()->createTextCursorByRange( xStart
));
2042 if( !xAttrCursor
.is() )
2043 return; // Robust (defect file)
2044 xAttrCursor
->gotoRange( xEnd
, sal_True
);
2046 // xml:id for RDF metadata
2047 if (m_sXmlId
.getLength() || m_bHaveAbout
|| m_sProperty
.getLength())
2050 const uno::Reference
<container::XEnumerationAccess
> xEA
2051 (xAttrCursor
, uno::UNO_QUERY_THROW
);
2052 const uno::Reference
<container::XEnumeration
> xEnum(
2053 xEA
->createEnumeration(), uno::UNO_QUERY_THROW
);
2054 OSL_ENSURE(xEnum
->hasMoreElements(), "xml:id: no paragraph?");
2055 if (xEnum
->hasMoreElements()) {
2056 uno::Reference
<rdf::XMetadatable
> xMeta
;
2057 xEnum
->nextElement() >>= xMeta
;
2058 OSL_ENSURE(xMeta
.is(), "xml:id: not XMetadatable");
2059 GetImport().SetXmlId(xMeta
, m_sXmlId
);
2062 GetImport().AddRDFa(xMeta
,
2063 m_sAbout
, m_sProperty
, m_sContent
, m_sDatatype
);
2065 OSL_ENSURE(!xEnum
->hasMoreElements(), "xml:id: > 1 paragraph?");
2067 } catch (uno::Exception
&) {
2068 OSL_TRACE("XMLParaContext::~XMLParaContext: exception");
2072 OUString sCellParaStyleName
= xTxtImport
->sCellParaStyleDefault
;
2073 if( sCellParaStyleName
.getLength() > 0 )
2075 // --> OD 2007-08-16 #i80724#
2076 // suppress handling of outline and list attributes,
2077 // because of side effects of method <SetStyleAndAttrs(..)>
2078 xTxtImport
->SetStyleAndAttrs( GetImport(), xAttrCursor
,
2082 sal_False
, -1, // suppress outline handling
2083 sal_False
); // suppress list attributes handling
2087 // #103445# for headings without style name, find the proper style
2088 if( bHeading
&& (sStyleName
.getLength() == 0) )
2089 xTxtImport
->FindOutlineStyleName( sStyleName
, nOutlineLevel
);
2091 // set style and hard attributes at the previous paragraph
2092 // --> OD 2007-07-25 #i73509# - add paramter <mbOutlineLevelAttrFound>
2093 sStyleName
= xTxtImport
->SetStyleAndAttrs( GetImport(), xAttrCursor
,
2097 mbOutlineLevelAttrFound
,
2098 bHeading
? nOutlineLevel
: -1 );
2101 // handle list style header
2102 if (bHeading
&& (bIsListHeader
|| bIsRestart
))
2104 Reference
<XPropertySet
> xPropSet( xAttrCursor
, UNO_QUERY
);
2110 OUString sNumberingIsNumber
2111 (RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber"));
2112 if(xPropSet
->getPropertySetInfo()->
2113 hasPropertyByName(sNumberingIsNumber
))
2115 xPropSet
->setPropertyValue
2116 (sNumberingIsNumber
, makeAny( false ) );
2121 OUString sParaIsNumberingRestart
2122 (RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart"));
2123 OUString sNumberingStartValue
2124 (RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue"));
2125 if (xPropSet
->getPropertySetInfo()->
2126 hasPropertyByName(sParaIsNumberingRestart
))
2128 xPropSet
->setPropertyValue
2129 (sParaIsNumberingRestart
, makeAny(true));
2132 if (xPropSet
->getPropertySetInfo()->
2133 hasPropertyByName(sNumberingStartValue
))
2135 xPropSet
->setPropertyValue
2136 (sNumberingStartValue
, makeAny(nStartValue
));
2143 if( pHints
&& pHints
->Count() )
2145 for( sal_uInt16 i
=0; i
<pHints
->Count(); i
++ )
2147 XMLHint_Impl
*pHint
= (*pHints
)[i
];
2148 xAttrCursor
->gotoRange( pHint
->GetStart(), sal_False
);
2149 xAttrCursor
->gotoRange( pHint
->GetEnd(), sal_True
);
2150 switch( pHint
->GetType() )
2152 case XML_HINT_STYLE
:
2154 const OUString
& rStyleName
=
2155 ((XMLStyleHint_Impl
*)pHint
)->GetStyleName();
2156 if( rStyleName
.getLength() )
2157 xTxtImport
->SetStyleAndAttrs( GetImport(),
2158 xAttrCursor
, rStyleName
, OUString(),
2162 case XML_HINT_REFERENCE
:
2164 const OUString
& rRefName
=
2165 ((XMLReferenceHint_Impl
*)pHint
)->GetRefName();
2166 if( rRefName
.getLength() )
2168 if( !pHint
->GetEnd().is() )
2169 pHint
->SetEnd(xEnd
);
2171 // convert XCursor to XTextRange
2172 Reference
<XTextRange
> xRange(xAttrCursor
, UNO_QUERY
);
2174 // reference name uses rStyleName member
2175 // borrow from XMLTextMarkImportContext
2176 XMLTextMarkImportContext::CreateAndInsertMark(
2179 RTL_CONSTASCII_USTRINGPARAM(
2180 "com.sun.star.text.ReferenceMark")),
2186 case XML_HINT_HYPERLINK
:
2188 const XMLHyperlinkHint_Impl
*pHHint
=
2189 (const XMLHyperlinkHint_Impl
*)pHint
;
2190 xTxtImport
->SetHyperlink( GetImport(),
2194 pHHint
->GetTargetFrameName(),
2195 pHHint
->GetStyleName(),
2196 pHHint
->GetVisitedStyleName(),
2197 pHHint
->GetEventsContext() );
2202 const XMLRubyHint_Impl
*pRHint
=
2203 (const XMLRubyHint_Impl
*)pHint
;
2204 xTxtImport
->SetRuby( GetImport(),
2206 pRHint
->GetStyleName(),
2207 pRHint
->GetTextStyleName(),
2208 pRHint
->GetText() );
2211 case XML_HINT_INDEX_MARK
:
2213 Reference
<beans::XPropertySet
> xMark(
2214 ((const XMLIndexMarkHint_Impl
*)pHint
)->GetMark());
2215 Reference
<XTextContent
> xContent(xMark
, UNO_QUERY
);
2216 Reference
<XTextRange
> xRange(xAttrCursor
, UNO_QUERY
);
2217 xTxtImport
->GetText()->insertTextContent(
2218 xRange
, xContent
, sal_True
);
2221 case XML_HINT_TEXT_FRAME
:
2223 const XMLTextFrameHint_Impl
*pFHint
=
2224 (const XMLTextFrameHint_Impl
*)pHint
;
2225 // --> OD 2004-08-24 #i33242# - check for text content
2226 Reference
< XTextContent
> xTextContent
=
2227 pFHint
->GetTextContent();
2228 if ( xTextContent
.is() )
2230 // OD 2004-04-20 #i26791#
2231 Reference
<XTextRange
> xRange(xAttrCursor
, UNO_QUERY
);
2232 if ( pFHint
->IsBoundAtChar() )
2234 xTextContent
->attach( xRange
);
2238 // --> OD 2004-08-24 #i33242# - consider, that hint can
2239 // also contain a shape - e.g. drawing object of type 'Text'.
2242 Reference
< XShape
> xShape
= pFHint
->GetShape();
2245 // determine anchor type
2246 Reference
< XPropertySet
> xPropSet( xShape
, UNO_QUERY
);
2247 TextContentAnchorType eAnchorType
=
2248 TextContentAnchorType_AT_PARAGRAPH
;
2250 OUString
sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2251 Any aAny
= xPropSet
->getPropertyValue( sAnchorType
);
2252 aAny
>>= eAnchorType
;
2254 if ( TextContentAnchorType_AT_CHARACTER
== eAnchorType
)
2256 // set anchor position for at-character anchored objects
2257 Reference
<XTextRange
> xRange(xAttrCursor
, UNO_QUERY
);
2260 OUString
sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) );
2261 xPropSet
->setPropertyValue(sTextRange
, aPos
);
2268 // --> DVO, OD 2004-07-14 #i26791#
2271 const XMLDrawHint_Impl
*pDHint
=
2272 static_cast<const XMLDrawHint_Impl
*>(pHint
);
2273 // --> OD 2004-08-24 #i33242# - improvement: hint directly
2274 // provides the shape.
2275 Reference
< XShape
> xShape
= pDHint
->GetShape();
2278 // determine anchor type
2279 Reference
< XPropertySet
> xPropSet( xShape
, UNO_QUERY
);
2280 TextContentAnchorType eAnchorType
= TextContentAnchorType_AT_PARAGRAPH
;
2282 OUString
sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2283 Any aAny
= xPropSet
->getPropertyValue( sAnchorType
);
2284 aAny
>>= eAnchorType
;
2286 if ( TextContentAnchorType_AT_CHARACTER
== eAnchorType
)
2288 // set anchor position for at-character anchored objects
2289 Reference
<XTextRange
> xRange(xAttrCursor
, UNO_QUERY
);
2292 OUString
sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) );
2293 xPropSet
->setPropertyValue(sTextRange
, aPos
);
2302 DBG_ASSERT( !this, "What's this" );
2310 SvXMLImportContext
*XMLParaContext::CreateChildContext(
2311 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
2312 const Reference
< xml::sax::XAttributeList
> & xAttrList
)
2314 const SvXMLTokenMap
& rTokenMap
=
2315 GetImport().GetTextImport()->GetTextPElemTokenMap();
2316 sal_uInt16 nToken
= rTokenMap
.Get( nPrefix
, rLocalName
);
2318 pHints
= new XMLHints_Impl
;
2319 return XMLImpSpanContext_Impl::CreateChildContext(
2320 GetImport(), nPrefix
, rLocalName
, xAttrList
,
2321 nToken
, *pHints
, bIgnoreLeadingSpace
2322 , nStarFontsConvFlags
2326 void XMLParaContext::Characters( const OUString
& rChars
)
2329 GetImport().GetTextImport()->ConvertStarFonts( rChars
, m_sStyleName
,
2330 nStarFontsConvFlags
,
2331 sal_True
, GetImport() );
2332 GetImport().GetTextImport()->InsertString( sChars
, bIgnoreLeadingSpace
);
2337 TYPEINIT1( XMLNumberedParaContext
, SvXMLImportContext
);
2339 XMLNumberedParaContext::XMLNumberedParaContext(
2340 SvXMLImport
& i_rImport
,
2341 sal_uInt16 i_nPrefix
,
2342 const OUString
& i_rLocalName
,
2343 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
) :
2344 SvXMLImportContext( i_rImport
, i_nPrefix
, i_rLocalName
),
2350 ::rtl::OUString StyleName
;
2351 bool ContinuteNumbering(false);
2353 const SvXMLTokenMap
& rTokenMap(
2354 i_rImport
.GetTextImport()->GetTextNumberedParagraphAttrTokenMap() );
2356 const sal_Int16
nAttrCount( i_xAttrList
.is() ?
2357 i_xAttrList
->getLength() : 0 );
2358 for ( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
2360 const ::rtl::OUString
& rAttrName( i_xAttrList
->getNameByIndex( i
) );
2361 const ::rtl::OUString
& rValue ( i_xAttrList
->getValueByIndex( i
) );
2363 ::rtl::OUString aLocalName
;
2364 const sal_uInt16
nPrefix(
2365 GetImport().GetNamespaceMap().GetKeyByAttrName(
2366 rAttrName
, &aLocalName
) );
2367 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
2369 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_XMLID
:
2371 //FIXME: there is no UNO API for lists
2373 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LIST_ID
:
2376 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LEVEL
:
2378 sal_Int32 nTmp
= rValue
.toInt32();
2379 if ( nTmp
>= 1 && nTmp
<= SHRT_MAX
) {
2380 m_Level
= static_cast<sal_uInt16
>(nTmp
) - 1;
2384 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_STYLE_NAME
:
2387 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_CONTINUE_NUMBERING
:
2388 ContinuteNumbering
= IsXMLToken(rValue
, XML_TRUE
);
2389 // ??? what in Fred's name is this supposed to do?
2391 case XML_TOK_TEXT_NUMBERED_PARAGRAPH_START_VALUE
:
2393 sal_Int32 nTmp
= rValue
.toInt32();
2394 if ( nTmp
>= 0 && nTmp
<= SHRT_MAX
) {
2395 m_StartValue
= static_cast<sal_Int16
>(nTmp
);
2402 XMLTextListsHelper
& rTextListsHelper(
2403 i_rImport
.GetTextImport()->GetTextListHelper() );
2404 if (!m_ListId
.getLength()) {
2405 OSL_ENSURE( ! i_rImport
.GetODFVersion().equalsAsciiL(
2406 RTL_CONSTASCII_STRINGPARAM("1.2") ),
2407 "invalid numbered-paragraph: no list-id (1.2)");
2408 m_ListId
= rTextListsHelper
.GetNumberedParagraphListId(m_Level
,
2410 OSL_ENSURE(m_ListId
.getLength(), "numbered-paragraph: no ListId");
2411 if (!m_ListId
.getLength()) {
2415 m_xNumRules
= rTextListsHelper
.EnsureNumberedParagraph( i_rImport
,
2416 m_ListId
, m_Level
, StyleName
);
2418 OSL_ENSURE(m_xNumRules
.is(), "numbered-paragraph: no NumRules");
2420 i_rImport
.GetTextImport()->GetTextListHelper().PushListContext( this );
2423 XMLNumberedParaContext::~XMLNumberedParaContext()
2427 void XMLNumberedParaContext::EndElement()
2429 if (m_ListId
.getLength()) {
2430 GetImport().GetTextImport()->PopListContext();
2434 SvXMLImportContext
*XMLNumberedParaContext::CreateChildContext(
2435 sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
,
2436 const Reference
< xml::sax::XAttributeList
> & i_xAttrList
)
2438 SvXMLImportContext
*pContext( 0 );
2440 if ( XML_NAMESPACE_TEXT
== i_nPrefix
)
2442 bool bIsHeader( IsXMLToken( i_rLocalName
, XML_H
) );
2443 if ( bIsHeader
|| IsXMLToken( i_rLocalName
, XML_P
) )
2445 pContext
= new XMLParaContext( GetImport(),
2446 i_nPrefix
, i_rLocalName
, i_xAttrList
, bIsHeader
);
2447 // ignore text:number } else if (IsXMLToken( i_rLocalName, XML_NUMBER )) {
2452 pContext
= SvXMLImportContext::CreateChildContext(
2453 i_nPrefix
, i_rLocalName
, i_xAttrList
);