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 "MutableAttrList.hxx"
21 #include "xmloff/xmlnmspe.hxx"
22 #include <xmloff/nmspmap.hxx>
23 #include "ActionMapTypesOASIS.hxx"
24 #include "AttrTransformerAction.hxx"
25 #include "TransformerActions.hxx"
26 #include "TransformerBase.hxx"
27 #include "ControlOASISTContext.hxx"
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::xml::sax
;
31 using namespace ::xmloff::token
;
33 TYPEINIT1( XMLControlOASISTransformerContext
, XMLTransformerContext
);
35 XMLControlOASISTransformerContext::XMLControlOASISTransformerContext(
36 XMLTransformerBase
& rImp
,
37 const OUString
& rQName
,
38 sal_Bool bCreateControl
) :
39 XMLTransformerContext( rImp
, rQName
),
40 m_aElemQName( rImp
.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_FORM
,
41 ::xmloff::token::GetXMLToken( XML_CONTROL
) ) ),
42 m_bCreateControl( bCreateControl
)
46 XMLControlOASISTransformerContext::~XMLControlOASISTransformerContext()
50 void XMLControlOASISTransformerContext::StartElement(
51 const Reference
< XAttributeList
>& rAttrList
)
54 XMLTransformerActions
*pActions
=
55 GetTransformer().GetUserDefinedActions( OASIS_FORM_CONTROL_ACTIONS
);
56 OSL_ENSURE( pActions
, "go no actions" );
58 Reference
< XAttributeList
> xAttrList( rAttrList
);
59 XMLMutableAttributeList
*pMutableAttrList
= 0;
60 // GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
63 XMLMutableAttributeList
*pControlMutableAttrList
=
64 m_bCreateControl
? new XMLMutableAttributeList
: 0;
65 Reference
< XAttributeList
> xControlAttrList( pControlMutableAttrList
);
67 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
68 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
70 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
73 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
75 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
76 XMLTransformerActions::const_iterator aIter
=
77 pActions
->find( aKey
);
78 if( !(aIter
== pActions
->end() ) )
80 if( !pMutableAttrList
)
83 new XMLMutableAttributeList( rAttrList
);
84 xAttrList
= pMutableAttrList
;
86 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
87 switch( (*aIter
).second
.m_nActionType
)
89 case XML_ATACTION_MOVE_TO_ELEM
:
90 if( m_bCreateControl
)
92 pControlMutableAttrList
->AddAttribute( rAttrName
,
94 pMutableAttrList
->RemoveAttributeByIndex( i
);
99 case XML_ATACTION_RENAME_REMOVE_NAMESPACE_PREFIX
:
101 OUString
aAttrValue( rAttrValue
);
102 sal_uInt16 nValPrefix
=
103 static_cast<sal_uInt16
>( (*aIter
).second
.m_nParam2
);
104 GetTransformer().RemoveNamespacePrefix( aAttrValue
,
106 OUString
aNewAttrQName(
107 GetTransformer().GetNamespaceMap().GetQNameByKey(
108 (*aIter
).second
.GetQNamePrefixFromParam1(),
109 ::xmloff::token::GetXMLToken(
110 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
111 if( m_bCreateControl
)
113 pControlMutableAttrList
->AddAttribute( aNewAttrQName
,
115 pMutableAttrList
->RemoveAttributeByIndex( i
);
121 pMutableAttrList
->RenameAttributeByIndex( i
,
123 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
126 case XML_ATACTION_URI_OASIS
:
128 OUString
aAttrValue( rAttrValue
);
129 if( GetTransformer().ConvertURIToOOo( aAttrValue
,
130 static_cast< sal_Bool
>((*aIter
).second
.m_nParam1
)) )
131 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
135 OSL_ENSURE( !this, "unknown action" );
141 if( m_bCreateControl
)
142 GetTransformer().GetDocHandler()->startElement( m_aElemQName
,
144 XMLTransformerContext::StartElement( xAttrList
);
147 void XMLControlOASISTransformerContext::EndElement()
149 XMLTransformerContext::EndElement();
150 if( m_bCreateControl
)
151 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */