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 "IgnoreTContext.hxx"
22 #include "MutableAttrList.hxx"
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/nmspmap.hxx>
25 #include "ActionMapTypesOOo.hxx"
26 #include "AttrTransformerAction.hxx"
27 #include "ElemTransformerAction.hxx"
28 #include "TransformerActions.hxx"
29 #include "TransformerBase.hxx"
30 #include <osl/diagnose.h>
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::xml::sax
;
34 using namespace ::xmloff::token
;
36 TYPEINIT1( XMLFrameOOoTransformerContext
, XMLPersElemContentTContext
);
38 XMLFrameOOoTransformerContext::XMLFrameOOoTransformerContext(
39 XMLTransformerBase
& rImp
,
40 const OUString
& rQName
) :
41 XMLPersElemContentTContext( rImp
, rQName
),
42 m_aElemQName( rImp
.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW
,
43 ::xmloff::token::GetXMLToken( XML_FRAME
) ) )
47 XMLFrameOOoTransformerContext::~XMLFrameOOoTransformerContext()
51 void XMLFrameOOoTransformerContext::StartElement(
52 const Reference
< XAttributeList
>& rAttrList
)
55 XMLTransformerActions
*pActions
=
56 GetTransformer().GetUserDefinedActions( OOO_FRAME_ATTR_ACTIONS
);
57 OSL_ENSURE( pActions
, "go no actions" );
59 Reference
< XAttributeList
> xAttrList( rAttrList
);
60 XMLMutableAttributeList
*pMutableAttrList
=
61 GetTransformer().ProcessAttrList( xAttrList
, OOO_SHAPE_ACTIONS
,
63 if( !pMutableAttrList
)
64 pMutableAttrList
= new XMLMutableAttributeList( rAttrList
);
65 xAttrList
= pMutableAttrList
;
67 XMLMutableAttributeList
*pFrameMutableAttrList
=
68 new XMLMutableAttributeList
;
69 Reference
< XAttributeList
> xFrameAttrList( pFrameMutableAttrList
);
71 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
72 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
74 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
77 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
79 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
80 XMLTransformerActions::const_iterator aIter
=
81 pActions
->find( aKey
);
82 if( !(aIter
== pActions
->end() ) )
84 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
85 switch( (*aIter
).second
.m_nActionType
)
87 case XML_ATACTION_MOVE_TO_ELEM
:
88 pFrameMutableAttrList
->AddAttribute( rAttrName
, rAttrValue
);
89 pMutableAttrList
->RemoveAttributeByIndex( i
);
94 OSL_ENSURE( false, "unknown action" );
100 GetTransformer().GetDocHandler()->startElement( m_aElemQName
,
102 XMLTransformerContext::StartElement( xAttrList
);
105 XMLTransformerContext
*XMLFrameOOoTransformerContext::CreateChildContext(
107 const OUString
& rLocalName
,
108 const OUString
& rQName
,
109 const Reference
< XAttributeList
>& rAttrList
)
111 XMLTransformerContext
*pContext
= 0;
113 XMLTransformerActions
*pActions
=
114 GetTransformer().GetUserDefinedActions( OOO_FRAME_ELEM_ACTIONS
);
115 OSL_ENSURE( pActions
, "go no actions" );
116 XMLTransformerActions::key_type
aKey( nPrefix
, rLocalName
);
117 XMLTransformerActions::const_iterator aIter
= pActions
->find( aKey
);
119 if( !(aIter
== pActions
->end()) )
121 switch( (*aIter
).second
.m_nActionType
)
123 case XML_ETACTION_COPY
:
124 case XML_ETACTION_COPY_TEXT
:
125 case XML_ETACTION_RENAME_ELEM
:
126 // the ones in the list have to be persistent
128 pContext
= XMLPersElemContentTContext::CreateChildContext(
129 nPrefix
, rLocalName
, rQName
, rAttrList
);
132 OSL_ENSURE( false, "unknown action" );
137 // default is copying
139 pContext
= XMLTransformerContext::CreateChildContext(
140 nPrefix
, rLocalName
, rQName
, rAttrList
);
145 void XMLFrameOOoTransformerContext::EndElement()
147 XMLTransformerContext::EndElement();
149 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);
152 void XMLFrameOOoTransformerContext::Characters( const OUString
& rChars
)
154 XMLTransformerContext::Characters( rChars
);
157 bool XMLFrameOOoTransformerContext::IsPersistent() const
159 // this context stores some of its child elements, but is not persistent
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */