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: ControlOASISTContext.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 "MutableAttrList.hxx"
34 #include "xmlnmspe.hxx"
35 #include <xmloff/nmspmap.hxx>
36 #include "ActionMapTypesOASIS.hxx"
37 #include "AttrTransformerAction.hxx"
38 #include "TransformerActions.hxx"
39 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
40 #include "TransformerBase.hxx"
42 #include "ControlOASISTContext.hxx"
44 using ::rtl::OUString
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::xml::sax
;
47 using namespace ::xmloff::token
;
49 TYPEINIT1( XMLControlOASISTransformerContext
, XMLTransformerContext
);
51 XMLControlOASISTransformerContext::XMLControlOASISTransformerContext(
52 XMLTransformerBase
& rImp
,
53 const OUString
& rQName
,
54 sal_Bool bCreateControl
) :
55 XMLTransformerContext( rImp
, rQName
),
56 m_aElemQName( rImp
.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_FORM
,
57 ::xmloff::token::GetXMLToken( XML_CONTROL
) ) ),
58 m_bCreateControl( bCreateControl
)
62 XMLControlOASISTransformerContext::~XMLControlOASISTransformerContext()
66 void XMLControlOASISTransformerContext::StartElement(
67 const Reference
< XAttributeList
>& rAttrList
)
70 XMLTransformerActions
*pActions
=
71 GetTransformer().GetUserDefinedActions( OASIS_FORM_CONTROL_ACTIONS
);
72 OSL_ENSURE( pActions
, "go no actions" );
74 Reference
< XAttributeList
> xAttrList( rAttrList
);
75 XMLMutableAttributeList
*pMutableAttrList
= 0;
76 // GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
79 XMLMutableAttributeList
*pControlMutableAttrList
=
80 m_bCreateControl
? new XMLMutableAttributeList
: 0;
81 Reference
< XAttributeList
> xControlAttrList( pControlMutableAttrList
);
83 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
84 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
86 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
89 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
91 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
92 XMLTransformerActions::const_iterator aIter
=
93 pActions
->find( aKey
);
94 if( !(aIter
== pActions
->end() ) )
96 if( !pMutableAttrList
)
99 new XMLMutableAttributeList( rAttrList
);
100 xAttrList
= pMutableAttrList
;
102 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
103 switch( (*aIter
).second
.m_nActionType
)
105 case XML_ATACTION_MOVE_TO_ELEM
:
106 if( m_bCreateControl
)
108 pControlMutableAttrList
->AddAttribute( rAttrName
,
110 pMutableAttrList
->RemoveAttributeByIndex( i
);
115 case XML_ATACTION_RENAME_REMOVE_NAMESPACE_PREFIX
:
117 OUString
aAttrValue( rAttrValue
);
118 sal_uInt16 nValPrefix
=
119 static_cast<sal_uInt16
>( (*aIter
).second
.m_nParam2
);
120 GetTransformer().RemoveNamespacePrefix( aAttrValue
,
122 OUString
aNewAttrQName(
123 GetTransformer().GetNamespaceMap().GetQNameByKey(
124 (*aIter
).second
.GetQNamePrefixFromParam1(),
125 ::xmloff::token::GetXMLToken(
126 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
127 if( m_bCreateControl
)
129 pControlMutableAttrList
->AddAttribute( aNewAttrQName
,
131 pMutableAttrList
->RemoveAttributeByIndex( i
);
137 pMutableAttrList
->RenameAttributeByIndex( i
,
139 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
142 case XML_ATACTION_URI_OASIS
:
144 OUString
aAttrValue( rAttrValue
);
145 if( GetTransformer().ConvertURIToOOo( aAttrValue
,
146 static_cast< sal_Bool
>((*aIter
).second
.m_nParam1
)) )
147 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
151 OSL_ENSURE( !this, "unknown action" );
157 if( m_bCreateControl
)
158 GetTransformer().GetDocHandler()->startElement( m_aElemQName
,
160 XMLTransformerContext::StartElement( xAttrList
);
163 void XMLControlOASISTransformerContext::EndElement()
165 XMLTransformerContext::EndElement();
166 if( m_bCreateControl
)
167 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);