Teach symstore more duplicated DLLs
[LibreOffice.git] / xmloff / source / transform / MergeElemTContext.cxx
blobac10b30442828781fd69d3192cfbe2a506ccdda3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "MergeElemTContext.hxx"
21 #include "MutableAttrList.hxx"
22 #include "TransformerBase.hxx"
23 #include "TransformerActions.hxx"
24 #include "ElemTransformerAction.hxx"
25 #include "IgnoreTContext.hxx"
26 #include <xmloff/xmlnmspe.hxx>
27 #include <osl/diagnose.h>
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::xml::sax;
31 using namespace ::xmloff::token;
33 class XMLParagraphTransformerContext : public XMLTransformerContext
35 public:
36 XMLParagraphTransformerContext( XMLTransformerBase& rTransformer,
37 const OUString& rQName );
39 // Create a children element context. By default, the import's
40 // CreateContext method is called to create a new default context.
41 virtual rtl::Reference<XMLTransformerContext> CreateChildContext( sal_uInt16 nPrefix,
42 const OUString& rLocalName,
43 const OUString& rQName,
44 const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
47 XMLParagraphTransformerContext::XMLParagraphTransformerContext(
48 XMLTransformerBase& rImp,
49 const OUString& rQName ) :
50 XMLTransformerContext( rImp, rQName )
54 rtl::Reference<XMLTransformerContext> XMLParagraphTransformerContext::CreateChildContext(
55 sal_uInt16 /*nPrefix*/,
56 const OUString& /*rLocalName*/,
57 const OUString& rQName,
58 const Reference< XAttributeList >& )
60 return new XMLIgnoreTransformerContext( GetTransformer(),
61 rQName, true );
64 class XMLPersTextContentRNGTransformTContext : public XMLPersTextContentTContext
66 public:
67 XMLPersTextContentRNGTransformTContext(
68 XMLTransformerBase& rTransformer,
69 const OUString& rQName,
70 sal_uInt16 nPrefix,
71 ::xmloff::token::XMLTokenEnum eToken );
73 virtual void Characters( const OUString& rChars ) override;
76 XMLPersTextContentRNGTransformTContext::XMLPersTextContentRNGTransformTContext(
77 XMLTransformerBase& rTransformer,
78 const OUString& rQName,
79 sal_uInt16 nPrefix,
80 ::xmloff::token::XMLTokenEnum eToken ) :
81 XMLPersTextContentTContext(
82 rTransformer, rQName, nPrefix, eToken )
85 void XMLPersTextContentRNGTransformTContext::Characters( const OUString& rChars )
87 OUString aConvChars( rChars );
88 XMLTransformerBase::ConvertRNGDateTimeToISO( aConvChars );
89 XMLPersTextContentTContext::Characters( aConvChars );
93 void XMLMergeElemTransformerContext::ExportStartElement()
95 for( const auto& rChildContext : m_aChildContexts )
97 XMLPersTextContentTContext *pContext = rChildContext.get();
98 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
99 ->AddAttribute( pContext->GetExportQName(),
100 pContext->GetTextContent() );
102 XMLTransformerContext::StartElement( m_xAttrList );
104 m_bStartElementExported = true;
107 XMLMergeElemTransformerContext::XMLMergeElemTransformerContext(
108 XMLTransformerBase& rImp,
109 const OUString& rQName,
110 sal_uInt16 nActionMap ) :
111 XMLTransformerContext( rImp, rQName ),
112 m_nActionMap( nActionMap ),
113 m_bStartElementExported( false )
117 void XMLMergeElemTransformerContext::StartElement(
118 const Reference< XAttributeList >& rAttrList )
120 XMLMutableAttributeList *pMutableAttrList =
121 new XMLMutableAttributeList( rAttrList, true );
122 m_xAttrList = pMutableAttrList;
124 sal_Int16 nAttrCount = m_xAttrList.is() ? m_xAttrList->getLength() : 0;
125 for( sal_Int16 i=0; i < nAttrCount; i++ )
127 const OUString& rAttrName = m_xAttrList->getNameByIndex( i );
128 OUString aLocalName;
129 sal_uInt16 nPrefix =
130 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
131 &aLocalName );
132 bool bRemove = true;
133 if( XML_NAMESPACE_OFFICE == nPrefix)
135 if (IsXMLToken( aLocalName, XML_DISPLAY ) )
136 bRemove = false;
137 else if (IsXMLToken( aLocalName, XML_AUTHOR ) )
138 bRemove = false;
139 else if (IsXMLToken( aLocalName, XML_CREATE_DATE ) )
140 bRemove = false;
141 else if (IsXMLToken( aLocalName, XML_CREATE_DATE_STRING ) )
142 bRemove = false;
144 if (bRemove)
146 pMutableAttrList->RemoveAttributeByIndex( i );
147 --i;
148 --nAttrCount;
153 rtl::Reference<XMLTransformerContext> XMLMergeElemTransformerContext::CreateChildContext(
154 sal_uInt16 nPrefix,
155 const OUString& rLocalName,
156 const OUString& rQName,
157 const Reference< XAttributeList >& rAttrList )
159 rtl::Reference<XMLTransformerContext> pContext;
161 if( !m_bStartElementExported )
163 XMLTransformerActions *pActions =
164 GetTransformer().GetUserDefinedActions( m_nActionMap );
165 OSL_ENSURE( pActions, "go no actions" );
166 if( pActions )
168 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
169 XMLTransformerActions::const_iterator aIter =
170 pActions->find( aKey );
172 if( aIter != pActions->end() )
174 switch( (*aIter).second.m_nActionType )
176 case XML_ETACTION_MOVE_TO_ATTR_RNG2ISO_DATETIME:
178 rtl::Reference<XMLPersTextContentTContext> pTC(
179 new XMLPersTextContentRNGTransformTContext(
180 GetTransformer(), rQName,
181 (*aIter).second.GetQNamePrefixFromParam1(),
182 (*aIter).second.GetQNameTokenFromParam1() ));
183 m_aChildContexts.push_back(pTC);
184 pContext.set(pTC.get());
186 break;
187 case XML_ETACTION_MOVE_TO_ATTR:
189 rtl::Reference<XMLPersTextContentTContext> pTC(
190 new XMLPersTextContentTContext(
191 GetTransformer(), rQName,
192 (*aIter).second.GetQNamePrefixFromParam1(),
193 (*aIter).second.GetQNameTokenFromParam1() ));
194 m_aChildContexts.push_back(pTC);
195 pContext.set(pTC.get());
197 break;
198 case XML_ETACTION_EXTRACT_CHARACTERS:
200 if( !m_bStartElementExported )
201 ExportStartElement();
202 pContext.set(
203 new XMLParagraphTransformerContext( GetTransformer(),
204 rQName));
206 break;
207 default:
208 OSL_ENSURE( false, "unknown action" );
209 break;
214 else
216 XMLTransformerActions *pActions =
217 GetTransformer().GetUserDefinedActions( m_nActionMap );
218 OSL_ENSURE( pActions, "go no actions" );
219 if( pActions )
221 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
222 XMLTransformerActions::const_iterator aIter =
223 pActions->find( aKey );
225 if( aIter != pActions->end() )
227 switch( (*aIter).second.m_nActionType )
229 case XML_ETACTION_EXTRACT_CHARACTERS:
231 if( !m_bStartElementExported )
232 ExportStartElement();
233 pContext.set(
234 new XMLParagraphTransformerContext( GetTransformer(),
235 rQName));
237 break;
238 default:
239 OSL_ENSURE( false, "unknown action" );
240 break;
246 // default is copying
247 if( !pContext.is() )
249 if( !m_bStartElementExported )
250 ExportStartElement();
251 pContext = XMLTransformerContext::CreateChildContext( nPrefix,
252 rLocalName,
253 rQName,
254 rAttrList );
257 return pContext;
260 void XMLMergeElemTransformerContext::EndElement()
262 if( !m_bStartElementExported )
263 ExportStartElement();
264 XMLTransformerContext::EndElement();
267 void XMLMergeElemTransformerContext::Characters( const OUString& )
269 // ignore
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */