Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / xml / XMLTableSourceContext.cxx
blob93ec9ac0ea7513ee38b0f22437a5d4f0db939a9b
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "XMLTableSourceContext.hxx"
21 #include "xmlimprt.hxx"
22 #include <document.hxx>
23 #include "xmlsubti.hxx"
24 #include <tablink.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnmspe.hxx>
27 #include <sax/tools/converter.hxx>
28 #include <com/sun/star/sheet/XSheetLinkable.hpp>
30 using namespace com::sun::star;
31 using namespace xmloff::token;
33 ScXMLTableSourceContext::ScXMLTableSourceContext( ScXMLImport& rImport,
34 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
35 ScXMLImportContext( rImport ),
36 sLink(),
37 sTableName(),
38 sFilterName(),
39 sFilterOptions(),
40 nRefresh(0),
41 nMode(sheet::SheetLinkMode_NORMAL)
43 if ( rAttrList.is() )
45 for (auto &aIter : *rAttrList)
47 switch (aIter.getToken())
49 case XML_ELEMENT( XLINK, XML_HREF ):
50 sLink = GetScImport().GetAbsoluteReference(aIter.toString());
51 break;
52 case XML_ELEMENT( TABLE, XML_TABLE_NAME ):
53 sTableName = aIter.toString();
54 break;
55 case XML_ELEMENT( TABLE, XML_FILTER_NAME):
56 sFilterName = aIter.toString();
57 break;
58 case XML_ELEMENT( TABLE, XML_FILTER_OPTIONS ):
59 sFilterOptions = aIter.toString();
60 break;
61 case XML_ELEMENT( TABLE, XML_MODE ):
62 if (IsXMLToken(aIter, XML_COPY_RESULTS_ONLY))
63 nMode = sheet::SheetLinkMode_VALUE;
64 break;
65 case XML_ELEMENT( TABLE, XML_REFRESH_DELAY ):
66 double fTime;
67 if (::sax::Converter::convertDuration( fTime, aIter.toString() ))
68 nRefresh = std::max( static_cast<sal_Int32>(fTime * 86400.0), sal_Int32(0) );
69 break;
75 ScXMLTableSourceContext::~ScXMLTableSourceContext()
79 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLTableSourceContext::createFastChildContext(
80 sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
82 return new SvXMLImportContext( GetImport() );
85 void SAL_CALL ScXMLTableSourceContext::endFastElement( sal_Int32 /*nElement*/ )
87 if (!sLink.isEmpty())
89 uno::Reference <sheet::XSheetLinkable> xLinkable (GetScImport().GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
90 ScDocument* pDoc(GetScImport().GetDocument());
91 if (xLinkable.is() && pDoc)
93 ScXMLImport::MutexGuard aGuard(GetScImport());
94 if (pDoc->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
95 GetScImport().GetTables().GetCurrentSheetName(), true/*bExternalDocument*/))
97 sLink = ScGlobal::GetAbsDocName( sLink, pDoc->GetDocumentShell() );
98 if (sFilterName.isEmpty())
99 ScDocumentLoader::GetFilterName( sLink, sFilterName, sFilterOptions, false, false );
101 ScLinkMode nLinkMode = ScLinkMode::NONE;
102 if ( nMode == sheet::SheetLinkMode_NORMAL )
103 nLinkMode = ScLinkMode::NORMAL;
104 else if ( nMode == sheet::SheetLinkMode_VALUE )
105 nLinkMode = ScLinkMode::VALUE;
107 pDoc->SetLink( GetScImport().GetTables().GetCurrentSheet(),
108 nLinkMode, sLink, sFilterName, sFilterOptions,
109 sTableName, nRefresh );
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */