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/xmlnamespace.hxx>
22 #include <xmloff/namespacemap.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 XMLTokenEnum
XMLFormPropOASISTransformerContext::GetValueType(
35 std::u16string_view rValue
)
37 XMLTokenEnum eRet
= XML_DOUBLE
;
42 sal_Int32 nLen
= rValue
.size();
45 while( nPos
< nLen
&& ' ' == rValue
[nPos
] )
48 if( nPos
< nLen
&& '-' == rValue
[nPos
] )
55 bool bOverflow
= false;
57 '0' <= rValue
[nPos
] &&
61 nVal
+= (rValue
[nPos
] - '0');
62 bOverflow
|= (nVal
> (bNeg
? 2147483648UL : 2147483647UL));
67 while( nPos
< nLen
&& ' ' == rValue
[nPos
] )
72 // It's an integer number
75 else if( nVal
> (bNeg
? 32768UL : 32767UL) )
84 XMLFormPropOASISTransformerContext::XMLFormPropOASISTransformerContext(
85 XMLTransformerBase
& rImp
,
86 const OUString
& rQName
,
87 XMLTokenEnum eLocalName
) :
88 XMLRenameElemTransformerContext( rImp
, rQName
, XML_NAMESPACE_FORM
,
90 m_bIsList( XML_LIST_PROPERTY
== eLocalName
),
91 m_bIsListValue( XML_LIST_VALUE
== eLocalName
)
95 XMLFormPropOASISTransformerContext::~XMLFormPropOASISTransformerContext()
99 void XMLFormPropOASISTransformerContext::StartElement(
100 const Reference
< XAttributeList
>& rAttrList
)
103 XMLTransformerActions
*pActions
=
104 GetTransformer().GetUserDefinedActions( OASIS_FORM_PROP_ACTIONS
);
105 OSL_ENSURE( pActions
, "go no actions" );
107 rtl::Reference
<XMLMutableAttributeList
> pMutableAttrList
=
108 new XMLMutableAttributeList( rAttrList
);
109 Reference
< XAttributeList
> xAttrList( pMutableAttrList
);
111 sal_Int16 nValueTypeAttr
= -1;
113 bool bIsVoid
= false;
114 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
115 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
117 const OUString aAttrName
= xAttrList
->getNameByIndex( i
);
120 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName
,
122 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
123 XMLTransformerActions::const_iterator aIter
=
124 pActions
->find( aKey
);
125 if( aIter
!= pActions
->end() )
127 const OUString aAttrValue
= xAttrList
->getValueByIndex( i
);
128 switch( (*aIter
).second
.m_nActionType
)
130 case XML_ATACTION_RENAME
:
131 if( IsXMLToken( aLocalName
, XML_VALUE_TYPE
) )
133 if( IsXMLToken( aAttrValue
, XML_FLOAT
) )
137 else if( IsXMLToken( aAttrValue
, XML_VOID
) )
139 pMutableAttrList
->SetValueByIndex( i
,
140 GetXMLToken( XML_SHORT
) );
145 OUString
aNewAttrQName(
146 GetTransformer().GetNamespaceMap().GetQNameByKey(
147 (*aIter
).second
.GetQNamePrefixFromParam1(),
148 ::xmloff::token::GetXMLToken(
149 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
150 pMutableAttrList
->RenameAttributeByIndex( i
, aNewAttrQName
);
153 case XML_ATACTION_REMOVE
:
154 if( !IsXMLToken( aLocalName
, XML_CURRENCY
) )
156 pMutableAttrList
->RemoveAttributeByIndex( i
);
161 OSL_ENSURE( false, "unknown action" );
168 OUString
aNewAttrQName(
169 GetTransformer().GetNamespaceMap().GetQNameByKey(
171 GetXMLToken( XML_PROPERTY_IS_LIST
) ) );
172 pMutableAttrList
->AddAttribute( aNewAttrQName
,
173 GetXMLToken( XML_TRUE
) );
176 if( nValueTypeAttr
!= -1 )
177 pMutableAttrList
->SetValueByIndex( nValueTypeAttr
,
178 GetXMLToken( GetValueType( aValue
) ) );
180 if( !m_bIsListValue
)
181 XMLRenameElemTransformerContext::StartElement( xAttrList
);
185 pMutableAttrList
= new XMLMutableAttributeList
;
186 xAttrList
= pMutableAttrList
;
189 OUString
aNewAttrQName(
190 GetTransformer().GetNamespaceMap().GetQNameByKey(
191 XML_NAMESPACE_FORM
, GetXMLToken( XML_PROPERTY_IS_VOID
) ) );
192 pMutableAttrList
->AddAttribute( aNewAttrQName
,
193 GetXMLToken( XML_TRUE
) );
196 OUString
aValueElemQName(
197 GetTransformer().GetNamespaceMap().GetQNameByKey(
198 XML_NAMESPACE_FORM
, GetXMLToken( XML_PROPERTY_VALUE
) ) );
199 GetTransformer().GetDocHandler()->startElement( aValueElemQName
,
201 GetTransformer().GetDocHandler()->characters( aValue
);
202 GetTransformer().GetDocHandler()->endElement( aValueElemQName
);
205 void XMLFormPropOASISTransformerContext::EndElement()
207 if( !m_bIsListValue
)
208 XMLRenameElemTransformerContext::EndElement();
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */