Teach symstore more duplicated DLLs
[LibreOffice.git] / xmloff / source / transform / EventOOoTContext.cxx
blobbd77d111642539e087a5693a4295f767be73e4af
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 "EventOOoTContext.hxx"
21 #include "EventMap.hxx"
22 #include "MutableAttrList.hxx"
23 #include "ActionMapTypesOOo.hxx"
24 #include "AttrTransformerAction.hxx"
25 #include "TransformerActions.hxx"
26 #include "TransformerBase.hxx"
27 #include <osl/diagnose.h>
29 #include <unordered_map>
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::xml::sax;
33 using namespace ::xmloff::token;
35 class XMLTransformerOOoEventMap_Impl:
36 public std::unordered_map< OUString, NameKey_Impl >
38 public:
40 void AddMap( XMLTransformerEventMapEntry const *pInit );
42 XMLTransformerOOoEventMap_Impl( XMLTransformerEventMapEntry const *pInit,
43 XMLTransformerEventMapEntry const *pInit2 );
46 void XMLTransformerOOoEventMap_Impl::AddMap( XMLTransformerEventMapEntry const *pInit )
48 XMLTransformerOOoEventMap_Impl::key_type aKey;
49 XMLTransformerOOoEventMap_Impl::mapped_type aData;
50 while( pInit->m_pOOoName )
52 aKey = OUString::createFromAscii(pInit->m_pOOoName);
54 OSL_ENSURE( find( aKey ) == end(), "duplicate event map entry" );
56 aData.m_nPrefix = pInit->m_nOASISPrefix;
57 aData.m_aLocalName = OUString::createFromAscii(pInit->m_pOASISName);
59 XMLTransformerOOoEventMap_Impl::value_type aVal( aKey, aData );
61 if( !insert( aVal ).second )
63 OSL_FAIL( "duplicate OOo event name entry" );
66 ++pInit;
70 XMLTransformerOOoEventMap_Impl::XMLTransformerOOoEventMap_Impl(
71 XMLTransformerEventMapEntry const *pInit,
72 XMLTransformerEventMapEntry const *pInit2 )
74 if( pInit )
75 AddMap( pInit );
76 if( pInit2 )
77 AddMap( pInit2 );
80 XMLEventOOoTransformerContext::XMLEventOOoTransformerContext(
81 XMLTransformerBase& rImp,
82 const OUString& rQName,
83 bool bPersistent ) :
84 XMLPersElemContentTContext( rImp, rQName,
85 rImp.GetNamespaceMap().GetKeyByAttrName( rQName ), XML_EVENT_LISTENER ),
86 m_bPersistent( bPersistent )
90 XMLEventOOoTransformerContext::~XMLEventOOoTransformerContext()
94 XMLTransformerOOoEventMap_Impl
95 *XMLEventOOoTransformerContext::CreateEventMap()
97 return new XMLTransformerOOoEventMap_Impl( aTransformerEventMap,
98 aFormTransformerEventMap );
101 void XMLEventOOoTransformerContext::FlushEventMap(
102 XMLTransformerOOoEventMap_Impl *p )
104 delete p;
107 sal_uInt16 XMLEventOOoTransformerContext::GetEventName(
108 const OUString& rName,
109 OUString& rNewName,
110 XMLTransformerOOoEventMap_Impl& rMap )
112 const XMLTransformerOOoEventMap_Impl::key_type& aKey( rName );
113 XMLTransformerOOoEventMap_Impl::const_iterator aIter = rMap.find( aKey );
114 if( aIter == rMap.end() )
116 rNewName = rName;
117 return XML_NAMESPACE_UNKNOWN;
119 else
121 rNewName = (*aIter).second.m_aLocalName;
122 return (*aIter).second.m_nPrefix;
126 void XMLEventOOoTransformerContext::StartElement(
127 const Reference< XAttributeList >& rAttrList )
129 XMLTransformerActions *pActions =
130 GetTransformer().GetUserDefinedActions( OOO_EVENT_ACTIONS );
131 OSL_ENSURE( pActions, "go no actions" );
133 OUString aLocation, aMacroName;
134 sal_Int16 nMacroName = -1;
135 Reference< XAttributeList > xAttrList( rAttrList );
136 XMLMutableAttributeList *pMutableAttrList = nullptr;
137 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
138 for( sal_Int16 i=0; i < nAttrCount; i++ )
140 const OUString& rAttrName = xAttrList->getNameByIndex( i );
141 OUString aLocalName;
142 sal_uInt16 nPrefix =
143 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
144 &aLocalName );
145 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
146 XMLTransformerActions::const_iterator aIter =
147 pActions->find( aKey );
148 if( aIter != pActions->end() )
150 if( !pMutableAttrList )
152 pMutableAttrList =
153 new XMLMutableAttributeList( xAttrList );
154 xAttrList = pMutableAttrList;
156 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
157 switch( (*aIter).second.m_nActionType )
159 case XML_ATACTION_HREF:
160 // TODO
161 break;
162 case XML_ATACTION_EVENT_NAME:
163 pMutableAttrList->SetValueByIndex( i,
164 GetTransformer().GetEventName( rAttrValue ) );
165 break;
166 case XML_ATACTION_ADD_NAMESPACE_PREFIX:
168 OUString aAttrValue( rAttrValue );
169 sal_uInt16 nValPrefix =
170 static_cast<sal_uInt16>((*aIter).second.m_nParam1);
171 GetTransformer().AddNamespacePrefix( aAttrValue,
172 nValPrefix );
173 pMutableAttrList->SetValueByIndex( i, aAttrValue );
175 break;
176 case XML_ATACTION_MACRO_LOCATION:
177 aLocation = rAttrValue;
178 pMutableAttrList->RemoveAttributeByIndex( i );
179 --i;
180 --nAttrCount;
181 break;
182 case XML_ATACTION_MACRO_NAME:
183 aMacroName = rAttrValue;
184 nMacroName = i;
185 break;
186 case XML_ATACTION_COPY:
187 break;
188 default:
189 OSL_ENSURE( false, "unknown action" );
190 break;
195 if( nMacroName != -1 && !aLocation.isEmpty() )
197 if( !IsXMLToken( aLocation, XML_APPLICATION ) )
198 aLocation = GetXMLToken( XML_DOCUMENT );
199 OUString sTmp = aLocation + ":" + aMacroName;
200 pMutableAttrList->SetValueByIndex( nMacroName, sTmp );
203 if( m_bPersistent )
204 XMLPersElemContentTContext::StartElement( xAttrList );
205 else
206 GetTransformer().GetDocHandler()->startElement( GetExportQName(), xAttrList );
209 void XMLEventOOoTransformerContext::EndElement()
211 if( m_bPersistent )
212 XMLPersElemContentTContext::EndElement();
213 else
214 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
217 rtl::Reference<XMLTransformerContext> XMLEventOOoTransformerContext::CreateChildContext(
218 sal_uInt16 nPrefix,
219 const OUString& rLocalName,
220 const OUString& rQName,
221 const Reference< XAttributeList >& xAttrList )
223 if( m_bPersistent )
224 return XMLPersElemContentTContext::CreateChildContext(nPrefix, rLocalName, rQName, xAttrList);
225 else
226 return XMLTransformerContext::CreateChildContext(nPrefix, rLocalName, rQName, xAttrList);
229 bool XMLEventOOoTransformerContext::IsPersistent() const
231 return m_bPersistent;
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */