Line data Source code
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 <com/sun/star/xml/sax/SAXParseException.hpp>
21 : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
22 : #include <com/sun/star/xml/sax/SAXException.hpp>
23 : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 : #include <com/sun/star/xml/sax/XAttributeList.hpp>
25 : #include <com/sun/star/xml/sax/XLocator.hpp>
26 : #include <com/sun/star/container/XNameContainer.hpp>
27 : #include <com/sun/star/beans/XPropertySet.hpp>
28 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29 : #include <com/sun/star/style/XAutoStylesSupplier.hpp>
30 : #include <com/sun/star/style/XAutoStyleFamily.hpp>
31 : #include "PageMasterPropMapper.hxx"
32 : #include <tools/debug.hxx>
33 : #include <svl/itemset.hxx>
34 : #include <xmloff/nmspmap.hxx>
35 : #include <xmloff/xmlnmspe.hxx>
36 : #include <xmloff/xmltoken.hxx>
37 :
38 : #include <xmloff/families.hxx>
39 : #include <xmloff/xmlimp.hxx>
40 : #include <xmloff/xmlnumi.hxx>
41 : #include <xmloff/xmlimppr.hxx>
42 : #include <xmloff/xmlstyle.hxx>
43 : #include <xmloff/txtstyli.hxx>
44 : #include <xmloff/txtprmap.hxx>
45 : #include <xmloff/xmlnumfi.hxx>
46 : #include "XMLChartStyleContext.hxx"
47 : #include "XMLChartPropertySetMapper.hxx"
48 : #include <xmloff/XMLShapeStyleContext.hxx>
49 : #include "FillStyleContext.hxx"
50 : #include "XMLFootnoteConfigurationImportContext.hxx"
51 : #include "XMLIndexBibliographyConfigurationContext.hxx"
52 : #include "XMLLineNumberingImportContext.hxx"
53 : #include "PageMasterImportContext.hxx"
54 : #include "PageMasterImportPropMapper.hxx"
55 :
56 : #include <set>
57 : #include <vector>
58 :
59 : using namespace ::com::sun::star;
60 : using namespace ::com::sun::star::uno;
61 : using namespace ::com::sun::star::container;
62 : using namespace ::com::sun::star::style;
63 : using namespace ::xmloff::token;
64 :
65 : static SvXMLTokenMapEntry aStyleStylesElemTokenMap[] =
66 : {
67 : { XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_STYLE_STYLE },
68 : { XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT, XML_TOK_STYLE_PAGE_MASTER },
69 : { XML_NAMESPACE_TEXT, XML_LIST_STYLE, XML_TOK_TEXT_LIST_STYLE },
70 : { XML_NAMESPACE_TEXT, XML_OUTLINE_STYLE, XML_TOK_TEXT_OUTLINE },
71 : { XML_NAMESPACE_STYLE, XML_DEFAULT_STYLE, XML_TOK_STYLE_DEFAULT_STYLE },
72 : { XML_NAMESPACE_DRAW, XML_GRADIENT, XML_TOK_STYLES_GRADIENTSTYLES },
73 : { XML_NAMESPACE_DRAW, XML_HATCH, XML_TOK_STYLES_HATCHSTYLES },
74 : { XML_NAMESPACE_DRAW, XML_FILL_IMAGE, XML_TOK_STYLES_BITMAPSTYLES },
75 : { XML_NAMESPACE_DRAW, XML_OPACITY, XML_TOK_STYLES_TRANSGRADIENTSTYLES },
76 : { XML_NAMESPACE_DRAW, XML_MARKER, XML_TOK_STYLES_MARKERSTYLES },
77 : { XML_NAMESPACE_DRAW, XML_STROKE_DASH, XML_TOK_STYLES_DASHSTYLES },
78 : { XML_NAMESPACE_TEXT, XML_NOTES_CONFIGURATION, XML_TOK_TEXT_NOTE_CONFIG },
79 : { XML_NAMESPACE_TEXT, XML_BIBLIOGRAPHY_CONFIGURATION, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG },
80 : { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,XML_TOK_TEXT_LINENUMBERING_CONFIG },
81 : { XML_NAMESPACE_STYLE, XML_DEFAULT_PAGE_LAYOUT, XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT },
82 : XML_TOKEN_MAP_END
83 : };
84 :
85 28714 : const SvXMLTokenMap& SvXMLStylesContext::GetStyleStylesElemTokenMap()
86 : {
87 28714 : if( !mpStyleStylesElemTokenMap )
88 : mpStyleStylesElemTokenMap =
89 2508 : new SvXMLTokenMap( aStyleStylesElemTokenMap );
90 :
91 28714 : return *mpStyleStylesElemTokenMap;
92 : }
93 :
94 61502 : void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
95 : const OUString& rLocalName,
96 : const OUString& rValue )
97 : {
98 : // TODO: use a map here
99 61502 : if( XML_NAMESPACE_STYLE == nPrefixKey )
100 : {
101 56588 : if( IsXMLToken( rLocalName, XML_FAMILY ) )
102 : {
103 922 : if( IsXMLToken( rValue, XML_PARAGRAPH ) )
104 0 : mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_PARA;
105 922 : else if( IsXMLToken( rValue, XML_TEXT ) )
106 0 : mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_CHAR;
107 : }
108 55666 : else if( IsXMLToken( rLocalName, XML_NAME ) )
109 : {
110 38408 : maName = rValue;
111 : }
112 17258 : else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) )
113 : {
114 4242 : maDisplayName = rValue;
115 : }
116 13016 : else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) )
117 : {
118 9726 : maParentName = rValue;
119 : }
120 3290 : else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) )
121 : {
122 524 : maFollow = rValue;
123 : }
124 2766 : else if( IsXMLToken( rLocalName, XML_HELP_FILE_NAME ) )
125 : {
126 0 : maHelpFile = rValue;
127 : }
128 2766 : else if( IsXMLToken( rLocalName, XML_HELP_ID ) )
129 : {
130 0 : sal_Int32 nTmp = rValue.toInt32();
131 : mnHelpId =
132 : (nTmp < 0L) ? 0U : ( (nTmp > USHRT_MAX) ? USHRT_MAX
133 0 : : (sal_uInt16)nTmp );
134 : }
135 2766 : else if( IsXMLToken( rLocalName, XML_HIDDEN ) )
136 : {
137 0 : mbHidden = rValue.toBoolean();
138 : }
139 : }
140 61502 : }
141 :
142 6312 : TYPEINIT1( SvXMLStyleContext, SvXMLImportContext );
143 :
144 42438 : SvXMLStyleContext::SvXMLStyleContext(
145 : SvXMLImport& rImp, sal_uInt16 nPrfx,
146 : const OUString& rLName,
147 : const uno::Reference< xml::sax::XAttributeList >&,
148 : sal_uInt16 nFam, bool bDefault ) :
149 : SvXMLImportContext( rImp, nPrfx, rLName ),
150 : mbHidden( false ),
151 : mnHelpId( UCHAR_MAX ),
152 : mnFamily( nFam ),
153 : mbValid( true ),
154 : mbNew( true ),
155 42438 : mbDefaultStyle( bDefault )
156 : {
157 42438 : }
158 :
159 42438 : SvXMLStyleContext::~SvXMLStyleContext()
160 : {
161 42438 : }
162 :
163 10 : SvXMLImportContext *SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix,
164 : const OUString& rLocalName,
165 : const uno::Reference< xml::sax::XAttributeList > & )
166 : {
167 10 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
168 : }
169 :
170 39610 : void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttributeList > & xAttrList )
171 : {
172 39610 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
173 148778 : for( sal_Int16 i=0; i < nAttrCount; i++ )
174 : {
175 109168 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
176 218336 : OUString aLocalName;
177 109168 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
178 218336 : const OUString& rValue = xAttrList->getValueByIndex( i );
179 :
180 109168 : SetAttribute( nPrefix, aLocalName, rValue );
181 109168 : }
182 39610 : }
183 :
184 0 : void SvXMLStyleContext::SetDefaults()
185 : {
186 0 : }
187 :
188 1078 : void SvXMLStyleContext::CreateAndInsert( bool /*bOverwrite*/ )
189 : {
190 1078 : }
191 :
192 11326 : void SvXMLStyleContext::CreateAndInsertLate( bool /*bOverwrite*/ )
193 : {
194 11326 : }
195 :
196 3672 : void SvXMLStyleContext::Finish( bool /*bOverwrite*/ )
197 : {
198 3672 : }
199 :
200 40106 : bool SvXMLStyleContext::IsTransient() const
201 : {
202 40106 : return false;
203 : }
204 :
205 134630 : class SvXMLStyleIndex_Impl
206 : {
207 : OUString sName;
208 : sal_uInt16 nFamily;
209 : const SvXMLStyleContext *pStyle;
210 :
211 : public:
212 :
213 58408 : SvXMLStyleIndex_Impl( sal_uInt16 nFam, const OUString& rName ) :
214 : sName( rName ),
215 : nFamily( nFam ),
216 58408 : pStyle ( 0 )
217 : {
218 58408 : }
219 :
220 76222 : SvXMLStyleIndex_Impl( const SvXMLStyleContext *pStl ) :
221 76222 : sName( pStl->GetName() ),
222 76222 : nFamily( pStl->GetFamily() ),
223 152444 : pStyle ( pStl )
224 : {
225 76222 : }
226 :
227 652948 : const OUString& GetName() const { return sName; }
228 1656624 : sal_uInt16 GetFamily() const { return nFamily; }
229 54998 : const SvXMLStyleContext *GetStyle() const { return pStyle; }
230 : };
231 :
232 : struct SvXMLStyleIndexCmp_Impl
233 : {
234 453656 : bool operator()(const SvXMLStyleIndex_Impl& r1, const SvXMLStyleIndex_Impl& r2) const
235 : {
236 : sal_Int32 nRet;
237 :
238 453656 : if( (sal_uInt16)r1.GetFamily() < (sal_uInt16)r2.GetFamily() )
239 79000 : nRet = -1;
240 374656 : else if( (sal_uInt16)r1.GetFamily() > (sal_uInt16)r2.GetFamily() )
241 48182 : nRet = 1;
242 : else
243 326474 : nRet = r1.GetName().compareTo( r2.GetName() );
244 :
245 453656 : return nRet < 0;
246 : }
247 : };
248 :
249 : class SvXMLStylesContext_Impl
250 : {
251 : typedef std::vector<SvXMLStyleContext*> StylesType;
252 : typedef std::set<SvXMLStyleIndex_Impl, SvXMLStyleIndexCmp_Impl> IndicesType;
253 :
254 : StylesType aStyles;
255 : mutable IndicesType* pIndices;
256 : bool bAutomaticStyle;
257 :
258 : #ifdef DBG_UTIL
259 : mutable sal_uInt32 nIndexCreated;
260 : #endif
261 :
262 47766 : void FlushIndex() { delete pIndices; pIndices = 0; }
263 :
264 : public:
265 : SvXMLStylesContext_Impl( bool bAuto );
266 : ~SvXMLStylesContext_Impl();
267 :
268 18086 : size_t GetStyleCount() const { return aStyles.size(); }
269 :
270 64772 : SvXMLStyleContext *GetStyle( size_t i )
271 : {
272 64772 : return i < aStyles.size() ? aStyles[ i ] : 0;
273 : }
274 :
275 : inline void AddStyle( SvXMLStyleContext *pStyle );
276 : void Clear();
277 :
278 : const SvXMLStyleContext *FindStyleChildContext( sal_uInt16 nFamily,
279 : const OUString& rName,
280 : bool bCreateIndex ) const;
281 36062 : bool IsAutomaticStyle() const { return bAutomaticStyle; }
282 : };
283 :
284 5036 : SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto ) :
285 : pIndices( 0 ),
286 5036 : bAutomaticStyle( bAuto )
287 : #ifdef DBG_UTIL
288 : , nIndexCreated( 0 )
289 : #endif
290 5036 : {}
291 :
292 10072 : SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl()
293 : {
294 5036 : delete pIndices;
295 :
296 5770 : for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
297 : {
298 734 : SvXMLStyleContext *pStyle = aStyles[ i ];
299 734 : pStyle->ReleaseRef();
300 : }
301 5036 : aStyles.clear();
302 5036 : }
303 :
304 41700 : inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle )
305 : {
306 41700 : aStyles.push_back( pStyle );
307 41700 : pStyle->AddFirstRef();
308 :
309 41700 : FlushIndex();
310 41700 : }
311 :
312 6066 : void SvXMLStylesContext_Impl::Clear()
313 : {
314 6066 : FlushIndex();
315 :
316 47032 : for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
317 : {
318 40966 : SvXMLStyleContext *pStyle = aStyles[ i ];
319 40966 : pStyle->ReleaseRef();
320 : }
321 6066 : aStyles.clear();
322 6066 : }
323 :
324 63722 : const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext( sal_uInt16 nFamily,
325 : const OUString& rName,
326 : bool bCreateIndex ) const
327 : {
328 63722 : const SvXMLStyleContext *pStyle = 0;
329 :
330 63722 : if( !pIndices && bCreateIndex && !aStyles.empty() )
331 : {
332 : #ifdef DBG_UTIL
333 : DBG_ASSERT( 0==nIndexCreated,
334 : "Performance warning: sdbcx::Index created multiple times" );
335 : #endif
336 2746 : pIndices = new IndicesType(aStyles.begin(), aStyles.end());
337 : SAL_WARN_IF(pIndices->size() != aStyles.size(), "xmloff", "Here is a duplicate Style");
338 : #ifdef DBG_UTIL
339 : ++nIndexCreated;
340 : #endif
341 : }
342 :
343 63722 : if( pIndices )
344 : {
345 58408 : SvXMLStyleIndex_Impl aIndex( nFamily, rName );
346 58408 : IndicesType::iterator aFind = pIndices->find(aIndex);
347 58408 : if( aFind != pIndices->end() )
348 54998 : pStyle = aFind->GetStyle();
349 : }
350 : else
351 : {
352 121372 : for( size_t i = 0; !pStyle && i < aStyles.size(); i++ )
353 : {
354 116058 : const SvXMLStyleContext *pS = aStyles[ i ];
355 208244 : if( pS->GetFamily() == nFamily &&
356 92186 : pS->GetName() == rName )
357 4486 : pStyle = pS;
358 : }
359 : }
360 63722 : return pStyle;
361 : }
362 :
363 0 : TYPEINIT1( SvXMLStylesContext, SvXMLImportContext );
364 :
365 18086 : sal_uInt32 SvXMLStylesContext::GetStyleCount() const
366 : {
367 18086 : return mpImpl->GetStyleCount();
368 : }
369 :
370 52804 : SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i )
371 : {
372 52804 : return mpImpl->GetStyle( i );
373 : }
374 :
375 11968 : const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const
376 : {
377 11968 : return mpImpl->GetStyle( i );
378 : }
379 :
380 36062 : bool SvXMLStylesContext::IsAutomaticStyle() const
381 : {
382 36062 : return mpImpl->IsAutomaticStyle();
383 : }
384 :
385 32348 : SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( sal_uInt16 p_nPrefix,
386 : const OUString& rLocalName,
387 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
388 : {
389 32348 : SvXMLStyleContext *pStyle = NULL;
390 :
391 32348 : if(GetImport().GetDataStylesImport())
392 : {
393 29406 : pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix,
394 58812 : rLocalName, xAttrList, *this);
395 : }
396 :
397 32348 : if (!pStyle)
398 : {
399 28714 : const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap();
400 28714 : sal_uInt16 nToken = rTokenMap.Get( p_nPrefix, rLocalName );
401 28714 : switch( nToken )
402 : {
403 : case XML_TOK_STYLE_STYLE:
404 : case XML_TOK_STYLE_DEFAULT_STYLE:
405 : {
406 24654 : sal_uInt16 nFamily = 0;
407 24654 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
408 44896 : for( sal_Int16 i=0; i < nAttrCount; i++ )
409 : {
410 44896 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
411 65138 : OUString aLocalName;
412 : sal_uInt16 nPrefix =
413 44896 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
414 44896 : &aLocalName );
415 89792 : if( XML_NAMESPACE_STYLE == nPrefix &&
416 44896 : IsXMLToken( aLocalName, XML_FAMILY ) )
417 : {
418 24654 : const OUString& rValue = xAttrList->getValueByIndex( i );
419 24654 : nFamily = GetFamily( rValue );
420 24654 : break;
421 : }
422 20242 : }
423 : pStyle = XML_TOK_STYLE_STYLE==nToken
424 : ? CreateStyleStyleChildContext( nFamily, p_nPrefix,
425 22096 : rLocalName, xAttrList )
426 : : CreateDefaultStyleStyleChildContext( nFamily, p_nPrefix,
427 46750 : rLocalName, xAttrList );
428 : }
429 24654 : break;
430 : case XML_TOK_STYLE_PAGE_MASTER:
431 : case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT:
432 : {
433 : //there is not page family in ODF now, so I specify one for it
434 1516 : bool bDefaultStyle = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken;
435 1516 : pStyle = new PageStyleContext( GetImport(), p_nPrefix,
436 1516 : rLocalName, xAttrList, *this, bDefaultStyle );
437 : }
438 1516 : break;
439 : case XML_TOK_TEXT_LIST_STYLE:
440 548 : pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
441 548 : rLocalName, xAttrList );
442 548 : break;
443 : case XML_TOK_TEXT_OUTLINE:
444 312 : pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
445 312 : rLocalName, xAttrList, true );
446 312 : break;
447 : case XML_TOK_TEXT_NOTE_CONFIG:
448 828 : pStyle = new XMLFootnoteConfigurationImportContext(GetImport(),
449 : p_nPrefix,
450 : rLocalName,
451 828 : xAttrList);
452 828 : break;
453 :
454 : case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG:
455 : pStyle = new XMLIndexBibliographyConfigurationContext(
456 4 : GetImport(), p_nPrefix, rLocalName, xAttrList);
457 4 : break;
458 :
459 : case XML_TOK_TEXT_LINENUMBERING_CONFIG:
460 : pStyle = new XMLLineNumberingImportContext(
461 414 : GetImport(), p_nPrefix, rLocalName, xAttrList);
462 414 : break;
463 :
464 :
465 : // FillStyles
466 :
467 : case XML_TOK_STYLES_GRADIENTSTYLES:
468 : {
469 120 : pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
470 120 : break;
471 : }
472 : case XML_TOK_STYLES_HATCHSTYLES:
473 : {
474 44 : pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
475 44 : break;
476 : }
477 : case XML_TOK_STYLES_BITMAPSTYLES:
478 : {
479 138 : pStyle = new XMLBitmapStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
480 138 : break;
481 : }
482 : case XML_TOK_STYLES_TRANSGRADIENTSTYLES:
483 : {
484 14 : pStyle = new XMLTransGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
485 14 : break;
486 : }
487 : case XML_TOK_STYLES_MARKERSTYLES:
488 : {
489 92 : pStyle = new XMLMarkerStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
490 92 : break;
491 : }
492 : case XML_TOK_STYLES_DASHSTYLES:
493 : {
494 30 : pStyle = new XMLDashStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
495 30 : break;
496 : }
497 : }
498 : }
499 :
500 32348 : return pStyle;
501 : }
502 :
503 13598 : SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext(
504 : sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
505 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
506 : {
507 13598 : SvXMLStyleContext *pStyle = 0;
508 :
509 13598 : switch( nFamily )
510 : {
511 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
512 : case XML_STYLE_FAMILY_TEXT_TEXT:
513 : case XML_STYLE_FAMILY_TEXT_SECTION:
514 2942 : pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
515 2942 : xAttrList, *this, nFamily );
516 2942 : break;
517 :
518 : case XML_STYLE_FAMILY_TEXT_RUBY:
519 14 : pStyle = new XMLPropStyleContext( GetImport(), nPrefix, rLocalName,
520 14 : xAttrList, *this, nFamily );
521 14 : break;
522 : case XML_STYLE_FAMILY_SCH_CHART_ID:
523 2658 : pStyle = new XMLChartStyleContext( GetImport(), nPrefix, rLocalName,
524 2658 : xAttrList, *this, nFamily );
525 2658 : break;
526 :
527 : case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
528 : case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
529 : case XML_STYLE_FAMILY_SD_POOL_ID:
530 1952 : pStyle = new XMLShapeStyleContext( GetImport(), nPrefix, rLocalName,
531 1952 : xAttrList, *this, nFamily );
532 : }
533 :
534 13598 : return pStyle;
535 : }
536 :
537 878 : SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
538 : sal_uInt16 /*nFamily*/, sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/,
539 : const uno::Reference< xml::sax::XAttributeList > & )
540 : {
541 878 : return 0;
542 : }
543 :
544 16796 : bool SvXMLStylesContext::InsertStyleFamily( sal_uInt16 ) const
545 : {
546 16796 : return true;
547 : }
548 :
549 24654 : sal_uInt16 SvXMLStylesContext::GetFamily( const OUString& rValue ) const
550 : {
551 24654 : sal_uInt16 nFamily = 0U;
552 24654 : if( IsXMLToken( rValue, XML_PARAGRAPH ) )
553 : {
554 6968 : nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH;
555 : }
556 17686 : else if( IsXMLToken( rValue, XML_TEXT ) )
557 : {
558 3132 : nFamily = XML_STYLE_FAMILY_TEXT_TEXT;
559 : }
560 14554 : else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
561 : {
562 0 : nFamily = XML_STYLE_FAMILY_DATA_STYLE;
563 : }
564 14554 : else if ( IsXMLToken( rValue, XML_SECTION ) )
565 : {
566 52 : nFamily = XML_STYLE_FAMILY_TEXT_SECTION;
567 : }
568 14502 : else if( IsXMLToken( rValue, XML_TABLE ) )
569 : {
570 906 : nFamily = XML_STYLE_FAMILY_TABLE_TABLE;
571 : }
572 13596 : else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
573 2536 : nFamily = XML_STYLE_FAMILY_TABLE_COLUMN;
574 11060 : else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
575 1094 : nFamily = XML_STYLE_FAMILY_TABLE_ROW;
576 9966 : else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
577 3932 : nFamily = XML_STYLE_FAMILY_TABLE_CELL;
578 6034 : else if ( rValue == XML_STYLE_FAMILY_SD_GRAPHICS_NAME )
579 : {
580 2488 : nFamily = XML_STYLE_FAMILY_SD_GRAPHICS_ID;
581 : }
582 3546 : else if ( rValue == XML_STYLE_FAMILY_SD_PRESENTATION_NAME )
583 : {
584 650 : nFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
585 : }
586 2896 : else if ( rValue == XML_STYLE_FAMILY_SD_POOL_NAME )
587 : {
588 0 : nFamily = XML_STYLE_FAMILY_SD_POOL_ID;
589 : }
590 2896 : else if ( rValue == XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME )
591 : {
592 224 : nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID;
593 : }
594 2672 : else if ( rValue == XML_STYLE_FAMILY_SCH_CHART_NAME )
595 : {
596 2658 : nFamily = XML_STYLE_FAMILY_SCH_CHART_ID;
597 : }
598 14 : else if ( IsXMLToken( rValue, XML_RUBY ) )
599 : {
600 14 : nFamily = XML_STYLE_FAMILY_TEXT_RUBY;
601 : }
602 :
603 24654 : return nFamily;
604 : }
605 :
606 112502 : rtl::Reference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper(
607 : sal_uInt16 nFamily ) const
608 : {
609 112502 : rtl::Reference < SvXMLImportPropertyMapper > xMapper;
610 :
611 112502 : switch( nFamily )
612 : {
613 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
614 29180 : if( !mxParaImpPropMapper.is() )
615 : {
616 1050 : SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
617 1050 : pThis->mxParaImpPropMapper =
618 1050 : pThis->GetImport().GetTextImport()
619 2100 : ->GetParaImportPropertySetMapper();
620 : }
621 29180 : xMapper = mxParaImpPropMapper;
622 29180 : break;
623 : case XML_STYLE_FAMILY_TEXT_TEXT:
624 16730 : if( !mxTextImpPropMapper.is() )
625 : {
626 648 : SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
627 648 : pThis->mxTextImpPropMapper =
628 648 : pThis->GetImport().GetTextImport()
629 1296 : ->GetTextImportPropertySetMapper();
630 : }
631 16730 : xMapper = mxTextImpPropMapper;
632 16730 : break;
633 :
634 : case XML_STYLE_FAMILY_TEXT_SECTION:
635 : // don't cache section mapper, as it's rarely used
636 : // *sigh*, cast to non-const, because this is a const method,
637 : // but SvXMLImport::GetTextImport() isn't.
638 182 : xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
639 182 : GetSectionImportPropertySetMapper();
640 182 : break;
641 :
642 : case XML_STYLE_FAMILY_TEXT_RUBY:
643 : // don't cache section mapper, as it's rarely used
644 : // *sigh*, cast to non-const, because this is a const method,
645 : // but SvXMLImport::GetTextImport() isn't.
646 38 : xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
647 38 : GetRubyImportPropertySetMapper();
648 38 : break;
649 :
650 : case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
651 : case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
652 : case XML_STYLE_FAMILY_SD_POOL_ID:
653 14734 : if(!mxShapeImpPropMapper.is())
654 : {
655 990 : rtl::Reference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
656 990 : ((SvXMLStylesContext*)this)->mxShapeImpPropMapper =
657 990 : aImpHelper->GetPropertySetMapper();
658 : }
659 14734 : xMapper = mxShapeImpPropMapper;
660 14734 : break;
661 : case XML_STYLE_FAMILY_SCH_CHART_ID:
662 13340 : if( ! mxChartImpPropMapper.is() )
663 : {
664 244 : XMLPropertySetMapper *pPropMapper = new XMLChartPropertySetMapper( false );
665 244 : mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() );
666 : }
667 13340 : xMapper = mxChartImpPropMapper;
668 13340 : break;
669 : case XML_STYLE_FAMILY_PAGE_MASTER:
670 9134 : if( ! mxPageImpPropMapper.is() )
671 : {
672 : XMLPropertySetMapper *pPropMapper =
673 800 : new XMLPageMasterPropSetMapper( false );
674 3200 : mxPageImpPropMapper =
675 : new PageMasterImportPropertyMapper( pPropMapper,
676 2400 : ((SvXMLStylesContext*)this)->GetImport() );
677 : }
678 9134 : xMapper = mxPageImpPropMapper;
679 9134 : break;
680 : }
681 :
682 112502 : return xMapper;
683 : }
684 :
685 2698 : Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily ) const
686 : {
687 2698 : Reference < XAutoStyleFamily > xAutoStyles;
688 2698 : if( XML_STYLE_FAMILY_TEXT_TEXT == nFamily || XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily)
689 : {
690 2698 : bool bPara = XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily;
691 2698 : OUString sName;
692 2698 : if( !bPara && mxTextAutoStyles.is() )
693 966 : xAutoStyles = mxTextAutoStyles;
694 1732 : else if( bPara && mxParaAutoStyles.is() )
695 1182 : xAutoStyles = mxParaAutoStyles;
696 : else
697 : {
698 550 : sName = bPara ? OUString( "ParagraphStyles" ): OUString( "CharacterStyles" );
699 550 : Reference< XAutoStylesSupplier > xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY );
700 1100 : Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
701 550 : if (xAutoStyleFamilies->hasByName(sName))
702 : {
703 550 : Any aAny = xAutoStyleFamilies->getByName( sName );
704 550 : xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue();
705 550 : if( bPara )
706 342 : ((SvXMLStylesContext *)this)->mxParaAutoStyles = xAutoStyles;
707 : else
708 208 : ((SvXMLStylesContext *)this)->mxTextAutoStyles = xAutoStyles;
709 550 : }
710 2698 : }
711 : }
712 2698 : return xAutoStyles;
713 : }
714 :
715 13610 : Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
716 : sal_uInt16 nFamily ) const
717 : {
718 13610 : Reference < XNameContainer > xStyles;
719 27220 : OUString sName;
720 13610 : switch( nFamily )
721 : {
722 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
723 7898 : if( mxParaStyles.is() )
724 6866 : xStyles = mxParaStyles;
725 : else
726 1032 : sName = "ParagraphStyles";
727 7898 : break;
728 :
729 : case XML_STYLE_FAMILY_TEXT_TEXT:
730 2700 : if( mxTextStyles.is() )
731 2240 : xStyles = mxTextStyles;
732 : else
733 460 : sName = "CharacterStyles";
734 2700 : break;
735 : }
736 13610 : if( !xStyles.is() && !sName.isEmpty() )
737 : {
738 : Reference< XStyleFamiliesSupplier > xFamiliesSupp(
739 1492 : GetImport().GetModel(), UNO_QUERY );
740 1492 : if ( xFamiliesSupp.is() )
741 : {
742 1492 : Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
743 1492 : if (xFamilies->hasByName(sName))
744 : {
745 652 : xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
746 :
747 652 : switch( nFamily )
748 : {
749 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
750 416 : ((SvXMLStylesContext *)this)->mxParaStyles = xStyles;
751 416 : break;
752 :
753 : case XML_STYLE_FAMILY_TEXT_TEXT:
754 236 : ((SvXMLStylesContext *)this)->mxTextStyles = xStyles;
755 236 : break;
756 : }
757 1492 : }
758 1492 : }
759 : }
760 :
761 27220 : return xStyles;
762 : }
763 :
764 1446 : OUString SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily ) const
765 : {
766 1446 : OUString sServiceName;
767 1446 : switch( nFamily )
768 : {
769 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
770 314 : sServiceName = msParaStyleServiceName;
771 314 : break;
772 : case XML_STYLE_FAMILY_TEXT_TEXT:
773 956 : sServiceName = msTextStyleServiceName;
774 956 : break;
775 : }
776 :
777 1446 : return sServiceName;
778 : }
779 :
780 5036 : SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
781 : const OUString& rLName,
782 : const uno::Reference< xml::sax::XAttributeList > &, bool bAuto ) :
783 : SvXMLImportContext( rImport, nPrfx, rLName ),
784 : msParaStyleServiceName( "com.sun.star.style.ParagraphStyle" ),
785 : msTextStyleServiceName( "com.sun.star.style.CharacterStyle" ),
786 5036 : mpImpl( new SvXMLStylesContext_Impl( bAuto ) ),
787 10072 : mpStyleStylesElemTokenMap( 0 )
788 : {
789 5036 : }
790 :
791 10560 : SvXMLStylesContext::~SvXMLStylesContext()
792 : {
793 5036 : delete mpStyleStylesElemTokenMap;
794 5036 : delete mpImpl;
795 5524 : }
796 :
797 40972 : SvXMLImportContext *SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix,
798 : const OUString& rLocalName,
799 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
800 : {
801 40972 : SvXMLImportContext *pContext = 0;
802 :
803 : SvXMLStyleContext *pStyle =
804 40972 : CreateStyleChildContext( nPrefix, rLocalName, xAttrList );
805 40972 : if( pStyle )
806 : {
807 40544 : if( !pStyle->IsTransient() )
808 40106 : mpImpl->AddStyle( pStyle );
809 40544 : pContext = pStyle;
810 : }
811 : else
812 : {
813 428 : pContext = new SvXMLImportContext( GetImport(), nPrefix,
814 428 : rLocalName );
815 : }
816 :
817 40972 : return pContext;
818 : }
819 :
820 2884 : void SvXMLStylesContext::EndElement()
821 : {
822 2884 : }
823 :
824 1594 : void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew)
825 : {
826 1594 : mpImpl->AddStyle( &rNew );
827 1594 : }
828 :
829 6066 : void SvXMLStylesContext::Clear()
830 : {
831 6066 : mpImpl->Clear();
832 6066 : }
833 :
834 730 : void SvXMLStylesContext::CopyAutoStylesToDoc()
835 : {
836 730 : sal_uInt32 nCount = GetStyleCount();
837 : sal_uInt32 i;
838 5802 : for( i = 0; i < nCount; i++ )
839 : {
840 5072 : SvXMLStyleContext *pStyle = GetStyle( i );
841 10954 : if( !pStyle || ( pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT &&
842 6288 : pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH &&
843 2390 : pStyle->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL ) )
844 1984 : continue;
845 3088 : pStyle->CreateAndInsert( false );
846 : }
847 730 : }
848 :
849 742 : void SvXMLStylesContext::CopyStylesToDoc( bool bOverwrite,
850 : bool bFinish )
851 : {
852 : // pass 1: create text, paragraph and frame styles
853 742 : sal_uInt32 nCount = GetStyleCount();
854 : sal_uInt32 i;
855 :
856 14982 : for( i = 0; i < nCount; i++ )
857 : {
858 14240 : SvXMLStyleContext *pStyle = GetStyle( i );
859 14240 : if( !pStyle )
860 0 : continue;
861 :
862 14240 : if (pStyle->IsDefaultStyle())
863 2154 : pStyle->SetDefaults();
864 12086 : else if( InsertStyleFamily( pStyle->GetFamily() ) )
865 11780 : pStyle->CreateAndInsert( bOverwrite );
866 : }
867 :
868 : // pass 2: create list styles (they require char styles)
869 14982 : for( i=0; i<nCount; i++ )
870 : {
871 14240 : SvXMLStyleContext *pStyle = GetStyle( i );
872 14240 : if( !pStyle || pStyle->IsDefaultStyle())
873 2154 : continue;
874 :
875 12086 : if( InsertStyleFamily( pStyle->GetFamily() ) )
876 11780 : pStyle->CreateAndInsertLate( bOverwrite );
877 : }
878 :
879 : // pass3: finish creation of styles
880 742 : if( bFinish )
881 324 : FinishStyles( bOverwrite );
882 742 : }
883 :
884 1632 : void SvXMLStylesContext::FinishStyles( bool bOverwrite )
885 : {
886 1632 : sal_uInt32 nCount = GetStyleCount();
887 19130 : for( sal_uInt32 i=0; i<nCount; i++ )
888 : {
889 17498 : SvXMLStyleContext *pStyle = GetStyle( i );
890 17498 : if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
891 2664 : continue;
892 :
893 14834 : if( InsertStyleFamily( pStyle->GetFamily() ) )
894 14528 : pStyle->Finish( bOverwrite );
895 : }
896 1632 : }
897 :
898 63722 : const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext(
899 : sal_uInt16 nFamily,
900 : const OUString& rName,
901 : bool bCreateIndex ) const
902 : {
903 63722 : return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
904 : }
905 :
906 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|