1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
)
27 rImport
.LockSolarMutex();
30 ScXMLMappingsContext::~ScXMLMappingsContext()
32 GetScImport().UnlockSolarMutex();
35 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLMappingsContext::createFastChildContext(
37 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
39 SvXMLImportContext
*pContext
= nullptr;
40 sax_fastparser::FastAttributeList
*pAttribList
=
41 &sax_fastparser::castToFastAttributeList( xAttrList
);
45 case XML_ELEMENT( CALC_EXT
, XML_DATA_MAPPING
):
47 pContext
= new ScXMLMappingContext( GetScImport(), pAttribList
);
50 case XML_ELEMENT( CALC_EXT
, XML_DATA_TRANSFORMATIONS
):
52 pContext
= new ScXMLTransformationsContext( GetScImport() );
60 ScXMLMappingContext::ScXMLMappingContext( ScXMLImport
& rImport
,
61 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
62 ScXMLImportContext( rImport
)
67 // OUString aFrequency;
71 for (auto &aIter
: *rAttrList
)
73 switch (aIter
.getToken())
75 case XML_ELEMENT( XLINK
, XML_HREF
):
77 aURL
= aIter
.toString();
80 case XML_ELEMENT( CALC_EXT
, XML_PROVIDER
):
82 aProvider
= aIter
.toString();
85 case XML_ELEMENT( CALC_EXT
, XML_ID
):
87 aID
= aIter
.toString();
90 case XML_ELEMENT( CALC_EXT
, XML_DATABASE_NAME
):
92 aDBName
= aIter
.toString();
95 case XML_ELEMENT( CALC_EXT
, XML_DATA_FREQUENCY
):
103 if (!aProvider
.isEmpty())
105 ScDocument
* pDoc
= GetScImport().GetDocument();
106 auto& rDataMapper
= pDoc
->GetExternalDataMapper();
107 sc::ExternalDataSource
aSource(aURL
, aProvider
, pDoc
);
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;
131 case XML_ELEMENT( CALC_EXT
, XML_DATA_TRANSFORMATIONS
):
133 pContext
= new ScXMLTransformationsContext( GetScImport() );
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */