LibreOffice Module sc (master) 1
xmlmappingi.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#include "xmlimprt.hxx"
11#include "xmlmappingi.hxx"
13
14#include <xmloff/xmltoken.hxx>
16
17#include <datamapper.hxx>
18#include <document.hxx>
19
20using namespace com::sun::star;
21using namespace xmloff::token;
22
24 ScXMLImportContext( rImport )
25{
26 // has no attributes
27 rImport.LockSolarMutex();
28}
29
31{
33}
34
35uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLMappingsContext::createFastChildContext(
36 sal_Int32 nElement,
37 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
38{
39 SvXMLImportContext *pContext = nullptr;
42
43 switch( nElement )
44 {
45 case XML_ELEMENT( CALC_EXT, XML_DATA_MAPPING ):
46 {
47 pContext = new ScXMLMappingContext( GetScImport(), pAttribList );
48 }
49 break;
51 {
52 pContext = new ScXMLTransformationsContext( GetScImport() );
53 }
54 break;
55 }
56
57 return pContext;
58}
59
62 ScXMLImportContext( rImport )
63{
64 OUString aProvider;
65 OUString aID;
66 OUString aURL;
67 // OUString aFrequency;
68 OUString aDBName;
69 if ( rAttrList.is() )
70 {
71 for (auto &aIter : *rAttrList)
72 {
73 switch (aIter.getToken())
74 {
75 case XML_ELEMENT( XLINK, XML_HREF ):
76 {
77 aURL = aIter.toString();
78 }
79 break;
80 case XML_ELEMENT( CALC_EXT, XML_PROVIDER ):
81 {
82 aProvider = aIter.toString();
83 }
84 break;
85 case XML_ELEMENT( CALC_EXT, XML_ID ):
86 {
87 aID = aIter.toString();
88 }
89 break;
90 case XML_ELEMENT( CALC_EXT, XML_DATABASE_NAME ):
91 {
92 aDBName = aIter.toString();
93 }
94 break;
95 case XML_ELEMENT( CALC_EXT, XML_DATA_FREQUENCY ):
96 {
97 }
98 break;
99 }
100 }
101 }
102
103 if (!aProvider.isEmpty())
104 {
106 auto& rDataMapper = pDoc->GetExternalDataMapper();
107 sc::ExternalDataSource aSource(aURL, aProvider, pDoc);
108 aSource.setID(aID);
109 aSource.setDBData(aDBName);
110 rDataMapper.insertDataSource(aSource);
111 }
112}
113
115{
117 auto& rDataMapper = pDoc->GetExternalDataMapper();
118 auto& rDataSources = rDataMapper.getDataSources();
119 if(!rDataSources.empty())
120 rDataSources[0].refresh(pDoc, true);
121}
122
123uno::Reference<xml::sax::XFastContextHandler>
125 sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& /*xAttrList*/)
126{
127 SvXMLImportContext *pContext = nullptr;
128
129 switch( nElement )
130 {
131 case XML_ELEMENT( CALC_EXT, XML_DATA_TRANSFORMATIONS):
132 {
133 pContext = new ScXMLTransformationsContext( GetScImport() );
134 }
135 break;
136 }
137
138 return pContext;
139}
140/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC sc::ExternalDataMapper & GetExternalDataMapper()
This class exists only to provide GetScImport() to its derived classes.
ScXMLImport & GetScImport()
void LockSolarMutex()
Definition: xmlimprt.cxx:1519
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
void UnlockSolarMutex()
Definition: xmlimprt.cxx:1537
ScXMLMappingContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
Definition: xmlmappingi.cxx:60
virtual ~ScXMLMappingContext() override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlmappingi.cxx:35
virtual ~ScXMLMappingsContext() override
Definition: xmlmappingi.cxx:30
ScXMLMappingsContext(ScXMLImport &rImport)
Definition: xmlmappingi.cxx:23
const std::vector< ExternalDataSource > & getDataSources() const
void setID(const OUString &rID)
void setDBData(const OUString &rDBName)
URL aURL
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_DATABASE_NAME
XML_HREF
XML_DATA_TRANSFORMATIONS
XML_ID
XML_DATA_MAPPING
XML_PROVIDER
XML_DATA_FREQUENCY
#define XML_ELEMENT(prefix, name)