merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / transform / FormPropOASISTContext.cxx
blob3646f5f2e8c6508718bb6c30eecf40f72d5a2366
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FormPropOASISTContext.cxx,v $
10 * $Revision: 1.6 $
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"
41 #endif
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;
57 sal_uInt32 nVal = 0;
59 sal_Int32 nPos = 0L;
60 sal_Int32 nLen = rValue.getLength();
62 // skip white space
63 while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] )
64 nPos++;
66 if( nPos < nLen && sal_Unicode('-') == rValue[nPos] )
68 bNeg = sal_True;
69 nPos++;
72 // get number
73 sal_Bool bOverflow = sal_False;
74 while( nPos < nLen &&
75 sal_Unicode('0') <= rValue[nPos] &&
76 sal_Unicode('9') >= rValue[nPos] )
78 nVal *= 10;
79 nVal += (rValue[nPos] - sal_Unicode('0'));
80 bOverflow |= (nVal > (bNeg ? 2147483648UL : 2147483647UL));
81 nPos++;
84 // skip white space
85 while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] )
86 nPos++;
88 if( nPos == nLen )
90 // It's a integer number
91 if( bOverflow )
92 eRet = XML_LONG;
93 else if( nVal > (bNeg ? 32768UL : 32767UL) )
94 eRet = XML_INT;
95 else
96 eRet = XML_SHORT;
99 return eRet;
102 XMLFormPropOASISTransformerContext::XMLFormPropOASISTransformerContext(
103 XMLTransformerBase& rImp,
104 const OUString& rQName,
105 XMLTokenEnum eLocalName ) :
106 XMLRenameElemTransformerContext( rImp, rQName, XML_NAMESPACE_FORM,
107 XML_PROPERTY ),
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;
130 OUString aValue;
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 );
136 OUString aLocalName;
137 sal_uInt16 nPrefix =
138 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
139 &aLocalName );
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 ) )
153 nValueTypeAttr = i;
155 else if( IsXMLToken( rAttrValue, XML_VOID ) )
157 pMutableAttrList->SetValueByIndex( i,
158 GetXMLToken( XML_SHORT ) );
159 bIsVoid = sal_True;
163 OUString aNewAttrQName(
164 GetTransformer().GetNamespaceMap().GetQNameByKey(
165 (*aIter).second.GetQNamePrefixFromParam1(),
166 ::xmloff::token::GetXMLToken(
167 (*aIter).second.GetQNameTokenFromParam1()) ) );
168 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
170 break;
171 case XML_ATACTION_REMOVE:
172 if( !IsXMLToken( aLocalName, XML_CURRENCY ) )
173 aValue = rAttrValue;
174 pMutableAttrList->RemoveAttributeByIndex( i );
175 --i;
176 --nAttrCount;
177 break;
178 default:
179 OSL_ENSURE( !this, "unknown action" );
180 break;
184 if( m_bIsList )
186 OUString aNewAttrQName(
187 GetTransformer().GetNamespaceMap().GetQNameByKey(
188 XML_NAMESPACE_FORM,
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 );
200 if( !m_bIsList )
202 pMutableAttrList =
203 new XMLMutableAttributeList;
204 xAttrList = pMutableAttrList;
205 if( bIsVoid )
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,
218 xAttrList );
219 GetTransformer().GetDocHandler()->characters( aValue );
220 GetTransformer().GetDocHandler()->endElement( aValueElemQName );
224 void XMLFormPropOASISTransformerContext::EndElement()
226 if( !m_bIsListValue )
227 XMLRenameElemTransformerContext::EndElement();