Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / xml / XMLTableSourceContext.cxx
blob535f532dcaa30ef27b63f22f8415061df62da7bd
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/xmlnamespace.hxx>
27 #include <sax/tools/converter.hxx>
28 #include <com/sun/star/sheet/XSheetLinkable.hpp>
29 #include <com/sun/star/sheet/XSpreadsheet.hpp>
31 using namespace com::sun::star;
32 using namespace xmloff::token;
34 ScXMLTableSourceContext::ScXMLTableSourceContext( ScXMLImport& rImport,
35 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
36 ScXMLImportContext( rImport ),
37 nRefresh(0),
38 nMode(sheet::SheetLinkMode_NORMAL)
40 if ( !rAttrList.is() )
41 return;
43 for (auto &aIter : *rAttrList)
45 switch (aIter.getToken())
47 case XML_ELEMENT( XLINK, XML_HREF ):
48 sLink = GetScImport().GetAbsoluteReference(aIter.toString());
49 break;
50 case XML_ELEMENT( TABLE, XML_TABLE_NAME ):
51 sTableName = aIter.toString();
52 break;
53 case XML_ELEMENT( TABLE, XML_FILTER_NAME):
54 sFilterName = aIter.toString();
55 break;
56 case XML_ELEMENT( TABLE, XML_FILTER_OPTIONS ):
57 sFilterOptions = aIter.toString();
58 break;
59 case XML_ELEMENT( TABLE, XML_MODE ):
60 if (IsXMLToken(aIter, XML_COPY_RESULTS_ONLY))
61 nMode = sheet::SheetLinkMode_VALUE;
62 break;
63 case XML_ELEMENT( TABLE, XML_REFRESH_DELAY ):
64 double fTime;
65 if (::sax::Converter::convertDuration( fTime, aIter.toView() ))
66 nRefresh = std::max( static_cast<sal_Int32>(fTime * 86400.0), sal_Int32(0) );
67 break;
72 ScXMLTableSourceContext::~ScXMLTableSourceContext()
76 void SAL_CALL ScXMLTableSourceContext::endFastElement( sal_Int32 /*nElement*/ )
78 if (sLink.isEmpty())
79 return;
81 uno::Reference <sheet::XSheetLinkable> xLinkable (GetScImport().GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
82 ScDocument* pDoc(GetScImport().GetDocument());
83 if (!(xLinkable.is() && pDoc))
84 return;
86 ScXMLImport::MutexGuard aGuard(GetScImport());
87 if (!pDoc->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
88 GetScImport().GetTables().GetCurrentSheetName(), true/*bExternalDocument*/))
89 return;
91 sLink = ScGlobal::GetAbsDocName( sLink, pDoc->GetDocumentShell() );
92 if (sFilterName.isEmpty())
93 ScDocumentLoader::GetFilterName( sLink, sFilterName, sFilterOptions, false, false );
95 ScLinkMode nLinkMode = ScLinkMode::NONE;
96 if ( nMode == sheet::SheetLinkMode_NORMAL )
97 nLinkMode = ScLinkMode::NORMAL;
98 else if ( nMode == sheet::SheetLinkMode_VALUE )
99 nLinkMode = ScLinkMode::VALUE;
101 pDoc->SetLink( GetScImport().GetTables().GetCurrentSheet(),
102 nLinkMode, sLink, sFilterName, sFilterOptions,
103 sTableName, nRefresh );
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */