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 "IgnoreTContext.hxx"
30cdf0e10cSrcweir #ifndef _XMLOFF_ACTIONMAPTYPESOOo_HXX
31cdf0e10cSrcweir #include "ActionMapTypesOOo.hxx"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include "AttrTransformerAction.hxx"
34cdf0e10cSrcweir #include "TransformerActions.hxx"
35cdf0e10cSrcweir #ifndef _XMLOFF_TRANSFORMERBASE_HXX
36cdf0e10cSrcweir #include "TransformerBase.hxx"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #include "FormPropOOoTContext.hxx"
39cdf0e10cSrcweir
40cdf0e10cSrcweir using ::rtl::OUString;
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
43cdf0e10cSrcweir using namespace ::xmloff::token;
44cdf0e10cSrcweir
45cdf0e10cSrcweir class XMLFormPropValueTContext_Impl : public XMLTransformerContext
46cdf0e10cSrcweir {
47cdf0e10cSrcweir OUString m_aAttrQName;
48cdf0e10cSrcweir ::rtl::OUString m_aCharacters;
49cdf0e10cSrcweir sal_Bool m_bPersistent;
50cdf0e10cSrcweir sal_Bool m_bIsVoid;
51cdf0e10cSrcweir
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir TYPEINFO();
54cdf0e10cSrcweir
55cdf0e10cSrcweir // element content persistence only
56cdf0e10cSrcweir XMLFormPropValueTContext_Impl( XMLTransformerBase& rTransformer,
57cdf0e10cSrcweir const OUString& rQName );
58cdf0e10cSrcweir XMLFormPropValueTContext_Impl( XMLTransformerBase& rTransformer,
59cdf0e10cSrcweir const OUString& rQName,
60cdf0e10cSrcweir sal_uInt16 nAttrPrefix,
61cdf0e10cSrcweir XMLTokenEnum eAttrToken );
62cdf0e10cSrcweir
63cdf0e10cSrcweir virtual ~XMLFormPropValueTContext_Impl();
64cdf0e10cSrcweir
65cdf0e10cSrcweir virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
66cdf0e10cSrcweir
67cdf0e10cSrcweir virtual void EndElement();
68cdf0e10cSrcweir
69cdf0e10cSrcweir virtual void Characters( const ::rtl::OUString& rChars );
70cdf0e10cSrcweir
71cdf0e10cSrcweir virtual sal_Bool IsPersistent() const;
72cdf0e10cSrcweir
IsVoid() const73cdf0e10cSrcweir sal_Bool IsVoid() const { return m_bIsVoid; }
GetTextContent() const74cdf0e10cSrcweir const ::rtl::OUString& GetTextContent() const { return m_aCharacters; }
75cdf0e10cSrcweir };
76cdf0e10cSrcweir
77cdf0e10cSrcweir TYPEINIT1( XMLFormPropValueTContext_Impl, XMLTransformerContext );
78cdf0e10cSrcweir
XMLFormPropValueTContext_Impl(XMLTransformerBase & rTransformer,const::rtl::OUString & rQName)79cdf0e10cSrcweir XMLFormPropValueTContext_Impl::XMLFormPropValueTContext_Impl(
80cdf0e10cSrcweir XMLTransformerBase& rTransformer,
81cdf0e10cSrcweir const ::rtl::OUString& rQName ) :
82cdf0e10cSrcweir XMLTransformerContext( rTransformer, rQName ),
83cdf0e10cSrcweir m_bPersistent( sal_True ),
84cdf0e10cSrcweir m_bIsVoid( sal_False )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
XMLFormPropValueTContext_Impl(XMLTransformerBase & rTransformer,const::rtl::OUString & rQName,sal_uInt16 nAttrPrefix,XMLTokenEnum eAttrToken)88cdf0e10cSrcweir XMLFormPropValueTContext_Impl::XMLFormPropValueTContext_Impl(
89cdf0e10cSrcweir XMLTransformerBase& rTransformer,
90cdf0e10cSrcweir const ::rtl::OUString& rQName,
91cdf0e10cSrcweir sal_uInt16 nAttrPrefix,
92cdf0e10cSrcweir XMLTokenEnum eAttrToken ) :
93cdf0e10cSrcweir XMLTransformerContext( rTransformer, rQName ),
94cdf0e10cSrcweir m_aAttrQName( rTransformer.GetNamespaceMap().GetQNameByKey(
95cdf0e10cSrcweir nAttrPrefix, GetXMLToken(eAttrToken) ) ),
96cdf0e10cSrcweir m_bPersistent( sal_True ),
97cdf0e10cSrcweir m_bIsVoid( sal_False )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
~XMLFormPropValueTContext_Impl()101cdf0e10cSrcweir XMLFormPropValueTContext_Impl::~XMLFormPropValueTContext_Impl()
102cdf0e10cSrcweir {
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
StartElement(const Reference<XAttributeList> & rAttrList)105cdf0e10cSrcweir void XMLFormPropValueTContext_Impl::StartElement(
106cdf0e10cSrcweir const Reference< XAttributeList >& rAttrList )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
109cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir const OUString& rAttrName = rAttrList->getNameByIndex( i );
112cdf0e10cSrcweir OUString aLocalName;
113cdf0e10cSrcweir sal_uInt16 nPrefix =
114cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
115cdf0e10cSrcweir &aLocalName );
116cdf0e10cSrcweir if( XML_NAMESPACE_FORM == nPrefix &&
117cdf0e10cSrcweir IsXMLToken( aLocalName, XML_PROPERTY_IS_VOID ) &&
118cdf0e10cSrcweir IsXMLToken( rAttrList->getValueByIndex( i ), XML_TRUE ) )
119cdf0e10cSrcweir m_bIsVoid = sal_True;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir }
122cdf0e10cSrcweir
EndElement()123cdf0e10cSrcweir void XMLFormPropValueTContext_Impl::EndElement()
124cdf0e10cSrcweir {
125cdf0e10cSrcweir if( !m_bPersistent )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir XMLMutableAttributeList *pMutableAttrList =
128cdf0e10cSrcweir new XMLMutableAttributeList;
129cdf0e10cSrcweir Reference< XAttributeList > xAttrList( pMutableAttrList );
130cdf0e10cSrcweir pMutableAttrList->AddAttribute( m_aAttrQName,
131cdf0e10cSrcweir m_aCharacters );
132cdf0e10cSrcweir
133cdf0e10cSrcweir OUString aElemQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
134cdf0e10cSrcweir XML_NAMESPACE_FORM, GetXMLToken(XML_LIST_VALUE) ) );
135cdf0e10cSrcweir GetTransformer().GetDocHandler()->startElement( aElemQName,
136cdf0e10cSrcweir xAttrList );
137cdf0e10cSrcweir GetTransformer().GetDocHandler()->endElement( aElemQName );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
Characters(const OUString & rChars)141cdf0e10cSrcweir void XMLFormPropValueTContext_Impl::Characters( const OUString& rChars )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir m_aCharacters += rChars;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
146cdf0e10cSrcweir
IsPersistent() const147cdf0e10cSrcweir sal_Bool XMLFormPropValueTContext_Impl::IsPersistent() const
148cdf0e10cSrcweir {
149cdf0e10cSrcweir return m_bPersistent;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir //------------------------------------------------------------------------------
153cdf0e10cSrcweir
154cdf0e10cSrcweir TYPEINIT1( XMLFormPropOOoTransformerContext, XMLTransformerContext );
155cdf0e10cSrcweir
XMLFormPropOOoTransformerContext(XMLTransformerBase & rImp,const OUString & rQName)156cdf0e10cSrcweir XMLFormPropOOoTransformerContext::XMLFormPropOOoTransformerContext(
157cdf0e10cSrcweir XMLTransformerBase& rImp,
158cdf0e10cSrcweir const OUString& rQName ) :
159cdf0e10cSrcweir XMLTransformerContext( rImp, rQName ),
160cdf0e10cSrcweir m_aElemQName( rQName ),
161cdf0e10cSrcweir m_nValueTypeAttr( -1 ),
162cdf0e10cSrcweir m_eValueToken( XML_VALUE ),
163cdf0e10cSrcweir m_eValueTypeToken( XML_TOKEN_END ),
164cdf0e10cSrcweir m_bIsList( sal_False )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
~XMLFormPropOOoTransformerContext()168cdf0e10cSrcweir XMLFormPropOOoTransformerContext::~XMLFormPropOOoTransformerContext()
169cdf0e10cSrcweir {
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const OUString & rQName,const Reference<XAttributeList> &)172cdf0e10cSrcweir XMLTransformerContext *XMLFormPropOOoTransformerContext::CreateChildContext(
173cdf0e10cSrcweir sal_uInt16 nPrefix,
174cdf0e10cSrcweir const OUString& rLocalName,
175cdf0e10cSrcweir const OUString& rQName,
176cdf0e10cSrcweir const Reference< XAttributeList >& )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir XMLTransformerContext *pContext = 0;
179cdf0e10cSrcweir
180cdf0e10cSrcweir if( XML_NAMESPACE_FORM == nPrefix &&
181cdf0e10cSrcweir IsXMLToken( rLocalName, XML_PROPERTY_VALUE ) )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir if( m_bIsList )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir pContext = new XMLFormPropValueTContext_Impl( GetTransformer(),
186cdf0e10cSrcweir rQName,
187cdf0e10cSrcweir XML_NAMESPACE_OFFICE,
188cdf0e10cSrcweir m_eValueToken );
189cdf0e10cSrcweir }
190cdf0e10cSrcweir else if( !m_xValueContext.is() )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir m_xValueContext=
193cdf0e10cSrcweir new XMLFormPropValueTContext_Impl( GetTransformer(), rQName );
194cdf0e10cSrcweir pContext = m_xValueContext.get();
195cdf0e10cSrcweir }
196cdf0e10cSrcweir }
197cdf0e10cSrcweir
198cdf0e10cSrcweir // default is ignore
199cdf0e10cSrcweir if( !pContext )
200cdf0e10cSrcweir pContext = new XMLIgnoreTransformerContext( GetTransformer(), rQName,
201cdf0e10cSrcweir sal_True, sal_True );
202cdf0e10cSrcweir return pContext;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir
StartElement(const Reference<XAttributeList> & rAttrList)205cdf0e10cSrcweir void XMLFormPropOOoTransformerContext::StartElement(
206cdf0e10cSrcweir const Reference< XAttributeList >& rAttrList )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir
209cdf0e10cSrcweir XMLTransformerActions *pActions =
210cdf0e10cSrcweir GetTransformer().GetUserDefinedActions( OOO_FORM_PROP_ACTIONS );
211cdf0e10cSrcweir OSL_ENSURE( pActions, "go no actions" );
212cdf0e10cSrcweir
213cdf0e10cSrcweir XMLMutableAttributeList *pMutableAttrList =
214cdf0e10cSrcweir new XMLMutableAttributeList( rAttrList, sal_True );
215cdf0e10cSrcweir m_xAttrList = pMutableAttrList;
216cdf0e10cSrcweir
217cdf0e10cSrcweir OUString aValueType;
218cdf0e10cSrcweir sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
219cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir const OUString& rAttrName = rAttrList->getNameByIndex( i );
222cdf0e10cSrcweir OUString aLocalName;
223cdf0e10cSrcweir sal_uInt16 nPrefix =
224cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
225cdf0e10cSrcweir &aLocalName );
226cdf0e10cSrcweir XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
227cdf0e10cSrcweir XMLTransformerActions::const_iterator aIter =
228cdf0e10cSrcweir pActions->find( aKey );
229cdf0e10cSrcweir if( !(aIter == pActions->end() ) )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir const OUString& rAttrValue = rAttrList->getValueByIndex( i );
232cdf0e10cSrcweir switch( (*aIter).second.m_nActionType )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir case XML_ATACTION_RENAME:
235cdf0e10cSrcweir if( IsXMLToken( aLocalName, XML_PROPERTY_TYPE ) )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir aValueType = rAttrValue;
238cdf0e10cSrcweir m_nValueTypeAttr = i;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir {
241cdf0e10cSrcweir OUString aNewAttrQName(
242cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey(
243cdf0e10cSrcweir (*aIter).second.GetQNamePrefixFromParam1(),
244cdf0e10cSrcweir ::xmloff::token::GetXMLToken(
245cdf0e10cSrcweir (*aIter).second.GetQNameTokenFromParam1()) ) );
246cdf0e10cSrcweir pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
247cdf0e10cSrcweir }
248cdf0e10cSrcweir break;
249cdf0e10cSrcweir case XML_ATACTION_REMOVE:
250cdf0e10cSrcweir if( IsXMLToken( aLocalName, XML_PROPERTY_IS_LIST ) )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir m_aElemQName =
253cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey(
254cdf0e10cSrcweir XML_NAMESPACE_FORM, GetXMLToken( XML_LIST_PROPERTY ) );
255cdf0e10cSrcweir m_bIsList = sal_True;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir pMutableAttrList->RemoveAttributeByIndex( i );
258cdf0e10cSrcweir --i;
259cdf0e10cSrcweir --nAttrCount;
260cdf0e10cSrcweir break;
261cdf0e10cSrcweir default:
262cdf0e10cSrcweir OSL_ENSURE( !this, "unknown action" );
263cdf0e10cSrcweir break;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir }
266cdf0e10cSrcweir }
267cdf0e10cSrcweir
268cdf0e10cSrcweir if( aValueType.getLength() )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir if( IsXMLToken( aValueType, XML_STRING ) )
271cdf0e10cSrcweir m_eValueToken = XML_STRING_VALUE;
272cdf0e10cSrcweir else if( IsXMLToken( aValueType, XML_BOOLEAN ) )
273cdf0e10cSrcweir m_eValueToken = XML_BOOLEAN_VALUE;
274cdf0e10cSrcweir else if( IsXMLToken( aValueType, XML_SHORT ) ||
275cdf0e10cSrcweir IsXMLToken( aValueType, XML_INT ) ||
276cdf0e10cSrcweir IsXMLToken( aValueType, XML_LONG ) ||
277cdf0e10cSrcweir IsXMLToken( aValueType, XML_DOUBLE ) )
278cdf0e10cSrcweir m_eValueTypeToken = XML_FLOAT;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
EndElement()282cdf0e10cSrcweir void XMLFormPropOOoTransformerContext::EndElement()
283cdf0e10cSrcweir {
284cdf0e10cSrcweir if( m_xValueContext.is() )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir if( m_xValueContext->IsVoid() )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir m_eValueTypeToken = XML_VOID;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir else
291cdf0e10cSrcweir {
292cdf0e10cSrcweir OUString aAttrQName(
293cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey(
294cdf0e10cSrcweir XML_NAMESPACE_OFFICE, GetXMLToken(m_eValueToken) ) );
295cdf0e10cSrcweir static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
296cdf0e10cSrcweir ->AddAttribute( aAttrQName, m_xValueContext->GetTextContent() );
297cdf0e10cSrcweir }
298cdf0e10cSrcweir }
299cdf0e10cSrcweir
300cdf0e10cSrcweir if( m_nValueTypeAttr != -1 && m_eValueTypeToken != XML_TOKEN_END )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
303cdf0e10cSrcweir ->SetValueByIndex( m_nValueTypeAttr ,
304cdf0e10cSrcweir GetXMLToken( m_eValueTypeToken ) );
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
307cdf0e10cSrcweir GetTransformer().GetDocHandler()->startElement( m_aElemQName,
308cdf0e10cSrcweir m_xAttrList );
309cdf0e10cSrcweir GetTransformer().GetDocHandler()->endElement( m_aElemQName );
310cdf0e10cSrcweir }
311