LibreOffice Module xmloff (master) 1
MergeElemTContext.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 "MergeElemTContext.hxx"
21#include "MutableAttrList.hxx"
22#include "TransformerBase.hxx"
25#include "IgnoreTContext.hxx"
27#include <osl/diagnose.h>
28
29using namespace ::com::sun::star::uno;
30using namespace ::com::sun::star::xml::sax;
31using namespace ::xmloff::token;
32
33namespace {
34
35class XMLParagraphTransformerContext : public XMLTransformerContext
36{
37public:
38 XMLParagraphTransformerContext( XMLTransformerBase& rTransformer,
39 const OUString& rQName );
40
41 // Create a children element context. By default, the import's
42 // CreateContext method is called to create a new default context.
44 const OUString& rLocalName,
45 const OUString& rQName,
46 const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
47};
48
49}
50
51XMLParagraphTransformerContext::XMLParagraphTransformerContext(
53 const OUString& rQName ) :
54 XMLTransformerContext( rImp, rQName )
55{
56}
57
58rtl::Reference<XMLTransformerContext> XMLParagraphTransformerContext::CreateChildContext(
59 sal_uInt16 /*nPrefix*/,
60 const OUString& /*rLocalName*/,
61 const OUString& rQName,
62 const Reference< XAttributeList >& )
63{
64 return new XMLIgnoreTransformerContext( GetTransformer(),
65 rQName, true );
66}
67
68namespace {
69
70class XMLPersTextContentRNGTransformTContext : public XMLPersTextContentTContext
71{
72public:
73 XMLPersTextContentRNGTransformTContext(
74 XMLTransformerBase& rTransformer,
75 const OUString& rQName,
76 sal_uInt16 nPrefix,
78
79 virtual void Characters( const OUString& rChars ) override;
80};
81
82}
83
84XMLPersTextContentRNGTransformTContext::XMLPersTextContentRNGTransformTContext(
85 XMLTransformerBase& rTransformer,
86 const OUString& rQName,
87 sal_uInt16 nPrefix,
90 rTransformer, rQName, nPrefix, eToken )
91{}
92
93void XMLPersTextContentRNGTransformTContext::Characters( const OUString& rChars )
94{
95 OUString aConvChars( rChars );
98}
99
100
102{
103 for( const auto& rChildContext : m_aChildContexts )
104 {
105 XMLPersTextContentTContext *pContext = rChildContext.get();
106 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
107 ->AddAttribute( pContext->GetExportQName(),
108 pContext->GetTextContent() );
109 }
111
113}
114
116 XMLTransformerBase& rImp,
117 const OUString& rQName,
118 sal_uInt16 nActionMap ) :
119 XMLTransformerContext( rImp, rQName ),
120 m_nActionMap( nActionMap ),
121 m_bStartElementExported( false )
122{
123}
124
126 const Reference< XAttributeList >& rAttrList )
127{
129 new XMLMutableAttributeList( rAttrList, true );
130 m_xAttrList = pMutableAttrList;
131
132 sal_Int16 nAttrCount = m_xAttrList.is() ? m_xAttrList->getLength() : 0;
133 for( sal_Int16 i=0; i < nAttrCount; i++ )
134 {
135 const OUString& rAttrName = m_xAttrList->getNameByIndex( i );
136 OUString aLocalName;
137 sal_uInt16 nPrefix =
139 &aLocalName );
140 bool bRemove = true;
141 if( XML_NAMESPACE_OFFICE == nPrefix)
142 {
143 if (IsXMLToken( aLocalName, XML_DISPLAY ) )
144 bRemove = false;
145 else if (IsXMLToken( aLocalName, XML_AUTHOR ) )
146 bRemove = false;
147 else if (IsXMLToken( aLocalName, XML_CREATE_DATE ) )
148 bRemove = false;
149 else if (IsXMLToken( aLocalName, XML_CREATE_DATE_STRING ) )
150 bRemove = false;
151 }
152 if (bRemove)
153 {
154 pMutableAttrList->RemoveAttributeByIndex( i );
155 --i;
156 --nAttrCount;
157 }
158 }
159}
160
162 sal_uInt16 nPrefix,
163 const OUString& rLocalName,
164 const OUString& rQName,
165 const Reference< XAttributeList >& rAttrList )
166{
168
170 {
171 XMLTransformerActions *pActions =
173 OSL_ENSURE( pActions, "go no actions" );
174 if( pActions )
175 {
176 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
177 XMLTransformerActions::const_iterator aIter =
178 pActions->find( aKey );
179
180 if( aIter != pActions->end() )
181 {
182 switch( (*aIter).second.m_nActionType )
183 {
185 {
187 new XMLPersTextContentRNGTransformTContext(
188 GetTransformer(), rQName,
189 (*aIter).second.GetQNamePrefixFromParam1(),
190 (*aIter).second.GetQNameTokenFromParam1() ));
191 m_aChildContexts.push_back(pTC);
192 pContext = pTC;
193 }
194 break;
196 {
199 GetTransformer(), rQName,
200 (*aIter).second.GetQNamePrefixFromParam1(),
201 (*aIter).second.GetQNameTokenFromParam1() ));
202 m_aChildContexts.push_back(pTC);
203 pContext = pTC;
204 }
205 break;
207 {
210 pContext.set(
211 new XMLParagraphTransformerContext( GetTransformer(),
212 rQName));
213 }
214 break;
215 default:
216 OSL_ENSURE( false, "unknown action" );
217 break;
218 }
219 }
220 }
221 }
222 else
223 {
224 XMLTransformerActions *pActions =
226 OSL_ENSURE( pActions, "go no actions" );
227 if( pActions )
228 {
229 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
230 XMLTransformerActions::const_iterator aIter =
231 pActions->find( aKey );
232
233 if( aIter != pActions->end() )
234 {
235 switch( (*aIter).second.m_nActionType )
236 {
238 {
241 pContext.set(
242 new XMLParagraphTransformerContext( GetTransformer(),
243 rQName));
244 }
245 break;
246 default:
247 OSL_ENSURE( false, "unknown action" );
248 break;
249 }
250 }
251 }
252 }
253
254 // default is copying
255 if( !pContext.is() )
256 {
260 rLocalName,
261 rQName,
262 rAttrList );
263 }
264
265 return pContext;
266}
267
269{
273}
274
276{
277 // ignore
278}
279
280/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ XML_ETACTION_EXTRACT_CHARACTERS
@ XML_ETACTION_MOVE_TO_ATTR
@ XML_ETACTION_MOVE_TO_ATTR_RNG2ISO_DATETIME
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
XMLPersTextContentTContextVector m_aChildContexts
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
css::uno::Reference< css::xml::sax::XAttributeList > m_xAttrList
virtual void EndElement() override
XMLMergeElemTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName, sal_uInt16 nActionMap)
virtual void Characters(const OUString &rChars) override
const OUString & GetExportQName() const
virtual void Characters(const OUString &rChars) override
const OUString & GetTextContent() const
virtual XMLTransformerActions * GetUserDefinedActions(sal_uInt16 n)
static bool ConvertRNGDateTimeToISO(OUString &rDateTime)
converts the '.
SvXMLNamespaceMap & GetNamespaceMap()
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
XMLTransformerBase & GetTransformer()
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
int i
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
@ XML_CREATE_DATE_STRING
Definition: xmltoken.hxx:543
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
XMLTokenEnum eToken
Definition: xmltoken.cxx:40