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 22820 : const SvXMLTokenMap& SvXMLStylesContext::GetStyleStylesElemTokenMap()
86 : {
87 22820 : if( !mpStyleStylesElemTokenMap )
88 : mpStyleStylesElemTokenMap =
89 1800 : new SvXMLTokenMap( aStyleStylesElemTokenMap );
90 :
91 22820 : return *mpStyleStylesElemTokenMap;
92 : }
93 :
94 49219 : void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
95 : const OUString& rLocalName,
96 : const OUString& rValue )
97 : {
98 : // TODO: use a map here
99 49219 : if( XML_NAMESPACE_STYLE == nPrefixKey )
100 : {
101 45622 : if( IsXMLToken( rLocalName, XML_FAMILY ) )
102 : {
103 910 : if( IsXMLToken( rValue, XML_PARAGRAPH ) )
104 0 : mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_PARA;
105 910 : else if( IsXMLToken( rValue, XML_TEXT ) )
106 0 : mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_CHAR;
107 : }
108 44712 : else if( IsXMLToken( rLocalName, XML_NAME ) )
109 : {
110 29492 : maName = rValue;
111 : }
112 15220 : else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) )
113 : {
114 3488 : maDisplayName = rValue;
115 : }
116 11732 : else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) )
117 : {
118 9036 : maParentName = rValue;
119 : }
120 2696 : else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) )
121 : {
122 815 : maFollow = rValue;
123 : }
124 1881 : else if( IsXMLToken( rLocalName, XML_HELP_FILE_NAME ) )
125 : {
126 0 : maHelpFile = rValue;
127 : }
128 1881 : 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 1881 : else if( IsXMLToken( rLocalName, XML_HIDDEN ) )
136 : {
137 0 : mbHidden = rValue.toBoolean();
138 : }
139 : }
140 49219 : }
141 :
142 6291 : TYPEINIT1( SvXMLStyleContext, SvXMLImportContext );
143 :
144 32746 : 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 32746 : mbDefaultStyle( bDefault )
156 : {
157 32746 : }
158 :
159 32746 : SvXMLStyleContext::~SvXMLStyleContext()
160 : {
161 32746 : }
162 :
163 45 : SvXMLImportContext *SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix,
164 : const OUString& rLocalName,
165 : const uno::Reference< xml::sax::XAttributeList > & )
166 : {
167 45 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
168 : }
169 :
170 30823 : void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttributeList > & xAttrList )
171 : {
172 30823 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
173 118817 : for( sal_Int16 i=0; i < nAttrCount; i++ )
174 : {
175 87994 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
176 175988 : OUString aLocalName;
177 87994 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
178 175988 : const OUString& rValue = xAttrList->getValueByIndex( i );
179 :
180 87994 : SetAttribute( nPrefix, aLocalName, rValue );
181 87994 : }
182 30823 : }
183 :
184 0 : void SvXMLStyleContext::SetDefaults()
185 : {
186 0 : }
187 :
188 1201 : void SvXMLStyleContext::CreateAndInsert( bool /*bOverwrite*/ )
189 : {
190 1201 : }
191 :
192 8989 : void SvXMLStyleContext::CreateAndInsertLate( bool /*bOverwrite*/ )
193 : {
194 8989 : }
195 :
196 2679 : void SvXMLStyleContext::Finish( bool /*bOverwrite*/ )
197 : {
198 2679 : }
199 :
200 31152 : bool SvXMLStyleContext::IsTransient() const
201 : {
202 31152 : return false;
203 : }
204 :
205 92061 : class SvXMLStyleIndex_Impl
206 : {
207 : OUString sName;
208 : sal_uInt16 nFamily;
209 : const SvXMLStyleContext *pStyle;
210 :
211 : public:
212 :
213 39144 : SvXMLStyleIndex_Impl( sal_uInt16 nFam, const OUString& rName ) :
214 : sName( rName ),
215 : nFamily( nFam ),
216 39144 : pStyle ( 0 )
217 : {
218 39144 : }
219 :
220 52917 : SvXMLStyleIndex_Impl( const SvXMLStyleContext *pStl ) :
221 52917 : sName( pStl->GetName() ),
222 52917 : nFamily( pStl->GetFamily() ),
223 105834 : pStyle ( pStl )
224 : {
225 52917 : }
226 :
227 470692 : const OUString& GetName() const { return sName; }
228 1182036 : sal_uInt16 GetFamily() const { return nFamily; }
229 36274 : const SvXMLStyleContext *GetStyle() const { return pStyle; }
230 : };
231 :
232 : struct SvXMLStyleIndexCmp_Impl
233 : {
234 319042 : bool operator()(const SvXMLStyleIndex_Impl& r1, const SvXMLStyleIndex_Impl& r2) const
235 : {
236 : sal_Int32 nRet;
237 :
238 319042 : if( (sal_uInt16)r1.GetFamily() < (sal_uInt16)r2.GetFamily() )
239 47066 : nRet = -1;
240 271976 : else if( (sal_uInt16)r1.GetFamily() > (sal_uInt16)r2.GetFamily() )
241 36630 : nRet = 1;
242 : else
243 235346 : nRet = r1.GetName().compareTo( r2.GetName() );
244 :
245 319042 : 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 : #if OSL_DEBUG_LEVEL > 0
259 : mutable sal_uInt32 m_nIndexCreated;
260 : #endif
261 :
262 36487 : void FlushIndex() { delete pIndices; pIndices = 0; }
263 :
264 : public:
265 : explicit SvXMLStylesContext_Impl( bool bAuto );
266 : ~SvXMLStylesContext_Impl();
267 :
268 19497 : size_t GetStyleCount() const { return aStyles.size(); }
269 :
270 58280 : SvXMLStyleContext *GetStyle( size_t i )
271 : {
272 58280 : 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 28436 : bool IsAutomaticStyle() const { return bAutomaticStyle; }
282 : };
283 :
284 3610 : SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto ) :
285 : pIndices( 0 ),
286 3610 : bAutomaticStyle( bAuto )
287 : #if OSL_DEBUG_LEVEL > 0
288 : , m_nIndexCreated( 0 )
289 : #endif
290 3610 : {}
291 :
292 7220 : SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl()
293 : {
294 3610 : delete pIndices;
295 :
296 4051 : for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
297 : {
298 441 : SvXMLStyleContext *pStyle = aStyles[ i ];
299 441 : pStyle->ReleaseRef();
300 : }
301 3610 : aStyles.clear();
302 3610 : }
303 :
304 32061 : inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle )
305 : {
306 32061 : aStyles.push_back( pStyle );
307 32061 : pStyle->AddFirstRef();
308 :
309 32061 : FlushIndex();
310 32061 : }
311 :
312 4426 : void SvXMLStylesContext_Impl::Clear()
313 : {
314 4426 : FlushIndex();
315 :
316 36046 : for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
317 : {
318 31620 : SvXMLStyleContext *pStyle = aStyles[ i ];
319 31620 : pStyle->ReleaseRef();
320 : }
321 4426 : aStyles.clear();
322 4426 : }
323 :
324 42567 : const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext( sal_uInt16 nFamily,
325 : const OUString& rName,
326 : bool bCreateIndex ) const
327 : {
328 42567 : const SvXMLStyleContext *pStyle = 0;
329 :
330 42567 : if( !pIndices && bCreateIndex && !aStyles.empty() )
331 : {
332 1957 : pIndices = new IndicesType(aStyles.begin(), aStyles.end());
333 : SAL_WARN_IF(pIndices->size() != aStyles.size(), "xmloff", "Here is a duplicate Style");
334 : #if OSL_DEBUG_LEVEL > 0
335 : SAL_WARN_IF(0 != m_nIndexCreated, "xmloff.style",
336 : "Performance warning: sdbcx::Index created multiple times");
337 : ++m_nIndexCreated;
338 : #endif
339 : }
340 :
341 42567 : if( pIndices )
342 : {
343 39144 : SvXMLStyleIndex_Impl aIndex( nFamily, rName );
344 39144 : IndicesType::iterator aFind = pIndices->find(aIndex);
345 39144 : if( aFind != pIndices->end() )
346 36274 : pStyle = aFind->GetStyle();
347 : }
348 : else
349 : {
350 73042 : for( size_t i = 0; !pStyle && i < aStyles.size(); i++ )
351 : {
352 69619 : const SvXMLStyleContext *pS = aStyles[ i ];
353 118798 : if( pS->GetFamily() == nFamily &&
354 49179 : pS->GetName() == rName )
355 2830 : pStyle = pS;
356 : }
357 : }
358 42567 : return pStyle;
359 : }
360 :
361 0 : TYPEINIT1( SvXMLStylesContext, SvXMLImportContext );
362 :
363 19497 : sal_uInt32 SvXMLStylesContext::GetStyleCount() const
364 : {
365 19497 : return mpImpl->GetStyleCount();
366 : }
367 :
368 43770 : SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i )
369 : {
370 43770 : return mpImpl->GetStyle( i );
371 : }
372 :
373 14510 : const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const
374 : {
375 14510 : return mpImpl->GetStyle( i );
376 : }
377 :
378 28436 : bool SvXMLStylesContext::IsAutomaticStyle() const
379 : {
380 28436 : return mpImpl->IsAutomaticStyle();
381 : }
382 :
383 24764 : SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( sal_uInt16 p_nPrefix,
384 : const OUString& rLocalName,
385 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
386 : {
387 24764 : SvXMLStyleContext *pStyle = NULL;
388 :
389 24764 : if(GetImport().GetDataStylesImport())
390 : {
391 21802 : pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix,
392 43604 : rLocalName, xAttrList, *this);
393 : }
394 :
395 24764 : if (!pStyle)
396 : {
397 22820 : const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap();
398 22820 : sal_uInt16 nToken = rTokenMap.Get( p_nPrefix, rLocalName );
399 22820 : switch( nToken )
400 : {
401 : case XML_TOK_STYLE_STYLE:
402 : case XML_TOK_STYLE_DEFAULT_STYLE:
403 : {
404 19416 : sal_uInt16 nFamily = 0;
405 19416 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
406 37077 : for( sal_Int16 i=0; i < nAttrCount; i++ )
407 : {
408 37077 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
409 54738 : OUString aLocalName;
410 : sal_uInt16 nPrefix =
411 37077 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
412 37077 : &aLocalName );
413 74154 : if( XML_NAMESPACE_STYLE == nPrefix &&
414 37077 : IsXMLToken( aLocalName, XML_FAMILY ) )
415 : {
416 19416 : const OUString& rValue = xAttrList->getValueByIndex( i );
417 19416 : nFamily = GetFamily( rValue );
418 19416 : break;
419 : }
420 17661 : }
421 : pStyle = XML_TOK_STYLE_STYLE==nToken
422 : ? CreateStyleStyleChildContext( nFamily, p_nPrefix,
423 17509 : rLocalName, xAttrList )
424 : : CreateDefaultStyleStyleChildContext( nFamily, p_nPrefix,
425 36925 : rLocalName, xAttrList );
426 : }
427 19416 : break;
428 : case XML_TOK_STYLE_PAGE_MASTER:
429 : case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT:
430 : {
431 : //there is not page family in ODF now, so I specify one for it
432 1033 : bool bDefaultStyle = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken;
433 1033 : pStyle = new PageStyleContext( GetImport(), p_nPrefix,
434 1033 : rLocalName, xAttrList, *this, bDefaultStyle );
435 : }
436 1033 : break;
437 : case XML_TOK_TEXT_LIST_STYLE:
438 707 : pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
439 707 : rLocalName, xAttrList );
440 707 : break;
441 : case XML_TOK_TEXT_OUTLINE:
442 285 : pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
443 285 : rLocalName, xAttrList, true );
444 285 : break;
445 : case XML_TOK_TEXT_NOTE_CONFIG:
446 676 : pStyle = new XMLFootnoteConfigurationImportContext(GetImport(),
447 : p_nPrefix,
448 : rLocalName,
449 676 : xAttrList);
450 676 : break;
451 :
452 : case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG:
453 : pStyle = new XMLIndexBibliographyConfigurationContext(
454 5 : GetImport(), p_nPrefix, rLocalName, xAttrList);
455 5 : break;
456 :
457 : case XML_TOK_TEXT_LINENUMBERING_CONFIG:
458 : pStyle = new XMLLineNumberingImportContext(
459 338 : GetImport(), p_nPrefix, rLocalName, xAttrList);
460 338 : break;
461 :
462 :
463 : // FillStyles
464 :
465 : case XML_TOK_STYLES_GRADIENTSTYLES:
466 : {
467 80 : pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
468 80 : break;
469 : }
470 : case XML_TOK_STYLES_HATCHSTYLES:
471 : {
472 41 : pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
473 41 : break;
474 : }
475 : case XML_TOK_STYLES_BITMAPSTYLES:
476 : {
477 79 : pStyle = new XMLBitmapStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
478 79 : break;
479 : }
480 : case XML_TOK_STYLES_TRANSGRADIENTSTYLES:
481 : {
482 11 : pStyle = new XMLTransGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
483 11 : break;
484 : }
485 : case XML_TOK_STYLES_MARKERSTYLES:
486 : {
487 118 : pStyle = new XMLMarkerStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
488 118 : break;
489 : }
490 : case XML_TOK_STYLES_DASHSTYLES:
491 : {
492 31 : pStyle = new XMLDashStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
493 31 : break;
494 : }
495 : }
496 : }
497 :
498 24764 : return pStyle;
499 : }
500 :
501 9267 : SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext(
502 : sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
503 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
504 : {
505 9267 : SvXMLStyleContext *pStyle = 0;
506 :
507 9267 : switch( nFamily )
508 : {
509 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
510 : case XML_STYLE_FAMILY_TEXT_TEXT:
511 : case XML_STYLE_FAMILY_TEXT_SECTION:
512 2733 : pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
513 2733 : xAttrList, *this, nFamily );
514 2733 : break;
515 :
516 : case XML_STYLE_FAMILY_TEXT_RUBY:
517 7 : pStyle = new XMLPropStyleContext( GetImport(), nPrefix, rLocalName,
518 7 : xAttrList, *this, nFamily );
519 7 : break;
520 : case XML_STYLE_FAMILY_SCH_CHART_ID:
521 916 : pStyle = new XMLChartStyleContext( GetImport(), nPrefix, rLocalName,
522 916 : xAttrList, *this, nFamily );
523 916 : break;
524 :
525 : case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
526 : case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
527 : case XML_STYLE_FAMILY_SD_POOL_ID:
528 2021 : pStyle = new XMLShapeStyleContext( GetImport(), nPrefix, rLocalName,
529 2021 : xAttrList, *this, nFamily );
530 : }
531 :
532 9267 : return pStyle;
533 : }
534 :
535 505 : SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
536 : sal_uInt16 /*nFamily*/, sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/,
537 : const uno::Reference< xml::sax::XAttributeList > & )
538 : {
539 505 : return 0;
540 : }
541 :
542 10318 : bool SvXMLStylesContext::InsertStyleFamily( sal_uInt16 ) const
543 : {
544 10318 : return true;
545 : }
546 :
547 19416 : sal_uInt16 SvXMLStylesContext::GetFamily( const OUString& rValue ) const
548 : {
549 19416 : sal_uInt16 nFamily = 0U;
550 19416 : if( IsXMLToken( rValue, XML_PARAGRAPH ) )
551 : {
552 6931 : nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH;
553 : }
554 12485 : else if( IsXMLToken( rValue, XML_TEXT ) )
555 : {
556 2641 : nFamily = XML_STYLE_FAMILY_TEXT_TEXT;
557 : }
558 9844 : else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
559 : {
560 0 : nFamily = XML_STYLE_FAMILY_DATA_STYLE;
561 : }
562 9844 : else if ( IsXMLToken( rValue, XML_SECTION ) )
563 : {
564 39 : nFamily = XML_STYLE_FAMILY_TEXT_SECTION;
565 : }
566 9805 : else if( IsXMLToken( rValue, XML_TABLE ) )
567 : {
568 679 : nFamily = XML_STYLE_FAMILY_TABLE_TABLE;
569 : }
570 9126 : else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
571 1535 : nFamily = XML_STYLE_FAMILY_TABLE_COLUMN;
572 7591 : else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
573 762 : nFamily = XML_STYLE_FAMILY_TABLE_ROW;
574 6829 : else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
575 2612 : nFamily = XML_STYLE_FAMILY_TABLE_CELL;
576 4217 : else if ( rValue == XML_STYLE_FAMILY_SD_GRAPHICS_NAME )
577 : {
578 2255 : nFamily = XML_STYLE_FAMILY_SD_GRAPHICS_ID;
579 : }
580 1962 : else if ( rValue == XML_STYLE_FAMILY_SD_PRESENTATION_NAME )
581 : {
582 821 : nFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
583 : }
584 1141 : else if ( rValue == XML_STYLE_FAMILY_SD_POOL_NAME )
585 : {
586 0 : nFamily = XML_STYLE_FAMILY_SD_POOL_ID;
587 : }
588 1141 : else if ( rValue == XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME )
589 : {
590 218 : nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID;
591 : }
592 923 : else if ( rValue == XML_STYLE_FAMILY_SCH_CHART_NAME )
593 : {
594 916 : nFamily = XML_STYLE_FAMILY_SCH_CHART_ID;
595 : }
596 7 : else if ( IsXMLToken( rValue, XML_RUBY ) )
597 : {
598 7 : nFamily = XML_STYLE_FAMILY_TEXT_RUBY;
599 : }
600 :
601 19416 : return nFamily;
602 : }
603 :
604 83440 : rtl::Reference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper(
605 : sal_uInt16 nFamily ) const
606 : {
607 83440 : rtl::Reference < SvXMLImportPropertyMapper > xMapper;
608 :
609 83440 : switch( nFamily )
610 : {
611 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
612 29202 : if( !mxParaImpPropMapper.is() )
613 : {
614 848 : SvXMLStylesContext * pThis = const_cast<SvXMLStylesContext *>(this);
615 848 : pThis->mxParaImpPropMapper =
616 848 : pThis->GetImport().GetTextImport()
617 1696 : ->GetParaImportPropertySetMapper();
618 : }
619 29202 : xMapper = mxParaImpPropMapper;
620 29202 : break;
621 : case XML_STYLE_FAMILY_TEXT_TEXT:
622 11642 : if( !mxTextImpPropMapper.is() )
623 : {
624 430 : SvXMLStylesContext * pThis = const_cast<SvXMLStylesContext *>(this);
625 430 : pThis->mxTextImpPropMapper =
626 430 : pThis->GetImport().GetTextImport()
627 860 : ->GetTextImportPropertySetMapper();
628 : }
629 11642 : xMapper = mxTextImpPropMapper;
630 11642 : break;
631 :
632 : case XML_STYLE_FAMILY_TEXT_SECTION:
633 : // don't cache section mapper, as it's rarely used
634 : // *sigh*, cast to non-const, because this is a const method,
635 : // but SvXMLImport::GetTextImport() isn't.
636 143 : xMapper = const_cast<SvXMLStylesContext*>(this)->GetImport().GetTextImport()->
637 143 : GetSectionImportPropertySetMapper();
638 143 : break;
639 :
640 : case XML_STYLE_FAMILY_TEXT_RUBY:
641 : // don't cache section mapper, as it's rarely used
642 : // *sigh*, cast to non-const, because this is a const method,
643 : // but SvXMLImport::GetTextImport() isn't.
644 19 : xMapper = const_cast<SvXMLStylesContext*>(this)->GetImport().GetTextImport()->
645 19 : GetRubyImportPropertySetMapper();
646 19 : break;
647 :
648 : case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
649 : case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
650 : case XML_STYLE_FAMILY_SD_POOL_ID:
651 14133 : if(!mxShapeImpPropMapper.is())
652 : {
653 810 : rtl::Reference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
654 810 : const_cast<SvXMLStylesContext*>(this)->mxShapeImpPropMapper =
655 810 : aImpHelper->GetPropertySetMapper();
656 : }
657 14133 : xMapper = mxShapeImpPropMapper;
658 14133 : break;
659 : case XML_STYLE_FAMILY_SCH_CHART_ID:
660 4557 : if( ! mxChartImpPropMapper.is() )
661 : {
662 86 : XMLPropertySetMapper *pPropMapper = new XMLChartPropertySetMapper( false );
663 86 : mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() );
664 : }
665 4557 : xMapper = mxChartImpPropMapper;
666 4557 : break;
667 : case XML_STYLE_FAMILY_PAGE_MASTER:
668 6484 : if( ! mxPageImpPropMapper.is() )
669 : {
670 : XMLPropertySetMapper *pPropMapper =
671 576 : new XMLPageMasterPropSetMapper( false );
672 2304 : mxPageImpPropMapper =
673 : new PageMasterImportPropertyMapper( pPropMapper,
674 1728 : const_cast<SvXMLStylesContext*>(this)->GetImport() );
675 : }
676 6484 : xMapper = mxPageImpPropMapper;
677 6484 : break;
678 : }
679 :
680 83440 : return xMapper;
681 : }
682 :
683 3040 : Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily ) const
684 : {
685 3040 : Reference < XAutoStyleFamily > xAutoStyles;
686 3040 : if( XML_STYLE_FAMILY_TEXT_TEXT == nFamily || XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily)
687 : {
688 3040 : bool bPara = XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily;
689 3040 : OUString sName;
690 3040 : if( !bPara && mxTextAutoStyles.is() )
691 1013 : xAutoStyles = mxTextAutoStyles;
692 2027 : else if( bPara && mxParaAutoStyles.is() )
693 1596 : xAutoStyles = mxParaAutoStyles;
694 : else
695 : {
696 431 : sName = bPara ? OUString( "ParagraphStyles" ): OUString( "CharacterStyles" );
697 431 : Reference< XAutoStylesSupplier > xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY );
698 862 : Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
699 431 : if (xAutoStyleFamilies->hasByName(sName))
700 : {
701 431 : Any aAny = xAutoStyleFamilies->getByName( sName );
702 431 : xAutoStyles = *static_cast<Reference<XAutoStyleFamily> const *>(aAny.getValue());
703 431 : if( bPara )
704 281 : const_cast<SvXMLStylesContext *>(this)->mxParaAutoStyles = xAutoStyles;
705 : else
706 150 : const_cast<SvXMLStylesContext *>(this)->mxTextAutoStyles = xAutoStyles;
707 431 : }
708 3040 : }
709 : }
710 3040 : return xAutoStyles;
711 : }
712 :
713 12084 : Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
714 : sal_uInt16 nFamily ) const
715 : {
716 12084 : Reference < XNameContainer > xStyles;
717 24168 : OUString sName;
718 12084 : switch( nFamily )
719 : {
720 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
721 7914 : if( mxParaStyles.is() )
722 7252 : xStyles = mxParaStyles;
723 : else
724 662 : sName = "ParagraphStyles";
725 7914 : break;
726 :
727 : case XML_STYLE_FAMILY_TEXT_TEXT:
728 2274 : if( mxTextStyles.is() )
729 2006 : xStyles = mxTextStyles;
730 : else
731 268 : sName = "CharacterStyles";
732 2274 : break;
733 : }
734 12084 : if( !xStyles.is() && !sName.isEmpty() )
735 : {
736 : Reference< XStyleFamiliesSupplier > xFamiliesSupp(
737 930 : GetImport().GetModel(), UNO_QUERY );
738 930 : if ( xFamiliesSupp.is() )
739 : {
740 930 : Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
741 930 : if (xFamilies->hasByName(sName))
742 : {
743 495 : xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
744 :
745 495 : switch( nFamily )
746 : {
747 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
748 343 : const_cast<SvXMLStylesContext *>(this)->mxParaStyles = xStyles;
749 343 : break;
750 :
751 : case XML_STYLE_FAMILY_TEXT_TEXT:
752 152 : const_cast<SvXMLStylesContext *>(this)->mxTextStyles = xStyles;
753 152 : break;
754 : }
755 930 : }
756 930 : }
757 : }
758 :
759 24168 : return xStyles;
760 : }
761 :
762 1541 : OUString SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily ) const
763 : {
764 1541 : OUString sServiceName;
765 1541 : switch( nFamily )
766 : {
767 : case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
768 657 : sServiceName = msParaStyleServiceName;
769 657 : break;
770 : case XML_STYLE_FAMILY_TEXT_TEXT:
771 776 : sServiceName = msTextStyleServiceName;
772 776 : break;
773 : }
774 :
775 1541 : return sServiceName;
776 : }
777 :
778 3610 : SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
779 : const OUString& rLName,
780 : const uno::Reference< xml::sax::XAttributeList > &, bool bAuto ) :
781 : SvXMLImportContext( rImport, nPrfx, rLName ),
782 : msParaStyleServiceName( "com.sun.star.style.ParagraphStyle" ),
783 : msTextStyleServiceName( "com.sun.star.style.CharacterStyle" ),
784 3610 : mpImpl( new SvXMLStylesContext_Impl( bAuto ) ),
785 7220 : mpStyleStylesElemTokenMap( 0 )
786 : {
787 3610 : }
788 :
789 7392 : SvXMLStylesContext::~SvXMLStylesContext()
790 : {
791 3610 : delete mpStyleStylesElemTokenMap;
792 3610 : delete mpImpl;
793 3782 : }
794 :
795 31738 : SvXMLImportContext *SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix,
796 : const OUString& rLocalName,
797 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
798 : {
799 31738 : SvXMLImportContext *pContext = 0;
800 :
801 : SvXMLStyleContext *pStyle =
802 31738 : CreateStyleChildContext( nPrefix, rLocalName, xAttrList );
803 31738 : if( pStyle )
804 : {
805 31512 : if( !pStyle->IsTransient() )
806 31152 : mpImpl->AddStyle( pStyle );
807 31512 : pContext = pStyle;
808 : }
809 : else
810 : {
811 226 : pContext = new SvXMLImportContext( GetImport(), nPrefix,
812 226 : rLocalName );
813 : }
814 :
815 31738 : return pContext;
816 : }
817 :
818 1870 : void SvXMLStylesContext::EndElement()
819 : {
820 1870 : }
821 :
822 909 : void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew)
823 : {
824 909 : mpImpl->AddStyle( &rNew );
825 909 : }
826 :
827 4426 : void SvXMLStylesContext::Clear()
828 : {
829 4426 : mpImpl->Clear();
830 4426 : }
831 :
832 632 : void SvXMLStylesContext::CopyAutoStylesToDoc()
833 : {
834 632 : sal_uInt32 nCount = GetStyleCount();
835 : sal_uInt32 i;
836 5804 : for( i = 0; i < nCount; i++ )
837 : {
838 5172 : SvXMLStyleContext *pStyle = GetStyle( i );
839 10896 : if( !pStyle || ( pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT &&
840 6149 : pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH &&
841 2140 : pStyle->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL ) )
842 1715 : continue;
843 3457 : pStyle->CreateAndInsert( false );
844 : }
845 632 : }
846 :
847 543 : void SvXMLStylesContext::CopyStylesToDoc( bool bOverwrite,
848 : bool bFinish )
849 : {
850 : // pass 1: create text, paragraph and frame styles
851 543 : sal_uInt32 nCount = GetStyleCount();
852 : sal_uInt32 i;
853 :
854 11998 : for( i = 0; i < nCount; i++ )
855 : {
856 11455 : SvXMLStyleContext *pStyle = GetStyle( i );
857 11455 : if( !pStyle )
858 0 : continue;
859 :
860 11455 : if (pStyle->IsDefaultStyle())
861 1676 : pStyle->SetDefaults();
862 9779 : else if( InsertStyleFamily( pStyle->GetFamily() ) )
863 9620 : pStyle->CreateAndInsert( bOverwrite );
864 : }
865 :
866 : // pass 2: create list styles (they require char styles)
867 11998 : for( i=0; i<nCount; i++ )
868 : {
869 11455 : SvXMLStyleContext *pStyle = GetStyle( i );
870 11455 : if( !pStyle || pStyle->IsDefaultStyle())
871 1676 : continue;
872 :
873 9779 : if( InsertStyleFamily( pStyle->GetFamily() ) )
874 9620 : pStyle->CreateAndInsertLate( bOverwrite );
875 : }
876 :
877 : // pass3: finish creation of styles
878 543 : if( bFinish )
879 198 : FinishStyles( bOverwrite );
880 543 : }
881 :
882 1216 : void SvXMLStylesContext::FinishStyles( bool bOverwrite )
883 : {
884 1216 : sal_uInt32 nCount = GetStyleCount();
885 15304 : for( sal_uInt32 i=0; i<nCount; i++ )
886 : {
887 14088 : SvXMLStyleContext *pStyle = GetStyle( i );
888 14088 : if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
889 1941 : continue;
890 :
891 12147 : if( InsertStyleFamily( pStyle->GetFamily() ) )
892 11988 : pStyle->Finish( bOverwrite );
893 : }
894 1216 : }
895 :
896 42567 : const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext(
897 : sal_uInt16 nFamily,
898 : const OUString& rName,
899 : bool bCreateIndex ) const
900 : {
901 42567 : return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
902 : }
903 :
904 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|