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: FormPropOASISTContext.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 "FormPropOASISTContext.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( XMLFormPropOASISTransformerContext
,
50 XMLRenameElemTransformerContext
);
52 XMLTokenEnum
XMLFormPropOASISTransformerContext::GetValueType(
53 const OUString
& rValue
)
55 XMLTokenEnum eRet
= XML_DOUBLE
;
56 sal_Bool bNeg
= sal_False
;
60 sal_Int32 nLen
= rValue
.getLength();
63 while( nPos
< nLen
&& sal_Unicode(' ') == rValue
[nPos
] )
66 if( nPos
< nLen
&& sal_Unicode('-') == rValue
[nPos
] )
73 sal_Bool bOverflow
= sal_False
;
75 sal_Unicode('0') <= rValue
[nPos
] &&
76 sal_Unicode('9') >= rValue
[nPos
] )
79 nVal
+= (rValue
[nPos
] - sal_Unicode('0'));
80 bOverflow
|= (nVal
> (bNeg
? 2147483648UL : 2147483647UL));
85 while( nPos
< nLen
&& sal_Unicode(' ') == rValue
[nPos
] )
90 // It's a integer number
93 else if( nVal
> (bNeg
? 32768UL : 32767UL) )
102 XMLFormPropOASISTransformerContext::XMLFormPropOASISTransformerContext(
103 XMLTransformerBase
& rImp
,
104 const OUString
& rQName
,
105 XMLTokenEnum eLocalName
) :
106 XMLRenameElemTransformerContext( rImp
, rQName
, XML_NAMESPACE_FORM
,
108 m_bIsList( XML_LIST_PROPERTY
== eLocalName
),
109 m_bIsListValue( XML_LIST_VALUE
== eLocalName
)
113 XMLFormPropOASISTransformerContext::~XMLFormPropOASISTransformerContext()
117 void XMLFormPropOASISTransformerContext::StartElement(
118 const Reference
< XAttributeList
>& rAttrList
)
121 XMLTransformerActions
*pActions
=
122 GetTransformer().GetUserDefinedActions( OASIS_FORM_PROP_ACTIONS
);
123 OSL_ENSURE( pActions
, "go no actions" );
125 XMLMutableAttributeList
*pMutableAttrList
=
126 new XMLMutableAttributeList( rAttrList
);
127 Reference
< XAttributeList
> xAttrList( pMutableAttrList
);
129 sal_Int16 nValueTypeAttr
= -1;
131 sal_Bool bIsVoid
= sal_False
;
132 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
133 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
135 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
138 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
140 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
141 XMLTransformerActions::const_iterator aIter
=
142 pActions
->find( aKey
);
143 if( !(aIter
== pActions
->end() ) )
145 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
146 switch( (*aIter
).second
.m_nActionType
)
148 case XML_ATACTION_RENAME
:
149 if( IsXMLToken( aLocalName
, XML_VALUE_TYPE
) )
151 if( IsXMLToken( rAttrValue
, XML_FLOAT
) )
155 else if( IsXMLToken( rAttrValue
, XML_VOID
) )
157 pMutableAttrList
->SetValueByIndex( i
,
158 GetXMLToken( XML_SHORT
) );
163 OUString
aNewAttrQName(
164 GetTransformer().GetNamespaceMap().GetQNameByKey(
165 (*aIter
).second
.GetQNamePrefixFromParam1(),
166 ::xmloff::token::GetXMLToken(
167 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
168 pMutableAttrList
->RenameAttributeByIndex( i
, aNewAttrQName
);
171 case XML_ATACTION_REMOVE
:
172 if( !IsXMLToken( aLocalName
, XML_CURRENCY
) )
174 pMutableAttrList
->RemoveAttributeByIndex( i
);
179 OSL_ENSURE( !this, "unknown action" );
186 OUString
aNewAttrQName(
187 GetTransformer().GetNamespaceMap().GetQNameByKey(
189 GetXMLToken( XML_PROPERTY_IS_LIST
) ) );
190 pMutableAttrList
->AddAttribute( aNewAttrQName
,
191 GetXMLToken( XML_TRUE
) );
194 if( nValueTypeAttr
!= -1 )
195 pMutableAttrList
->SetValueByIndex( nValueTypeAttr
,
196 GetXMLToken( GetValueType( aValue
) ) );
198 if( !m_bIsListValue
)
199 XMLRenameElemTransformerContext::StartElement( xAttrList
);
203 new XMLMutableAttributeList
;
204 xAttrList
= pMutableAttrList
;
207 OUString
aNewAttrQName(
208 GetTransformer().GetNamespaceMap().GetQNameByKey(
209 XML_NAMESPACE_FORM
, GetXMLToken( XML_PROPERTY_IS_VOID
) ) );
210 pMutableAttrList
->AddAttribute( aNewAttrQName
,
211 GetXMLToken( XML_TRUE
) );
214 OUString
aValueElemQName(
215 GetTransformer().GetNamespaceMap().GetQNameByKey(
216 XML_NAMESPACE_FORM
, GetXMLToken( XML_PROPERTY_VALUE
) ) );
217 GetTransformer().GetDocHandler()->startElement( aValueElemQName
,
219 GetTransformer().GetDocHandler()->characters( aValue
);
220 GetTransformer().GetDocHandler()->endElement( aValueElemQName
);
224 void XMLFormPropOASISTransformerContext::EndElement()
226 if( !m_bIsListValue
)
227 XMLRenameElemTransformerContext::EndElement();