xref: /AOO41X/main/xmloff/source/text/txtparae.cxx (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
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 <tools/debug.hxx>
28 #ifndef _SVSTDARR_LONGS_DECL
29 #define _SVSTDARR_LONGS
30 #include <svl/svstdarr.hxx>
31 #endif
32 #include <svl/svarray.hxx>
33 #include <rtl/ustrbuf.hxx>
34 #include <sal/types.h>
35 
36 #include <vector>
37 #include <list>
38 #include <hash_map>
39 
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/container/XEnumerationAccess.hpp>
42 #include <com/sun/star/container/XEnumeration.hpp>
43 #include <com/sun/star/container/XIndexReplace.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/beans/XMultiPropertySet.hpp>
46 #include <com/sun/star/beans/XPropertyState.hpp>
47 #include <com/sun/star/text/XTextDocument.hpp>
48 #include <com/sun/star/text/XTextSectionsSupplier.hpp>
49 #include <com/sun/star/text/XTextTablesSupplier.hpp>
50 #include <com/sun/star/text/XNumberingRulesSupplier.hpp>
51 #include <com/sun/star/text/XChapterNumberingSupplier.hpp>//#outline level,add by zhaojianwei
52 #include <com/sun/star/text/XTextTable.hpp>
53 #include <com/sun/star/text/XText.hpp>
54 #include <com/sun/star/text/XTextContent.hpp>
55 #include <com/sun/star/text/XTextRange.hpp>
56 #include <com/sun/star/text/XTextField.hpp>
57 #include <com/sun/star/text/XFootnote.hpp>
58 #include <com/sun/star/container/XNamed.hpp>
59 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
60 #include <com/sun/star/text/XTextFrame.hpp>
61 #include <com/sun/star/container/XNameAccess.hpp>
62 #include <com/sun/star/text/SizeType.hpp>
63 #include <com/sun/star/text/HoriOrientation.hpp>
64 #include <com/sun/star/text/VertOrientation.hpp>
65 #include <com/sun/star/text/TextContentAnchorType.hpp>
66 #include <com/sun/star/text/XTextFramesSupplier.hpp>
67 #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
68 #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
69 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
70 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
71 #include <com/sun/star/document/XEventsSupplier.hpp>
72 #include <com/sun/star/document/XRedlinesSupplier.hpp>
73 
74 #include <com/sun/star/text/XBookmarksSupplier.hpp>
75 #include <com/sun/star/text/XFormField.hpp>
76 
77 #include <com/sun/star/text/XTextSection.hpp>
78 #include <com/sun/star/text/SectionFileLink.hpp>
79 #include <com/sun/star/drawing/XShape.hpp>
80 #include <com/sun/star/text/XTextShapesSupplier.hpp>
81 
82 #include <com/sun/star/style/XAutoStylesSupplier.hpp>
83 #include <com/sun/star/style/XAutoStyleFamily.hpp>
84 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
85 #include <com/sun/star/text/XFootnotesSupplier.hpp>
86 #include <com/sun/star/text/XEndnotesSupplier.hpp>
87 #include <com/sun/star/drawing/XControlShape.hpp>
88 #include <com/sun/star/util/DateTime.hpp>
89 #include "xmloff/xmlnmspe.hxx"
90 #include <xmloff/xmlaustp.hxx>
91 #include <xmloff/families.hxx>
92 #include "txtexppr.hxx"
93 #include <xmloff/xmlnumfe.hxx>
94 #include <xmloff/xmlnume.hxx>
95 #include <xmloff/xmluconv.hxx>
96 #include "XMLAnchorTypePropHdl.hxx"
97 #include "xexptran.hxx"
98 #include <xmloff/ProgressBarHelper.hxx>
99 #include <xmloff/nmspmap.hxx>
100 #include <xmloff/xmlexp.hxx>
101 #include "txtflde.hxx"
102 #include <xmloff/txtprmap.hxx>
103 #include "XMLImageMapExport.hxx"
104 #include "XMLTextNumRuleInfo.hxx"
105 #include "xmloff/XMLTextListAutoStylePool.hxx"
106 #include <xmloff/txtparae.hxx>
107 #include "XMLSectionExport.hxx"
108 #include "XMLIndexMarkExport.hxx"
109 #include <xmloff/XMLEventExport.hxx>
110 #include "XMLRedlineExport.hxx"
111 #include "MultiPropertySetHelper.hxx"
112 #include <xmloff/formlayerexport.hxx>
113 #include "XMLTextCharStyleNamesElementExport.hxx"
114 #include <comphelper/stlunosequence.hxx>
115 
116 // --> OD 2008-04-25 #refactorlists#
117 #include <txtlists.hxx>
118 // <--
119 #include <com/sun/star/rdf/XMetadatable.hpp>
120 
121 using ::rtl::OUString;
122 using ::rtl::OUStringBuffer;
123 
124 using namespace ::std;
125 using namespace ::com::sun::star;
126 using namespace ::com::sun::star::uno;
127 using namespace ::com::sun::star::lang;
128 using namespace ::com::sun::star::beans;
129 using namespace ::com::sun::star::container;
130 using namespace ::com::sun::star::text;
131 using namespace ::com::sun::star::style;
132 using namespace ::com::sun::star::util;
133 using namespace ::com::sun::star::drawing;
134 using namespace ::com::sun::star::document;
135 using namespace ::com::sun::star::frame;
136 using namespace ::xmloff;
137 using namespace ::xmloff::token;
138 
139 namespace
140 {
141     class TextContentSet
142     {
143         public:
144             typedef Reference<XTextContent> text_content_ref_t;
145             typedef list<text_content_ref_t> contents_t;
146             typedef back_insert_iterator<contents_t> inserter_t;
147             typedef contents_t::const_iterator const_iterator_t;
148 
149             inserter_t getInserter()
150                 { return back_insert_iterator<contents_t>(m_vTextContents); };
151             const_iterator_t getBegin() const
152                 { return m_vTextContents.begin(); };
153             const_iterator_t getEnd() const
154                 { return m_vTextContents.end(); };
155 
156         private:
157             contents_t m_vTextContents;
158     };
159 
160     struct FrameRefHash
161         : public unary_function<Reference<XTextFrame>, size_t>
162     {
163         size_t operator()(const Reference<XTextFrame> xFrame) const
164             { return sal::static_int_cast<size_t>(reinterpret_cast<sal_uIntPtr>(xFrame.get())); }
165     };
166 
167     static bool lcl_TextContentsUnfiltered(const Reference<XTextContent>&)
168         { return true; };
169 
170     static bool lcl_ShapeFilter(const Reference<XTextContent>& xTxtContent)
171     {
172         static const OUString sTextFrameService = OUString::createFromAscii("com.sun.star.text.TextFrame");
173         static const OUString sTextGraphicService = OUString::createFromAscii("com.sun.star.text.TextGraphicObject");
174         static const OUString sTextEmbeddedService = OUString::createFromAscii("com.sun.star.text.TextEmbeddedObject");
175         Reference<XShape> xShape(xTxtContent, UNO_QUERY);
176         if(!xShape.is())
177             return false;
178         Reference<XServiceInfo> xServiceInfo(xTxtContent, UNO_QUERY);
179         if(xServiceInfo->supportsService(sTextFrameService) ||
180             xServiceInfo->supportsService(sTextGraphicService) ||
181             xServiceInfo->supportsService(sTextEmbeddedService) )
182             return false;
183         return true;
184     };
185 
186     class BoundFrames
187     {
188         public:
189             typedef bool (*filter_t)(const Reference<XTextContent>&);
190             BoundFrames(
191                 const Reference<XEnumerationAccess> xEnumAccess,
192                 const filter_t& rFilter)
193                 : m_xEnumAccess(xEnumAccess)
194             {
195                 Fill(rFilter);
196             };
197             BoundFrames()
198                 {};
199             const TextContentSet* GetPageBoundContents() const
200                 { return &m_vPageBounds; };
201             const TextContentSet* GetFrameBoundContents(const Reference<XTextFrame>& rParentFrame) const
202             {
203                 framebound_map_t::const_iterator it = m_vFrameBoundsOf.find(rParentFrame);
204                 if(it == m_vFrameBoundsOf.end())
205                     return NULL;
206                 return &(it->second);
207             };
208             Reference<XEnumeration> createEnumeration() const
209             {
210                 if(!m_xEnumAccess.is())
211                     return Reference<XEnumeration>();
212                 return m_xEnumAccess->createEnumeration();
213             };
214 
215         private:
216             typedef hash_map<
217                 Reference<XTextFrame>,
218                 TextContentSet,
219                 FrameRefHash> framebound_map_t;
220             TextContentSet m_vPageBounds;
221             framebound_map_t m_vFrameBoundsOf;
222             const Reference<XEnumerationAccess> m_xEnumAccess;
223             void Fill(const filter_t& rFilter);
224             static const OUString our_sAnchorType;
225             static const OUString our_sAnchorFrame;
226     };
227     const OUString BoundFrames::our_sAnchorType = OUString::createFromAscii("AnchorType");
228     const OUString BoundFrames::our_sAnchorFrame = OUString::createFromAscii("AnchorFrame");
229 
230     class FieldParamExporter
231     {
232         public:
233             FieldParamExporter(SvXMLExport* const pExport, Reference<XNameContainer> xFieldParams)
234                 : m_pExport(pExport)
235                 , m_xFieldParams(xFieldParams)
236                 { };
237             void Export();
238 
239         private:
240             SvXMLExport* const m_pExport;
241             const Reference<XNameContainer> m_xFieldParams;
242 
243             void ExportParameter(const OUString& sKey, const OUString& sValue);
244     };
245 }
246 
247 namespace xmloff
248 {
249     class BoundFrameSets
250     {
251         public:
252             BoundFrameSets(const Reference<XInterface> xModel);
253             const BoundFrames* GetTexts() const
254                 { return m_pTexts.get(); };
255             const BoundFrames* GetGraphics() const
256                 { return m_pGraphics.get(); };
257             const BoundFrames* GetEmbeddeds() const
258                 { return m_pEmbeddeds.get(); };
259             const BoundFrames* GetShapes() const
260                 { return m_pShapes.get(); };
261         private:
262             auto_ptr<BoundFrames> m_pTexts;
263             auto_ptr<BoundFrames> m_pGraphics;
264             auto_ptr<BoundFrames> m_pEmbeddeds;
265             auto_ptr<BoundFrames> m_pShapes;
266     };
267 }
268 
269 typedef OUString *OUStringPtr;
270 SV_DECL_PTRARR_DEL( OUStrings_Impl, OUStringPtr, 20, 10 )
271 SV_IMPL_PTRARR( OUStrings_Impl, OUStringPtr )
272 
273 SV_DECL_PTRARR_SORT_DEL( OUStringsSort_Impl, OUStringPtr, 20, 10 )
274 SV_IMPL_OP_PTRARR_SORT( OUStringsSort_Impl, OUStringPtr )
275 
276 #ifdef DBG_UTIL
277 static int txtparae_bContainsIllegalCharacters = sal_False;
278 #endif
279 
280 // The following map shows which property values are required:
281 //
282 // property                     auto style pass     export
283 // --------------------------------------------------------
284 // ParaStyleName                if style exists     always
285 // ParaConditionalStyleName     if style exists     always
286 // NumberingRules               if style exists     always
287 // TextSection                  always              always
288 // ParaChapterNumberingLevel    never               always
289 // NumberingIsNumber            never               always
290 
291 // The conclusion is that for auto styles the first three properties
292 // should be queried using a multi property set if, and only if, an
293 // auto style needs to be exported. TextSection should be queried by
294 // an individual call to getPropertyvalue, because this seems to be
295 // less expensive than querying the first three properties if they aren't
296 // required.
297 
298 // For the export pass all properties can be queried using a multi property
299 // set.
300 
301 static const sal_Char* aParagraphPropertyNamesAuto[] =
302 {
303     "NumberingRules",
304     "ParaConditionalStyleName",
305     "ParaStyleName",
306     NULL
307 };
308 
309 enum eParagraphPropertyNamesEnumAuto
310 {
311     NUMBERING_RULES_AUTO = 0,
312     PARA_CONDITIONAL_STYLE_NAME_AUTO = 1,
313     PARA_STYLE_NAME_AUTO = 2
314 };
315 
316 static const sal_Char* aParagraphPropertyNames[] =
317 {
318     "NumberingIsNumber",
319     "NumberingStyleName",           //#outline level,add by zhaojianwei
320 
321     //"ParaChapterNumberingLevel",  //#outline level,remove by zhaojianwei
322     "OutlineLevel",                 //<-end,add by zhaojianwei
323     "ParaConditionalStyleName",
324     "ParaStyleName",
325     "TextSection",
326     NULL
327 };
328 
329 enum eParagraphPropertyNamesEnum
330 {
331     NUMBERING_IS_NUMBER = 0,
332     PARA_NUMBERING_STYLENAME = 1,       //#outline level,add by zhaojianwei
333     //PARA_CHAPTER_NUMERBING_LEVEL = 1, //#outline level,remove by zhaojianwei
334     PARA_OUTLINE_LEVEL=2,               //<-end.add by zhaojianwei
335     PARA_CONDITIONAL_STYLE_NAME = 3,
336     PARA_STYLE_NAME = 4,
337     TEXT_SECTION = 5
338 };
339 
340 void BoundFrames::Fill(const filter_t& rFilter)
341 {
342     if(!m_xEnumAccess.is())
343         return;
344     const Reference< XEnumeration > xEnum = m_xEnumAccess->createEnumeration();
345     if(!xEnum.is())
346         return;
347     while(xEnum->hasMoreElements())
348     {
349         Reference<XPropertySet> xPropSet(xEnum->nextElement(), UNO_QUERY);
350         Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
351         if(!xPropSet.is() || !xTextContent.is())
352             continue;
353         TextContentAnchorType eAnchor;
354         xPropSet->getPropertyValue(our_sAnchorType) >>= eAnchor;
355         if(TextContentAnchorType_AT_PAGE != eAnchor && TextContentAnchorType_AT_FRAME != eAnchor)
356             continue;
357         if(!rFilter(xTextContent))
358             continue;
359 
360         TextContentSet::inserter_t pInserter = m_vPageBounds.getInserter();
361         if(TextContentAnchorType_AT_FRAME == eAnchor)
362         {
363             Reference<XTextFrame> xAnchorTxtFrame(
364                 xPropSet->getPropertyValue(our_sAnchorFrame),
365                 uno::UNO_QUERY);
366             pInserter = m_vFrameBoundsOf[xAnchorTxtFrame].getInserter();
367         }
368         *pInserter++ = xTextContent;
369     }
370 }
371 
372 BoundFrameSets::BoundFrameSets(const Reference<XInterface> xModel)
373     : m_pTexts(new BoundFrames())
374     , m_pGraphics(new BoundFrames())
375     , m_pEmbeddeds(new BoundFrames())
376     , m_pShapes(new BoundFrames())
377 {
378     const Reference<XTextFramesSupplier> xTFS(xModel, UNO_QUERY);
379     const Reference<XTextGraphicObjectsSupplier> xGOS(xModel, UNO_QUERY);
380     const Reference<XTextEmbeddedObjectsSupplier> xEOS(xModel, UNO_QUERY);
381     const Reference<XDrawPageSupplier> xDPS(xModel, UNO_QUERY);
382     if(xTFS.is())
383         m_pTexts = auto_ptr<BoundFrames>(new BoundFrames(
384             Reference<XEnumerationAccess>(xTFS->getTextFrames(), UNO_QUERY),
385             &lcl_TextContentsUnfiltered));
386     if(xGOS.is())
387         m_pGraphics = auto_ptr<BoundFrames>(new BoundFrames(
388             Reference<XEnumerationAccess>(xGOS->getGraphicObjects(), UNO_QUERY),
389             &lcl_TextContentsUnfiltered));
390     if(xEOS.is())
391         m_pEmbeddeds = auto_ptr<BoundFrames>(new BoundFrames(
392             Reference<XEnumerationAccess>(xEOS->getEmbeddedObjects(), UNO_QUERY),
393             &lcl_TextContentsUnfiltered));
394     if(xDPS.is())
395         m_pShapes = auto_ptr<BoundFrames>(new BoundFrames(
396             Reference<XEnumerationAccess>(xDPS->getDrawPage(), UNO_QUERY),
397             &lcl_ShapeFilter));
398 };
399 
400 void FieldParamExporter::Export()
401 {
402     static const Type aStringType = ::getCppuType((OUString*)0);
403     static const Type aBoolType = ::getCppuType((sal_Bool*)0);
404     static const Type aSeqType = ::getCppuType((Sequence<OUString>*)0);
405     static const Type aIntType = ::getCppuType((sal_Int32*)0);
406     Sequence<OUString> vParameters(m_xFieldParams->getElementNames());
407     for(const OUString* pCurrent=::comphelper::stl_begin(vParameters); pCurrent!=::comphelper::stl_end(vParameters); ++pCurrent)
408     {
409         const Any aValue = m_xFieldParams->getByName(*pCurrent);
410         const Type aValueType = aValue.getValueType();
411         if(aValueType == aStringType)
412         {
413             OUString sValue;
414             aValue >>= sValue;
415             ExportParameter(*pCurrent,sValue);
416         }
417         else if(aValueType == aBoolType)
418         {
419             sal_Bool bValue = false;
420             aValue >>= bValue;
421             ExportParameter(*pCurrent,OUString::createFromAscii(bValue ? "true" : "false"));
422         }
423         else if(aValueType == aSeqType)
424         {
425             Sequence<OUString> vValue;
426             aValue >>= vValue;
427             for(OUString* pSeqCurrent = ::comphelper::stl_begin(vValue); pSeqCurrent != ::comphelper::stl_end(vValue); ++pSeqCurrent)
428             {
429                 ExportParameter(*pCurrent, *pSeqCurrent);
430             }
431         }
432         else if(aValueType == aIntType)
433         {
434             sal_Int32 nValue = 0;
435             aValue >>= nValue;
436             ExportParameter(*pCurrent, OUStringBuffer().append(nValue).makeStringAndClear());
437         }
438     }
439 }
440 
441 void FieldParamExporter::ExportParameter(const OUString& sKey, const OUString& sValue)
442 {
443     m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, sKey);
444     m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, sValue);
445     m_pExport->StartElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
446     m_pExport->EndElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
447 }
448 
449 void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
450                                   const Reference < XPropertySet > & rPropSet,
451                                   const XMLPropertyState** ppAddStates, bool bDontSeek )
452 {
453     UniReference < SvXMLExportPropertyMapper > xPropMapper;
454     switch( nFamily )
455     {
456     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
457         xPropMapper = GetParaPropMapper();
458         break;
459     case XML_STYLE_FAMILY_TEXT_TEXT:
460         xPropMapper = GetTextPropMapper();
461         break;
462     case XML_STYLE_FAMILY_TEXT_FRAME:
463         xPropMapper = GetAutoFramePropMapper();
464         break;
465     case XML_STYLE_FAMILY_TEXT_SECTION:
466         xPropMapper = GetSectionPropMapper();
467         break;
468     case XML_STYLE_FAMILY_TEXT_RUBY:
469         xPropMapper = GetRubyPropMapper();
470         break;
471     }
472     DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" );
473 
474     vector< XMLPropertyState > xPropStates =
475             xPropMapper->Filter( rPropSet );
476 
477     if( ppAddStates )
478     {
479         while( *ppAddStates )
480         {
481             xPropStates.push_back( **ppAddStates );
482             ppAddStates++;
483         }
484     }
485 
486     if( !xPropStates.empty() )
487     {
488         Reference< XPropertySetInfo > xPropSetInfo(rPropSet->getPropertySetInfo());
489         OUString sParent, sCondParent;
490         sal_uInt16 nIgnoreProps = 0;
491         switch( nFamily )
492         {
493         case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
494             if( xPropSetInfo->hasPropertyByName( sParaStyleName ) )
495             {
496                 rPropSet->getPropertyValue( sParaStyleName ) >>= sParent;
497             }
498             if( xPropSetInfo->hasPropertyByName( sParaConditionalStyleName ) )
499             {
500                 rPropSet->getPropertyValue( sParaConditionalStyleName ) >>= sCondParent;
501             }
502             if( xPropSetInfo->hasPropertyByName( sNumberingRules ) )
503             {
504                 Reference < XIndexReplace > xNumRule(rPropSet->getPropertyValue( sNumberingRules ), uno::UNO_QUERY);
505                 if( xNumRule.is() && xNumRule->getCount() )
506                 {
507                     Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
508                     OUString sName;
509                     if( xNamed.is() )
510                         sName = xNamed->getName();
511                     sal_Bool bAdd = !sName.getLength();
512                     if( !bAdd )
513                     {
514                         Reference < XPropertySet > xNumPropSet( xNumRule,
515                                                                 UNO_QUERY );
516                         const OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) );
517                         if( xNumPropSet.is() &&
518                             xNumPropSet->getPropertySetInfo()
519                                        ->hasPropertyByName( sIsAutomatic ) )
520                         {
521                             bAdd = *(sal_Bool *)xNumPropSet->getPropertyValue( sIsAutomatic ).getValue();
522                             // --> OD 2007-01-12 #i73361# - check on outline style
523                             const OUString sNumberingIsOutline( RTL_CONSTASCII_USTRINGPARAM( "NumberingIsOutline" ) );
524                             if ( bAdd &&
525                                  xNumPropSet->getPropertySetInfo()
526                                            ->hasPropertyByName( sNumberingIsOutline ) )
527                             {
528                                 bAdd = !(*(sal_Bool *)xNumPropSet->getPropertyValue( sNumberingIsOutline ).getValue());
529                             }
530                             // <--
531                         }
532                         else
533                         {
534                             bAdd = sal_True;
535                         }
536                     }
537                     if( bAdd )
538                         pListAutoPool->Add( xNumRule );
539                 }
540             }
541             break;
542         case XML_STYLE_FAMILY_TEXT_TEXT:
543             {
544                 // Get parent and remove hyperlinks (they aren't of interest)
545                 UniReference< XMLPropertySetMapper > xPM(xPropMapper->getPropertySetMapper());
546                 for( ::std::vector< XMLPropertyState >::iterator i(xPropStates.begin());
547                      nIgnoreProps < 2 && i != xPropStates.end(); )
548                 {
549                     if( i->mnIndex == -1 )
550                     {
551                         ++i;
552                         continue;
553                     }
554 
555                     switch( xPM->GetEntryContextId(i->mnIndex) )
556                     {
557                     case CTF_CHAR_STYLE_NAME:
558                     case CTF_HYPERLINK_URL:
559                         i->mnIndex = -1;
560                         nIgnoreProps++;
561                         i = xPropStates.erase( i );
562                         break;
563                     default:
564                         ++i;
565                         break;
566                     }
567                 }
568             }
569             break;
570         case XML_STYLE_FAMILY_TEXT_FRAME:
571             if( xPropSetInfo->hasPropertyByName( sFrameStyleName ) )
572             {
573                 rPropSet->getPropertyValue( sFrameStyleName ) >>= sParent;
574             }
575             break;
576         case XML_STYLE_FAMILY_TEXT_SECTION:
577         case XML_STYLE_FAMILY_TEXT_RUBY:
578             ; // section styles have no parents
579             break;
580         }
581         if( (xPropStates.size() - nIgnoreProps) > 0 )
582         {
583             GetAutoStylePool().Add( nFamily, sParent, xPropStates, bDontSeek );
584             if( sCondParent.getLength() && sParent != sCondParent )
585                 GetAutoStylePool().Add( nFamily, sCondParent, xPropStates );
586         }
587     }
588 }
589 
590 bool lcl_validPropState( const XMLPropertyState& rState )
591 {
592     return rState.mnIndex != -1;
593 }
594 
595 void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
596                                   MultiPropertySetHelper& rPropSetHelper,
597                                   const Reference < XPropertySet > & rPropSet,
598                                   const XMLPropertyState** ppAddStates)
599 {
600     UniReference < SvXMLExportPropertyMapper > xPropMapper;
601     switch( nFamily )
602     {
603     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
604         xPropMapper = GetParaPropMapper();
605         break;
606     }
607     DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" );
608 
609     vector< XMLPropertyState > xPropStates(xPropMapper->Filter( rPropSet ));
610     if( ppAddStates )
611     {
612         while( *ppAddStates )
613         {
614             xPropStates.push_back( **ppAddStates );
615             ++ppAddStates;
616         }
617     }
618 
619     if( rPropSetHelper.hasProperty( NUMBERING_RULES_AUTO ) )
620     {
621         Reference < XIndexReplace > xNumRule(rPropSetHelper.getValue( NUMBERING_RULES_AUTO,
622             rPropSet, sal_True ), uno::UNO_QUERY);
623         if( xNumRule.is() && xNumRule->getCount() )
624         {
625             Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
626             OUString sName;
627             if( xNamed.is() )
628                 sName = xNamed->getName();
629             sal_Bool bAdd = !sName.getLength();
630             if( !bAdd )
631             {
632                 Reference < XPropertySet > xNumPropSet( xNumRule,
633                                                         UNO_QUERY );
634                 const OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) );
635                 if( xNumPropSet.is() &&
636                     xNumPropSet->getPropertySetInfo()
637                                ->hasPropertyByName( sIsAutomatic ) )
638                 {
639                     bAdd = *(sal_Bool *)xNumPropSet->getPropertyValue( sIsAutomatic ).getValue();
640                     // --> OD 2007-01-12 #i73361# - check on outline style
641                     const OUString sNumberingIsOutline( RTL_CONSTASCII_USTRINGPARAM( "NumberingIsOutline" ) );
642                     if ( bAdd &&
643                          xNumPropSet->getPropertySetInfo()
644                                    ->hasPropertyByName( sNumberingIsOutline ) )
645                     {
646                         bAdd = !(*(sal_Bool *)xNumPropSet->getPropertyValue( sNumberingIsOutline ).getValue());
647                     }
648                     // <--
649                 }
650                 else
651                 {
652                     bAdd = sal_True;
653                 }
654             }
655             if( bAdd )
656                 pListAutoPool->Add( xNumRule );
657         }
658     }
659 
660     if( !xPropStates.empty() )
661     {
662         OUString sParent, sCondParent;
663         switch( nFamily )
664         {
665         case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
666             if( rPropSetHelper.hasProperty( PARA_STYLE_NAME_AUTO ) )
667             {
668                 rPropSetHelper.getValue( PARA_STYLE_NAME_AUTO, rPropSet,
669                                                 sal_True ) >>= sParent;
670             }
671             if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME_AUTO ) )
672             {
673                 rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME_AUTO,
674                                                 rPropSet, sal_True ) >>= sCondParent;
675             }
676 
677             break;
678         }
679 
680         if( find_if( xPropStates.begin(), xPropStates.end(), lcl_validPropState ) != xPropStates.end() )
681         {
682             GetAutoStylePool().Add( nFamily, sParent, xPropStates );
683             if( sCondParent.getLength() && sParent != sCondParent )
684                 GetAutoStylePool().Add( nFamily, sCondParent, xPropStates );
685         }
686     }
687 }
688 
689 OUString XMLTextParagraphExport::Find(
690         sal_uInt16 nFamily,
691         const Reference < XPropertySet > & rPropSet,
692         const OUString& rParent,
693         const XMLPropertyState** ppAddStates) const
694 {
695     OUString sName( rParent );
696     UniReference < SvXMLExportPropertyMapper > xPropMapper;
697     switch( nFamily )
698     {
699     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
700         xPropMapper = GetParaPropMapper();
701         break;
702     case XML_STYLE_FAMILY_TEXT_FRAME:
703         xPropMapper = GetAutoFramePropMapper();
704         break;
705     case XML_STYLE_FAMILY_TEXT_SECTION:
706         xPropMapper = GetSectionPropMapper();
707         break;
708     case XML_STYLE_FAMILY_TEXT_RUBY:
709         xPropMapper = GetRubyPropMapper();
710         break;
711     }
712     DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" );
713     if( !xPropMapper.is() )
714         return sName;
715     vector< XMLPropertyState > xPropStates(xPropMapper->Filter( rPropSet ));
716     if( ppAddStates )
717     {
718         while( *ppAddStates )
719         {
720             xPropStates.push_back( **ppAddStates );
721             ++ppAddStates;
722         }
723     }
724     if( find_if( xPropStates.begin(), xPropStates.end(), lcl_validPropState ) != xPropStates.end() )
725         sName = GetAutoStylePool().Find( nFamily, sName, xPropStates );
726 
727     return sName;
728 }
729 
730 OUString XMLTextParagraphExport::FindTextStyleAndHyperlink(
731         const Reference < XPropertySet > & rPropSet,
732         sal_Bool& rbHyperlink,
733         sal_Bool& rbHasCharStyle,
734         sal_Bool& rbHasAutoStyle,
735         const XMLPropertyState** ppAddStates ) const
736 {
737     UniReference < SvXMLExportPropertyMapper > xPropMapper(GetTextPropMapper());
738     vector< XMLPropertyState > xPropStates(xPropMapper->Filter( rPropSet ));
739 
740     // Get parent and remove hyperlinks (they aren't of interest)
741     OUString sName;
742     rbHyperlink = rbHasCharStyle = rbHasAutoStyle = sal_False;
743     sal_uInt16 nIgnoreProps = 0;
744     UniReference< XMLPropertySetMapper > xPM(xPropMapper->getPropertySetMapper());
745     ::std::vector< XMLPropertyState >::iterator aFirstDel = xPropStates.end();
746     ::std::vector< XMLPropertyState >::iterator aSecondDel = xPropStates.end();
747 
748     for( ::std::vector< XMLPropertyState >::iterator
749             i = xPropStates.begin();
750          nIgnoreProps < 2 && i != xPropStates.end();
751          i++ )
752     {
753         if( i->mnIndex == -1 )
754             continue;
755 
756         switch( xPM->GetEntryContextId(i->mnIndex) )
757         {
758         case CTF_CHAR_STYLE_NAME:
759             i->maValue >>= sName;
760             i->mnIndex = -1;
761             rbHasCharStyle = sName.getLength() > 0;
762             if( nIgnoreProps )
763                 aSecondDel = i;
764             else
765                 aFirstDel = i;
766             nIgnoreProps++;
767             break;
768         case CTF_HYPERLINK_URL:
769             rbHyperlink = sal_True;
770             i->mnIndex = -1;
771             if( nIgnoreProps )
772                 aSecondDel = i;
773             else
774                 aFirstDel = i;
775             nIgnoreProps++;
776             break;
777         }
778     }
779     if( ppAddStates )
780     {
781         while( *ppAddStates )
782         {
783             xPropStates.push_back( **ppAddStates );
784             ppAddStates++;
785         }
786     }
787     if( (xPropStates.size() - nIgnoreProps) > 0L )
788     {
789         // erase the character style, otherwise the autostyle cannot be found!
790         // erase the hyperlink, otherwise the autostyle cannot be found!
791         if ( nIgnoreProps )
792         {
793             // If two elements of a vector have to be deleted,
794             // we should delete the second one first.
795             if( --nIgnoreProps )
796                 xPropStates.erase( aSecondDel );
797             xPropStates.erase( aFirstDel );
798         }
799         OUString sParent; // AutoStyles should not have parents!
800         sName = GetAutoStylePool().Find( XML_STYLE_FAMILY_TEXT_TEXT, sParent, xPropStates );
801         DBG_ASSERT( sName.getLength(), "AutoStyle could not be found" );
802         rbHasAutoStyle = sal_True;
803     }
804 
805     return sName;
806 }
807 
808 OUString XMLTextParagraphExport::FindTextStyle(
809         const Reference < XPropertySet > & rPropSet,
810         sal_Bool& rHasCharStyle ) const
811 {
812     sal_Bool bDummy;
813     sal_Bool bDummy2;
814     return FindTextStyleAndHyperlink( rPropSet, bDummy, rHasCharStyle, bDummy2 );
815 }
816 
817 
818 // --> OD 2008-04-25 #refactorlists#
819 // adjustments to support lists independent from list style
820 void XMLTextParagraphExport::exportListChange(
821         const XMLTextNumRuleInfo& rPrevInfo,
822         const XMLTextNumRuleInfo& rNextInfo )
823 {
824     // end a list
825     if ( rPrevInfo.GetLevel() > 0 )
826     {
827         bool bRootListToBeClosed = false;
828         sal_Int16 nListLevelsToBeClosed = 0;
829         if ( !rNextInfo.BelongsToSameList( rPrevInfo ) ||
830              rNextInfo.GetLevel() <= 0 )
831         {
832             // close complete previous list
833             bRootListToBeClosed = true;
834             nListLevelsToBeClosed = rPrevInfo.GetLevel();
835         }
836         else if ( rPrevInfo.GetLevel() > rNextInfo.GetLevel() )
837         {
838             // close corresponding sub lists
839             DBG_ASSERT( rNextInfo.GetLevel() > 0,
840                         "<rPrevInfo.GetLevel() > 0> not hold. Serious defect -> please inform OD." );
841             nListLevelsToBeClosed = rPrevInfo.GetLevel() - rNextInfo.GetLevel();
842         }
843 
844         if ( nListLevelsToBeClosed > 0 &&
845              pListElements &&
846              pListElements->Count() >= ( 2 * nListLevelsToBeClosed ) )
847         {
848             do {
849                 for( sal_uInt16 j = 0; j < 2; ++j )
850                 {
851                     OUString *pElem = (*pListElements)[pListElements->Count()-1];
852                     pListElements->Remove( pListElements->Count()-1 );
853 
854                     GetExport().EndElement( *pElem, sal_True );
855 
856                     delete pElem;
857                 }
858 
859                 // remove closed list from list stack
860                 mpTextListsHelper->PopListFromStack();
861 
862                 --nListLevelsToBeClosed;
863             } while ( nListLevelsToBeClosed > 0 );
864         }
865     }
866 
867     const bool bExportODF =
868                 ( GetExport().getExportFlags() & EXPORT_OASIS ) != 0;
869     const SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion =
870                                     GetExport().getDefaultVersion();
871 
872     // start a new list
873     if ( rNextInfo.GetLevel() > 0 )
874     {
875         bool bRootListToBeStarted = false;
876         sal_Int16 nListLevelsToBeOpened = 0;
877         if ( !rPrevInfo.BelongsToSameList( rNextInfo ) ||
878              rPrevInfo.GetLevel() <= 0 )
879         {
880             // new root list
881             bRootListToBeStarted = true;
882             nListLevelsToBeOpened = rNextInfo.GetLevel();
883         }
884         else if ( rNextInfo.GetLevel() > rPrevInfo.GetLevel() )
885         {
886             // open corresponding sub lists
887             DBG_ASSERT( rPrevInfo.GetLevel() > 0,
888                         "<rPrevInfo.GetLevel() > 0> not hold. Serious defect -> please inform OD." );
889             nListLevelsToBeOpened = rNextInfo.GetLevel() - rPrevInfo.GetLevel();
890         }
891 
892         if ( nListLevelsToBeOpened > 0 )
893         {
894             const ::rtl::OUString sListStyleName( rNextInfo.GetNumRulesName() );
895             // Currently only the text documents support <ListId>.
896             // Thus, for other document types <sListId> is empty.
897             const ::rtl::OUString sListId( rNextInfo.GetListId() );
898             bool bExportListStyle( true );
899             bool bRestartNumberingAtContinuedRootList( false );
900             sal_Int16 nRestartValueForContinuedRootList( -1 );
901             // --> OD 2008-11-26 #158694#
902             bool bContinueingPreviousSubList = !bRootListToBeStarted &&
903                                                rNextInfo.IsContinueingPreviousSubTree();
904             // <--
905             do {
906                 GetExport().CheckAttrList();
907 
908                 if ( bRootListToBeStarted )
909                 {
910                     if ( !mpTextListsHelper->IsListProcessed( sListId ) )
911                     {
912                         if ( bExportODF &&
913                              eODFDefaultVersion >= SvtSaveOptions::ODFVER_012 &&
914                              sListId.getLength() > 0 )
915                         {
916                             // --> OD 2008-07-31 #i92221#
917                             GetExport().AddAttribute( XML_NAMESPACE_XML,
918                                                       XML_ID,
919                                                       sListId );
920                             // <--
921                         }
922                         mpTextListsHelper->KeepListAsProcessed( sListId,
923                                                                 sListStyleName,
924                                                                 ::rtl::OUString() );
925                     }
926                     else
927                     {
928                         const ::rtl::OUString sNewListId(
929                                         mpTextListsHelper->GenerateNewListId() );
930                         if ( bExportODF &&
931                              eODFDefaultVersion >= SvtSaveOptions::ODFVER_012 &&
932                              sListId.getLength() > 0 )
933                         {
934                             // --> OD 2008-07-31 #i92221#
935                             GetExport().AddAttribute( XML_NAMESPACE_XML,
936                                                       XML_ID,
937                                                       sNewListId );
938                             // <--
939                         }
940 
941                         const ::rtl::OUString sContinueListId =
942                             mpTextListsHelper->GetLastContinuingListId( sListId );
943                         // store that list with list id <sNewListId> is last list,
944                         // which has continued list with list id <sListId>
945                         mpTextListsHelper->StoreLastContinuingList( sListId,
946                                                                     sNewListId );
947                         if ( sListStyleName ==
948                                 mpTextListsHelper->GetListStyleOfLastProcessedList() &&
949                              // --> OD 2008-08-15 #i92811#
950                              sContinueListId ==
951                                 mpTextListsHelper->GetLastProcessedListId() &&
952                              // <--
953                              !rNextInfo.IsRestart() )
954                         {
955                             GetExport().AddAttribute( XML_NAMESPACE_TEXT,
956                                                       XML_CONTINUE_NUMBERING,
957                                                       XML_TRUE );
958                         }
959                         else
960                         {
961                             if ( bExportODF &&
962                                  eODFDefaultVersion >= SvtSaveOptions::ODFVER_012 &&
963                                  sListId.getLength() > 0 )
964                             {
965                                 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
966                                                           XML_CONTINUE_LIST,
967                                                           sContinueListId );
968                             }
969 
970                             if ( rNextInfo.IsRestart() &&
971                                  ( nListLevelsToBeOpened != 1 ||
972                                    !rNextInfo.HasStartValue() ) )
973                             {
974                                 bRestartNumberingAtContinuedRootList = true;
975                                 nRestartValueForContinuedRootList =
976                                                 rNextInfo.GetListLevelStartValue();
977                             }
978                         }
979 
980                         mpTextListsHelper->KeepListAsProcessed( sNewListId,
981                                                                 sListStyleName,
982                                                                 sContinueListId );
983                     }
984 
985                     GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
986                             GetExport().EncodeStyleName( sListStyleName ) );
987                     bExportListStyle = false;
988 
989                     bRootListToBeStarted = false;
990                 }
991                 else if ( bExportListStyle &&
992                           !mpTextListsHelper->EqualsToTopListStyleOnStack( sListStyleName ) )
993                 {
994                     GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
995                             GetExport().EncodeStyleName( sListStyleName ) );
996                     bExportListStyle = false;
997                 }
998 
999                 // --> OD 2008-11-26 #158694#
1000                 if ( bContinueingPreviousSubList )
1001                 {
1002                     GetExport().AddAttribute( XML_NAMESPACE_TEXT,
1003                                               XML_CONTINUE_NUMBERING, XML_TRUE );
1004                     bContinueingPreviousSubList = false;
1005                 }
1006                 // <--
1007 
1008                 enum XMLTokenEnum eLName = XML_LIST;
1009 
1010                 OUString *pElem = new OUString(
1011                         GetExport().GetNamespaceMap().GetQNameByKey(
1012                                             XML_NAMESPACE_TEXT,
1013                                             GetXMLToken(eLName) ) );
1014                 GetExport().IgnorableWhitespace();
1015                 GetExport().StartElement( *pElem, sal_False );
1016 
1017                 if( !pListElements )
1018                     pListElements = new OUStrings_Impl;
1019                 pListElements->Insert( pElem, pListElements->Count() );
1020 
1021                 mpTextListsHelper->PushListOnStack( sListId,
1022                                                     sListStyleName );
1023 
1024                 // <text:list-header> or <text:list-item>
1025                 GetExport().CheckAttrList();
1026 
1027                 // --> OD 2009-06-24 #i97309#
1028                 // export start value in case of <bRestartNumberingAtContinuedRootList>
1029                 // at correct list item
1030                 if ( nListLevelsToBeOpened == 1 )
1031                 {
1032                     if ( rNextInfo.HasStartValue() )
1033                     {
1034                         OUStringBuffer aBuffer;
1035                         aBuffer.append( (sal_Int32)rNextInfo.GetStartValue() );
1036                         GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
1037                                       aBuffer.makeStringAndClear() );
1038                     }
1039                     else if ( bRestartNumberingAtContinuedRootList )
1040                     {
1041                         OUStringBuffer aBuffer;
1042                         aBuffer.append( (sal_Int32)nRestartValueForContinuedRootList );
1043                         GetExport().AddAttribute( XML_NAMESPACE_TEXT,
1044                                                   XML_START_VALUE,
1045                                                   aBuffer.makeStringAndClear() );
1046                         bRestartNumberingAtContinuedRootList = false;
1047                     }
1048                 }
1049                 // <--
1050 
1051                 eLName = ( rNextInfo.IsNumbered() || nListLevelsToBeOpened > 1 )
1052                          ? XML_LIST_ITEM
1053                          : XML_LIST_HEADER;
1054                 pElem = new OUString(  GetExport().GetNamespaceMap().GetQNameByKey(
1055                                             XML_NAMESPACE_TEXT,
1056                                             GetXMLToken(eLName) ) );
1057                 GetExport().IgnorableWhitespace();
1058                 GetExport().StartElement( *pElem, sal_False );
1059 
1060                 pListElements->Insert( pElem, pListElements->Count() );
1061 
1062                 // --> OD 2008-11-26 #158694#
1063                 // export of <text:number> element for last opened <text:list-item>, if requested
1064                 if ( GetExport().exportTextNumberElement() &&
1065                      eLName == XML_LIST_ITEM && nListLevelsToBeOpened == 1 && // last iteration --> last opened <text:list-item>
1066                      rNextInfo.ListLabelString().getLength() > 0 )
1067                 {
1068                     const ::rtl::OUString aTextNumberElem =
1069                             OUString( GetExport().GetNamespaceMap().GetQNameByKey(
1070                                       XML_NAMESPACE_TEXT,
1071                                       GetXMLToken(XML_NUMBER) ) );
1072                     GetExport().IgnorableWhitespace();
1073                     GetExport().StartElement( aTextNumberElem, sal_False );
1074                     GetExport().Characters( rNextInfo.ListLabelString() );
1075                     GetExport().EndElement( aTextNumberElem, sal_True );
1076                 }
1077                 // <--
1078 
1079                 --nListLevelsToBeOpened;
1080             } while ( nListLevelsToBeOpened > 0 );
1081         }
1082     }
1083 
1084     if ( rNextInfo.GetLevel() > 0 &&
1085          rNextInfo.IsNumbered() &&
1086          rPrevInfo.BelongsToSameList( rNextInfo ) &&
1087          rPrevInfo.GetLevel() >= rNextInfo.GetLevel() )
1088     {
1089         // close previous list-item
1090         DBG_ASSERT( pListElements && pListElements->Count() >= 2,
1091                 "SwXMLExport::ExportListChange: list elements missing" );
1092 
1093         OUString *pElem = (*pListElements)[pListElements->Count()-1];
1094         GetExport().EndElement( *pElem, sal_True );
1095 
1096         pListElements->Remove( pListElements->Count()-1 );
1097         delete pElem;
1098 
1099         // --> OD 2009-11-12 #i103745# - only for sub lists
1100         if ( rNextInfo.IsRestart() && !rNextInfo.HasStartValue() &&
1101              rNextInfo.GetLevel() != 1 )
1102         // <--
1103         {
1104             // start new sub list respectively list on same list level
1105             pElem = (*pListElements)[pListElements->Count()-1];
1106             GetExport().EndElement( *pElem, sal_True );
1107             GetExport().IgnorableWhitespace();
1108             GetExport().StartElement( *pElem, sal_False );
1109         }
1110 
1111         // open new list-item
1112         GetExport().CheckAttrList();
1113         if( rNextInfo.HasStartValue() )
1114         {
1115             OUStringBuffer aBuffer;
1116             aBuffer.append( (sal_Int32)rNextInfo.GetStartValue() );
1117             GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
1118                                       aBuffer.makeStringAndClear() );
1119         }
1120         // --> OD 2009-11-12 #i103745# - handle restart without start value on list level 1
1121         else if ( rNextInfo.IsRestart() && /*!rNextInfo.HasStartValue() &&*/
1122                   rNextInfo.GetLevel() == 1 )
1123         {
1124             OUStringBuffer aBuffer;
1125             aBuffer.append( (sal_Int32)rNextInfo.GetListLevelStartValue() );
1126             GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
1127                                       aBuffer.makeStringAndClear() );
1128         }
1129         // <--
1130         if ( ( GetExport().getExportFlags() & EXPORT_OASIS ) != 0 &&
1131              GetExport().getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
1132         {
1133             const ::rtl::OUString sListStyleName( rNextInfo.GetNumRulesName() );
1134             if ( !mpTextListsHelper->EqualsToTopListStyleOnStack( sListStyleName ) )
1135             {
1136                 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
1137                                           XML_STYLE_OVERRIDE,
1138                                           GetExport().EncodeStyleName( sListStyleName ) );
1139             }
1140         }
1141         pElem = new OUString( GetExport().GetNamespaceMap().GetQNameByKey(
1142                                 XML_NAMESPACE_TEXT,
1143                                 GetXMLToken(XML_LIST_ITEM) ) );
1144         GetExport().IgnorableWhitespace();
1145         GetExport().StartElement( *pElem, sal_False );
1146 
1147         pListElements->Insert( pElem, pListElements->Count() );
1148 
1149         // --> OD 2008-11-26 #158694#
1150         // export of <text:number> element for <text:list-item>, if requested
1151         if ( GetExport().exportTextNumberElement() &&
1152              rNextInfo.ListLabelString().getLength() > 0 )
1153         {
1154             const ::rtl::OUString aTextNumberElem =
1155                     OUString( GetExport().GetNamespaceMap().GetQNameByKey(
1156                               XML_NAMESPACE_TEXT,
1157                               GetXMLToken(XML_NUMBER) ) );
1158             GetExport().IgnorableWhitespace();
1159             GetExport().StartElement( aTextNumberElem, sal_False );
1160             GetExport().Characters( rNextInfo.ListLabelString() );
1161             GetExport().EndElement( aTextNumberElem, sal_True );
1162         }
1163         // <--
1164     }
1165 }
1166 // <--
1167 
1168 XMLTextParagraphExport::XMLTextParagraphExport(
1169         SvXMLExport& rExp,
1170         SvXMLAutoStylePoolP & rASP
1171         ) :
1172     XMLStyleExport( rExp, OUString(), &rASP ),
1173     rAutoStylePool( rASP ),
1174     pBoundFrameSets(new BoundFrameSets(GetExport().GetModel())),
1175     pFieldExport( 0 ),
1176     pListElements( 0 ),
1177     // --> OD 2008-05-07 #refactorlists# - no longer needed
1178 //    pExportedLists( 0 ),
1179     // <--
1180     pListAutoPool( new XMLTextListAutoStylePool( this->GetExport() ) ),
1181     pSectionExport( NULL ),
1182     pIndexMarkExport( NULL ),
1183 
1184     pRedlineExport( NULL ),
1185     pHeadingStyles( NULL ),
1186 
1187     bProgress( sal_False ),
1188     bBlock( sal_False ),
1189 
1190     bOpenRuby( sal_False ),
1191     // --> OD 2008-04-25 #refactorlists#
1192     mpTextListsHelper( 0 ),
1193     maTextListsHelperStack(),
1194     // <--
1195 
1196     sActualSize(RTL_CONSTASCII_USTRINGPARAM("ActualSize")),
1197     // --> OD 2009-07-22 #i73249#
1198 //    sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")),
1199     sTitle(RTL_CONSTASCII_USTRINGPARAM("Title")),
1200     sDescription(RTL_CONSTASCII_USTRINGPARAM("Description")),
1201     // <--
1202     sAnchorCharStyleName(RTL_CONSTASCII_USTRINGPARAM("AnchorCharStyleName")),
1203     sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")),
1204     sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")),
1205     sBeginNotice(RTL_CONSTASCII_USTRINGPARAM("BeginNotice")),
1206     sBookmark(RTL_CONSTASCII_USTRINGPARAM("Bookmark")),
1207     sCategory(RTL_CONSTASCII_USTRINGPARAM("Category")),
1208     sChainNextName(RTL_CONSTASCII_USTRINGPARAM("ChainNextName")),
1209     sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")),
1210     sCharStyleNames(RTL_CONSTASCII_USTRINGPARAM("CharStyleNames")),
1211     sContourPolyPolygon(RTL_CONSTASCII_USTRINGPARAM("ContourPolyPolygon")),
1212     sDocumentIndex(RTL_CONSTASCII_USTRINGPARAM("DocumentIndex")),
1213     sDocumentIndexMark(RTL_CONSTASCII_USTRINGPARAM("DocumentIndexMark")),
1214     sEndNotice(RTL_CONSTASCII_USTRINGPARAM("EndNotice")),
1215     sFootnote(RTL_CONSTASCII_USTRINGPARAM("Footnote")),
1216     sFootnoteCounting(RTL_CONSTASCII_USTRINGPARAM("FootnoteCounting")),
1217     sFrame(RTL_CONSTASCII_USTRINGPARAM("Frame")),
1218     sFrameHeightAbsolute(RTL_CONSTASCII_USTRINGPARAM("FrameHeightAbsolute")),
1219     sFrameHeightPercent(RTL_CONSTASCII_USTRINGPARAM("FrameHeightPercent")),
1220     sFrameStyleName(RTL_CONSTASCII_USTRINGPARAM("FrameStyleName")),
1221     sFrameWidthAbsolute(RTL_CONSTASCII_USTRINGPARAM("FrameWidthAbsolute")),
1222     sFrameWidthPercent(RTL_CONSTASCII_USTRINGPARAM("FrameWidthPercent")),
1223     sGraphicFilter(RTL_CONSTASCII_USTRINGPARAM("GraphicFilter")),
1224     sGraphicRotation(RTL_CONSTASCII_USTRINGPARAM("GraphicRotation")),
1225     sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")),
1226     sReplacementGraphicURL(RTL_CONSTASCII_USTRINGPARAM("ReplacementGraphicURL")),
1227     sHeight(RTL_CONSTASCII_USTRINGPARAM("Height")),
1228     sHoriOrient(RTL_CONSTASCII_USTRINGPARAM("HoriOrient")),
1229     sHoriOrientPosition(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition")),
1230     sHyperLinkName(RTL_CONSTASCII_USTRINGPARAM("HyperLinkName")),
1231     sHyperLinkTarget(RTL_CONSTASCII_USTRINGPARAM("HyperLinkTarget")),
1232     sHyperLinkURL(RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL")),
1233     sIsAutomaticContour(RTL_CONSTASCII_USTRINGPARAM("IsAutomaticContour")),
1234     sIsCollapsed(RTL_CONSTASCII_USTRINGPARAM("IsCollapsed")),
1235     sIsPixelContour(RTL_CONSTASCII_USTRINGPARAM("IsPixelContour")),
1236     sIsStart(RTL_CONSTASCII_USTRINGPARAM("IsStart")),
1237     sIsSyncHeightToWidth(RTL_CONSTASCII_USTRINGPARAM("IsSyncHeightToWidth")),
1238     sIsSyncWidthToHeight(RTL_CONSTASCII_USTRINGPARAM("IsSyncWidthToHeight")),
1239     sNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules")),
1240     sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")),
1241     sPageDescName(RTL_CONSTASCII_USTRINGPARAM("PageDescName")),
1242     sPageStyleName(RTL_CONSTASCII_USTRINGPARAM("PageStyleName")),
1243     sParaChapterNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("ParaChapterNumberingLevel")),
1244     sParaConditionalStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaConditionalStyleName")),
1245     sParagraphService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph")),
1246     sParaStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")),
1247     sPositionEndOfDoc(RTL_CONSTASCII_USTRINGPARAM("PositionEndOfDoc")),
1248     sPrefix(RTL_CONSTASCII_USTRINGPARAM("Prefix")),
1249     sRedline(RTL_CONSTASCII_USTRINGPARAM("Redline")),
1250     sReferenceId(RTL_CONSTASCII_USTRINGPARAM("ReferenceId")),
1251     sReferenceMark(RTL_CONSTASCII_USTRINGPARAM("ReferenceMark")),
1252     sRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("RelativeHeight")),
1253     sRelativeWidth(RTL_CONSTASCII_USTRINGPARAM("RelativeWidth")),
1254     sRuby(RTL_CONSTASCII_USTRINGPARAM("Ruby")),
1255     sRubyAdjust(RTL_CONSTASCII_USTRINGPARAM("RubyAdjust")),
1256     sRubyCharStyleName(RTL_CONSTASCII_USTRINGPARAM("RubyCharStyleName")),
1257     sRubyText(RTL_CONSTASCII_USTRINGPARAM("RubyText")),
1258     sServerMap(RTL_CONSTASCII_USTRINGPARAM("ServerMap")),
1259     sShapeService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Shape")),
1260     sSizeType(RTL_CONSTASCII_USTRINGPARAM("SizeType")),
1261     sSoftPageBreak( RTL_CONSTASCII_USTRINGPARAM( "SoftPageBreak" ) ),
1262     sStartAt(RTL_CONSTASCII_USTRINGPARAM("StartAt")),
1263     sSuffix(RTL_CONSTASCII_USTRINGPARAM("Suffix")),
1264     sTableService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextTable")),
1265     sText(RTL_CONSTASCII_USTRINGPARAM("Text")),
1266     sTextContentService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextContent")),
1267     sTextEmbeddedService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextEmbeddedObject")),
1268     sTextEndnoteService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Endnote")),
1269     sTextField(RTL_CONSTASCII_USTRINGPARAM("TextField")),
1270     sTextFieldService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField")),
1271     sTextFrameService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame")),
1272     sTextGraphicService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextGraphicObject")),
1273     sTextPortionType(RTL_CONSTASCII_USTRINGPARAM("TextPortionType")),
1274     sTextSection(RTL_CONSTASCII_USTRINGPARAM("TextSection")),
1275     sUnvisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("UnvisitedCharStyleName")),
1276     sVertOrient(RTL_CONSTASCII_USTRINGPARAM("VertOrient")),
1277     sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition")),
1278     sVisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("VisitedCharStyleName")),
1279     sWidth(RTL_CONSTASCII_USTRINGPARAM("Width")),
1280     sWidthType( RTL_CONSTASCII_USTRINGPARAM( "WidthType" ) ),
1281     sTextFieldStart( RTL_CONSTASCII_USTRINGPARAM( "TextFieldStart" ) ),
1282     sTextFieldEnd( RTL_CONSTASCII_USTRINGPARAM( "TextFieldEnd" ) ),
1283     sTextFieldStartEnd( RTL_CONSTASCII_USTRINGPARAM( "TextFieldStartEnd" ) ),
1284     aCharStyleNamesPropInfoCache( sCharStyleNames )
1285 {
1286     UniReference < XMLPropertySetMapper > xPropMapper(new XMLTextPropertySetMapper( TEXT_PROP_MAP_PARA ));
1287     xParaPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1288                                                           GetExport() );
1289 
1290     OUString sFamily( GetXMLToken(XML_PARAGRAPH) );
1291     OUString aPrefix( String( 'P' ) );
1292     rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_PARAGRAPH, sFamily,
1293                               xParaPropMapper, aPrefix );
1294 
1295     xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT );
1296     xTextPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1297                                                           GetExport() );
1298     sFamily = OUString( GetXMLToken(XML_TEXT) );
1299     aPrefix = OUString( String( 'T' ) );
1300     rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_TEXT, sFamily,
1301                               xTextPropMapper, aPrefix );
1302 
1303     xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_AUTO_FRAME );
1304     xAutoFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1305                                                                GetExport() );
1306     sFamily = OUString( RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME) );
1307     aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "fr" ) );
1308     rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_FRAME, sFamily,
1309                               xAutoFramePropMapper, aPrefix );
1310 
1311     xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_SECTION );
1312     xSectionPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1313                                                              GetExport() );
1314     sFamily = OUString( GetXMLToken( XML_SECTION ) );
1315     aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "Sect" ) );
1316     rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_SECTION, sFamily,
1317                               xSectionPropMapper, aPrefix );
1318 
1319     xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_RUBY );
1320     xRubyPropMapper = new SvXMLExportPropertyMapper( xPropMapper );
1321     sFamily = OUString( GetXMLToken( XML_RUBY ) );
1322     aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "Ru" ) );
1323     rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_RUBY, sFamily,
1324                               xRubyPropMapper, aPrefix );
1325 
1326     xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_FRAME );
1327     xFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
1328                                                            GetExport() );
1329 
1330     pSectionExport = new XMLSectionExport( rExp, *this );
1331     pIndexMarkExport = new XMLIndexMarkExport( rExp, *this );
1332 
1333     if( ! IsBlockMode() &&
1334         Reference<XRedlinesSupplier>( GetExport().GetModel(), UNO_QUERY ).is())
1335         pRedlineExport = new XMLRedlineExport( rExp );
1336 
1337     // The text field helper needs a pre-constructed XMLPropertyState
1338     // to export the combined characters field. We construct that
1339     // here, because we need the text property mapper to do it.
1340 
1341     // construct Any value, then find index
1342     sal_Int32 nIndex = xTextPropMapper->getPropertySetMapper()->FindEntryIndex(
1343                                 "", XML_NAMESPACE_STYLE,
1344                                 GetXMLToken(XML_TEXT_COMBINE));
1345     pFieldExport = new XMLTextFieldExport( rExp, new XMLPropertyState( nIndex, uno::makeAny(sal_True) ) );
1346 
1347     // --> OD 2008-05-08 #refactorlists#
1348     PushNewTextListsHelper();
1349     // <--
1350 }
1351 
1352 XMLTextParagraphExport::~XMLTextParagraphExport()
1353 {
1354     delete pHeadingStyles;
1355     delete pRedlineExport;
1356     delete pIndexMarkExport;
1357     delete pSectionExport;
1358     delete pFieldExport;
1359     delete pListElements;
1360     // --> OD 2008-05-07 #refactorlists# - no longer needed
1361 //    delete pExportedLists;
1362     // <--
1363     delete pListAutoPool;
1364 #ifdef DBG_UTIL
1365     txtparae_bContainsIllegalCharacters = sal_False;
1366 #endif
1367     // --> OD 2008-04-25 #refactorlists#
1368     // also deletes <mpTextListsHelper>
1369     PopTextListsHelper();
1370     DBG_ASSERT( maTextListsHelperStack.size() == 0,
1371                 "misusage of text lists helper stack - it is not empty. Serious defect - please inform OD" );
1372     // <--
1373 }
1374 
1375 SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateShapeExtPropMapper(
1376         SvXMLExport& rExport )
1377 {
1378     UniReference < XMLPropertySetMapper > xPropMapper =
1379         new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE );
1380     return new XMLTextExportPropertySetMapper( xPropMapper, rExport );
1381 }
1382 
1383 SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateCharExtPropMapper(
1384         SvXMLExport& rExport)
1385 {
1386     XMLPropertySetMapper *pPropMapper =
1387         new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT );
1388     return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
1389 }
1390 
1391 SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateParaExtPropMapper(
1392         SvXMLExport& rExport)
1393 {
1394     XMLPropertySetMapper *pPropMapper =
1395         new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE_PARA );
1396     return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
1397 }
1398 
1399 SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateParaDefaultExtPropMapper(
1400         SvXMLExport& rExport)
1401 {
1402     XMLPropertySetMapper *pPropMapper =
1403         new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT_ADDITIONAL_DEFAULTS );
1404     return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
1405 }
1406 
1407 void XMLTextParagraphExport::exportPageFrames( sal_Bool bAutoStyles,
1408                                                sal_Bool bIsProgress )
1409 {
1410     const TextContentSet* const pTexts = pBoundFrameSets->GetTexts()->GetPageBoundContents();
1411     const TextContentSet* const pGraphics = pBoundFrameSets->GetGraphics()->GetPageBoundContents();
1412     const TextContentSet* const pEmbeddeds = pBoundFrameSets->GetEmbeddeds()->GetPageBoundContents();
1413     const TextContentSet* const pShapes = pBoundFrameSets->GetShapes()->GetPageBoundContents();
1414     for(TextContentSet::const_iterator_t it = pTexts->getBegin();
1415         it != pTexts->getEnd();
1416         ++it)
1417         exportTextFrame(*it, bAutoStyles, bIsProgress, sal_True);
1418     for(TextContentSet::const_iterator_t it = pGraphics->getBegin();
1419         it != pGraphics->getEnd();
1420         ++it)
1421         exportTextGraphic(*it, bAutoStyles);
1422     for(TextContentSet::const_iterator_t it = pEmbeddeds->getBegin();
1423         it != pEmbeddeds->getEnd();
1424         ++it)
1425         exportTextEmbedded(*it, bAutoStyles);
1426     for(TextContentSet::const_iterator_t it = pShapes->getBegin();
1427         it != pShapes->getEnd();
1428         ++it)
1429         exportShape(*it, bAutoStyles);
1430 }
1431 
1432 void XMLTextParagraphExport::exportFrameFrames(
1433         sal_Bool bAutoStyles,
1434         sal_Bool bIsProgress,
1435         const Reference < XTextFrame > *pParentTxtFrame )
1436 {
1437     const TextContentSet* const pTexts = pBoundFrameSets->GetTexts()->GetFrameBoundContents(*pParentTxtFrame);
1438     if(pTexts)
1439         for(TextContentSet::const_iterator_t it = pTexts->getBegin();
1440             it != pTexts->getEnd();
1441             ++it)
1442             exportTextFrame(*it, bAutoStyles, bIsProgress, sal_True);
1443     const TextContentSet* const pGraphics = pBoundFrameSets->GetGraphics()->GetFrameBoundContents(*pParentTxtFrame);
1444     if(pGraphics)
1445         for(TextContentSet::const_iterator_t it = pGraphics->getBegin();
1446             it != pGraphics->getEnd();
1447             ++it)
1448             exportTextGraphic(*it, bAutoStyles);
1449     const TextContentSet* const pEmbeddeds = pBoundFrameSets->GetEmbeddeds()->GetFrameBoundContents(*pParentTxtFrame);
1450     if(pEmbeddeds)
1451         for(TextContentSet::const_iterator_t it = pEmbeddeds->getBegin();
1452             it != pEmbeddeds->getEnd();
1453             ++it)
1454             exportTextEmbedded(*it, bAutoStyles);
1455     const TextContentSet* const pShapes = pBoundFrameSets->GetShapes()->GetFrameBoundContents(*pParentTxtFrame);
1456     if(pShapes)
1457         for(TextContentSet::const_iterator_t it = pShapes->getBegin();
1458             it != pShapes->getEnd();
1459             ++it)
1460             exportShape(*it, bAutoStyles);
1461 }
1462 
1463 // bookmarks, reference marks (and TOC marks) are the same except for the
1464 // element names. We use the same method for export and it an array with
1465 // the proper element names
1466 static const enum XMLTokenEnum lcl_XmlReferenceElements[] = {
1467     XML_REFERENCE_MARK, XML_REFERENCE_MARK_START, XML_REFERENCE_MARK_END };
1468 static const enum XMLTokenEnum lcl_XmlBookmarkElements[] = {
1469     XML_BOOKMARK, XML_BOOKMARK_START, XML_BOOKMARK_END };
1470 
1471 // This function replaces the text portion iteration during auto style
1472 // collection.
1473 bool XMLTextParagraphExport::collectTextAutoStylesOptimized( sal_Bool bIsProgress )
1474 {
1475     GetExport().GetShapeExport(); // make sure the graphics styles family is added
1476 
1477     const sal_Bool bAutoStyles = sal_True;
1478     const sal_Bool bExportContent = sal_False;
1479 
1480     // Export AutoStyles:
1481     Reference< XAutoStylesSupplier > xAutoStylesSupp( GetExport().GetModel(), UNO_QUERY );
1482     if ( xAutoStylesSupp.is() )
1483     {
1484         Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
1485         OUString sName;
1486         sal_uInt16 nFamily;
1487 
1488         for ( int i = 0; i < 3; ++i )
1489         {
1490             if ( 0 == i )
1491             {
1492                 sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
1493                 nFamily = XML_STYLE_FAMILY_TEXT_TEXT;
1494             }
1495             else if ( 1 == i )
1496             {
1497                 sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "RubyStyles" ) );
1498                 nFamily = XML_STYLE_FAMILY_TEXT_RUBY;
1499             }
1500             else
1501             {
1502                 sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) );
1503                 nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH;
1504             }
1505 
1506             Any aAny = xAutoStyleFamilies->getByName( sName );
1507             Reference< XAutoStyleFamily > xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue();
1508             Reference < XEnumeration > xAutoStylesEnum( xAutoStyles->createEnumeration() );
1509 
1510             while ( xAutoStylesEnum->hasMoreElements() )
1511             {
1512                 aAny = xAutoStylesEnum->nextElement();
1513                 Reference< XAutoStyle > xAutoStyle = *(Reference<XAutoStyle>*)aAny.getValue();
1514                 Reference < XPropertySet > xPSet( xAutoStyle, uno::UNO_QUERY );
1515                 Add( nFamily, xPSet, 0, true );
1516             }
1517         }
1518     }
1519 
1520     // Export Field AutoStyles:
1521     Reference< XTextFieldsSupplier > xTextFieldsSupp( GetExport().GetModel(), UNO_QUERY );
1522     if ( xTextFieldsSupp.is() )
1523     {
1524         Reference< XEnumerationAccess > xTextFields = xTextFieldsSupp->getTextFields();
1525         Reference < XEnumeration > xTextFieldsEnum( xTextFields->createEnumeration() );
1526 
1527         while ( xTextFieldsEnum->hasMoreElements() )
1528         {
1529             Any aAny = xTextFieldsEnum->nextElement();
1530             Reference< XTextField > xTextField = *(Reference<XTextField>*)aAny.getValue();
1531             exportTextField( xTextField, bAutoStyles, bIsProgress,
1532                 !xAutoStylesSupp.is() );
1533             try
1534             {
1535                 Reference < XPropertySet > xSet( xTextField, UNO_QUERY );
1536                 Reference < XText > xText;
1537                 Any a = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("TextRange") );
1538                 a >>= xText;
1539                 if ( xText.is() )
1540                 {
1541                     exportText( xText, sal_True, bIsProgress, bExportContent );
1542                     GetExport().GetTextParagraphExport()
1543                         ->collectTextAutoStyles( xText );
1544                 }
1545             }
1546             catch (Exception&)
1547             {
1548             }
1549         }
1550     }
1551 
1552     // Export text frames:
1553     Reference<XEnumeration> xTextFramesEnum = pBoundFrameSets->GetTexts()->createEnumeration();
1554     if(xTextFramesEnum.is())
1555         while(xTextFramesEnum->hasMoreElements())
1556         {
1557             Reference<XTextContent> xTxtCntnt(xTextFramesEnum->nextElement(), UNO_QUERY);
1558             if(xTxtCntnt.is())
1559                 exportTextFrame(xTxtCntnt, bAutoStyles, bIsProgress, bExportContent, 0);
1560         }
1561 
1562     // Export graphic objects:
1563     Reference<XEnumeration> xGraphicsEnum = pBoundFrameSets->GetGraphics()->createEnumeration();
1564     if(xGraphicsEnum.is())
1565         while(xGraphicsEnum->hasMoreElements())
1566         {
1567             Reference<XTextContent> xTxtCntnt(xGraphicsEnum->nextElement(), UNO_QUERY);
1568             if(xTxtCntnt.is())
1569                 exportTextGraphic(xTxtCntnt, true, 0);
1570         }
1571 
1572     // Export embedded objects:
1573     Reference<XEnumeration> xEmbeddedsEnum = pBoundFrameSets->GetEmbeddeds()->createEnumeration();
1574     if(xEmbeddedsEnum.is())
1575         while(xEmbeddedsEnum->hasMoreElements())
1576         {
1577             Reference<XTextContent> xTxtCntnt(xEmbeddedsEnum->nextElement(), UNO_QUERY);
1578             if(xTxtCntnt.is())
1579                 exportTextEmbedded(xTxtCntnt, true, 0);
1580         }
1581 
1582     // Export shapes:
1583     Reference<XEnumeration> xShapesEnum = pBoundFrameSets->GetShapes()->createEnumeration();
1584     if(xShapesEnum.is())
1585         while(xShapesEnum->hasMoreElements())
1586         {
1587             Reference<XTextContent> xTxtCntnt(xShapesEnum->nextElement(), UNO_QUERY);
1588             if(xTxtCntnt.is())
1589             {
1590                 Reference<XServiceInfo> xServiceInfo(xTxtCntnt, UNO_QUERY);
1591                 if( xServiceInfo->supportsService(sShapeService))
1592                     exportShape(xTxtCntnt, true, 0);
1593             }
1594         }
1595 
1596     sal_Int32 nCount;
1597     // AutoStyles for sections
1598     Reference< XTextSectionsSupplier > xSectionsSupp( GetExport().GetModel(), UNO_QUERY );
1599     if ( xSectionsSupp.is() )
1600     {
1601         Reference< XIndexAccess > xSections( xSectionsSupp->getTextSections(), UNO_QUERY );
1602         if ( xSections.is() )
1603         {
1604             nCount = xSections->getCount();
1605             for( sal_Int32 i = 0; i < nCount; ++i )
1606             {
1607                 Any aAny = xSections->getByIndex( i );
1608                 Reference< XTextSection > xSection = *(Reference<XTextSection>*)aAny.getValue();
1609                 Reference < XPropertySet > xPSet( xSection, uno::UNO_QUERY );
1610                 Add( XML_STYLE_FAMILY_TEXT_SECTION, xPSet );
1611             }
1612         }
1613     }
1614 
1615     // AutoStyles for tables (Note: suppress autostyle collection for paragraphs in exportTable)
1616     Reference< XTextTablesSupplier > xTablesSupp( GetExport().GetModel(), UNO_QUERY );
1617     if ( xTablesSupp.is() )
1618     {
1619         Reference< XIndexAccess > xTables( xTablesSupp->getTextTables(), UNO_QUERY );
1620         if ( xTables.is() )
1621         {
1622             nCount = xTables->getCount();
1623             for( sal_Int32 i = 0; i < nCount; ++i )
1624             {
1625                 Any aAny = xTables->getByIndex( i );
1626                 Reference< XTextTable > xTable = *(Reference<XTextTable>*)aAny.getValue();
1627                 Reference < XTextContent > xTextContent( xTable, uno::UNO_QUERY );
1628                 exportTable( xTextContent, sal_True, sal_True );
1629             }
1630         }
1631     }
1632 
1633     Reference< XNumberingRulesSupplier > xNumberingRulesSupp( GetExport().GetModel(), UNO_QUERY );
1634     if ( xNumberingRulesSupp.is() )
1635     {
1636         Reference< XIndexAccess > xNumberingRules = xNumberingRulesSupp->getNumberingRules();
1637         nCount = xNumberingRules->getCount();
1638         // --> OD 2007-01-12 #i73361#
1639         const OUString sNumberingIsOutline( RTL_CONSTASCII_USTRINGPARAM( "NumberingIsOutline" ) );
1640         // <--
1641         for( sal_Int32 i = 0; i < nCount; ++i )
1642         {
1643             Reference< XIndexReplace > xNumRule( xNumberingRules->getByIndex( i ), UNO_QUERY );
1644             if( xNumRule.is() && xNumRule->getCount() )
1645             {
1646                 Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
1647                 OUString sName;
1648                 if( xNamed.is() )
1649                     sName = xNamed->getName();
1650                 sal_Bool bAdd = !sName.getLength();
1651                 if( !bAdd )
1652                 {
1653                     Reference < XPropertySet > xNumPropSet( xNumRule,
1654                                                             UNO_QUERY );
1655                     const OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) );
1656                     if( xNumPropSet.is() &&
1657                         xNumPropSet->getPropertySetInfo()
1658                                    ->hasPropertyByName( sIsAutomatic ) )
1659                     {
1660                         bAdd = *(sal_Bool *)xNumPropSet->getPropertyValue( sIsAutomatic ).getValue();
1661                         // --> OD 2007-01-12 #i73361# - check on outline style
1662                         if ( bAdd &&
1663                              xNumPropSet->getPropertySetInfo()
1664                                        ->hasPropertyByName( sNumberingIsOutline ) )
1665                         {
1666                             bAdd = !(*(sal_Bool *)xNumPropSet->getPropertyValue( sNumberingIsOutline ).getValue());
1667                         }
1668                         // <--
1669                     }
1670                     else
1671                     {
1672                         bAdd = sal_True;
1673                     }
1674                 }
1675                 if( bAdd )
1676                     pListAutoPool->Add( xNumRule );
1677             }
1678         }
1679     }
1680 
1681     return true;
1682 }
1683 
1684 void XMLTextParagraphExport::exportText(
1685         const Reference < XText > & rText,
1686         sal_Bool bAutoStyles,
1687         sal_Bool bIsProgress,
1688         sal_Bool bExportParagraph )
1689 {
1690     if( bAutoStyles )
1691         GetExport().GetShapeExport(); // make sure the graphics styles family
1692                                       // is added
1693     Reference < XEnumerationAccess > xEA( rText, UNO_QUERY );
1694     Reference < XEnumeration > xParaEnum(xEA->createEnumeration());
1695     Reference < XPropertySet > xPropertySet( rText, UNO_QUERY );
1696     Reference < XTextSection > xBaseSection;
1697 
1698     // #97718# footnotes don't supply paragraph enumerations in some cases
1699     // This is always a bug, but at least we don't want to crash.
1700     DBG_ASSERT( xParaEnum.is(), "We need a paragraph enumeration" );
1701     if( ! xParaEnum.is() )
1702         return;
1703 
1704     sal_Bool bExportLevels = sal_True;
1705 
1706     if (xPropertySet.is())
1707     {
1708         Reference < XPropertySetInfo > xInfo ( xPropertySet->getPropertySetInfo() );
1709 
1710         if( xInfo.is() )
1711         {
1712             if (xInfo->hasPropertyByName( sTextSection ))
1713             {
1714                 xPropertySet->getPropertyValue(sTextSection) >>= xBaseSection ;
1715             }
1716 
1717 /* #i35937#
1718             // for applications that use the outliner we need to check if
1719             // the current text object needs the level information exported
1720             if( !bAutoStyles )
1721             {
1722                 // fixme: move string to class member, couldn't do now because
1723                 //        of no incompatible build
1724                 OUString sHasLevels( RTL_CONSTASCII_USTRINGPARAM("HasLevels") );
1725                 if (xInfo->hasPropertyByName( sHasLevels ) )
1726                 {
1727                     xPropertySet->getPropertyValue(sHasLevels) >>= bExportLevels;
1728                 }
1729             }
1730 */
1731         }
1732     }
1733 
1734     // #96530# Export redlines at start & end of XText before & after
1735     // exporting the text content enumeration
1736     if( !bAutoStyles && (pRedlineExport != NULL) )
1737         pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_True );
1738     exportTextContentEnumeration( xParaEnum, bAutoStyles, xBaseSection,
1739                                   bIsProgress, bExportParagraph, 0, bExportLevels );
1740     if( !bAutoStyles && (pRedlineExport != NULL) )
1741         pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_False );
1742 }
1743 
1744 void XMLTextParagraphExport::exportText(
1745         const Reference < XText > & rText,
1746         const Reference < XTextSection > & rBaseSection,
1747         sal_Bool bAutoStyles,
1748         sal_Bool bIsProgress,
1749         sal_Bool bExportParagraph )
1750 {
1751     if( bAutoStyles )
1752         GetExport().GetShapeExport(); // make sure the graphics styles family
1753                                       // is added
1754     Reference < XEnumerationAccess > xEA( rText, UNO_QUERY );
1755     Reference < XEnumeration > xParaEnum(xEA->createEnumeration());
1756 
1757     // #98165# don't continue without a paragraph enumeration
1758     if( ! xParaEnum.is() )
1759         return;
1760 
1761     // #96530# Export redlines at start & end of XText before & after
1762     // exporting the text content enumeration
1763     Reference<XPropertySet> xPropertySet;
1764     if( !bAutoStyles && (pRedlineExport != NULL) )
1765     {
1766         xPropertySet.set(rText, uno::UNO_QUERY );
1767         pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_True );
1768     }
1769     exportTextContentEnumeration( xParaEnum, bAutoStyles, rBaseSection,
1770                                   bIsProgress, bExportParagraph );
1771     if( !bAutoStyles && (pRedlineExport != NULL) )
1772         pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_False );
1773 }
1774 
1775 sal_Bool XMLTextParagraphExport::exportTextContentEnumeration(
1776         const Reference < XEnumeration > & rContEnum,
1777         sal_Bool bAutoStyles,
1778         const Reference < XTextSection > & rBaseSection,
1779         sal_Bool bIsProgress,
1780         sal_Bool bExportParagraph,
1781         const Reference < XPropertySet > *pRangePropSet,
1782         sal_Bool bExportLevels )
1783 {
1784     DBG_ASSERT( rContEnum.is(), "No enumeration to export!" );
1785     sal_Bool bHasMoreElements = rContEnum->hasMoreElements();
1786     if( !bHasMoreElements )
1787         return sal_False;
1788 
1789     XMLTextNumRuleInfo aPrevNumInfo;
1790     XMLTextNumRuleInfo aNextNumInfo;
1791 
1792     sal_Bool bHasContent = sal_False;
1793     Reference<XTextSection> xCurrentTextSection(rBaseSection);
1794 
1795     MultiPropertySetHelper aPropSetHelper(
1796                             bAutoStyles ? aParagraphPropertyNamesAuto :
1797                                           aParagraphPropertyNames );
1798 
1799     sal_Bool bHoldElement = sal_False;
1800     Reference < XTextContent > xTxtCntnt;
1801     while( bHoldElement || bHasMoreElements )
1802     {
1803         if (bHoldElement)
1804         {
1805             bHoldElement = sal_False;
1806         }
1807         else
1808         {
1809             xTxtCntnt.set(rContEnum->nextElement(), uno::UNO_QUERY);
1810 
1811             aPropSetHelper.resetValues();
1812 
1813         }
1814 
1815         Reference<XServiceInfo> xServiceInfo( xTxtCntnt, UNO_QUERY );
1816         if( xServiceInfo->supportsService( sParagraphService ) )
1817         {
1818             if( bExportLevels )
1819             {
1820                 if( bAutoStyles )
1821                 {
1822                     exportListAndSectionChange( xCurrentTextSection, xTxtCntnt,
1823                                                 aPrevNumInfo, aNextNumInfo,
1824                                                 bAutoStyles );
1825                 }
1826                 else
1827                 {
1828                     // --> OD 2006-09-27 #i69627#
1829                     // --> OD 2008-04-24 #refactorlists#
1830                     // pass list auto style pool to <XMLTextNumRuleInfo> instance
1831                     // --> OD 2008-11-26 #158694#
1832                     // pass info about request to export <text:number> element
1833                     // to <XMLTextNumRuleInfo> instance
1834                     aNextNumInfo.Set( xTxtCntnt,
1835                                       GetExport().writeOutlineStyleAsNormalListStyle(),
1836                                       GetListAutoStylePool(),
1837                                       GetExport().exportTextNumberElement() );
1838                     // <--
1839 
1840                     exportListAndSectionChange( xCurrentTextSection, aPropSetHelper,
1841                                                 TEXT_SECTION, xTxtCntnt,
1842                                                 aPrevNumInfo, aNextNumInfo,
1843                                                 bAutoStyles );
1844                 }
1845             }
1846 
1847             // if we found a mute section: skip all section content
1848             if (pSectionExport->IsMuteSection(xCurrentTextSection))
1849             {
1850                 // Make sure headings are exported anyway.
1851                 if( !bAutoStyles )
1852                     pSectionExport->ExportMasterDocHeadingDummies();
1853 
1854                 while (rContEnum->hasMoreElements() &&
1855                        pSectionExport->IsInSection( xCurrentTextSection,
1856                                                     xTxtCntnt, sal_True ))
1857                 {
1858                     xTxtCntnt.set(rContEnum->nextElement(), uno::UNO_QUERY);
1859                     aPropSetHelper.resetValues();
1860                     aNextNumInfo.Reset();
1861                 }
1862                 // the first non-mute element still needs to be processed
1863                 bHoldElement =
1864                     ! pSectionExport->IsInSection( xCurrentTextSection,
1865                                                    xTxtCntnt, sal_False );
1866             }
1867             else
1868                 exportParagraph( xTxtCntnt, bAutoStyles, bIsProgress,
1869                                  bExportParagraph, aPropSetHelper );
1870             bHasContent = sal_True;
1871         }
1872         else if( xServiceInfo->supportsService( sTableService ) )
1873         {
1874             if( !bAutoStyles )
1875             {
1876                 aNextNumInfo.Reset();
1877             }
1878 
1879             exportListAndSectionChange( xCurrentTextSection, xTxtCntnt,
1880                                         aPrevNumInfo, aNextNumInfo,
1881                                         bAutoStyles );
1882 
1883             if (! pSectionExport->IsMuteSection(xCurrentTextSection))
1884             {
1885                 // export start + end redlines (for wholly redlined tables)
1886                 if ((! bAutoStyles) && (NULL != pRedlineExport))
1887                     pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, sal_True);
1888 
1889                 exportTable( xTxtCntnt, bAutoStyles, bIsProgress  );
1890 
1891                 if ((! bAutoStyles) && (NULL != pRedlineExport))
1892                     pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, sal_False);
1893             }
1894             else if( !bAutoStyles )
1895             {
1896                 // Make sure headings are exported anyway.
1897                 pSectionExport->ExportMasterDocHeadingDummies();
1898             }
1899 
1900             bHasContent = sal_True;
1901         }
1902         else if( xServiceInfo->supportsService( sTextFrameService ) )
1903         {
1904             exportTextFrame( xTxtCntnt, bAutoStyles, bIsProgress, sal_True, pRangePropSet );
1905         }
1906         else if( xServiceInfo->supportsService( sTextGraphicService ) )
1907         {
1908             exportTextGraphic( xTxtCntnt, bAutoStyles, pRangePropSet );
1909         }
1910         else if( xServiceInfo->supportsService( sTextEmbeddedService ) )
1911         {
1912             exportTextEmbedded( xTxtCntnt, bAutoStyles, pRangePropSet );
1913         }
1914         else if( xServiceInfo->supportsService( sShapeService ) )
1915         {
1916             exportShape( xTxtCntnt, bAutoStyles, pRangePropSet );
1917         }
1918         else
1919         {
1920             DBG_ASSERT( !xTxtCntnt.is(), "unknown text content" );
1921         }
1922 
1923         if( !bAutoStyles )
1924         {
1925             aPrevNumInfo = aNextNumInfo;
1926         }
1927 
1928         bHasMoreElements = rContEnum->hasMoreElements();
1929     }
1930 
1931     if( bExportLevels && bHasContent && !bAutoStyles )
1932     {
1933         aNextNumInfo.Reset();
1934 
1935         // close open lists and sections; no new styles
1936         exportListAndSectionChange( xCurrentTextSection, rBaseSection,
1937                                     aPrevNumInfo, aNextNumInfo,
1938                                     bAutoStyles );
1939     }
1940 
1941     return sal_True;
1942 }
1943 
1944 void XMLTextParagraphExport::exportParagraph(
1945         const Reference < XTextContent > & rTextContent,
1946         sal_Bool bAutoStyles, sal_Bool bIsProgress, sal_Bool bExportParagraph,
1947         MultiPropertySetHelper& rPropSetHelper)
1948 {
1949     sal_Int16 nOutlineLevel = -1;
1950 
1951     if( bIsProgress )
1952     {
1953         ProgressBarHelper *pProgress = GetExport().GetProgressBarHelper();
1954         pProgress->SetValue( pProgress->GetValue()+1 );
1955     }
1956 
1957     // get property set or multi property set and initialize helper
1958     Reference<XMultiPropertySet> xMultiPropSet( rTextContent, UNO_QUERY );
1959     Reference<XPropertySet> xPropSet( rTextContent, UNO_QUERY );
1960 
1961     // check for supported properties
1962     if( !rPropSetHelper.checkedProperties() )
1963         rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
1964 
1965 //  if( xMultiPropSet.is() )
1966 //      rPropSetHelper.getValues( xMultiPropSet );
1967 //  else
1968 //      rPropSetHelper.getValues( xPropSet );
1969 
1970     if( bExportParagraph )
1971     {
1972         if( bAutoStyles )
1973         {
1974             Add( XML_STYLE_FAMILY_TEXT_PARAGRAPH, rPropSetHelper, xPropSet );
1975         }
1976         else
1977         {
1978             // xml:id for RDF metadata
1979             GetExport().AddAttributeXmlId(rTextContent);
1980             GetExport().AddAttributesRDFa(rTextContent);
1981 
1982             OUString sStyle;
1983             if( rPropSetHelper.hasProperty( PARA_STYLE_NAME ) )
1984             {
1985                 if( xMultiPropSet.is() )
1986                     rPropSetHelper.getValue( PARA_STYLE_NAME,
1987                                                     xMultiPropSet ) >>= sStyle;
1988                 else
1989                     rPropSetHelper.getValue( PARA_STYLE_NAME,
1990                                                     xPropSet ) >>= sStyle;
1991             }
1992 
1993             Reference< XInterface > xRef( rTextContent, UNO_QUERY );
1994             if( xRef.is() )
1995             {
1996                 const OUString& rIdentifier = GetExport().getInterfaceToIdentifierMapper().getIdentifier( xRef );
1997                 if( rIdentifier.getLength() )
1998                 {
1999                     // FIXME: this is just temporary until EditEngine
2000                     // paragraphs implement XMetadatable.
2001                     // then that must be used and not the mapper, because
2002                     // when both can be used we get two xml:id!
2003                     uno::Reference<rdf::XMetadatable> const xMeta(xRef,
2004                         uno::UNO_QUERY);
2005                     OSL_ENSURE(!xMeta.is(), "paragraph that implements "
2006                         "XMetadatable used in interfaceToIdentifierMapper?");
2007                     GetExport().AddAttributeIdLegacy(XML_NAMESPACE_TEXT,
2008                         rIdentifier);
2009                 }
2010             }
2011 
2012             OUString sAutoStyle( sStyle );
2013             sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet, sStyle );
2014             if( sAutoStyle.getLength() )
2015                 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
2016                               GetExport().EncodeStyleName( sAutoStyle ) );
2017 
2018             if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME ) )
2019             {
2020                 OUString sCondStyle;
2021                 if( xMultiPropSet.is() )
2022                     rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME,
2023                                                     xMultiPropSet ) >>= sCondStyle;
2024                 else
2025                     rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME,
2026                                                     xPropSet ) >>= sCondStyle;
2027                 if( sCondStyle != sStyle )
2028                 {
2029                     sCondStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet,
2030                                        sCondStyle );
2031                     if( sCondStyle.getLength() )
2032                         GetExport().AddAttribute( XML_NAMESPACE_TEXT,
2033                                                   XML_COND_STYLE_NAME,
2034                               GetExport().EncodeStyleName( sCondStyle ) );
2035                 }
2036             }
2037 
2038             //if( rPropSetHelper.hasProperty( PARA_CHAPTER_NUMERBING_LEVEL ) )  //#outline level,zhaojianwei
2039             if( rPropSetHelper.hasProperty( PARA_OUTLINE_LEVEL ) )              //<-end
2040             {
2041                 if( xMultiPropSet.is() )
2042                     //rPropSetHelper.getValue( PARA_CHAPTER_NUMERBING_LEVEL,    //#outline level,zhaojianwei
2043                     rPropSetHelper.getValue( PARA_OUTLINE_LEVEL,                //<-end
2044                                                     xMultiPropSet ) >>= nOutlineLevel;
2045                 else
2046                     //rPropSetHelper.getValue( PARA_CHAPTER_NUMERBING_LEVEL,    //#outline level,zhaojianwei
2047                     rPropSetHelper.getValue( PARA_OUTLINE_LEVEL,                //<-end
2048                                                     xPropSet ) >>= nOutlineLevel;
2049 
2050                 //if( -1 != nOutlineLevel ) //#outline level,zhaojianwei
2051                 if( 0 < nOutlineLevel ) //<-end,zhaojianwei
2052                 {
2053                     OUStringBuffer sTmp;
2054                     //sTmp.append( sal_Int32( nOutlineLevel + 1 ) );    //#outline level,zhaojianwei
2055                     sTmp.append( sal_Int32( nOutlineLevel) );       //<-end,zhaojianwei
2056                     GetExport().AddAttribute( XML_NAMESPACE_TEXT,
2057                                               XML_OUTLINE_LEVEL,
2058                                   sTmp.makeStringAndClear() );
2059 
2060                     if( rPropSetHelper.hasProperty( NUMBERING_IS_NUMBER ) )
2061                     {
2062                         bool bIsNumber = false;
2063                         if( xMultiPropSet.is() )
2064                             rPropSetHelper.getValue(
2065                                        NUMBERING_IS_NUMBER, xMultiPropSet ) >>= bIsNumber;
2066                         else
2067                             rPropSetHelper.getValue(
2068                                        NUMBERING_IS_NUMBER, xPropSet ) >>= bIsNumber;
2069 
2070                         OUString sListStyleName;
2071                         if( xMultiPropSet.is() )
2072                             rPropSetHelper.getValue(
2073                                        PARA_NUMBERING_STYLENAME, xMultiPropSet ) >>= sListStyleName;
2074                         else
2075                             rPropSetHelper.getValue(
2076                                        PARA_NUMBERING_STYLENAME, xPropSet ) >>= sListStyleName;
2077 
2078 
2079 
2080                         bool bAssignedtoOutlineStyle = false;//#outline level,add by zhaojianwei
2081                         {
2082                             Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(), UNO_QUERY );
2083 
2084                             OUString sOutlineName;
2085                             if (xCNSupplier.is())
2086                             {
2087                                 Reference< XIndexReplace > xNumRule ( xCNSupplier->getChapterNumberingRules() );
2088                                 DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" );
2089 
2090                                 if (xNumRule.is())
2091                                 {
2092                                     Reference< XPropertySet > xNumRulePropSet( xNumRule, UNO_QUERY );
2093                                     xNumRulePropSet->getPropertyValue(
2094                                         OUString(RTL_CONSTASCII_USTRINGPARAM("Name")) ) >>= sOutlineName;
2095                                     bAssignedtoOutlineStyle = ( sListStyleName == sOutlineName );
2096                                 }
2097                             }
2098 
2099                         }   //<end,zhaojianwei
2100 
2101                         //if( ! bIsNumber )         //#outline level,removed by zhaojianwei
2102                         if( ! bIsNumber && bAssignedtoOutlineStyle )    //#outline level,add by zhaojianwei
2103                             GetExport().AddAttribute( XML_NAMESPACE_TEXT,
2104                                                       XML_IS_LIST_HEADER,
2105                                                       XML_TRUE );
2106                     }
2107 
2108                     {
2109                         String sParaIsNumberingRestart
2110                             (RTL_CONSTASCII_USTRINGPARAM
2111                              ("ParaIsNumberingRestart"));
2112                         bool bIsRestartNumbering = false;
2113 
2114                         Reference< XPropertySetInfo >
2115                         xPropSetInfo(xMultiPropSet.is() ?
2116                                      xMultiPropSet->getPropertySetInfo():
2117                                      xPropSet->getPropertySetInfo());
2118 
2119                         if (xPropSetInfo->
2120                             hasPropertyByName(sParaIsNumberingRestart))
2121                         {
2122                             xPropSet->getPropertyValue(sParaIsNumberingRestart)
2123                                 >>= bIsRestartNumbering;
2124                         }
2125 
2126                         if (bIsRestartNumbering)
2127                         {
2128                             GetExport().AddAttribute(XML_NAMESPACE_TEXT,
2129                                                      XML_RESTART_NUMBERING,
2130                                                      XML_TRUE);
2131 
2132                             String sNumberingStartValue
2133                                 (RTL_CONSTASCII_USTRINGPARAM
2134                                  ("NumberingStartValue"));
2135 
2136 
2137                             sal_Int32 nStartValue = 0;
2138 
2139                             if (xPropSetInfo->
2140                                 hasPropertyByName(sNumberingStartValue))
2141                             {
2142                                 xPropSet->getPropertyValue(sNumberingStartValue)
2143                                     >>= nStartValue;
2144 
2145                                 OUStringBuffer sTmpStartValue;
2146 
2147                                 sTmpStartValue.append(nStartValue);
2148 
2149                                 GetExport().
2150                                     AddAttribute(XML_NAMESPACE_TEXT,
2151                                                  XML_START_VALUE,
2152                                                  sTmpStartValue.
2153                                                  makeStringAndClear());
2154                             }
2155                         }
2156                     }
2157                 }
2158             }
2159         }
2160     }
2161 
2162     Reference < XEnumerationAccess > xEA( rTextContent, UNO_QUERY );
2163     Reference < XEnumeration > xTextEnum;
2164     xTextEnum = xEA->createEnumeration();
2165     const sal_Bool bHasPortions = xTextEnum.is();
2166 
2167     Reference < XEnumeration> xContentEnum;
2168     Reference < XContentEnumerationAccess > xCEA( rTextContent, UNO_QUERY );
2169     if( xCEA.is() )
2170         xContentEnum.set(xCEA->createContentEnumeration( sTextContentService ));
2171     const sal_Bool bHasContentEnum = xContentEnum.is() &&
2172                                      xContentEnum->hasMoreElements();
2173 
2174     Reference < XTextSection > xSection;
2175     if( bHasContentEnum )
2176     {
2177         // For the auto styles, the multi property set helper is only used
2178         // if hard attributes are existing. Therfor, it seems to be a better
2179         // strategy to have the TextSection property seperate, because otherwise
2180         // we always retrieve the style names even if they are not required.
2181         if( bAutoStyles )
2182         {
2183             if( xPropSet->getPropertySetInfo()->hasPropertyByName( sTextSection ) )
2184             {
2185                 xSection.set(xPropSet->getPropertyValue( sTextSection ), uno::UNO_QUERY);
2186             }
2187         }
2188         else
2189         {
2190             if( rPropSetHelper.hasProperty( TEXT_SECTION ) )
2191             {
2192                 xSection.set(rPropSetHelper.getValue( TEXT_SECTION ), uno::UNO_QUERY);
2193             }
2194         }
2195     }
2196 
2197     if( bAutoStyles )
2198     {
2199         sal_Bool bPrevCharIsSpace = sal_True;
2200         if( bHasContentEnum )
2201             bPrevCharIsSpace = !exportTextContentEnumeration(
2202                                     xContentEnum, bAutoStyles, xSection,
2203                                     bIsProgress, sal_True, 0, sal_True );
2204         if ( bHasPortions )
2205             exportTextRangeEnumeration( xTextEnum, bAutoStyles, bIsProgress );
2206     }
2207     else
2208     {
2209         sal_Bool bPrevCharIsSpace = sal_True;
2210         enum XMLTokenEnum eElem =
2211             //-1 == nOutlineLevel ? XML_P : XML_H;  //#outline level,zhaojianwei
2212             0 < nOutlineLevel ? XML_H : XML_P;  //<-end,zhaojianwei
2213         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem,
2214                                   sal_True, sal_False );
2215         if( bHasContentEnum )
2216             bPrevCharIsSpace = !exportTextContentEnumeration(
2217                                     xContentEnum, bAutoStyles, xSection,
2218                                     bIsProgress );
2219         exportTextRangeEnumeration( xTextEnum, bAutoStyles, bIsProgress,
2220                                     bPrevCharIsSpace );
2221     }
2222 }
2223 
2224 void XMLTextParagraphExport::exportTextRangeEnumeration(
2225         const Reference < XEnumeration > & rTextEnum,
2226         sal_Bool bAutoStyles, sal_Bool bIsProgress,
2227         sal_Bool bPrvChrIsSpc )
2228 {
2229     static OUString sMeta(RTL_CONSTASCII_USTRINGPARAM("InContentMetadata"));
2230     sal_Bool bPrevCharIsSpace = bPrvChrIsSpc;
2231 
2232     while( rTextEnum->hasMoreElements() )
2233     {
2234         Reference<XPropertySet> xPropSet(rTextEnum->nextElement(), UNO_QUERY);
2235         Reference < XTextRange > xTxtRange(xPropSet, uno::UNO_QUERY);
2236         Reference<XPropertySetInfo> xPropInfo(xPropSet->getPropertySetInfo());
2237 
2238         if (xPropInfo->hasPropertyByName(sTextPortionType))
2239         {
2240             rtl::OUString sType;
2241             xPropSet->getPropertyValue(sTextPortionType) >>= sType;
2242 
2243             if( sType.equals(sText))
2244             {
2245                 exportTextRange( xTxtRange, bAutoStyles,
2246                                  bPrevCharIsSpace );
2247             }
2248             else if( sType.equals(sTextField))
2249             {
2250                 exportTextField( xTxtRange, bAutoStyles, bIsProgress );
2251                 bPrevCharIsSpace = sal_False;
2252             }
2253             else if( sType.equals( sFrame ) )
2254             {
2255                 Reference < XEnumeration> xContentEnum;
2256                 Reference < XContentEnumerationAccess > xCEA( xTxtRange,
2257                                                               UNO_QUERY );
2258                 if( xCEA.is() )
2259                     xContentEnum.set(xCEA->createContentEnumeration(
2260                                                     sTextContentService ));
2261                 // frames are never in sections
2262                 Reference<XTextSection> xSection;
2263                 if( xContentEnum.is() )
2264                     exportTextContentEnumeration( xContentEnum,
2265                                                   bAutoStyles,
2266                                                   xSection, bIsProgress, sal_True,
2267                                                   &xPropSet );
2268 
2269                 bPrevCharIsSpace = sal_False;
2270             }
2271             else if (sType.equals(sFootnote))
2272             {
2273                 exportTextFootnote(xPropSet,
2274                                    xTxtRange->getString(),
2275                                    bAutoStyles, bIsProgress );
2276                 bPrevCharIsSpace = sal_False;
2277             }
2278             else if (sType.equals(sBookmark))
2279             {
2280                 exportTextMark(xPropSet,
2281                                sBookmark,
2282                                lcl_XmlBookmarkElements,
2283                                bAutoStyles);
2284             }
2285             else if (sType.equals(sReferenceMark))
2286             {
2287                 exportTextMark(xPropSet,
2288                                sReferenceMark,
2289                                lcl_XmlReferenceElements,
2290                                bAutoStyles);
2291             }
2292             else if (sType.equals(sDocumentIndexMark))
2293             {
2294                 pIndexMarkExport->ExportIndexMark(xPropSet, bAutoStyles);
2295             }
2296             else if (sType.equals(sRedline))
2297             {
2298                 if (NULL != pRedlineExport)
2299                     pRedlineExport->ExportChange(xPropSet, bAutoStyles);
2300             }
2301             else if (sType.equals(sRuby))
2302             {
2303                 exportRuby(xPropSet, bAutoStyles);
2304             }
2305             else if (sType.equals(sMeta))
2306             {
2307                 exportMeta(xPropSet, bAutoStyles, bIsProgress);
2308             }
2309             else if (sType.equals(sTextFieldStart))
2310             {
2311                 Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
2312                 if (xBookmark.is())
2313                 {
2314                     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
2315                 }
2316                 Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
2317                 if (xFormField.is())
2318                 {
2319                     GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
2320                 }
2321                 GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False);
2322                 if (xFormField.is())
2323                 {
2324                     FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
2325                 }
2326                 GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False);
2327             }
2328             else if (sType.equals(sTextFieldEnd))
2329             {
2330                 GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_END, sal_False);
2331                 GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_END, sal_False);
2332             }
2333             else if (sType.equals(sTextFieldStartEnd))
2334             {
2335                 Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
2336                 if (xBookmark.is())
2337                 {
2338                     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
2339                 }
2340                 Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
2341                 if (xFormField.is())
2342                 {
2343                     GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
2344                 }
2345                 GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False);
2346                 if (xFormField.is())
2347                 {
2348                     FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
2349                 }
2350                 GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False);
2351             }
2352             else if (sType.equals(sSoftPageBreak))
2353             {
2354                 exportSoftPageBreak(xPropSet,   bAutoStyles);
2355             }
2356             else {
2357                 DBG_ERROR("unknown text portion type");
2358             }
2359         }
2360         else
2361         {
2362             Reference<XServiceInfo> xServiceInfo( xTxtRange, UNO_QUERY );
2363             if( xServiceInfo->supportsService( sTextFieldService ) )
2364             {
2365                 exportTextField( xTxtRange, bAutoStyles, bIsProgress );
2366                 bPrevCharIsSpace = sal_False;
2367             }
2368             else
2369             {
2370                 // no TextPortionType property -> non-Writer app -> text
2371                 exportTextRange( xTxtRange, bAutoStyles, bPrevCharIsSpace );
2372             }
2373         }
2374     }
2375 
2376 // now that there are nested enumerations for meta(-field), this may be valid!
2377 //  DBG_ASSERT( !bOpenRuby, "Red Alert: Ruby still open!" );
2378 }
2379 
2380 void XMLTextParagraphExport::exportTable(
2381         const Reference < XTextContent > &,
2382         sal_Bool /*bAutoStyles*/, sal_Bool /*bIsProgress*/ )
2383 {
2384 }
2385 
2386 void XMLTextParagraphExport::exportTextField(
2387         const Reference < XTextRange > & rTextRange,
2388         sal_Bool bAutoStyles, sal_Bool bIsProgress )
2389 {
2390     Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY );
2391     // non-Writer apps need not support Property TextField, so test first
2392     if (xPropSet->getPropertySetInfo()->hasPropertyByName( sTextField ))
2393     {
2394         Reference < XTextField > xTxtFld(xPropSet->getPropertyValue( sTextField ), uno::UNO_QUERY);
2395         DBG_ASSERT( xTxtFld.is(), "text field missing" );
2396         if( xTxtFld.is() )
2397         {
2398             exportTextField(xTxtFld, bAutoStyles, bIsProgress, sal_True);
2399         }
2400         else
2401         {
2402             // write only characters
2403             GetExport().Characters(rTextRange->getString());
2404         }
2405     }
2406 }
2407 
2408 void XMLTextParagraphExport::exportTextField(
2409         const Reference < XTextField > & xTextField,
2410         const sal_Bool bAutoStyles, const sal_Bool bIsProgress,
2411         const sal_Bool bRecursive )
2412 {
2413     if ( bAutoStyles )
2414     {
2415         pFieldExport->ExportFieldAutoStyle( xTextField, bIsProgress,
2416                 bRecursive );
2417     }
2418     else
2419     {
2420         pFieldExport->ExportField( xTextField, bIsProgress );
2421     }
2422 }
2423 
2424 void XMLTextParagraphExport::exportSoftPageBreak(
2425     const Reference<XPropertySet> & ,
2426     sal_Bool )
2427 {
2428     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
2429                               XML_SOFT_PAGE_BREAK, sal_False,
2430                               sal_False );
2431 }
2432 
2433 void XMLTextParagraphExport::exportTextMark(
2434     const Reference<XPropertySet> & rPropSet,
2435     const OUString sProperty,
2436     const enum XMLTokenEnum pElements[],
2437     sal_Bool bAutoStyles)
2438 {
2439     // mib said: "Hau wech!"
2440     //
2441     // (Originally, I'd export a span element in case the (book|reference)mark
2442     //  was formatted. This actually makes a difference in case some pervert
2443     //  sets a point reference mark in the document and, say, formats it bold.
2444     //  This basically meaningless formatting will now been thrown away
2445     //  (aka cleaned up), since mib said: ...                   dvo
2446 
2447     if (!bAutoStyles)
2448     {
2449         // name element
2450         Reference<XNamed> xName(rPropSet->getPropertyValue(sProperty), UNO_QUERY);
2451         GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
2452                                  xName->getName());
2453 
2454         // start, end, or point-reference?
2455         sal_Int8 nElement;
2456         if( *(sal_Bool *)rPropSet->getPropertyValue(sIsCollapsed).getValue() )
2457         {
2458             nElement = 0;
2459         }
2460         else
2461         {
2462             nElement = *(sal_Bool *)rPropSet->getPropertyValue(sIsStart).getValue() ? 1 : 2;
2463         }
2464 
2465         // bookmark, bookmark-start: xml:id and RDFa for RDF metadata
2466         if( nElement < 2 ) {
2467             GetExport().AddAttributeXmlId(xName);
2468             const uno::Reference<text::XTextContent> xTextContent(
2469                     xName, uno::UNO_QUERY_THROW);
2470             GetExport().AddAttributesRDFa(xTextContent);
2471         }
2472 
2473         // export element
2474         DBG_ASSERT(pElements != NULL, "illegal element array");
2475         DBG_ASSERT(nElement >= 0, "illegal element number");
2476         DBG_ASSERT(nElement <= 2, "illegal element number");
2477         SvXMLElementExport aElem(GetExport(),
2478                                  XML_NAMESPACE_TEXT, pElements[nElement],
2479                                  sal_False, sal_False);
2480     }
2481     // else: no styles. (see above)
2482 }
2483 
2484 sal_Bool lcl_txtpara_isBoundAsChar(
2485         const Reference < XPropertySet > & rPropSet,
2486         const Reference < XPropertySetInfo > & rPropSetInfo )
2487 {
2488     sal_Bool bIsBoundAsChar = sal_False;
2489     OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) );
2490     if( rPropSetInfo->hasPropertyByName( sAnchorType ) )
2491     {
2492         TextContentAnchorType eAnchor;
2493         rPropSet->getPropertyValue( sAnchorType ) >>= eAnchor;
2494         bIsBoundAsChar = TextContentAnchorType_AS_CHARACTER == eAnchor;
2495     }
2496 
2497     return bIsBoundAsChar;
2498 }
2499 
2500 sal_Int32 XMLTextParagraphExport::addTextFrameAttributes(
2501     const Reference < XPropertySet >& rPropSet,
2502     sal_Bool bShape,
2503     OUString *pMinHeightValue )
2504 {
2505     sal_Int32 nShapeFeatures = SEF_DEFAULT;
2506 
2507     // draw:name (#97662#: not for shapes, since those names will be
2508     // treated in the shape export)
2509     if( !bShape )
2510     {
2511         Reference < XNamed > xNamed( rPropSet, UNO_QUERY );
2512         if( xNamed.is() )
2513         {
2514             OUString sName( xNamed->getName() );
2515             if( sName.getLength() )
2516                 GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
2517                                           xNamed->getName() );
2518         }
2519     }
2520 
2521     OUStringBuffer sValue;
2522 
2523     // text:anchor-type
2524     TextContentAnchorType eAnchor = TextContentAnchorType_AT_PARAGRAPH;
2525     rPropSet->getPropertyValue( sAnchorType ) >>= eAnchor;
2526     {
2527         XMLAnchorTypePropHdl aAnchorTypeHdl;
2528         OUString sTmp;
2529         aAnchorTypeHdl.exportXML( sTmp, uno::makeAny(eAnchor),
2530                                   GetExport().GetMM100UnitConverter() );
2531         GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_TYPE, sTmp );
2532     }
2533 
2534     // text:anchor-page-number
2535     if( TextContentAnchorType_AT_PAGE == eAnchor )
2536     {
2537         sal_Int16 nPage = 0;
2538         rPropSet->getPropertyValue( sAnchorPageNo ) >>= nPage;
2539         GetExport().GetMM100UnitConverter().convertNumber( sValue,
2540                                                            (sal_Int32)nPage );
2541         GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_PAGE_NUMBER,
2542                                   sValue.makeStringAndClear() );
2543     }
2544     else
2545     {
2546         // #92210#
2547         nShapeFeatures |= SEF_EXPORT_NO_WS;
2548     }
2549 
2550     // OD 2004-06-01 #i27691# - correction: no export of svg:x, if object
2551     // is anchored as-character.
2552     if ( !bShape &&
2553          eAnchor != TextContentAnchorType_AS_CHARACTER )
2554     {
2555         // svg:x
2556         sal_Int16 nHoriOrient =  HoriOrientation::NONE;
2557         rPropSet->getPropertyValue( sHoriOrient ) >>= nHoriOrient;
2558         if( HoriOrientation::NONE == nHoriOrient )
2559         {
2560             sal_Int32 nPos = 0;
2561             rPropSet->getPropertyValue( sHoriOrientPosition ) >>= nPos;
2562             GetExport().GetMM100UnitConverter().convertMeasure( sValue, nPos );
2563             GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_X,
2564                                       sValue.makeStringAndClear() );
2565         }
2566     }
2567     else if( TextContentAnchorType_AS_CHARACTER == eAnchor )
2568         nShapeFeatures = (nShapeFeatures & ~SEF_EXPORT_X);
2569 
2570     if( !bShape || TextContentAnchorType_AS_CHARACTER == eAnchor  )
2571     {
2572         // svg:y
2573         sal_Int16 nVertOrient =  VertOrientation::NONE;
2574         rPropSet->getPropertyValue( sVertOrient ) >>= nVertOrient;
2575         if( VertOrientation::NONE == nVertOrient )
2576         {
2577             sal_Int32 nPos = 0;
2578             rPropSet->getPropertyValue( sVertOrientPosition ) >>= nPos;
2579             GetExport().GetMM100UnitConverter().convertMeasure( sValue, nPos );
2580             GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_Y,
2581                                       sValue.makeStringAndClear() );
2582         }
2583         if( bShape )
2584             nShapeFeatures = (nShapeFeatures & ~SEF_EXPORT_Y);
2585     }
2586 
2587 
2588     Reference< XPropertySetInfo > xPropSetInfo(rPropSet->getPropertySetInfo());
2589 
2590     // svg:width
2591     sal_Int16 nWidthType = SizeType::FIX;
2592     if( xPropSetInfo->hasPropertyByName( sWidthType ) )
2593     {
2594         rPropSet->getPropertyValue( sWidthType ) >>= nWidthType;
2595     }
2596     if( xPropSetInfo->hasPropertyByName( sWidth ) )
2597     {
2598         sal_Int32 nWidth =  0;
2599         // VAR size will be written as zero min-size
2600         if( SizeType::VARIABLE != nWidthType )
2601         {
2602             rPropSet->getPropertyValue( sWidth ) >>= nWidth;
2603         }
2604         GetExport().GetMM100UnitConverter().convertMeasure( sValue, nWidth );
2605         if( SizeType::FIX != nWidthType )
2606             GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_WIDTH,
2607                                       sValue.makeStringAndClear() );
2608         else
2609             GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH,
2610                                       sValue.makeStringAndClear() );
2611     }
2612     sal_Bool bSyncWidth = sal_False;
2613     if( xPropSetInfo->hasPropertyByName( sIsSyncWidthToHeight ) )
2614     {
2615         bSyncWidth = *(sal_Bool *)rPropSet->getPropertyValue( sIsSyncWidthToHeight ).getValue();
2616         if( bSyncWidth )
2617             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
2618                                       XML_SCALE );
2619     }
2620     if( !bSyncWidth && xPropSetInfo->hasPropertyByName( sRelativeWidth ) )
2621     {
2622         sal_Int16 nRelWidth =  0;
2623         rPropSet->getPropertyValue( sRelativeWidth ) >>= nRelWidth;
2624         DBG_ASSERT( nRelWidth >= 0 && nRelWidth <= 254,
2625                     "Got illegal relative width from API" );
2626         if( nRelWidth > 0 )
2627         {
2628             GetExport().GetMM100UnitConverter().convertPercent( sValue,
2629                                                                 nRelWidth );
2630             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
2631                                       sValue.makeStringAndClear() );
2632         }
2633     }
2634 
2635     // svg:height, fo:min-height or style:rel-height
2636     sal_Int16 nSizeType = SizeType::FIX;
2637     if( xPropSetInfo->hasPropertyByName( sSizeType ) )
2638     {
2639         rPropSet->getPropertyValue( sSizeType ) >>= nSizeType;
2640     }
2641     sal_Bool bSyncHeight = sal_False;
2642     if( xPropSetInfo->hasPropertyByName( sIsSyncHeightToWidth ) )
2643     {
2644         bSyncHeight = *(sal_Bool *)rPropSet->getPropertyValue( sIsSyncHeightToWidth ).getValue();
2645     }
2646     sal_Int16 nRelHeight =  0;
2647     if( !bSyncHeight && xPropSetInfo->hasPropertyByName( sRelativeHeight ) )
2648     {
2649         rPropSet->getPropertyValue( sRelativeHeight ) >>= nRelHeight;
2650     }
2651     if( xPropSetInfo->hasPropertyByName( sHeight ) )
2652     {
2653         sal_Int32 nHeight =  0;
2654         if( SizeType::VARIABLE != nSizeType )
2655         {
2656             rPropSet->getPropertyValue( sHeight ) >>= nHeight;
2657         }
2658         GetExport().GetMM100UnitConverter().convertMeasure( sValue,
2659                                                             nHeight );
2660         if( SizeType::FIX != nSizeType && 0==nRelHeight && !bSyncHeight &&
2661             pMinHeightValue )
2662             *pMinHeightValue = sValue.makeStringAndClear();
2663         else
2664             GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT,
2665                                       sValue.makeStringAndClear() );
2666     }
2667     if( bSyncHeight )
2668     {
2669         GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT,
2670                 SizeType::MIN == nSizeType ? XML_SCALE_MIN : XML_SCALE );
2671 
2672     }
2673     else if( nRelHeight > 0 )
2674     {
2675         GetExport().GetMM100UnitConverter().convertPercent( sValue,
2676                                                             nRelHeight );
2677         if( SizeType::MIN == nSizeType )
2678             GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_HEIGHT,
2679                                       sValue.makeStringAndClear() );
2680         else
2681             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT,
2682                                       sValue.makeStringAndClear() );
2683     }
2684 
2685     OUString sZOrder( RTL_CONSTASCII_USTRINGPARAM( "ZOrder" ) );
2686     if( xPropSetInfo->hasPropertyByName( sZOrder ) )
2687     {
2688         sal_Int32 nZIndex = 0;
2689         rPropSet->getPropertyValue( sZOrder ) >>= nZIndex;
2690         if( -1 != nZIndex )
2691         {
2692             GetExport().GetMM100UnitConverter().convertNumber( sValue,
2693                                                                 nZIndex );
2694             GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_ZINDEX,
2695                                       sValue.makeStringAndClear() );
2696         }
2697     }
2698 
2699     return nShapeFeatures;
2700 }
2701 
2702 void XMLTextParagraphExport::exportAnyTextFrame(
2703         const Reference < XTextContent > & rTxtCntnt,
2704         FrameType eType,
2705         sal_Bool bAutoStyles,
2706         sal_Bool bIsProgress,
2707         sal_Bool bExportContent,
2708         const Reference < XPropertySet > *pRangePropSet)
2709 {
2710     Reference < XPropertySet > xPropSet( rTxtCntnt, UNO_QUERY );
2711 
2712     if( bAutoStyles )
2713     {
2714         if( FT_EMBEDDED == eType )
2715             _collectTextEmbeddedAutoStyles( xPropSet );
2716         // --> OD 2004-08-09 #i28745# - no text frame style for shapes
2717         else if ( FT_SHAPE != eType )
2718             Add( XML_STYLE_FAMILY_TEXT_FRAME, xPropSet );
2719         // <--
2720 
2721         if( pRangePropSet && lcl_txtpara_isBoundAsChar( xPropSet,
2722                                             xPropSet->getPropertySetInfo() ) )
2723             Add( XML_STYLE_FAMILY_TEXT_TEXT, *pRangePropSet );
2724 
2725         switch( eType )
2726         {
2727         case FT_TEXT:
2728             {
2729                 // frame bound frames
2730                 if ( bExportContent )
2731                 {
2732                     Reference < XTextFrame > xTxtFrame( rTxtCntnt, UNO_QUERY );
2733                     Reference < XText > xTxt(xTxtFrame->getText());
2734                     exportFrameFrames( sal_True, bIsProgress, &xTxtFrame );
2735                     exportText( xTxt, bAutoStyles, bIsProgress, sal_True );
2736                 }
2737             }
2738             break;
2739         case FT_SHAPE:
2740             {
2741                 Reference < XShape > xShape( rTxtCntnt, UNO_QUERY );
2742                 GetExport().GetShapeExport()->collectShapeAutoStyles( xShape );
2743             }
2744             break;
2745         default:
2746             break;
2747         }
2748     }
2749     else
2750     {
2751         Reference< XPropertySetInfo > xPropSetInfo(xPropSet->getPropertySetInfo());
2752         Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
2753         {
2754             sal_Bool bAddCharStyles = pRangePropSet &&
2755                 lcl_txtpara_isBoundAsChar( xPropSet, xPropSetInfo );
2756 
2757             sal_Bool bIsUICharStyle;
2758             sal_Bool bHasAutoStyle = sal_False;
2759             sal_Bool bDummy;
2760 
2761             OUString sStyle;
2762 
2763             if( bAddCharStyles )
2764                 sStyle = FindTextStyleAndHyperlink( *pRangePropSet, bDummy, bIsUICharStyle, bHasAutoStyle );
2765             else
2766                 bIsUICharStyle = sal_False;
2767 
2768             XMLTextCharStyleNamesElementExport aCharStylesExport(
2769                 GetExport(), bIsUICharStyle &&
2770                              aCharStyleNamesPropInfoCache.hasProperty(
2771                                             *pRangePropSet ), bHasAutoStyle,
2772                 *pRangePropSet, sCharStyleNames );
2773 
2774             if( sStyle.getLength() )
2775                 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
2776                                   GetExport().EncodeStyleName( sStyle ) );
2777             {
2778                 SvXMLElementExport aElem( GetExport(), sStyle.getLength() > 0,
2779                     XML_NAMESPACE_TEXT, XML_SPAN, sal_False, sal_False );
2780                 {
2781                     SvXMLElementExport aElement( GetExport(),
2782                         FT_SHAPE != eType &&
2783                         addHyperlinkAttributes( xPropSet,
2784                                                 xPropState,xPropSetInfo ),
2785                         XML_NAMESPACE_DRAW, XML_A, sal_False, sal_False );
2786                     switch( eType )
2787                     {
2788                     case FT_TEXT:
2789                         _exportTextFrame( xPropSet, xPropSetInfo, bIsProgress );
2790                         break;
2791                     case FT_GRAPHIC:
2792                         _exportTextGraphic( xPropSet, xPropSetInfo );
2793                         break;
2794                     case FT_EMBEDDED:
2795                         _exportTextEmbedded( xPropSet, xPropSetInfo );
2796                         break;
2797                     case FT_SHAPE:
2798                         {
2799                             Reference < XShape > xShape( rTxtCntnt, UNO_QUERY );
2800                             sal_Int32 nFeatures =
2801                                 addTextFrameAttributes( xPropSet, sal_True );
2802                             GetExport().GetShapeExport()
2803                                 ->exportShape( xShape, nFeatures );
2804                         }
2805                         break;
2806                     }
2807                 }
2808             }
2809         }
2810     }
2811 }
2812 
2813 void XMLTextParagraphExport::_exportTextFrame(
2814         const Reference < XPropertySet > & rPropSet,
2815         const Reference < XPropertySetInfo > & rPropSetInfo,
2816         sal_Bool bIsProgress )
2817 {
2818     Reference < XTextFrame > xTxtFrame( rPropSet, UNO_QUERY );
2819     Reference < XText > xTxt(xTxtFrame->getText());
2820 
2821     OUString sStyle;
2822     if( rPropSetInfo->hasPropertyByName( sFrameStyleName ) )
2823     {
2824         rPropSet->getPropertyValue( sFrameStyleName ) >>= sStyle;
2825     }
2826 
2827     OUString sAutoStyle( sStyle );
2828     OUString aMinHeightValue;
2829     sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_FRAME, rPropSet, sStyle );
2830     if( sAutoStyle.getLength() )
2831         GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME,
2832                               GetExport().EncodeStyleName( sAutoStyle ) );
2833     addTextFrameAttributes( rPropSet, sal_False, &aMinHeightValue );
2834 
2835     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW,
2836                               XML_FRAME, sal_False, sal_True );
2837 
2838     if( aMinHeightValue.getLength() )
2839         GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_HEIGHT,
2840                                   aMinHeightValue );
2841 
2842     // draw:chain-next-name
2843     if( rPropSetInfo->hasPropertyByName( sChainNextName ) )
2844     {
2845         OUString sNext;
2846         if( (rPropSet->getPropertyValue( sChainNextName ) >>= sNext) && sNext.getLength() > 0 )
2847             GetExport().AddAttribute( XML_NAMESPACE_DRAW,
2848                                       XML_CHAIN_NEXT_NAME,
2849                                       sNext );
2850     }
2851 
2852     {
2853         SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_DRAW,
2854                                   XML_TEXT_BOX, sal_True, sal_True );
2855 
2856         // frame bound frames
2857         exportFramesBoundToFrame( xTxtFrame, bIsProgress );
2858 
2859         exportText( xTxt, sal_False, bIsProgress, sal_True );
2860     }
2861 
2862     // script:events
2863     Reference<XEventsSupplier> xEventsSupp( xTxtFrame, UNO_QUERY );
2864     GetExport().GetEventExport().Export(xEventsSupp);
2865 
2866     // image map
2867     GetExport().GetImageMapExport().Export( rPropSet );
2868 
2869     // --> OD 2009-07-22 #i73249#
2870     // svg:title and svg:desc
2871     exportTitleAndDescription( rPropSet, rPropSetInfo );
2872     // <--
2873 }
2874 
2875 void XMLTextParagraphExport::exportContour(
2876         const Reference < XPropertySet > & rPropSet,
2877         const Reference < XPropertySetInfo > & rPropSetInfo )
2878 {
2879     if( !rPropSetInfo->hasPropertyByName( sContourPolyPolygon ) )
2880         return;
2881 
2882     PointSequenceSequence aSourcePolyPolygon;
2883     rPropSet->getPropertyValue( sContourPolyPolygon ) >>= aSourcePolyPolygon;
2884 
2885     if( !aSourcePolyPolygon.getLength() )
2886         return;
2887 
2888     awt::Point aPoint( 0, 0 );
2889     awt::Size aSize( 0, 0 );
2890     sal_Int32 nPolygons = aSourcePolyPolygon.getLength();
2891     const PointSequence *pPolygons = aSourcePolyPolygon.getConstArray();
2892     while( nPolygons-- )
2893     {
2894         sal_Int32 nPoints = pPolygons->getLength();
2895         const awt::Point *pPoints = pPolygons->getConstArray();
2896         while( nPoints-- )
2897         {
2898             if( aSize.Width < pPoints->X )
2899                 aSize.Width = pPoints->X;
2900             if( aSize.Height < pPoints->Y )
2901                 aSize.Height = pPoints->Y;
2902             pPoints++;
2903         }
2904         pPolygons++;
2905     }
2906 
2907     sal_Bool bPixel = sal_False;
2908     if( rPropSetInfo->hasPropertyByName( sIsPixelContour ) )
2909     {
2910         bPixel = *(sal_Bool *)rPropSet->getPropertyValue( sIsPixelContour ).getValue();
2911     }
2912 
2913     // svg: width
2914     OUStringBuffer aStringBuffer( 10 );
2915     if( bPixel )
2916         GetExport().GetMM100UnitConverter().convertMeasurePx(aStringBuffer, aSize.Width);
2917     else
2918         GetExport().GetMM100UnitConverter().convertMeasure(aStringBuffer, aSize.Width);
2919     GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH,
2920                               aStringBuffer.makeStringAndClear() );
2921 
2922     // svg: height
2923     if( bPixel )
2924         GetExport().GetMM100UnitConverter().convertMeasurePx(aStringBuffer, aSize.Height);
2925     else
2926         GetExport().GetMM100UnitConverter().convertMeasure(aStringBuffer, aSize.Height);
2927     GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT,
2928                               aStringBuffer.makeStringAndClear() );
2929 
2930     // svg:viewbox
2931     SdXMLImExViewBox aViewBox(0, 0, aSize.Width, aSize.Height);
2932     GetExport().AddAttribute(XML_NAMESPACE_SVG, XML_VIEWBOX,
2933                 aViewBox.GetExportString());
2934 
2935     sal_Int32 nOuterCnt( aSourcePolyPolygon.getLength() );
2936 
2937     enum XMLTokenEnum eElem = XML_TOKEN_INVALID;
2938     if( 1L == nOuterCnt )
2939     {
2940         // simple polygon shape, can be written as svg:points sequence
2941         /*const*/ PointSequence* pSequence =
2942                             (PointSequence*)aSourcePolyPolygon.getConstArray();
2943 
2944         SdXMLImExPointsElement aPoints( pSequence, aViewBox, aPoint, aSize );
2945 
2946         // write point array
2947         GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_POINTS,
2948                                       aPoints.GetExportString());
2949         eElem = XML_CONTOUR_POLYGON;
2950     }
2951     else
2952     {
2953         // polypolygon, needs to be written as a svg:path sequence
2954         /*const*/ PointSequence* pOuterSequence =
2955                         (PointSequence*)aSourcePolyPolygon.getConstArray();
2956         if(pOuterSequence)
2957         {
2958             // prepare svx:d element export
2959             SdXMLImExSvgDElement aSvgDElement( aViewBox );
2960 
2961             for(sal_Int32 a(0L); a < nOuterCnt; a++)
2962             {
2963                 /*const*/ PointSequence* pSequence = pOuterSequence++;
2964                 if(pSequence)
2965                 {
2966                     aSvgDElement.AddPolygon(pSequence, 0L, aPoint,
2967                         aSize, sal_True );
2968                 }
2969             }
2970 
2971             // write point array
2972             GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_D,
2973                                       aSvgDElement.GetExportString());
2974             eElem = XML_CONTOUR_PATH;
2975         }
2976     }
2977 
2978     if( rPropSetInfo->hasPropertyByName( sIsAutomaticContour ) )
2979     {
2980         sal_Bool bTmp = *(sal_Bool *)rPropSet->getPropertyValue(
2981                                             sIsAutomaticContour ).getValue();
2982         GetExport().AddAttribute( XML_NAMESPACE_DRAW,
2983                       XML_RECREATE_ON_EDIT, bTmp ? XML_TRUE : XML_FALSE );
2984     }
2985 
2986     // write object now
2987     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW, eElem,
2988                               sal_True, sal_True );
2989 }
2990 
2991 void XMLTextParagraphExport::_exportTextGraphic(
2992         const Reference < XPropertySet > & rPropSet,
2993         const Reference < XPropertySetInfo > & rPropSetInfo )
2994 {
2995     OUString sStyle;
2996     if( rPropSetInfo->hasPropertyByName( sFrameStyleName ) )
2997     {
2998         rPropSet->getPropertyValue( sFrameStyleName ) >>= sStyle;
2999     }
3000 
3001     OUString sAutoStyle( sStyle );
3002     sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_FRAME, rPropSet, sStyle );
3003     if( sAutoStyle.getLength() )
3004         GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME,
3005                                   GetExport().EncodeStyleName( sAutoStyle ) );
3006     addTextFrameAttributes( rPropSet, sal_False );
3007 
3008     // svg:transform
3009     sal_Int16 nVal = 0;
3010     rPropSet->getPropertyValue( sGraphicRotation ) >>= nVal;
3011     if( nVal != 0 )
3012     {
3013         OUStringBuffer sRet( GetXMLToken(XML_ROTATE).getLength()+4 );
3014         sRet.append( GetXMLToken(XML_ROTATE));
3015         sRet.append( (sal_Unicode)'(' );
3016         GetExport().GetMM100UnitConverter().convertNumber( sRet, (sal_Int32)nVal );
3017         sRet.append( (sal_Unicode)')' );
3018         GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_TRANSFORM,
3019                                   sRet.makeStringAndClear() );
3020     }
3021 
3022     // original content
3023     SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_DRAW, XML_FRAME, sal_False, sal_True);
3024 
3025     // replacement graphic for backwards compatibility, but
3026     // only for SVG currently
3027     OUString sReplacementOrigURL;
3028     rPropSet->getPropertyValue( sReplacementGraphicURL ) >>= sReplacementOrigURL;
3029 
3030     if(sReplacementOrigURL.getLength())
3031     {
3032         const OUString sReplacementURL(GetExport().AddEmbeddedGraphicObject( sReplacementOrigURL ));
3033 
3034         // If there is no url, then then graphic is empty
3035         if(sReplacementURL.getLength())
3036         {
3037             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sReplacementURL);
3038             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE);
3039             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED);
3040             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD);
3041 
3042             // xlink:href for replacement, only written for Svg content
3043             SvXMLElementExport aElement(GetExport(), XML_NAMESPACE_DRAW, XML_IMAGE, sal_False, sal_True);
3044 
3045             // optional office:binary-data
3046             GetExport().AddEmbeddedGraphicObjectAsBase64(sReplacementURL);
3047         }
3048     }
3049 
3050     // xlink:href
3051     OUString sOrigURL;
3052     rPropSet->getPropertyValue( sGraphicURL ) >>= sOrigURL;
3053     OUString sURL(GetExport().AddEmbeddedGraphicObject( sOrigURL ));
3054     setTextEmbeddedGraphicURL( rPropSet, sURL );
3055 
3056     // If there still is no url, then then graphic is empty
3057     if( sURL.getLength() )
3058     {
3059         GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sURL );
3060         GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
3061         GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
3062         GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE,
3063                                                        XML_ONLOAD );
3064     }
3065 
3066     // draw:filter-name
3067     OUString sGrfFilter;
3068     rPropSet->getPropertyValue( sGraphicFilter ) >>= sGrfFilter;
3069     if( sGrfFilter.getLength() )
3070         GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_FILTER_NAME,
3071                                   sGrfFilter );
3072 
3073     {
3074         SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_DRAW,
3075                                   XML_IMAGE, sal_False, sal_True );
3076 
3077         // optional office:binary-data
3078         GetExport().AddEmbeddedGraphicObjectAsBase64( sOrigURL );
3079     }
3080 
3081     // script:events
3082     Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY );
3083     GetExport().GetEventExport().Export(xEventsSupp);
3084 
3085     // image map
3086     GetExport().GetImageMapExport().Export( rPropSet );
3087 
3088     // --> OD 2009-07-22 #i73249#
3089     // svg:title and svg:desc
3090     exportTitleAndDescription( rPropSet, rPropSetInfo );
3091     // <--
3092 
3093     // draw:contour
3094     exportContour( rPropSet, rPropSetInfo );
3095 }
3096 
3097 void XMLTextParagraphExport::_collectTextEmbeddedAutoStyles(const Reference < XPropertySet > & )
3098 {
3099     DBG_ASSERT( !this, "no API implementation avialable" );
3100 }
3101 
3102 void XMLTextParagraphExport::_exportTextEmbedded(
3103         const Reference < XPropertySet > &,
3104         const Reference < XPropertySetInfo > & )
3105 {
3106     DBG_ASSERT( !this, "no API implementation avialable" );
3107 }
3108 
3109 void XMLTextParagraphExport::exportEvents( const Reference < XPropertySet > & rPropSet )
3110 {
3111     // script:events
3112     Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY );
3113     GetExport().GetEventExport().Export(xEventsSupp);
3114 
3115     // image map
3116     OUString sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap"));
3117     if (rPropSet->getPropertySetInfo()->hasPropertyByName(sImageMap))
3118         GetExport().GetImageMapExport().Export( rPropSet );
3119 }
3120 
3121 // --> OD 2009-07-22 #i73249#
3122 void XMLTextParagraphExport::exportTitleAndDescription(
3123         const Reference < XPropertySet > & rPropSet,
3124         const Reference < XPropertySetInfo > & rPropSetInfo )
3125 {
3126     // svg:title
3127     if( rPropSetInfo->hasPropertyByName( sTitle ) )
3128     {
3129         OUString sObjTitle;
3130         rPropSet->getPropertyValue( sTitle ) >>= sObjTitle;
3131         if( sObjTitle.getLength() )
3132         {
3133             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG,
3134                                       XML_TITLE, sal_True, sal_False );
3135             GetExport().Characters( sObjTitle );
3136         }
3137     }
3138 
3139     // svg:description
3140     if( rPropSetInfo->hasPropertyByName( sDescription ) )
3141     {
3142         OUString sObjDesc;
3143         rPropSet->getPropertyValue( sDescription ) >>= sObjDesc;
3144         if( sObjDesc.getLength() )
3145         {
3146             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG,
3147                                       XML_DESC, sal_True, sal_False );
3148             GetExport().Characters( sObjDesc );
3149         }
3150     }
3151 }
3152 // <--
3153 
3154 void XMLTextParagraphExport::setTextEmbeddedGraphicURL(
3155     const Reference < XPropertySet >&,
3156     OUString& /*rStreamName*/ ) const
3157 {
3158 }
3159 
3160 sal_Bool XMLTextParagraphExport::addHyperlinkAttributes(
3161         const Reference < XPropertySet > & rPropSet,
3162         const Reference < XPropertyState > & rPropState,
3163         const Reference < XPropertySetInfo > & rPropSetInfo )
3164 {
3165     sal_Bool bExport = sal_False;
3166     OUString sHRef, sName, sTargetFrame, sUStyleName, sVStyleName;
3167     sal_Bool bServerMap = sal_False;
3168 
3169 /*    bool bHyperLinkURL = false;
3170     bool bHyperLinkName = false;
3171     bool bHyperLinkTarget = false;
3172     bool bServer = false;
3173     bool bUnvisitedCharStyleName = false;
3174     bool bVisitedCharStyleName = false;
3175 
3176     const Reference< XMultiPropertySet > xMultiPropertySet( rPropSet, UNO_QUERY );
3177     if ( xMultiPropertySet.is() )
3178     {
3179     sal_uInt32 nCount = 0;
3180     Sequence< OUString > aPropertyNames( 6 );
3181     OUString* pArray = aPropertyNames.getArray();
3182 
3183     if ( rPropSetInfo->hasPropertyByName( sServerMap ) )
3184     {
3185         bServer = true;
3186         pArray[ nCount++ ] = sServerMap;
3187     }
3188     if ( rPropSetInfo->hasPropertyByName( sHyperLinkName ) )
3189     {
3190         bHyperLinkName = true;
3191         pArray[ nCount++ ] = sHyperLinkName;
3192     }
3193     if ( rPropSetInfo->hasPropertyByName( sHyperLinkTarget ) )
3194     {
3195         bHyperLinkTarget = true;
3196         pArray[ nCount++ ] = sHyperLinkTarget;
3197     }
3198     if ( rPropSetInfo->hasPropertyByName( sHyperLinkURL ) )
3199     {
3200         bHyperLinkURL = true;
3201         pArray[ nCount++ ] = sHyperLinkURL;
3202     }
3203     if ( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) )
3204     {
3205         bUnvisitedCharStyleName = true;
3206         pArray[ nCount++ ] = sUnvisitedCharStyleName;
3207     }
3208     if ( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) )
3209     {
3210         bVisitedCharStyleName = true;
3211         pArray[ nCount++ ] = sVisitedCharStyleName;
3212     }
3213 
3214     aPropertyNames.realloc( nCount );
3215 
3216     if ( nCount )
3217     {
3218         Sequence< PropertyState > aPropertyStates( nCount );
3219         PropertyState* pStateArray = aPropertyStates.getArray();
3220 
3221         if ( rPropState.is() )
3222             aPropertyStates = rPropState->getPropertyStates( aPropertyNames );
3223 
3224         Sequence< Any > aPropertyValues ( xMultiPropertySet->getPropertyValues( aPropertyNames ) );
3225         Any* pValueArray = aPropertyValues.getArray();
3226 
3227         sal_uInt32 nIdx = 0;
3228 
3229         if ( bServer )
3230         {
3231             if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3232             {
3233                 bServerMap = *(sal_Bool *)pValueArray[ nIdx ].getValue();
3234                 if( bServerMap  )
3235                     bExport = sal_True;
3236             }
3237             ++nIdx;
3238         }
3239         if ( bHyperLinkName )
3240         {
3241             if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3242             {
3243                 pValueArray[ nIdx ] >>= sName;
3244                 if( sName.getLength() > 0 )
3245                     bExport = sal_True;
3246             }
3247             ++nIdx;
3248         }
3249         if ( bHyperLinkTarget )
3250         {
3251             if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3252             {
3253                 pValueArray[ nIdx ] >>= sTargetFrame;
3254                 if( sTargetFrame.getLength() )
3255                     bExport = sal_True;
3256             }
3257             ++nIdx;
3258         }
3259         if ( bHyperLinkURL )
3260         {
3261             if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3262             {
3263                 pValueArray[ nIdx ] >>= sHRef;
3264                 if( sHRef.getLength() > 0 )
3265                     bExport = sal_True;
3266             }
3267             ++nIdx;
3268         }
3269         if ( bUnvisitedCharStyleName )
3270         {
3271             if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3272             {
3273                 pValueArray[ nIdx ] >>= sUStyleName;
3274                 if( sUStyleName.getLength() )
3275                     bExport = sal_True;
3276             }
3277             ++nIdx;
3278         }
3279         if ( bVisitedCharStyleName )
3280         {
3281             if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
3282             {
3283                 pValueArray[ nIdx ] >>= sVStyleName;
3284                 if( sVStyleName.getLength() )
3285                     bExport = sal_True;
3286             }
3287             ++nIdx;
3288         }
3289     }
3290     }
3291     else
3292     {*/
3293     if( rPropSetInfo->hasPropertyByName( sHyperLinkURL ) &&
3294         ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3295                     rPropState->getPropertyState( sHyperLinkURL ) ) )
3296     {
3297         rPropSet->getPropertyValue( sHyperLinkURL ) >>= sHRef;
3298 
3299         if( sHRef.getLength() > 0 )
3300             bExport = sal_True;
3301     }
3302 
3303     if( rPropSetInfo->hasPropertyByName( sHyperLinkName ) &&
3304         ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3305                     rPropState->getPropertyState( sHyperLinkName ) ) )
3306     {
3307         rPropSet->getPropertyValue( sHyperLinkName ) >>= sName;
3308         if( sName.getLength() > 0 )
3309             bExport = sal_True;
3310     }
3311 
3312     if( rPropSetInfo->hasPropertyByName( sHyperLinkTarget ) &&
3313         ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3314                     rPropState->getPropertyState( sHyperLinkTarget ) ) )
3315     {
3316         rPropSet->getPropertyValue( sHyperLinkTarget ) >>= sTargetFrame;
3317         if( sTargetFrame.getLength() )
3318             bExport = sal_True;
3319     }
3320 
3321     if( rPropSetInfo->hasPropertyByName( sServerMap ) &&
3322         ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3323                     rPropState->getPropertyState( sServerMap ) ) )
3324     {
3325         bServerMap = *(sal_Bool *)rPropSet->getPropertyValue( sServerMap ).getValue();
3326         if( bServerMap  )
3327             bExport = sal_True;
3328     }
3329 
3330     if( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) &&
3331         ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3332             rPropState->getPropertyState( sUnvisitedCharStyleName ) ) )
3333     {
3334         rPropSet->getPropertyValue( sUnvisitedCharStyleName ) >>= sUStyleName;
3335         if( sUStyleName.getLength() )
3336             bExport = sal_True;
3337     }
3338 
3339     if( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) &&
3340         ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
3341             rPropState->getPropertyState( sVisitedCharStyleName ) ) )
3342     {
3343         rPropSet->getPropertyValue( sVisitedCharStyleName ) >>= sVStyleName;
3344         if( sVStyleName.getLength() )
3345             bExport = sal_True;
3346     }
3347 
3348     if( bExport )
3349     {
3350         GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
3351         GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, GetExport().GetRelativeReference( sHRef ) );
3352 
3353         if( sName.getLength() > 0 )
3354             GetExport().AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME, sName );
3355 
3356         if( sTargetFrame.getLength() )
3357         {
3358             GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
3359                                       XML_TARGET_FRAME_NAME, sTargetFrame );
3360             enum XMLTokenEnum eTok =
3361                 sTargetFrame.equalsAsciiL( "_blank", sizeof("_blank")-1 )
3362                     ? XML_NEW : XML_REPLACE;
3363             GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, eTok );
3364         }
3365 
3366         if( bServerMap  )
3367             GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
3368                                       XML_SERVER_MAP, XML_TRUE );
3369 
3370         if( sUStyleName.getLength() )
3371             GetExport().AddAttribute( XML_NAMESPACE_TEXT,
3372               XML_STYLE_NAME, GetExport().EncodeStyleName( sUStyleName ) );
3373 
3374         if( sVStyleName.getLength() )
3375             GetExport().AddAttribute( XML_NAMESPACE_TEXT,
3376               XML_VISITED_STYLE_NAME, GetExport().EncodeStyleName( sVStyleName ) );
3377     }
3378 
3379     return bExport;
3380 }
3381 
3382 void XMLTextParagraphExport::exportTextRange(
3383         const Reference < XTextRange > & rTextRange,
3384         sal_Bool bAutoStyles,
3385         sal_Bool& rPrevCharIsSpace )
3386 {
3387     Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY );
3388     if( bAutoStyles )
3389     {
3390         Add( XML_STYLE_FAMILY_TEXT_TEXT, xPropSet );
3391     }
3392     else
3393     {
3394         sal_Bool bHyperlink = sal_False;
3395         sal_Bool bIsUICharStyle = sal_False;
3396         sal_Bool bHasAutoStyle = sal_False;
3397 
3398         OUString sStyle(FindTextStyleAndHyperlink( xPropSet, bHyperlink,
3399                                                      bIsUICharStyle, bHasAutoStyle ));
3400 
3401         Reference < XPropertySetInfo > xPropSetInfo;
3402         if( bHyperlink )
3403         {
3404             Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
3405             xPropSetInfo.set(xPropSet->getPropertySetInfo());
3406             bHyperlink = addHyperlinkAttributes( xPropSet, xPropState, xPropSetInfo );
3407         }
3408         SvXMLElementExport aElem( GetExport(), bHyperlink, XML_NAMESPACE_TEXT,
3409                                   XML_A, sal_False, sal_False );
3410         if( bHyperlink )
3411         {
3412             // export events (if supported)
3413             OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM(
3414                 "HyperLinkEvents"));
3415             if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents))
3416             {
3417                 Reference<XNameReplace> xName(xPropSet->getPropertyValue(sHyperLinkEvents), uno::UNO_QUERY);
3418                 GetExport().GetEventExport().Export(xName, sal_False);
3419             }
3420         }
3421 
3422         {
3423             XMLTextCharStyleNamesElementExport aCharStylesExport(
3424                 GetExport(), bIsUICharStyle &&
3425                              aCharStyleNamesPropInfoCache.hasProperty(
3426                                                     xPropSet, xPropSetInfo ), bHasAutoStyle,
3427                 xPropSet, sCharStyleNames );
3428 
3429             OUString aText(rTextRange->getString());
3430             if( sStyle.getLength() )
3431                 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
3432                           GetExport().EncodeStyleName( sStyle ) );
3433             {
3434                 // in a block to make sure it is destroyed before the text:a element
3435                 SvXMLElementExport aElement( GetExport(), sStyle.getLength() > 0,
3436                                           XML_NAMESPACE_TEXT, XML_SPAN, sal_False,
3437                                           sal_False );
3438                 exportText( aText, rPrevCharIsSpace );
3439             }
3440         }
3441     }
3442 }
3443 
3444 void XMLTextParagraphExport::exportText( const OUString& rText,
3445                                          sal_Bool& rPrevCharIsSpace )
3446 {
3447     sal_Int32 nExpStartPos = 0;
3448     sal_Int32 nEndPos = rText.getLength();
3449     sal_Int32 nSpaceChars = 0;
3450     for( sal_Int32 nPos = 0; nPos < nEndPos; nPos++ )
3451     {
3452         sal_Unicode cChar = rText[nPos];
3453         sal_Bool bExpCharAsText = sal_True;
3454         sal_Bool bExpCharAsElement = sal_False;
3455         sal_Bool bCurrCharIsSpace = sal_False;
3456         switch( cChar )
3457         {
3458         case 0x0009:    // Tab
3459         case 0x000A:    // LF
3460             // These characters are exported as text.
3461             bExpCharAsElement = sal_True;
3462             bExpCharAsText = sal_False;
3463             break;
3464         case 0x000D:
3465             break;  // legal character
3466         case 0x0020:    // Blank
3467             if( rPrevCharIsSpace )
3468             {
3469                 // If the previous character is a space character,
3470                 // too, export a special space element.
3471                 bExpCharAsText = sal_False;
3472             }
3473             bCurrCharIsSpace = sal_True;
3474             break;
3475         default:
3476             if( cChar < 0x0020 )
3477             {
3478 #ifdef DBG_UTIL
3479                 OSL_ENSURE( txtparae_bContainsIllegalCharacters ||
3480                             cChar >= 0x0020,
3481                             "illegal character in text content" );
3482                 txtparae_bContainsIllegalCharacters = sal_True;
3483 #endif
3484                 bExpCharAsText = sal_False;
3485             }
3486             break;
3487         }
3488 
3489         // If the current character is not exported as text
3490         // the text that has not been exported by now has to be exported now.
3491         if( nPos > nExpStartPos && !bExpCharAsText )
3492         {
3493             DBG_ASSERT( 0==nSpaceChars, "pending spaces" );
3494             OUString sExp( rText.copy( nExpStartPos, nPos - nExpStartPos ) );
3495             GetExport().Characters( sExp );
3496             nExpStartPos = nPos;
3497         }
3498 
3499         // If there are spaces left that have not been exported and the
3500         // current chracter is not a space , the pending spaces have to be
3501         // exported now.
3502         if( nSpaceChars > 0 && !bCurrCharIsSpace )
3503         {
3504             DBG_ASSERT( nExpStartPos == nPos, " pending characters" );
3505 
3506             if( nSpaceChars > 1 )
3507             {
3508                 OUStringBuffer sTmp;
3509                 sTmp.append( (sal_Int32)nSpaceChars );
3510                 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C,
3511                               sTmp.makeStringAndClear() );
3512             }
3513 
3514             SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
3515                                       XML_S, sal_False, sal_False );
3516 
3517             nSpaceChars = 0;
3518         }
3519 
3520         // If the current character has to be exported as a special
3521         // element, the elemnt will be exported now.
3522         if( bExpCharAsElement )
3523         {
3524             switch( cChar )
3525             {
3526             case 0x0009:    // Tab
3527                 {
3528                     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
3529                                               XML_TAB, sal_False,
3530                                               sal_False );
3531                 }
3532                 break;
3533             case 0x000A:    // LF
3534                 {
3535                     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
3536                                               XML_LINE_BREAK, sal_False,
3537                                               sal_False );
3538                 }
3539                 break;
3540             }
3541         }
3542 
3543         // If the current character is a space, and the previous one
3544         // is a space, too, the number of pending spaces is incremented
3545         // only.
3546         if( bCurrCharIsSpace && rPrevCharIsSpace )
3547             nSpaceChars++;
3548         rPrevCharIsSpace = bCurrCharIsSpace;
3549 
3550         // If the currect character is not exported as text, the start
3551         // position for text is the position behind the current position.
3552         if( !bExpCharAsText )
3553         {
3554             DBG_ASSERT( nExpStartPos == nPos, "wrong export start pos" );
3555             nExpStartPos = nPos+1;
3556         }
3557     }
3558 
3559     if( nExpStartPos < nEndPos )
3560     {
3561         DBG_ASSERT( 0==nSpaceChars, " pending spaces " );
3562         OUString sExp( rText.copy( nExpStartPos, nEndPos - nExpStartPos ) );
3563         GetExport().Characters( sExp );
3564     }
3565 
3566     // If there are some spaces left, they have to be exported now.
3567     if( nSpaceChars > 0 )
3568     {
3569         if( nSpaceChars > 1 )
3570         {
3571             OUStringBuffer sTmp;
3572             sTmp.append( (sal_Int32)nSpaceChars );
3573             GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C,
3574                           sTmp.makeStringAndClear() );
3575         }
3576 
3577         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_S,
3578                                   sal_False, sal_False );
3579     }
3580 }
3581 
3582 void XMLTextParagraphExport::exportTextDeclarations()
3583 {
3584     pFieldExport->ExportFieldDeclarations();
3585 
3586     // get XPropertySet from the document and ask for AutoMarkFileURL.
3587     // If it exists, export the auto-mark-file element.
3588     Reference<XPropertySet> xPropertySet( GetExport().GetModel(), UNO_QUERY );
3589     if (xPropertySet.is())
3590     {
3591         OUString sUrl;
3592         OUString sIndexAutoMarkFileURL(
3593             RTL_CONSTASCII_USTRINGPARAM("IndexAutoMarkFileURL"));
3594         if (xPropertySet->getPropertySetInfo()->hasPropertyByName(
3595             sIndexAutoMarkFileURL))
3596         {
3597             xPropertySet->getPropertyValue(sIndexAutoMarkFileURL) >>= sUrl;
3598             if (sUrl.getLength() > 0)
3599             {
3600                 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF,
3601                                           GetExport().GetRelativeReference(sUrl) );
3602                 SvXMLElementExport aAutoMarkElement(
3603                     GetExport(), XML_NAMESPACE_TEXT,
3604                     XML_ALPHABETICAL_INDEX_AUTO_MARK_FILE,
3605                     sal_True, sal_True );
3606             }
3607         }
3608     }
3609 }
3610 
3611 void XMLTextParagraphExport::exportTextDeclarations(
3612     const Reference<XText> & rText )
3613 {
3614     pFieldExport->ExportFieldDeclarations(rText);
3615 }
3616 
3617 void XMLTextParagraphExport::exportUsedDeclarations( sal_Bool bOnlyUsed )
3618 {
3619     pFieldExport->SetExportOnlyUsedFieldDeclarations( bOnlyUsed );
3620 }
3621 
3622 
3623 void XMLTextParagraphExport::exportTrackedChanges(sal_Bool bAutoStyles)
3624 {
3625     if (NULL != pRedlineExport)
3626         pRedlineExport->ExportChangesList( bAutoStyles );
3627 }
3628 
3629 void XMLTextParagraphExport::exportTrackedChanges(
3630     const Reference<XText> & rText,
3631     sal_Bool bAutoStyle)
3632 {
3633     if (NULL != pRedlineExport)
3634         pRedlineExport->ExportChangesList(rText, bAutoStyle);
3635 }
3636 
3637 void XMLTextParagraphExport::recordTrackedChangesForXText(
3638     const Reference<XText> & rText )
3639 {
3640     if (NULL != pRedlineExport)
3641         pRedlineExport->SetCurrentXText(rText);
3642 }
3643 
3644 void XMLTextParagraphExport::recordTrackedChangesNoXText()
3645 {
3646     if (NULL != pRedlineExport)
3647         pRedlineExport->SetCurrentXText();
3648 }
3649 
3650 
3651 void XMLTextParagraphExport::exportTextAutoStyles()
3652 {
3653     GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_PARAGRAPH,
3654                                    GetExport().GetDocHandler(),
3655                                    GetExport().GetMM100UnitConverter(),
3656                                    GetExport().GetNamespaceMap() );
3657 
3658     GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_TEXT,
3659                                    GetExport().GetDocHandler(),
3660                                    GetExport().GetMM100UnitConverter(),
3661                                    GetExport().GetNamespaceMap() );
3662 
3663     GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_FRAME,
3664                                    GetExport().GetDocHandler(),
3665                                    GetExport().GetMM100UnitConverter(),
3666                                    GetExport().GetNamespaceMap() );
3667 
3668     GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_SECTION,
3669                                   GetExport().GetDocHandler(),
3670                                   GetExport().GetMM100UnitConverter(),
3671                                   GetExport().GetNamespaceMap() );
3672 
3673     GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_RUBY,
3674                                   GetExport().GetDocHandler(),
3675                                   GetExport().GetMM100UnitConverter(),
3676                                   GetExport().GetNamespaceMap() );
3677 
3678     pListAutoPool->exportXML();
3679 }
3680 
3681 void XMLTextParagraphExport::exportRuby(
3682     const Reference<XPropertySet> & rPropSet,
3683     sal_Bool bAutoStyles )
3684 {
3685     // early out: a collapsed ruby makes no sense
3686     if (*(sal_Bool*)rPropSet->getPropertyValue(sIsCollapsed).getValue())
3687         return;
3688 
3689     // start value ?
3690     sal_Bool bStart = (*(sal_Bool*)rPropSet->getPropertyValue(sIsStart).getValue());
3691 
3692     if (bAutoStyles)
3693     {
3694         // ruby auto styles
3695         if (bStart)
3696             Add( XML_STYLE_FAMILY_TEXT_RUBY, rPropSet );
3697     }
3698     else
3699     {
3700         // prepare element names
3701         OUString aRuby(GetXMLToken(XML_RUBY));
3702         OUString sTextRuby(GetExport().GetNamespaceMap().
3703                            GetQNameByKey(XML_NAMESPACE_TEXT, aRuby));
3704         OUString sRubyBase(GetXMLToken(XML_RUBY_BASE));
3705         OUString sTextRubyBase(GetExport().GetNamespaceMap().
3706                            GetQNameByKey(XML_NAMESPACE_TEXT, sRubyBase));
3707 
3708         if (bStart)
3709         {
3710             // ruby start
3711 
3712             // we can only start a ruby if none is open
3713             DBG_ASSERT(! bOpenRuby, "Can't open a ruby inside of ruby!");
3714             if( bOpenRuby )
3715                 return;
3716 
3717             // save ruby text + ruby char style
3718             rPropSet->getPropertyValue(sRubyText) >>= sOpenRubyText;
3719             rPropSet->getPropertyValue(sRubyCharStyleName) >>= sOpenRubyCharStyle;
3720 
3721             // ruby style
3722             GetExport().CheckAttrList();
3723             OUString sEmpty;
3724             OUString sStyleName(Find( XML_STYLE_FAMILY_TEXT_RUBY, rPropSet,
3725                                         sEmpty ));
3726             DBG_ASSERT(sStyleName.getLength() > 0, "I can't find the style!");
3727             GetExport().AddAttribute(XML_NAMESPACE_TEXT,
3728                                      XML_STYLE_NAME, sStyleName);
3729 
3730             // export <text:ruby> and <text:ruby-base> start elements
3731             GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY, sal_False);
3732             GetExport().ClearAttrList();
3733             GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY_BASE,
3734                                       sal_False );
3735             bOpenRuby = sal_True;
3736         }
3737         else
3738         {
3739             // ruby end
3740 
3741             // check for an open ruby
3742             DBG_ASSERT(bOpenRuby, "Can't close a ruby if none is open!");
3743             if( !bOpenRuby )
3744                 return;
3745 
3746             // close <text:ruby-base>
3747             GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY_BASE,
3748                                    sal_False);
3749 
3750             // write the ruby text (with char style)
3751             {
3752                 if (sOpenRubyCharStyle.getLength() > 0)
3753                     GetExport().AddAttribute(
3754                         XML_NAMESPACE_TEXT, XML_STYLE_NAME,
3755                         GetExport().EncodeStyleName( sOpenRubyCharStyle) );
3756 
3757                 SvXMLElementExport aRubyElement(
3758                     GetExport(), XML_NAMESPACE_TEXT, XML_RUBY_TEXT,
3759                     sal_False, sal_False);
3760 
3761                 GetExport().Characters(sOpenRubyText);
3762             }
3763 
3764             // and finally, close the ruby
3765             GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY, sal_False);
3766             bOpenRuby = sal_False;
3767         }
3768     }
3769 }
3770 
3771 void XMLTextParagraphExport::exportMeta(
3772     const Reference<XPropertySet> & i_xPortion,
3773     sal_Bool i_bAutoStyles, sal_Bool i_isProgress)
3774 {
3775     static OUString sMeta(RTL_CONSTASCII_USTRINGPARAM("InContentMetadata"));
3776 
3777     bool doExport(!i_bAutoStyles); // do not export element if autostyles
3778     // check version >= 1.2
3779     switch (GetExport().getDefaultVersion()) {
3780         case SvtSaveOptions::ODFVER_011: // fall thru
3781         case SvtSaveOptions::ODFVER_010: doExport = false; break;
3782         default: break;
3783     }
3784 
3785     const Reference< XTextContent > xTextContent(
3786             i_xPortion->getPropertyValue(sMeta), UNO_QUERY_THROW);
3787     const Reference< XEnumerationAccess > xEA( xTextContent, UNO_QUERY_THROW );
3788     const Reference< XEnumeration > xTextEnum( xEA->createEnumeration() );
3789 
3790     if (doExport)
3791     {
3792         const Reference<rdf::XMetadatable> xMeta(xTextContent, UNO_QUERY_THROW);
3793 
3794         // text:meta with neither xml:id nor RDFa is invalid
3795         xMeta->ensureMetadataReference();
3796 
3797         // xml:id and RDFa for RDF metadata
3798         GetExport().AddAttributeXmlId(xMeta);
3799         GetExport().AddAttributesRDFa(xTextContent);
3800     }
3801 
3802     SvXMLElementExport aElem( GetExport(), doExport,
3803         XML_NAMESPACE_TEXT, XML_META, sal_False, sal_False );
3804 
3805     // recurse to export content
3806     exportTextRangeEnumeration( xTextEnum, i_bAutoStyles, i_isProgress );
3807 }
3808 
3809 
3810 void XMLTextParagraphExport::PreventExportOfControlsInMuteSections(
3811     const Reference<XIndexAccess> & rShapes,
3812     UniReference<xmloff::OFormLayerXMLExport> xFormExport   )
3813 {
3814     // check parameters ad pre-conditions
3815     if( ( ! rShapes.is() ) || ( ! xFormExport.is() ) )
3816     {
3817         // if we don't have shapes or a form export, there's nothing to do
3818         return;
3819     }
3820     DBG_ASSERT( pSectionExport != NULL, "We need the section export." );
3821 
3822     Reference<XEnumeration> xShapesEnum = pBoundFrameSets->GetShapes()->createEnumeration();
3823     if(!xShapesEnum.is())
3824         return;
3825     while( xShapesEnum->hasMoreElements() )
3826     {
3827         // now we need to check
3828         // 1) if this is a control shape, and
3829         // 2) if it's in a mute section
3830         // if both answers are 'yes', notify the form layer export
3831 
3832         // we join accessing the shape and testing for control
3833         Reference<XControlShape> xControlShape(xShapesEnum->nextElement(), UNO_QUERY);
3834         if( xControlShape.is() )
3835         {
3836             //            Reference<XPropertySet> xPropSet( xControlShape, UNO_QUERY );
3837             //            Reference<XTextContent> xTextContent;
3838             //            xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) ) ) >>= xTextContent;
3839 
3840             Reference<XTextContent> xTextContent( xControlShape, UNO_QUERY );
3841             if( xTextContent.is() )
3842             {
3843                 if( pSectionExport->IsMuteSection( xTextContent, sal_False ) )
3844                 {
3845                     // Ah, we've found a shape that
3846                     // 1) is a control shape
3847                     // 2) is anchored in a mute section
3848                     // so: don't export it!
3849                     xFormExport->excludeFromExport(
3850                         xControlShape->getControl() );
3851                 }
3852                 // else: not in mute section -> should be exported -> nothing
3853                 // to do
3854             }
3855             // else: no anchor -> ignore
3856         }
3857         // else: no control shape -> nothing to do
3858     }
3859 }
3860 sal_Int32 XMLTextParagraphExport::GetHeadingLevel( const OUString& rStyleName )
3861 {
3862     if( !pHeadingStyles )
3863     {
3864         pHeadingStyles = new XMLStringVector;
3865         SvxXMLNumRuleExport::GetOutlineStyles( *pHeadingStyles,
3866                                                GetExport().GetModel() );
3867     }
3868     for( XMLStringVector::size_type i=0; i < pHeadingStyles->size(); ++i )
3869     {
3870         if( (*pHeadingStyles)[i] == rStyleName )
3871             return static_cast < sal_Int32 >( i );
3872     }
3873 
3874     return -1;
3875 }
3876 
3877 // --> OD 2008-05-08 #refactorlists#
3878 void XMLTextParagraphExport::PushNewTextListsHelper()
3879 {
3880     mpTextListsHelper = new XMLTextListsHelper();
3881     maTextListsHelperStack.push_back( mpTextListsHelper );
3882 }
3883 
3884 void XMLTextParagraphExport::PopTextListsHelper()
3885 {
3886     delete mpTextListsHelper;
3887     mpTextListsHelper = 0;
3888     maTextListsHelperStack.pop_back();
3889     if ( !maTextListsHelperStack.empty() )
3890     {
3891         mpTextListsHelper = maTextListsHelperStack.back();
3892     }
3893 }
3894 // <--
3895