Bump for 3.6-28
[LibreOffice.git] / xmloff / source / script / XMLEventImportHelper.cxx
blob9aac9d1a9e8ef5bb9e4fabf0d279b96bd1648a71
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "XMLEventImportHelper.hxx"
31 #include <tools/debug.hxx>
32 #include <xmloff/xmlimp.hxx>
33 #include <xmloff/nmspmap.hxx>
34 #include "xmloff/xmlnmspe.hxx"
35 #include "xmloff/xmlerror.hxx"
37 using ::rtl::OUString;
38 using ::com::sun::star::xml::sax::XAttributeList;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Sequence;
42 XMLEventImportHelper::XMLEventImportHelper() :
43 aFactoryMap(),
44 pEventNameMap(new NameMap()),
45 aEventNameMapList()
50 XMLEventImportHelper::~XMLEventImportHelper()
52 // delete factories
53 FactoryMap::iterator aEnd = aFactoryMap.end();
54 for(FactoryMap::iterator aIter = aFactoryMap.begin();
55 aIter != aEnd;
56 ++aIter)
58 delete aIter->second;
60 aFactoryMap.clear();
62 // delete name map
63 delete pEventNameMap;
66 void XMLEventImportHelper::RegisterFactory(
67 const OUString& rLanguage,
68 XMLEventContextFactory* pFactory )
70 DBG_ASSERT(pFactory != NULL, "I need a factory.");
71 if (NULL != pFactory)
73 aFactoryMap[rLanguage] = pFactory;
77 void XMLEventImportHelper::AddTranslationTable(
78 const XMLEventNameTranslation* pTransTable )
80 if (NULL != pTransTable)
82 // put translation table into map
83 for(const XMLEventNameTranslation* pTrans = pTransTable;
84 pTrans->sAPIName != NULL;
85 pTrans++)
87 XMLEventName aName( pTrans->nPrefix, pTrans->sXMLName );
89 // check for conflicting entries
90 DBG_ASSERT(pEventNameMap->find(aName) == pEventNameMap->end(),
91 "conflicting event translations");
93 // assign new translation
94 (*pEventNameMap)[aName] =
95 OUString::createFromAscii(pTrans->sAPIName);
98 // else? ignore!
101 void XMLEventImportHelper::PushTranslationTable()
103 // save old map and install new one
104 aEventNameMapList.push_back(pEventNameMap);
105 pEventNameMap = new NameMap();
108 void XMLEventImportHelper::PopTranslationTable()
110 DBG_ASSERT(aEventNameMapList.size() > 0,
111 "no translation tables left to pop");
112 if ( !aEventNameMapList.empty() )
114 // delete current and install old map
115 delete pEventNameMap;
116 pEventNameMap = aEventNameMapList.back();
117 aEventNameMapList.pop_back();
122 SvXMLImportContext* XMLEventImportHelper::CreateContext(
123 SvXMLImport& rImport,
124 sal_uInt16 nPrefix,
125 const OUString& rLocalName,
126 const Reference<XAttributeList> & xAttrList,
127 XMLEventsImportContext* rEvents,
128 const OUString& rXmlEventName,
129 const OUString& rLanguage)
131 SvXMLImportContext* pContext = NULL;
133 // translate event name form xml to api
134 OUString sMacroName;
135 sal_uInt16 nMacroPrefix =
136 rImport.GetNamespaceMap().GetKeyByAttrName( rXmlEventName,
137 &sMacroName );
138 XMLEventName aEventName( nMacroPrefix, sMacroName );
139 NameMap::iterator aNameIter = pEventNameMap->find(aEventName);
140 if (aNameIter != pEventNameMap->end())
142 OUString aScriptLanguage;
143 sal_uInt16 nScriptPrefix = rImport.GetNamespaceMap().
144 GetKeyByAttrName( rLanguage, &aScriptLanguage );
145 if( XML_NAMESPACE_OOO != nScriptPrefix )
146 aScriptLanguage = rLanguage ;
148 // check for factory
149 FactoryMap::iterator aFactoryIterator =
150 aFactoryMap.find(aScriptLanguage);
151 if (aFactoryIterator != aFactoryMap.end())
153 // delegate to factory
154 pContext = aFactoryIterator->second->CreateContext(
155 rImport, nPrefix, rLocalName, xAttrList,
156 rEvents, aNameIter->second, aScriptLanguage);
160 // default context (if no context was created above)
161 if( NULL == pContext )
163 pContext = new SvXMLImportContext(rImport, nPrefix, rLocalName);
165 Sequence<OUString> aMsgParams(2);
167 aMsgParams[0] = rXmlEventName;
168 aMsgParams[1] = rLanguage;
170 rImport.SetError(XMLERROR_FLAG_ERROR | XMLERROR_ILLEGAL_EVENT,
171 aMsgParams);
175 return pContext;
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */