Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / xml / xmlmappingi.cxx
blob0ce24a568e4b93466576214e6d223f3d75606017
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/xmlnmspe.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::FastAttributeList::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 if( !pContext )
58 pContext = new SvXMLImportContext( GetImport() );
60 return pContext;
63 ScXMLMappingContext::ScXMLMappingContext( ScXMLImport& rImport,
64 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
65 ScXMLImportContext( rImport )
67 OUString aProvider;
68 OUString aID;
69 OUString aURL;
70 // OUString aFrequency;
71 OUString aDBName;
72 if ( rAttrList.is() )
74 for (auto &aIter : *rAttrList)
76 switch (aIter.getToken())
78 case XML_ELEMENT( XLINK, XML_HREF ):
80 aURL = aIter.toString();
82 break;
83 case XML_ELEMENT( CALC_EXT, XML_PROVIDER ):
85 aProvider = aIter.toString();
87 break;
88 case XML_ELEMENT( CALC_EXT, XML_ID ):
90 aID = aIter.toString();
92 break;
93 case XML_ELEMENT( CALC_EXT, XML_DATABASE_NAME ):
95 aDBName = aIter.toString();
97 break;
98 case XML_ELEMENT( CALC_EXT, XML_DATA_FREQUENCY ):
101 break;
106 if (!aProvider.isEmpty())
108 ScDocument* pDoc = GetScImport().GetDocument();
109 auto& rDataMapper = pDoc->GetExternalDataMapper();
110 sc::ExternalDataSource aSource(aURL, aProvider, pDoc);
111 aSource.setID(aID);
112 aSource.setDBData(aDBName);
113 rDataMapper.insertDataSource(aSource);
117 ScXMLMappingContext::~ScXMLMappingContext()
119 ScDocument* pDoc = GetScImport().GetDocument();
120 auto& rDataMapper = pDoc->GetExternalDataMapper();
121 auto& rDataSources = rDataMapper.getDataSources();
122 if(!rDataSources.empty())
123 rDataSources[0].refresh(pDoc, true);
126 uno::Reference<xml::sax::XFastContextHandler>
127 SAL_CALL ScXMLMappingContext::createFastChildContext(
128 sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& /*xAttrList*/)
130 SvXMLImportContext *pContext = nullptr;
132 switch( nElement )
134 case XML_ELEMENT( CALC_EXT, XML_DATA_TRANSFORMATIONS):
136 pContext = new ScXMLTransformationsContext( GetScImport() );
138 break;
141 if( !pContext )
142 pContext = new SvXMLImportContext( GetImport() );
144 return pContext;
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */