LibreOffice Module xmloff (master) 1
FormPropOASISTContext.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"
26#include "TransformerBase.hxx"
28#include <osl/diagnose.h>
29
30using namespace ::com::sun::star::uno;
31using namespace ::com::sun::star::xml::sax;
32using namespace ::xmloff::token;
33
35 std::u16string_view rValue )
36{
38 bool bNeg = false;
39 sal_uInt32 nVal = 0;
40
41 sal_Int32 nPos = 0;
42 sal_Int32 nLen = rValue.size();
43
44 // skip white space
45 while( nPos < nLen && ' ' == rValue[nPos] )
46 nPos++;
47
48 if( nPos < nLen && '-' == rValue[nPos] )
49 {
50 bNeg = true;
51 nPos++;
52 }
53
54 // get number
55 bool bOverflow = false;
56 while( nPos < nLen &&
57 '0' <= rValue[nPos] &&
58 '9' >= rValue[nPos] )
59 {
60 nVal *= 10;
61 nVal += (rValue[nPos] - '0');
62 bOverflow |= (nVal > (bNeg ? 2147483648UL : 2147483647UL));
63 nPos++;
64 }
65
66 // skip white space
67 while( nPos < nLen && ' ' == rValue[nPos] )
68 nPos++;
69
70 if( nPos == nLen )
71 {
72 // It's an integer number
73 if( bOverflow )
74 eRet = XML_LONG;
75 else if( nVal > (bNeg ? 32768UL : 32767UL) )
76 eRet = XML_INT;
77 else
78 eRet = XML_SHORT;
79 }
80
81 return eRet;
82}
83
86 const OUString& rQName,
87 XMLTokenEnum eLocalName ) :
90 m_bIsList( XML_LIST_PROPERTY == eLocalName),
91 m_bIsListValue( XML_LIST_VALUE == eLocalName)
92{
93}
94
96{
97}
98
100 const Reference< XAttributeList >& rAttrList )
101{
102
103 XMLTransformerActions *pActions =
105 OSL_ENSURE( pActions, "go no actions" );
106
108 new XMLMutableAttributeList( rAttrList );
109 Reference< XAttributeList > xAttrList( pMutableAttrList );
110
111 sal_Int16 nValueTypeAttr = -1;
112 OUString aValue;
113 bool bIsVoid = false;
114 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
115 for( sal_Int16 i=0; i < nAttrCount; i++ )
116 {
117 const OUString& rAttrName = xAttrList->getNameByIndex( i );
118 OUString aLocalName;
119 sal_uInt16 nPrefix =
121 &aLocalName );
122 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
123 XMLTransformerActions::const_iterator aIter =
124 pActions->find( aKey );
125 if( aIter != pActions->end() )
126 {
127 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
128 switch( (*aIter).second.m_nActionType )
129 {
131 if( IsXMLToken( aLocalName, XML_VALUE_TYPE ) )
132 {
133 if( IsXMLToken( rAttrValue, XML_FLOAT ) )
134 {
135 nValueTypeAttr = i;
136 }
137 else if( IsXMLToken( rAttrValue, XML_VOID ) )
138 {
139 pMutableAttrList->SetValueByIndex( i,
141 bIsVoid = true;
142 }
143 }
144 {
145 OUString aNewAttrQName(
146 GetTransformer().GetNamespaceMap().GetQNameByKey(
147 (*aIter).second.GetQNamePrefixFromParam1(),
149 (*aIter).second.GetQNameTokenFromParam1()) ) );
150 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
151 }
152 break;
154 if( !IsXMLToken( aLocalName, XML_CURRENCY ) )
155 aValue = rAttrValue;
156 pMutableAttrList->RemoveAttributeByIndex( i );
157 --i;
158 --nAttrCount;
159 break;
160 default:
161 OSL_ENSURE( false, "unknown action" );
162 break;
163 }
164 }
165 }
166 if( m_bIsList )
167 {
168 OUString aNewAttrQName(
169 GetTransformer().GetNamespaceMap().GetQNameByKey(
172 pMutableAttrList->AddAttribute( aNewAttrQName,
174 }
175
176 if( nValueTypeAttr != -1 )
177 pMutableAttrList->SetValueByIndex( nValueTypeAttr,
178 GetXMLToken( GetValueType( aValue ) ) );
179
180 if( !m_bIsListValue )
182 if( m_bIsList )
183 return;
184
185 pMutableAttrList = new XMLMutableAttributeList;
186 xAttrList = pMutableAttrList;
187 if( bIsVoid )
188 {
189 OUString aNewAttrQName(
190 GetTransformer().GetNamespaceMap().GetQNameByKey(
192 pMutableAttrList->AddAttribute( aNewAttrQName,
194 }
195
196 OUString aValueElemQName(
197 GetTransformer().GetNamespaceMap().GetQNameByKey(
199 GetTransformer().GetDocHandler()->startElement( aValueElemQName,
200 xAttrList );
201 GetTransformer().GetDocHandler()->characters( aValue );
202 GetTransformer().GetDocHandler()->endElement( aValueElemQName );
203}
204
206{
207 if( !m_bIsListValue )
209}
210
211/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ OASIS_FORM_PROP_ACTIONS
@ XML_ATACTION_REMOVE
@ XML_ATACTION_RENAME
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
XMLFormPropOASISTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName, ::xmloff::token::XMLTokenEnum eLocalName)
::xmloff::token::XMLTokenEnum GetValueType(std::u16string_view rValue)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual ~XMLFormPropOASISTransformerContext() override
virtual void EndElement() override
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual XMLTransformerActions * GetUserDefinedActions(sal_uInt16 n)
SvXMLNamespaceMap & GetNamespaceMap()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
XMLTransformerBase & GetTransformer()
sal_uInt16 nPos
int i
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
constexpr sal_uInt16 XML_NAMESPACE_FORM