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