1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/xml/sax/SAXParseException.hpp>
21 #include <com/sun/star/xml/sax/SAXException.hpp>
22 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
23 #include <com/sun/star/xml/sax/XAttributeList.hpp>
24 #include <rtl/ustrbuf.hxx>
25 #include <sax/tools/converter.hxx>
26 #include <xmloff/nmspmap.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include "xmloff/xmlnmspe.hxx"
29 #include "PropType.hxx"
30 #include "DeepTContext.hxx"
31 #include "ProcAttrTContext.hxx"
32 #include "TransformerBase.hxx"
33 #include "TransformerActions.hxx"
34 #include "ActionMapTypesOASIS.hxx"
35 #include "MutableAttrList.hxx"
36 #include "PropertyActionsOASIS.hxx"
37 #include "StyleOASISTContext.hxx"
38 #include <xmloff/xmluconv.hxx>
40 using namespace ::xmloff::token
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::xml::sax
;
43 //------------------------------------------------------------------------------
45 static sal_uInt16 aAttrActionMaps
[XML_PROP_TYPE_END
] =
47 PROP_OASIS_GRAPHIC_ATTR_ACTIONS
,
48 PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS
, // DRAWING_PAGE
49 PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS
,
50 PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS
,
51 PROP_OASIS_TEXT_ATTR_ACTIONS
,
52 PROP_OASIS_PARAGRAPH_ATTR_ACTIONS
,
53 MAX_OASIS_PROP_ACTIONS
, // RUBY
54 PROP_OASIS_SECTION_ATTR_ACTIONS
,
55 PROP_OASIS_TABLE_ATTR_ACTIONS
,
56 PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS
,
57 PROP_OASIS_TABLE_ROW_ATTR_ACTIONS
,
58 PROP_OASIS_TABLE_CELL_ATTR_ACTIONS
,
59 PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS
,
60 PROP_OASIS_CHART_ATTR_ACTIONS
63 //------------------------------------------------------------------------------
65 class XMLPropertiesTContext_Impl
: public XMLPersElemContentTContext
67 ::com::sun::star::uno::Reference
<
68 ::com::sun::star::xml::sax::XAttributeList
> m_xAttrList
;
70 XMLPropType m_ePropType
;
71 sal_Bool m_bControlStyle
;
72 OUString m_aStyleFamily
;
76 void SetQNameAndPropType( const OUString
& rQName
,
77 XMLPropType ePropType
)
79 m_ePropType
= ePropType
;
80 XMLTransformerContext::SetQName( rQName
);
85 XMLPropertiesTContext_Impl( XMLTransformerBase
& rTransformer
,
86 const OUString
& rQName
,
88 const OUString
& rStyleFamily
,
89 sal_Bool _bControlStyle
= sal_False
);
91 virtual ~XMLPropertiesTContext_Impl();
93 virtual void StartElement( const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
);
95 virtual void Export();
97 static XMLPropType
GetPropType( const OUString
& rLocalName
);
99 static OUString
MergeUnderline( XMLTokenEnum eUnderline
,
100 sal_Bool bBold
, sal_Bool bDouble
);
101 static OUString
MergeLineThrough( XMLTokenEnum eLineThrough
,
102 sal_Bool bBold
, sal_Bool bDouble
,
106 TYPEINIT1( XMLPropertiesTContext_Impl
, XMLPersElemContentTContext
);
108 XMLPropertiesTContext_Impl::XMLPropertiesTContext_Impl(
109 XMLTransformerBase
& rImp
, const OUString
& rQName
, XMLPropType eP
,
110 const OUString
& rStyleFamily
, sal_Bool _bControlStyle
) :
111 XMLPersElemContentTContext( rImp
, rQName
, XML_NAMESPACE_STYLE
,
114 m_bControlStyle( _bControlStyle
),
115 m_aStyleFamily( rStyleFamily
)
119 XMLPropertiesTContext_Impl::~XMLPropertiesTContext_Impl()
123 void XMLPropertiesTContext_Impl::StartElement(
124 const Reference
< XAttributeList
>& rAttrList
)
126 XMLTransformerActions
*pActions
= 0;
127 sal_uInt16 nActionMap
= aAttrActionMaps
[m_ePropType
];
128 if( nActionMap
< MAX_OASIS_PROP_ACTIONS
)
130 pActions
= GetTransformer().GetUserDefinedActions( nActionMap
);
131 OSL_ENSURE( pActions
, "go no actions" );
136 XMLMutableAttributeList
*pAttrList
= 0;
137 if( !m_xAttrList
.is() )
139 pAttrList
= new XMLMutableAttributeList();
140 m_xAttrList
= pAttrList
;
145 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() );
148 XMLTokenEnum eUnderline
= XML_TOKEN_END
;
149 sal_Bool bBoldUnderline
= sal_False
, bDoubleUnderline
= sal_False
;
150 XMLTokenEnum eLineThrough
= XML_TOKEN_END
;
151 sal_Bool bBoldLineThrough
= sal_False
, bDoubleLineThrough
= sal_False
;
152 sal_Unicode cLineThroughChar
= 0;
154 bool bIntervalMinorFound
= false;
155 double fIntervalMajor
= 0.0;
156 sal_Int32 nIntervalMinorDivisor
= 0;
159 OUString aOpacityValueRemember
;
160 OUString aImageOpacityValueRemember
;
162 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
163 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
165 const OUString
& rAttrName
= rAttrList
->getNameByIndex( i
);
166 const OUString
& rAttrValue
= rAttrList
->getValueByIndex( i
);
169 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
172 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
173 XMLTransformerActions::const_iterator aIter
=
174 pActions
->find( aKey
);
175 if( !(aIter
== pActions
->end() ) )
177 switch( (*aIter
).second
.m_nActionType
)
179 case XML_ATACTION_REMOVE
:
181 case XML_ATACTION_COPY
:
182 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
184 case XML_ATACTION_RENAME
:
186 OUString
aNewAttrQName(
187 GetTransformer().GetNamespaceMap().GetQNameByKey(
188 (*aIter
).second
.GetQNamePrefixFromParam1(),
189 ::xmloff::token::GetXMLToken(
190 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
191 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
194 case XML_ATACTION_IN2INCH
:
196 OUString
aAttrValue( rAttrValue
);
197 XMLTransformerBase::ReplaceSingleInWithInch(
199 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
202 case XML_ATACTION_INS2INCHS
:
204 OUString
aAttrValue( rAttrValue
);
205 XMLTransformerBase::ReplaceInWithInch(
207 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
210 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
212 OUString
aAttrValue( rAttrValue
);
213 GetTransformer().DecodeStyleName(aAttrValue
);
214 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
217 case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF
:
219 OUString
aNewAttrQName(
220 GetTransformer().GetNamespaceMap().GetQNameByKey(
221 (*aIter
).second
.GetQNamePrefixFromParam1(),
222 ::xmloff::token::GetXMLToken(
223 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
224 OUString
aAttrValue( rAttrValue
);
225 GetTransformer().DecodeStyleName(aAttrValue
);
226 pAttrList
->AddAttribute( aNewAttrQName
, aAttrValue
);
229 case XML_ATACTION_NEG_PERCENT
:
231 OUString
aAttrValue( rAttrValue
);
232 GetTransformer().NegPercent(aAttrValue
);
233 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
236 case XML_ATACTION_RENAME_NEG_PERCENT
:
238 OUString
aNewAttrQName(
239 GetTransformer().GetNamespaceMap().GetQNameByKey(
240 (*aIter
).second
.GetQNamePrefixFromParam1(),
241 ::xmloff::token::GetXMLToken(
242 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
243 OUString
aAttrValue( rAttrValue
);
244 GetTransformer().NegPercent(aAttrValue
);
245 pAttrList
->AddAttribute( aNewAttrQName
, aAttrValue
);
248 case XML_OPTACTION_LINE_MODE
:
251 IsXMLToken( rAttrValue
, XML_SKIP_WHITE_SPACE
);
253 GetTransformer().GetNamespaceMap().GetQNameByKey(
255 GetXMLToken( XML_SCORE_SPACES
) ) );
257 pAttrList
->GetIndexByName( aAttrQName
);
262 const OUString
& rOldValue
=
263 pAttrList
->getValueByIndex( nIndex
);
264 if( !IsXMLToken( rOldValue
, XML_TRUE
) )
266 pAttrList
->SetValueByIndex( nIndex
,
267 GetXMLToken( XML_TRUE
) );
273 OUString
aAttrValue( GetXMLToken( bWordMode
276 pAttrList
->AddAttribute( aAttrQName
, aAttrValue
);
280 case XML_OPTACTION_KEEP_WITH_NEXT
:
282 OUString
aAttrValue( GetXMLToken(
283 IsXMLToken( rAttrValue
, XML_ALWAYS
)
286 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
289 case XML_OPTACTION_UNDERLINE_WIDTH
:
290 if( IsXMLToken( rAttrValue
, XML_BOLD
) )
291 bBoldUnderline
= sal_True
;
293 case XML_OPTACTION_UNDERLINE_TYPE
:
294 if( IsXMLToken( rAttrValue
, XML_DOUBLE
) )
295 bDoubleUnderline
= sal_True
;
297 case XML_OPTACTION_UNDERLINE_STYLE
:
298 eUnderline
= GetTransformer().GetToken( rAttrValue
);
300 case XML_OPTACTION_LINETHROUGH_WIDTH
:
301 if( IsXMLToken( rAttrValue
, XML_BOLD
) )
302 bBoldLineThrough
= sal_True
;
304 case XML_OPTACTION_LINETHROUGH_TYPE
:
305 if( IsXMLToken( rAttrValue
, XML_DOUBLE
) )
306 bDoubleLineThrough
= sal_True
;
308 case XML_OPTACTION_LINETHROUGH_STYLE
:
309 eLineThrough
= GetTransformer().GetToken( rAttrValue
);
311 case XML_OPTACTION_LINETHROUGH_TEXT
:
312 if( !rAttrValue
.isEmpty() )
313 cLineThroughChar
= rAttrValue
[0];
315 case XML_OPTACTION_INTERPOLATION
:
318 sal_Int32 nSplineType
= 0;
319 if( IsXMLToken( rAttrValue
, XML_CUBIC_SPLINE
))
321 else if( IsXMLToken( rAttrValue
, XML_B_SPLINE
))
324 pAttrList
->AddAttribute(
325 GetTransformer().GetNamespaceMap().GetQNameByKey(
327 GetXMLToken( XML_SPLINES
)),
328 OUString::valueOf( nSplineType
));
331 case XML_OPTACTION_INTERVAL_MAJOR
:
332 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
333 ::sax::Converter::convertDouble(fIntervalMajor
, rAttrValue
);
335 case XML_OPTACTION_INTERVAL_MINOR_DIVISOR
:
336 ::sax::Converter::convertNumber(nIntervalMinorDivisor
, rAttrValue
);
337 bIntervalMinorFound
= true;
339 case XML_OPTACTION_SYMBOL_TYPE
:
341 // if symbol_type is "named-symbol" the "symbol"
342 // property is set in the action XML_OPTACTION_SYMBOL_NAME
343 sal_Int32 nSymbolType
= 0;
344 if( IsXMLToken( rAttrValue
, XML_NONE
))
346 else if( IsXMLToken( rAttrValue
, XML_AUTOMATIC
))
348 else if( IsXMLToken( rAttrValue
, XML_IMAGE
))
351 if( nSymbolType
< 0 )
352 pAttrList
->AddAttribute(
353 GetTransformer().GetNamespaceMap().GetQNameByKey(
355 GetXMLToken( XML_SYMBOL
)),
356 OUString::valueOf( nSymbolType
));
359 case XML_OPTACTION_SYMBOL_NAME
:
361 // assume "symbol-type" == "named-symbol"
362 sal_Int32 nSymbolType
= -3; // NONE
363 // "square" just has an awkward token-name
364 if( IsXMLToken( rAttrValue
, XML_GRADIENTSTYLE_SQUARE
))
366 else if( IsXMLToken( rAttrValue
, XML_DIAMOND
))
368 else if( IsXMLToken( rAttrValue
, XML_ARROW_DOWN
))
370 else if( IsXMLToken( rAttrValue
, XML_ARROW_UP
))
372 else if( IsXMLToken( rAttrValue
, XML_ARROW_RIGHT
))
374 else if( IsXMLToken( rAttrValue
, XML_ARROW_LEFT
))
376 else if( IsXMLToken( rAttrValue
, XML_BOW_TIE
))
378 else if( IsXMLToken( rAttrValue
, XML_HOURGLASS
))
380 else if( IsXMLToken( rAttrValue
, XML_CIRCLE
))
382 else if( IsXMLToken( rAttrValue
, XML_STAR
))
384 else if( IsXMLToken( rAttrValue
, XML_X
))
386 else if( IsXMLToken( rAttrValue
, XML_PLUS
))
388 else if( IsXMLToken( rAttrValue
, XML_ASTERISK
))
390 else if( IsXMLToken( rAttrValue
, XML_HORIZONTAL_BAR
))
392 else if( IsXMLToken( rAttrValue
, XML_VERTICAL_BAR
))
395 if( nSymbolType
>= 0 )
396 pAttrList
->AddAttribute(
397 GetTransformer().GetNamespaceMap().GetQNameByKey(
399 GetXMLToken( XML_SYMBOL
)),
400 OUString::valueOf( nSymbolType
));
404 case XML_OPTACTION_OPACITY
:
405 aOpacityValueRemember
= rAttrValue
;
406 GetTransformer().NegPercent(aOpacityValueRemember
);
410 case XML_OPTACTION_IMAGE_OPACITY
:
411 aImageOpacityValueRemember
= rAttrValue
;
412 GetTransformer().NegPercent(aImageOpacityValueRemember
);
415 case XML_OPTACTION_KEEP_TOGETHER
:
416 pAttrList
->AddAttribute(
417 GetTransformer().GetNamespaceMap().GetQNameByKey(
418 XML_NAMESPACE_STYLE
,GetXMLToken(XML_BREAK_INSIDE
)),
420 IsXMLToken( rAttrValue
, XML_ALWAYS
)
421 ? XML_COLUMNSPLIT_AVOID
422 : XML_COLUMNSPLIT_AUTO
) );
425 case XML_OPTACTION_CONTROL_TEXT_ALIGN
:
426 if ( m_bControlStyle
)
428 OUString
aNewAttrQName(
429 GetTransformer().GetNamespaceMap().GetQNameByKey(
431 ::xmloff::token::GetXMLToken(
432 XML_TEXT_ALIGN
) ) );
433 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
437 OUString
aNewAttrQName(
438 GetTransformer().GetNamespaceMap().GetQNameByKey(
440 ::xmloff::token::GetXMLToken(
441 XML_TEXT_ALIGN
) ) );
442 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
446 case XML_OPTACTION_DRAW_WRITING_MODE
:
447 if( IsXMLToken( m_aStyleFamily
, XML_GRAPHICS
) )
449 pAttrList
->AddAttribute(
450 GetTransformer().GetNamespaceMap().GetQNameByKey(
452 GetXMLToken( XML_WRITING_MODE
) ), rAttrValue
);
454 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
457 case XML_ATACTION_CAPTION_ESCAPE_OASIS
:
459 OUString
aAttrValue( rAttrValue
);
460 if( aAttrValue
.indexOf( sal_Unicode('%') ) != -1 )
462 sal_Int32 nValue
= 0;
463 ::sax::Converter::convertPercent(nValue
, rAttrValue
);
468 ::sax::Converter::convertPercent(aOut
, nValue
);
469 aAttrValue
= aOut
.makeStringAndClear();
474 XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue
);
477 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
481 case XML_ATACTION_DECODE_PROTECT
:
483 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
485 if( rAttrValue
.indexOf( GetXMLToken( XML_SIZE
) ) != -1 )
486 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
488 GetXMLToken( XML_SIZE_PROTECT
)), GetXMLToken( XML_TRUE
) );
490 if( rAttrValue
.indexOf( GetXMLToken( XML_POSITION
) ) != -1 )
491 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
493 GetXMLToken( XML_MOVE_PROTECT
)), GetXMLToken( XML_TRUE
) );
497 case XML_ATACTION_DRAW_MIRROR_OASIS
: // renames style:mirror to draw:mirror and adapts values
499 // keep original for writer graphic objects
500 // Adapts attribute values (#i49139#)
501 OUString aNewAttrValue
;
502 SvXMLTokenEnumerator
aTokenEnum( rAttrValue
);
504 while( aTokenEnum
.getNextToken( aToken
) )
506 if ( !aNewAttrValue
.isEmpty() )
508 aNewAttrValue
+= OUString(" " );
511 if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_EVEN
) )
513 aNewAttrValue
+= GetXMLToken( XML_HORIZONTAL_ON_LEFT_PAGES
);
515 else if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_ODD
) )
517 aNewAttrValue
+= GetXMLToken( XML_HORIZONTAL_ON_RIGHT_PAGES
);
521 aNewAttrValue
+= aToken
;
524 pAttrList
->AddAttribute( rAttrName
, aNewAttrValue
);
526 // create old draw:mirror for drawing graphic objects
527 OUString
aAttrValue( GetXMLToken( IsXMLToken( rAttrValue
, XML_HORIZONTAL
) ? XML_TRUE
: XML_FALSE
) );
528 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
530 GetXMLToken( XML_MIRROR
)), aAttrValue
);
533 case XML_ATACTION_GAMMA_OASIS
: // converts percentage value to double
536 ::sax::Converter::convertPercent( nValue
, rAttrValue
);
537 const double fValue
= ((double)nValue
) / 100.0;
538 pAttrList
->AddAttribute( rAttrName
, OUString::valueOf( fValue
) );
541 case XML_ATACTION_OPACITY_FIX
:
544 if( rAttrValue
.indexOf( sal_Unicode('%') ) != -1 )
546 ::sax::Converter::convertPercent(nValue
, rAttrValue
);
550 nValue
= sal_Int32( rAttrValue
.toDouble() * 100.0 );
552 nValue
= 100 - nValue
;
555 ::sax::Converter::convertPercent(aOut
, nValue
);
556 pAttrList
->AddAttribute( rAttrName
, aOut
.makeStringAndClear() );
560 OSL_ENSURE( !this, "unknown action" );
566 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
569 if( XML_TOKEN_END
!= eUnderline
)
570 pAttrList
->AddAttribute(
571 GetTransformer().GetNamespaceMap().GetQNameByKey(
573 GetXMLToken( XML_TEXT_UNDERLINE
) ),
574 MergeUnderline( eUnderline
, bBoldUnderline
,
575 bDoubleUnderline
) );
576 if( XML_TOKEN_END
!= eLineThrough
)
577 pAttrList
->AddAttribute(
578 GetTransformer().GetNamespaceMap().GetQNameByKey(
580 GetXMLToken( XML_TEXT_CROSSING_OUT
) ),
581 MergeLineThrough( eLineThrough
, bBoldLineThrough
,
582 bDoubleLineThrough
, cLineThroughChar
) );
583 if( bIntervalMinorFound
)
585 double fIntervalMinor
= 0.0;
586 if( nIntervalMinorDivisor
!= 0)
587 fIntervalMinor
= fIntervalMajor
/ static_cast< double >( nIntervalMinorDivisor
);
590 ::sax::Converter::convertDouble( aBuf
, fIntervalMinor
);
591 pAttrList
->AddAttribute(
592 GetTransformer().GetNamespaceMap().GetQNameByKey(
594 GetXMLToken( XML_INTERVAL_MINOR
)),
595 aBuf
.makeStringAndClear());
599 if(!aOpacityValueRemember
.isEmpty() || !aImageOpacityValueRemember
.isEmpty())
601 pAttrList
->AddAttribute(
602 GetTransformer().GetNamespaceMap().GetQNameByKey(
604 GetXMLToken( XML_TRANSPARENCY
) ),
605 !aImageOpacityValueRemember
.isEmpty()
606 ? aImageOpacityValueRemember
: aOpacityValueRemember
);
611 if( !m_xAttrList
.is() )
613 m_xAttrList
= new XMLMutableAttributeList( rAttrList
, sal_True
);
617 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
618 ->AppendAttributeList( rAttrList
);
623 void XMLPropertiesTContext_Impl::Export()
625 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
628 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
631 XMLPropType
XMLPropertiesTContext_Impl::GetPropType( const OUString
& rLocalName
)
633 XMLPropType eProp
= XML_PROP_TYPE_END
;
634 if( IsXMLToken( rLocalName
, XML_GRAPHIC_PROPERTIES
) )
635 eProp
= XML_PROP_TYPE_GRAPHIC
;
636 else if( IsXMLToken( rLocalName
, XML_DRAWING_PAGE_PROPERTIES
) )
637 eProp
= XML_PROP_TYPE_DRAWING_PAGE
;
638 else if( IsXMLToken( rLocalName
, XML_PAGE_LAYOUT_PROPERTIES
) )
639 eProp
= XML_PROP_TYPE_PAGE_LAYOUT
;
640 else if( IsXMLToken( rLocalName
, XML_HEADER_FOOTER_PROPERTIES
) )
641 eProp
= XML_PROP_TYPE_HEADER_FOOTER
;
642 else if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) )
643 eProp
= XML_PROP_TYPE_TEXT
;
644 else if( IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
) )
645 eProp
= XML_PROP_TYPE_PARAGRAPH
;
646 else if( IsXMLToken( rLocalName
, XML_RUBY_PROPERTIES
) )
647 eProp
= XML_PROP_TYPE_RUBY
;
648 else if( IsXMLToken( rLocalName
, XML_SECTION_PROPERTIES
) )
649 eProp
= XML_PROP_TYPE_SECTION
;
650 else if( IsXMLToken( rLocalName
, XML_TABLE_PROPERTIES
) )
651 eProp
= XML_PROP_TYPE_TABLE
;
652 else if( IsXMLToken( rLocalName
, XML_TABLE_COLUMN_PROPERTIES
) )
653 eProp
= XML_PROP_TYPE_TABLE_COLUMN
;
654 else if( IsXMLToken( rLocalName
, XML_TABLE_ROW_PROPERTIES
) )
655 eProp
= XML_PROP_TYPE_TABLE_ROW
;
656 else if( IsXMLToken( rLocalName
, XML_TABLE_CELL_PROPERTIES
) )
657 eProp
= XML_PROP_TYPE_TABLE_CELL
;
658 else if( IsXMLToken( rLocalName
, XML_LIST_LEVEL_PROPERTIES
) )
659 eProp
= XML_PROP_TYPE_LIST_LEVEL
;
660 else if( IsXMLToken( rLocalName
, XML_CHART_PROPERTIES
) )
661 eProp
= XML_PROP_TYPE_CHART
;
666 OUString
XMLPropertiesTContext_Impl::MergeUnderline(
667 XMLTokenEnum eUnderline
, sal_Bool bBold
, sal_Bool bDouble
)
674 eUnderline
= XML_DOUBLE_WAVE
;
677 eUnderline
= XML_DOUBLE
;
687 eUnderline
= XML_BOLD
;
690 eUnderline
= XML_BOLD_DOTTED
;
693 eUnderline
= XML_BOLD_DASH
;
696 eUnderline
= XML_BOLD_LONG_DASH
;
699 eUnderline
= XML_BOLD_DOT_DASH
;
701 case XML_DOT_DOT_DASH
:
702 eUnderline
= XML_BOLD_DOT_DOT_DASH
;
705 eUnderline
= XML_BOLD_WAVE
;
708 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
717 eUnderline
= XML_SINGLE
;
720 eUnderline
= XML_NONE
;
723 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
728 return GetXMLToken( eUnderline
);
731 OUString
XMLPropertiesTContext_Impl::MergeLineThrough(
732 XMLTokenEnum eLineThrough
, sal_Bool bBold
, sal_Bool bDouble
,
736 eLineThrough
= c
=='/' ? XML_SLASH
: XML_uX
;
738 eLineThrough
= XML_DOUBLE_LINE
;
740 eLineThrough
= XML_THICK_LINE
;
741 else if( XML_NONE
!= eLineThrough
)
742 eLineThrough
= XML_SINGLE_LINE
;
744 return GetXMLToken( eLineThrough
);
747 //------------------------------------------------------------------------------
749 TYPEINIT1( XMLStyleOASISTContext
, XMLPersElemContentTContext
);
751 XMLStyleOASISTContext::XMLStyleOASISTContext( XMLTransformerBase
& rImp
,
752 const OUString
& rQName
,
753 sal_Bool bPersistent
) :
754 XMLPersElemContentTContext ( rImp
, rQName
),
755 m_bPersistent( bPersistent
),
756 m_bControlStyle( false )
760 XMLStyleOASISTContext::XMLStyleOASISTContext(
761 XMLTransformerBase
& rImp
,
762 const OUString
& rQName
,
764 ::xmloff::token::XMLTokenEnum eToken
,
765 sal_Bool bPersistent
) :
766 XMLPersElemContentTContext( rImp
, rQName
, nPrefix
, eToken
),
767 m_bPersistent( bPersistent
)
771 XMLStyleOASISTContext::~XMLStyleOASISTContext()
775 XMLTransformerContext
*XMLStyleOASISTContext::CreateChildContext(
777 const OUString
& rLocalName
,
778 const OUString
& rQName
,
779 const Reference
< XAttributeList
>& rAttrList
)
781 XMLTransformerContext
*pContext
= 0;
783 if( XML_NAMESPACE_STYLE
== nPrefix
)
785 XMLPropType ePropType
=
786 XMLPropertiesTContext_Impl::GetPropType( rLocalName
);
787 if( XML_PROP_TYPE_END
!= ePropType
)
789 // if no properties context exist start a new one.
790 if( !m_xPropContext
.is() )
791 m_xPropContext
= new XMLPropertiesTContext_Impl(
792 GetTransformer(), rQName
, ePropType
, m_aStyleFamily
, m_bControlStyle
);
794 m_xPropContext
->SetQNameAndPropType( rQName
, ePropType
);
795 pContext
= m_xPropContext
.get();
800 // if a properties context exist close it
801 if( m_xPropContext
.is() && !m_bPersistent
)
803 m_xPropContext
->Export();
807 pContext
= m_bPersistent
808 ? XMLPersElemContentTContext::CreateChildContext(
809 nPrefix
, rLocalName
, rQName
, rAttrList
)
810 : XMLTransformerContext::CreateChildContext(
811 nPrefix
, rLocalName
, rQName
, rAttrList
);
817 void XMLStyleOASISTContext::StartElement(
818 const Reference
< XAttributeList
>& rAttrList
)
820 XMLTransformerActions
*pActions
=
821 GetTransformer().GetUserDefinedActions( OASIS_STYLE_ACTIONS
);
822 OSL_ENSURE( pActions
, "go no actions" );
824 Reference
< XAttributeList
> xAttrList( rAttrList
);
825 XMLMutableAttributeList
*pMutableAttrList
= 0;
826 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
827 sal_Int16 nFamilyAttr
= -1;
828 m_bControlStyle
= sal_False
;
830 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
832 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
835 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
837 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
838 XMLTransformerActions::const_iterator aIter
=
839 pActions
->find( aKey
);
840 if( !(aIter
== pActions
->end() ) )
842 if( !pMutableAttrList
)
845 new XMLMutableAttributeList( xAttrList
);
846 xAttrList
= pMutableAttrList
;
848 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
849 switch( (*aIter
).second
.m_nActionType
)
851 case XML_ATACTION_STYLE_FAMILY
:
852 if( IsXMLToken( rAttrValue
, XML_GRAPHIC
) )
854 m_aStyleFamily
= GetXMLToken( XML_GRAPHICS
) ;
855 pMutableAttrList
->SetValueByIndex( i
, m_aStyleFamily
);
859 m_aStyleFamily
= rAttrValue
;
861 if( IsXMLToken( rAttrValue
, XML_PARAGRAPH
) )
866 case XML_ATACTION_STYLE_DISPLAY_NAME
:
867 case XML_ATACTION_REMOVE
:
868 pMutableAttrList
->RemoveAttributeByIndex( i
);
872 case XML_ATACTION_DECODE_STYLE_NAME
:
873 m_bControlStyle
= rAttrValue
.startsWith( "ctrl" );
874 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
876 OUString
aAttrValue( rAttrValue
);
877 if( GetTransformer().DecodeStyleName(aAttrValue
) )
878 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
881 case XML_ATACTION_IN2INCH
:
883 OUString
aAttrValue( rAttrValue
);
884 if( XMLTransformerBase::ReplaceSingleInWithInch(
886 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
889 case XML_ATACTION_NEG_PERCENT
:
891 OUString
aAttrValue( rAttrValue
);
892 if( GetTransformer().NegPercent(aAttrValue
) )
893 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
896 case XML_ATACTION_URI_OASIS
:
898 OUString
aAttrValue( rAttrValue
);
899 if( GetTransformer().ConvertURIToOOo( aAttrValue
,
900 static_cast< sal_Bool
>((*aIter
).second
.m_nParam1
)))
901 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
905 OSL_ENSURE( !this, "unknown action" );
911 if( m_bControlStyle
&& nFamilyAttr
!= -1 )
912 pMutableAttrList
->SetValueByIndex( nFamilyAttr
, GetXMLToken( XML_CONTROL
) );
916 XMLPersElemContentTContext::StartElement( xAttrList
);
918 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
922 void XMLStyleOASISTContext::EndElement()
926 XMLPersElemContentTContext::EndElement();
930 // if a properties context exist close it
931 if( m_xPropContext
.is() )
933 m_xPropContext
->Export();
936 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
940 void XMLStyleOASISTContext::Characters( const OUString
& )
942 // element content only:
945 void XMLStyleOASISTContext::ExportContent()
947 if( m_xPropContext
.is() )
948 m_xPropContext
->Export();
949 XMLPersElemContentTContext::ExportContent();
952 sal_Bool
XMLStyleOASISTContext::IsPersistent() const
954 return m_bPersistent
;
957 XMLTransformerActions
*XMLStyleOASISTContext::CreateTransformerActions(
960 XMLTransformerActionInit
*pInit
= 0;
964 case PROP_OASIS_GRAPHIC_ATTR_ACTIONS
:
965 pInit
= aGraphicPropertyOASISAttrActionTable
;
967 case PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS
:
968 pInit
= aDrawingPagePropertyOASISAttrActionTable
;
970 case PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS
:
971 pInit
= aPageLayoutPropertyOASISAttrActionTable
;
973 case PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS
:
974 pInit
= aHeaderFooterPropertyOASISAttrActionTable
;
976 case PROP_OASIS_TEXT_ATTR_ACTIONS
:
977 pInit
= aTextPropertyOASISAttrActionTable
;
979 case PROP_OASIS_PARAGRAPH_ATTR_ACTIONS
:
980 pInit
= aParagraphPropertyOASISAttrActionTable
;
982 case PROP_OASIS_SECTION_ATTR_ACTIONS
:
983 pInit
= aSectionPropertyOASISAttrActionTable
;
985 case PROP_OASIS_TABLE_ATTR_ACTIONS
:
986 pInit
= aTablePropertyOASISAttrActionTable
;
988 case PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS
:
989 pInit
= aTableColumnPropertyOASISAttrActionTable
;
991 case PROP_OASIS_TABLE_ROW_ATTR_ACTIONS
:
992 pInit
= aTableRowPropertyOASISAttrActionTable
;
994 case PROP_OASIS_TABLE_CELL_ATTR_ACTIONS
:
995 pInit
= aTableCellPropertyOASISAttrActionTable
;
997 case PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS
:
998 pInit
= aListLevelPropertyOASISAttrActionTable
;
1000 case PROP_OASIS_CHART_ATTR_ACTIONS
:
1001 pInit
= aChartPropertyOASISAttrActionTable
;
1005 XMLTransformerActions
*pActions
= 0;
1007 pActions
= new XMLTransformerActions( pInit
);
1012 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */