1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "MutableAttrList.hxx"
27cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
28cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
29cdf0e10cSrcweir #include "ActionMapTypesOASIS.hxx"
30cdf0e10cSrcweir #include "AttrTransformerAction.hxx"
31cdf0e10cSrcweir #include "TransformerActions.hxx"
32cdf0e10cSrcweir #ifndef _XMLOFF_TRANSFORMERBASE_HXX
33cdf0e10cSrcweir #include "TransformerBase.hxx"
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #include "FormPropOASISTContext.hxx"
36cdf0e10cSrcweir
37cdf0e10cSrcweir using ::rtl::OUString;
38cdf0e10cSrcweir using namespace ::com::sun::star::uno;
39cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
40cdf0e10cSrcweir using namespace ::xmloff::token;
41cdf0e10cSrcweir
42cdf0e10cSrcweir TYPEINIT1( XMLFormPropOASISTransformerContext,
43cdf0e10cSrcweir XMLRenameElemTransformerContext );
44cdf0e10cSrcweir
GetValueType(const OUString & rValue)45cdf0e10cSrcweir XMLTokenEnum XMLFormPropOASISTransformerContext::GetValueType(
46cdf0e10cSrcweir const OUString& rValue )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir XMLTokenEnum eRet = XML_DOUBLE;
49cdf0e10cSrcweir sal_Bool bNeg = sal_False;
50cdf0e10cSrcweir sal_uInt32 nVal = 0;
51cdf0e10cSrcweir
52cdf0e10cSrcweir sal_Int32 nPos = 0;
53cdf0e10cSrcweir sal_Int32 nLen = rValue.getLength();
54cdf0e10cSrcweir
55cdf0e10cSrcweir // skip white space
56cdf0e10cSrcweir while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] )
57cdf0e10cSrcweir nPos++;
58cdf0e10cSrcweir
59cdf0e10cSrcweir if( nPos < nLen && sal_Unicode('-') == rValue[nPos] )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir bNeg = sal_True;
62cdf0e10cSrcweir nPos++;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
65cdf0e10cSrcweir // get number
66cdf0e10cSrcweir sal_Bool bOverflow = sal_False;
67cdf0e10cSrcweir while( nPos < nLen &&
68cdf0e10cSrcweir sal_Unicode('0') <= rValue[nPos] &&
69cdf0e10cSrcweir sal_Unicode('9') >= rValue[nPos] )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir nVal *= 10;
72cdf0e10cSrcweir nVal += (rValue[nPos] - sal_Unicode('0'));
73cdf0e10cSrcweir bOverflow |= (nVal > (bNeg ? 2147483648UL : 2147483647UL));
74cdf0e10cSrcweir nPos++;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir // skip white space
78cdf0e10cSrcweir while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] )
79cdf0e10cSrcweir nPos++;
80cdf0e10cSrcweir
81cdf0e10cSrcweir if( nPos == nLen )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir // It's a integer number
84cdf0e10cSrcweir if( bOverflow )
85cdf0e10cSrcweir eRet = XML_LONG;
86cdf0e10cSrcweir else if( nVal > (bNeg ? 32768UL : 32767UL) )
87cdf0e10cSrcweir eRet = XML_INT;
88cdf0e10cSrcweir else
89cdf0e10cSrcweir eRet = XML_SHORT;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir return eRet;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
XMLFormPropOASISTransformerContext(XMLTransformerBase & rImp,const OUString & rQName,XMLTokenEnum eLocalName)95cdf0e10cSrcweir XMLFormPropOASISTransformerContext::XMLFormPropOASISTransformerContext(
96cdf0e10cSrcweir XMLTransformerBase& rImp,
97cdf0e10cSrcweir const OUString& rQName,
98cdf0e10cSrcweir XMLTokenEnum eLocalName ) :
99cdf0e10cSrcweir XMLRenameElemTransformerContext( rImp, rQName, XML_NAMESPACE_FORM,
100cdf0e10cSrcweir XML_PROPERTY ),
101cdf0e10cSrcweir m_bIsList( XML_LIST_PROPERTY == eLocalName),
102cdf0e10cSrcweir m_bIsListValue( XML_LIST_VALUE == eLocalName)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
~XMLFormPropOASISTransformerContext()106cdf0e10cSrcweir XMLFormPropOASISTransformerContext::~XMLFormPropOASISTransformerContext()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
StartElement(const Reference<XAttributeList> & rAttrList)110cdf0e10cSrcweir void XMLFormPropOASISTransformerContext::StartElement(
111cdf0e10cSrcweir const Reference< XAttributeList >& rAttrList )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir
114cdf0e10cSrcweir XMLTransformerActions *pActions =
115cdf0e10cSrcweir GetTransformer().GetUserDefinedActions( OASIS_FORM_PROP_ACTIONS );
116cdf0e10cSrcweir OSL_ENSURE( pActions, "go no actions" );
117cdf0e10cSrcweir
118cdf0e10cSrcweir XMLMutableAttributeList *pMutableAttrList =
119cdf0e10cSrcweir new XMLMutableAttributeList( rAttrList );
120cdf0e10cSrcweir Reference< XAttributeList > xAttrList( pMutableAttrList );
121cdf0e10cSrcweir
122cdf0e10cSrcweir sal_Int16 nValueTypeAttr = -1;
123cdf0e10cSrcweir OUString aValue;
124cdf0e10cSrcweir sal_Bool bIsVoid = sal_False;
125cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
126cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir const OUString& rAttrName = xAttrList->getNameByIndex( i );
129cdf0e10cSrcweir OUString aLocalName;
130cdf0e10cSrcweir sal_uInt16 nPrefix =
131cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
132cdf0e10cSrcweir &aLocalName );
133cdf0e10cSrcweir XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
134cdf0e10cSrcweir XMLTransformerActions::const_iterator aIter =
135cdf0e10cSrcweir pActions->find( aKey );
136cdf0e10cSrcweir if( !(aIter == pActions->end() ) )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir const OUString& rAttrValue = xAttrList->getValueByIndex( i );
139cdf0e10cSrcweir switch( (*aIter).second.m_nActionType )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir case XML_ATACTION_RENAME:
142cdf0e10cSrcweir if( IsXMLToken( aLocalName, XML_VALUE_TYPE ) )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir if( IsXMLToken( rAttrValue, XML_FLOAT ) )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir nValueTypeAttr = i;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir else if( IsXMLToken( rAttrValue, XML_VOID ) )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir pMutableAttrList->SetValueByIndex( i,
151cdf0e10cSrcweir GetXMLToken( XML_SHORT ) );
152cdf0e10cSrcweir bIsVoid = sal_True;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir {
156cdf0e10cSrcweir OUString aNewAttrQName(
157cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey(
158cdf0e10cSrcweir (*aIter).second.GetQNamePrefixFromParam1(),
159cdf0e10cSrcweir ::xmloff::token::GetXMLToken(
160cdf0e10cSrcweir (*aIter).second.GetQNameTokenFromParam1()) ) );
161cdf0e10cSrcweir pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir break;
164cdf0e10cSrcweir case XML_ATACTION_REMOVE:
165cdf0e10cSrcweir if( !IsXMLToken( aLocalName, XML_CURRENCY ) )
166cdf0e10cSrcweir aValue = rAttrValue;
167cdf0e10cSrcweir pMutableAttrList->RemoveAttributeByIndex( i );
168cdf0e10cSrcweir --i;
169cdf0e10cSrcweir --nAttrCount;
170cdf0e10cSrcweir break;
171cdf0e10cSrcweir default:
172cdf0e10cSrcweir OSL_ENSURE( !this, "unknown action" );
173cdf0e10cSrcweir break;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir }
176cdf0e10cSrcweir }
177cdf0e10cSrcweir if( m_bIsList )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir OUString aNewAttrQName(
180cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey(
181cdf0e10cSrcweir XML_NAMESPACE_FORM,
182cdf0e10cSrcweir GetXMLToken( XML_PROPERTY_IS_LIST ) ) );
183cdf0e10cSrcweir pMutableAttrList->AddAttribute( aNewAttrQName,
184cdf0e10cSrcweir GetXMLToken( XML_TRUE ) );
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187cdf0e10cSrcweir if( nValueTypeAttr != -1 )
188cdf0e10cSrcweir pMutableAttrList->SetValueByIndex( nValueTypeAttr,
189cdf0e10cSrcweir GetXMLToken( GetValueType( aValue ) ) );
190cdf0e10cSrcweir
191cdf0e10cSrcweir if( !m_bIsListValue )
192cdf0e10cSrcweir XMLRenameElemTransformerContext::StartElement( xAttrList );
193cdf0e10cSrcweir if( !m_bIsList )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir pMutableAttrList =
196cdf0e10cSrcweir new XMLMutableAttributeList;
197cdf0e10cSrcweir xAttrList = pMutableAttrList;
198cdf0e10cSrcweir if( bIsVoid )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir OUString aNewAttrQName(
201cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey(
202cdf0e10cSrcweir XML_NAMESPACE_FORM, GetXMLToken( XML_PROPERTY_IS_VOID ) ) );
203cdf0e10cSrcweir pMutableAttrList->AddAttribute( aNewAttrQName,
204cdf0e10cSrcweir GetXMLToken( XML_TRUE ) );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir OUString aValueElemQName(
208cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey(
209cdf0e10cSrcweir XML_NAMESPACE_FORM, GetXMLToken( XML_PROPERTY_VALUE ) ) );
210cdf0e10cSrcweir GetTransformer().GetDocHandler()->startElement( aValueElemQName,
211cdf0e10cSrcweir xAttrList );
212cdf0e10cSrcweir GetTransformer().GetDocHandler()->characters( aValue );
213cdf0e10cSrcweir GetTransformer().GetDocHandler()->endElement( aValueElemQName );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
EndElement()217cdf0e10cSrcweir void XMLFormPropOASISTransformerContext::EndElement()
218cdf0e10cSrcweir {
219cdf0e10cSrcweir if( !m_bIsListValue )
220cdf0e10cSrcweir XMLRenameElemTransformerContext::EndElement();
221cdf0e10cSrcweir }
222