LibreOffice Module xmloff (master) 1
FormPropOOoTContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "MutableAttrList.hxx"
23#include "IgnoreTContext.hxx"
24#include "ActionMapTypesOOo.hxx"
27#include "TransformerBase.hxx"
29#include <osl/diagnose.h>
30
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::xml::sax;
33using namespace ::xmloff::token;
34
36{
37 OUString m_aCharacters;
39
40public:
41 // element content persistence only
43 const OUString& rQName );
44
45 virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
46
47 virtual void EndElement() override;
48
49 virtual void Characters( const OUString& rChars ) override;
50
51 virtual bool IsPersistent() const override;
52
53 bool IsVoid() const { return m_bIsVoid; }
54 const OUString& GetTextContent() const { return m_aCharacters; }
55};
56
58 XMLTransformerBase& rTransformer,
59 const OUString& rQName ) :
60 XMLTransformerContext( rTransformer, rQName ),
61 m_bIsVoid( false )
62{
63}
64
66 const Reference< XAttributeList >& rAttrList )
67{
68 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
69 for( sal_Int16 i=0; i < nAttrCount; i++ )
70 {
71 const OUString& rAttrName = rAttrList->getNameByIndex( i );
72 OUString aLocalName;
73 sal_uInt16 nPrefix =
75 &aLocalName );
76 if( XML_NAMESPACE_FORM == nPrefix &&
77 IsXMLToken( aLocalName, XML_PROPERTY_IS_VOID ) &&
78 IsXMLToken( rAttrList->getValueByIndex( i ), XML_TRUE ) )
79 m_bIsVoid = true;
80 }
81}
82
84{
85}
86
87void XMLFormPropValueTContext_Impl::Characters( const OUString& rChars )
88{
89 m_aCharacters += rChars;
90}
91
93{
94 return true;
95}
96
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 ),
105 m_bIsList( false )
106{
107}
108
110{
111}
112
114 sal_uInt16 nPrefix,
115 const OUString& rLocalName,
116 const OUString& rQName,
117 const Reference< XAttributeList >& )
118{
120
121 if( XML_NAMESPACE_FORM == nPrefix &&
122 IsXMLToken( rLocalName, XML_PROPERTY_VALUE ) )
123 {
124 if( m_bIsList )
125 {
127 rQName ));
128 }
129 else if( !m_xValueContext.is() )
130 {
133 pContext = m_xValueContext;
134 }
135 }
136
137 // default is ignore
138 if( !pContext.is() )
139 pContext.set(new XMLIgnoreTransformerContext( GetTransformer(), rQName,
140 true, true ));
141 return pContext;
142}
143
145 const Reference< XAttributeList >& rAttrList )
146{
147
148 XMLTransformerActions *pActions =
150 OSL_ENSURE( pActions, "go no actions" );
151
153 new XMLMutableAttributeList( rAttrList, true );
154 m_xAttrList = pMutableAttrList;
155
156 OUString aValueType;
157 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
158 for( sal_Int16 i=0; i < nAttrCount; i++ )
159 {
160 const OUString& rAttrName = rAttrList->getNameByIndex( i );
161 OUString aLocalName;
162 sal_uInt16 nPrefix =
164 &aLocalName );
165 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
166 XMLTransformerActions::const_iterator aIter =
167 pActions->find( aKey );
168 if( aIter != pActions->end() )
169 {
170 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
171 switch( (*aIter).second.m_nActionType )
172 {
174 if( IsXMLToken( aLocalName, XML_PROPERTY_TYPE ) )
175 {
176 aValueType = rAttrValue;
178 }
179 {
180 OUString aNewAttrQName(
181 GetTransformer().GetNamespaceMap().GetQNameByKey(
182 (*aIter).second.GetQNamePrefixFromParam1(),
184 (*aIter).second.GetQNameTokenFromParam1()) ) );
185 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
186 }
187 break;
189 if( IsXMLToken( aLocalName, XML_PROPERTY_IS_LIST ) )
190 {
194 m_bIsList = true;
195 }
196 pMutableAttrList->RemoveAttributeByIndex( i );
197 --i;
198 --nAttrCount;
199 break;
200 default:
201 OSL_ENSURE( false, "unknown action" );
202 break;
203 }
204 }
205 }
206
207 if( !aValueType.isEmpty() )
208 {
209 if( IsXMLToken( aValueType, XML_STRING ) )
211 else if( IsXMLToken( aValueType, XML_BOOLEAN ) )
213 else if( IsXMLToken( aValueType, XML_SHORT ) ||
214 IsXMLToken( aValueType, XML_INT ) ||
215 IsXMLToken( aValueType, XML_LONG ) ||
216 IsXMLToken( aValueType, XML_DOUBLE ) )
218 }
219}
220
222{
223 if( m_xValueContext.is() )
224 {
225 if( m_xValueContext->IsVoid() )
226 {
228 }
229 else
230 {
231 OUString aAttrQName(
232 GetTransformer().GetNamespaceMap().GetQNameByKey(
234 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
235 ->AddAttribute( aAttrQName, m_xValueContext->GetTextContent() );
236 }
237 }
238
240 {
241 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
242 ->SetValueByIndex( m_nValueTypeAttr ,
244 }
245
247 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
248}
249
250/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ OOO_FORM_PROP_ACTIONS
@ XML_ATACTION_REMOVE
@ XML_ATACTION_RENAME
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
::xmloff::token::XMLTokenEnum m_eValueTypeToken
css::uno::Reference< css::xml::sax::XAttributeList > m_xAttrList
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
::rtl::Reference< XMLFormPropValueTContext_Impl > m_xValueContext
virtual ~XMLFormPropOOoTransformerContext() override
::xmloff::token::XMLTokenEnum m_eValueToken
XMLFormPropOOoTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName)
const OUString & GetTextContent() const
virtual void Characters(const OUString &rChars) override
virtual bool IsPersistent() const override
XMLFormPropValueTContext_Impl(XMLTransformerBase &rTransformer, const OUString &rQName)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual void EndElement() override
virtual XMLTransformerActions * GetUserDefinedActions(sal_uInt16 n)
SvXMLNamespaceMap & GetNamespaceMap()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
XMLTransformerBase & GetTransformer()
int i
Handling of tokens in XML:
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3581
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3525
constexpr sal_uInt16 XML_NAMESPACE_FORM
constexpr sal_uInt16 XML_NAMESPACE_OFFICE