LibreOffice Module xmloff (master)  1
xmlstyle.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/xml/sax/XAttributeList.hpp>
24 #include <com/sun/star/container/XNameContainer.hpp>
25 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
26 #include <com/sun/star/style/XAutoStylesSupplier.hpp>
27 #include <com/sun/star/style/XAutoStyleFamily.hpp>
28 #include "PageMasterPropMapper.hxx"
29 #include <sal/log.hxx>
30 #include <svl/style.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmlnmspe.hxx>
33 #include <xmloff/xmltoken.hxx>
34 
35 #include <xmloff/families.hxx>
36 #include <xmloff/xmlimp.hxx>
37 #include <xmloff/xmlnumi.hxx>
38 #include <xmloff/xmlimppr.hxx>
39 #include <xmloff/xmlstyle.hxx>
40 #include <xmloff/txtstyli.hxx>
41 #include <xmloff/xmlnumfi.hxx>
42 #include <XMLChartStyleContext.hxx>
45 #include "FillStyleContext.hxx"
51 
52 #include <memory>
53 #include <set>
54 #include <vector>
55 
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::container;
59 using namespace ::com::sun::star::style;
60 using namespace ::xmloff::token;
61 
63 {
80 };
81 
82 static const OUStringLiteral gsParaStyleServiceName( "com.sun.star.style.ParagraphStyle" );
83 static const OUStringLiteral gsTextStyleServiceName( "com.sun.star.style.CharacterStyle" );
84 
86 {
89  new SvXMLTokenMap( aStyleStylesElemTokenMap ) );
90 
92 }
93 
94 void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
95  const OUString& rLocalName,
96  const OUString& rValue )
97 {
98  // TODO: use a map here
99  if( XML_NAMESPACE_STYLE == nPrefixKey )
100  {
101  if( IsXMLToken( rLocalName, XML_FAMILY ) )
102  {
103  if( IsXMLToken( rValue, XML_PARAGRAPH ) )
104  mnFamily = XmlStyleFamily(SfxStyleFamily::Para);
105  else if( IsXMLToken( rValue, XML_TEXT ) )
106  mnFamily = XmlStyleFamily(SfxStyleFamily::Char);
107  }
108  else if( IsXMLToken( rLocalName, XML_NAME ) )
109  {
110  maName = rValue;
111  }
112  else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) )
113  {
115  }
116  else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) )
117  {
119  }
120  else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) )
121  {
122  maFollow = rValue;
123  }
124  else if( IsXMLToken( rLocalName, XML_HIDDEN ) )
125  {
126  mbHidden = rValue.toBoolean();
127  }
128  }
129 }
130 
131 
133  SvXMLImport& rImp, sal_uInt16 nPrfx,
134  const OUString& rLName,
135  const uno::Reference< xml::sax::XAttributeList >&,
136  XmlStyleFamily nFam, bool bDefault ) :
137  SvXMLImportContext( rImp, nPrfx, rLName ),
138  mbHidden( false ),
139  mnFamily( nFam ),
140  mbValid( true ),
141  mbNew( true ),
142  mbDefaultStyle( bDefault )
143 {
144 }
145 
147  SvXMLImport& rImp,
148  sal_Int32 /*nElement*/,
149  const css::uno::Reference< css::xml::sax::XFastAttributeList > &,
150  XmlStyleFamily nFam, bool bDefault ) :
151  SvXMLImportContext( rImp ),
152  mbHidden( false ),
153  mnFamily( nFam ),
154  mbValid( true ),
155  mbNew( true ),
156  mbDefaultStyle( bDefault )
157 {
158 }
159 
161 {
162 }
163 
164 void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttributeList > & xAttrList )
165 {
166  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
167  for( sal_Int16 i=0; i < nAttrCount; i++ )
168  {
169  const OUString& rAttrName = xAttrList->getNameByIndex( i );
170  OUString aLocalName;
171  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
172  const OUString& rValue = xAttrList->getValueByIndex( i );
173 
174  SetAttribute( nPrefix, aLocalName, rValue );
175  }
176 }
177 
179 {
180 }
181 
182 void SvXMLStyleContext::CreateAndInsert( bool /*bOverwrite*/ )
183 {
184 }
185 
186 void SvXMLStyleContext::CreateAndInsertLate( bool /*bOverwrite*/ )
187 {
188 }
189 
190 void SvXMLStyleContext::Finish( bool /*bOverwrite*/ )
191 {
192 }
193 
195 {
196  return false;
197 }
198 
199 namespace {
200 
201 class SvXMLStyleIndex_Impl
202 {
203  OUString sName;
204  XmlStyleFamily nFamily;
205  const rtl::Reference<SvXMLStyleContext> mxStyle;
206 
207 public:
208 
209  SvXMLStyleIndex_Impl( XmlStyleFamily nFam, const OUString& rName ) :
210  sName( rName ),
211  nFamily( nFam )
212  {
213  }
214 
215  SvXMLStyleIndex_Impl( const rtl::Reference<SvXMLStyleContext> &rStl ) :
216  sName( rStl->GetName() ),
217  nFamily( rStl->GetFamily() ),
218  mxStyle ( rStl )
219  {
220  }
221 
222  const OUString& GetName() const { return sName; }
223  XmlStyleFamily GetFamily() const { return nFamily; }
224  const SvXMLStyleContext *GetStyle() const { return mxStyle.get(); }
225 };
226 
227 struct SvXMLStyleIndexCmp_Impl
228 {
229  bool operator()(const SvXMLStyleIndex_Impl& r1, const SvXMLStyleIndex_Impl& r2) const
230  {
231  sal_Int32 nRet;
232 
233  if( r1.GetFamily() < r2.GetFamily() )
234  nRet = -1;
235  else if( r1.GetFamily() > r2.GetFamily() )
236  nRet = 1;
237  else
238  nRet = r1.GetName().compareTo( r2.GetName() );
239 
240  return nRet < 0;
241  }
242 };
243 
244 }
245 
247 {
248  typedef std::set<SvXMLStyleIndex_Impl, SvXMLStyleIndexCmp_Impl> IndicesType;
249 
250  std::vector<rtl::Reference<SvXMLStyleContext>> aStyles;
251  mutable std::unique_ptr<IndicesType> pIndices;
253 
254 #if OSL_DEBUG_LEVEL > 0
255  mutable sal_uInt32 m_nIndexCreated;
256 #endif
257 
258  void FlushIndex() { pIndices.reset(); }
259 
260 public:
261  explicit SvXMLStylesContext_Impl( bool bAuto );
262 
263  size_t GetStyleCount() const { return aStyles.size(); }
264 
266  {
267  return i < aStyles.size() ? aStyles[ i ].get() : nullptr;
268  }
269 
270  inline void AddStyle( SvXMLStyleContext *pStyle );
271  void Clear();
272 
274  const OUString& rName,
275  bool bCreateIndex ) const;
276  bool IsAutomaticStyle() const { return bAutomaticStyle; }
277 };
278 
280  bAutomaticStyle( bAuto )
281 #if OSL_DEBUG_LEVEL > 0
282  , m_nIndexCreated( 0 )
283 #endif
284 {}
285 
287 {
288  aStyles.emplace_back(pStyle );
289 
290  FlushIndex();
291 }
292 
294 {
295  FlushIndex();
296  aStyles.clear();
297 }
298 
300  const OUString& rName,
301  bool bCreateIndex ) const
302 {
303  const SvXMLStyleContext *pStyle = nullptr;
304 
305  if( !pIndices && bCreateIndex && !aStyles.empty() )
306  {
307  pIndices = std::make_unique<IndicesType>(aStyles.begin(), aStyles.end());
308  SAL_WARN_IF(pIndices->size() != aStyles.size(), "xmloff.style", "Here is a duplicate Style");
309 #if OSL_DEBUG_LEVEL > 0
310  SAL_WARN_IF(0 != m_nIndexCreated, "xmloff.style",
311  "Performance warning: sdbcx::Index created multiple times");
312  ++m_nIndexCreated;
313 #endif
314  }
315 
316  if( pIndices )
317  {
318  SvXMLStyleIndex_Impl aIndex( nFamily, rName );
319  IndicesType::iterator aFind = pIndices->find(aIndex);
320  if( aFind != pIndices->end() )
321  pStyle = aFind->GetStyle();
322  }
323  else
324  {
325  for( size_t i = 0; !pStyle && i < aStyles.size(); i++ )
326  {
327  const SvXMLStyleContext *pS = aStyles[ i ].get();
328  if( pS->GetFamily() == nFamily &&
329  pS->GetName() == rName )
330  pStyle = pS;
331  }
332  }
333  return pStyle;
334 }
335 
336 
338 {
339  return mpImpl->GetStyleCount();
340 }
341 
343 {
344  return mpImpl->GetStyle( i );
345 }
346 
348 {
349  return mpImpl->GetStyle( i );
350 }
351 
353 {
354  return mpImpl->IsAutomaticStyle();
355 }
356 
358  const OUString& rLocalName,
359  const uno::Reference< xml::sax::XAttributeList > & xAttrList )
360 {
361  SvXMLStyleContext *pStyle = nullptr;
362 
363  if(GetImport().GetDataStylesImport())
364  {
365  pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix,
366  rLocalName, xAttrList, *this);
367  }
368 
369  if (!pStyle)
370  {
371  const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap();
372  sal_uInt16 nToken = rTokenMap.Get( p_nPrefix, rLocalName );
373  switch( nToken )
374  {
375  case XML_TOK_STYLE_STYLE:
377  {
379  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
380  for( sal_Int16 i=0; i < nAttrCount; i++ )
381  {
382  const OUString& rAttrName = xAttrList->getNameByIndex( i );
383  OUString aLocalName;
384  sal_uInt16 nPrefix =
386  &aLocalName );
387  if( XML_NAMESPACE_STYLE == nPrefix &&
388  IsXMLToken( aLocalName, XML_FAMILY ) )
389  {
390  const OUString& rValue = xAttrList->getValueByIndex( i );
391  nFamily = GetFamily( rValue );
392  break;
393  }
394  }
395  pStyle = XML_TOK_STYLE_STYLE==nToken
396  ? CreateStyleStyleChildContext( nFamily, p_nPrefix,
397  rLocalName, xAttrList )
398  : CreateDefaultStyleStyleChildContext( nFamily, p_nPrefix,
399  rLocalName, xAttrList );
400  }
401  break;
404  {
405  //there is not page family in ODF now, so I specify one for it
406  bool bDefaultStyle = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken;
407  pStyle = new PageStyleContext( GetImport(), p_nPrefix,
408  rLocalName, xAttrList, *this, bDefaultStyle );
409  }
410  break;
412  pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
413  rLocalName, xAttrList );
414  break;
416  pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
417  rLocalName, xAttrList, true );
418  break;
421  p_nPrefix,
422  rLocalName,
423  xAttrList);
424  break;
425 
428  GetImport(), p_nPrefix, rLocalName, xAttrList);
429  break;
430 
432  pStyle = new XMLLineNumberingImportContext(
433  GetImport(), p_nPrefix, rLocalName, xAttrList);
434  break;
435 
436 
437  // FillStyles
438 
440  {
441  pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
442  break;
443  }
445  {
446  pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
447  break;
448  }
450  {
451  pStyle = new XMLBitmapStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
452  break;
453  }
455  {
456  pStyle = new XMLTransGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
457  break;
458  }
460  {
461  pStyle = new XMLMarkerStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
462  break;
463  }
465  {
466  pStyle = new XMLDashStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
467  break;
468  }
469  }
470  }
471 
472  return pStyle;
473 }
474 
476  XmlStyleFamily nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
477  const uno::Reference< xml::sax::XAttributeList > & xAttrList )
478 {
479  SvXMLStyleContext *pStyle = nullptr;
480 
481  switch( nFamily )
482  {
486  pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
487  xAttrList, *this, nFamily );
488  break;
489 
491  pStyle = new XMLPropStyleContext( GetImport(), nPrefix, rLocalName,
492  xAttrList, *this, nFamily );
493  break;
495  pStyle = new XMLChartStyleContext( GetImport(), nPrefix, rLocalName,
496  xAttrList, *this, nFamily );
497  break;
498 
502  pStyle = new XMLShapeStyleContext( GetImport(), nPrefix, rLocalName,
503  xAttrList, *this, nFamily );
504  break;
505  default: break;
506  }
507 
508  return pStyle;
509 }
510 
512  XmlStyleFamily /*nFamily*/, sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/,
513  const uno::Reference< xml::sax::XAttributeList > & )
514 {
515  return nullptr;
516 }
517 
519 {
520  return true;
521 }
522 
524 {
526  if( IsXMLToken( rValue, XML_PARAGRAPH ) )
527  {
529  }
530  else if( IsXMLToken( rValue, XML_TEXT ) )
531  {
532  nFamily = XmlStyleFamily::TEXT_TEXT;
533  }
534  else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
535  {
536  nFamily = XmlStyleFamily::DATA_STYLE;
537  }
538  else if ( IsXMLToken( rValue, XML_SECTION ) )
539  {
541  }
542  else if( IsXMLToken( rValue, XML_TABLE ) )
543  {
544  nFamily = XmlStyleFamily::TABLE_TABLE;
545  }
546  else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
548  else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
549  nFamily = XmlStyleFamily::TABLE_ROW;
550  else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
551  nFamily = XmlStyleFamily::TABLE_CELL;
552  else if ( rValue == XML_STYLE_FAMILY_SD_GRAPHICS_NAME )
553  {
555  }
556  else if ( rValue == XML_STYLE_FAMILY_SD_PRESENTATION_NAME )
557  {
559  }
560  else if ( rValue == XML_STYLE_FAMILY_SD_POOL_NAME )
561  {
562  nFamily = XmlStyleFamily::SD_POOL_ID;
563  }
564  else if ( rValue == XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME )
565  {
567  }
568  else if ( rValue == XML_STYLE_FAMILY_SCH_CHART_NAME )
569  {
571  }
572  else if ( IsXMLToken( rValue, XML_RUBY ) )
573  {
574  nFamily = XmlStyleFamily::TEXT_RUBY;
575  }
576 
577  return nFamily;
578 }
579 
581  XmlStyleFamily nFamily ) const
582 {
584 
585  switch( nFamily )
586  {
588  if( !mxParaImpPropMapper.is() )
589  {
590  SvXMLStylesContext * pThis = const_cast<SvXMLStylesContext *>(this);
591  pThis->mxParaImpPropMapper =
592  pThis->GetImport().GetTextImport()
593  ->GetParaImportPropertySetMapper();
594  }
595  xMapper = mxParaImpPropMapper;
596  break;
598  if( !mxTextImpPropMapper.is() )
599  {
600  SvXMLStylesContext * pThis = const_cast<SvXMLStylesContext *>(this);
601  pThis->mxTextImpPropMapper =
602  pThis->GetImport().GetTextImport()
603  ->GetTextImportPropertySetMapper();
604  }
605  xMapper = mxTextImpPropMapper;
606  break;
607 
609  // don't cache section mapper, as it's rarely used
610  // *sigh*, cast to non-const, because this is a const method,
611  // but SvXMLImport::GetTextImport() isn't.
612  xMapper = const_cast<SvXMLStylesContext*>(this)->GetImport().GetTextImport()->
613  GetSectionImportPropertySetMapper();
614  break;
615 
617  // don't cache section mapper, as it's rarely used
618  // *sigh*, cast to non-const, because this is a const method,
619  // but SvXMLImport::GetTextImport() isn't.
620  xMapper = const_cast<SvXMLStylesContext*>(this)->GetImport().GetTextImport()->
621  GetRubyImportPropertySetMapper();
622  break;
623 
627  if(!mxShapeImpPropMapper.is())
628  {
629  rtl::Reference< XMLShapeImportHelper > aImpHelper = const_cast<SvXMLImport&>(GetImport()).GetShapeImport();
630  const_cast<SvXMLStylesContext*>(this)->mxShapeImpPropMapper =
631  aImpHelper->GetPropertySetMapper();
632  }
633  xMapper = mxShapeImpPropMapper;
634  break;
636  if( ! mxChartImpPropMapper.is() )
637  {
638  XMLPropertySetMapper *pPropMapper = new XMLChartPropertySetMapper( false );
640  }
641  xMapper = mxChartImpPropMapper;
642  break;
644  if( ! mxPageImpPropMapper.is() )
645  {
646  XMLPropertySetMapper *pPropMapper =
649  new PageMasterImportPropertyMapper( pPropMapper,
650  const_cast<SvXMLStylesContext*>(this)->GetImport() );
651  }
652  xMapper = mxPageImpPropMapper;
653  break;
654  default: break;
655  }
656 
657  return xMapper;
658 }
659 
660 Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( XmlStyleFamily nFamily ) const
661 {
662  Reference < XAutoStyleFamily > xAutoStyles;
663  if( XmlStyleFamily::TEXT_TEXT == nFamily || XmlStyleFamily::TEXT_PARAGRAPH == nFamily)
664  {
665  bool bPara = XmlStyleFamily::TEXT_PARAGRAPH == nFamily;
666  OUString sName;
667  if( !bPara && mxTextAutoStyles.is() )
668  xAutoStyles = mxTextAutoStyles;
669  else if( bPara && mxParaAutoStyles.is() )
670  xAutoStyles = mxParaAutoStyles;
671  else
672  {
673  sName = bPara ? OUStringLiteral( "ParagraphStyles" ): OUStringLiteral( "CharacterStyles" );
674  Reference< XAutoStylesSupplier > xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY );
675  Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
676  if (xAutoStyleFamilies->hasByName(sName))
677  {
678  Any aAny = xAutoStyleFamilies->getByName( sName );
679  aAny >>= xAutoStyles;
680  if( bPara )
681  const_cast<SvXMLStylesContext *>(this)->mxParaAutoStyles = xAutoStyles;
682  else
683  const_cast<SvXMLStylesContext *>(this)->mxTextAutoStyles = xAutoStyles;
684  }
685  }
686  }
687  return xAutoStyles;
688 }
689 
690 Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
691  XmlStyleFamily nFamily ) const
692 {
693  Reference < XNameContainer > xStyles;
694  OUString sName;
695  switch( nFamily )
696  {
698  if( mxParaStyles.is() )
699  xStyles = mxParaStyles;
700  else
701  sName = "ParagraphStyles";
702  break;
703 
705  if( mxTextStyles.is() )
706  xStyles = mxTextStyles;
707  else
708  sName = "CharacterStyles";
709  break;
710  default: break;
711  }
712  if( !xStyles.is() && !sName.isEmpty() )
713  {
714  Reference< XStyleFamiliesSupplier > xFamiliesSupp(
715  GetImport().GetModel(), UNO_QUERY );
716  if ( xFamiliesSupp.is() )
717  {
718  Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
719  if (xFamilies->hasByName(sName))
720  {
721  xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
722 
723  switch( nFamily )
724  {
726  const_cast<SvXMLStylesContext *>(this)->mxParaStyles = xStyles;
727  break;
728 
730  const_cast<SvXMLStylesContext *>(this)->mxTextStyles = xStyles;
731  break;
732  default: break;
733  }
734  }
735  }
736  }
737 
738  return xStyles;
739 }
740 
742 {
743  OUString sServiceName;
744  switch( nFamily )
745  {
747  sServiceName = gsParaStyleServiceName;
748  break;
750  sServiceName = gsTextStyleServiceName;
751  break;
752  default: break;
753  }
754 
755  return sServiceName;
756 }
757 
759  SvXMLImportContext( rImport ),
760  mpImpl( new SvXMLStylesContext_Impl( bAuto ) )
761 {
762 }
763 
765 {
766 }
767 
768 css::uno::Reference< css::xml::sax::XFastContextHandler > SvXMLStylesContext::createFastChildContext(
769  sal_Int32 /*nElement*/, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
770 {
771  return nullptr;
772 }
773 
775  const OUString& rLocalName,
776  const uno::Reference< xml::sax::XAttributeList > & xAttrList )
777 {
778  SvXMLImportContext *pContext = nullptr;
779 
780  SvXMLStyleContext *pStyle =
781  CreateStyleChildContext( nPrefix, rLocalName, xAttrList );
782  if( pStyle )
783  {
784  if( !pStyle->IsTransient() )
785  mpImpl->AddStyle( pStyle );
786  pContext = pStyle;
787  }
788 
789  return pContext;
790 }
791 
793 {
794 }
795 
797 {
798  mpImpl->AddStyle( &rNew );
799 }
800 
802 {
803  mpImpl->Clear();
804 }
805 
807 {
808  sal_uInt32 nCount = GetStyleCount();
809  sal_uInt32 i;
810  for( i = 0; i < nCount; i++ )
811  {
812  SvXMLStyleContext *pStyle = GetStyle( i );
813  if( !pStyle || ( pStyle->GetFamily() != XmlStyleFamily::TEXT_TEXT &&
815  pStyle->GetFamily() != XmlStyleFamily::TABLE_CELL ) )
816  continue;
817  pStyle->CreateAndInsert( false );
818  }
819 }
820 
822  bool bFinish )
823 {
824  // pass 1: create text, paragraph and frame styles
825  sal_uInt32 nCount = GetStyleCount();
826  sal_uInt32 i;
827 
828  for( i = 0; i < nCount; i++ )
829  {
830  SvXMLStyleContext *pStyle = GetStyle( i );
831  if( !pStyle )
832  continue;
833 
834  if (pStyle->IsDefaultStyle())
835  pStyle->SetDefaults();
836  else if( InsertStyleFamily( pStyle->GetFamily() ) )
837  pStyle->CreateAndInsert( bOverwrite );
838  }
839 
840  // pass 2: create list styles (they require char styles)
841  for( i=0; i<nCount; i++ )
842  {
843  SvXMLStyleContext *pStyle = GetStyle( i );
844  if( !pStyle || pStyle->IsDefaultStyle())
845  continue;
846 
847  if( InsertStyleFamily( pStyle->GetFamily() ) )
848  pStyle->CreateAndInsertLate( bOverwrite );
849  }
850 
851  // pass3: finish creation of styles
852  if( bFinish )
853  FinishStyles( bOverwrite );
854 }
855 
856 void SvXMLStylesContext::FinishStyles( bool bOverwrite )
857 {
858  sal_uInt32 nCount = GetStyleCount();
859  for( sal_uInt32 i=0; i<nCount; i++ )
860  {
861  SvXMLStyleContext *pStyle = GetStyle( i );
862  if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
863  continue;
864 
865  if( InsertStyleFamily( pStyle->GetFamily() ) )
866  pStyle->Finish( bOverwrite );
867  }
868 }
869 
871  XmlStyleFamily nFamily,
872  const OUString& rName,
873  bool bCreateIndex ) const
874 {
875  return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
876 }
877 
878 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::style::XAutoStyleFamily > mxTextAutoStyles
Definition: xmlstyle.hxx:162
XmlStyleFamily GetFamily() const
Definition: xmlstyle.hxx:112
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:30
std::set< SvXMLStyleIndex_Impl, SvXMLStyleIndexCmp_Impl > IndicesType
Definition: xmlstyle.cxx:248
bool IsAutomaticStyle() const
Definition: xmlstyle.cxx:276
void CopyAutoStylesToDoc()
Definition: xmlstyle.cxx:806
OUString maParentName
Definition: xmlstyle.hxx:64
std::vector< rtl::Reference< SvXMLStyleContext > > aStyles
Definition: xmlstyle.cxx:250
rtl::Reference< SvXMLImportPropertyMapper > mxParaImpPropMapper
Definition: xmlstyle.hxx:164
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex) const
Definition: xmlstyle.cxx:299
size_t GetStyleCount() const
Definition: xmlstyle.cxx:263
css::uno::Reference< css::container::XNameContainer > mxParaStyles
Definition: xmlstyle.hxx:156
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
virtual SvXMLStyleContext * CreateStyleChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
Definition: xmlstyle.cxx:357
SvXMLStyleContext * GetStyle(sal_uInt32 i)
Definition: xmlstyle.cxx:342
css::uno::Reference< css::style::XAutoStyleFamily > GetAutoStyles(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:660
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:397
bool IsDefaultStyle() const
Definition: xmlstyle.hxx:137
SvXMLNumFmtHelper * GetDataStylesImport()
Definition: xmlimp.hxx:646
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:31
virtual ~SvXMLStyleContext() override
Definition: xmlstyle.cxx:160
void AddStyle(SvXMLStyleContext *pStyle)
Definition: xmlstyle.cxx:286
virtual ~SvXMLStylesContext() override
Definition: xmlstyle.cxx:764
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:594
SvXMLStyleContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, XmlStyleFamily nFamily=XmlStyleFamily::DATA_STYLE, bool bDefaultStyle=false)
#define XML_STYLE_FAMILY_SCH_CHART_NAME
Definition: families.hxx:43
virtual void Finish(bool bOverwrite)
Definition: xmlstyle.cxx:190
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
Definition: nmspmap.cxx:437
SvXMLStyleContext * GetStyle(size_t i)
Definition: xmlstyle.cxx:265
#define XML_STYLE_FAMILY_SD_PRESENTATION_NAME
Definition: families.hxx:38
bool IsAutomaticStyle() const
Definition: xmlstyle.cxx:352
#define XML_TOKEN_MAP_END
Definition: xmltkmap.hxx:33
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
XmlStyleFamily
Definition: families.hxx:47
virtual SvXMLStyleContext * CreateDefaultStyleStyleChildContext(XmlStyleFamily nFamily, sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
Definition: xmlstyle.cxx:511
sal_uInt32 m_nIndexCreated
Definition: xmlstyle.cxx:255
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: xmlstyle.cxx:768
bool IsValid() const
Definition: xmlstyle.hxx:114
int nCount
if(nullptr==pCandidateA||nullptr==pCandidateB)
const char * sName
#define XML_STYLE_FAMILY_SD_GRAPHICS_NAME
Definition: families.hxx:36
const char * pS
constexpr sal_uInt16 XML_NAMESPACE_DRAW
Definition: xmlnmspe.hxx:33
static const OUStringLiteral gsTextStyleServiceName("com.sun.star.style.CharacterStyle")
OUString maDisplayName
Definition: xmlstyle.hxx:62
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:580
#define XML_STYLE_FAMILY_SD_POOL_NAME
Definition: families.hxx:40
int i
SvXMLStylesContext_Impl(bool bAuto)
Definition: xmlstyle.cxx:279
void CopyStylesToDoc(bool bOverwrite, bool bFinish=true)
Definition: xmlstyle.cxx:821
std::unique_ptr< IndicesType > pIndices
Definition: xmlstyle.cxx:251
virtual bool IsTransient() const
if this method returns true, its parent styles context should not add it to its container.
Definition: xmlstyle.cxx:194
static const OUStringLiteral gsParaStyleServiceName("com.sun.star.style.ParagraphStyle")
rtl::Reference< SvXMLImportPropertyMapper > mxChartImpPropMapper
Definition: xmlstyle.hxx:167
virtual void SetDefaults()
Definition: xmlstyle.cxx:178
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:93
std::unique_ptr< SvXMLStylesContext_Impl > mpImpl
Definition: xmlstyle.hxx:152
SvXMLStyleContext * CreateChildContext(SvXMLImport &rImport, sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, SvXMLStylesContext &rStyles)
Definition: xmlnumfi.cxx:2273
import footnote and endnote configuration elements
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) final override
StartElement is called after a context has been constructed and before an elements context is parsed...
Definition: xmlstyle.cxx:164
virtual bool InsertStyleFamily(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:518
#define XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME
Definition: families.hxx:41
SAL_DLLPRIVATE const SvXMLTokenMap & GetStyleStylesElemTokenMap()
Definition: xmlstyle.cxx:85
virtual OUString GetServiceName(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:741
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
Definition: xmlstyle.cxx:774
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
DefTokenId nToken
virtual void CreateAndInsert(bool bOverwrite)
Definition: xmlstyle.cxx:182
std::deque< AttacherIndex_Impl > aIndex
SvXMLStylesContext(SvXMLStylesContext const &)=delete
#define SAL_WARN_IF(condition, area, stream)
rtl::Reference< SvXMLImportPropertyMapper > mxTextImpPropMapper
Definition: xmlstyle.hxx:165
const OUString & GetName() const
Definition: xmlstyle.hxx:106
OUString maName
Definition: xmlstyle.hxx:61
Handling of tokens in XML:
XmlStyleFamily mnFamily
Definition: xmlstyle.hxx:68
OUString maFollow
Definition: xmlstyle.hxx:65
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
Definition: xmlstyle.cxx:792
static const SvXMLTokenMapEntry aStyleStylesElemTokenMap[]
Definition: xmlstyle.cxx:62
virtual SvXMLStyleContext * CreateStyleStyleChildContext(XmlStyleFamily nFamily, sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
Definition: xmlstyle.cxx:475
void AddStyle(SvXMLStyleContext &rNew)
Definition: xmlstyle.cxx:796
virtual void SetAttribute(sal_uInt16 nPrefixKey, const OUString &rLocalName, const OUString &rValue)
Definition: xmlstyle.cxx:94
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
Definition: xmlstyle.cxx:870
css::uno::Reference< css::style::XAutoStyleFamily > mxParaAutoStyles
Definition: xmlstyle.hxx:160
static XmlStyleFamily GetFamily(const OUString &rFamily)
Definition: xmlstyle.cxx:523
const char sServiceName[]
css::uno::Reference< css::container::XNameContainer > mxTextStyles
Definition: xmlstyle.hxx:158
virtual css::uno::Reference< css::container::XNameContainer > GetStylesContainer(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:690
sal_uInt32 GetStyleCount() const
Definition: xmlstyle.cxx:337
rtl::Reference< SvXMLImportPropertyMapper > mxPageImpPropMapper
Definition: xmlstyle.hxx:168
rtl::Reference< SvXMLImportPropertyMapper > mxShapeImpPropMapper
Definition: xmlstyle.hxx:166
std::unique_ptr< SvXMLTokenMap > mpStyleStylesElemTokenMap
Definition: xmlstyle.hxx:153
void FinishStyles(bool bOverwrite)
Definition: xmlstyle.cxx:856
virtual void CreateAndInsertLate(bool bOverwrite)
Definition: xmlstyle.cxx:186
bool mbValid