cid#1607171 Data race condition
[LibreOffice.git] / sc / source / filter / xml / xmlmappingi.cxx
blob9e9b23e36a986551275db7027c2d63688abe7d25
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "xmlimprt.hxx"
11 #include "xmlmappingi.hxx"
12 #include "xmltransformationi.hxx"
14 #include <xmloff/xmltoken.hxx>
15 #include <xmloff/xmlnamespace.hxx>
17 #include <datamapper.hxx>
18 #include <document.hxx>
20 using namespace com::sun::star;
21 using namespace xmloff::token;
23 ScXMLMappingsContext::ScXMLMappingsContext( ScXMLImport& rImport ) :
24 ScXMLImportContext( rImport )
26 // has no attributes
27 rImport.LockSolarMutex();
30 ScXMLMappingsContext::~ScXMLMappingsContext()
32 GetScImport().UnlockSolarMutex();
35 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLMappingsContext::createFastChildContext(
36 sal_Int32 nElement,
37 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
39 SvXMLImportContext *pContext = nullptr;
40 sax_fastparser::FastAttributeList *pAttribList =
41 &sax_fastparser::castToFastAttributeList( xAttrList );
43 switch( nElement )
45 case XML_ELEMENT( CALC_EXT, XML_DATA_MAPPING ):
47 pContext = new ScXMLMappingContext( GetScImport(), pAttribList );
49 break;
50 case XML_ELEMENT( CALC_EXT, XML_DATA_TRANSFORMATIONS):
52 pContext = new ScXMLTransformationsContext( GetScImport() );
54 break;
57 return pContext;
60 ScXMLMappingContext::ScXMLMappingContext( ScXMLImport& rImport,
61 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
62 ScXMLImportContext( rImport )
64 OUString aProvider;
65 OUString aID;
66 OUString aURL;
67 // OUString aFrequency;
68 OUString aDBName;
69 if ( rAttrList.is() )
71 for (auto &aIter : *rAttrList)
73 switch (aIter.getToken())
75 case XML_ELEMENT( XLINK, XML_HREF ):
77 aURL = aIter.toString();
79 break;
80 case XML_ELEMENT( CALC_EXT, XML_PROVIDER ):
82 aProvider = aIter.toString();
84 break;
85 case XML_ELEMENT( CALC_EXT, XML_ID ):
87 aID = aIter.toString();
89 break;
90 case XML_ELEMENT( CALC_EXT, XML_DATABASE_NAME ):
92 aDBName = aIter.toString();
94 break;
95 case XML_ELEMENT( CALC_EXT, XML_DATA_FREQUENCY ):
98 break;
103 if (!aProvider.isEmpty())
105 ScDocument* pDoc = GetScImport().GetDocument();
106 auto& rDataMapper = pDoc->GetExternalDataMapper();
107 sc::ExternalDataSource aSource(aURL, aProvider, pDoc);
108 aSource.setID(aID);
109 aSource.setDBData(aDBName);
110 rDataMapper.insertDataSource(aSource);
114 ScXMLMappingContext::~ScXMLMappingContext()
116 ScDocument* pDoc = GetScImport().GetDocument();
117 auto& rDataMapper = pDoc->GetExternalDataMapper();
118 auto& rDataSources = rDataMapper.getDataSources();
119 if(!rDataSources.empty())
120 rDataSources[0].refresh(pDoc, true);
123 uno::Reference<xml::sax::XFastContextHandler>
124 SAL_CALL ScXMLMappingContext::createFastChildContext(
125 sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& /*xAttrList*/)
127 SvXMLImportContext *pContext = nullptr;
129 switch( nElement )
131 case XML_ELEMENT( CALC_EXT, XML_DATA_TRANSFORMATIONS):
133 pContext = new ScXMLTransformationsContext( GetScImport() );
135 break;
138 return pContext;
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */