1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 30*cdf0e10cSrcweir #include "MutableAttrList.hxx" 31*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 32*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 33*cdf0e10cSrcweir #include "ActionMapTypesOASIS.hxx" 34*cdf0e10cSrcweir #include "AttrTransformerAction.hxx" 35*cdf0e10cSrcweir #include "TransformerActions.hxx" 36*cdf0e10cSrcweir #ifndef _XMLOFF_TRANSFORMERBASE_HXX 37*cdf0e10cSrcweir #include "TransformerBase.hxx" 38*cdf0e10cSrcweir #endif 39*cdf0e10cSrcweir #include "FormPropOASISTContext.hxx" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using ::rtl::OUString; 42*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 44*cdf0e10cSrcweir using namespace ::xmloff::token; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir TYPEINIT1( XMLFormPropOASISTransformerContext, 47*cdf0e10cSrcweir XMLRenameElemTransformerContext ); 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir XMLTokenEnum XMLFormPropOASISTransformerContext::GetValueType( 50*cdf0e10cSrcweir const OUString& rValue ) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir XMLTokenEnum eRet = XML_DOUBLE; 53*cdf0e10cSrcweir sal_Bool bNeg = sal_False; 54*cdf0e10cSrcweir sal_uInt32 nVal = 0; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir sal_Int32 nPos = 0; 57*cdf0e10cSrcweir sal_Int32 nLen = rValue.getLength(); 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir // skip white space 60*cdf0e10cSrcweir while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] ) 61*cdf0e10cSrcweir nPos++; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir if( nPos < nLen && sal_Unicode('-') == rValue[nPos] ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir bNeg = sal_True; 66*cdf0e10cSrcweir nPos++; 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // get number 70*cdf0e10cSrcweir sal_Bool bOverflow = sal_False; 71*cdf0e10cSrcweir while( nPos < nLen && 72*cdf0e10cSrcweir sal_Unicode('0') <= rValue[nPos] && 73*cdf0e10cSrcweir sal_Unicode('9') >= rValue[nPos] ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir nVal *= 10; 76*cdf0e10cSrcweir nVal += (rValue[nPos] - sal_Unicode('0')); 77*cdf0e10cSrcweir bOverflow |= (nVal > (bNeg ? 2147483648UL : 2147483647UL)); 78*cdf0e10cSrcweir nPos++; 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // skip white space 82*cdf0e10cSrcweir while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] ) 83*cdf0e10cSrcweir nPos++; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir if( nPos == nLen ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir // It's a integer number 88*cdf0e10cSrcweir if( bOverflow ) 89*cdf0e10cSrcweir eRet = XML_LONG; 90*cdf0e10cSrcweir else if( nVal > (bNeg ? 32768UL : 32767UL) ) 91*cdf0e10cSrcweir eRet = XML_INT; 92*cdf0e10cSrcweir else 93*cdf0e10cSrcweir eRet = XML_SHORT; 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir return eRet; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir XMLFormPropOASISTransformerContext::XMLFormPropOASISTransformerContext( 100*cdf0e10cSrcweir XMLTransformerBase& rImp, 101*cdf0e10cSrcweir const OUString& rQName, 102*cdf0e10cSrcweir XMLTokenEnum eLocalName ) : 103*cdf0e10cSrcweir XMLRenameElemTransformerContext( rImp, rQName, XML_NAMESPACE_FORM, 104*cdf0e10cSrcweir XML_PROPERTY ), 105*cdf0e10cSrcweir m_bIsList( XML_LIST_PROPERTY == eLocalName), 106*cdf0e10cSrcweir m_bIsListValue( XML_LIST_VALUE == eLocalName) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir XMLFormPropOASISTransformerContext::~XMLFormPropOASISTransformerContext() 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir void XMLFormPropOASISTransformerContext::StartElement( 115*cdf0e10cSrcweir const Reference< XAttributeList >& rAttrList ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir XMLTransformerActions *pActions = 119*cdf0e10cSrcweir GetTransformer().GetUserDefinedActions( OASIS_FORM_PROP_ACTIONS ); 120*cdf0e10cSrcweir OSL_ENSURE( pActions, "go no actions" ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir XMLMutableAttributeList *pMutableAttrList = 123*cdf0e10cSrcweir new XMLMutableAttributeList( rAttrList ); 124*cdf0e10cSrcweir Reference< XAttributeList > xAttrList( pMutableAttrList ); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir sal_Int16 nValueTypeAttr = -1; 127*cdf0e10cSrcweir OUString aValue; 128*cdf0e10cSrcweir sal_Bool bIsVoid = sal_False; 129*cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 130*cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir const OUString& rAttrName = xAttrList->getNameByIndex( i ); 133*cdf0e10cSrcweir OUString aLocalName; 134*cdf0e10cSrcweir sal_uInt16 nPrefix = 135*cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, 136*cdf0e10cSrcweir &aLocalName ); 137*cdf0e10cSrcweir XMLTransformerActions::key_type aKey( nPrefix, aLocalName ); 138*cdf0e10cSrcweir XMLTransformerActions::const_iterator aIter = 139*cdf0e10cSrcweir pActions->find( aKey ); 140*cdf0e10cSrcweir if( !(aIter == pActions->end() ) ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir const OUString& rAttrValue = xAttrList->getValueByIndex( i ); 143*cdf0e10cSrcweir switch( (*aIter).second.m_nActionType ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir case XML_ATACTION_RENAME: 146*cdf0e10cSrcweir if( IsXMLToken( aLocalName, XML_VALUE_TYPE ) ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir if( IsXMLToken( rAttrValue, XML_FLOAT ) ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir nValueTypeAttr = i; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir else if( IsXMLToken( rAttrValue, XML_VOID ) ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir pMutableAttrList->SetValueByIndex( i, 155*cdf0e10cSrcweir GetXMLToken( XML_SHORT ) ); 156*cdf0e10cSrcweir bIsVoid = sal_True; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir OUString aNewAttrQName( 161*cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey( 162*cdf0e10cSrcweir (*aIter).second.GetQNamePrefixFromParam1(), 163*cdf0e10cSrcweir ::xmloff::token::GetXMLToken( 164*cdf0e10cSrcweir (*aIter).second.GetQNameTokenFromParam1()) ) ); 165*cdf0e10cSrcweir pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName ); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir break; 168*cdf0e10cSrcweir case XML_ATACTION_REMOVE: 169*cdf0e10cSrcweir if( !IsXMLToken( aLocalName, XML_CURRENCY ) ) 170*cdf0e10cSrcweir aValue = rAttrValue; 171*cdf0e10cSrcweir pMutableAttrList->RemoveAttributeByIndex( i ); 172*cdf0e10cSrcweir --i; 173*cdf0e10cSrcweir --nAttrCount; 174*cdf0e10cSrcweir break; 175*cdf0e10cSrcweir default: 176*cdf0e10cSrcweir OSL_ENSURE( !this, "unknown action" ); 177*cdf0e10cSrcweir break; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir if( m_bIsList ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir OUString aNewAttrQName( 184*cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey( 185*cdf0e10cSrcweir XML_NAMESPACE_FORM, 186*cdf0e10cSrcweir GetXMLToken( XML_PROPERTY_IS_LIST ) ) ); 187*cdf0e10cSrcweir pMutableAttrList->AddAttribute( aNewAttrQName, 188*cdf0e10cSrcweir GetXMLToken( XML_TRUE ) ); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir if( nValueTypeAttr != -1 ) 192*cdf0e10cSrcweir pMutableAttrList->SetValueByIndex( nValueTypeAttr, 193*cdf0e10cSrcweir GetXMLToken( GetValueType( aValue ) ) ); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir if( !m_bIsListValue ) 196*cdf0e10cSrcweir XMLRenameElemTransformerContext::StartElement( xAttrList ); 197*cdf0e10cSrcweir if( !m_bIsList ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir pMutableAttrList = 200*cdf0e10cSrcweir new XMLMutableAttributeList; 201*cdf0e10cSrcweir xAttrList = pMutableAttrList; 202*cdf0e10cSrcweir if( bIsVoid ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir OUString aNewAttrQName( 205*cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey( 206*cdf0e10cSrcweir XML_NAMESPACE_FORM, GetXMLToken( XML_PROPERTY_IS_VOID ) ) ); 207*cdf0e10cSrcweir pMutableAttrList->AddAttribute( aNewAttrQName, 208*cdf0e10cSrcweir GetXMLToken( XML_TRUE ) ); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir OUString aValueElemQName( 212*cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey( 213*cdf0e10cSrcweir XML_NAMESPACE_FORM, GetXMLToken( XML_PROPERTY_VALUE ) ) ); 214*cdf0e10cSrcweir GetTransformer().GetDocHandler()->startElement( aValueElemQName, 215*cdf0e10cSrcweir xAttrList ); 216*cdf0e10cSrcweir GetTransformer().GetDocHandler()->characters( aValue ); 217*cdf0e10cSrcweir GetTransformer().GetDocHandler()->endElement( aValueElemQName ); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir void XMLFormPropOASISTransformerContext::EndElement() 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir if( !m_bIsListValue ) 224*cdf0e10cSrcweir XMLRenameElemTransformerContext::EndElement(); 225*cdf0e10cSrcweir } 226