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