LibreOffice Module xmloff (master) 1
EventOOoTContext.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 "EventOOoTContext.hxx"
21#include "EventMap.hxx"
22#include "MutableAttrList.hxx"
23#include "ActionMapTypesOOo.hxx"
26#include "TransformerBase.hxx"
27#include <osl/diagnose.h>
28
29#include <unordered_map>
30
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::xml::sax;
33using namespace ::xmloff::token;
34
36 public std::unordered_map< OUString, NameKey_Impl >
37{
38public:
39
40 void AddMap( XMLTransformerEventMapEntry const *pInit );
41
43 XMLTransformerEventMapEntry const *pInit2 );
44};
45
47{
48 XMLTransformerOOoEventMap_Impl::key_type aKey;
49 XMLTransformerOOoEventMap_Impl::mapped_type aData;
50 while( pInit->m_pOOoName )
51 {
52 aKey = OUString::createFromAscii(pInit->m_pOOoName);
53
54 OSL_ENSURE( find( aKey ) == end(), "duplicate event map entry" );
55
56 aData.m_nPrefix = pInit->m_nOASISPrefix;
57 aData.m_aLocalName = OUString::createFromAscii(pInit->m_pOASISName);
58
59 XMLTransformerOOoEventMap_Impl::value_type aVal( aKey, aData );
60
61 if( !insert( aVal ).second )
62 {
63 OSL_FAIL( "duplicate OOo event name entry" );
64 }
65
66 ++pInit;
67 }
68}
69
71 XMLTransformerEventMapEntry const *pInit,
72 XMLTransformerEventMapEntry const *pInit2 )
73{
74 if( pInit )
75 AddMap( pInit );
76 if( pInit2 )
77 AddMap( pInit2 );
78}
79
82 const OUString& rQName,
83 bool bPersistent ) :
84 XMLPersElemContentTContext( rImp, rQName,
85 rImp.GetNamespaceMap().GetKeyByAttrValueQName(rQName, nullptr),
87 m_bPersistent( bPersistent )
88{
89}
90
92{
93}
94
97{
100}
101
104{
105 delete p;
106}
107
109 const OUString& rName,
110 OUString& rNewName,
112{
113 const XMLTransformerOOoEventMap_Impl::key_type& aKey( rName );
114 XMLTransformerOOoEventMap_Impl::const_iterator aIter = rMap.find( aKey );
115 if( aIter == rMap.end() )
116 {
117 rNewName = rName;
119 }
120 else
121 {
122 rNewName = (*aIter).second.m_aLocalName;
123 return (*aIter).second.m_nPrefix;
124 }
125}
126
128 const Reference< XAttributeList >& rAttrList )
129{
130 XMLTransformerActions *pActions =
132 OSL_ENSURE( pActions, "go no actions" );
133
134 OUString aLocation, aMacroName;
135 sal_Int16 nMacroName = -1;
136 Reference< XAttributeList > xAttrList( rAttrList );
138 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
139 for( sal_Int16 i=0; i < nAttrCount; i++ )
140 {
141 const OUString& rAttrName = xAttrList->getNameByIndex( i );
142 OUString aLocalName;
143 sal_uInt16 nPrefix =
145 &aLocalName );
146 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
147 XMLTransformerActions::const_iterator aIter =
148 pActions->find( aKey );
149 if( aIter != pActions->end() )
150 {
151 if( !pMutableAttrList )
152 {
153 pMutableAttrList =
154 new XMLMutableAttributeList( xAttrList );
155 xAttrList = pMutableAttrList;
156 }
157 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
158 switch( (*aIter).second.m_nActionType )
159 {
161 // TODO
162 break;
164 pMutableAttrList->SetValueByIndex( i,
165 GetTransformer().GetEventName( rAttrValue ) );
166 break;
168 {
169 OUString aAttrValue( rAttrValue );
170 sal_uInt16 nValPrefix =
171 static_cast<sal_uInt16>((*aIter).second.m_nParam1);
173 nValPrefix );
174 pMutableAttrList->SetValueByIndex( i, aAttrValue );
175 }
176 break;
178 aLocation = rAttrValue;
179 pMutableAttrList->RemoveAttributeByIndex( i );
180 --i;
181 --nAttrCount;
182 break;
184 aMacroName = rAttrValue;
185 nMacroName = i;
186 break;
188 break;
189 default:
190 OSL_ENSURE( false, "unknown action" );
191 break;
192 }
193 }
194 }
195
196 if( nMacroName != -1 && !aLocation.isEmpty() )
197 {
198 if( !IsXMLToken( aLocation, XML_APPLICATION ) )
199 aLocation = GetXMLToken( XML_DOCUMENT );
200 OUString sTmp = aLocation + ":" + aMacroName;
201 pMutableAttrList->SetValueByIndex( nMacroName, sTmp );
202 }
203
204 if( m_bPersistent )
206 else
207 GetTransformer().GetDocHandler()->startElement( GetExportQName(), xAttrList );
208}
209
211{
212 if( m_bPersistent )
214 else
215 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
216}
217
219 sal_uInt16 nPrefix,
220 const OUString& rLocalName,
221 const OUString& rQName,
222 const Reference< XAttributeList >& xAttrList )
223{
224 if( m_bPersistent )
225 return XMLPersElemContentTContext::CreateChildContext(nPrefix, rLocalName, rQName, xAttrList);
226 else
227 return XMLTransformerContext::CreateChildContext(nPrefix, rLocalName, rQName, xAttrList);
228}
229
231{
232 return m_bPersistent;
233}
234
235/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ OOO_EVENT_ACTIONS
@ XML_ATACTION_EVENT_NAME
@ XML_ATACTION_MACRO_LOCATION
@ XML_ATACTION_HREF
@ XML_ATACTION_ADD_NAMESPACE_PREFIX
@ XML_ATACTION_COPY
@ XML_ATACTION_MACRO_NAME
XMLTransformerEventMapEntry const aFormTransformerEventMap[]
Definition: EventMap.cxx:95
XMLTransformerEventMapEntry const aTransformerEventMap[]
Definition: EventMap.cxx:24
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
XMLEventOOoTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName, bool bPersistent)
virtual ~XMLEventOOoTransformerContext() override
static sal_uInt16 GetEventName(const OUString &rName, OUString &rNewName, XMLTransformerOOoEventMap_Impl &rMap)
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 EndElement() override
static XMLTransformerOOoEventMap_Impl * CreateEventMap()
virtual bool IsPersistent() const override
static void FlushEventMap(XMLTransformerOOoEventMap_Impl *p)
const OUString & GetExportQName() const
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual void EndElement() override
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 XMLTransformerActions * GetUserDefinedActions(sal_uInt16 n)
void AddNamespacePrefix(OUString &rName, sal_uInt16 nPrefix) const
SvXMLNamespaceMap & GetNamespaceMap()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
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()
XMLTransformerOOoEventMap_Impl(XMLTransformerEventMapEntry const *pInit, XMLTransformerEventMapEntry const *pInit2)
void AddMap(XMLTransformerEventMapEntry const *pInit)
void * p
constexpr OUStringLiteral aData
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
int i
const sal_uInt16 XML_NAMESPACE_UNKNOWN
end
Handling of tokens in XML:
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
sal_uInt16 const m_nOASISPrefix
Definition: EventMap.hxx:26