xref: /AOO41X/main/xmloff/source/style/xmlstyle.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
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 <com/sun/star/xml/sax/SAXParseException.hpp>
27 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
28 #include <com/sun/star/xml/sax/SAXException.hpp>
29 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
30 #include <com/sun/star/xml/sax/XAttributeList.hpp>
31 #include <com/sun/star/xml/sax/XLocator.hpp>
32 #include <com/sun/star/container/XNameContainer.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
35 #include <com/sun/star/style/XAutoStylesSupplier.hpp>
36 #include <com/sun/star/style/XAutoStyleFamily.hpp>
37 #ifndef _XMLOFF_PAGEMASTERPROPMAPPER_HXX
38 #include "PageMasterPropMapper.hxx"
39 #endif
40 #include <tools/debug.hxx>
41 #include <tools/list.hxx>
42 #include <svl/cntnrsrt.hxx>
43 #include <svl/itemset.hxx>
44 #include <xmloff/nmspmap.hxx>
45 #include "xmloff/xmlnmspe.hxx"
46 #include <xmloff/xmltoken.hxx>
47 
48 #ifndef _XMLOFF_FAMILIES_HXX
49 #include <xmloff/families.hxx>
50 #endif
51 #include <xmloff/xmlimp.hxx>
52 #include <xmloff/xmlnumi.hxx>
53 #include <xmloff/xmlimppr.hxx>
54 #include <xmloff/xmlstyle.hxx>
55 #ifndef _XMLOFF_TXTSTYLI_HXX
56 #include <xmloff/txtstyli.hxx>
57 #endif
58 #ifndef _XMLOFF_TXTPRMAP_HXX
59 #include <xmloff/txtprmap.hxx>
60 #endif
61 #include <xmloff/xmlnumfi.hxx>
62 #include "XMLChartStyleContext.hxx"
63 #include "XMLChartPropertySetMapper.hxx"
64 #include <xmloff/XMLShapeStyleContext.hxx>
65 #include "FillStyleContext.hxx"
66 #include "XMLFootnoteConfigurationImportContext.hxx"
67 #include "XMLIndexBibliographyConfigurationContext.hxx"
68 #include "XMLLineNumberingImportContext.hxx"
69 #include "PageMasterImportContext.hxx"
70 #include "PageMasterImportPropMapper.hxx"
71 
72 using ::rtl::OUString;
73 using ::rtl::OUStringBuffer;
74 
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::container;
78 using namespace ::com::sun::star::style;
79 using namespace ::xmloff::token;
80 
81 // ---------------------------------------------------------------------
82 
83 static __FAR_DATA SvXMLTokenMapEntry aStyleStylesElemTokenMap[] =
84 {
85     { XML_NAMESPACE_STYLE,  XML_STYLE,          XML_TOK_STYLE_STYLE                },
86     { XML_NAMESPACE_STYLE,  XML_PAGE_LAYOUT,    XML_TOK_STYLE_PAGE_MASTER          },
87     { XML_NAMESPACE_TEXT,   XML_LIST_STYLE,     XML_TOK_TEXT_LIST_STYLE            },
88     { XML_NAMESPACE_TEXT,   XML_OUTLINE_STYLE,  XML_TOK_TEXT_OUTLINE               },
89     { XML_NAMESPACE_STYLE,  XML_DEFAULT_STYLE,  XML_TOK_STYLE_DEFAULT_STYLE        },
90     { XML_NAMESPACE_DRAW,   XML_GRADIENT,       XML_TOK_STYLES_GRADIENTSTYLES      },
91     { XML_NAMESPACE_DRAW,   XML_HATCH,          XML_TOK_STYLES_HATCHSTYLES         },
92     { XML_NAMESPACE_DRAW,   XML_FILL_IMAGE,     XML_TOK_STYLES_BITMAPSTYLES        },
93     { XML_NAMESPACE_DRAW,   XML_OPACITY,        XML_TOK_STYLES_TRANSGRADIENTSTYLES },
94     { XML_NAMESPACE_DRAW,   XML_MARKER,         XML_TOK_STYLES_MARKERSTYLES        },
95     { XML_NAMESPACE_DRAW,   XML_STROKE_DASH,    XML_TOK_STYLES_DASHSTYLES        },
96     { XML_NAMESPACE_TEXT,   XML_NOTES_CONFIGURATION,    XML_TOK_TEXT_NOTE_CONFIG },
97     { XML_NAMESPACE_TEXT,   XML_BIBLIOGRAPHY_CONFIGURATION, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG },
98     { XML_NAMESPACE_TEXT,   XML_LINENUMBERING_CONFIGURATION,XML_TOK_TEXT_LINENUMBERING_CONFIG },
99     { XML_NAMESPACE_STYLE,  XML_DEFAULT_PAGE_LAYOUT,    XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT        },
100     XML_TOKEN_MAP_END
101 };
102 
GetStyleStylesElemTokenMap()103 const SvXMLTokenMap& SvXMLStylesContext::GetStyleStylesElemTokenMap()
104 {
105     if( !mpStyleStylesElemTokenMap )
106         mpStyleStylesElemTokenMap =
107             new SvXMLTokenMap( aStyleStylesElemTokenMap );
108 
109     return *mpStyleStylesElemTokenMap;
110 }
111 
112 // ---------------------------------------------------------------------
113 
SetAttribute(sal_uInt16 nPrefixKey,const OUString & rLocalName,const OUString & rValue)114 void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
115                                       const OUString& rLocalName,
116                                       const OUString& rValue )
117 {
118     // TODO: use a map here
119     if( XML_NAMESPACE_STYLE == nPrefixKey )
120     {
121         if( IsXMLToken( rLocalName, XML_FAMILY ) )
122         {
123             if( IsXMLToken( rValue, XML_PARAGRAPH ) )
124                 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_PARA;
125             else if( IsXMLToken( rValue, XML_TEXT ) )
126                 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_CHAR;
127         }
128         else if( IsXMLToken( rLocalName, XML_NAME ) )
129         {
130             maName = rValue;
131         }
132         else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) )
133         {
134             maDisplayName = rValue;
135         }
136         else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) )
137         {
138             maParentName = rValue;
139         }
140         else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) )
141         {
142             maFollow = rValue;
143         }
144         else if( IsXMLToken( rLocalName, XML_HELP_FILE_NAME ) )
145         {
146             maHelpFile = rValue;
147         }
148         else if( IsXMLToken( rLocalName, XML_HELP_ID ) )
149         {
150             sal_Int32 nTmp = rValue.toInt32();
151             mnHelpId =
152                 (nTmp < 0L) ? 0U : ( (nTmp > USHRT_MAX) ? USHRT_MAX
153                                                         : (sal_uInt16)nTmp );
154         }
155     }
156 }
157 
158 TYPEINIT1( SvXMLStyleContext, SvXMLImportContext );
159 
SvXMLStyleContext(SvXMLImport & rImp,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &,sal_uInt16 nFam,sal_Bool bDefault)160 SvXMLStyleContext::SvXMLStyleContext(
161         SvXMLImport& rImp, sal_uInt16 nPrfx,
162         const OUString& rLName,
163         const uno::Reference< xml::sax::XAttributeList >&,
164         sal_uInt16 nFam, sal_Bool bDefault ) :
165     SvXMLImportContext( rImp, nPrfx, rLName ),
166     mnHelpId( UCHAR_MAX ),
167     mnFamily( nFam ),
168     mbValid( sal_True ),
169     mbNew( sal_True ),
170     mbDefaultStyle( bDefault )
171 {
172 }
173 
~SvXMLStyleContext()174 SvXMLStyleContext::~SvXMLStyleContext()
175 {
176 }
177 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> &)178 SvXMLImportContext *SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix,
179                                             const OUString& rLocalName,
180                                             const uno::Reference< xml::sax::XAttributeList > & )
181 {
182     return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );;
183 }
184 
StartElement(const uno::Reference<xml::sax::XAttributeList> & xAttrList)185 void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttributeList > & xAttrList )
186 {
187     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
188     for( sal_Int16 i=0; i < nAttrCount; i++ )
189     {
190         const OUString& rAttrName = xAttrList->getNameByIndex( i );
191         OUString aLocalName;
192         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
193         const OUString& rValue = xAttrList->getValueByIndex( i );
194 
195         SetAttribute( nPrefix, aLocalName, rValue );
196     }
197 }
198 
SetDefaults()199 void SvXMLStyleContext::SetDefaults()
200 {
201 }
202 
CreateAndInsert(sal_Bool)203 void SvXMLStyleContext::CreateAndInsert( sal_Bool /*bOverwrite*/ )
204 {
205 }
206 
CreateAndInsertLate(sal_Bool)207 void SvXMLStyleContext::CreateAndInsertLate( sal_Bool /*bOverwrite*/ )
208 {
209 }
210 
Finish(sal_Bool)211 void SvXMLStyleContext::Finish( sal_Bool /*bOverwrite*/ )
212 {
213 }
214 
IsTransient() const215 sal_Bool SvXMLStyleContext::IsTransient() const
216 {
217     return sal_False;
218 }
219 
220 // ---------------------------------------------------------------------
221 
222 class SvXMLStyleIndex_Impl
223 {
224     OUString              sName;
225     sal_uInt16            nFamily;
226     const SvXMLStyleContext *pStyle;
227 
228 public:
229 
SvXMLStyleIndex_Impl(sal_uInt16 nFam,const OUString & rName)230     SvXMLStyleIndex_Impl( sal_uInt16 nFam, const OUString& rName ) :
231         sName( rName ),
232         nFamily( nFam ),
233         pStyle ( 0 )
234     {
235     }
236 
SvXMLStyleIndex_Impl(const SvXMLStyleContext * pStl)237     SvXMLStyleIndex_Impl( const SvXMLStyleContext *pStl ) :
238         sName( pStl->GetName() ),
239         nFamily( pStl->GetFamily() ),
240         pStyle ( pStl )
241     {
242     }
243 
GetName() const244     const OUString& GetName() const { return sName; }
GetFamily() const245     sal_uInt16 GetFamily() const { return nFamily; }
GetStyle() const246     const SvXMLStyleContext *GetStyle() const { return pStyle; }
247 };
248 
SvXMLStyleIndexCmp_Impl(const SvXMLStyleIndex_Impl & r1,const SvXMLStyleIndex_Impl & r2)249 int SvXMLStyleIndexCmp_Impl( const SvXMLStyleIndex_Impl& r1,
250                               const SvXMLStyleIndex_Impl& r2 )
251 {
252     int nRet;
253     if( (sal_uInt16)r1.GetFamily() < (sal_uInt16)r2.GetFamily() )
254         nRet = -1;
255     else if( (sal_uInt16)r1.GetFamily() > (sal_uInt16)r2.GetFamily() )
256         nRet = 1;
257     else
258         nRet = (int)r1.GetName().compareTo( r2.GetName() );
259 
260     return nRet;
261 }
262 
263 // ---------------------------------------------------------------------
264 
265 typedef SvXMLStyleContext *SvXMLStyleContextPtr;
266 DECLARE_LIST( SvXMLStyleContexts_Impl, SvXMLStyleContextPtr )
267 
268 DECLARE_CONTAINER_SORT_DEL( SvXMLStyleIndices_Impl, SvXMLStyleIndex_Impl )
269 IMPL_CONTAINER_SORT( SvXMLStyleIndices_Impl, SvXMLStyleIndex_Impl,
270                      SvXMLStyleIndexCmp_Impl )
271 
272 
273 class SvXMLStylesContext_Impl
274 {
275     SvXMLStyleContexts_Impl aStyles;
276     SvXMLStyleIndices_Impl  *pIndices;
277     sal_Bool bAutomaticStyle;
278 
279 #ifdef DBG_UTIL
280     sal_uInt32 nIndexCreated;
281 #endif
282 
FlushIndex()283     void FlushIndex() { delete pIndices; pIndices = 0; }
284 
285 public:
286     SvXMLStylesContext_Impl( sal_Bool bAuto );
287     ~SvXMLStylesContext_Impl();
288 
GetStyleCount() const289     sal_uInt32 GetStyleCount() const { return aStyles.Count(); }
290 
GetStyle(sal_uInt32 i) const291     const SvXMLStyleContext *GetStyle( sal_uInt32 i ) const
292     {
293         return i < aStyles.Count() ? aStyles.GetObject(i) : 0;
294     }
295 
GetStyle(sal_uInt32 i)296     SvXMLStyleContext *GetStyle( sal_uInt32 i )
297     {
298         return i < aStyles.Count() ? aStyles.GetObject(i) : 0;
299     }
300 
301     inline void AddStyle( SvXMLStyleContext *pStyle );
302     void Clear();
303 
304     const SvXMLStyleContext *FindStyleChildContext( sal_uInt16 nFamily,
305                             const OUString& rName, sal_Bool bCreateIndex ) const;
IsAutomaticStyle() const306     sal_Bool IsAutomaticStyle() const { return bAutomaticStyle; }
307 };
308 
SvXMLStylesContext_Impl(sal_Bool bAuto)309 SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( sal_Bool bAuto ) :
310     aStyles( 20, 5 ),
311     pIndices( 0 ),
312     bAutomaticStyle( bAuto )
313 #ifdef DBG_UTIL
314 ,   nIndexCreated( 0 )
315 #endif
316 {}
317 
~SvXMLStylesContext_Impl()318 SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl()
319 {
320     delete pIndices;
321 
322     while( aStyles.Count() )
323     {
324         SvXMLStyleContext *pStyle = aStyles.GetObject(0);
325         aStyles.Remove( 0UL );
326         pStyle->ReleaseRef();
327     }
328 }
329 
AddStyle(SvXMLStyleContext * pStyle)330 inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle )
331 {
332     aStyles.Insert( pStyle, aStyles.Count() );
333     pStyle->AddRef();
334 
335     FlushIndex();
336 }
337 
Clear()338 void SvXMLStylesContext_Impl::Clear()
339 {
340     FlushIndex();
341 
342     while( aStyles.Count() )
343     {
344         SvXMLStyleContext *pStyle = aStyles.GetObject(0);
345         aStyles.Remove( 0UL );
346         pStyle->ReleaseRef();
347     }
348 }
349 
FindStyleChildContext(sal_uInt16 nFamily,const OUString & rName,sal_Bool bCreateIndex) const350 const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext(
351                                   sal_uInt16 nFamily,
352                                   const OUString& rName,
353                                   sal_Bool bCreateIndex ) const
354 {
355     const SvXMLStyleContext *pStyle = 0;
356 
357     if( !pIndices && bCreateIndex && aStyles.Count() > 0 )
358     {
359 #ifdef DBG_UTIL
360         DBG_ASSERT( 0==nIndexCreated,
361                     "Performance warning: sdbcx::Index created multiple times" );
362 #endif
363         ((SvXMLStylesContext_Impl *)this)->pIndices =
364             new SvXMLStyleIndices_Impl(
365                 sal::static_int_cast< sal_uInt16 >(aStyles.Count()), 5 );
366         for( sal_uInt32 i=0; i < aStyles.Count(); i++ )
367         {
368             SvXMLStyleIndex_Impl* pStyleIndex = new SvXMLStyleIndex_Impl( aStyles.GetObject(i));
369             if (!pIndices->Insert( pStyleIndex ))
370             {
371                 DBG_ERROR("Here is a double Style");
372                 delete pStyleIndex;
373             }
374         }
375 #ifdef DBG_UTIL
376         ((SvXMLStylesContext_Impl *)this)->nIndexCreated++;
377 #endif
378     }
379 
380     if( pIndices )
381     {
382         SvXMLStyleIndex_Impl aIndex( nFamily, rName );
383         sal_uLong nPos = 0;
384         if( pIndices->Seek_Entry( &aIndex, &nPos ) )
385             pStyle = pIndices->GetObject( nPos )->GetStyle();
386     }
387     else
388     {
389         for( sal_uInt32 i=0; !pStyle && i < aStyles.Count(); i++ )
390         {
391             const SvXMLStyleContext *pS = aStyles.GetObject( i );
392             if( pS->GetFamily() == nFamily &&
393                 pS->GetName() == rName )
394                 pStyle = pS;
395         }
396     }
397     return pStyle;
398 }
399 
400 // ---------------------------------------------------------------------
401 
402 TYPEINIT1( SvXMLStylesContext, SvXMLImportContext );
403 
GetStyleCount() const404 sal_uInt32 SvXMLStylesContext::GetStyleCount() const
405 {
406     return mpImpl->GetStyleCount();
407 }
408 
GetStyle(sal_uInt32 i)409 SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i )
410 {
411     return mpImpl->GetStyle( i );
412 }
413 
GetStyle(sal_uInt32 i) const414 const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const
415 {
416     return mpImpl->GetStyle( i );
417 }
418 
IsAutomaticStyle() const419 sal_Bool SvXMLStylesContext::IsAutomaticStyle() const
420 {
421     return mpImpl->IsAutomaticStyle();
422 }
423 
CreateStyleChildContext(sal_uInt16 p_nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)424 SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext(
425         sal_uInt16 p_nPrefix,
426         const OUString& rLocalName,
427         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
428 {
429     SvXMLStyleContext *pStyle = NULL;
430 
431     if(GetImport().GetDataStylesImport())
432     {
433         pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix,
434                                             rLocalName, xAttrList, *this);
435     }
436 
437     if (!pStyle)
438     {
439         const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap();
440         sal_uInt16 nToken = rTokenMap.Get( p_nPrefix, rLocalName );
441         switch( nToken  )
442         {
443             case XML_TOK_STYLE_STYLE:
444             case XML_TOK_STYLE_DEFAULT_STYLE:
445             {
446                 sal_uInt16 nFamily = 0;
447                 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
448                 for( sal_Int16 i=0; i < nAttrCount; i++ )
449                 {
450                     const OUString& rAttrName = xAttrList->getNameByIndex( i );
451                     OUString aLocalName;
452                     sal_uInt16 nPrefix =
453                         GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
454                                                                     &aLocalName );
455                     if( XML_NAMESPACE_STYLE == nPrefix &&
456                         IsXMLToken( aLocalName, XML_FAMILY ) )
457                     {
458                         const OUString& rValue = xAttrList->getValueByIndex( i );
459                         nFamily = GetFamily( rValue );
460                         break;
461                     }
462                 }
463                 pStyle = XML_TOK_STYLE_STYLE==nToken
464                     ? CreateStyleStyleChildContext( nFamily, p_nPrefix,
465                                                     rLocalName, xAttrList )
466                     : CreateDefaultStyleStyleChildContext( nFamily, p_nPrefix,
467                                                     rLocalName, xAttrList );
468             }
469             break;
470             case XML_TOK_STYLE_PAGE_MASTER:
471             case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT:
472             {
473                 //there is not page family in odf now, so I specify one for it
474                 sal_Bool bDefaultStyle  = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken
475                     ? sal_True: sal_False;
476                 pStyle = new PageStyleContext( GetImport(), p_nPrefix,
477                                                     rLocalName, xAttrList, *this, bDefaultStyle );
478             }
479             break;
480             case XML_TOK_TEXT_LIST_STYLE:
481                 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
482                                                     rLocalName, xAttrList );
483                 break;
484             case XML_TOK_TEXT_OUTLINE:
485                 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
486                                                     rLocalName, xAttrList, sal_True );
487                 break;
488             case XML_TOK_TEXT_NOTE_CONFIG:
489 #ifndef SVX_LIGHT
490                 pStyle = new XMLFootnoteConfigurationImportContext(GetImport(),
491                                                                    p_nPrefix,
492                                                                    rLocalName,
493                                                                    xAttrList);
494 #else
495                 // create default context to skip content
496                 pStyle = new SvXMLStyleContext( GetImport(), nPrefix, rLocalName, xAttrList );
497 #endif // #ifndef SVX_LIGHT
498                 break;
499 
500             case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG:
501 #ifndef SVX_LIGHT
502                 pStyle = new XMLIndexBibliographyConfigurationContext(
503                     GetImport(), p_nPrefix, rLocalName, xAttrList);
504 #else
505                 // create default context to skip content
506                 pStyle = new SvXMLStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
507 #endif // #ifndef SVX_LIGHT
508                 break;
509 
510             case XML_TOK_TEXT_LINENUMBERING_CONFIG:
511 #ifndef SVX_LIGHT
512                 pStyle = new XMLLineNumberingImportContext(
513                     GetImport(), p_nPrefix, rLocalName, xAttrList);
514 #else
515                 // create default context to skip content
516                 pStyle = new SvXMLStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
517 #endif // #ifndef SVX_LIGHT
518                 break;
519 
520             //
521             // FillStyles
522             //
523             case XML_TOK_STYLES_GRADIENTSTYLES:
524             {
525                 pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
526                 break;
527             }
528             case XML_TOK_STYLES_HATCHSTYLES:
529             {
530                 pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
531                 break;
532             }
533             case XML_TOK_STYLES_BITMAPSTYLES:
534             {
535                 pStyle = new XMLBitmapStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
536                 break;
537             }
538             case XML_TOK_STYLES_TRANSGRADIENTSTYLES:
539             {
540                 pStyle = new XMLTransGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
541                 break;
542             }
543             case XML_TOK_STYLES_MARKERSTYLES:
544             {
545                 pStyle = new XMLMarkerStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
546                 break;
547             }
548             case XML_TOK_STYLES_DASHSTYLES:
549             {
550                 pStyle = new XMLDashStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
551                 break;
552             }
553         }
554     }
555 
556     return pStyle;
557 }
558 
CreateStyleStyleChildContext(sal_uInt16 nFamily,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)559 SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext(
560         sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
561         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
562 {
563     SvXMLStyleContext *pStyle = 0;
564 
565     switch( nFamily )
566     {
567         case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
568         case XML_STYLE_FAMILY_TEXT_TEXT:
569         case XML_STYLE_FAMILY_TEXT_SECTION:
570             pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
571                                               xAttrList, *this, nFamily );
572             break;
573 
574         case XML_STYLE_FAMILY_TEXT_RUBY:
575             pStyle = new XMLPropStyleContext( GetImport(), nPrefix, rLocalName,
576                                               xAttrList, *this, nFamily );
577             break;
578         case XML_STYLE_FAMILY_SCH_CHART_ID:
579             pStyle = new XMLChartStyleContext( GetImport(), nPrefix, rLocalName,
580                                                xAttrList, *this, nFamily );
581             break;
582 
583         case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
584         case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
585         case XML_STYLE_FAMILY_SD_POOL_ID:
586             pStyle = new XMLShapeStyleContext( GetImport(), nPrefix, rLocalName,
587                                                xAttrList, *this, nFamily );
588     }
589 
590     return pStyle;
591 }
592 
CreateDefaultStyleStyleChildContext(sal_uInt16,sal_uInt16,const OUString &,const uno::Reference<xml::sax::XAttributeList> &)593 SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
594         sal_uInt16 /*nFamily*/, sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/,
595         const uno::Reference< xml::sax::XAttributeList > & )
596 {
597     return 0;
598 }
599 
600 
InsertStyleFamily(sal_uInt16) const601 sal_Bool SvXMLStylesContext::InsertStyleFamily( sal_uInt16 ) const
602 {
603     return sal_True;
604 }
605 
GetFamily(const::rtl::OUString & rValue) const606 sal_uInt16 SvXMLStylesContext::GetFamily(
607         const ::rtl::OUString& rValue ) const
608 {
609     sal_uInt16 nFamily = 0U;
610     if( IsXMLToken( rValue, XML_PARAGRAPH ) )
611     {
612         nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH;
613     }
614     else if( IsXMLToken( rValue, XML_TEXT ) )
615     {
616         nFamily = XML_STYLE_FAMILY_TEXT_TEXT;
617     }
618     else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
619     {
620         nFamily = XML_STYLE_FAMILY_DATA_STYLE;
621     }
622     else if ( IsXMLToken( rValue, XML_SECTION ) )
623     {
624         nFamily = XML_STYLE_FAMILY_TEXT_SECTION;
625     }
626     else if( IsXMLToken( rValue, XML_TABLE ) )
627     {
628         nFamily = XML_STYLE_FAMILY_TABLE_TABLE;
629     }
630     else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
631         nFamily = XML_STYLE_FAMILY_TABLE_COLUMN;
632     else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
633         nFamily = XML_STYLE_FAMILY_TABLE_ROW;
634     else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
635         nFamily = XML_STYLE_FAMILY_TABLE_CELL;
636     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME)))
637     {
638         nFamily = XML_STYLE_FAMILY_SD_GRAPHICS_ID;
639     }
640     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_PRESENTATION_NAME)))
641     {
642         nFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
643     }
644     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_POOL_NAME)))
645     {
646         nFamily = XML_STYLE_FAMILY_SD_POOL_ID;
647     }
648     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME)))
649     {
650         nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID;
651     }
652     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( XML_STYLE_FAMILY_SCH_CHART_NAME )))
653     {
654         nFamily = XML_STYLE_FAMILY_SCH_CHART_ID;
655     }
656     else if ( IsXMLToken( rValue, XML_RUBY ) )
657     {
658         nFamily = XML_STYLE_FAMILY_TEXT_RUBY;
659     }
660 
661     return nFamily;
662 }
663 
GetImportPropertyMapper(sal_uInt16 nFamily) const664 UniReference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper(
665                         sal_uInt16 nFamily ) const
666 {
667     UniReference < SvXMLImportPropertyMapper > xMapper;
668 
669     switch( nFamily )
670     {
671     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
672         if( !mxParaImpPropMapper.is() )
673         {
674             SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
675             pThis->mxParaImpPropMapper =
676                 pThis->GetImport().GetTextImport()
677                      ->GetParaImportPropertySetMapper();
678         }
679         xMapper = mxParaImpPropMapper;
680         break;
681     case XML_STYLE_FAMILY_TEXT_TEXT:
682         if( !mxTextImpPropMapper.is() )
683         {
684             SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
685             pThis->mxTextImpPropMapper =
686                 pThis->GetImport().GetTextImport()
687                      ->GetTextImportPropertySetMapper();
688         }
689         xMapper = mxTextImpPropMapper;
690         break;
691 
692     case XML_STYLE_FAMILY_TEXT_SECTION:
693         // don't cache section mapper, as it's rarely used
694         // *sigh*, cast to non-const, because this is a const method,
695         // but SvXMLImport::GetTextImport() isn't.
696         xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
697             GetSectionImportPropertySetMapper();
698         break;
699 
700     case XML_STYLE_FAMILY_TEXT_RUBY:
701         // don't cache section mapper, as it's rarely used
702         // *sigh*, cast to non-const, because this is a const method,
703         // but SvXMLImport::GetTextImport() isn't.
704         xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
705             GetRubyImportPropertySetMapper();
706         break;
707 
708     case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
709     case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
710     case XML_STYLE_FAMILY_SD_POOL_ID:
711         if(!mxShapeImpPropMapper.is())
712         {
713             UniReference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
714             ((SvXMLStylesContext*)this)->mxShapeImpPropMapper =
715                 aImpHelper->GetPropertySetMapper();
716         }
717         xMapper = mxShapeImpPropMapper;
718         break;
719 #ifndef SVX_LIGHT
720     case XML_STYLE_FAMILY_SCH_CHART_ID:
721         if( ! mxChartImpPropMapper.is() )
722         {
723             XMLPropertySetMapper *pPropMapper = new XMLChartPropertySetMapper();
724             mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() );
725         }
726         xMapper = mxChartImpPropMapper;
727         break;
728 #endif
729     case XML_STYLE_FAMILY_PAGE_MASTER:
730         if( ! mxPageImpPropMapper.is() )
731         {
732             XMLPropertySetMapper *pPropMapper =
733                 new XMLPageMasterPropSetMapper();
734             mxPageImpPropMapper =
735                 new PageMasterImportPropertyMapper( pPropMapper,
736                                     ((SvXMLStylesContext*)this)->GetImport() );
737         }
738         xMapper = mxPageImpPropMapper;
739         break;
740     }
741 
742     return xMapper;
743 }
744 
GetAutoStyles(sal_uInt16 nFamily) const745 Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily ) const
746 {
747     Reference < XAutoStyleFamily > xAutoStyles;
748     if( XML_STYLE_FAMILY_TEXT_TEXT == nFamily || XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily)
749     {
750         bool bPara = XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily;
751         OUString sName;
752         if( !bPara && mxTextAutoStyles.is() )
753             xAutoStyles = mxTextAutoStyles;
754         else if( bPara && mxParaAutoStyles.is() )
755             xAutoStyles = mxParaAutoStyles;
756         else
757         {
758             sName = bPara ?
759                 OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) ):
760                 OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
761             Reference< XAutoStylesSupplier > xAutoStylesSupp(   GetImport().GetModel(), UNO_QUERY );
762             Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
763             if (xAutoStyleFamilies->hasByName(sName))
764             {
765                 Any aAny = xAutoStyleFamilies->getByName( sName );
766                 xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue();
767                 if( bPara )
768                     ((SvXMLStylesContext *)this)->mxParaAutoStyles = xAutoStyles;
769                 else
770                     ((SvXMLStylesContext *)this)->mxTextAutoStyles = xAutoStyles;
771             }
772         }
773     }
774     return xAutoStyles;
775 }
776 
GetStylesContainer(sal_uInt16 nFamily) const777 Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
778                                                 sal_uInt16 nFamily ) const
779 {
780     Reference < XNameContainer > xStyles;
781     OUString sName;
782     switch( nFamily )
783     {
784     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
785         if( mxParaStyles.is() )
786             xStyles = mxParaStyles;
787         else
788             sName =
789                 OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) );
790         break;
791 
792     case XML_STYLE_FAMILY_TEXT_TEXT:
793         if( mxTextStyles.is() )
794             xStyles = mxTextStyles;
795         else
796             sName =
797                 OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
798         break;
799     }
800     if( !xStyles.is() && sName.getLength() )
801     {
802         Reference< XStyleFamiliesSupplier > xFamiliesSupp(
803                                         GetImport().GetModel(), UNO_QUERY );
804         if ( xFamiliesSupp.is() )
805         {
806             Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
807             if (xFamilies->hasByName(sName))
808             {
809                 xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
810 
811                 switch( nFamily )
812                 {
813                 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
814                     ((SvXMLStylesContext *)this)->mxParaStyles = xStyles;
815                     break;
816 
817                 case XML_STYLE_FAMILY_TEXT_TEXT:
818                     ((SvXMLStylesContext *)this)->mxTextStyles = xStyles;
819                     break;
820                 }
821             }
822         }
823     }
824 
825     return xStyles;
826 }
827 
GetServiceName(sal_uInt16 nFamily) const828 OUString SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily ) const
829 {
830     String sServiceName;
831     switch( nFamily )
832     {
833     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
834         sServiceName = msParaStyleServiceName;
835         break;
836     case XML_STYLE_FAMILY_TEXT_TEXT:
837         sServiceName = msTextStyleServiceName;
838         break;
839     }
840 
841     return sServiceName;
842 }
843 
844 
SvXMLStylesContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &,sal_Bool bAuto)845 SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
846                                         const OUString& rLName,
847                                         const uno::Reference< xml::sax::XAttributeList > &, sal_Bool bAuto ) :
848     SvXMLImportContext( rImport, nPrfx, rLName ),
849     msParaStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphStyle" ) ),
850     msTextStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterStyle" ) ),
851     mpImpl( new SvXMLStylesContext_Impl( bAuto ) ),
852     mpStyleStylesElemTokenMap( 0 )
853 {
854 }
855 
856 
~SvXMLStylesContext()857 SvXMLStylesContext::~SvXMLStylesContext()
858 {
859     delete mpStyleStylesElemTokenMap;
860     delete mpImpl;
861 }
862 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)863 SvXMLImportContext *SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix,
864                                          const OUString& rLocalName,
865                                          const uno::Reference< xml::sax::XAttributeList > & xAttrList )
866 {
867     SvXMLImportContext *pContext = 0;
868 
869     SvXMLStyleContext *pStyle =
870         CreateStyleChildContext( nPrefix, rLocalName, xAttrList );
871 //      DBG_ASSERT( pStyle->GetFamily(), "Style without a family" );
872     if( pStyle )
873     {
874         if( !pStyle->IsTransient() )
875             mpImpl->AddStyle( pStyle );
876         pContext = pStyle;
877     }
878     else
879     {
880         pContext = new SvXMLImportContext( GetImport(), nPrefix,
881                                            rLocalName );
882     }
883 
884     return pContext;
885 }
886 
EndElement()887 void SvXMLStylesContext::EndElement()
888 {
889 }
890 
AddStyle(SvXMLStyleContext & rNew)891 void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew)
892 {
893     mpImpl->AddStyle( &rNew );
894 }
895 
Clear()896 void SvXMLStylesContext::Clear()
897 {
898     mpImpl->Clear();
899 }
900 
CopyAutoStylesToDoc()901 void SvXMLStylesContext::CopyAutoStylesToDoc()
902 {
903     sal_uInt32 nCount = GetStyleCount();
904     sal_uInt32 i;
905     for( i = 0; i < nCount; i++ )
906     {
907         SvXMLStyleContext *pStyle = GetStyle( i );
908         if( !pStyle || ( pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT &&
909             pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH  &&
910             pStyle->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL ) )
911             continue;
912         pStyle->CreateAndInsert( sal_False );
913     }
914 }
915 
CopyStylesToDoc(sal_Bool bOverwrite,sal_Bool bFinish)916 void SvXMLStylesContext::CopyStylesToDoc( sal_Bool bOverwrite,
917                                           sal_Bool bFinish )
918 {
919     // pass 1: create text, paragraph and frame styles
920     sal_uInt32 nCount = GetStyleCount();
921     sal_uInt32 i;
922 
923     for( i = 0; i < nCount; i++ )
924     {
925         SvXMLStyleContext *pStyle = GetStyle( i );
926         if( !pStyle )
927             continue;
928 
929         if (pStyle->IsDefaultStyle())
930             pStyle->SetDefaults();
931         else if( InsertStyleFamily( pStyle->GetFamily() ) )
932             pStyle->CreateAndInsert( bOverwrite );
933     }
934 
935     // pass 2: create list styles (they require char styles)
936     for( i=0; i<nCount; i++ )
937     {
938         SvXMLStyleContext *pStyle = GetStyle( i );
939         if( !pStyle || pStyle->IsDefaultStyle())
940             continue;
941 
942         if( InsertStyleFamily( pStyle->GetFamily() ) )
943             pStyle->CreateAndInsertLate( bOverwrite );
944     }
945 
946     // pass3: finish creation of styles
947     if( bFinish )
948         FinishStyles( bOverwrite );
949 }
950 
FinishStyles(sal_Bool bOverwrite)951 void SvXMLStylesContext::FinishStyles( sal_Bool bOverwrite )
952 {
953     sal_uInt32 nCount = GetStyleCount();
954     for( sal_uInt32 i=0; i<nCount; i++ )
955     {
956         SvXMLStyleContext *pStyle = GetStyle( i );
957         if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
958             continue;
959 
960         if( InsertStyleFamily( pStyle->GetFamily() ) )
961             pStyle->Finish( bOverwrite );
962     }
963 }
964 
965 
FindStyleChildContext(sal_uInt16 nFamily,const OUString & rName,sal_Bool bCreateIndex) const966 const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext(
967                                   sal_uInt16 nFamily,
968                                   const OUString& rName,
969                                   sal_Bool bCreateIndex ) const
970 {
971     return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
972 }
973