LibreOffice Module xmloff (master) 1
XMLEventImportHelper.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
22#include <tools/debug.hxx>
23#include <xmloff/xmlimp.hxx>
26#include <xmloff/xmlerror.hxx>
27
28using ::com::sun::star::uno::Reference;
29
31 pEventNameMap(new NameMap)
32{
33}
34
36{
37 // delete factories
38 aFactoryMap.clear();
39
40 // delete name map
41 pEventNameMap.reset();
42}
43
45 const OUString& rLanguage,
46 std::unique_ptr<XMLEventContextFactory> pFactory )
47{
48 assert(pFactory);
49 aFactoryMap[rLanguage] = std::move(pFactory);
50}
51
53 const XMLEventNameTranslation* pTransTable )
54{
55 if (nullptr == pTransTable)
56 return;
57
58 // put translation table into map
59 for(const XMLEventNameTranslation* pTrans = pTransTable;
60 pTrans->sAPIName != nullptr;
61 pTrans++)
62 {
63 XMLEventName aName( pTrans->nPrefix, pTrans->sXMLName );
64
65 // check for conflicting entries
67 "conflicting event translations");
68
69 // assign new translation
70 (*pEventNameMap)[aName] =
71 OUString::createFromAscii(pTrans->sAPIName);
72 }
73 // else? ignore!
74}
75
77{
78 // save old map and install new one
79 aEventNameMapVector.push_back(std::move(pEventNameMap));
80 pEventNameMap.reset( new NameMap );
81}
82
84{
86 "no translation tables left to pop");
87 if ( !aEventNameMapVector.empty() )
88 {
89 // delete current and install old map
90 pEventNameMap = std::move(aEventNameMapVector.back());
91 aEventNameMapVector.pop_back();
92 }
93}
94
95
97 SvXMLImport& rImport,
98 const Reference<css::xml::sax::XFastAttributeList> & xAttrList,
100 const OUString& rXmlEventName,
101 const OUString& rLanguage)
102{
103 SvXMLImportContext* pContext = nullptr;
104
105 // translate event name from xml to api
106 OUString sMacroName;
107 sal_uInt16 nMacroPrefix =
108 rImport.GetNamespaceMap().GetKeyByAttrValueQName(rXmlEventName,
109 &sMacroName );
110 XMLEventName aEventName( nMacroPrefix, sMacroName );
111 NameMap::iterator aNameIter = pEventNameMap->find(aEventName);
112 if (aNameIter != pEventNameMap->end())
113 {
114 OUString aScriptLanguage;
115 sal_uInt16 nScriptPrefix = rImport.GetNamespaceMap().
116 GetKeyByAttrValueQName(rLanguage, &aScriptLanguage);
117 if( XML_NAMESPACE_OOO != nScriptPrefix )
118 aScriptLanguage = rLanguage ;
119
120 // check for factory
121 FactoryMap::iterator aFactoryIterator =
122 aFactoryMap.find(aScriptLanguage);
123 if (aFactoryIterator != aFactoryMap.end())
124 {
125 // delegate to factory
126 pContext = aFactoryIterator->second->CreateContext(
127 rImport, xAttrList,
128 rEvents, aNameIter->second);
129 }
130 }
131
132 // default context (if no context was created above)
133 if( nullptr == pContext )
134 {
135 pContext = new SvXMLImportContext(rImport);
136
138 { rXmlEventName, rLanguage });
139
140 }
141
142 return pContext;
143}
144
145/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::map< XMLEventName, OUString > NameMap
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
FactoryMap aFactoryMap
map of XMLEventContextFactory objects
std::vector< std::unique_ptr< NameMap > > aEventNameMapVector
stack of previous aEventNameMap
void AddTranslationTable(const XMLEventNameTranslation *pTransTable)
add event name translation to the internal table
SvXMLImportContext * CreateContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, XMLEventsImportContext *rEvents, const OUString &rXmlEventName, const OUString &rLanguage)
create an appropriate import context for a particular event
std::unique_ptr< NameMap > pEventNameMap
map from XML to API names
void RegisterFactory(const OUString &rLanguage, std::unique_ptr< XMLEventContextFactory > aFactory)
register a handler for a particular language type
void PopTranslationTable()
recover the top-most previously saved translation table
void PushTranslationTable()
save the old translation table on a stack and install an empty table
Import <script:events> element.
#define DBG_ASSERT(sCon, aError)
OUString aName
XMLEventNameTranslation: define tables that translate between event names as used in the XML file for...
Definition: xmlevent.hxx:77
const char * sAPIName
Definition: xmlevent.hxx:78
constexpr OUStringLiteral sMacroName
#define XMLERROR_ILLEGAL_EVENT
Definition: xmlerror.hxx:56
#define XMLERROR_FLAG_ERROR
Definition: xmlerror.hxx:36
constexpr sal_uInt16 XML_NAMESPACE_OOO