1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: StyleOASISTContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/xml/sax/SAXParseException.hpp>
34 #include <com/sun/star/xml/sax/SAXException.hpp>
35 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
36 #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 #include <rtl/ustrbuf.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include "xmlnmspe.hxx"
41 #include "PropType.hxx"
42 #include "DeepTContext.hxx"
43 #include "ProcAttrTContext.hxx"
44 #ifndef _XMLOFF_TRANSFOERMERBASE_HXX
45 #include "TransformerBase.hxx"
47 #include "TransformerActions.hxx"
48 #include "ActionMapTypesOASIS.hxx"
49 #include "MutableAttrList.hxx"
50 #include "PropertyActionsOASIS.hxx"
51 #include "StyleOASISTContext.hxx"
52 #include <xmloff/xmluconv.hxx>
53 #include <rtl/ustrbuf.hxx>
55 using ::rtl::OUString
;
56 using namespace ::xmloff::token
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::xml::sax
;
59 //------------------------------------------------------------------------------
61 static sal_uInt16 aAttrActionMaps
[XML_PROP_TYPE_END
] =
63 PROP_OASIS_GRAPHIC_ATTR_ACTIONS
,
64 PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS
, // DRAWING_PAGE
65 PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS
,
66 PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS
,
67 PROP_OASIS_TEXT_ATTR_ACTIONS
,
68 PROP_OASIS_PARAGRAPH_ATTR_ACTIONS
,
69 MAX_OASIS_PROP_ACTIONS
, // RUBY
70 PROP_OASIS_SECTION_ATTR_ACTIONS
,
71 PROP_OASIS_TABLE_ATTR_ACTIONS
,
72 PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS
,
73 PROP_OASIS_TABLE_ROW_ATTR_ACTIONS
,
74 PROP_OASIS_TABLE_CELL_ATTR_ACTIONS
,
75 PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS
,
76 PROP_OASIS_CHART_ATTR_ACTIONS
79 //------------------------------------------------------------------------------
81 class XMLPropertiesTContext_Impl
: public XMLPersElemContentTContext
83 ::com::sun::star::uno::Reference
<
84 ::com::sun::star::xml::sax::XAttributeList
> m_xAttrList
;
86 XMLPropType m_ePropType
;
87 sal_Bool m_bControlStyle
;
88 ::rtl::OUString m_aStyleFamily
;
92 void SetQNameAndPropType( const ::rtl::OUString
& rQName
,
93 XMLPropType ePropType
)
95 m_ePropType
= ePropType
;
96 XMLTransformerContext::SetQName( rQName
);
101 XMLPropertiesTContext_Impl( XMLTransformerBase
& rTransformer
,
102 const ::rtl::OUString
& rQName
,
104 const ::rtl::OUString
& rStyleFamily
,
105 sal_Bool _bControlStyle
= sal_False
);
107 virtual ~XMLPropertiesTContext_Impl();
109 virtual void StartElement( const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
);
111 virtual void Export();
113 static XMLPropType
GetPropType( const OUString
& rLocalName
);
115 static OUString
MergeUnderline( XMLTokenEnum eUnderline
,
116 sal_Bool bBold
, sal_Bool bDouble
);
117 static OUString
MergeLineThrough( XMLTokenEnum eLineThrough
,
118 sal_Bool bBold
, sal_Bool bDouble
,
122 TYPEINIT1( XMLPropertiesTContext_Impl
, XMLPersElemContentTContext
);
124 XMLPropertiesTContext_Impl::XMLPropertiesTContext_Impl(
125 XMLTransformerBase
& rImp
, const OUString
& rQName
, XMLPropType eP
,
126 const ::rtl::OUString
& rStyleFamily
, sal_Bool _bControlStyle
) :
127 XMLPersElemContentTContext( rImp
, rQName
, XML_NAMESPACE_STYLE
,
130 m_bControlStyle( _bControlStyle
),
131 m_aStyleFamily( rStyleFamily
)
135 XMLPropertiesTContext_Impl::~XMLPropertiesTContext_Impl()
139 void XMLPropertiesTContext_Impl::StartElement(
140 const Reference
< XAttributeList
>& rAttrList
)
142 XMLTransformerActions
*pActions
= 0;
143 sal_uInt16 nActionMap
= aAttrActionMaps
[m_ePropType
];
144 if( nActionMap
< MAX_OASIS_PROP_ACTIONS
)
146 pActions
= GetTransformer().GetUserDefinedActions( nActionMap
);
147 OSL_ENSURE( pActions
, "go no actions" );
152 XMLMutableAttributeList
*pAttrList
= 0;
153 if( !m_xAttrList
.is() )
155 pAttrList
= new XMLMutableAttributeList();
156 m_xAttrList
= pAttrList
;
161 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() );
164 XMLTokenEnum eUnderline
= XML_TOKEN_END
;
165 sal_Bool bBoldUnderline
= sal_False
, bDoubleUnderline
= sal_False
;
166 XMLTokenEnum eLineThrough
= XML_TOKEN_END
;
167 sal_Bool bBoldLineThrough
= sal_False
, bDoubleLineThrough
= sal_False
;
168 sal_Unicode cLineThroughChar
= 0;
170 bool bIntervalMinorFound
= false;
171 double fIntervalMajor
= 0.0;
172 sal_Int32 nIntervalMinorDivisor
= 0;
175 OUString aOpacityValueRemember
;
176 OUString aImageOpacityValueRemember
;
178 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
179 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
181 const OUString
& rAttrName
= rAttrList
->getNameByIndex( i
);
182 const OUString
& rAttrValue
= rAttrList
->getValueByIndex( i
);
185 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
188 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
189 XMLTransformerActions::const_iterator aIter
=
190 pActions
->find( aKey
);
191 if( !(aIter
== pActions
->end() ) )
193 switch( (*aIter
).second
.m_nActionType
)
195 case XML_ATACTION_REMOVE
:
197 case XML_ATACTION_COPY
:
198 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
200 case XML_ATACTION_RENAME
:
202 OUString
aNewAttrQName(
203 GetTransformer().GetNamespaceMap().GetQNameByKey(
204 (*aIter
).second
.GetQNamePrefixFromParam1(),
205 ::xmloff::token::GetXMLToken(
206 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
207 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
210 case XML_ATACTION_IN2INCH
:
212 OUString
aAttrValue( rAttrValue
);
213 XMLTransformerBase::ReplaceSingleInWithInch(
215 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
218 case XML_ATACTION_INS2INCHS
:
220 OUString
aAttrValue( rAttrValue
);
221 XMLTransformerBase::ReplaceInWithInch(
223 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
226 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
228 OUString
aAttrValue( rAttrValue
);
229 GetTransformer().DecodeStyleName(aAttrValue
);
230 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
233 case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF
:
235 OUString
aNewAttrQName(
236 GetTransformer().GetNamespaceMap().GetQNameByKey(
237 (*aIter
).second
.GetQNamePrefixFromParam1(),
238 ::xmloff::token::GetXMLToken(
239 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
240 OUString
aAttrValue( rAttrValue
);
241 GetTransformer().DecodeStyleName(aAttrValue
);
242 pAttrList
->AddAttribute( aNewAttrQName
, aAttrValue
);
245 case XML_ATACTION_NEG_PERCENT
:
247 OUString
aAttrValue( rAttrValue
);
248 GetTransformer().NegPercent(aAttrValue
);
249 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
252 case XML_ATACTION_RENAME_NEG_PERCENT
:
254 OUString
aNewAttrQName(
255 GetTransformer().GetNamespaceMap().GetQNameByKey(
256 (*aIter
).second
.GetQNamePrefixFromParam1(),
257 ::xmloff::token::GetXMLToken(
258 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
259 OUString
aAttrValue( rAttrValue
);
260 GetTransformer().NegPercent(aAttrValue
);
261 pAttrList
->AddAttribute( aNewAttrQName
, aAttrValue
);
264 case XML_OPTACTION_LINE_MODE
:
267 IsXMLToken( rAttrValue
, XML_SKIP_WHITE_SPACE
);
269 GetTransformer().GetNamespaceMap().GetQNameByKey(
271 GetXMLToken( XML_SCORE_SPACES
) ) );
273 pAttrList
->GetIndexByName( aAttrQName
);
278 const OUString
& rOldValue
=
279 pAttrList
->getValueByIndex( nIndex
);
280 if( !IsXMLToken( rOldValue
, XML_TRUE
) )
282 pAttrList
->SetValueByIndex( nIndex
,
283 GetXMLToken( XML_TRUE
) );
289 OUString
aAttrValue( GetXMLToken( bWordMode
292 pAttrList
->AddAttribute( aAttrQName
, aAttrValue
);
296 case XML_OPTACTION_KEEP_WITH_NEXT
:
298 OUString
aAttrValue( GetXMLToken(
299 IsXMLToken( rAttrValue
, XML_ALWAYS
)
302 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
305 case XML_OPTACTION_UNDERLINE_WIDTH
:
306 if( IsXMLToken( rAttrValue
, XML_BOLD
) )
307 bBoldUnderline
= sal_True
;
309 case XML_OPTACTION_UNDERLINE_TYPE
:
310 if( IsXMLToken( rAttrValue
, XML_DOUBLE
) )
311 bDoubleUnderline
= sal_True
;
313 case XML_OPTACTION_UNDERLINE_STYLE
:
314 eUnderline
= GetTransformer().GetToken( rAttrValue
);
316 case XML_OPTACTION_LINETHROUGH_WIDTH
:
317 if( IsXMLToken( rAttrValue
, XML_BOLD
) )
318 bBoldLineThrough
= sal_True
;
320 case XML_OPTACTION_LINETHROUGH_TYPE
:
321 if( IsXMLToken( rAttrValue
, XML_DOUBLE
) )
322 bDoubleLineThrough
= sal_True
;
324 case XML_OPTACTION_LINETHROUGH_STYLE
:
325 eLineThrough
= GetTransformer().GetToken( rAttrValue
);
327 case XML_OPTACTION_LINETHROUGH_TEXT
:
328 if( rAttrValue
.getLength() )
329 cLineThroughChar
= rAttrValue
[0];
331 case XML_OPTACTION_INTERPOLATION
:
334 sal_Int32 nSplineType
= 0;
335 if( IsXMLToken( rAttrValue
, XML_CUBIC_SPLINE
))
337 else if( IsXMLToken( rAttrValue
, XML_B_SPLINE
))
340 pAttrList
->AddAttribute(
341 GetTransformer().GetNamespaceMap().GetQNameByKey(
343 GetXMLToken( XML_SPLINES
)),
344 OUString::valueOf( nSplineType
));
347 case XML_OPTACTION_INTERVAL_MAJOR
:
348 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
349 SvXMLUnitConverter::convertDouble( fIntervalMajor
, rAttrValue
);
351 case XML_OPTACTION_INTERVAL_MINOR_DIVISOR
:
352 SvXMLUnitConverter::convertNumber( nIntervalMinorDivisor
, rAttrValue
);
353 bIntervalMinorFound
= true;
355 case XML_OPTACTION_SYMBOL_TYPE
:
357 // if symbol_type is "named-symbol" the "symbol"
358 // property is set in the action XML_OPTACTION_SYMBOL_NAME
359 sal_Int32 nSymbolType
= 0;
360 if( IsXMLToken( rAttrValue
, XML_NONE
))
362 else if( IsXMLToken( rAttrValue
, XML_AUTOMATIC
))
364 else if( IsXMLToken( rAttrValue
, XML_IMAGE
))
367 if( nSymbolType
< 0 )
368 pAttrList
->AddAttribute(
369 GetTransformer().GetNamespaceMap().GetQNameByKey(
371 GetXMLToken( XML_SYMBOL
)),
372 OUString::valueOf( nSymbolType
));
375 case XML_OPTACTION_SYMBOL_NAME
:
377 // assume "symbol-type" == "named-symbol"
378 sal_Int32 nSymbolType
= -3; // NONE
379 // "square" just has an awkward token-name
380 if( IsXMLToken( rAttrValue
, XML_GRADIENTSTYLE_SQUARE
))
382 else if( IsXMLToken( rAttrValue
, XML_DIAMOND
))
384 else if( IsXMLToken( rAttrValue
, XML_ARROW_DOWN
))
386 else if( IsXMLToken( rAttrValue
, XML_ARROW_UP
))
388 else if( IsXMLToken( rAttrValue
, XML_ARROW_RIGHT
))
390 else if( IsXMLToken( rAttrValue
, XML_ARROW_LEFT
))
392 else if( IsXMLToken( rAttrValue
, XML_BOW_TIE
))
394 else if( IsXMLToken( rAttrValue
, XML_HOURGLASS
))
397 if( nSymbolType
>= 0 )
398 pAttrList
->AddAttribute(
399 GetTransformer().GetNamespaceMap().GetQNameByKey(
401 GetXMLToken( XML_SYMBOL
)),
402 OUString::valueOf( nSymbolType
));
406 case XML_OPTACTION_OPACITY
:
407 aOpacityValueRemember
= rAttrValue
;
408 GetTransformer().NegPercent(aOpacityValueRemember
);
412 case XML_OPTACTION_IMAGE_OPACITY
:
413 aImageOpacityValueRemember
= rAttrValue
;
414 GetTransformer().NegPercent(aImageOpacityValueRemember
);
417 case XML_OPTACTION_KEEP_TOGETHER
:
418 pAttrList
->AddAttribute(
419 GetTransformer().GetNamespaceMap().GetQNameByKey(
420 XML_NAMESPACE_STYLE
,GetXMLToken(XML_BREAK_INSIDE
)),
422 IsXMLToken( rAttrValue
, XML_ALWAYS
)
423 ? XML_COLUMNSPLIT_AVOID
424 : XML_COLUMNSPLIT_AUTO
) );
427 case XML_OPTACTION_CONTROL_TEXT_ALIGN
:
428 if ( m_bControlStyle
)
430 OUString
aNewAttrQName(
431 GetTransformer().GetNamespaceMap().GetQNameByKey(
433 ::xmloff::token::GetXMLToken(
434 XML_TEXT_ALIGN
) ) );
435 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
439 OUString
aNewAttrQName(
440 GetTransformer().GetNamespaceMap().GetQNameByKey(
442 ::xmloff::token::GetXMLToken(
443 XML_TEXT_ALIGN
) ) );
444 pAttrList
->AddAttribute( aNewAttrQName
, rAttrValue
);
448 case XML_OPTACTION_DRAW_WRITING_MODE
:
449 if( IsXMLToken( m_aStyleFamily
, XML_GRAPHICS
) )
451 pAttrList
->AddAttribute(
452 GetTransformer().GetNamespaceMap().GetQNameByKey(
454 GetXMLToken( XML_WRITING_MODE
) ), rAttrValue
);
456 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
459 case XML_ATACTION_CAPTION_ESCAPE_OASIS
:
461 OUString
aAttrValue( rAttrValue
);
462 if( aAttrValue
.indexOf( sal_Unicode('%') ) != -1 )
464 sal_Int32 nValue
= 0;
465 SvXMLUnitConverter::convertPercent( nValue
, rAttrValue
);
469 rtl::OUStringBuffer aOut
;
470 SvXMLUnitConverter::convertPercent( aOut
, nValue
);
471 aAttrValue
= aOut
.makeStringAndClear();
476 XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue
);
479 pAttrList
->AddAttribute( rAttrName
, aAttrValue
);
483 case XML_ATACTION_DECODE_PROTECT
:
485 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
487 if( rAttrValue
.indexOf( GetXMLToken( XML_SIZE
) ) != -1 )
488 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
490 GetXMLToken( XML_SIZE_PROTECT
)), GetXMLToken( XML_TRUE
) );
492 if( rAttrValue
.indexOf( GetXMLToken( XML_POSITION
) ) != -1 )
493 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
495 GetXMLToken( XML_MOVE_PROTECT
)), GetXMLToken( XML_TRUE
) );
499 case XML_ATACTION_DRAW_MIRROR_OASIS
: // renames style:mirror to draw:mirror and adapts values
501 // keep original for writer graphic objects
502 // --> OD 2005-05-12 #i49139# - adapts attribute values,
503 OUString aNewAttrValue
;
504 SvXMLTokenEnumerator
aTokenEnum( rAttrValue
);
506 while( aTokenEnum
.getNextToken( aToken
) )
508 if ( aNewAttrValue
.getLength() > 0 )
510 aNewAttrValue
+= rtl::OUString::createFromAscii( " " );
513 if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_EVEN
) )
515 aNewAttrValue
+= GetXMLToken( XML_HORIZONTAL_ON_LEFT_PAGES
);
517 else if ( IsXMLToken( aToken
, XML_HORIZONTAL_ON_ODD
) )
519 aNewAttrValue
+= GetXMLToken( XML_HORIZONTAL_ON_RIGHT_PAGES
);
523 aNewAttrValue
+= aToken
;
526 pAttrList
->AddAttribute( rAttrName
, aNewAttrValue
);
529 // create old draw:mirror for drawing graphic objects
530 OUString
aAttrValue( GetXMLToken( IsXMLToken( rAttrValue
, XML_HORIZONTAL
) ? XML_TRUE
: XML_FALSE
) );
531 pAttrList
->AddAttribute( GetTransformer().GetNamespaceMap().GetQNameByKey(
533 GetXMLToken( XML_MIRROR
)), aAttrValue
);
536 case XML_ATACTION_GAMMA_OASIS
: // converts percentage value to double
539 SvXMLUnitConverter::convertPercent( nValue
, rAttrValue
);
540 const double fValue
= ((double)nValue
) / 100.0;
541 pAttrList
->AddAttribute( rAttrName
, OUString::valueOf( fValue
) );
544 case XML_ATACTION_OPACITY_FIX
:
547 if( rAttrValue
.indexOf( sal_Unicode('%') ) != -1 )
549 SvXMLUnitConverter::convertPercent( nValue
, rAttrValue
);
553 nValue
= sal_Int32( rAttrValue
.toDouble() * 100.0 );
555 nValue
= 100 - nValue
;
557 rtl::OUStringBuffer aOut
;
558 SvXMLUnitConverter::convertPercent( aOut
, nValue
);
559 pAttrList
->AddAttribute( rAttrName
, aOut
.makeStringAndClear() );
563 OSL_ENSURE( !this, "unknown action" );
569 pAttrList
->AddAttribute( rAttrName
, rAttrValue
);
572 if( XML_TOKEN_END
!= eUnderline
)
573 pAttrList
->AddAttribute(
574 GetTransformer().GetNamespaceMap().GetQNameByKey(
576 GetXMLToken( XML_TEXT_UNDERLINE
) ),
577 MergeUnderline( eUnderline
, bBoldUnderline
,
578 bDoubleUnderline
) );
579 if( XML_TOKEN_END
!= eLineThrough
)
580 pAttrList
->AddAttribute(
581 GetTransformer().GetNamespaceMap().GetQNameByKey(
583 GetXMLToken( XML_TEXT_CROSSING_OUT
) ),
584 MergeLineThrough( eLineThrough
, bBoldLineThrough
,
585 bDoubleLineThrough
, cLineThroughChar
) );
586 if( bIntervalMinorFound
)
588 double fIntervalMinor
= 0.0;
589 if( nIntervalMinorDivisor
!= 0)
590 fIntervalMinor
= fIntervalMajor
/ static_cast< double >( nIntervalMinorDivisor
);
592 ::rtl::OUStringBuffer aBuf
;
593 SvXMLUnitConverter::convertDouble( aBuf
, fIntervalMinor
);
594 pAttrList
->AddAttribute(
595 GetTransformer().GetNamespaceMap().GetQNameByKey(
597 GetXMLToken( XML_INTERVAL_MINOR
)),
598 aBuf
.makeStringAndClear());
602 if(aOpacityValueRemember
.getLength() || aImageOpacityValueRemember
.getLength())
604 pAttrList
->AddAttribute(
605 GetTransformer().GetNamespaceMap().GetQNameByKey(
607 GetXMLToken( XML_TRANSPARENCY
) ),
608 aImageOpacityValueRemember
.getLength()
609 ? aImageOpacityValueRemember
: aOpacityValueRemember
);
614 if( !m_xAttrList
.is() )
616 m_xAttrList
= new XMLMutableAttributeList( rAttrList
, sal_True
);
620 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
621 ->AppendAttributeList( rAttrList
);
626 void XMLPropertiesTContext_Impl::Export()
628 OUString
aNewQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
630 ::xmloff::token::GetXMLToken( XML_PROPERTIES
) ) );
631 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
634 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
637 XMLPropType
XMLPropertiesTContext_Impl::GetPropType( const OUString
& rLocalName
)
639 XMLPropType eProp
= XML_PROP_TYPE_END
;
640 if( IsXMLToken( rLocalName
, XML_GRAPHIC_PROPERTIES
) )
641 eProp
= XML_PROP_TYPE_GRAPHIC
;
642 else if( IsXMLToken( rLocalName
, XML_DRAWING_PAGE_PROPERTIES
) )
643 eProp
= XML_PROP_TYPE_DRAWING_PAGE
;
644 else if( IsXMLToken( rLocalName
, XML_PAGE_LAYOUT_PROPERTIES
) )
645 eProp
= XML_PROP_TYPE_PAGE_LAYOUT
;
646 else if( IsXMLToken( rLocalName
, XML_HEADER_FOOTER_PROPERTIES
) )
647 eProp
= XML_PROP_TYPE_HEADER_FOOTER
;
648 else if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) )
649 eProp
= XML_PROP_TYPE_TEXT
;
650 else if( IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
) )
651 eProp
= XML_PROP_TYPE_PARAGRAPH
;
652 else if( IsXMLToken( rLocalName
, XML_RUBY_PROPERTIES
) )
653 eProp
= XML_PROP_TYPE_RUBY
;
654 else if( IsXMLToken( rLocalName
, XML_SECTION_PROPERTIES
) )
655 eProp
= XML_PROP_TYPE_SECTION
;
656 else if( IsXMLToken( rLocalName
, XML_TABLE_PROPERTIES
) )
657 eProp
= XML_PROP_TYPE_TABLE
;
658 else if( IsXMLToken( rLocalName
, XML_TABLE_COLUMN_PROPERTIES
) )
659 eProp
= XML_PROP_TYPE_TABLE_COLUMN
;
660 else if( IsXMLToken( rLocalName
, XML_TABLE_ROW_PROPERTIES
) )
661 eProp
= XML_PROP_TYPE_TABLE_ROW
;
662 else if( IsXMLToken( rLocalName
, XML_TABLE_CELL_PROPERTIES
) )
663 eProp
= XML_PROP_TYPE_TABLE_CELL
;
664 else if( IsXMLToken( rLocalName
, XML_LIST_LEVEL_PROPERTIES
) )
665 eProp
= XML_PROP_TYPE_LIST_LEVEL
;
666 else if( IsXMLToken( rLocalName
, XML_CHART_PROPERTIES
) )
667 eProp
= XML_PROP_TYPE_CHART
;
672 OUString
XMLPropertiesTContext_Impl::MergeUnderline(
673 XMLTokenEnum eUnderline
, sal_Bool bBold
, sal_Bool bDouble
)
680 eUnderline
= XML_DOUBLE_WAVE
;
683 eUnderline
= XML_DOUBLE
;
693 eUnderline
= XML_BOLD
;
696 eUnderline
= XML_BOLD_DOTTED
;
699 eUnderline
= XML_BOLD_DASH
;
702 eUnderline
= XML_BOLD_LONG_DASH
;
705 eUnderline
= XML_BOLD_DOT_DASH
;
707 case XML_DOT_DOT_DASH
:
708 eUnderline
= XML_BOLD_DOT_DOT_DASH
;
711 eUnderline
= XML_BOLD_WAVE
;
714 OSL_ENSURE( false, "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
723 eUnderline
= XML_SINGLE
;
726 eUnderline
= XML_NONE
;
729 OSL_ENSURE( false, "xmloff::XMLPropertiesTContext_Impl::MergeUnderline(), missing underline case!" );
734 return GetXMLToken( eUnderline
);
737 OUString
XMLPropertiesTContext_Impl::MergeLineThrough(
738 XMLTokenEnum eLineThrough
, sal_Bool bBold
, sal_Bool bDouble
,
742 eLineThrough
= c
=='/' ? XML_SLASH
: XML_uX
;
744 eLineThrough
= XML_DOUBLE_LINE
;
746 eLineThrough
= XML_THICK_LINE
;
747 else if( XML_NONE
!= eLineThrough
)
748 eLineThrough
= XML_SINGLE_LINE
;
750 return GetXMLToken( eLineThrough
);
753 //------------------------------------------------------------------------------
755 TYPEINIT1( XMLStyleOASISTContext
, XMLPersElemContentTContext
);
757 XMLStyleOASISTContext::XMLStyleOASISTContext( XMLTransformerBase
& rImp
,
758 const OUString
& rQName
,
759 sal_Bool bPersistent
) :
760 XMLPersElemContentTContext ( rImp
, rQName
),
761 m_bPersistent( bPersistent
),
762 m_bControlStyle( false )
766 XMLStyleOASISTContext::XMLStyleOASISTContext(
767 XMLTransformerBase
& rImp
,
768 const OUString
& rQName
,
770 ::xmloff::token::XMLTokenEnum eToken
,
771 sal_Bool bPersistent
) :
772 XMLPersElemContentTContext( rImp
, rQName
, nPrefix
, eToken
),
773 m_bPersistent( bPersistent
)
777 XMLStyleOASISTContext::~XMLStyleOASISTContext()
781 XMLTransformerContext
*XMLStyleOASISTContext::CreateChildContext(
783 const OUString
& rLocalName
,
784 const OUString
& rQName
,
785 const Reference
< XAttributeList
>& rAttrList
)
787 XMLTransformerContext
*pContext
= 0;
789 if( XML_NAMESPACE_STYLE
== nPrefix
)
791 XMLPropType ePropType
=
792 XMLPropertiesTContext_Impl::GetPropType( rLocalName
);
793 if( XML_PROP_TYPE_END
!= ePropType
)
795 // if no properties context exist start a new one.
796 if( !m_xPropContext
.is() )
797 m_xPropContext
= new XMLPropertiesTContext_Impl(
798 GetTransformer(), rQName
, ePropType
, m_aStyleFamily
, m_bControlStyle
);
800 m_xPropContext
->SetQNameAndPropType( rQName
, ePropType
);
801 pContext
= m_xPropContext
.get();
806 // if a properties context exist close it
807 if( m_xPropContext
.is() && !m_bPersistent
)
809 m_xPropContext
->Export();
813 pContext
= m_bPersistent
814 ? XMLPersElemContentTContext::CreateChildContext(
815 nPrefix
, rLocalName
, rQName
, rAttrList
)
816 : XMLTransformerContext::CreateChildContext(
817 nPrefix
, rLocalName
, rQName
, rAttrList
);
823 void XMLStyleOASISTContext::StartElement(
824 const Reference
< XAttributeList
>& rAttrList
)
826 XMLTransformerActions
*pActions
=
827 GetTransformer().GetUserDefinedActions( OASIS_STYLE_ACTIONS
);
828 OSL_ENSURE( pActions
, "go no actions" );
830 Reference
< XAttributeList
> xAttrList( rAttrList
);
831 XMLMutableAttributeList
*pMutableAttrList
= 0;
832 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
833 sal_Int16 nFamilyAttr
= -1;
834 m_bControlStyle
= sal_False
;
836 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
838 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
841 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
843 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
844 XMLTransformerActions::const_iterator aIter
=
845 pActions
->find( aKey
);
846 if( !(aIter
== pActions
->end() ) )
848 if( !pMutableAttrList
)
851 new XMLMutableAttributeList( xAttrList
);
852 xAttrList
= pMutableAttrList
;
854 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
855 switch( (*aIter
).second
.m_nActionType
)
857 case XML_ATACTION_STYLE_FAMILY
:
858 if( IsXMLToken( rAttrValue
, XML_GRAPHIC
) )
860 m_aStyleFamily
= GetXMLToken( XML_GRAPHICS
) ;
861 pMutableAttrList
->SetValueByIndex( i
, m_aStyleFamily
);
865 m_aStyleFamily
= rAttrValue
;
867 if( IsXMLToken( rAttrValue
, XML_PARAGRAPH
) )
872 case XML_ATACTION_STYLE_DISPLAY_NAME
:
873 case XML_ATACTION_REMOVE
:
874 pMutableAttrList
->RemoveAttributeByIndex( i
);
878 case XML_ATACTION_DECODE_STYLE_NAME
:
879 m_bControlStyle
= 0 == rAttrValue
.compareToAscii( "ctrl", 4 );
880 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
882 OUString
aAttrValue( rAttrValue
);
883 if( GetTransformer().DecodeStyleName(aAttrValue
) )
884 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
887 case XML_ATACTION_IN2INCH
:
889 OUString
aAttrValue( rAttrValue
);
890 if( XMLTransformerBase::ReplaceSingleInWithInch(
892 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
895 case XML_ATACTION_NEG_PERCENT
:
897 OUString
aAttrValue( rAttrValue
);
898 if( GetTransformer().NegPercent(aAttrValue
) )
899 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
902 case XML_ATACTION_URI_OASIS
:
904 OUString
aAttrValue( rAttrValue
);
905 if( GetTransformer().ConvertURIToOOo( aAttrValue
,
906 static_cast< sal_Bool
>((*aIter
).second
.m_nParam1
)))
907 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
911 OSL_ENSURE( !this, "unknown action" );
917 if( m_bControlStyle
&& nFamilyAttr
!= -1 )
918 pMutableAttrList
->SetValueByIndex( nFamilyAttr
, GetXMLToken( XML_CONTROL
) );
922 XMLPersElemContentTContext::StartElement( xAttrList
);
924 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
928 void XMLStyleOASISTContext::EndElement()
932 XMLPersElemContentTContext::EndElement();
936 // if a properties context exist close it
937 if( m_xPropContext
.is() )
939 m_xPropContext
->Export();
942 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
946 void XMLStyleOASISTContext::Characters( const OUString
& )
948 // element content only:
951 void XMLStyleOASISTContext::ExportContent()
953 if( m_xPropContext
.is() )
954 m_xPropContext
->Export();
955 XMLPersElemContentTContext::ExportContent();
958 sal_Bool
XMLStyleOASISTContext::IsPersistent() const
960 return m_bPersistent
;
963 XMLTransformerActions
*XMLStyleOASISTContext::CreateTransformerActions(
966 XMLTransformerActionInit
*pInit
= 0;
970 case PROP_OASIS_GRAPHIC_ATTR_ACTIONS
:
971 pInit
= aGraphicPropertyOASISAttrActionTable
;
973 case PROP_OASIS_DRAWING_PAGE_ATTR_ACTIONS
:
974 pInit
= aDrawingPagePropertyOASISAttrActionTable
;
976 case PROP_OASIS_PAGE_LAYOUT_ATTR_ACTIONS
:
977 pInit
= aPageLayoutPropertyOASISAttrActionTable
;
979 case PROP_OASIS_HEADER_FOOTER_ATTR_ACTIONS
:
980 pInit
= aHeaderFooterPropertyOASISAttrActionTable
;
982 case PROP_OASIS_TEXT_ATTR_ACTIONS
:
983 pInit
= aTextPropertyOASISAttrActionTable
;
985 case PROP_OASIS_PARAGRAPH_ATTR_ACTIONS
:
986 pInit
= aParagraphPropertyOASISAttrActionTable
;
988 case PROP_OASIS_SECTION_ATTR_ACTIONS
:
989 pInit
= aSectionPropertyOASISAttrActionTable
;
991 case PROP_OASIS_TABLE_ATTR_ACTIONS
:
992 pInit
= aTablePropertyOASISAttrActionTable
;
994 case PROP_OASIS_TABLE_COLUMN_ATTR_ACTIONS
:
995 pInit
= aTableColumnPropertyOASISAttrActionTable
;
997 case PROP_OASIS_TABLE_ROW_ATTR_ACTIONS
:
998 pInit
= aTableRowPropertyOASISAttrActionTable
;
1000 case PROP_OASIS_TABLE_CELL_ATTR_ACTIONS
:
1001 pInit
= aTableCellPropertyOASISAttrActionTable
;
1003 case PROP_OASIS_LIST_LEVEL_ATTR_ACTIONS
:
1004 pInit
= aListLevelPropertyOASISAttrActionTable
;
1006 case PROP_OASIS_CHART_ATTR_ACTIONS
:
1007 pInit
= aChartPropertyOASISAttrActionTable
;
1011 XMLTransformerActions
*pActions
= 0;
1013 pActions
= new XMLTransformerActions( pInit
);