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 "FrameOOoTContext.hxx"
21 #include "MutableAttrList.hxx"
22 #include <xmloff/xmlnmspe.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include "ActionMapTypesOOo.hxx"
25 #include "AttrTransformerAction.hxx"
26 #include "ElemTransformerAction.hxx"
27 #include "TransformerActions.hxx"
28 #include "TransformerBase.hxx"
29 #include <osl/diagnose.h>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::xml::sax
;
33 using namespace ::xmloff::token
;
35 XMLFrameOOoTransformerContext::XMLFrameOOoTransformerContext(
36 XMLTransformerBase
& rImp
,
37 const OUString
& rQName
) :
38 XMLPersElemContentTContext( rImp
, rQName
),
39 m_aElemQName( rImp
.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW
,
40 ::xmloff::token::GetXMLToken( XML_FRAME
) ) )
44 void XMLFrameOOoTransformerContext::StartElement(
45 const Reference
< XAttributeList
>& rAttrList
)
48 XMLTransformerActions
*pActions
=
49 GetTransformer().GetUserDefinedActions( OOO_FRAME_ATTR_ACTIONS
);
50 OSL_ENSURE( pActions
, "go no actions" );
52 Reference
< XAttributeList
> xAttrList( rAttrList
);
53 XMLMutableAttributeList
*pMutableAttrList
=
54 GetTransformer().ProcessAttrList( xAttrList
, OOO_SHAPE_ACTIONS
,
56 if( !pMutableAttrList
)
57 pMutableAttrList
= new XMLMutableAttributeList( rAttrList
);
58 xAttrList
= pMutableAttrList
;
60 XMLMutableAttributeList
*pFrameMutableAttrList
=
61 new XMLMutableAttributeList
;
62 Reference
< XAttributeList
> xFrameAttrList( pFrameMutableAttrList
);
64 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
65 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
67 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
70 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
72 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
73 XMLTransformerActions::const_iterator aIter
=
74 pActions
->find( aKey
);
75 if( aIter
!= pActions
->end() )
77 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
78 switch( (*aIter
).second
.m_nActionType
)
80 case XML_ATACTION_MOVE_TO_ELEM
:
81 pFrameMutableAttrList
->AddAttribute( rAttrName
, rAttrValue
);
82 pMutableAttrList
->RemoveAttributeByIndex( i
);
87 OSL_ENSURE( false, "unknown action" );
93 GetTransformer().GetDocHandler()->startElement( m_aElemQName
,
95 XMLTransformerContext::StartElement( xAttrList
);
98 rtl::Reference
<XMLTransformerContext
> XMLFrameOOoTransformerContext::CreateChildContext(
100 const OUString
& rLocalName
,
101 const OUString
& rQName
,
102 const Reference
< XAttributeList
>& rAttrList
)
104 rtl::Reference
<XMLTransformerContext
> pContext
;
106 XMLTransformerActions
*pActions
=
107 GetTransformer().GetUserDefinedActions( OOO_FRAME_ELEM_ACTIONS
);
108 OSL_ENSURE( pActions
, "go no actions" );
109 XMLTransformerActions::key_type
aKey( nPrefix
, rLocalName
);
110 XMLTransformerActions::const_iterator aIter
= pActions
->find( aKey
);
112 if( aIter
!= pActions
->end() )
114 switch( (*aIter
).second
.m_nActionType
)
116 case XML_ETACTION_COPY
:
117 case XML_ETACTION_COPY_TEXT
:
118 case XML_ETACTION_RENAME_ELEM
:
119 // the ones in the list have to be persistent
121 pContext
= XMLPersElemContentTContext::CreateChildContext(
122 nPrefix
, rLocalName
, rQName
, rAttrList
);
125 OSL_ENSURE( false, "unknown action" );
130 // default is copying
132 pContext
= XMLTransformerContext::CreateChildContext(
133 nPrefix
, rLocalName
, rQName
, rAttrList
);
138 void XMLFrameOOoTransformerContext::EndElement()
140 XMLTransformerContext::EndElement();
142 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);
145 void XMLFrameOOoTransformerContext::Characters( const OUString
& rChars
)
147 XMLTransformerContext::Characters( rChars
);
150 bool XMLFrameOOoTransformerContext::IsPersistent() const
152 // this context stores some of its child elements, but is not persistent
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */