merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / script / XMLEventImportHelper.cxx
blobd1697d92a9138fced0b3a70b13b6213e0d59e31b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLEventImportHelper.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #ifndef _XMLOFF_XMLEVENTIMPORTHELPER_HXX
35 #include "XMLEventImportHelper.hxx"
36 #endif
37 #include <tools/debug.hxx>
38 #include <xmloff/xmlimp.hxx>
39 #include <xmloff/nmspmap.hxx>
40 #include "xmlnmspe.hxx"
41 #include "xmlerror.hxx"
43 using ::rtl::OUString;
44 using ::com::sun::star::xml::sax::XAttributeList;
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::Sequence;
48 XMLEventImportHelper::XMLEventImportHelper() :
49 aFactoryMap(),
50 pEventNameMap(new NameMap()),
51 aEventNameMapList()
56 XMLEventImportHelper::~XMLEventImportHelper()
58 // delete factories
59 FactoryMap::iterator aEnd = aFactoryMap.end();
60 for(FactoryMap::iterator aIter = aFactoryMap.begin();
61 aIter != aEnd;
62 aIter++ )
64 delete aIter->second;
66 aFactoryMap.clear();
68 // delete name map
69 delete pEventNameMap;
72 void XMLEventImportHelper::RegisterFactory(
73 const OUString& rLanguage,
74 XMLEventContextFactory* pFactory )
76 DBG_ASSERT(pFactory != NULL, "I need a factory.");
77 if (NULL != pFactory)
79 aFactoryMap[rLanguage] = pFactory;
83 void XMLEventImportHelper::AddTranslationTable(
84 const XMLEventNameTranslation* pTransTable )
86 if (NULL != pTransTable)
88 // put translation table into map
89 for(const XMLEventNameTranslation* pTrans = pTransTable;
90 pTrans->sAPIName != NULL;
91 pTrans++)
93 XMLEventName aName( pTrans->nPrefix, pTrans->sXMLName );
95 // check for conflicting entries
96 DBG_ASSERT(pEventNameMap->find(aName) == pEventNameMap->end(),
97 "conflicting event translations");
99 // assign new translation
100 (*pEventNameMap)[aName] =
101 OUString::createFromAscii(pTrans->sAPIName);
104 // else? ignore!
107 void XMLEventImportHelper::PushTranslationTable()
109 // save old map and install new one
110 aEventNameMapList.push_back(pEventNameMap);
111 pEventNameMap = new NameMap();
114 void XMLEventImportHelper::PopTranslationTable()
116 DBG_ASSERT(aEventNameMapList.size() > 0,
117 "no translation tables left to pop");
118 if ( !aEventNameMapList.empty() )
120 // delete current and install old map
121 delete pEventNameMap;
122 pEventNameMap = aEventNameMapList.back();
123 aEventNameMapList.pop_back();
128 SvXMLImportContext* XMLEventImportHelper::CreateContext(
129 SvXMLImport& rImport,
130 sal_uInt16 nPrefix,
131 const OUString& rLocalName,
132 const Reference<XAttributeList> & xAttrList,
133 XMLEventsImportContext* rEvents,
134 const OUString& rXmlEventName,
135 const OUString& rLanguage)
137 SvXMLImportContext* pContext = NULL;
139 // translate event name form xml to api
140 OUString sMacroName;
141 sal_uInt16 nMacroPrefix =
142 rImport.GetNamespaceMap().GetKeyByAttrName( rXmlEventName,
143 &sMacroName );
144 XMLEventName aEventName( nMacroPrefix, sMacroName );
145 NameMap::iterator aNameIter = pEventNameMap->find(aEventName);
146 if (aNameIter != pEventNameMap->end())
148 OUString aScriptLanguage;
149 sal_uInt16 nScriptPrefix = rImport.GetNamespaceMap().
150 GetKeyByAttrName( rLanguage, &aScriptLanguage );
151 if( XML_NAMESPACE_OOO != nScriptPrefix )
152 aScriptLanguage = rLanguage ;
154 // check for factory
155 FactoryMap::iterator aFactoryIterator =
156 aFactoryMap.find(aScriptLanguage);
157 if (aFactoryIterator != aFactoryMap.end())
159 // delegate to factory
160 pContext = aFactoryIterator->second->CreateContext(
161 rImport, nPrefix, rLocalName, xAttrList,
162 rEvents, aNameIter->second, aScriptLanguage);
166 // default context (if no context was created above)
167 if( NULL == pContext )
169 pContext = new SvXMLImportContext(rImport, nPrefix, rLocalName);
171 Sequence<OUString> aMsgParams(2);
173 aMsgParams[0] = rXmlEventName;
174 aMsgParams[1] = rLanguage;
176 rImport.SetError(XMLERROR_FLAG_ERROR | XMLERROR_ILLEGAL_EVENT,
177 aMsgParams);
181 return pContext;