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"
25 #include "TransformerActions.hxx"
26 #include "TransformerBase.hxx"
27 #include <osl/diagnose.h>
28 
29 #include <unordered_map>
30 
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::xml::sax;
33 using namespace ::xmloff::token;
34 
36  public std::unordered_map< OUString, NameKey_Impl >
37 {
38 public:
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 
81  XMLTransformerBase& rImp,
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;
118  return XML_NAMESPACE_UNKNOWN;
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 );
137  XMLMutableAttributeList *pMutableAttrList = nullptr;
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  {
160  case XML_ATACTION_HREF:
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);
172  GetTransformer().AddNamespacePrefix( aAttrValue,
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;
187  case XML_ATACTION_COPY:
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: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
const char aData[]
XMLTransformerEventMapEntry const aFormTransformerEventMap[]
Definition: EventMap.cxx:95
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
const sal_uInt16 XML_NAMESPACE_UNKNOWN
static sal_uInt16 GetEventName(const OUString &rName, OUString &rNewName, XMLTransformerOOoEventMap_Impl &rMap)
SvXMLNamespaceMap & GetNamespaceMap()
virtual sal_Int16 SAL_CALL getLength() override
virtual void EndElement() override
XMLEventOOoTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName, bool bPersistent)
XMLTransformerOOoEventMap_Impl(XMLTransformerEventMapEntry const *pInit, XMLTransformerEventMapEntry const *pInit2)
static void FlushEventMap(XMLTransformerOOoEventMap_Impl *p)
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
int i
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, const OUString &_rVal, const ::comphelper::UStringMixEqual &_rCase)
virtual bool IsPersistent() const override
void SetValueByIndex(sal_Int16 i, const OUString &rValue)
void RemoveAttributeByIndex(sal_Int16 i)
void AddMap(XMLTransformerEventMapEntry const *pInit)
XMLTransformerEventMapEntry const aTransformerEventMap[]
Definition: EventMap.cxx:24
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
enumrange< T >::Iterator end(enumrange< T >)
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
const OUString & GetExportQName() const
void AddNamespacePrefix(OUString &rName, sal_uInt16 nPrefix) const
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)
static XMLTransformerOOoEventMap_Impl * CreateEventMap()
XMLTransformerBase & GetTransformer()
virtual ~XMLEventOOoTransformerContext() override
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3378
Handling of tokens in XML:
sal_uInt16 const m_nOASISPrefix
Definition: EventMap.hxx:27
virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) 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)