1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "MutableAttrList.hxx"
21 #include <xmloff/xmlnamespace.hxx>
22 #include <xmloff/namespacemap.hxx>
23 #include "IgnoreTContext.hxx"
24 #include "ActionMapTypesOOo.hxx"
25 #include "AttrTransformerAction.hxx"
26 #include "TransformerActions.hxx"
27 #include "TransformerBase.hxx"
28 #include "FormPropOOoTContext.hxx"
29 #include <osl/diagnose.h>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::xml::sax
;
33 using namespace ::xmloff::token
;
35 class XMLFormPropValueTContext_Impl
: public XMLTransformerContext
37 OUString m_aCharacters
;
41 // element content persistence only
42 XMLFormPropValueTContext_Impl( XMLTransformerBase
& rTransformer
,
43 const OUString
& rQName
);
45 virtual void StartElement( const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
) override
;
47 virtual void EndElement() override
;
49 virtual void Characters( const OUString
& rChars
) override
;
51 virtual bool IsPersistent() const override
;
53 bool IsVoid() const { return m_bIsVoid
; }
54 const OUString
& GetTextContent() const { return m_aCharacters
; }
57 XMLFormPropValueTContext_Impl::XMLFormPropValueTContext_Impl(
58 XMLTransformerBase
& rTransformer
,
59 const OUString
& rQName
) :
60 XMLTransformerContext( rTransformer
, rQName
),
65 void XMLFormPropValueTContext_Impl::StartElement(
66 const Reference
< XAttributeList
>& rAttrList
)
68 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
69 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
71 const OUString aAttrName
= rAttrList
->getNameByIndex( i
);
74 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName
,
76 if( XML_NAMESPACE_FORM
== nPrefix
&&
77 IsXMLToken( aLocalName
, XML_PROPERTY_IS_VOID
) &&
78 IsXMLToken( rAttrList
->getValueByIndex( i
), XML_TRUE
) )
83 void XMLFormPropValueTContext_Impl::EndElement()
87 void XMLFormPropValueTContext_Impl::Characters( const OUString
& rChars
)
89 m_aCharacters
+= rChars
;
92 bool XMLFormPropValueTContext_Impl::IsPersistent() const
97 XMLFormPropOOoTransformerContext::XMLFormPropOOoTransformerContext(
98 XMLTransformerBase
& rImp
,
99 const OUString
& rQName
) :
100 XMLTransformerContext( rImp
, rQName
),
101 m_aElemQName( rQName
),
102 m_nValueTypeAttr( -1 ),
103 m_eValueToken( XML_VALUE
),
104 m_eValueTypeToken( XML_TOKEN_END
),
109 XMLFormPropOOoTransformerContext::~XMLFormPropOOoTransformerContext()
113 rtl::Reference
<XMLTransformerContext
> XMLFormPropOOoTransformerContext::CreateChildContext(
115 const OUString
& rLocalName
,
116 const OUString
& rQName
,
117 const Reference
< XAttributeList
>& )
119 rtl::Reference
<XMLTransformerContext
> pContext
;
121 if( XML_NAMESPACE_FORM
== nPrefix
&&
122 IsXMLToken( rLocalName
, XML_PROPERTY_VALUE
) )
126 pContext
.set(new XMLFormPropValueTContext_Impl( GetTransformer(),
129 else if( !m_xValueContext
.is() )
132 new XMLFormPropValueTContext_Impl( GetTransformer(), rQName
);
133 pContext
= m_xValueContext
;
139 pContext
.set(new XMLIgnoreTransformerContext( GetTransformer(), rQName
,
144 void XMLFormPropOOoTransformerContext::StartElement(
145 const Reference
< XAttributeList
>& rAttrList
)
148 XMLTransformerActions
*pActions
=
149 GetTransformer().GetUserDefinedActions( OOO_FORM_PROP_ACTIONS
);
150 OSL_ENSURE( pActions
, "go no actions" );
152 rtl::Reference
<XMLMutableAttributeList
> pMutableAttrList
=
153 new XMLMutableAttributeList( rAttrList
, true );
154 m_xAttrList
= pMutableAttrList
;
157 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
158 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
160 const OUString aAttrName
= rAttrList
->getNameByIndex( i
);
163 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName
,
165 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
166 XMLTransformerActions::const_iterator aIter
=
167 pActions
->find( aKey
);
168 if( aIter
!= pActions
->end() )
170 const OUString aAttrValue
= rAttrList
->getValueByIndex( i
);
171 switch( (*aIter
).second
.m_nActionType
)
173 case XML_ATACTION_RENAME
:
174 if( IsXMLToken( aLocalName
, XML_PROPERTY_TYPE
) )
176 aValueType
= aAttrValue
;
177 m_nValueTypeAttr
= i
;
180 OUString
aNewAttrQName(
181 GetTransformer().GetNamespaceMap().GetQNameByKey(
182 (*aIter
).second
.GetQNamePrefixFromParam1(),
183 ::xmloff::token::GetXMLToken(
184 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
185 pMutableAttrList
->RenameAttributeByIndex( i
, aNewAttrQName
);
188 case XML_ATACTION_REMOVE
:
189 if( IsXMLToken( aLocalName
, XML_PROPERTY_IS_LIST
) )
192 GetTransformer().GetNamespaceMap().GetQNameByKey(
193 XML_NAMESPACE_FORM
, GetXMLToken( XML_LIST_PROPERTY
) );
196 pMutableAttrList
->RemoveAttributeByIndex( i
);
201 OSL_ENSURE( false, "unknown action" );
207 if( !aValueType
.isEmpty() )
209 if( IsXMLToken( aValueType
, XML_STRING
) )
210 m_eValueToken
= XML_STRING_VALUE
;
211 else if( IsXMLToken( aValueType
, XML_BOOLEAN
) )
212 m_eValueToken
= XML_BOOLEAN_VALUE
;
213 else if( IsXMLToken( aValueType
, XML_SHORT
) ||
214 IsXMLToken( aValueType
, XML_INT
) ||
215 IsXMLToken( aValueType
, XML_LONG
) ||
216 IsXMLToken( aValueType
, XML_DOUBLE
) )
217 m_eValueTypeToken
= XML_FLOAT
;
221 void XMLFormPropOOoTransformerContext::EndElement()
223 if( m_xValueContext
.is() )
225 if( m_xValueContext
->IsVoid() )
227 m_eValueTypeToken
= XML_VOID
;
232 GetTransformer().GetNamespaceMap().GetQNameByKey(
233 XML_NAMESPACE_OFFICE
, GetXMLToken(m_eValueToken
) ) );
234 m_xAttrList
->AddAttribute( aAttrQName
, m_xValueContext
->GetTextContent() );
238 if( m_nValueTypeAttr
!= -1 && m_eValueTypeToken
!= XML_TOKEN_END
)
240 m_xAttrList
->SetValueByIndex( m_nValueTypeAttr
,
241 GetXMLToken( m_eValueTypeToken
) );
244 GetTransformer().GetDocHandler()->startElement( m_aElemQName
, m_xAttrList
);
245 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */