1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlstyle.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/xml/sax/SAXParseException.hpp>
34 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
35 #include <com/sun/star/xml/sax/SAXException.hpp>
36 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
37 #include <com/sun/star/xml/sax/XAttributeList.hpp>
38 #include <com/sun/star/xml/sax/XLocator.hpp>
39 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
42 #include <com/sun/star/style/XAutoStylesSupplier.hpp>
43 #include <com/sun/star/style/XAutoStyleFamily.hpp>
44 #ifndef _XMLOFF_PAGEMASTERPROPMAPPER_HXX
45 #include "PageMasterPropMapper.hxx"
47 #include <tools/debug.hxx>
48 #include <tools/list.hxx>
49 #include <svtools/cntnrsrt.hxx>
50 #include <svtools/itemset.hxx>
51 #include <xmloff/nmspmap.hxx>
52 #include "xmlnmspe.hxx"
53 #include <xmloff/xmltoken.hxx>
55 #ifndef _XMLOFF_FAMILIES_HXX
56 #include <xmloff/families.hxx>
58 #include <xmloff/xmlimp.hxx>
59 #include <xmloff/xmlnumi.hxx>
60 #include <xmloff/xmlimppr.hxx>
61 #include <xmloff/xmlstyle.hxx>
62 #ifndef _XMLOFF_TXTSTYLI_HXX
63 #include <xmloff/txtstyli.hxx>
65 #ifndef _XMLOFF_TXTPRMAP_HXX
66 #include <xmloff/txtprmap.hxx>
68 #include <xmloff/xmlnumfi.hxx>
69 #include "XMLChartStyleContext.hxx"
70 #include "XMLChartPropertySetMapper.hxx"
71 #include <xmloff/XMLShapeStyleContext.hxx>
72 #include "FillStyleContext.hxx"
73 #include "XMLFootnoteConfigurationImportContext.hxx"
74 #include "XMLIndexBibliographyConfigurationContext.hxx"
75 #include "XMLLineNumberingImportContext.hxx"
76 #include "PageMasterImportContext.hxx"
77 #include "PageMasterImportPropMapper.hxx"
79 using ::rtl::OUString
;
80 using ::rtl::OUStringBuffer
;
82 using namespace ::com::sun::star
;
83 using namespace ::com::sun::star::uno
;
84 using namespace ::com::sun::star::container
;
85 using namespace ::com::sun::star::style
;
86 using namespace ::xmloff::token
;
88 // ---------------------------------------------------------------------
90 static __FAR_DATA SvXMLTokenMapEntry aStyleStylesElemTokenMap
[] =
92 { XML_NAMESPACE_STYLE
, XML_STYLE
, XML_TOK_STYLE_STYLE
},
93 { XML_NAMESPACE_STYLE
, XML_PAGE_LAYOUT
, XML_TOK_STYLE_PAGE_MASTER
},
94 { XML_NAMESPACE_TEXT
, XML_LIST_STYLE
, XML_TOK_TEXT_LIST_STYLE
},
95 { XML_NAMESPACE_TEXT
, XML_OUTLINE_STYLE
, XML_TOK_TEXT_OUTLINE
},
96 { XML_NAMESPACE_STYLE
, XML_DEFAULT_STYLE
, XML_TOK_STYLE_DEFAULT_STYLE
},
97 { XML_NAMESPACE_DRAW
, XML_GRADIENT
, XML_TOK_STYLES_GRADIENTSTYLES
},
98 { XML_NAMESPACE_DRAW
, XML_HATCH
, XML_TOK_STYLES_HATCHSTYLES
},
99 { XML_NAMESPACE_DRAW
, XML_FILL_IMAGE
, XML_TOK_STYLES_BITMAPSTYLES
},
100 { XML_NAMESPACE_DRAW
, XML_OPACITY
, XML_TOK_STYLES_TRANSGRADIENTSTYLES
},
101 { XML_NAMESPACE_DRAW
, XML_MARKER
, XML_TOK_STYLES_MARKERSTYLES
},
102 { XML_NAMESPACE_DRAW
, XML_STROKE_DASH
, XML_TOK_STYLES_DASHSTYLES
},
103 { XML_NAMESPACE_TEXT
, XML_NOTES_CONFIGURATION
, XML_TOK_TEXT_NOTE_CONFIG
},
104 { XML_NAMESPACE_TEXT
, XML_BIBLIOGRAPHY_CONFIGURATION
, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG
},
105 { XML_NAMESPACE_TEXT
, XML_LINENUMBERING_CONFIGURATION
,XML_TOK_TEXT_LINENUMBERING_CONFIG
},
106 { XML_NAMESPACE_STYLE
, XML_DEFAULT_PAGE_LAYOUT
, XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT
},
110 const SvXMLTokenMap
& SvXMLStylesContext::GetStyleStylesElemTokenMap()
112 if( !mpStyleStylesElemTokenMap
)
113 mpStyleStylesElemTokenMap
=
114 new SvXMLTokenMap( aStyleStylesElemTokenMap
);
116 return *mpStyleStylesElemTokenMap
;
119 // ---------------------------------------------------------------------
121 void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey
,
122 const OUString
& rLocalName
,
123 const OUString
& rValue
)
125 // TODO: use a map here
126 if( XML_NAMESPACE_STYLE
== nPrefixKey
)
128 if( IsXMLToken( rLocalName
, XML_FAMILY
) )
130 if( IsXMLToken( rValue
, XML_PARAGRAPH
) )
131 mnFamily
= (sal_uInt16
)SFX_STYLE_FAMILY_PARA
;
132 else if( IsXMLToken( rValue
, XML_TEXT
) )
133 mnFamily
= (sal_uInt16
)SFX_STYLE_FAMILY_CHAR
;
135 else if( IsXMLToken( rLocalName
, XML_NAME
) )
139 else if( IsXMLToken( rLocalName
, XML_DISPLAY_NAME
) )
141 maDisplayName
= rValue
;
143 else if( IsXMLToken( rLocalName
, XML_PARENT_STYLE_NAME
) )
145 maParentName
= rValue
;
147 else if( IsXMLToken( rLocalName
, XML_NEXT_STYLE_NAME
) )
151 else if( IsXMLToken( rLocalName
, XML_HELP_FILE_NAME
) )
155 else if( IsXMLToken( rLocalName
, XML_HELP_ID
) )
157 sal_Int32 nTmp
= rValue
.toInt32();
159 (nTmp
< 0L) ? 0U : ( (nTmp
> USHRT_MAX
) ? USHRT_MAX
160 : (sal_uInt16
)nTmp
);
165 TYPEINIT1( SvXMLStyleContext
, SvXMLImportContext
);
167 SvXMLStyleContext::SvXMLStyleContext(
168 SvXMLImport
& rImp
, sal_uInt16 nPrfx
,
169 const OUString
& rLName
,
170 const uno::Reference
< xml::sax::XAttributeList
>&,
171 sal_uInt16 nFam
, sal_Bool bDefault
) :
172 SvXMLImportContext( rImp
, nPrfx
, rLName
),
173 mnHelpId( UCHAR_MAX
),
177 mbDefaultStyle( bDefault
)
181 SvXMLStyleContext::~SvXMLStyleContext()
185 SvXMLImportContext
*SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix
,
186 const OUString
& rLocalName
,
187 const uno::Reference
< xml::sax::XAttributeList
> & )
189 return new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);;
192 void SvXMLStyleContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
194 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
195 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
197 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
199 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
200 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
202 SetAttribute( nPrefix
, aLocalName
, rValue
);
206 void SvXMLStyleContext::SetDefaults()
210 void SvXMLStyleContext::CreateAndInsert( sal_Bool
/*bOverwrite*/ )
214 void SvXMLStyleContext::CreateAndInsertLate( sal_Bool
/*bOverwrite*/ )
218 void SvXMLStyleContext::Finish( sal_Bool
/*bOverwrite*/ )
222 BOOL
SvXMLStyleContext::IsTransient() const
227 // ---------------------------------------------------------------------
229 class SvXMLStyleIndex_Impl
233 const SvXMLStyleContext
*pStyle
;
237 SvXMLStyleIndex_Impl( sal_uInt16 nFam
, const OUString
& rName
) :
244 SvXMLStyleIndex_Impl( const SvXMLStyleContext
*pStl
) :
245 sName( pStl
->GetName() ),
246 nFamily( pStl
->GetFamily() ),
251 const OUString
& GetName() const { return sName
; }
252 sal_uInt16
GetFamily() const { return nFamily
; }
253 const SvXMLStyleContext
*GetStyle() const { return pStyle
; }
256 int SvXMLStyleIndexCmp_Impl( const SvXMLStyleIndex_Impl
& r1
,
257 const SvXMLStyleIndex_Impl
& r2
)
260 if( (sal_uInt16
)r1
.GetFamily() < (sal_uInt16
)r2
.GetFamily() )
262 else if( (sal_uInt16
)r1
.GetFamily() > (sal_uInt16
)r2
.GetFamily() )
265 nRet
= (int)r1
.GetName().compareTo( r2
.GetName() );
270 // ---------------------------------------------------------------------
272 typedef SvXMLStyleContext
*SvXMLStyleContextPtr
;
273 DECLARE_LIST( SvXMLStyleContexts_Impl
, SvXMLStyleContextPtr
)
275 DECLARE_CONTAINER_SORT_DEL( SvXMLStyleIndices_Impl
, SvXMLStyleIndex_Impl
)
276 IMPL_CONTAINER_SORT( SvXMLStyleIndices_Impl
, SvXMLStyleIndex_Impl
,
277 SvXMLStyleIndexCmp_Impl
)
280 class SvXMLStylesContext_Impl
282 SvXMLStyleContexts_Impl aStyles
;
283 SvXMLStyleIndices_Impl
*pIndices
;
284 sal_Bool bAutomaticStyle
;
287 sal_uInt32 nIndexCreated
;
290 void FlushIndex() { delete pIndices
; pIndices
= 0; }
293 SvXMLStylesContext_Impl( sal_Bool bAuto
);
294 ~SvXMLStylesContext_Impl();
296 sal_uInt32
GetStyleCount() const { return aStyles
.Count(); }
298 const SvXMLStyleContext
*GetStyle( sal_uInt32 i
) const
300 return i
< aStyles
.Count() ? aStyles
.GetObject(i
) : 0;
303 SvXMLStyleContext
*GetStyle( sal_uInt32 i
)
305 return i
< aStyles
.Count() ? aStyles
.GetObject(i
) : 0;
308 inline void AddStyle( SvXMLStyleContext
*pStyle
);
311 const SvXMLStyleContext
*FindStyleChildContext( sal_uInt16 nFamily
,
312 const OUString
& rName
, sal_Bool bCreateIndex
) const;
313 sal_Bool
IsAutomaticStyle() const { return bAutomaticStyle
; }
316 SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( sal_Bool bAuto
) :
319 bAutomaticStyle( bAuto
)
325 SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl()
329 while( aStyles
.Count() )
331 SvXMLStyleContext
*pStyle
= aStyles
.GetObject(0);
332 aStyles
.Remove( 0UL );
333 pStyle
->ReleaseRef();
337 inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext
*pStyle
)
339 aStyles
.Insert( pStyle
, aStyles
.Count() );
345 void SvXMLStylesContext_Impl::Clear()
349 while( aStyles
.Count() )
351 SvXMLStyleContext
*pStyle
= aStyles
.GetObject(0);
352 aStyles
.Remove( 0UL );
353 pStyle
->ReleaseRef();
357 const SvXMLStyleContext
*SvXMLStylesContext_Impl::FindStyleChildContext(
359 const OUString
& rName
,
360 sal_Bool bCreateIndex
) const
362 const SvXMLStyleContext
*pStyle
= 0;
364 if( !pIndices
&& bCreateIndex
&& aStyles
.Count() > 0 )
367 DBG_ASSERT( 0==nIndexCreated
,
368 "Performance warning: sdbcx::Index created multiple times" );
370 ((SvXMLStylesContext_Impl
*)this)->pIndices
=
371 new SvXMLStyleIndices_Impl(
372 sal::static_int_cast
< USHORT
>(aStyles
.Count()), 5 );
373 for( sal_uInt32 i
=0; i
< aStyles
.Count(); i
++ )
375 SvXMLStyleIndex_Impl
* pStyleIndex
= new SvXMLStyleIndex_Impl( aStyles
.GetObject(i
));
376 if (!pIndices
->Insert( pStyleIndex
))
378 DBG_ERROR("Here is a double Style");
383 ((SvXMLStylesContext_Impl
*)this)->nIndexCreated
++;
389 SvXMLStyleIndex_Impl
aIndex( nFamily
, rName
);
391 if( pIndices
->Seek_Entry( &aIndex
, &nPos
) )
392 pStyle
= pIndices
->GetObject( nPos
)->GetStyle();
396 for( sal_uInt32 i
=0; !pStyle
&& i
< aStyles
.Count(); i
++ )
398 const SvXMLStyleContext
*pS
= aStyles
.GetObject( i
);
399 if( pS
->GetFamily() == nFamily
&&
400 pS
->GetName() == rName
)
407 // ---------------------------------------------------------------------
409 TYPEINIT1( SvXMLStylesContext
, SvXMLImportContext
);
411 sal_uInt32
SvXMLStylesContext::GetStyleCount() const
413 return mpImpl
->GetStyleCount();
416 SvXMLStyleContext
*SvXMLStylesContext::GetStyle( sal_uInt32 i
)
418 return mpImpl
->GetStyle( i
);
421 const SvXMLStyleContext
*SvXMLStylesContext::GetStyle( sal_uInt32 i
) const
423 return mpImpl
->GetStyle( i
);
426 sal_Bool
SvXMLStylesContext::IsAutomaticStyle() const
428 return mpImpl
->IsAutomaticStyle();
431 SvXMLStyleContext
*SvXMLStylesContext::CreateStyleChildContext(
432 sal_uInt16 p_nPrefix
,
433 const OUString
& rLocalName
,
434 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
436 SvXMLStyleContext
*pStyle
= NULL
;
438 if(GetImport().GetDataStylesImport())
440 pStyle
= GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix
,
441 rLocalName
, xAttrList
, *this);
446 const SvXMLTokenMap
& rTokenMap
= GetStyleStylesElemTokenMap();
447 sal_uInt16 nToken
= rTokenMap
.Get( p_nPrefix
, rLocalName
);
450 case XML_TOK_STYLE_STYLE
:
451 case XML_TOK_STYLE_DEFAULT_STYLE
:
453 sal_uInt16 nFamily
= 0;
454 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
455 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
457 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
460 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
462 if( XML_NAMESPACE_STYLE
== nPrefix
&&
463 IsXMLToken( aLocalName
, XML_FAMILY
) )
465 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
466 nFamily
= GetFamily( rValue
);
470 pStyle
= XML_TOK_STYLE_STYLE
==nToken
471 ? CreateStyleStyleChildContext( nFamily
, p_nPrefix
,
472 rLocalName
, xAttrList
)
473 : CreateDefaultStyleStyleChildContext( nFamily
, p_nPrefix
,
474 rLocalName
, xAttrList
);
477 case XML_TOK_STYLE_PAGE_MASTER
:
478 case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT
:
480 //there is not page family in odf now, so I specify one for it
481 sal_Bool bDefaultStyle
= XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT
== nToken
482 ? sal_True
: sal_False
;
483 pStyle
= new PageStyleContext( GetImport(), p_nPrefix
,
484 rLocalName
, xAttrList
, *this, bDefaultStyle
);
487 case XML_TOK_TEXT_LIST_STYLE
:
488 pStyle
= new SvxXMLListStyleContext( GetImport(), p_nPrefix
,
489 rLocalName
, xAttrList
);
491 case XML_TOK_TEXT_OUTLINE
:
492 pStyle
= new SvxXMLListStyleContext( GetImport(), p_nPrefix
,
493 rLocalName
, xAttrList
, sal_True
);
495 case XML_TOK_TEXT_NOTE_CONFIG
:
497 pStyle
= new XMLFootnoteConfigurationImportContext(GetImport(),
502 // create default context to skip content
503 pStyle
= new SvXMLStyleContext( GetImport(), nPrefix
, rLocalName
, xAttrList
);
504 #endif // #ifndef SVX_LIGHT
507 case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG
:
509 pStyle
= new XMLIndexBibliographyConfigurationContext(
510 GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
512 // create default context to skip content
513 pStyle
= new SvXMLStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
514 #endif // #ifndef SVX_LIGHT
517 case XML_TOK_TEXT_LINENUMBERING_CONFIG
:
519 pStyle
= new XMLLineNumberingImportContext(
520 GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
522 // create default context to skip content
523 pStyle
= new SvXMLStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
524 #endif // #ifndef SVX_LIGHT
530 case XML_TOK_STYLES_GRADIENTSTYLES
:
532 pStyle
= new XMLGradientStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
535 case XML_TOK_STYLES_HATCHSTYLES
:
537 pStyle
= new XMLHatchStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
540 case XML_TOK_STYLES_BITMAPSTYLES
:
542 pStyle
= new XMLBitmapStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
545 case XML_TOK_STYLES_TRANSGRADIENTSTYLES
:
547 pStyle
= new XMLTransGradientStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
550 case XML_TOK_STYLES_MARKERSTYLES
:
552 pStyle
= new XMLMarkerStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
555 case XML_TOK_STYLES_DASHSTYLES
:
557 pStyle
= new XMLDashStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
566 SvXMLStyleContext
*SvXMLStylesContext::CreateStyleStyleChildContext(
567 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
568 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
570 SvXMLStyleContext
*pStyle
= 0;
574 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
575 case XML_STYLE_FAMILY_TEXT_TEXT
:
576 case XML_STYLE_FAMILY_TEXT_SECTION
:
577 pStyle
= new XMLTextStyleContext( GetImport(), nPrefix
, rLocalName
,
578 xAttrList
, *this, nFamily
);
581 case XML_STYLE_FAMILY_TEXT_RUBY
:
582 pStyle
= new XMLPropStyleContext( GetImport(), nPrefix
, rLocalName
,
583 xAttrList
, *this, nFamily
);
585 case XML_STYLE_FAMILY_SCH_CHART_ID
:
586 pStyle
= new XMLChartStyleContext( GetImport(), nPrefix
, rLocalName
,
587 xAttrList
, *this, nFamily
);
590 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
591 case XML_STYLE_FAMILY_SD_PRESENTATION_ID
:
592 case XML_STYLE_FAMILY_SD_POOL_ID
:
593 pStyle
= new XMLShapeStyleContext( GetImport(), nPrefix
, rLocalName
,
594 xAttrList
, *this, nFamily
);
600 SvXMLStyleContext
*SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
601 sal_uInt16
/*nFamily*/, sal_uInt16
/*nPrefix*/, const OUString
& /*rLocalName*/,
602 const uno::Reference
< xml::sax::XAttributeList
> & )
608 sal_Bool
SvXMLStylesContext::InsertStyleFamily( sal_uInt16
) const
613 sal_uInt16
SvXMLStylesContext::GetFamily(
614 const ::rtl::OUString
& rValue
) const
616 sal_uInt16 nFamily
= 0U;
617 if( IsXMLToken( rValue
, XML_PARAGRAPH
) )
619 nFamily
= XML_STYLE_FAMILY_TEXT_PARAGRAPH
;
621 else if( IsXMLToken( rValue
, XML_TEXT
) )
623 nFamily
= XML_STYLE_FAMILY_TEXT_TEXT
;
625 else if( IsXMLToken( rValue
, XML_DATA_STYLE
) )
627 nFamily
= XML_STYLE_FAMILY_DATA_STYLE
;
629 else if ( IsXMLToken( rValue
, XML_SECTION
) )
631 nFamily
= XML_STYLE_FAMILY_TEXT_SECTION
;
633 else if( IsXMLToken( rValue
, XML_TABLE
) )
635 nFamily
= XML_STYLE_FAMILY_TABLE_TABLE
;
637 else if( IsXMLToken( rValue
, XML_TABLE_COLUMN
) )
638 nFamily
= XML_STYLE_FAMILY_TABLE_COLUMN
;
639 else if( IsXMLToken( rValue
, XML_TABLE_ROW
) )
640 nFamily
= XML_STYLE_FAMILY_TABLE_ROW
;
641 else if( IsXMLToken( rValue
, XML_TABLE_CELL
) )
642 nFamily
= XML_STYLE_FAMILY_TABLE_CELL
;
643 else if( rValue
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME
)))
645 nFamily
= XML_STYLE_FAMILY_SD_GRAPHICS_ID
;
647 else if( rValue
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_PRESENTATION_NAME
)))
649 nFamily
= XML_STYLE_FAMILY_SD_PRESENTATION_ID
;
651 else if( rValue
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_POOL_NAME
)))
653 nFamily
= XML_STYLE_FAMILY_SD_POOL_ID
;
655 else if( rValue
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME
)))
657 nFamily
= XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID
;
659 else if( rValue
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( XML_STYLE_FAMILY_SCH_CHART_NAME
)))
661 nFamily
= XML_STYLE_FAMILY_SCH_CHART_ID
;
663 else if ( IsXMLToken( rValue
, XML_RUBY
) )
665 nFamily
= XML_STYLE_FAMILY_TEXT_RUBY
;
671 UniReference
< SvXMLImportPropertyMapper
> SvXMLStylesContext::GetImportPropertyMapper(
672 sal_uInt16 nFamily
) const
674 UniReference
< SvXMLImportPropertyMapper
> xMapper
;
678 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
679 if( !mxParaImpPropMapper
.is() )
681 SvXMLStylesContext
* pThis
= (SvXMLStylesContext
*)this;
682 pThis
->mxParaImpPropMapper
=
683 pThis
->GetImport().GetTextImport()
684 ->GetParaImportPropertySetMapper();
686 xMapper
= mxParaImpPropMapper
;
688 case XML_STYLE_FAMILY_TEXT_TEXT
:
689 if( !mxTextImpPropMapper
.is() )
691 SvXMLStylesContext
* pThis
= (SvXMLStylesContext
*)this;
692 pThis
->mxTextImpPropMapper
=
693 pThis
->GetImport().GetTextImport()
694 ->GetTextImportPropertySetMapper();
696 xMapper
= mxTextImpPropMapper
;
699 case XML_STYLE_FAMILY_TEXT_SECTION
:
700 // don't cache section mapper, as it's rarely used
701 // *sigh*, cast to non-const, because this is a const method,
702 // but SvXMLImport::GetTextImport() isn't.
703 xMapper
= ((SvXMLStylesContext
*)this)->GetImport().GetTextImport()->
704 GetSectionImportPropertySetMapper();
707 case XML_STYLE_FAMILY_TEXT_RUBY
:
708 // don't cache section mapper, as it's rarely used
709 // *sigh*, cast to non-const, because this is a const method,
710 // but SvXMLImport::GetTextImport() isn't.
711 xMapper
= ((SvXMLStylesContext
*)this)->GetImport().GetTextImport()->
712 GetRubyImportPropertySetMapper();
715 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
716 case XML_STYLE_FAMILY_SD_PRESENTATION_ID
:
717 case XML_STYLE_FAMILY_SD_POOL_ID
:
718 if(!mxShapeImpPropMapper
.is())
720 UniReference
< XMLShapeImportHelper
> aImpHelper
= ((SvXMLImport
&)GetImport()).GetShapeImport();
721 ((SvXMLStylesContext
*)this)->mxShapeImpPropMapper
=
722 aImpHelper
->GetPropertySetMapper();
724 xMapper
= mxShapeImpPropMapper
;
727 case XML_STYLE_FAMILY_SCH_CHART_ID
:
728 if( ! mxChartImpPropMapper
.is() )
730 XMLPropertySetMapper
*pPropMapper
= new XMLChartPropertySetMapper();
731 mxChartImpPropMapper
= new XMLChartImportPropertyMapper( pPropMapper
, GetImport() );
733 xMapper
= mxChartImpPropMapper
;
736 case XML_STYLE_FAMILY_PAGE_MASTER
:
737 if( ! mxPageImpPropMapper
.is() )
739 XMLPropertySetMapper
*pPropMapper
=
740 new XMLPageMasterPropSetMapper();
741 mxPageImpPropMapper
=
742 new PageMasterImportPropertyMapper( pPropMapper
,
743 ((SvXMLStylesContext
*)this)->GetImport() );
745 xMapper
= mxPageImpPropMapper
;
752 Reference
< XAutoStyleFamily
> SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily
) const
754 Reference
< XAutoStyleFamily
> xAutoStyles
;
755 if( XML_STYLE_FAMILY_TEXT_TEXT
== nFamily
|| XML_STYLE_FAMILY_TEXT_PARAGRAPH
== nFamily
)
757 bool bPara
= XML_STYLE_FAMILY_TEXT_PARAGRAPH
== nFamily
;
759 if( !bPara
&& mxTextAutoStyles
.is() )
760 xAutoStyles
= mxTextAutoStyles
;
761 else if( bPara
&& mxParaAutoStyles
.is() )
762 xAutoStyles
= mxParaAutoStyles
;
766 OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) ):
767 OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
768 Reference
< XAutoStylesSupplier
> xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY
);
769 Reference
< XAutoStyles
> xAutoStyleFamilies
= xAutoStylesSupp
->getAutoStyles();
770 if (xAutoStyleFamilies
->hasByName(sName
))
772 Any aAny
= xAutoStyleFamilies
->getByName( sName
);
773 xAutoStyles
= *(Reference
<XAutoStyleFamily
>*)aAny
.getValue();
775 ((SvXMLStylesContext
*)this)->mxParaAutoStyles
= xAutoStyles
;
777 ((SvXMLStylesContext
*)this)->mxTextAutoStyles
= xAutoStyles
;
784 Reference
< XNameContainer
> SvXMLStylesContext::GetStylesContainer(
785 sal_uInt16 nFamily
) const
787 Reference
< XNameContainer
> xStyles
;
791 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
792 if( mxParaStyles
.is() )
793 xStyles
= mxParaStyles
;
796 OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) );
799 case XML_STYLE_FAMILY_TEXT_TEXT
:
800 if( mxTextStyles
.is() )
801 xStyles
= mxTextStyles
;
804 OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
807 if( !xStyles
.is() && sName
.getLength() )
809 Reference
< XStyleFamiliesSupplier
> xFamiliesSupp(
810 GetImport().GetModel(), UNO_QUERY
);
811 if ( xFamiliesSupp
.is() )
813 Reference
< XNameAccess
> xFamilies
= xFamiliesSupp
->getStyleFamilies();
814 if (xFamilies
->hasByName(sName
))
816 xStyles
.set(xFamilies
->getByName( sName
),uno::UNO_QUERY
);
820 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
821 ((SvXMLStylesContext
*)this)->mxParaStyles
= xStyles
;
824 case XML_STYLE_FAMILY_TEXT_TEXT
:
825 ((SvXMLStylesContext
*)this)->mxTextStyles
= xStyles
;
835 OUString
SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily
) const
840 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
841 sServiceName
= msParaStyleServiceName
;
843 case XML_STYLE_FAMILY_TEXT_TEXT
:
844 sServiceName
= msTextStyleServiceName
;
852 SvXMLStylesContext::SvXMLStylesContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
853 const OUString
& rLName
,
854 const uno::Reference
< xml::sax::XAttributeList
> &, sal_Bool bAuto
) :
855 SvXMLImportContext( rImport
, nPrfx
, rLName
),
856 msParaStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphStyle" ) ),
857 msTextStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterStyle" ) ),
858 mpImpl( new SvXMLStylesContext_Impl( bAuto
) ),
859 mpStyleStylesElemTokenMap( 0 )
864 SvXMLStylesContext::~SvXMLStylesContext()
866 delete mpStyleStylesElemTokenMap
;
870 SvXMLImportContext
*SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix
,
871 const OUString
& rLocalName
,
872 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
874 SvXMLImportContext
*pContext
= 0;
876 SvXMLStyleContext
*pStyle
=
877 CreateStyleChildContext( nPrefix
, rLocalName
, xAttrList
);
878 // DBG_ASSERT( pStyle->GetFamily(), "Style without a family" );
881 if( !pStyle
->IsTransient() )
882 mpImpl
->AddStyle( pStyle
);
887 pContext
= new SvXMLImportContext( GetImport(), nPrefix
,
894 void SvXMLStylesContext::EndElement()
898 void SvXMLStylesContext::AddStyle(SvXMLStyleContext
& rNew
)
900 mpImpl
->AddStyle( &rNew
);
903 void SvXMLStylesContext::Clear()
908 void SvXMLStylesContext::CopyAutoStylesToDoc()
910 sal_uInt32 nCount
= GetStyleCount();
912 for( i
= 0; i
< nCount
; i
++ )
914 SvXMLStyleContext
*pStyle
= GetStyle( i
);
915 if( !pStyle
|| ( pStyle
->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT
&&
916 pStyle
->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH
&&
917 pStyle
->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL
) )
919 pStyle
->CreateAndInsert( sal_False
);
923 void SvXMLStylesContext::CopyStylesToDoc( sal_Bool bOverwrite
,
926 // pass 1: create text, paragraph and frame styles
927 sal_uInt32 nCount
= GetStyleCount();
930 for( i
= 0; i
< nCount
; i
++ )
932 SvXMLStyleContext
*pStyle
= GetStyle( i
);
936 if (pStyle
->IsDefaultStyle())
937 pStyle
->SetDefaults();
938 else if( InsertStyleFamily( pStyle
->GetFamily() ) )
939 pStyle
->CreateAndInsert( bOverwrite
);
942 // pass 2: create list styles (they require char styles)
943 for( i
=0; i
<nCount
; i
++ )
945 SvXMLStyleContext
*pStyle
= GetStyle( i
);
946 if( !pStyle
|| pStyle
->IsDefaultStyle())
949 if( InsertStyleFamily( pStyle
->GetFamily() ) )
950 pStyle
->CreateAndInsertLate( bOverwrite
);
953 // pass3: finish creation of styles
955 FinishStyles( bOverwrite
);
958 void SvXMLStylesContext::FinishStyles( sal_Bool bOverwrite
)
960 sal_uInt32 nCount
= GetStyleCount();
961 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
963 SvXMLStyleContext
*pStyle
= GetStyle( i
);
964 if( !pStyle
|| !pStyle
->IsValid() || pStyle
->IsDefaultStyle() )
967 if( InsertStyleFamily( pStyle
->GetFamily() ) )
968 pStyle
->Finish( bOverwrite
);
973 const SvXMLStyleContext
*SvXMLStylesContext::FindStyleChildContext(
975 const OUString
& rName
,
976 sal_Bool bCreateIndex
) const
978 return mpImpl
->FindStyleChildContext( nFamily
, rName
, bCreateIndex
);