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