xref: /aoo4110/main/xmloff/source/text/txtparai.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "unointerfacetouniqueidentifiermapper.hxx"
27 #include <rtl/ustring.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <tools/debug.hxx>
30 
31 #include <tools/string.hxx>
32 #include <svl/svarray.hxx>
33 #include <com/sun/star/text/XTextFrame.hpp>
34 #include <com/sun/star/text/XTextCursor.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/beans/XPropertySetInfo.hpp>
37 #include <com/sun/star/text/ControlCharacter.hpp>
38 #include <com/sun/star/container/XIndexReplace.hpp>
39 #include <com/sun/star/drawing/XShapes.hpp>
40 #include <com/sun/star/container/XEnumerationAccess.hpp>
41 #include <com/sun/star/rdf/XMetadatable.hpp>
42 
43 
44 #include <xmloff/xmlictxt.hxx>
45 #include <xmloff/xmlimp.hxx>
46 #include <xmloff/xmltoken.hxx>
47 #include <xmloff/nmspmap.hxx>
48 #include "xmloff/xmlnmspe.hxx"
49 #include <xmloff/txtimp.hxx>
50 #include "txtparai.hxx"
51 #include "txtfldi.hxx"
52 #include <xmloff/xmluconv.hxx>
53 #include "XMLFootnoteImportContext.hxx"
54 #include "XMLTextMarkImportContext.hxx"
55 #include "XMLTextFrameContext.hxx"
56 #include <xmloff/XMLCharContext.hxx>
57 #include "XMLTextFrameHyperlinkContext.hxx"
58 #include <xmloff/XMLEventsImportContext.hxx>
59 #include "XMLChangeImportContext.hxx"
60 #include "txtlists.hxx"
61 
62 
63 // OD 2004-04-21 #i26791#
64 #include <txtparaimphint.hxx>
65 typedef XMLHint_Impl *XMLHint_ImplPtr;
66 SV_DECL_PTRARR_DEL( XMLHints_Impl, XMLHint_ImplPtr, 5, 5 )
67 SV_IMPL_PTRARR( XMLHints_Impl, XMLHint_ImplPtr )
68 // OD 2004-04-21 #i26791#
69 #include <com/sun/star/beans/XPropertySet.hpp>
70 
71 using ::rtl::OUString;
72 using ::rtl::OUStringBuffer;
73 
74 using namespace ::com::sun::star;
75 using namespace ::com::sun::star::uno;
76 using namespace ::com::sun::star::text;
77 using namespace ::com::sun::star::drawing;
78 using namespace ::com::sun::star::beans;
79 using namespace ::xmloff::token;
80 using ::com::sun::star::container::XEnumerationAccess;
81 using ::com::sun::star::container::XEnumeration;
82 
83 
84 TYPEINIT1( XMLCharContext, SvXMLImportContext );
85 
XMLCharContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList,sal_Unicode c,sal_Bool bCount)86 XMLCharContext::XMLCharContext(
87 		SvXMLImport& rImport,
88 		sal_uInt16 nPrfx,
89 		const OUString& rLName,
90 		const Reference< xml::sax::XAttributeList > & xAttrList,
91 		sal_Unicode c,
92 		sal_Bool bCount ) :
93 	SvXMLImportContext( rImport, nPrfx, rLName )
94     ,m_nControl(0)
95     ,m_nCount(1)
96     ,m_c(c)
97 {
98 	if( bCount )
99 	{
100         const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
101 		sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
102 		for( sal_Int16 i=0; i < nAttrCount; i++ )
103 		{
104 			const OUString& rAttrName = xAttrList->getNameByIndex( i );
105 
106 			OUString aLocalName;
107 			sal_uInt16 nPrefix =rMap.GetKeyByAttrName( rAttrName,&aLocalName );
108 			if( XML_NAMESPACE_TEXT == nPrefix &&
109 				IsXMLToken( aLocalName, XML_C ) )
110 			{
111 				sal_Int32 nTmp = xAttrList->getValueByIndex(i).toInt32();
112 				if( nTmp > 0L )
113 				{
114 					if( nTmp > USHRT_MAX )
115 						m_nCount = USHRT_MAX;
116 					else
117 						m_nCount = (sal_uInt16)nTmp;
118 				}
119 			}
120 		}
121 	}
122 }
123 
XMLCharContext(SvXMLImport & rImp,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> &,sal_Int16 nControl)124 XMLCharContext::XMLCharContext(
125 		SvXMLImport& rImp,
126 		sal_uInt16 nPrfx,
127 		const OUString& rLName,
128 		const Reference< xml::sax::XAttributeList > &,
129 		sal_Int16 nControl ) :
130 	SvXMLImportContext( rImp, nPrfx, rLName )
131     ,m_nControl(nControl)
132     ,m_nCount(0)
133 {
134 }
135 
~XMLCharContext()136 XMLCharContext::~XMLCharContext()
137 {
138 }
139 // -----------------------------------------------------------------------------
EndElement()140 void XMLCharContext::EndElement()
141 {
142     if ( !m_nCount )
143         InsertControlCharacter( m_nControl );
144     else
145     {
146         if( 1U == m_nCount )
147 	    {
148 		    OUString sBuff( &m_c, 1 );
149             InsertString(sBuff);
150 	    }
151 	    else
152 	    {
153 		    OUStringBuffer sBuff( m_nCount );
154 		    while( m_nCount-- )
155 			    sBuff.append( &m_c, 1 );
156 
157             InsertString(sBuff.makeStringAndClear() );
158 	    }
159     }
160 }
161 // -----------------------------------------------------------------------------
InsertControlCharacter(sal_Int16 _nControl)162 void XMLCharContext::InsertControlCharacter(sal_Int16   _nControl)
163 {
164     GetImport().GetTextImport()->InsertControlCharacter( _nControl );
165 }
InsertString(const::rtl::OUString & _sString)166 void XMLCharContext::InsertString(const ::rtl::OUString& _sString)
167 {
168     GetImport().GetTextImport()->InsertString( _sString );
169 }
170 
171 // ---------------------------------------------------------------------
172 
173 /** import start of reference (<text:reference-start>) */
174 class XMLStartReferenceContext_Impl : public SvXMLImportContext
175 {
176 public:
177 	TYPEINFO();
178 
179 	// Do everything in constructor. Well ...
180 	XMLStartReferenceContext_Impl (
181 		SvXMLImport& rImport,
182 		sal_uInt16 nPrefix,
183 		const OUString& rLocalName,
184 		XMLHints_Impl& rHnts,
185 		const Reference<xml::sax::XAttributeList> & xAttrList);
186 
187     static sal_Bool FindName(
188         SvXMLImport& rImport,
189         const Reference<xml::sax::XAttributeList> & xAttrList,
190         OUString& rName);
191 };
192 
193 TYPEINIT1( XMLStartReferenceContext_Impl, SvXMLImportContext );
194 
XMLStartReferenceContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,XMLHints_Impl & rHints,const Reference<xml::sax::XAttributeList> & xAttrList)195 XMLStartReferenceContext_Impl::XMLStartReferenceContext_Impl(
196 	SvXMLImport& rImport,
197 	sal_uInt16 nPrefix,
198 	const OUString& rLocalName,
199 	XMLHints_Impl& rHints,
200 	const Reference<xml::sax::XAttributeList> & xAttrList) :
201 		SvXMLImportContext(rImport, nPrefix, rLocalName)
202 {
203 	OUString sName;
204 
205     if (FindName(GetImport(), xAttrList, sName))
206 	{
207 		XMLHint_Impl* pHint = new XMLReferenceHint_Impl(
208 			sName, rImport.GetTextImport()->GetCursor()->getStart() );
209 
210 		// degenerates to point reference, if no end is found!
211 		pHint->SetEnd(rImport.GetTextImport()->GetCursor()->getStart() );
212 
213 		rHints.Insert(pHint, rHints.Count());
214 	}
215 }
216 
FindName(SvXMLImport & rImport,const Reference<xml::sax::XAttributeList> & xAttrList,OUString & rName)217 sal_Bool XMLStartReferenceContext_Impl::FindName(
218     SvXMLImport& rImport,
219     const Reference<xml::sax::XAttributeList> & xAttrList,
220     OUString& rName)
221 {
222     sal_Bool bNameOK( sal_False );
223 
224     // find name attribute first
225     const sal_Int16 nLength( xAttrList->getLength() );
226     for (sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
227     {
228         OUString sLocalName;
229         const sal_uInt16 nPrefix = rImport.GetNamespaceMap().
230             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
231                               &sLocalName );
232 
233         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
234              IsXMLToken(sLocalName, XML_NAME)   )
235         {
236             rName = xAttrList->getValueByIndex(nAttr);
237             bNameOK = sal_True;
238         }
239     }
240 
241     return bNameOK;
242 }
243 
244 // ---------------------------------------------------------------------
245 
246 /** import end of reference (<text:reference-end>) */
247 class XMLEndReferenceContext_Impl : public SvXMLImportContext
248 {
249 public:
250 	TYPEINFO();
251 
252 	// Do everything in constructor. Well ...
253 	XMLEndReferenceContext_Impl(
254 		SvXMLImport& rImport,
255 		sal_uInt16 nPrefix,
256 		const OUString& rLocalName,
257 		XMLHints_Impl& rHnts,
258 		const Reference<xml::sax::XAttributeList> & xAttrList);
259 };
260 
261 TYPEINIT1( XMLEndReferenceContext_Impl, SvXMLImportContext );
262 
XMLEndReferenceContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,XMLHints_Impl & rHints,const Reference<xml::sax::XAttributeList> & xAttrList)263 XMLEndReferenceContext_Impl::XMLEndReferenceContext_Impl(
264 	SvXMLImport& rImport,
265 	sal_uInt16 nPrefix,
266 	const OUString& rLocalName,
267 	XMLHints_Impl& rHints,
268 	const Reference<xml::sax::XAttributeList> & xAttrList) :
269 		SvXMLImportContext(rImport, nPrefix, rLocalName)
270 {
271 	OUString sName;
272 
273     // borrow from XMLStartReferenceContext_Impl
274     if (XMLStartReferenceContext_Impl::FindName(GetImport(), xAttrList, sName))
275 	{
276 		// search for reference start
277 		sal_uInt16 nCount = rHints.Count();
278 		for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
279 		{
280 			XMLHint_Impl *pHint = rHints[nPos];
281 			if ( pHint->IsReference() &&
282 				 sName.equals( ((XMLReferenceHint_Impl *)pHint)->GetRefName()) )
283 			{
284 				// set end and stop searching
285 				pHint->SetEnd(GetImport().GetTextImport()->
286 									 GetCursor()->getStart() );
287 				break;
288 			}
289 		}
290 		// else: no start (in this paragraph) -> ignore
291 	}
292 }
293 
294 // ---------------------------------------------------------------------
295 
296 class XMLImpSpanContext_Impl : public SvXMLImportContext
297 {
298 	const OUString sTextFrame;
299 
300 	XMLHints_Impl&	rHints;
301 	XMLStyleHint_Impl	*pHint;
302 
303 	sal_Bool&		rIgnoreLeadingSpace;
304 
305 	sal_uInt8				nStarFontsConvFlags;
306 
307 public:
308 
309 	TYPEINFO();
310 
311 	XMLImpSpanContext_Impl(
312 			SvXMLImport& rImport,
313 			sal_uInt16 nPrfx,
314 			const OUString& rLName,
315 			const Reference< xml::sax::XAttributeList > & xAttrList,
316 			XMLHints_Impl& rHnts,
317 			sal_Bool& rIgnLeadSpace
318 	,sal_uInt8				nSFConvFlags
319 						  );
320 
321 	virtual ~XMLImpSpanContext_Impl();
322 
323 	static SvXMLImportContext *CreateChildContext(
324 			SvXMLImport& rImport,
325 			sal_uInt16 nPrefix, const OUString& rLocalName,
326 			const Reference< xml::sax::XAttributeList > & xAttrList,
327 			sal_uInt16 nToken, XMLHints_Impl& rHnts,
328 			sal_Bool& rIgnLeadSpace
329 	,sal_uInt8				nStarFontsConvFlags = 0
330 			 );
331 	virtual SvXMLImportContext *CreateChildContext(
332 			sal_uInt16 nPrefix, const OUString& rLocalName,
333 			const Reference< xml::sax::XAttributeList > & xAttrList );
334 
335 	virtual void Characters( const OUString& rChars );
336 };
337 // ---------------------------------------------------------------------
338 
339 class XMLImpHyperlinkContext_Impl : public SvXMLImportContext
340 {
341 	XMLHints_Impl&	mrHints;
342 	XMLHyperlinkHint_Impl	*mpHint;
343 
344 	sal_Bool&		mrbIgnoreLeadingSpace;
345 
346 public:
347 
348 	TYPEINFO();
349 
350 	XMLImpHyperlinkContext_Impl(
351 			SvXMLImport& rImport,
352 			sal_uInt16 nPrfx,
353 			const OUString& rLName,
354 			const Reference< xml::sax::XAttributeList > & xAttrList,
355 			XMLHints_Impl& rHnts,
356 			sal_Bool& rIgnLeadSpace );
357 
358 	virtual ~XMLImpHyperlinkContext_Impl();
359 
360 	virtual SvXMLImportContext *CreateChildContext(
361 			sal_uInt16 nPrefix, const OUString& rLocalName,
362 			const Reference< xml::sax::XAttributeList > & xAttrList );
363 
364 	virtual void Characters( const OUString& rChars );
365 };
366 
367 TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext );
368 
XMLImpHyperlinkContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList,XMLHints_Impl & rHnts,sal_Bool & rIgnLeadSpace)369 XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
370     SvXMLImport& rImport,
371     sal_uInt16 nPrfx,
372     const OUString& rLName,
373     const Reference< xml::sax::XAttributeList > & xAttrList,
374     XMLHints_Impl& rHnts,
375     sal_Bool& rIgnLeadSpace )
376     : SvXMLImportContext( rImport, nPrfx, rLName )
377     , mrHints( rHnts )
378     , mpHint( new XMLHyperlinkHint_Impl( GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) )
379     , mrbIgnoreLeadingSpace( rIgnLeadSpace )
380 {
381     OUString sShow;
382     const SvXMLTokenMap& rTokenMap = GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
383 
384     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
385     for ( sal_Int16 i = 0; i < nAttrCount; i++ )
386     {
387         const OUString& rAttrName = xAttrList->getNameByIndex( i );
388         const OUString& rValue = xAttrList->getValueByIndex( i );
389 
390         OUString aLocalName;
391         const sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
392         switch (rTokenMap.Get( nPrefix, aLocalName ))
393         {
394         case XML_TOK_TEXT_HYPERLINK_HREF:
395             mpHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
396             break;
397         case XML_TOK_TEXT_HYPERLINK_NAME:
398             mpHint->SetName( rValue );
399             break;
400         case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
401             mpHint->SetTargetFrameName( rValue );
402             break;
403         case XML_TOK_TEXT_HYPERLINK_SHOW:
404             sShow = rValue;
405             break;
406         case XML_TOK_TEXT_HYPERLINK_STYLE_NAME:
407             mpHint->SetStyleName( rValue );
408             break;
409         case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME:
410             mpHint->SetVisitedStyleName( rValue );
411             break;
412         }
413     }
414 
415 	if( sShow.getLength() && !mpHint->GetTargetFrameName().getLength() )
416 	{
417 		if( IsXMLToken( sShow, XML_NEW ) )
418 			mpHint->SetTargetFrameName(
419 					OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ) );
420 		else if( IsXMLToken( sShow, XML_REPLACE ) )
421 			mpHint->SetTargetFrameName(
422 					OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ) );
423 	}
424 
425     if ( mpHint->GetHRef().isEmpty() )
426     {
427         // hyperlink without an URL is not imported.
428         delete mpHint;
429         mpHint = NULL;
430     }
431     else
432     {
433         mrHints.Insert( mpHint, mrHints.Count() );
434     }
435 }
436 
~XMLImpHyperlinkContext_Impl()437 XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
438 {
439 	if( mpHint != NULL )
440 		mpHint->SetEnd( GetImport().GetTextImport()
441 							->GetCursorAsRange()->getStart() );
442 }
443 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)444 SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
445 		sal_uInt16 nPrefix, const OUString& rLocalName,
446 		const Reference< xml::sax::XAttributeList > & xAttrList )
447 {
448 	if ( (nPrefix == XML_NAMESPACE_OFFICE) &&
449 		 IsXMLToken(rLocalName, XML_EVENT_LISTENERS) )
450 	{
451 		XMLEventsImportContext* pCtxt = new XMLEventsImportContext(
452 			GetImport(), nPrefix, rLocalName);
453 		mpHint->SetEventsContext(pCtxt);
454 		return pCtxt;
455 	}
456 	else
457 	{
458 		const SvXMLTokenMap& rTokenMap =
459 			GetImport().GetTextImport()->GetTextPElemTokenMap();
460 		sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
461 
462 		return XMLImpSpanContext_Impl::CreateChildContext(
463 			GetImport(), nPrefix, rLocalName, xAttrList,
464 			nToken, mrHints, mrbIgnoreLeadingSpace );
465 	}
466 }
467 
Characters(const OUString & rChars)468 void XMLImpHyperlinkContext_Impl::Characters( const OUString& rChars )
469 {
470 	GetImport().GetTextImport()->InsertString( rChars, mrbIgnoreLeadingSpace );
471 }
472 
473 // ---------------------------------------------------------------------
474 
475 class XMLImpRubyBaseContext_Impl : public SvXMLImportContext
476 {
477 	XMLHints_Impl&	rHints;
478 
479 	sal_Bool&		rIgnoreLeadingSpace;
480 
481 public:
482 
483 	TYPEINFO();
484 
485 	XMLImpRubyBaseContext_Impl(
486 			SvXMLImport& rImport,
487 			sal_uInt16 nPrfx,
488 			const OUString& rLName,
489 			const Reference< xml::sax::XAttributeList > & xAttrList,
490 			XMLHints_Impl& rHnts,
491 			sal_Bool& rIgnLeadSpace );
492 
493 	virtual ~XMLImpRubyBaseContext_Impl();
494 
495 	virtual SvXMLImportContext *CreateChildContext(
496 			sal_uInt16 nPrefix, const OUString& rLocalName,
497 			const Reference< xml::sax::XAttributeList > & xAttrList );
498 
499 	virtual void Characters( const OUString& rChars );
500 };
501 
502 TYPEINIT1( XMLImpRubyBaseContext_Impl, SvXMLImportContext );
503 
XMLImpRubyBaseContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> &,XMLHints_Impl & rHnts,sal_Bool & rIgnLeadSpace)504 XMLImpRubyBaseContext_Impl::XMLImpRubyBaseContext_Impl(
505 		SvXMLImport& rImport,
506 		sal_uInt16 nPrfx,
507 		const OUString& rLName,
508 		const Reference< xml::sax::XAttributeList > &,
509 		XMLHints_Impl& rHnts,
510 		sal_Bool& rIgnLeadSpace ) :
511 	SvXMLImportContext( rImport, nPrfx, rLName ),
512 	rHints( rHnts ),
513 	rIgnoreLeadingSpace( rIgnLeadSpace )
514 {
515 }
516 
~XMLImpRubyBaseContext_Impl()517 XMLImpRubyBaseContext_Impl::~XMLImpRubyBaseContext_Impl()
518 {
519 }
520 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)521 SvXMLImportContext *XMLImpRubyBaseContext_Impl::CreateChildContext(
522 		sal_uInt16 nPrefix, const OUString& rLocalName,
523 		const Reference< xml::sax::XAttributeList > & xAttrList )
524 {
525 	const SvXMLTokenMap& rTokenMap =
526 		GetImport().GetTextImport()->GetTextPElemTokenMap();
527 	sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
528 
529 	return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), nPrefix,
530 													   rLocalName, xAttrList,
531 							   nToken, rHints, rIgnoreLeadingSpace );
532 }
533 
Characters(const OUString & rChars)534 void XMLImpRubyBaseContext_Impl::Characters( const OUString& rChars )
535 {
536 	GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
537 }
538 
539 // ---------------------------------------------------------------------
540 
541 class XMLImpRubyContext_Impl : public SvXMLImportContext
542 {
543     XMLHints_Impl&  rHints;
544 
545     sal_Bool&       rIgnoreLeadingSpace;
546 
547     Reference < XTextRange > m_xStart;
548     OUString        m_sStyleName;
549     OUString        m_sTextStyleName;
550     OUString        m_sText;
551 
552 public:
553 
554     TYPEINFO();
555 
556     XMLImpRubyContext_Impl(
557             SvXMLImport& rImport,
558             sal_uInt16 nPrfx,
559             const OUString& rLName,
560             const Reference< xml::sax::XAttributeList > & xAttrList,
561             XMLHints_Impl& rHnts,
562             sal_Bool& rIgnLeadSpace );
563 
564     virtual ~XMLImpRubyContext_Impl();
565 
566     virtual SvXMLImportContext *CreateChildContext(
567             sal_uInt16 nPrefix, const OUString& rLocalName,
568             const Reference< xml::sax::XAttributeList > & xAttrList );
569 
SetTextStyleName(const OUString & s)570     void SetTextStyleName( const OUString& s ) { m_sTextStyleName = s; }
AppendText(const OUString & s)571     void AppendText( const OUString& s ) { m_sText += s; }
572 };
573 
574 // ---------------------------------------------------------------------
575 
576 class XMLImpRubyTextContext_Impl : public SvXMLImportContext
577 {
578     XMLImpRubyContext_Impl & m_rRubyContext;
579 
580 public:
581 
582 	TYPEINFO();
583 
584 	XMLImpRubyTextContext_Impl(
585 			SvXMLImport& rImport,
586 			sal_uInt16 nPrfx,
587 			const OUString& rLName,
588 			const Reference< xml::sax::XAttributeList > & xAttrList,
589             XMLImpRubyContext_Impl & rParent );
590 
591 	virtual ~XMLImpRubyTextContext_Impl();
592 
593 	virtual void Characters( const OUString& rChars );
594 };
595 
596 TYPEINIT1( XMLImpRubyTextContext_Impl, SvXMLImportContext );
597 
XMLImpRubyTextContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList,XMLImpRubyContext_Impl & rParent)598 XMLImpRubyTextContext_Impl::XMLImpRubyTextContext_Impl(
599 		SvXMLImport& rImport,
600 		sal_uInt16 nPrfx,
601 		const OUString& rLName,
602 		const Reference< xml::sax::XAttributeList > & xAttrList,
603         XMLImpRubyContext_Impl & rParent )
604     : SvXMLImportContext( rImport, nPrfx, rLName )
605 	, m_rRubyContext( rParent )
606 {
607 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
608 	for( sal_Int16 i=0; i < nAttrCount; i++ )
609 	{
610 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
611 		const OUString& rValue = xAttrList->getValueByIndex( i );
612 
613 		OUString aLocalName;
614 		sal_uInt16 nPrefix =
615 			GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
616 															&aLocalName );
617 		if( XML_NAMESPACE_TEXT == nPrefix &&
618 			IsXMLToken( aLocalName, XML_STYLE_NAME ) )
619 		{
620             m_rRubyContext.SetTextStyleName( rValue );
621 			break;
622 		}
623 	}
624 }
625 
~XMLImpRubyTextContext_Impl()626 XMLImpRubyTextContext_Impl::~XMLImpRubyTextContext_Impl()
627 {
628 }
629 
Characters(const OUString & rChars)630 void XMLImpRubyTextContext_Impl::Characters( const OUString& rChars )
631 {
632     m_rRubyContext.AppendText( rChars );
633 }
634 
635 // ---------------------------------------------------------------------
636 
637 TYPEINIT1( XMLImpRubyContext_Impl, SvXMLImportContext );
638 
XMLImpRubyContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList,XMLHints_Impl & rHnts,sal_Bool & rIgnLeadSpace)639 XMLImpRubyContext_Impl::XMLImpRubyContext_Impl(
640 		SvXMLImport& rImport,
641 		sal_uInt16 nPrfx,
642 		const OUString& rLName,
643 		const Reference< xml::sax::XAttributeList > & xAttrList,
644 		XMLHints_Impl& rHnts,
645 		sal_Bool& rIgnLeadSpace ) :
646 	SvXMLImportContext( rImport, nPrfx, rLName ),
647 	rHints( rHnts ),
648 	rIgnoreLeadingSpace( rIgnLeadSpace )
649     , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
650 {
651 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
652 	for( sal_Int16 i=0; i < nAttrCount; i++ )
653 	{
654 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
655 		const OUString& rValue = xAttrList->getValueByIndex( i );
656 
657 		OUString aLocalName;
658 		sal_uInt16 nPrefix =
659 			GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
660 															&aLocalName );
661 		if( XML_NAMESPACE_TEXT == nPrefix &&
662 			IsXMLToken( aLocalName, XML_STYLE_NAME ) )
663 		{
664 			m_sStyleName = rValue;
665 			break;
666 		}
667 	}
668 }
669 
~XMLImpRubyContext_Impl()670 XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl()
671 {
672 	const UniReference < XMLTextImportHelper > xTextImport(
673 		GetImport().GetTextImport());
674 	const Reference < XTextCursor > xAttrCursor(
675 		xTextImport->GetText()->createTextCursorByRange( m_xStart ));
676     xAttrCursor->gotoRange(xTextImport->GetCursorAsRange()->getStart(),
677             sal_True);
678     xTextImport->SetRuby( GetImport(), xAttrCursor,
679          m_sStyleName, m_sTextStyleName, m_sText );
680 }
681 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)682 SvXMLImportContext *XMLImpRubyContext_Impl::CreateChildContext(
683 		sal_uInt16 nPrefix, const OUString& rLocalName,
684 		const Reference< xml::sax::XAttributeList > & xAttrList )
685 {
686 	SvXMLImportContext *pContext;
687 	if( XML_NAMESPACE_TEXT == nPrefix )
688 	{
689 		if( IsXMLToken( rLocalName, XML_RUBY_BASE ) )
690 			pContext = new XMLImpRubyBaseContext_Impl( GetImport(), nPrefix,
691 													   rLocalName,
692 													   xAttrList,
693 													   rHints,
694 													   rIgnoreLeadingSpace );
695 		else if( IsXMLToken( rLocalName, XML_RUBY_TEXT ) )
696 			pContext = new XMLImpRubyTextContext_Impl( GetImport(), nPrefix,
697 													   rLocalName,
698 													   xAttrList,
699 													   *this );
700 		else
701             pContext = new SvXMLImportContext(
702                 GetImport(), nPrefix, rLocalName );
703 	}
704 	else
705 		pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName,
706 															xAttrList );
707 
708 	return pContext;
709 }
710 
711 // ---------------------------------------------------------------------
712 
713 /** for text:meta and text:meta-field
714  */
715 class XMLMetaImportContextBase : public SvXMLImportContext
716 {
717     XMLHints_Impl&    m_rHints;
718 
719     sal_Bool& m_rIgnoreLeadingSpace;
720 
721     /// start position
722     Reference<XTextRange> m_xStart;
723 
724 protected:
725     OUString m_XmlId;
726 
727 public:
728     TYPEINFO();
729 
730     XMLMetaImportContextBase(
731         SvXMLImport& i_rImport,
732         const sal_uInt16 i_nPrefix,
733         const OUString& i_rLocalName,
734         XMLHints_Impl& i_rHints,
735         sal_Bool & i_rIgnoreLeadingSpace );
736 
737     virtual ~XMLMetaImportContextBase();
738 
739 	virtual void StartElement(
740             const Reference<xml::sax::XAttributeList> & i_xAttrList);
741 
742     virtual void EndElement();
743 
744     virtual SvXMLImportContext *CreateChildContext(
745             sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
746             const Reference< xml::sax::XAttributeList > & i_xAttrList);
747 
748     virtual void Characters( const OUString& i_rChars );
749 
750     virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
751         OUString const & i_rLocalName, OUString const & i_rValue);
752 
753     virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange)
754         = 0;
755 };
756 
757 TYPEINIT1( XMLMetaImportContextBase, SvXMLImportContext );
758 
XMLMetaImportContextBase(SvXMLImport & i_rImport,const sal_uInt16 i_nPrefix,const OUString & i_rLocalName,XMLHints_Impl & i_rHints,sal_Bool & i_rIgnoreLeadingSpace)759 XMLMetaImportContextBase::XMLMetaImportContextBase(
760         SvXMLImport& i_rImport,
761         const sal_uInt16 i_nPrefix,
762         const OUString& i_rLocalName,
763         XMLHints_Impl& i_rHints,
764         sal_Bool & i_rIgnoreLeadingSpace )
765     : SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName )
766     , m_rHints( i_rHints )
767     , m_rIgnoreLeadingSpace( i_rIgnoreLeadingSpace )
768     , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
769 {
770 }
771 
~XMLMetaImportContextBase()772 XMLMetaImportContextBase::~XMLMetaImportContextBase()
773 {
774 }
775 
StartElement(const Reference<xml::sax::XAttributeList> & i_xAttrList)776 void XMLMetaImportContextBase::StartElement(
777         const Reference<xml::sax::XAttributeList> & i_xAttrList)
778 {
779     const sal_Int16 nAttrCount(i_xAttrList.is() ? i_xAttrList->getLength() : 0);
780     for ( sal_Int16 i = 0; i < nAttrCount; ++i )
781     {
782         const OUString& rAttrName( i_xAttrList->getNameByIndex( i ) );
783         const OUString& rValue( i_xAttrList->getValueByIndex( i ) );
784 
785         OUString sLocalName;
786         const sal_uInt16 nPrefix(
787             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
788                                                             &sLocalName ));
789         ProcessAttribute(nPrefix, sLocalName, rValue);
790     }
791 }
792 
EndElement()793 void XMLMetaImportContextBase::EndElement()
794 {
795     OSL_ENSURE(m_xStart.is(), "no mxStart?");
796     if (!m_xStart.is()) return;
797 
798     const Reference<XTextRange> xEndRange(
799         GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
800 
801     // create range for insertion
802     const Reference<XTextCursor> xInsertionCursor(
803         GetImport().GetTextImport()->GetText()->createTextCursorByRange(
804             xEndRange) );
805     xInsertionCursor->gotoRange(m_xStart, sal_True);
806 
807     const Reference<XTextRange> xInsertionRange(xInsertionCursor, UNO_QUERY);
808 
809     InsertMeta(xInsertionRange);
810 }
811 
CreateChildContext(sal_uInt16 i_nPrefix,const OUString & i_rLocalName,const Reference<xml::sax::XAttributeList> & i_xAttrList)812 SvXMLImportContext * XMLMetaImportContextBase::CreateChildContext(
813             sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
814             const Reference< xml::sax::XAttributeList > & i_xAttrList )
815 {
816     const SvXMLTokenMap& rTokenMap(
817         GetImport().GetTextImport()->GetTextPElemTokenMap() );
818     const sal_uInt16 nToken( rTokenMap.Get( i_nPrefix, i_rLocalName ) );
819 
820     return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), i_nPrefix,
821         i_rLocalName, i_xAttrList, nToken, m_rHints, m_rIgnoreLeadingSpace );
822 }
823 
Characters(const OUString & i_rChars)824 void XMLMetaImportContextBase::Characters( const OUString& i_rChars )
825 {
826     GetImport().GetTextImport()->InsertString(i_rChars, m_rIgnoreLeadingSpace);
827 }
828 
ProcessAttribute(sal_uInt16 const i_nPrefix,OUString const & i_rLocalName,OUString const & i_rValue)829 void XMLMetaImportContextBase::ProcessAttribute(sal_uInt16 const i_nPrefix,
830     OUString const & i_rLocalName, OUString const & i_rValue)
831 {
832     if ( (XML_NAMESPACE_XML == i_nPrefix) && IsXMLToken(i_rLocalName, XML_ID) )
833     {
834         m_XmlId = i_rValue;
835     }
836 }
837 
838 
839 // ---------------------------------------------------------------------
840 
841 /** text:meta */
842 class XMLMetaImportContext : public XMLMetaImportContextBase
843 {
844     // RDFa
845     bool m_bHaveAbout;
846     ::rtl::OUString m_sAbout;
847     ::rtl::OUString m_sProperty;
848     ::rtl::OUString m_sContent;
849     ::rtl::OUString m_sDatatype;
850 
851 public:
852     TYPEINFO();
853 
854     XMLMetaImportContext(
855         SvXMLImport& i_rImport,
856         const sal_uInt16 i_nPrefix,
857         const OUString& i_rLocalName,
858         XMLHints_Impl& i_rHints,
859         sal_Bool & i_rIgnoreLeadingSpace );
860 
861     virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
862         OUString const & i_rLocalName, OUString const & i_rValue);
863 
864     virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange);
865 };
866 
867 TYPEINIT1( XMLMetaImportContext, XMLMetaImportContextBase );
868 
XMLMetaImportContext(SvXMLImport & i_rImport,const sal_uInt16 i_nPrefix,const OUString & i_rLocalName,XMLHints_Impl & i_rHints,sal_Bool & i_rIgnoreLeadingSpace)869 XMLMetaImportContext::XMLMetaImportContext(
870         SvXMLImport& i_rImport,
871         const sal_uInt16 i_nPrefix,
872         const OUString& i_rLocalName,
873         XMLHints_Impl& i_rHints,
874         sal_Bool & i_rIgnoreLeadingSpace )
875     : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
876             i_rHints, i_rIgnoreLeadingSpace )
877     , m_bHaveAbout(false)
878 {
879 }
880 
ProcessAttribute(sal_uInt16 const i_nPrefix,OUString const & i_rLocalName,OUString const & i_rValue)881 void XMLMetaImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
882     OUString const & i_rLocalName, OUString const & i_rValue)
883 {
884     if ( XML_NAMESPACE_XHTML == i_nPrefix )
885     {
886         // RDFa
887         if ( IsXMLToken( i_rLocalName, XML_ABOUT) )
888         {
889             m_sAbout = i_rValue;
890             m_bHaveAbout = true;
891         }
892         else if ( IsXMLToken( i_rLocalName, XML_PROPERTY) )
893         {
894             m_sProperty = i_rValue;
895         }
896         else if ( IsXMLToken( i_rLocalName, XML_CONTENT) )
897         {
898             m_sContent = i_rValue;
899         }
900         else if ( IsXMLToken( i_rLocalName, XML_DATATYPE) )
901         {
902             m_sDatatype = i_rValue;
903         }
904     }
905     else
906     {
907         XMLMetaImportContextBase::ProcessAttribute(
908             i_nPrefix, i_rLocalName, i_rValue);
909     }
910 }
911 
InsertMeta(const Reference<XTextRange> & i_xInsertionRange)912 void XMLMetaImportContext::InsertMeta(
913     const Reference<XTextRange> & i_xInsertionRange)
914 {
915     OSL_ENSURE(!m_bHaveAbout == !m_sProperty.getLength(),
916         "XMLMetaImportContext::InsertMeta: invalid RDFa?");
917     if (m_XmlId.getLength() || (m_bHaveAbout && m_sProperty.getLength()))
918     {
919         // insert mark
920         const uno::Reference<rdf::XMetadatable> xMeta(
921             XMLTextMarkImportContext::CreateAndInsertMark(
922                 GetImport(),
923                 OUString::createFromAscii(
924                     "com.sun.star.text.InContentMetadata"),
925                 OUString(),
926                 i_xInsertionRange, m_XmlId),
927             uno::UNO_QUERY);
928         OSL_ENSURE(xMeta.is(), "cannot insert Meta?");
929 
930         if (xMeta.is() && m_bHaveAbout)
931         {
932             GetImport().AddRDFa(xMeta,
933                 m_sAbout, m_sProperty, m_sContent, m_sDatatype);
934         }
935     }
936     else
937     {
938         OSL_TRACE("invalid <text:meta>: no xml:id, no valid RDFa");
939     }
940 }
941 
942 // ---------------------------------------------------------------------
943 
944 /** text:meta-field */
945 class XMLMetaFieldImportContext : public XMLMetaImportContextBase
946 {
947     OUString m_DataStyleName;
948 
949 public:
950     TYPEINFO();
951 
952     XMLMetaFieldImportContext(
953         SvXMLImport& i_rImport,
954         const sal_uInt16 i_nPrefix,
955         const OUString& i_rLocalName,
956         XMLHints_Impl& i_rHints,
957         sal_Bool & i_rIgnoreLeadingSpace );
958 
959     virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
960         OUString const & i_rLocalName, OUString const & i_rValue);
961 
962     virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange);
963 };
964 
965 TYPEINIT1( XMLMetaFieldImportContext, XMLMetaImportContextBase );
966 
XMLMetaFieldImportContext(SvXMLImport & i_rImport,const sal_uInt16 i_nPrefix,const OUString & i_rLocalName,XMLHints_Impl & i_rHints,sal_Bool & i_rIgnoreLeadingSpace)967 XMLMetaFieldImportContext::XMLMetaFieldImportContext(
968         SvXMLImport& i_rImport,
969         const sal_uInt16 i_nPrefix,
970         const OUString& i_rLocalName,
971         XMLHints_Impl& i_rHints,
972         sal_Bool & i_rIgnoreLeadingSpace )
973     : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
974             i_rHints, i_rIgnoreLeadingSpace )
975 {
976 }
977 
ProcessAttribute(sal_uInt16 const i_nPrefix,OUString const & i_rLocalName,OUString const & i_rValue)978 void XMLMetaFieldImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
979     OUString const & i_rLocalName, OUString const & i_rValue)
980 {
981     if ( XML_NAMESPACE_STYLE == i_nPrefix &&
982          IsXMLToken( i_rLocalName, XML_DATA_STYLE_NAME ) )
983     {
984         m_DataStyleName = i_rValue;
985     }
986     else
987     {
988         XMLMetaImportContextBase::ProcessAttribute(
989             i_nPrefix, i_rLocalName, i_rValue);
990     }
991 }
992 
InsertMeta(const Reference<XTextRange> & i_xInsertionRange)993 void XMLMetaFieldImportContext::InsertMeta(
994     const Reference<XTextRange> & i_xInsertionRange)
995 {
996     if (m_XmlId.getLength()) // valid?
997     {
998         // insert mark
999         const Reference<XPropertySet> xPropertySet(
1000             XMLTextMarkImportContext::CreateAndInsertMark(
1001                 GetImport(),
1002                 OUString::createFromAscii(
1003                     "com.sun.star.text.textfield.MetadataField"),
1004                 OUString(),
1005                 i_xInsertionRange, m_XmlId),
1006             UNO_QUERY);
1007         OSL_ENSURE(xPropertySet.is(), "cannot insert MetaField?");
1008         if (!xPropertySet.is()) return;
1009 
1010         if (m_DataStyleName.getLength())
1011         {
1012             sal_Bool isDefaultLanguage(sal_True);
1013 
1014             const sal_Int32 nKey( GetImport().GetTextImport()->GetDataStyleKey(
1015                                    m_DataStyleName, & isDefaultLanguage) );
1016 
1017             if (-1 != nKey)
1018             {
1019                 static ::rtl::OUString sPropertyIsFixedLanguage(
1020                     ::rtl::OUString::createFromAscii("IsFixedLanguage") );
1021                 Any any;
1022                 any <<= nKey;
1023                 xPropertySet->setPropertyValue(
1024                     OUString::createFromAscii("NumberFormat"), any);
1025                 if ( xPropertySet->getPropertySetInfo()->
1026                         hasPropertyByName( sPropertyIsFixedLanguage ) )
1027                 {
1028                     any <<= static_cast<bool>(!isDefaultLanguage);
1029                     xPropertySet->setPropertyValue( sPropertyIsFixedLanguage,
1030                         any );
1031                 }
1032             }
1033         }
1034     }
1035     else
1036     {
1037         OSL_TRACE("invalid <text:meta-field>: no xml:id");
1038     }
1039 }
1040 
1041 
1042 // ---------------------------------------------------------------------
1043 
1044 
1045 /**
1046  * Process index marks.
1047  *
1048  * All *-mark-end index marks should instantiate *this* class (because
1049  * it doesn't process attributes other than ID), while the *-mark and
1050  * *-mark-start classes should instantiate the apporpiate subclasses.
1051  */
1052 class XMLIndexMarkImportContext_Impl : public SvXMLImportContext
1053 {
1054 	const OUString sAlternativeText;
1055 
1056 	XMLHints_Impl& rHints;
1057 	const enum XMLTextPElemTokens eToken;
1058 	OUString sID;
1059 
1060 public:
1061 	TYPEINFO();
1062 
1063 	XMLIndexMarkImportContext_Impl(
1064 		SvXMLImport& rImport,
1065 		sal_uInt16 nPrefix,
1066 		const OUString& rLocalName,
1067 		enum XMLTextPElemTokens nTok,
1068 		XMLHints_Impl& rHnts);
1069 
1070 	void StartElement(const Reference<xml::sax::XAttributeList> & xAttrList);
1071 
1072 protected:
1073 
1074 	/// process all attributes
1075 	void ProcessAttributes(const Reference<xml::sax::XAttributeList> & xAttrList,
1076 						   Reference<beans::XPropertySet>& rPropSet);
1077 
1078 	/**
1079 	 * All marks can be created immediatly. Since we don't care about
1080 	 * the element content, ProcessAttribute should set the properties
1081 	 * immediatly.
1082 	 *
1083 	 * This method tolerates an empty PropertySet; subclasses however
1084 	 * are not expected to.
1085 	 */
1086 	virtual void ProcessAttribute(sal_uInt16 nNamespace,
1087 								  OUString sLocalName,
1088 								  OUString sValue,
1089 								  Reference<beans::XPropertySet>& rPropSet);
1090 
1091 	static void GetServiceName(OUString& sServiceName,
1092 							   enum XMLTextPElemTokens nToken);
1093 
1094 	sal_Bool CreateMark(Reference<beans::XPropertySet>& rPropSet,
1095 						const OUString& rServiceName);
1096 };
1097 
1098 
1099 TYPEINIT1( XMLIndexMarkImportContext_Impl, SvXMLImportContext );
1100 
XMLIndexMarkImportContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,enum XMLTextPElemTokens eTok,XMLHints_Impl & rHnts)1101 XMLIndexMarkImportContext_Impl::XMLIndexMarkImportContext_Impl(
1102 	SvXMLImport& rImport,
1103 	sal_uInt16 nPrefix,
1104 	const OUString& rLocalName,
1105 	enum XMLTextPElemTokens eTok,
1106 	XMLHints_Impl& rHnts) :
1107 		SvXMLImportContext(rImport, nPrefix, rLocalName),
1108 		sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")),
1109 		rHints(rHnts),
1110 		eToken(eTok)
1111 {
1112 }
1113 
StartElement(const Reference<xml::sax::XAttributeList> & xAttrList)1114 void XMLIndexMarkImportContext_Impl::StartElement(
1115 	const Reference<xml::sax::XAttributeList> & xAttrList)
1116 {
1117 	// get Cursor position (needed for all cases)
1118 	Reference<XTextRange> xPos(
1119 		GetImport().GetTextImport()->GetCursor()->getStart());
1120 	Reference<beans::XPropertySet> xMark;
1121 
1122 	switch (eToken)
1123 	{
1124 		case XML_TOK_TEXT_TOC_MARK:
1125 		case XML_TOK_TEXT_USER_INDEX_MARK:
1126 		case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1127 		{
1128 			// single mark: create mark and insert
1129 			OUString sService;
1130 			GetServiceName(sService, eToken);
1131 			if (CreateMark(xMark, sService))
1132 			{
1133 				ProcessAttributes(xAttrList, xMark);
1134 				XMLHint_Impl* pHint = new XMLIndexMarkHint_Impl(xMark, xPos);
1135 				rHints.Insert(pHint, rHints.Count());
1136 			}
1137 			// else: can't create mark -> ignore
1138 			break;
1139 		}
1140 
1141 		case XML_TOK_TEXT_TOC_MARK_START:
1142 		case XML_TOK_TEXT_USER_INDEX_MARK_START:
1143 		case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1144 		{
1145 			// start: create mark and insert (if ID is found)
1146 			OUString sService;
1147 			GetServiceName(sService, eToken);
1148 			if (CreateMark(xMark, sService))
1149 			{
1150 				ProcessAttributes(xAttrList, xMark);
1151 				if (sID.getLength() > 0)
1152 				{
1153 					// process only if we find an ID
1154 					XMLHint_Impl* pHint =
1155 						new XMLIndexMarkHint_Impl(xMark, xPos, sID);
1156 					rHints.Insert(pHint, rHints.Count());
1157 				}
1158 				// else: no ID -> we'll never find the end -> ignore
1159 			}
1160 			// else: can't create mark -> ignore
1161 			break;
1162 		}
1163 
1164 		case XML_TOK_TEXT_TOC_MARK_END:
1165 		case XML_TOK_TEXT_USER_INDEX_MARK_END:
1166 		case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1167 		{
1168 			// end: search for ID and set end of mark
1169 
1170 			// call process attributes with empty XPropertySet:
1171 			ProcessAttributes(xAttrList, xMark);
1172 			if (sID.getLength() > 0)
1173 			{
1174 				// if we have an ID, find the hint and set the end position
1175 				sal_uInt16 nCount = rHints.Count();
1176 				for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
1177 				{
1178 					XMLHint_Impl *pHint = rHints[nPos];
1179 					if ( pHint->IsIndexMark() &&
1180 						 sID.equals(
1181 							 ((XMLIndexMarkHint_Impl *)pHint)->GetID()) )
1182 					{
1183 						// set end and stop searching
1184 						pHint->SetEnd(xPos);
1185 						break;
1186 					}
1187 				}
1188 			}
1189 			// else: no ID -> ignore
1190 			break;
1191 		}
1192 
1193 		default:
1194 			DBG_ERROR("unknown index mark type!");
1195 			break;
1196 	}
1197 }
1198 
ProcessAttributes(const Reference<xml::sax::XAttributeList> & xAttrList,Reference<beans::XPropertySet> & rPropSet)1199 void XMLIndexMarkImportContext_Impl::ProcessAttributes(
1200 	const Reference<xml::sax::XAttributeList> & xAttrList,
1201 	Reference<beans::XPropertySet>& rPropSet)
1202 {
1203 	// process attributes
1204 	sal_Int16 nLength = xAttrList->getLength();
1205 	for(sal_Int16 i=0; i<nLength; i++)
1206 	{
1207 		OUString sLocalName;
1208 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1209 			GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
1210 
1211 		ProcessAttribute(nPrefix, sLocalName,
1212 						 xAttrList->getValueByIndex(i),
1213 						 rPropSet);
1214 	}
1215 }
1216 
ProcessAttribute(sal_uInt16 nNamespace,OUString sLocalName,OUString sValue,Reference<beans::XPropertySet> & rPropSet)1217 void XMLIndexMarkImportContext_Impl::ProcessAttribute(
1218 	sal_uInt16 nNamespace,
1219 	OUString sLocalName,
1220 	OUString sValue,
1221 	Reference<beans::XPropertySet>& rPropSet)
1222 {
1223 	// we only know ID + string-value attribute;
1224 	// (former: marks, latter: -start + -end-marks)
1225 	// the remainder is handled in sub-classes
1226 	switch (eToken)
1227 	{
1228 		case XML_TOK_TEXT_TOC_MARK:
1229 		case XML_TOK_TEXT_USER_INDEX_MARK:
1230 		case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1231 			if ( (XML_NAMESPACE_TEXT == nNamespace) &&
1232 				 IsXMLToken( sLocalName, XML_STRING_VALUE ) )
1233 			{
1234                 rPropSet->setPropertyValue(sAlternativeText, uno::makeAny(sValue));
1235 			}
1236 			// else: ignore!
1237 			break;
1238 
1239 		case XML_TOK_TEXT_TOC_MARK_START:
1240 		case XML_TOK_TEXT_USER_INDEX_MARK_START:
1241 		case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1242 		case XML_TOK_TEXT_TOC_MARK_END:
1243 		case XML_TOK_TEXT_USER_INDEX_MARK_END:
1244 		case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1245 			if ( (XML_NAMESPACE_TEXT == nNamespace) &&
1246 				 IsXMLToken( sLocalName, XML_ID ) )
1247 			{
1248 				sID = sValue;
1249 			}
1250 			// else: ignore
1251 			break;
1252 
1253 		default:
1254 			DBG_ERROR("unknown index mark type!");
1255 			break;
1256 	}
1257 }
1258 
1259 static const sal_Char sAPI_com_sun_star_text_ContentIndexMark[] =
1260 		"com.sun.star.text.ContentIndexMark";
1261 static const sal_Char sAPI_com_sun_star_text_UserIndexMark[] =
1262 		"com.sun.star.text.UserIndexMark";
1263 static const sal_Char sAPI_com_sun_star_text_DocumentIndexMark[] =
1264 		"com.sun.star.text.DocumentIndexMark";
1265 
1266 
GetServiceName(OUString & sServiceName,enum XMLTextPElemTokens eToken)1267 void XMLIndexMarkImportContext_Impl::GetServiceName(
1268 	OUString& sServiceName,
1269 	enum XMLTextPElemTokens eToken)
1270 {
1271 	switch (eToken)
1272 	{
1273 		case XML_TOK_TEXT_TOC_MARK:
1274 		case XML_TOK_TEXT_TOC_MARK_START:
1275 		case XML_TOK_TEXT_TOC_MARK_END:
1276 		{
1277 			OUString sTmp(RTL_CONSTASCII_USTRINGPARAM(
1278 				sAPI_com_sun_star_text_ContentIndexMark));
1279 			sServiceName = sTmp;
1280 			break;
1281 		}
1282 
1283 		case XML_TOK_TEXT_USER_INDEX_MARK:
1284 		case XML_TOK_TEXT_USER_INDEX_MARK_START:
1285 		case XML_TOK_TEXT_USER_INDEX_MARK_END:
1286 		{
1287 			OUString sTmp(RTL_CONSTASCII_USTRINGPARAM(
1288 				sAPI_com_sun_star_text_UserIndexMark));
1289 			sServiceName = sTmp;
1290 			break;
1291 		}
1292 
1293 		case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1294 		case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1295 		case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1296 		{
1297 			OUString sTmp(RTL_CONSTASCII_USTRINGPARAM(
1298 				sAPI_com_sun_star_text_DocumentIndexMark));
1299 			sServiceName = sTmp;
1300 			break;
1301 		}
1302 
1303 		default:
1304 		{
1305 			DBG_ERROR("unknown index mark type!");
1306 			OUString sTmp;
1307 			sServiceName = sTmp;
1308 			break;
1309 		}
1310 	}
1311 }
1312 
1313 
CreateMark(Reference<beans::XPropertySet> & rPropSet,const OUString & rServiceName)1314 sal_Bool XMLIndexMarkImportContext_Impl::CreateMark(
1315 	Reference<beans::XPropertySet>& rPropSet,
1316 	const OUString& rServiceName)
1317 {
1318 	Reference<lang::XMultiServiceFactory>
1319 		xFactory(GetImport().GetModel(), UNO_QUERY);
1320 
1321 	if( xFactory.is() )
1322 	{
1323 		Reference<beans::XPropertySet> xPropSet( xFactory->createInstance(rServiceName), UNO_QUERY );
1324 		if (xPropSet.is())
1325 			rPropSet = xPropSet;
1326 		return sal_True;
1327 	}
1328 
1329 	return sal_False;
1330 }
1331 
1332 
1333 class XMLTOCMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1334 {
1335 	const OUString sLevel;
1336 
1337 public:
1338 	TYPEINFO();
1339 
1340 	XMLTOCMarkImportContext_Impl(
1341 		SvXMLImport& rImport,
1342 		sal_uInt16 nPrefix,
1343 		const OUString& rLocalName,
1344 		enum XMLTextPElemTokens nTok,
1345 		XMLHints_Impl& rHnts);
1346 
1347 protected:
1348 
1349 	/** process outline level */
1350 	virtual void ProcessAttribute(sal_uInt16 nNamespace,
1351 								  OUString sLocalName,
1352 								  OUString sValue,
1353 								  Reference<beans::XPropertySet>& rPropSet);
1354 };
1355 
1356 TYPEINIT1( XMLTOCMarkImportContext_Impl, XMLIndexMarkImportContext_Impl );
1357 
1358 
XMLTOCMarkImportContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,enum XMLTextPElemTokens nTok,XMLHints_Impl & rHnts)1359 XMLTOCMarkImportContext_Impl::XMLTOCMarkImportContext_Impl(
1360 	SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1361 	enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1362 		XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1363 									   nTok, rHnts),
1364 		sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
1365 {
1366 }
1367 
ProcessAttribute(sal_uInt16 nNamespace,OUString sLocalName,OUString sValue,Reference<beans::XPropertySet> & rPropSet)1368 void XMLTOCMarkImportContext_Impl::ProcessAttribute(
1369 	sal_uInt16 nNamespace,
1370 	OUString sLocalName,
1371 	OUString sValue,
1372 	Reference<beans::XPropertySet>& rPropSet)
1373 {
1374 	DBG_ASSERT(rPropSet.is(), "need PropertySet");
1375 
1376 	if ((XML_NAMESPACE_TEXT == nNamespace) &&
1377 		IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
1378     {
1379 		// ouline level: set Level property
1380 		sal_Int32 nTmp;
1381         if ( SvXMLUnitConverter::convertNumber( nTmp, sValue )
1382              && nTmp >= 1
1383              && nTmp < GetImport().GetTextImport()->
1384                               GetChapterNumbering()->getCount() )
1385 		{
1386             rPropSet->setPropertyValue(sLevel, uno::makeAny((sal_Int16)(nTmp - 1)));
1387 		}
1388 		// else: value out of range -> ignore
1389 	}
1390 	else
1391 	{
1392 		// else: delegate to superclass
1393 		XMLIndexMarkImportContext_Impl::ProcessAttribute(
1394 			nNamespace, sLocalName, sValue, rPropSet);
1395 	}
1396 }
1397 
1398 class XMLUserIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1399 {
1400 	const OUString sUserIndexName;
1401     const OUString sLevel;
1402 
1403 public:
1404 	TYPEINFO();
1405 
1406 	XMLUserIndexMarkImportContext_Impl(
1407 		SvXMLImport& rImport,
1408 		sal_uInt16 nPrefix,
1409 		const OUString& rLocalName,
1410 		enum XMLTextPElemTokens nTok,
1411 		XMLHints_Impl& rHnts);
1412 
1413 protected:
1414 
1415 	/** process index name */
1416 	virtual void ProcessAttribute(sal_uInt16 nNamespace,
1417 								  OUString sLocalName,
1418 								  OUString sValue,
1419 								  Reference<beans::XPropertySet>& rPropSet);
1420 };
1421 
1422 TYPEINIT1( XMLUserIndexMarkImportContext_Impl, XMLIndexMarkImportContext_Impl);
1423 
XMLUserIndexMarkImportContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,enum XMLTextPElemTokens nTok,XMLHints_Impl & rHnts)1424 XMLUserIndexMarkImportContext_Impl::XMLUserIndexMarkImportContext_Impl(
1425 	SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1426 	enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1427 		XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1428 									   nTok, rHnts),
1429 		sUserIndexName(RTL_CONSTASCII_USTRINGPARAM("UserIndexName")),
1430         sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
1431 {
1432 }
1433 
ProcessAttribute(sal_uInt16 nNamespace,OUString sLocalName,OUString sValue,Reference<beans::XPropertySet> & rPropSet)1434 void XMLUserIndexMarkImportContext_Impl::ProcessAttribute(
1435 	sal_uInt16 nNamespace, OUString sLocalName, OUString sValue,
1436 	Reference<beans::XPropertySet>& rPropSet)
1437 {
1438 	if ( XML_NAMESPACE_TEXT == nNamespace )
1439     {
1440         if ( IsXMLToken( sLocalName, XML_INDEX_NAME ) )
1441         {
1442             rPropSet->setPropertyValue(sUserIndexName, uno::makeAny(sValue));
1443         }
1444         else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
1445         {
1446             // ouline level: set Level property
1447             sal_Int32 nTmp;
1448             if (SvXMLUnitConverter::convertNumber(
1449                 nTmp, sValue, 0,
1450                GetImport().GetTextImport()->GetChapterNumbering()->getCount()))
1451             {
1452                 rPropSet->setPropertyValue(sLevel, uno::makeAny(static_cast<sal_Int16>(nTmp - 1)));
1453             }
1454             // else: value out of range -> ignore
1455         }
1456         else
1457         {
1458             // else: unknown text property: delegate to super class
1459             XMLIndexMarkImportContext_Impl::ProcessAttribute(
1460                 nNamespace, sLocalName, sValue, rPropSet);
1461         }
1462     }
1463     else
1464     {
1465         // else: unknown namespace: delegate to super class
1466         XMLIndexMarkImportContext_Impl::ProcessAttribute(
1467             nNamespace, sLocalName, sValue, rPropSet);
1468     }
1469 }
1470 
1471 
1472 class XMLAlphaIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
1473 {
1474 	const OUString sPrimaryKey;
1475 	const OUString sSecondaryKey;
1476     const OUString sTextReading;
1477     const OUString sPrimaryKeyReading;
1478     const OUString sSecondaryKeyReading;
1479     const OUString sMainEntry;
1480 
1481 public:
1482 	TYPEINFO();
1483 
1484 	XMLAlphaIndexMarkImportContext_Impl(
1485 		SvXMLImport& rImport,
1486 		sal_uInt16 nPrefix,
1487 		const OUString& rLocalName,
1488 		enum XMLTextPElemTokens nTok,
1489 		XMLHints_Impl& rHnts);
1490 
1491 protected:
1492 
1493 	/** process primary + secondary keys */
1494 	virtual void ProcessAttribute(sal_uInt16 nNamespace,
1495 								  OUString sLocalName,
1496 								  OUString sValue,
1497 								  Reference<beans::XPropertySet>& rPropSet);
1498 };
1499 
1500 TYPEINIT1( XMLAlphaIndexMarkImportContext_Impl,
1501 		   XMLIndexMarkImportContext_Impl );
1502 
XMLAlphaIndexMarkImportContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,enum XMLTextPElemTokens nTok,XMLHints_Impl & rHnts)1503 XMLAlphaIndexMarkImportContext_Impl::XMLAlphaIndexMarkImportContext_Impl(
1504 	SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
1505 	enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
1506 		XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
1507 									   nTok, rHnts),
1508 		sPrimaryKey(RTL_CONSTASCII_USTRINGPARAM("PrimaryKey")),
1509 		sSecondaryKey(RTL_CONSTASCII_USTRINGPARAM("SecondaryKey")),
1510         sTextReading(RTL_CONSTASCII_USTRINGPARAM("TextReading")),
1511         sPrimaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("PrimaryKeyReading")),
1512         sSecondaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("SecondaryKeyReading")),
1513         sMainEntry(RTL_CONSTASCII_USTRINGPARAM("IsMainEntry"))
1514 {
1515 }
1516 
ProcessAttribute(sal_uInt16 nNamespace,OUString sLocalName,OUString sValue,Reference<beans::XPropertySet> & rPropSet)1517 void XMLAlphaIndexMarkImportContext_Impl::ProcessAttribute(
1518 	sal_uInt16 nNamespace, OUString sLocalName, OUString sValue,
1519 	Reference<beans::XPropertySet>& rPropSet)
1520 {
1521 	if (XML_NAMESPACE_TEXT == nNamespace)
1522 	{
1523 		if ( IsXMLToken( sLocalName, XML_KEY1 ) )
1524 		{
1525             rPropSet->setPropertyValue(sPrimaryKey, uno::makeAny(sValue));
1526 		}
1527 		else if ( IsXMLToken( sLocalName, XML_KEY2 ) )
1528 		{
1529             rPropSet->setPropertyValue(sSecondaryKey, uno::makeAny(sValue));
1530 		}
1531         else if ( IsXMLToken( sLocalName, XML_KEY1_PHONETIC ) )
1532         {
1533             rPropSet->setPropertyValue(sPrimaryKeyReading, uno::makeAny(sValue));
1534         }
1535         else if ( IsXMLToken( sLocalName, XML_KEY2_PHONETIC ) )
1536         {
1537             rPropSet->setPropertyValue(sSecondaryKeyReading, uno::makeAny(sValue));
1538         }
1539         else if ( IsXMLToken( sLocalName, XML_STRING_VALUE_PHONETIC ) )
1540         {
1541             rPropSet->setPropertyValue(sTextReading, uno::makeAny(sValue));
1542         }
1543         else if ( IsXMLToken( sLocalName, XML_MAIN_ENTRY ) )
1544         {
1545             sal_Bool bMainEntry = sal_False, bTmp;
1546 
1547             if (SvXMLUnitConverter::convertBool(bTmp, sValue))
1548                 bMainEntry = bTmp;
1549 
1550             rPropSet->setPropertyValue(sMainEntry, uno::makeAny(bMainEntry));
1551         }
1552 		else
1553 		{
1554 			XMLIndexMarkImportContext_Impl::ProcessAttribute(
1555 				nNamespace, sLocalName, sValue, rPropSet);
1556 		}
1557 	}
1558 	else
1559 	{
1560 		XMLIndexMarkImportContext_Impl::ProcessAttribute(
1561 			nNamespace, sLocalName, sValue, rPropSet);
1562 	}
1563 }
1564 
1565 
1566 // ---------------------------------------------------------------------
1567 
1568 TYPEINIT1( XMLImpSpanContext_Impl, SvXMLImportContext );
1569 
XMLImpSpanContext_Impl(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList,XMLHints_Impl & rHnts,sal_Bool & rIgnLeadSpace,sal_uInt8 nSFConvFlags)1570 XMLImpSpanContext_Impl::XMLImpSpanContext_Impl(
1571 		SvXMLImport& rImport,
1572 		sal_uInt16 nPrfx,
1573 		const OUString& rLName,
1574 		const Reference< xml::sax::XAttributeList > & xAttrList,
1575 		XMLHints_Impl& rHnts,
1576 		sal_Bool& rIgnLeadSpace
1577 	,sal_uInt8				nSFConvFlags
1578 											  )
1579 :	SvXMLImportContext( rImport, nPrfx, rLName )
1580 ,	sTextFrame(RTL_CONSTASCII_USTRINGPARAM("TextFrame"))
1581 ,	rHints( rHnts )
1582 ,	pHint( 0  )
1583 ,	rIgnoreLeadingSpace( rIgnLeadSpace )
1584 ,	nStarFontsConvFlags( nSFConvFlags & (CONV_FROM_STAR_BATS|CONV_FROM_STAR_MATH) )
1585 {
1586 	OUString aStyleName;
1587 
1588 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1589 	for( sal_Int16 i=0; i < nAttrCount; i++ )
1590 	{
1591 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
1592 
1593 		OUString aLocalName;
1594 		sal_uInt16 nPrefix =
1595 			GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
1596 															&aLocalName );
1597 		if( XML_NAMESPACE_TEXT == nPrefix &&
1598 			IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1599 			aStyleName = xAttrList->getValueByIndex( i );
1600 	}
1601 
1602 	if( aStyleName.getLength() )
1603 	{
1604 		pHint = new XMLStyleHint_Impl( aStyleName,
1605 				  GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
1606 			rHints.Insert( pHint, rHints.Count() );
1607 	}
1608 }
1609 
~XMLImpSpanContext_Impl()1610 XMLImpSpanContext_Impl::~XMLImpSpanContext_Impl()
1611 {
1612 	if( pHint )
1613 		pHint->SetEnd( GetImport().GetTextImport()
1614 							->GetCursorAsRange()->getStart() );
1615 }
1616 
CreateChildContext(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList,sal_uInt16 nToken,XMLHints_Impl & rHints,sal_Bool & rIgnoreLeadingSpace,sal_uInt8 nStarFontsConvFlags)1617 SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
1618 		SvXMLImport& rImport,
1619 		sal_uInt16 nPrefix, const OUString& rLocalName,
1620 		const Reference< xml::sax::XAttributeList > & xAttrList,
1621 		sal_uInt16 nToken,
1622 		XMLHints_Impl& rHints,
1623 		sal_Bool& rIgnoreLeadingSpace
1624 	,sal_uInt8				nStarFontsConvFlags
1625 	 )
1626 {
1627 	SvXMLImportContext *pContext = 0;
1628 
1629 	switch( nToken )
1630 	{
1631 	case XML_TOK_TEXT_SPAN:
1632 		pContext = new XMLImpSpanContext_Impl( rImport, nPrefix,
1633 											   rLocalName, xAttrList,
1634 											   rHints,
1635 											   rIgnoreLeadingSpace
1636 											   ,nStarFontsConvFlags
1637 											 );
1638 		break;
1639 
1640 	case XML_TOK_TEXT_TAB_STOP:
1641 		pContext = new XMLCharContext( rImport, nPrefix,
1642 											   rLocalName, xAttrList,
1643 											   0x0009, sal_False );
1644 		rIgnoreLeadingSpace = sal_False;
1645 		break;
1646 
1647 	case XML_TOK_TEXT_LINE_BREAK:
1648 		pContext = new XMLCharContext( rImport, nPrefix,
1649 											   rLocalName, xAttrList,
1650 											   ControlCharacter::LINE_BREAK );
1651 		rIgnoreLeadingSpace = sal_False;
1652 		break;
1653 
1654 	case XML_TOK_TEXT_S:
1655 		pContext = new XMLCharContext( rImport, nPrefix,
1656 											   rLocalName, xAttrList,
1657 											   0x0020, sal_True );
1658 		break;
1659 
1660     case XML_TOK_TEXT_HYPERLINK:
1661     {
1662         // test for HyperLinkURL property. If present, insert link as
1663         // text property (StarWriter), else try to insert as text
1664         // field (StarCalc, StarDraw, ...)
1665         Reference< beans::XPropertySet > xPropSet( rImport.GetTextImport()->GetCursor(), UNO_QUERY );
1666 
1667         static const OUString sHyperLinkURL( RTL_CONSTASCII_USTRINGPARAM( "HyperLinkURL" ) );
1668 
1669         if ( xPropSet->getPropertySetInfo()->hasPropertyByName( sHyperLinkURL ) )
1670         {
1671             pContext = new XMLImpHyperlinkContext_Impl(
1672                     rImport,
1673                     nPrefix,
1674                     rLocalName,
1675                     xAttrList,
1676                     rHints,
1677                     rIgnoreLeadingSpace );
1678         }
1679         else
1680         {
1681             pContext = new XMLUrlFieldImportContext( rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName );
1682             //whitespace handling like other fields
1683             rIgnoreLeadingSpace = sal_False;
1684 
1685         }
1686         break;
1687     }
1688 
1689 	case XML_TOK_TEXT_RUBY:
1690 		pContext = new XMLImpRubyContext_Impl( rImport, nPrefix,
1691 											   rLocalName, xAttrList,
1692 											   rHints,
1693 											   rIgnoreLeadingSpace );
1694 		break;
1695 
1696 	case XML_TOK_TEXT_NOTE:
1697 #ifndef SVX_LIGHT
1698 		if (rImport.GetTextImport()->IsInFrame())
1699 		{
1700 			// we must not insert footnotes into text frames
1701 			pContext = new SvXMLImportContext( rImport, nPrefix,
1702 											   rLocalName );
1703 		}
1704 		else
1705 		{
1706 			pContext = new XMLFootnoteImportContext( rImport,
1707 													 *rImport.GetTextImport().get(),
1708 													 nPrefix, rLocalName );
1709 		}
1710 #else
1711 		// create default context to skip content
1712 		pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName );
1713 #endif // #ifndef SVX_LIGHT
1714 		rIgnoreLeadingSpace = sal_False;
1715 		break;
1716 
1717 	case XML_TOK_TEXT_REFERENCE:
1718 	case XML_TOK_TEXT_BOOKMARK:
1719 	case XML_TOK_TEXT_BOOKMARK_START:
1720 	case XML_TOK_TEXT_BOOKMARK_END:
1721 		pContext = new XMLTextMarkImportContext( rImport,
1722 												 *rImport.GetTextImport().get(),
1723 												 nPrefix, rLocalName );
1724 		break;
1725 
1726 	case XML_TOK_TEXT_FIELDMARK:
1727 	case XML_TOK_TEXT_FIELDMARK_START:
1728 	case XML_TOK_TEXT_FIELDMARK_END:
1729 		pContext = new XMLTextMarkImportContext( rImport,
1730 												 *rImport.GetTextImport().get(),
1731 												 nPrefix, rLocalName );
1732 		break;
1733 
1734 	case XML_TOK_TEXT_REFERENCE_START:
1735 		pContext = new XMLStartReferenceContext_Impl( rImport,
1736 													  nPrefix, rLocalName,
1737 													  rHints, xAttrList );
1738 		break;
1739 
1740 	case XML_TOK_TEXT_REFERENCE_END:
1741 		pContext = new XMLEndReferenceContext_Impl( rImport,
1742 													nPrefix, rLocalName,
1743 													rHints, xAttrList );
1744 		break;
1745 
1746 	case XML_TOK_TEXT_FRAME:
1747 		{
1748 			Reference < XTextRange > xAnchorPos =
1749 				rImport.GetTextImport()->GetCursor()->getStart();
1750 			XMLTextFrameContext *pTextFrameContext =
1751 				new XMLTextFrameContext( rImport, nPrefix,
1752 										 rLocalName, xAttrList,
1753 										 TextContentAnchorType_AS_CHARACTER );
1754             // --> OD 2004-08-24 #i33242# - remove check for text content.
1755             // Check for text content is done on the processing of the hint
1756             if( TextContentAnchorType_AT_CHARACTER ==
1757                                             pTextFrameContext->GetAnchorType() )
1758             // <--
1759 			{
1760 				rHints.Insert( new XMLTextFrameHint_Impl(
1761 					pTextFrameContext, xAnchorPos ),
1762 					rHints.Count() );
1763 			}
1764 			pContext = pTextFrameContext;
1765 			rIgnoreLeadingSpace = sal_False;
1766 		}
1767 		break;
1768 	case XML_TOK_DRAW_A:
1769 		{
1770 			Reference < XTextRange > xAnchorPos(rImport.GetTextImport()->GetCursor()->getStart());
1771 			pContext =
1772 				new XMLTextFrameHyperlinkContext( rImport, nPrefix,
1773 										rLocalName, xAttrList,
1774 										TextContentAnchorType_AS_CHARACTER );
1775 			XMLTextFrameHint_Impl *pHint =
1776 				new XMLTextFrameHint_Impl( pContext, xAnchorPos);
1777 			rHints.Insert( pHint, rHints.Count() );
1778 		}
1779 		break;
1780 
1781 	case XML_TOK_TEXT_TOC_MARK:
1782 	case XML_TOK_TEXT_TOC_MARK_START:
1783 		pContext = new XMLTOCMarkImportContext_Impl(
1784 			rImport, nPrefix, rLocalName,
1785 			(enum XMLTextPElemTokens)nToken, rHints);
1786 		break;
1787 
1788 	case XML_TOK_TEXT_USER_INDEX_MARK:
1789 	case XML_TOK_TEXT_USER_INDEX_MARK_START:
1790 		pContext = new XMLUserIndexMarkImportContext_Impl(
1791 			rImport, nPrefix, rLocalName,
1792 			(enum XMLTextPElemTokens)nToken, rHints);
1793 		break;
1794 
1795 	case XML_TOK_TEXT_ALPHA_INDEX_MARK:
1796 	case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
1797 		pContext = new XMLAlphaIndexMarkImportContext_Impl(
1798 			rImport, nPrefix, rLocalName,
1799 			(enum XMLTextPElemTokens)nToken, rHints);
1800 		break;
1801 
1802 	case XML_TOK_TEXT_TOC_MARK_END:
1803 	case XML_TOK_TEXT_USER_INDEX_MARK_END:
1804 	case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
1805 		pContext = new XMLIndexMarkImportContext_Impl(
1806 			rImport, nPrefix, rLocalName, (enum XMLTextPElemTokens)nToken,
1807 			rHints);
1808 		break;
1809 
1810 	case XML_TOK_TEXTP_CHANGE_START:
1811 	case XML_TOK_TEXTP_CHANGE_END:
1812 	case XML_TOK_TEXTP_CHANGE:
1813 		pContext = new XMLChangeImportContext(
1814 			rImport, nPrefix, rLocalName,
1815 			(nToken != XML_TOK_TEXTP_CHANGE_END),
1816 			(nToken != XML_TOK_TEXTP_CHANGE_START),
1817 			sal_False);
1818 		break;
1819 
1820     case XML_TOK_TEXT_META:
1821         pContext = new XMLMetaImportContext(rImport, nPrefix, rLocalName,
1822             rHints, rIgnoreLeadingSpace );
1823         break;
1824 
1825     case XML_TOK_TEXT_META_FIELD:
1826         pContext = new XMLMetaFieldImportContext(rImport, nPrefix, rLocalName,
1827             rHints, rIgnoreLeadingSpace );
1828         break;
1829 
1830 	default:
1831 		// none of the above? then it's probably  a text field!
1832 		pContext =
1833 			XMLTextFieldImportContext::CreateTextFieldImportContext(
1834 				rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName,
1835 				nToken);
1836         // #108784# import draw elements (except control shapes in headers)
1837         if( pContext == NULL &&
1838             !( rImport.GetTextImport()->IsInHeaderFooter() &&
1839                nPrefix == XML_NAMESPACE_DRAW &&
1840                IsXMLToken( rLocalName, XML_CONTROL ) ) )
1841         {
1842             Reference < XShapes > xShapes;
1843             SvXMLShapeContext* pShapeContext = rImport.GetShapeImport()->CreateGroupChildContext(
1844                 rImport, nPrefix, rLocalName, xAttrList, xShapes );
1845             pContext = pShapeContext;
1846             // OD 2004-04-20 #i26791# - keep shape in a text frame hint to
1847             // adjust its anchor position, if its at-character anchored
1848             Reference < XTextRange > xAnchorPos =
1849                 rImport.GetTextImport()->GetCursor()->getStart();
1850             rHints.Insert( new XMLDrawHint_Impl( pShapeContext, xAnchorPos ),
1851                            rHints.Count() );
1852         }
1853 		if( !pContext )
1854 		{
1855 			// ignore unknown content
1856 			pContext =
1857 				new SvXMLImportContext( rImport, nPrefix, rLocalName );
1858 		}
1859 		// Behind fields, shapes and any unknown content blanks aren't ignored
1860 		rIgnoreLeadingSpace = sal_False;
1861 	}
1862 
1863 	return pContext;
1864 }
1865 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)1866 SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
1867 		sal_uInt16 nPrefix, const OUString& rLocalName,
1868 		const Reference< xml::sax::XAttributeList > & xAttrList )
1869 {
1870 	const SvXMLTokenMap& rTokenMap =
1871 		GetImport().GetTextImport()->GetTextPElemTokenMap();
1872 	sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
1873 
1874 	return CreateChildContext( GetImport(), nPrefix, rLocalName, xAttrList,
1875 							   nToken, rHints, rIgnoreLeadingSpace
1876 							   ,nStarFontsConvFlags
1877 							 );
1878 }
1879 
Characters(const OUString & rChars)1880 void XMLImpSpanContext_Impl::Characters( const OUString& rChars )
1881 {
1882 	OUString sStyleName;
1883 	if( pHint )
1884 		sStyleName = pHint->GetStyleName();
1885 	OUString sChars =
1886 		GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
1887 													   nStarFontsConvFlags,
1888 													   sal_False, GetImport() );
1889 	GetImport().GetTextImport()->InsertString( sChars, rIgnoreLeadingSpace );
1890 }
1891 
1892 // ---------------------------------------------------------------------
1893 
1894 TYPEINIT1( XMLParaContext, SvXMLImportContext );
1895 
XMLParaContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList,sal_Bool bHead)1896 XMLParaContext::XMLParaContext(
1897 		SvXMLImport& rImport,
1898 		sal_uInt16 nPrfx,
1899 		const OUString& rLName,
1900 		const Reference< xml::sax::XAttributeList > & xAttrList,
1901 		sal_Bool bHead ) :
1902 	SvXMLImportContext( rImport, nPrfx, rLName ),
1903 	xStart( rImport.GetTextImport()->GetCursorAsRange()->getStart() ),
1904     m_bHaveAbout(false),
1905 	nOutlineLevel( IsXMLToken( rLName, XML_H ) ? 1 : -1 ),
1906 	pHints( 0 ),
1907     // --> OD 2007-07-25 #i73509#
1908     mbOutlineLevelAttrFound( sal_False ),
1909     // <--
1910 	bIgnoreLeadingSpace( sal_True ),
1911 	bHeading( bHead ),
1912     bIsListHeader( false ),
1913     bIsRestart (false),
1914     nStartValue(0)
1915 	,nStarFontsConvFlags( 0 )
1916 {
1917 	const SvXMLTokenMap& rTokenMap =
1918 		GetImport().GetTextImport()->GetTextPAttrTokenMap();
1919 
1920     bool bHaveXmlId( false );
1921 	OUString aCondStyleName, sClassNames;
1922 
1923 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1924 	for( sal_Int16 i=0; i < nAttrCount; i++ )
1925 	{
1926 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
1927 		const OUString& rValue = xAttrList->getValueByIndex( i );
1928 
1929 		OUString aLocalName;
1930 		sal_uInt16 nPrefix =
1931 			GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
1932 															&aLocalName );
1933 		switch( rTokenMap.Get( nPrefix, aLocalName ) )
1934 		{
1935         case XML_TOK_TEXT_P_XMLID:
1936             m_sXmlId = rValue;
1937             bHaveXmlId = true;
1938             break;
1939         case XML_TOK_TEXT_P_ABOUT:
1940             m_sAbout = rValue;
1941             m_bHaveAbout = true;
1942             break;
1943         case XML_TOK_TEXT_P_PROPERTY:
1944             m_sProperty = rValue;
1945             break;
1946         case XML_TOK_TEXT_P_CONTENT:
1947             m_sContent = rValue;
1948             break;
1949         case XML_TOK_TEXT_P_DATATYPE:
1950             m_sDatatype = rValue;
1951             break;
1952         case XML_TOK_TEXT_P_TEXTID:
1953             if (!bHaveXmlId) { m_sXmlId = rValue; }
1954             break;
1955 		case XML_TOK_TEXT_P_STYLE_NAME:
1956 			sStyleName = rValue;
1957 			break;
1958 		case XML_TOK_TEXT_P_CLASS_NAMES:
1959 			sClassNames = rValue;
1960 			break;
1961 		case XML_TOK_TEXT_P_COND_STYLE_NAME:
1962 			aCondStyleName = rValue;
1963 			break;
1964 		case XML_TOK_TEXT_P_LEVEL:
1965 			{
1966 				sal_Int32 nTmp = rValue.toInt32();
1967 				if( nTmp > 0L )
1968 				{
1969 					if( nTmp > 127 )
1970 						nTmp = 127;
1971 					nOutlineLevel = (sal_Int8)nTmp;
1972 				}
1973                 // --> OD 2007-07-25 #i73509#
1974                 mbOutlineLevelAttrFound = sal_True;
1975                 // <--
1976 			}
1977             break;
1978 		case XML_TOK_TEXT_P_IS_LIST_HEADER:
1979 			{
1980                 sal_Bool bBool;
1981                 if( SvXMLUnitConverter::convertBool( bBool, rValue ) )
1982                 {
1983                     bIsListHeader = bBool;
1984                 }
1985 			}
1986             break;
1987         case XML_TOK_TEXT_P_RESTART_NUMBERING:
1988             {
1989                 sal_Bool bBool;
1990                 if (SvXMLUnitConverter::convertBool(bBool, rValue))
1991                 {
1992                     bIsRestart = bBool;
1993                 }
1994             }
1995             break;
1996         case XML_TOK_TEXT_P_START_VALUE:
1997             {
1998                 nStartValue = sal::static_int_cast< sal_Int16 >(
1999                     rValue.toInt32());
2000             }
2001             break;
2002 		}
2003 	}
2004 
2005 	if( aCondStyleName.getLength() )
2006 		sStyleName = aCondStyleName;
2007 	else if( sClassNames.getLength() )
2008 	{
2009 		sal_Int32 nDummy = 0;
2010 		sStyleName = sClassNames.getToken( 0, ' ', nDummy );
2011 	}
2012 }
2013 
~XMLParaContext()2014 XMLParaContext::~XMLParaContext()
2015 {
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());
2022 
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     // FIXME: this is just temporary, and should be removed when
2026     // EditEngine paragraphs implement XMetadatable!
2027     if (m_sXmlId.getLength())
2028 	{
2029 		Reference < XTextCursor > xIdCursor( xTxtImport->GetText()->createTextCursorByRange( xStart ) );
2030 		if( xIdCursor.is() )
2031 		{
2032 			xIdCursor->gotoRange( xEnd, sal_True );
2033 			Reference< XInterface > xRef( xIdCursor, UNO_QUERY );
2034             GetImport().getInterfaceToIdentifierMapper().registerReference(
2035                 m_sXmlId, xRef);
2036         }
2037     }
2038 
2039 	// insert a paragraph break
2040 	xTxtImport->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH );
2041 
2042 	// create a cursor that select the whole last paragraph
2043 	Reference < XTextCursor > xAttrCursor(
2044 		xTxtImport->GetText()->createTextCursorByRange( xStart ));
2045     if( !xAttrCursor.is() )
2046         return; // Robust (defect file)
2047 	xAttrCursor->gotoRange( xEnd, sal_True );
2048 
2049     // xml:id for RDF metadata
2050     if (m_sXmlId.getLength() || m_bHaveAbout || m_sProperty.getLength())
2051     {
2052         try {
2053             const uno::Reference<container::XEnumerationAccess> xEA
2054                 (xAttrCursor, uno::UNO_QUERY_THROW);
2055             const uno::Reference<container::XEnumeration> xEnum(
2056                 xEA->createEnumeration(), uno::UNO_QUERY_THROW);
2057             OSL_ENSURE(xEnum->hasMoreElements(), "xml:id: no paragraph?");
2058             if (xEnum->hasMoreElements()) {
2059                 uno::Reference<rdf::XMetadatable> xMeta;
2060                 xEnum->nextElement() >>= xMeta;
2061                 OSL_ENSURE(xMeta.is(), "xml:id: not XMetadatable");
2062                 GetImport().SetXmlId(xMeta, m_sXmlId);
2063                 if (m_bHaveAbout)
2064                 {
2065                     GetImport().AddRDFa(xMeta,
2066                         m_sAbout, m_sProperty, m_sContent, m_sDatatype);
2067                 }
2068                 OSL_ENSURE(!xEnum->hasMoreElements(), "xml:id: > 1 paragraph?");
2069             }
2070         } catch (uno::Exception &) {
2071             OSL_TRACE("XMLParaContext::~XMLParaContext: exception");
2072         }
2073     }
2074 
2075     OUString const sCellParaStyleName(xTxtImport->GetCellParaStyleDefault());
2076     if( sCellParaStyleName.getLength() > 0 )
2077     {
2078         // --> OD 2007-08-16 #i80724#
2079         // suppress handling of outline and list attributes,
2080         // because of side effects of method <SetStyleAndAttrs(..)>
2081         xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
2082                                       sCellParaStyleName,
2083                                       sal_True,
2084                                       sal_False, -1, // suppress outline handling
2085                                       sal_False );   // suppress list attributes handling
2086         // <--
2087     }
2088 
2089     // #103445# for headings without style name, find the proper style
2090     if( bHeading && (sStyleName.getLength() == 0) )
2091         xTxtImport->FindOutlineStyleName( sStyleName, nOutlineLevel );
2092 
2093 	// set style and hard attributes at the previous paragraph
2094     // --> OD 2007-07-25 #i73509# - add paramter <mbOutlineLevelAttrFound>
2095     sStyleName = xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
2096                                                sStyleName,
2097                                                sal_True,
2098                                                mbOutlineLevelAttrFound,
2099                                                bHeading ? nOutlineLevel : -1 );
2100     // <--
2101 
2102     // handle list style header
2103     if (bHeading && (bIsListHeader || bIsRestart))
2104     {
2105         Reference<XPropertySet> xPropSet( xAttrCursor, UNO_QUERY );
2106 
2107         if (xPropSet.is())
2108         {
2109             if (bIsListHeader)
2110             {
2111                 OUString sNumberingIsNumber
2112                     (RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber"));
2113                 if(xPropSet->getPropertySetInfo()->
2114                    hasPropertyByName(sNumberingIsNumber))
2115                 {
2116                     xPropSet->setPropertyValue
2117                         (sNumberingIsNumber, makeAny( false ) );
2118                 }
2119             }
2120             if (bIsRestart)
2121             {
2122                 OUString sParaIsNumberingRestart
2123                     (RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart"));
2124                 OUString sNumberingStartValue
2125                     (RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue"));
2126                 if (xPropSet->getPropertySetInfo()->
2127                     hasPropertyByName(sParaIsNumberingRestart))
2128                 {
2129                     xPropSet->setPropertyValue
2130                         (sParaIsNumberingRestart, makeAny(true));
2131                 }
2132 
2133                 if (xPropSet->getPropertySetInfo()->
2134                     hasPropertyByName(sNumberingStartValue))
2135                 {
2136                     xPropSet->setPropertyValue
2137                         (sNumberingStartValue, makeAny(nStartValue));
2138                 }
2139             }
2140 
2141         }
2142     }
2143 
2144 	if( pHints && pHints->Count() )
2145 	{
2146 		for( sal_uInt16 i=0; i<pHints->Count(); i++ )
2147 		{
2148 			XMLHint_Impl *pHint = (*pHints)[i];
2149 			xAttrCursor->gotoRange( pHint->GetStart(), sal_False );
2150 			xAttrCursor->gotoRange( pHint->GetEnd(), sal_True );
2151 			switch( pHint->GetType() )
2152 			{
2153 			case XML_HINT_STYLE:
2154 				{
2155 					const OUString& rStyleName =
2156 							((XMLStyleHint_Impl *)pHint)->GetStyleName();
2157 					if( rStyleName.getLength() )
2158 						xTxtImport->SetStyleAndAttrs( GetImport(),
2159 													  xAttrCursor, rStyleName,
2160                                                       sal_False );
2161 				}
2162 				break;
2163 			case XML_HINT_REFERENCE:
2164 				{
2165 					const OUString& rRefName =
2166 							((XMLReferenceHint_Impl *)pHint)->GetRefName();
2167 					if( rRefName.getLength() )
2168 					{
2169 						if( !pHint->GetEnd().is() )
2170 							pHint->SetEnd(xEnd);
2171 
2172 						// convert XCursor to XTextRange
2173 						Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2174 
2175 						// reference name uses rStyleName member
2176 						// borrow from XMLTextMarkImportContext
2177 						XMLTextMarkImportContext::CreateAndInsertMark(
2178 							GetImport(),
2179 							OUString(
2180 								RTL_CONSTASCII_USTRINGPARAM(
2181 									"com.sun.star.text.ReferenceMark")),
2182 							rRefName,
2183 							xRange);
2184 					}
2185 				}
2186 				break;
2187 			case XML_HINT_HYPERLINK:
2188 				{
2189 					const XMLHyperlinkHint_Impl *pHHint =
2190 						(const XMLHyperlinkHint_Impl *)pHint;
2191 					xTxtImport->SetHyperlink( GetImport(),
2192 											  xAttrCursor,
2193 											  pHHint->GetHRef(),
2194 											  pHHint->GetName(),
2195 											  pHHint->GetTargetFrameName(),
2196 											  pHHint->GetStyleName(),
2197 											  pHHint->GetVisitedStyleName(),
2198 											  pHHint->GetEventsContext() );
2199 				}
2200 				break;
2201 			case XML_HINT_INDEX_MARK:
2202 				{
2203 					Reference<beans::XPropertySet> xMark(
2204 						((const XMLIndexMarkHint_Impl *)pHint)->GetMark());
2205 					Reference<XTextContent> xContent(xMark,	UNO_QUERY);
2206 					Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2207 					xTxtImport->GetText()->insertTextContent(
2208 						xRange, xContent, sal_True );
2209 				}
2210 				break;
2211 			case XML_HINT_TEXT_FRAME:
2212 				{
2213 					const XMLTextFrameHint_Impl *pFHint =
2214 						(const XMLTextFrameHint_Impl *)pHint;
2215                     // --> OD 2004-08-24 #i33242# - check for text content
2216                     Reference < XTextContent > xTextContent =
2217                                                     pFHint->GetTextContent();
2218                     if ( xTextContent.is() )
2219                     {
2220                         // OD 2004-04-20 #i26791#
2221                         Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2222                         if ( pFHint->IsBoundAtChar() )
2223                         {
2224                             xTextContent->attach( xRange );
2225                         }
2226                     }
2227                     // <--
2228                     // --> OD 2004-08-24 #i33242# - consider, that hint can
2229                     // also contain a shape - e.g. drawing object of type 'Text'.
2230                     else
2231                     {
2232                         Reference < XShape > xShape = pFHint->GetShape();
2233                         if ( xShape.is() )
2234                         {
2235                             // determine anchor type
2236                             Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
2237                             TextContentAnchorType eAnchorType =
2238                                             TextContentAnchorType_AT_PARAGRAPH;
2239                             {
2240                                 OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2241                                 Any aAny = xPropSet->getPropertyValue( sAnchorType );
2242                                 aAny >>= eAnchorType;
2243                             }
2244                             if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
2245                             {
2246                                 // set anchor position for at-character anchored objects
2247                                 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2248                                 Any aPos;
2249                                 aPos <<= xRange;
2250                                 OUString sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) );
2251                                 xPropSet->setPropertyValue(sTextRange, aPos);
2252                             }
2253                         }
2254                     }
2255                     // <--
2256 				}
2257 				break;
2258 			// --> DVO, OD 2004-07-14 #i26791#
2259 			case XML_HINT_DRAW:
2260 				{
2261 					const XMLDrawHint_Impl *pDHint =
2262 						static_cast<const XMLDrawHint_Impl*>(pHint);
2263                     // --> OD 2004-08-24 #i33242# - improvement: hint directly
2264                     // provides the shape.
2265                     Reference < XShape > xShape = pDHint->GetShape();
2266                     if ( xShape.is() )
2267                     {
2268                         // determine anchor type
2269                         Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
2270                         TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
2271                         {
2272                             OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2273                             Any aAny = xPropSet->getPropertyValue( sAnchorType );
2274                             aAny >>= eAnchorType;
2275                         }
2276                         if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
2277                         {
2278                             // set anchor position for at-character anchored objects
2279                             Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
2280                             Any aPos;
2281                             aPos <<= xRange;
2282                             OUString sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) );
2283                             xPropSet->setPropertyValue(sTextRange, aPos);
2284                         }
2285                     }
2286                     // <--
2287 				}
2288 				break;
2289 			// <--
2290 
2291 			default:
2292 				DBG_ASSERT( !this, "What's this" );
2293 				break;
2294 			}
2295 		}
2296 	}
2297 	delete pHints;
2298 }
2299 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)2300 SvXMLImportContext *XMLParaContext::CreateChildContext(
2301 		sal_uInt16 nPrefix, const OUString& rLocalName,
2302 		const Reference< xml::sax::XAttributeList > & xAttrList )
2303 {
2304 	const SvXMLTokenMap& rTokenMap =
2305 		GetImport().GetTextImport()->GetTextPElemTokenMap();
2306 	sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
2307 	if( !pHints )
2308 		pHints = new XMLHints_Impl;
2309 	return XMLImpSpanContext_Impl::CreateChildContext(
2310 								GetImport(), nPrefix, rLocalName, xAttrList,
2311 							   	nToken, *pHints, bIgnoreLeadingSpace
2312 								, nStarFontsConvFlags
2313 													 );
2314 }
2315 
Characters(const OUString & rChars)2316 void XMLParaContext::Characters( const OUString& rChars )
2317 {
2318 	OUString sChars =
2319 		GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
2320 													   nStarFontsConvFlags,
2321 													   sal_True, GetImport() );
2322 	GetImport().GetTextImport()->InsertString( sChars, bIgnoreLeadingSpace );
2323 }
2324 
2325 
2326 
2327 TYPEINIT1( XMLNumberedParaContext, SvXMLImportContext );
2328 
XMLNumberedParaContext(SvXMLImport & i_rImport,sal_uInt16 i_nPrefix,const OUString & i_rLocalName,const Reference<xml::sax::XAttributeList> & i_xAttrList)2329 XMLNumberedParaContext::XMLNumberedParaContext(
2330         SvXMLImport& i_rImport,
2331         sal_uInt16 i_nPrefix,
2332         const OUString& i_rLocalName,
2333         const Reference< xml::sax::XAttributeList > & i_xAttrList ) :
2334     SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName ),
2335     m_Level(0),
2336     m_StartValue(-1),
2337     m_ListId(),
2338     m_xNumRules()
2339 {
2340     ::rtl::OUString StyleName;
2341 
2342     const SvXMLTokenMap& rTokenMap(
2343         i_rImport.GetTextImport()->GetTextNumberedParagraphAttrTokenMap() );
2344 
2345     const sal_Int16 nAttrCount( i_xAttrList.is() ?
2346         i_xAttrList->getLength() : 0 );
2347     for ( sal_Int16 i=0; i < nAttrCount; i++ )
2348     {
2349         const ::rtl::OUString& rAttrName( i_xAttrList->getNameByIndex( i )  );
2350         const ::rtl::OUString& rValue   ( i_xAttrList->getValueByIndex( i ) );
2351 
2352         ::rtl::OUString aLocalName;
2353         const sal_uInt16 nPrefix(
2354             GetImport().GetNamespaceMap().GetKeyByAttrName(
2355                 rAttrName, &aLocalName ) );
2356         switch( rTokenMap.Get( nPrefix, aLocalName ) )
2357         {
2358             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_XMLID:
2359                 m_XmlId = rValue;
2360 //FIXME: there is no UNO API for lists
2361                 break;
2362             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LIST_ID:
2363                 m_ListId = rValue;
2364                 break;
2365             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LEVEL:
2366                 {
2367                     sal_Int32 nTmp = rValue.toInt32();
2368                     if ( nTmp >= 1 && nTmp <= SHRT_MAX ) {
2369                         m_Level = static_cast<sal_uInt16>(nTmp) - 1;
2370                     }
2371                 }
2372                 break;
2373             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_STYLE_NAME:
2374                 StyleName = rValue;
2375                 break;
2376             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_CONTINUE_NUMBERING:
2377                 // this attribute is deprecated
2378 //                ContinuteNumbering = IsXMLToken(rValue, XML_TRUE);
2379                 break;
2380             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_START_VALUE:
2381                 {
2382                     sal_Int32 nTmp = rValue.toInt32();
2383                     if ( nTmp >= 0 && nTmp <= SHRT_MAX ) {
2384                         m_StartValue = static_cast<sal_Int16>(nTmp);
2385                     }
2386                 }
2387                 break;
2388         }
2389     }
2390 
2391     XMLTextListsHelper& rTextListsHelper(
2392         i_rImport.GetTextImport()->GetTextListHelper() );
2393     if (!m_ListId.getLength()) {
2394         OSL_ENSURE( ! i_rImport.GetODFVersion().equalsAsciiL(
2395                         RTL_CONSTASCII_STRINGPARAM("1.2") ),
2396             "invalid numbered-paragraph: no list-id (1.2)");
2397         m_ListId = rTextListsHelper.GetNumberedParagraphListId(m_Level,
2398             StyleName);
2399         OSL_ENSURE(m_ListId.getLength(), "numbered-paragraph: no ListId");
2400         if (!m_ListId.getLength()) {
2401             return;
2402         }
2403     }
2404     m_xNumRules = rTextListsHelper.EnsureNumberedParagraph( i_rImport,
2405         m_ListId, m_Level, StyleName);
2406 
2407     OSL_ENSURE(m_xNumRules.is(), "numbered-paragraph: no NumRules");
2408 
2409     i_rImport.GetTextImport()->GetTextListHelper().PushListContext( this );
2410 }
2411 
~XMLNumberedParaContext()2412 XMLNumberedParaContext::~XMLNumberedParaContext()
2413 {
2414 }
2415 
EndElement()2416 void XMLNumberedParaContext::EndElement()
2417 {
2418     if (m_ListId.getLength()) {
2419         GetImport().GetTextImport()->PopListContext();
2420     }
2421 }
2422 
CreateChildContext(sal_uInt16 i_nPrefix,const OUString & i_rLocalName,const Reference<xml::sax::XAttributeList> & i_xAttrList)2423 SvXMLImportContext *XMLNumberedParaContext::CreateChildContext(
2424     sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
2425     const Reference< xml::sax::XAttributeList > & i_xAttrList )
2426 {
2427     SvXMLImportContext *pContext( 0 );
2428 
2429     if ( XML_NAMESPACE_TEXT == i_nPrefix )
2430     {
2431         bool bIsHeader( IsXMLToken( i_rLocalName, XML_H ) );
2432         if ( bIsHeader || IsXMLToken( i_rLocalName, XML_P ) )
2433         {
2434             pContext = new XMLParaContext( GetImport(),
2435                 i_nPrefix, i_rLocalName, i_xAttrList, bIsHeader );
2436 // ignore text:number       } else if (IsXMLToken( i_rLocalName, XML_NUMBER )) {
2437         }
2438     }
2439 
2440     if (!pContext) {
2441         pContext = SvXMLImportContext::CreateChildContext(
2442             i_nPrefix, i_rLocalName, i_xAttrList );
2443     }
2444 
2445     return pContext;
2446 }
2447