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 <osl/diagnose.h>
26 #include <sax/tools/converter.hxx>
27 #include <xmloff/nmspmap.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include "PropType.hxx"
31 #include "DeepTContext.hxx"
32 #include "ProcAttrTContext.hxx"
33 #include "TransformerBase.hxx"
34 #include "TransformerActions.hxx"
35 #include "ActionMapTypesOASIS.hxx"
36 #include "MutableAttrList.hxx"
37 #include "PropertyActionsOASIS.hxx"
38 #include "StyleOASISTContext.hxx"
39 #include <xmloff/xmluconv.hxx>
41 using namespace ::xmloff::token
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::xml::sax
;
45 static const 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 class XMLPropertiesTContext_Impl
: public XMLPersElemContentTContext
65 ::com::sun::star::uno::Reference
<
66 ::com::sun::star::xml::sax::XAttributeList
> m_xAttrList
;
68 XMLPropType m_ePropType
;
70 OUString m_aStyleFamily
;
74 void SetQNameAndPropType( const OUString
& rQName
,
75 XMLPropType ePropType
)
77 m_ePropType
= ePropType
;
78 XMLTransformerContext::SetQName( rQName
);
83 XMLPropertiesTContext_Impl( XMLTransformerBase
& rTransformer
,
84 const OUString
& rQName
,
86 const OUString
& rStyleFamily
,
87 bool _bControlStyle
= false );
89 virtual ~XMLPropertiesTContext_Impl();
91 virtual void StartElement( const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
) SAL_OVERRIDE
;
93 virtual void Export() SAL_OVERRIDE
;
95 static XMLPropType
GetPropType( const OUString
& rLocalName
);
97 static OUString
MergeUnderline( XMLTokenEnum eUnderline
,
98 bool bBold
, bool bDouble
);
99 static OUString
MergeLineThrough( XMLTokenEnum eLineThrough
,
100 bool bBold
, bool bDouble
,
104 TYPEINIT1( XMLPropertiesTContext_Impl
, XMLPersElemContentTContext
);
106 XMLPropertiesTContext_Impl::XMLPropertiesTContext_Impl(
107 XMLTransformerBase
& rImp
, const OUString
& rQName
, XMLPropType eP
,
108 const OUString
& rStyleFamily
, bool _bControlStyle
) :
109 XMLPersElemContentTContext( rImp
, rQName
, XML_NAMESPACE_STYLE
,
112 m_bControlStyle( _bControlStyle
),
113 m_aStyleFamily( rStyleFamily
)
117 XMLPropertiesTContext_Impl::~XMLPropertiesTContext_Impl()
121 void XMLPropertiesTContext_Impl::StartElement(
122 const Reference
< XAttributeList
>& rAttrList
)
124 XMLTransformerActions
*pActions
= 0;
125 sal_uInt16 nActionMap
= aAttrActionMaps
[m_ePropType
];
126 if( nActionMap
< MAX_OASIS_PROP_ACTIONS
)
128 pActions
= GetTransformer().GetUserDefinedActions( nActionMap
);
129 OSL_ENSURE( pActions
, "go no actions" );
134 XMLMutableAttributeList
*pAttrList
= 0;
135 if( !m_xAttrList
.is() )
137 pAttrList
= new XMLMutableAttributeList();
138 m_xAttrList
= pAttrList
;
143 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() );
146 XMLTokenEnum eUnderline
= XML_TOKEN_END
;
147 bool bBoldUnderline
= false, bDoubleUnderline
= false;
148 XMLTokenEnum eLineThrough
= XML_TOKEN_END
;
149 bool bBoldLineThrough
= false, bDoubleLineThrough
= false;
150 sal_Unicode cLineThroughChar
= 0;
152 bool bIntervalMinorFound
= false;
153 double fIntervalMajor
= 0.0;
154 sal_Int32 nIntervalMinorDivisor
= 0;
157 OUString aOpacityValueRemember
;
158 OUString aImageOpacityValueRemember
;
160 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
161 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
163 const OUString
& rAttrName
= rAttrList
->getNameByIndex( i
);
164 const OUString
& rAttrValue
= rAttrList
->getValueByIndex( i
);
167 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
170 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
171 XMLTransformerActions::const_iterator aIter
=
172 pActions
->find( aKey
);
173 if( !(aIter
== pActions
->end() ) )
175 switch( (*aIter
).second
.m_nActionType
)
177 case XML_ATACTION_REMOVE
:
179 case XML_ATACTION_COPY
:
180 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
182 case XML_ATACTION_RENAME
:
184 OUString
aNewAttrQName(
185 GetTransformer().GetNamespaceMap().GetQNameByKey(
186 (*aIter
).second
.GetQNamePrefixFromParam1(),
187 ::xmloff::token::GetXMLToken(
188 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
189 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
192 case XML_ATACTION_IN2INCH
:
194 OUString
aAttrValue( rAttrValue
);
195 XMLTransformerBase::ReplaceSingleInWithInch(
197 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
200 case XML_ATACTION_INS2INCHS
:
202 OUString
aAttrValue( rAttrValue
);
203 XMLTransformerBase::ReplaceInWithInch(
205 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
208 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
210 OUString
aAttrValue( rAttrValue
);
211 XMLTransformerBase::DecodeStyleName(aAttrValue
);
212 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
215 case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF
:
217 OUString
aNewAttrQName(
218 GetTransformer().GetNamespaceMap().GetQNameByKey(
219 (*aIter
).second
.GetQNamePrefixFromParam1(),
220 ::xmloff::token::GetXMLToken(
221 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
222 OUString
aAttrValue( rAttrValue
);
223 XMLTransformerBase::DecodeStyleName(aAttrValue
);
224 pAttrList
->AddAttribute( aNewAttrQName
, aAttrValue
);
227 case XML_ATACTION_NEG_PERCENT
:
229 OUString
aAttrValue( rAttrValue
);
230 XMLTransformerBase::NegPercent(aAttrValue
);
231 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
234 case XML_ATACTION_RENAME_NEG_PERCENT
:
236 OUString
aNewAttrQName(
237 GetTransformer().GetNamespaceMap().GetQNameByKey(
238 (*aIter
).second
.GetQNamePrefixFromParam1(),
239 ::xmloff::token::GetXMLToken(
240 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
241 OUString
aAttrValue( rAttrValue
);
242 XMLTransformerBase::NegPercent(aAttrValue
);
243 pAttrList
->AddAttribute( aNewAttrQName
, aAttrValue
);
246 case XML_OPTACTION_LINE_MODE
:
249 IsXMLToken( rAttrValue
, XML_SKIP_WHITE_SPACE
);
251 GetTransformer().GetNamespaceMap().GetQNameByKey(
253 GetXMLToken( XML_SCORE_SPACES
) ) );
255 pAttrList
->GetIndexByName( aAttrQName
);
260 const OUString
& rOldValue
=
261 pAttrList
->getValueByIndex( nIndex
);
262 if( !IsXMLToken( rOldValue
, XML_TRUE
) )
264 pAttrList
->SetValueByIndex( nIndex
,
265 GetXMLToken( XML_TRUE
) );
271 OUString
aAttrValue( GetXMLToken( bWordMode
274 pAttrList
->AddAttribute( aAttrQName
, aAttrValue
);
278 case XML_OPTACTION_KEEP_WITH_NEXT
:
280 OUString
aAttrValue( GetXMLToken(
281 IsXMLToken( rAttrValue
, XML_ALWAYS
)
284 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
287 case XML_OPTACTION_UNDERLINE_WIDTH
:
288 if( IsXMLToken( rAttrValue
, XML_BOLD
) )
289 bBoldUnderline
= true;
291 case XML_OPTACTION_UNDERLINE_TYPE
:
292 if( IsXMLToken( rAttrValue
, XML_DOUBLE
) )
293 bDoubleUnderline
= true;
295 case XML_OPTACTION_UNDERLINE_STYLE
:
296 eUnderline
= GetTransformer().GetToken( rAttrValue
);
298 case XML_OPTACTION_LINETHROUGH_WIDTH
:
299 if( IsXMLToken( rAttrValue
, XML_BOLD
) )
300 bBoldLineThrough
= true;
302 case XML_OPTACTION_LINETHROUGH_TYPE
:
303 if( IsXMLToken( rAttrValue
, XML_DOUBLE
) )
304 bDoubleLineThrough
= true;
306 case XML_OPTACTION_LINETHROUGH_STYLE
:
307 eLineThrough
= GetTransformer().GetToken( rAttrValue
);
309 case XML_OPTACTION_LINETHROUGH_TEXT
:
310 if( !rAttrValue
.isEmpty() )
311 cLineThroughChar
= rAttrValue
[0];
313 case XML_OPTACTION_INTERPOLATION
:
316 sal_Int32 nSplineType
= 0;
317 if( IsXMLToken( rAttrValue
, XML_CUBIC_SPLINE
))
319 else if( IsXMLToken( rAttrValue
, XML_B_SPLINE
))
322 pAttrList
->AddAttribute(
323 GetTransformer().GetNamespaceMap().GetQNameByKey(
325 GetXMLToken( XML_SPLINES
)),
326 OUString::number( nSplineType
));
329 case XML_OPTACTION_INTERVAL_MAJOR
:
330 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
331 ::sax::Converter::convertDouble(fIntervalMajor
, rAttrValue
);
333 case XML_OPTACTION_INTERVAL_MINOR_DIVISOR
:
334 ::sax::Converter::convertNumber(nIntervalMinorDivisor
, rAttrValue
);
335 bIntervalMinorFound
= true;
337 case XML_OPTACTION_SYMBOL_TYPE
:
339 // if symbol_type is "named-symbol" the "symbol"
340 // property is set in the action XML_OPTACTION_SYMBOL_NAME
341 sal_Int32 nSymbolType
= 0;
342 if( IsXMLToken( rAttrValue
, XML_NONE
))
344 else if( IsXMLToken( rAttrValue
, XML_AUTOMATIC
))
346 else if( IsXMLToken( rAttrValue
, XML_IMAGE
))
349 if( nSymbolType
< 0 )
350 pAttrList
->AddAttribute(
351 GetTransformer().GetNamespaceMap().GetQNameByKey(
353 GetXMLToken( XML_SYMBOL
)),
354 OUString::number( nSymbolType
));
357 case XML_OPTACTION_SYMBOL_NAME
:
359 // assume "symbol-type" == "named-symbol"
360 sal_Int32 nSymbolType
= -3; // NONE
361 // "square" just has an awkward token-name
362 if( IsXMLToken( rAttrValue
, XML_GRADIENTSTYLE_SQUARE
))
364 else if( IsXMLToken( rAttrValue
, XML_DIAMOND
))
366 else if( IsXMLToken( rAttrValue
, XML_ARROW_DOWN
))
368 else if( IsXMLToken( rAttrValue
, XML_ARROW_UP
))
370 else if( IsXMLToken( rAttrValue
, XML_ARROW_RIGHT
))
372 else if( IsXMLToken( rAttrValue
, XML_ARROW_LEFT
))
374 else if( IsXMLToken( rAttrValue
, XML_BOW_TIE
))
376 else if( IsXMLToken( rAttrValue
, XML_HOURGLASS
))
378 else if( IsXMLToken( rAttrValue
, XML_CIRCLE
))
380 else if( IsXMLToken( rAttrValue
, XML_STAR
))
382 else if( IsXMLToken( rAttrValue
, XML_X
))
384 else if( IsXMLToken( rAttrValue
, XML_PLUS
))
386 else if( IsXMLToken( rAttrValue
, XML_ASTERISK
))
388 else if( IsXMLToken( rAttrValue
, XML_HORIZONTAL_BAR
))
390 else if( IsXMLToken( rAttrValue
, XML_VERTICAL_BAR
))
393 if( nSymbolType
>= 0 )
394 pAttrList
->AddAttribute(
395 GetTransformer().GetNamespaceMap().GetQNameByKey(
397 GetXMLToken( XML_SYMBOL
)),
398 OUString::number( nSymbolType
));
402 case XML_OPTACTION_OPACITY
:
403 aOpacityValueRemember
= rAttrValue
;
404 XMLTransformerBase::NegPercent(aOpacityValueRemember
);
408 case XML_OPTACTION_IMAGE_OPACITY
:
409 aImageOpacityValueRemember
= rAttrValue
;
410 XMLTransformerBase::NegPercent(aImageOpacityValueRemember
);
413 case XML_OPTACTION_KEEP_TOGETHER
:
414 pAttrList
->AddAttribute(
415 GetTransformer().GetNamespaceMap().GetQNameByKey(
416 XML_NAMESPACE_STYLE
,GetXMLToken(XML_BREAK_INSIDE
)),
418 IsXMLToken( rAttrValue
, XML_ALWAYS
)
419 ? XML_COLUMNSPLIT_AVOID
420 : XML_COLUMNSPLIT_AUTO
) );
423 case XML_OPTACTION_CONTROL_TEXT_ALIGN
:
424 if ( m_bControlStyle
)
426 OUString
aNewAttrQName(
427 GetTransformer().GetNamespaceMap().GetQNameByKey(
429 ::xmloff::token::GetXMLToken(
430 XML_TEXT_ALIGN
) ) );
431 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
435 OUString
aNewAttrQName(
436 GetTransformer().GetNamespaceMap().GetQNameByKey(
438 ::xmloff::token::GetXMLToken(
439 XML_TEXT_ALIGN
) ) );
440 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
444 case XML_OPTACTION_DRAW_WRITING_MODE
:
445 if( IsXMLToken( m_aStyleFamily
, XML_GRAPHICS
) )
447 pAttrList
->AddAttribute(
448 GetTransformer().GetNamespaceMap().GetQNameByKey(
450 GetXMLToken( XML_WRITING_MODE
) ), rAttrValue
);
452 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
455 case XML_ATACTION_CAPTION_ESCAPE_OASIS
:
457 OUString
aAttrValue( rAttrValue
);
458 if( aAttrValue
.indexOf( '%' ) != -1 )
460 sal_Int32 nValue
= 0;
461 ::sax::Converter::convertPercent(nValue
, rAttrValue
);
466 ::sax::Converter::convertPercent(aOut
, nValue
);
467 aAttrValue
= aOut
.makeStringAndClear();
472 XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue
);
475 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
479 case XML_ATACTION_DECODE_PROTECT
:
481 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
483 if( rAttrValue
.indexOf( GetXMLToken( XML_SIZE
) ) != -1 )
484 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
486 GetXMLToken( XML_SIZE_PROTECT
)), GetXMLToken( XML_TRUE
) );
488 if( rAttrValue
.indexOf( GetXMLToken( XML_POSITION
) ) != -1 )
489 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
491 GetXMLToken( XML_MOVE_PROTECT
)), GetXMLToken( XML_TRUE
) );
495 case XML_ATACTION_DRAW_MIRROR_OASIS
: // renames style:mirror to draw:mirror and adapts values
497 // keep original for writer graphic objects
498 // Adapts attribute values (#i49139#)
499 OUString aNewAttrValue
;
500 SvXMLTokenEnumerator
aTokenEnum( rAttrValue
);
502 while( aTokenEnum
.getNextToken( aToken
) )
504 if ( !aNewAttrValue
.isEmpty() )
506 aNewAttrValue
+= " ";
509 if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_EVEN
) )
511 aNewAttrValue
+= GetXMLToken( XML_HORIZONTAL_ON_LEFT_PAGES
);
513 else if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_ODD
) )
515 aNewAttrValue
+= GetXMLToken( XML_HORIZONTAL_ON_RIGHT_PAGES
);
519 aNewAttrValue
+= aToken
;
522 pAttrList
->AddAttribute( rAttrName
, aNewAttrValue
);
524 // create old draw:mirror for drawing graphic objects
525 OUString
aAttrValue( GetXMLToken( IsXMLToken( rAttrValue
, XML_HORIZONTAL
) ? XML_TRUE
: XML_FALSE
) );
526 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
528 GetXMLToken( XML_MIRROR
)), aAttrValue
);
531 case XML_ATACTION_GAMMA_OASIS
: // converts percentage value to double
534 ::sax::Converter::convertPercent( nValue
, rAttrValue
);
535 const double fValue
= ((double)nValue
) / 100.0;
536 pAttrList
->AddAttribute( rAttrName
, OUString::number( fValue
) );
539 case XML_ATACTION_OPACITY_FIX
:
542 if( rAttrValue
.indexOf( '%' ) != -1 )
544 ::sax::Converter::convertPercent(nValue
, rAttrValue
);
548 nValue
= sal_Int32( rAttrValue
.toDouble() * 100.0 );
550 nValue
= 100 - nValue
;
553 ::sax::Converter::convertPercent(aOut
, nValue
);
554 pAttrList
->AddAttribute( rAttrName
, aOut
.makeStringAndClear() );
558 OSL_ENSURE( false, "unknown action" );
564 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
567 if( XML_TOKEN_END
!= eUnderline
)
568 pAttrList
->AddAttribute(
569 GetTransformer().GetNamespaceMap().GetQNameByKey(
571 GetXMLToken( XML_TEXT_UNDERLINE
) ),
572 MergeUnderline( eUnderline
, bBoldUnderline
,
573 bDoubleUnderline
) );
574 if( XML_TOKEN_END
!= eLineThrough
)
575 pAttrList
->AddAttribute(
576 GetTransformer().GetNamespaceMap().GetQNameByKey(
578 GetXMLToken( XML_TEXT_CROSSING_OUT
) ),
579 MergeLineThrough( eLineThrough
, bBoldLineThrough
,
580 bDoubleLineThrough
, cLineThroughChar
) );
581 if( bIntervalMinorFound
)
583 double fIntervalMinor
= 0.0;
584 if( nIntervalMinorDivisor
!= 0)
585 fIntervalMinor
= fIntervalMajor
/ static_cast< double >( nIntervalMinorDivisor
);
588 ::sax::Converter::convertDouble( aBuf
, fIntervalMinor
);
589 pAttrList
->AddAttribute(
590 GetTransformer().GetNamespaceMap().GetQNameByKey(
592 GetXMLToken( XML_INTERVAL_MINOR
)),
593 aBuf
.makeStringAndClear());
597 if(!aOpacityValueRemember
.isEmpty() || !aImageOpacityValueRemember
.isEmpty())
599 pAttrList
->AddAttribute(
600 GetTransformer().GetNamespaceMap().GetQNameByKey(
602 GetXMLToken( XML_TRANSPARENCY
) ),
603 !aImageOpacityValueRemember
.isEmpty()
604 ? aImageOpacityValueRemember
: aOpacityValueRemember
);
609 if( !m_xAttrList
.is() )
611 m_xAttrList
= new XMLMutableAttributeList( rAttrList
, true );
615 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
616 ->AppendAttributeList( rAttrList
);
621 void XMLPropertiesTContext_Impl::Export()
623 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
626 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
629 XMLPropType
XMLPropertiesTContext_Impl::GetPropType( const OUString
& rLocalName
)
631 XMLPropType eProp
= XML_PROP_TYPE_END
;
632 if( IsXMLToken( rLocalName
, XML_GRAPHIC_PROPERTIES
) )
633 eProp
= XML_PROP_TYPE_GRAPHIC
;
634 else if( IsXMLToken( rLocalName
, XML_DRAWING_PAGE_PROPERTIES
) )
635 eProp
= XML_PROP_TYPE_DRAWING_PAGE
;
636 else if( IsXMLToken( rLocalName
, XML_PAGE_LAYOUT_PROPERTIES
) )
637 eProp
= XML_PROP_TYPE_PAGE_LAYOUT
;
638 else if( IsXMLToken( rLocalName
, XML_HEADER_FOOTER_PROPERTIES
) )
639 eProp
= XML_PROP_TYPE_HEADER_FOOTER
;
640 else if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) )
641 eProp
= XML_PROP_TYPE_TEXT
;
642 else if( IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
) )
643 eProp
= XML_PROP_TYPE_PARAGRAPH
;
644 else if( IsXMLToken( rLocalName
, XML_RUBY_PROPERTIES
) )
645 eProp
= XML_PROP_TYPE_RUBY
;
646 else if( IsXMLToken( rLocalName
, XML_SECTION_PROPERTIES
) )
647 eProp
= XML_PROP_TYPE_SECTION
;
648 else if( IsXMLToken( rLocalName
, XML_TABLE_PROPERTIES
) )
649 eProp
= XML_PROP_TYPE_TABLE
;
650 else if( IsXMLToken( rLocalName
, XML_TABLE_COLUMN_PROPERTIES
) )
651 eProp
= XML_PROP_TYPE_TABLE_COLUMN
;
652 else if( IsXMLToken( rLocalName
, XML_TABLE_ROW_PROPERTIES
) )
653 eProp
= XML_PROP_TYPE_TABLE_ROW
;
654 else if( IsXMLToken( rLocalName
, XML_TABLE_CELL_PROPERTIES
) )
655 eProp
= XML_PROP_TYPE_TABLE_CELL
;
656 else if( IsXMLToken( rLocalName
, XML_LIST_LEVEL_PROPERTIES
) )
657 eProp
= XML_PROP_TYPE_LIST_LEVEL
;
658 else if( IsXMLToken( rLocalName
, XML_CHART_PROPERTIES
) )
659 eProp
= XML_PROP_TYPE_CHART
;
664 OUString
XMLPropertiesTContext_Impl::MergeUnderline(
665 XMLTokenEnum eUnderline
, bool bBold
, bool bDouble
)
672 eUnderline
= XML_DOUBLE_WAVE
;
675 eUnderline
= XML_DOUBLE
;
685 eUnderline
= XML_BOLD
;
688 eUnderline
= XML_BOLD_DOTTED
;
691 eUnderline
= XML_BOLD_DASH
;
694 eUnderline
= XML_BOLD_LONG_DASH
;
697 eUnderline
= XML_BOLD_DOT_DASH
;
699 case XML_DOT_DOT_DASH
:
700 eUnderline
= XML_BOLD_DOT_DOT_DASH
;
703 eUnderline
= XML_BOLD_WAVE
;
706 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
715 eUnderline
= XML_SINGLE
;
718 eUnderline
= XML_NONE
;
721 OSL_FAIL( "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
726 return GetXMLToken( eUnderline
);
729 OUString
XMLPropertiesTContext_Impl::MergeLineThrough(
730 XMLTokenEnum eLineThrough
, bool bBold
, bool bDouble
,
734 eLineThrough
= c
=='/' ? XML_SLASH
: XML_uX
;
736 eLineThrough
= XML_DOUBLE_LINE
;
738 eLineThrough
= XML_THICK_LINE
;
739 else if( XML_NONE
!= eLineThrough
)
740 eLineThrough
= XML_SINGLE_LINE
;
742 return GetXMLToken( eLineThrough
);
745 TYPEINIT1( XMLStyleOASISTContext
, XMLPersElemContentTContext
);
747 XMLStyleOASISTContext::XMLStyleOASISTContext(XMLTransformerBase
& rImp
,
748 const OUString
& rQName
, bool bPersistent
)
749 : XMLPersElemContentTContext(rImp
, rQName
)
750 , m_bPersistent(bPersistent
)
751 , m_bControlStyle(false)
755 XMLStyleOASISTContext::XMLStyleOASISTContext(
756 XMLTransformerBase
& rImp
, const OUString
& rQName
,
757 sal_uInt16 nPrefix
, ::xmloff::token::XMLTokenEnum eToken
,
759 : XMLPersElemContentTContext(rImp
, rQName
, nPrefix
, eToken
)
760 , m_bPersistent(bPersistent
)
761 , m_bControlStyle(false)
765 XMLStyleOASISTContext::~XMLStyleOASISTContext()
769 XMLTransformerContext
*XMLStyleOASISTContext::CreateChildContext(
771 const OUString
& rLocalName
,
772 const OUString
& rQName
,
773 const Reference
< XAttributeList
>& rAttrList
)
775 XMLTransformerContext
*pContext
= 0;
777 if( XML_NAMESPACE_STYLE
== nPrefix
|| XML_NAMESPACE_LO_EXT
== nPrefix
)
779 XMLPropType ePropType
=
780 XMLPropertiesTContext_Impl::GetPropType( rLocalName
);
781 if( XML_PROP_TYPE_END
!= ePropType
)
783 // if no properties context exist start a new one.
784 if( !m_xPropContext
.is() )
785 m_xPropContext
= new XMLPropertiesTContext_Impl(
786 GetTransformer(), rQName
, ePropType
, m_aStyleFamily
, m_bControlStyle
);
788 m_xPropContext
->SetQNameAndPropType( rQName
, ePropType
);
789 pContext
= m_xPropContext
.get();
794 // if a properties context exist close it
795 if( m_xPropContext
.is() && !m_bPersistent
)
797 m_xPropContext
->Export();
801 pContext
= m_bPersistent
802 ? XMLPersElemContentTContext::CreateChildContext(
803 nPrefix
, rLocalName
, rQName
, rAttrList
)
804 : XMLTransformerContext::CreateChildContext(
805 nPrefix
, rLocalName
, rQName
, rAttrList
);
811 void XMLStyleOASISTContext::StartElement(
812 const Reference
< XAttributeList
>& rAttrList
)
814 XMLTransformerActions
*pActions
=
815 GetTransformer().GetUserDefinedActions( OASIS_STYLE_ACTIONS
);
816 OSL_ENSURE( pActions
, "go no actions" );
818 Reference
< XAttributeList
> xAttrList( rAttrList
);
819 XMLMutableAttributeList
*pMutableAttrList
= 0;
820 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
821 sal_Int16 nFamilyAttr
= -1;
822 m_bControlStyle
= false;
824 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
826 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
829 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
831 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
832 XMLTransformerActions::const_iterator aIter
=
833 pActions
->find( aKey
);
834 if( !(aIter
== pActions
->end() ) )
836 if( !pMutableAttrList
)
839 new XMLMutableAttributeList( xAttrList
);
840 xAttrList
= pMutableAttrList
;
842 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
843 switch( (*aIter
).second
.m_nActionType
)
845 case XML_ATACTION_STYLE_FAMILY
:
846 if( IsXMLToken( rAttrValue
, XML_GRAPHIC
) )
848 m_aStyleFamily
= GetXMLToken( XML_GRAPHICS
) ;
849 pMutableAttrList
->SetValueByIndex( i
, m_aStyleFamily
);
853 m_aStyleFamily
= rAttrValue
;
855 if( IsXMLToken( rAttrValue
, XML_PARAGRAPH
) )
860 case XML_ATACTION_STYLE_DISPLAY_NAME
:
861 case XML_ATACTION_REMOVE
:
862 pMutableAttrList
->RemoveAttributeByIndex( i
);
866 case XML_ATACTION_DECODE_STYLE_NAME
:
867 m_bControlStyle
= rAttrValue
.startsWith( "ctrl" );
869 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
871 OUString
aAttrValue( rAttrValue
);
872 if( XMLTransformerBase::DecodeStyleName(aAttrValue
) )
873 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
876 case XML_ATACTION_IN2INCH
:
878 OUString
aAttrValue( rAttrValue
);
879 if( XMLTransformerBase::ReplaceSingleInWithInch(
881 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
884 case XML_ATACTION_NEG_PERCENT
:
886 OUString
aAttrValue( rAttrValue
);
887 if( XMLTransformerBase::NegPercent(aAttrValue
) )
888 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
891 case XML_ATACTION_URI_OASIS
:
893 OUString
aAttrValue( rAttrValue
);
894 if( GetTransformer().ConvertURIToOOo( aAttrValue
,
895 static_cast< bool >((*aIter
).second
.m_nParam1
)))
896 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
900 OSL_ENSURE( false, "unknown action" );
906 if( m_bControlStyle
&& nFamilyAttr
!= -1 )
907 pMutableAttrList
->SetValueByIndex( nFamilyAttr
, GetXMLToken( XML_CONTROL
) );
910 XMLPersElemContentTContext::StartElement( xAttrList
);
912 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
916 void XMLStyleOASISTContext::EndElement()
920 XMLPersElemContentTContext::EndElement();
924 // if a properties context exist close it
925 if( m_xPropContext
.is() )
927 m_xPropContext
->Export();
930 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
934 void XMLStyleOASISTContext::Characters( const OUString
& )
936 // element content only:
939 void XMLStyleOASISTContext::ExportContent()
941 if( m_xPropContext
.is() )
942 m_xPropContext
->Export();
943 XMLPersElemContentTContext::ExportContent();
946 bool XMLStyleOASISTContext::IsPersistent() const
948 return m_bPersistent
;
951 XMLTransformerActions
*XMLStyleOASISTContext::CreateTransformerActions(
954 XMLTransformerActionInit
*pInit
= 0;
958 case PROP_OASIS_GRAPHIC_ATTR_ACTIONS
:
959 pInit
= aGraphicPropertyOASISAttrActionTable
;
961 case PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS
:
962 pInit
= aDrawingPagePropertyOASISAttrActionTable
;
964 case PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS
:
965 pInit
= aPageLayoutPropertyOASISAttrActionTable
;
967 case PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS
:
968 pInit
= aHeaderFooterPropertyOASISAttrActionTable
;
970 case PROP_OASIS_TEXT_ATTR_ACTIONS
:
971 pInit
= aTextPropertyOASISAttrActionTable
;
973 case PROP_OASIS_PARAGRAPH_ATTR_ACTIONS
:
974 pInit
= aParagraphPropertyOASISAttrActionTable
;
976 case PROP_OASIS_SECTION_ATTR_ACTIONS
:
977 pInit
= aSectionPropertyOASISAttrActionTable
;
979 case PROP_OASIS_TABLE_ATTR_ACTIONS
:
980 pInit
= aTablePropertyOASISAttrActionTable
;
982 case PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS
:
983 pInit
= aTableColumnPropertyOASISAttrActionTable
;
985 case PROP_OASIS_TABLE_ROW_ATTR_ACTIONS
:
986 pInit
= aTableRowPropertyOASISAttrActionTable
;
988 case PROP_OASIS_TABLE_CELL_ATTR_ACTIONS
:
989 pInit
= aTableCellPropertyOASISAttrActionTable
;
991 case PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS
:
992 pInit
= aListLevelPropertyOASISAttrActionTable
;
994 case PROP_OASIS_CHART_ATTR_ACTIONS
:
995 pInit
= aChartPropertyOASISAttrActionTable
;
999 XMLTransformerActions
*pActions
= 0;
1001 pActions
= new XMLTransformerActions( pInit
);
1006 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */