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/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
)
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::FastAttributeList::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() );
58 pContext
= new SvXMLImportContext( GetImport() );
63 ScXMLMappingContext::ScXMLMappingContext( ScXMLImport
& rImport
,
64 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
65 ScXMLImportContext( rImport
)
70 // OUString aFrequency;
74 for (auto &aIter
: *rAttrList
)
76 switch (aIter
.getToken())
78 case XML_ELEMENT( XLINK
, XML_HREF
):
80 aURL
= aIter
.toString();
83 case XML_ELEMENT( CALC_EXT
, XML_PROVIDER
):
85 aProvider
= aIter
.toString();
88 case XML_ELEMENT( CALC_EXT
, XML_ID
):
90 aID
= aIter
.toString();
93 case XML_ELEMENT( CALC_EXT
, XML_DATABASE_NAME
):
95 aDBName
= aIter
.toString();
98 case XML_ELEMENT( CALC_EXT
, XML_DATA_FREQUENCY
):
106 if (!aProvider
.isEmpty())
108 ScDocument
* pDoc
= GetScImport().GetDocument();
109 auto& rDataMapper
= pDoc
->GetExternalDataMapper();
110 sc::ExternalDataSource
aSource(aURL
, aProvider
, pDoc
);
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;
134 case XML_ELEMENT( CALC_EXT
, XML_DATA_TRANSFORMATIONS
):
136 pContext
= new ScXMLTransformationsContext( GetScImport() );
142 pContext
= new SvXMLImportContext( GetImport() );
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */