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 "FormPropOASISTContext.hxx"
28 #include <osl/diagnose.h>
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::xml::sax
;
32 using namespace ::xmloff::token
;
34 TYPEINIT1( XMLFormPropOASISTransformerContext
,
35 XMLRenameElemTransformerContext
);
37 XMLTokenEnum
XMLFormPropOASISTransformerContext::GetValueType(
38 const OUString
& rValue
)
40 XMLTokenEnum eRet
= XML_DOUBLE
;
45 sal_Int32 nLen
= rValue
.getLength();
48 while( nPos
< nLen
&& ' ' == rValue
[nPos
] )
51 if( nPos
< nLen
&& '-' == rValue
[nPos
] )
58 bool bOverflow
= false;
60 '0' <= rValue
[nPos
] &&
64 nVal
+= (rValue
[nPos
] - '0');
65 bOverflow
|= (nVal
> (bNeg
? 2147483648UL : 2147483647UL));
70 while( nPos
< nLen
&& ' ' == rValue
[nPos
] )
75 // It's a integer number
78 else if( nVal
> (bNeg
? 32768UL : 32767UL) )
87 XMLFormPropOASISTransformerContext::XMLFormPropOASISTransformerContext(
88 XMLTransformerBase
& rImp
,
89 const OUString
& rQName
,
90 XMLTokenEnum eLocalName
) :
91 XMLRenameElemTransformerContext( rImp
, rQName
, XML_NAMESPACE_FORM
,
93 m_bIsList( XML_LIST_PROPERTY
== eLocalName
),
94 m_bIsListValue( XML_LIST_VALUE
== eLocalName
)
98 XMLFormPropOASISTransformerContext::~XMLFormPropOASISTransformerContext()
102 void XMLFormPropOASISTransformerContext::StartElement(
103 const Reference
< XAttributeList
>& rAttrList
)
106 XMLTransformerActions
*pActions
=
107 GetTransformer().GetUserDefinedActions( OASIS_FORM_PROP_ACTIONS
);
108 OSL_ENSURE( pActions
, "go no actions" );
110 XMLMutableAttributeList
*pMutableAttrList
=
111 new XMLMutableAttributeList( rAttrList
);
112 Reference
< XAttributeList
> xAttrList( pMutableAttrList
);
114 sal_Int16 nValueTypeAttr
= -1;
116 bool bIsVoid
= false;
117 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
118 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
120 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
123 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
125 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
126 XMLTransformerActions::const_iterator aIter
=
127 pActions
->find( aKey
);
128 if( !(aIter
== pActions
->end() ) )
130 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
131 switch( (*aIter
).second
.m_nActionType
)
133 case XML_ATACTION_RENAME
:
134 if( IsXMLToken( aLocalName
, XML_VALUE_TYPE
) )
136 if( IsXMLToken( rAttrValue
, XML_FLOAT
) )
140 else if( IsXMLToken( rAttrValue
, XML_VOID
) )
142 pMutableAttrList
->SetValueByIndex( i
,
143 GetXMLToken( XML_SHORT
) );
148 OUString
aNewAttrQName(
149 GetTransformer().GetNamespaceMap().GetQNameByKey(
150 (*aIter
).second
.GetQNamePrefixFromParam1(),
151 ::xmloff::token::GetXMLToken(
152 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
153 pMutableAttrList
->RenameAttributeByIndex( i
, aNewAttrQName
);
156 case XML_ATACTION_REMOVE
:
157 if( !IsXMLToken( aLocalName
, XML_CURRENCY
) )
159 pMutableAttrList
->RemoveAttributeByIndex( i
);
164 OSL_ENSURE( false, "unknown action" );
171 OUString
aNewAttrQName(
172 GetTransformer().GetNamespaceMap().GetQNameByKey(
174 GetXMLToken( XML_PROPERTY_IS_LIST
) ) );
175 pMutableAttrList
->AddAttribute( aNewAttrQName
,
176 GetXMLToken( XML_TRUE
) );
179 if( nValueTypeAttr
!= -1 )
180 pMutableAttrList
->SetValueByIndex( nValueTypeAttr
,
181 GetXMLToken( GetValueType( aValue
) ) );
183 if( !m_bIsListValue
)
184 XMLRenameElemTransformerContext::StartElement( xAttrList
);
188 new XMLMutableAttributeList
;
189 xAttrList
= pMutableAttrList
;
192 OUString
aNewAttrQName(
193 GetTransformer().GetNamespaceMap().GetQNameByKey(
194 XML_NAMESPACE_FORM
, GetXMLToken( XML_PROPERTY_IS_VOID
) ) );
195 pMutableAttrList
->AddAttribute( aNewAttrQName
,
196 GetXMLToken( XML_TRUE
) );
199 OUString
aValueElemQName(
200 GetTransformer().GetNamespaceMap().GetQNameByKey(
201 XML_NAMESPACE_FORM
, GetXMLToken( XML_PROPERTY_VALUE
) ) );
202 GetTransformer().GetDocHandler()->startElement( aValueElemQName
,
204 GetTransformer().GetDocHandler()->characters( aValue
);
205 GetTransformer().GetDocHandler()->endElement( aValueElemQName
);
209 void XMLFormPropOASISTransformerContext::EndElement()
211 if( !m_bIsListValue
)
212 XMLRenameElemTransformerContext::EndElement();
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */